import{s as Pe,o as Ae,n as Qe}from"../chunks/scheduler.8c3d61f6.js";import{S as De,i as Ke,g as c,s as i,r as M,A as Oe,h as d,f as l,c as r,j as Le,u as J,x as u,k as P,y as et,a,v as T,d as w,t as y,w as b}from"../chunks/index.da70eac4.js";import{C as O}from"../chunks/CodeBlock.a9c4becf.js";import{H as K,E as tt}from"../chunks/getInferenceSnippets.cb466318.js";import{H as lt,a as Se}from"../chunks/HfOption.6c3b4e77.js";function at(j){let o,f="We can load and evaluate an optimized model by using the <code>EvaluationAgent</code> and pass it to the <code>Task</code>.",m,p,n;return p=new O({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmx1eFBpcGVsaW5lJTBBJTBBZnJvbSUyMHBydW5hJTIwaW1wb3J0JTIwUHJ1bmFNb2RlbCUwQWZyb20lMjBwcnVuYS5kYXRhLnBydW5hX2RhdGFtb2R1bGUlMjBpbXBvcnQlMjBQcnVuYURhdGFNb2R1bGUlMEFmcm9tJTIwcHJ1bmEuZXZhbHVhdGlvbi5ldmFsdWF0aW9uX2FnZW50JTIwaW1wb3J0JTIwRXZhbHVhdGlvbkFnZW50JTBBZnJvbSUyMHBydW5hLmV2YWx1YXRpb24ubWV0cmljcyUyMGltcG9ydCUyMCglMEElMjAlMjAlMjAlMjBUaHJvdWdocHV0TWV0cmljJTJDJTBBJTIwJTIwJTIwJTIwVG9yY2hNZXRyaWNXcmFwcGVyJTJDJTBBJTIwJTIwJTIwJTIwVG90YWxUaW1lTWV0cmljJTJDJTBBKSUwQWZyb20lMjBwcnVuYS5ldmFsdWF0aW9uLnRhc2slMjBpbXBvcnQlMjBUYXNrJTBBJTBBJTIzJTIwZGVmaW5lJTIwdGhlJTIwZGV2aWNlJTBBZGV2aWNlJTIwJTNEJTIwJTIyY3VkYSUyMiUyMGlmJTIwdG9yY2guY3VkYS5pc19hdmFpbGFibGUoKSUyMGVsc2UlMjAlMjJtcHMlMjIlMjBp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TNEZGF0YW1vZHVsZSUyQyUyMGRldmljZSUzRGRldmljZSklMEFldmFsX2FnZW50JTIwJTNEJTIwRXZhbHVhdGlvbkFnZW50KHRhc2spJTBBJTBBJTIzJTIwRXZhbHVhdGUlMjBzbWFzaGVkJTIwbW9kZWwlMjBhbmQlMjBvZmZsb2FkJTIwaXQlMjB0byUyMENQVSUwQXNtYXNoZWRfcGlwZS5tb3ZlX3RvX2RldmljZShkZXZpY2UpJTBBc21hc2hlZF9waXBlX3Jlc3VsdHMlMjAlM0QlMjBldmFsX2FnZW50LmV2YWx1YXRlKHNtYXNoZWRfcGlwZSklMEFzbWFzaGVkX3BpcGUubW92ZV90b19kZXZpY2UoJTIyY3B1JTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FluxPipeline

<span class="hljs-keyword">from</span> pruna <span class="hljs-keyword">import</span> PrunaModel
<span class="hljs-keyword">from</span> pruna.data.pruna_datamodule <span class="hljs-keyword">import</span> PrunaDataModule
<span class="hljs-keyword">from</span> pruna.evaluation.evaluation_agent <span class="hljs-keyword">import</span> EvaluationAgent
<span class="hljs-keyword">from</span> pruna.evaluation.metrics <span class="hljs-keyword">import</span> (
    ThroughputMetric,
    TorchMetricWrapper,
    TotalTimeMetric,
)
<span class="hljs-keyword">from</span> pruna.evaluation.task <span class="hljs-keyword">import</span> Task

<span class="hljs-comment"># define the device</span>
device = <span class="hljs-string">&quot;cuda&quot;</span> <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;mps&quot;</span> <span class="hljs-keyword">if</span> torch.backends.mps.is_available() <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cpu&quot;</span>

<span class="hljs-comment"># load the model</span>
<span class="hljs-comment"># Try PrunaAI/Segmind-Vega-smashed or PrunaAI/FLUX.1-dev-smashed with a small GPU memory</span>
smashed_pipe = PrunaModel.from_hub(<span class="hljs-string">&quot;PrunaAI/FLUX.1-dev-smashed&quot;</span>)

<span class="hljs-comment"># Define the metrics</span>
metrics = [
    TotalTimeMetric(n_iterations=<span class="hljs-number">20</span>, n_warmup_iterations=<span class="hljs-number">5</span>),
    ThroughputMetric(n_iterations=<span class="hljs-number">20</span>, n_warmup_iterations=<span class="hljs-number">5</span>),
    TorchMetricWrapper(<span class="hljs-string">&quot;clip&quot;</span>),
]

<span class="hljs-comment"># Define the datamodule</span>
datamodule = PrunaDataModule.from_string(<span class="hljs-string">&quot;LAION256&quot;</span>)
datamodule.limit_datasets(<span class="hljs-number">10</span>)

<span class="hljs-comment"># Define the task and evaluation agent</span>
task = Task(metrics, datamodule=datamodule, device=device)
eval_agent = EvaluationAgent(task)

<span class="hljs-comment"># Evaluate smashed model and offload it to CPU</span>
smashed_pipe.move_to_device(device)
smashed_pipe_results = eval_agent.evaluate(smashed_pipe)
smashed_pipe.move_to_device(<span class="hljs-string">&quot;cpu&quot;</span>)`,wrap:!1}}),{c(){o=c("p"),o.innerHTML=f,m=i(),M(p.$$.fragment)},l(s){o=d(s,"P",{"data-svelte-h":!0}),u(o)!=="svelte-1yv4f30"&&(o.innerHTML=f),m=r(s),J(p.$$.fragment,s)},m(s,h){a(s,o,h),a(s,m,h),T(p,s,h),n=!0},p:Qe,i(s){n||(w(p.$$.fragment,s),n=!0)},o(s){y(p.$$.fragment,s),n=!1},d(s){s&&(l(o),l(m)),b(p,s)}}}function st(j){let o,f="Instead of comparing the optimized model to the base model, you can also evaluate the standalone <code>diffusers</code> model. This is useful if you want to evaluate the performance of the model without the optimization. We can do so by using the <code>PrunaModel</code> wrapper and run the <code>EvaluationAgent</code> on it.",m,p,n;return p=new O({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmx1eFBpcGVsaW5lJTBBJTBBZnJvbSUyMHBydW5hJTIwaW1wb3J0JTIwUHJ1bmFNb2RlbCUwQSUwQSUyMyUyMGxvYWQlMjB0aGUlMjBtb2RlbCUwQSUyMyUyMFRyeSUyMFBydW5hQUklMkZTZWdtaW5kLVZlZ2Etc21hc2hlZCUyMG9yJTIwUHJ1bmFBSSUyRkZMVVguMS1kZXYtc21hc2hlZCUyMHdpdGglMjBhJTIwc21hbGwlMjBHUFUlMjBtZW1vcnklMEFwaXBlJTIwJTNEJTIwRmx1eFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJibGFjay1mb3Jlc3QtbGFicyUyRkZMVVguMS1kZXYlMjIlMkMlMEElMjAlMjAlMjAlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTBBKS50byglMjJjcHUlMjIpJTBBd3JhcHBlZF9waXBlJTIwJTNEJTIwUHJ1bmFNb2RlbChtb2RlbCUzRHBpcGUp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FluxPipeline

<span class="hljs-keyword">from</span> pruna <span class="hljs-keyword">import</span> PrunaModel

<span class="hljs-comment"># load the model</span>
<span class="hljs-comment"># Try PrunaAI/Segmind-Vega-smashed or PrunaAI/FLUX.1-dev-smashed with a small GPU memory</span>
pipe = FluxPipeline.from_pretrained(
    <span class="hljs-string">&quot;black-forest-labs/FLUX.1-dev&quot;</span>,
    torch_dtype=torch.bfloat16
).to(<span class="hljs-string">&quot;cpu&quot;</span>)
wrapped_pipe = PrunaModel(model=pipe)`,wrap:!1}}),{c(){o=c("p"),o.innerHTML=f,m=i(),M(p.$$.fragment)},l(s){o=d(s,"P",{"data-svelte-h":!0}),u(o)!=="svelte-1atmw9b"&&(o.innerHTML=f),m=r(s),J(p.$$.fragment,s)},m(s,h){a(s,o,h),a(s,m,h),T(p,s,h),n=!0},p:Qe,i(s){n||(w(p.$$.fragment,s),n=!0)},o(s){y(p.$$.fragment,s),n=!1},d(s){s&&(l(o),l(m)),b(p,s)}}}function nt(j){let o,f,m,p;return o=new Se({props:{id:"eval",option:"optimized model",$$slots:{default:[at]},$$scope:{ctx:j}}}),m=new Se({props:{id:"eval",option:"standalone model",$$slots:{default:[st]},$$scope:{ctx:j}}}),{c(){M(o.$$.fragment),f=i(),M(m.$$.fragment)},l(n){J(o.$$.fragment,n),f=r(n),J(m.$$.fragment,n)},m(n,s){T(o,n,s),a(n,f,s),T(m,n,s),p=!0},p(n,s){const h={};s&2&&(h.$$scope={dirty:s,ctx:n}),o.$set(h);const A={};s&2&&(A.$$scope={dirty:s,ctx:n}),m.$set(A)},i(n){p||(w(o.$$.fragment,n),w(m.$$.fragment,n),p=!0)},o(n){y(o.$$.fragment,n),y(m.$$.fragment,n),p=!1},d(n){n&&l(f),b(o,n),b(m,n)}}}function ot(j){let o,f,m,p,n,s,h,A='<a href="https://github.com/PrunaAI/pruna" rel="nofollow">Pruna</a> is a model optimization framework that offers various optimization methods - quantization, pruning, caching, compilation - for accelerating inference and reducing memory usage. A general overview of the optimization methods are shown below.',ee,Z,We='<thead><tr><th>Technique</th> <th>Description</th> <th align="center">Speed</th> <th align="center">Memory</th> <th align="center">Quality</th></tr></thead> <tbody><tr><td><code>batcher</code></td> <td>Groups multiple inputs together to be processed simultaneously, improving computational efficiency and reducing processing time.</td> <td align="center">✅</td> <td align="center">❌</td> <td align="center">➖</td></tr> <tr><td><code>cacher</code></td> <td>Stores intermediate results of computations to speed up subsequent operations.</td> <td align="center">✅</td> <td align="center">➖</td> <td align="center">➖</td></tr> <tr><td><code>compiler</code></td> <td>Optimises the model with instructions for specific hardware.</td> <td align="center">✅</td> <td align="center">➖</td> <td align="center">➖</td></tr> <tr><td><code>distiller</code></td> <td>Trains a smaller, simpler model to mimic a larger, more complex model.</td> <td align="center">✅</td> <td align="center">✅</td> <td align="center">❌</td></tr> <tr><td><code>quantizer</code></td> <td>Reduces the precision of weights and activations, lowering memory requirements.</td> <td align="center">✅</td> <td align="center">✅</td> <td align="center">❌</td></tr> <tr><td><code>pruner</code></td> <td>Removes less important or redundant connections and neurons, resulting in a sparser, more efficient network.</td> <td align="center">✅</td> <td align="center">✅</td> <td align="center">❌</td></tr> <tr><td><code>recoverer</code></td> <td>Restores the performance of a model after compression.</td> <td align="center">➖</td> <td align="center">➖</td> <td align="center">✅</td></tr> <tr><td><code>factorizer</code></td> <td>Factorization batches several small matrix multiplications into one large fused operation.</td> <td align="center">✅</td> <td align="center">➖</td> <td align="center">➖</td></tr> <tr><td><code>enhancer</code></td> <td>Enhances the model output by applying post-processing algorithms such as denoising or upscaling.</td> <td align="center">❌</td> <td align="center">-</td> <td align="center">✅</td></tr></tbody>',te,G,Ze="✅ (improves), ➖ (approx. the same), ❌ (worsens)",le,$,Ge='Explore the full range of optimization methods in the <a href="https://docs.pruna.ai/en/stable/docs_pruna/user_manual/configure.html#configure-algorithms" rel="nofollow">Pruna documentation</a>.',ae,F,se,k,$e="Install Pruna with the following command.",ne,_,oe,V,ie,X,Fe="A broad range of optimization algorithms are supported for Diffusers models as shown below.",re,g,ke='<img src="https://huggingface.co/datasets/PrunaAI/documentation-images/resolve/main/diffusers/diffusers_combinations.png" alt="Overview of the supported optimization algorithms for diffusers models"/>',pe,R,_e=`The example below optimizes <a href="https://huggingface.co/black-forest-labs/FLUX.1-dev" rel="nofollow">black-forest-labs/FLUX.1-dev</a>
with a combination of factorizer, compiler, and cacher algorithms. This combination accelerates inference by up to 4.2x and cuts peak GPU memory usage from 34.7GB to 28.0GB, all while maintaining virtually the same output quality.`,me,U,Ve='<p>Refer to the <a href="https://docs.pruna.ai/en/stable/docs_pruna/user_manual/configure.html" rel="nofollow">Pruna optimization</a> docs to learn more about the optimization techniques used in this example.</p>',ce,I,Xe='<img src="https://huggingface.co/datasets/PrunaAI/documentation-images/resolve/main/diffusers/flux_combination.png" alt="Optimization techniques used for FLUX.1-dev showing the combination of factorizer, compiler, and cacher algorithms"/>',de,z,Re="Start by defining a <code>SmashConfig</code> with the optimization algorithms to use. To optimize the model, wrap the pipeline and the <code>SmashConfig</code> with <code>smash</code> and then use the pipeline as normal for inference.",ue,C,he,v,ze='<img src="https://huggingface.co/datasets/PrunaAI/documentation-images/resolve/main/diffusers/flux_smashed_comparison.png"/>',fe,E,Ce="After optimization, we can share and load the optimized model using the Hugging Face Hub.",Me,H,Je,x,Te,N,Ee='Pruna provides the <a href="https://docs.pruna.ai/en/stable/docs_pruna/user_manual/evaluate.html" rel="nofollow">EvaluationAgent</a> to evaluate the quality of your optimized models.',we,Y,He="We can metrics we care about, such as total time and throughput, and the dataset to evaluate on. We can define a model and pass it to the <code>EvaluationAgent</code>.",ye,B,be,q,xe="Now that you have seen how to optimize and evaluate your models, you can start using Pruna to optimize your own models. Luckily, we have many examples to help you get started.",je,W,Ne='<p>For more details about benchmarking Flux, check out the <a href="https://huggingface.co/blog/PrunaAI/flux-fastest-image-generation-endpoint" rel="nofollow">Announcing FLUX-Juiced: The Fastest Image Generation Endpoint (2.6 times faster)!</a> blog post and the <a href="https://huggingface.co/spaces/PrunaAI/InferBench" rel="nofollow">InferBench</a> Space.</p>',ge,L,Ue,S,Ye='<li><a href="https://github.com/pruna-ai/pruna" rel="nofollow">Pruna</a></li> <li><a href="https://docs.pruna.ai/en/stable/docs_pruna/user_manual/configure.html#configure-algorithms" rel="nofollow">Pruna optimization</a></li> <li><a href="https://docs.pruna.ai/en/stable/docs_pruna/user_manual/evaluate.html" rel="nofollow">Pruna evaluation</a></li> <li><a href="https://docs.pruna.ai/en/stable/docs_pruna/tutorials/index.html" rel="nofollow">Pruna tutorials</a></li>',Ie,Q,ve,D,Be;return n=new K({props:{title:"Pruna",local:"pruna",headingTag:"h1"}}),F=new K({props:{title:"Installation",local:"installation",headingTag:"h2"}}),_=new O({props:{code:"cGlwJTIwaW5zdGFsbCUyMHBydW5h",highlighted:"pip install pruna",wrap:!1}}),V=new K({props:{title:"Optimize Diffusers models",local:"optimize-diffusers-models",headingTag:"h2"}}),C=new O({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb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MjBiZXN0JTIwcmVzdWx0cyUyMGluJTIwdGVybXMlMjBvZiUyMHNwZWVkJTIweW91JTIwY2FuJTIwYWRkJTIwdGhlc2UlMjBjb25maWdzJTBBJTIzJTIwaG93ZXZlciUyMHRoZXklMjB3aWxsJTIwaW5jcmVhc2UlMjB5b3VyJTIwd2FybXVwJTIwdGltZSUyMGZyb20lMjAxLjUlMjBtaW4lMjB0byUyMDEwJTIwbWluJTBBJTIzJTIwc21hc2hfY29uZmlnJTVCJTIydG9yY2hfY29tcGlsZV9tb2RlJTIyJTVEJTIwJTNEJTIwJTIybWF4LWF1dG90dW5lLW5vLWN1ZGFncmFwaHMlMjIlMEElMjMlMjBzbWFzaF9jb25maWclNUIlMjJxdWFudGl6ZXIlMjIlNUQlMjAlM0QlMjAlMjJ0b3JjaGFvJTIyJTBBJTIzJTIwc21hc2hfY29uZmlnJTVCJTIydG9yY2hhb19xdWFudF90eXBlJTIyJTVEJTIwJTNEJTIwJTIyZnA4ZHElMjIlMEElMjMlMjBzbWFzaF9jb25maWclNUIlMjJ0b3JjaGFvX2V4Y2x1ZGVkX21vZHVsZXMlMjIlNUQlMjAlM0QlMjAlMjJub3JtJTJCZW1iZWRkaW5nJTIyJTBBJTBBJTIzJTIwb3B0aW1pemUlMjB0aGUlMjBtb2RlbCUwQXNtYXNoZWRfcGlwZSUyMCUzRCUyMHNtYXNoKHBpcGUlMkMlMjBzbWFzaF9jb25maWcpJTBBJTBBJTIzJTIwcnVuJTIwdGhlJTIwbW9kZWwlMEFzbWFzaGVkX3BpcGUoJTIyYSUyMGtuaXR0ZWQlMjBwdXJwbGUlMjBwcnVuZSUyMikuaW1hZ2VzJTVCMCU1RA==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FluxPipeline

<span class="hljs-keyword">from</span> pruna <span class="hljs-keyword">import</span> PrunaModel, SmashConfig, smash

<span class="hljs-comment"># load the model</span>
<span class="hljs-comment"># Try segmind/Segmind-Vega or black-forest-labs/FLUX.1-schnell with a small GPU memory</span>
pipe = FluxPipeline.from_pretrained(
    <span class="hljs-string">&quot;black-forest-labs/FLUX.1-dev&quot;</span>,
    torch_dtype=torch.bfloat16
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-comment"># define the configuration</span>
smash_config = SmashConfig()
smash_config[<span class="hljs-string">&quot;factorizer&quot;</span>] = <span class="hljs-string">&quot;qkv_diffusers&quot;</span>
smash_config[<span class="hljs-string">&quot;compiler&quot;</span>] = <span class="hljs-string">&quot;torch_compile&quot;</span>
smash_config[<span class="hljs-string">&quot;torch_compile_target&quot;</span>] = <span class="hljs-string">&quot;module_list&quot;</span>
smash_config[<span class="hljs-string">&quot;cacher&quot;</span>] = <span class="hljs-string">&quot;fora&quot;</span>
smash_config[<span class="hljs-string">&quot;fora_interval&quot;</span>] = <span class="hljs-number">2</span>

<span class="hljs-comment"># for the best results in terms of speed you can add these configs</span>
<span class="hljs-comment"># however they will increase your warmup time from 1.5 min to 10 min</span>
<span class="hljs-comment"># smash_config[&quot;torch_compile_mode&quot;] = &quot;max-autotune-no-cudagraphs&quot;</span>
<span class="hljs-comment"># smash_config[&quot;quantizer&quot;] = &quot;torchao&quot;</span>
<span class="hljs-comment"># smash_config[&quot;torchao_quant_type&quot;] = &quot;fp8dq&quot;</span>
<span class="hljs-comment"># smash_config[&quot;torchao_excluded_modules&quot;] = &quot;norm+embedding&quot;</span>

<span class="hljs-comment"># optimize the model</span>
smashed_pipe = smash(pipe, smash_config)

<span class="hljs-comment"># run the model</span>
smashed_pipe(<span class="hljs-string">&quot;a knitted purple prune&quot;</span>).images[<span class="hljs-number">0</span>]`,wrap:!1}}),H=new O({props:{code:"JTIzJTIwc2F2ZSUyMHRoZSUyMG1vZGVsJTBBc21hc2hlZF9waXBlLnNhdmVfdG9faHViKCUyMiUzQ3VzZXJuYW1lJTNFJTJGRkxVWC4xLWRldi1zbWFzaGVkJTIyKSUwQSUwQSUyMyUyMGxvYWQlMjB0aGUlMjBtb2RlbCUwQXNtYXNoZWRfcGlwZSUyMCUzRCUyMFBydW5hTW9kZWwuZnJvbV9odWIoJTIyJTNDdXNlcm5hbWUlM0UlMkZGTFVYLjEtZGV2LXNtYXNoZWQlMjIp",highlighted:`<span class="hljs-comment"># save the model</span>
smashed_pipe.save_to_hub(<span class="hljs-string">&quot;&lt;username&gt;/FLUX.1-dev-smashed&quot;</span>)

<span class="hljs-comment"># load the model</span>
smashed_pipe = PrunaModel.from_hub(<span class="hljs-string">&quot;&lt;username&gt;/FLUX.1-dev-smashed&quot;</span>)`,wrap:!1}}),x=new K({props:{title:"Evaluate and benchmark Diffusers models",local:"evaluate-and-benchmark-diffusers-models",headingTag:"h2"}}),B=new lt({props:{id:"eval",options:["optimized model","standalone model"],$$slots:{default:[nt]},$$scope:{ctx:j}}}),L=new K({props:{title:"Reference",local:"reference",headingTag:"h2"}}),Q=new tt({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/optimization/pruna.md"}}),{c(){o=c("meta"),f=i(),m=c("p"),p=i(),M(n.$$.fragment),s=i(),h=c("p"),h.innerHTML=A,ee=i(),Z=c("table"),Z.innerHTML=We,te=i(),G=c("p"),G.textContent=Ze,le=i(),$=c("p"),$.innerHTML=Ge,ae=i(),M(F.$$.fragment),se=i(),k=c("p"),k.textContent=$e,ne=i(),M(_.$$.fragment),oe=i(),M(V.$$.fragment),ie=i(),X=c("p"),X.textContent=Fe,re=i(),g=c("div"),g.innerHTML=ke,pe=i(),R=c("p"),R.innerHTML=_e,me=i(),U=c("blockquote"),U.innerHTML=Ve,ce=i(),I=c("div"),I.innerHTML=Xe,de=i(),z=c("p"),z.innerHTML=Re,ue=i(),M(C.$$.fragment),he=i(),v=c("div"),v.innerHTML=ze,fe=i(),E=c("p"),E.textContent=Ce,Me=i(),M(H.$$.fragment),Je=i(),M(x.$$.fragment),Te=i(),N=c("p"),N.innerHTML=Ee,we=i(),Y=c("p"),Y.innerHTML=He,ye=i(),M(B.$$.fragment),be=i(),q=c("p"),q.textContent=xe,je=i(),W=c("blockquote"),W.innerHTML=Ne,ge=i(),M(L.$$.fragment),Ue=i(),S=c("ul"),S.innerHTML=Ye,Ie=i(),M(Q.$$.fragment),ve=i(),D=c("p"),this.h()},l(e){const t=Oe("svelte-u9bgzb",document.head);o=d(t,"META",{name:!0,content:!0}),t.forEach(l),f=r(e),m=d(e,"P",{}),Le(m).forEach(l),p=r(e),J(n.$$.fragment,e),s=r(e),h=d(e,"P",{"data-svelte-h":!0}),u(h)!=="svelte-doimg4"&&(h.innerHTML=A),ee=r(e),Z=d(e,"TABLE",{"data-svelte-h":!0}),u(Z)!=="svelte-ct3fez"&&(Z.innerHTML=We),te=r(e),G=d(e,"P",{"data-svelte-h":!0}),u(G)!=="svelte-vkdhl3"&&(G.textContent=Ze),le=r(e),$=d(e,"P",{"data-svelte-h":!0}),u($)!=="svelte-gicf0n"&&($.innerHTML=Ge),ae=r(e),J(F.$$.fragment,e),se=r(e),k=d(e,"P",{"data-svelte-h":!0}),u(k)!=="svelte-1mhda9e"&&(k.textContent=$e),ne=r(e),J(_.$$.fragment,e),oe=r(e),J(V.$$.fragment,e),ie=r(e),X=d(e,"P",{"data-svelte-h":!0}),u(X)!=="svelte-19uf75c"&&(X.textContent=Fe),re=r(e),g=d(e,"DIV",{class:!0,"data-svelte-h":!0}),u(g)!=="svelte-1diaiat"&&(g.innerHTML=ke),pe=r(e),R=d(e,"P",{"data-svelte-h":!0}),u(R)!=="svelte-2q15d4"&&(R.innerHTML=_e),me=r(e),U=d(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),u(U)!=="svelte-yl1m4o"&&(U.innerHTML=Ve),ce=r(e),I=d(e,"DIV",{class:!0,"data-svelte-h":!0}),u(I)!=="svelte-4p98l1"&&(I.innerHTML=Xe),de=r(e),z=d(e,"P",{"data-svelte-h":!0}),u(z)!=="svelte-9w0h81"&&(z.innerHTML=Re),ue=r(e),J(C.$$.fragment,e),he=r(e),v=d(e,"DIV",{class:!0,"data-svelte-h":!0}),u(v)!=="svelte-1or519q"&&(v.innerHTML=ze),fe=r(e),E=d(e,"P",{"data-svelte-h":!0}),u(E)!=="svelte-i3s1re"&&(E.textContent=Ce),Me=r(e),J(H.$$.fragment,e),Je=r(e),J(x.$$.fragment,e),Te=r(e),N=d(e,"P",{"data-svelte-h":!0}),u(N)!=="svelte-ocu867"&&(N.innerHTML=Ee),we=r(e),Y=d(e,"P",{"data-svelte-h":!0}),u(Y)!=="svelte-sdkumj"&&(Y.innerHTML=He),ye=r(e),J(B.$$.fragment,e),be=r(e),q=d(e,"P",{"data-svelte-h":!0}),u(q)!=="svelte-10l7kab"&&(q.textContent=xe),je=r(e),W=d(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),u(W)!=="svelte-pwj0k3"&&(W.innerHTML=Ne),ge=r(e),J(L.$$.fragment,e),Ue=r(e),S=d(e,"UL",{"data-svelte-h":!0}),u(S)!=="svelte-e63z7a"&&(S.innerHTML=Ye),Ie=r(e),J(Q.$$.fragment,e),ve=r(e),D=d(e,"P",{}),Le(D).forEach(l),this.h()},h(){P(o,"name","hf:doc:metadata"),P(o,"content",it),P(g,"class","flex justify-center"),P(U,"class","tip"),P(I,"class","flex justify-center"),P(v,"class","flex justify-center"),P(W,"class","tip")},m(e,t){et(document.head,o),a(e,f,t),a(e,m,t),a(e,p,t),T(n,e,t),a(e,s,t),a(e,h,t),a(e,ee,t),a(e,Z,t),a(e,te,t),a(e,G,t),a(e,le,t),a(e,$,t),a(e,ae,t),T(F,e,t),a(e,se,t),a(e,k,t),a(e,ne,t),T(_,e,t),a(e,oe,t),T(V,e,t),a(e,ie,t),a(e,X,t),a(e,re,t),a(e,g,t),a(e,pe,t),a(e,R,t),a(e,me,t),a(e,U,t),a(e,ce,t),a(e,I,t),a(e,de,t),a(e,z,t),a(e,ue,t),T(C,e,t),a(e,he,t),a(e,v,t),a(e,fe,t),a(e,E,t),a(e,Me,t),T(H,e,t),a(e,Je,t),T(x,e,t),a(e,Te,t),a(e,N,t),a(e,we,t),a(e,Y,t),a(e,ye,t),T(B,e,t),a(e,be,t),a(e,q,t),a(e,je,t),a(e,W,t),a(e,ge,t),T(L,e,t),a(e,Ue,t),a(e,S,t),a(e,Ie,t),T(Q,e,t),a(e,ve,t),a(e,D,t),Be=!0},p(e,[t]){const qe={};t&2&&(qe.$$scope={dirty:t,ctx:e}),B.$set(qe)},i(e){Be||(w(n.$$.fragment,e),w(F.$$.fragment,e),w(_.$$.fragment,e),w(V.$$.fragment,e),w(C.$$.fragment,e),w(H.$$.fragment,e),w(x.$$.fragment,e),w(B.$$.fragment,e),w(L.$$.fragment,e),w(Q.$$.fragment,e),Be=!0)},o(e){y(n.$$.fragment,e),y(F.$$.fragment,e),y(_.$$.fragment,e),y(V.$$.fragment,e),y(C.$$.fragment,e),y(H.$$.fragment,e),y(x.$$.fragment,e),y(B.$$.fragment,e),y(L.$$.fragment,e),y(Q.$$.fragment,e),Be=!1},d(e){e&&(l(f),l(m),l(p),l(s),l(h),l(ee),l(Z),l(te),l(G),l(le),l($),l(ae),l(se),l(k),l(ne),l(oe),l(ie),l(X),l(re),l(g),l(pe),l(R),l(me),l(U),l(ce),l(I),l(de),l(z),l(ue),l(he),l(v),l(fe),l(E),l(Me),l(Je),l(Te),l(N),l(we),l(Y),l(ye),l(be),l(q),l(je),l(W),l(ge),l(Ue),l(S),l(Ie),l(ve),l(D)),l(o),b(n,e),b(F,e),b(_,e),b(V,e),b(C,e),b(H,e),b(x,e),b(B,e),b(L,e),b(Q,e)}}}const it='{"title":"Pruna","local":"pruna","sections":[{"title":"Installation","local":"installation","sections":[],"depth":2},{"title":"Optimize Diffusers models","local":"optimize-diffusers-models","sections":[],"depth":2},{"title":"Evaluate and benchmark Diffusers models","local":"evaluate-and-benchmark-diffusers-models","sections":[],"depth":2},{"title":"Reference","local":"reference","sections":[],"depth":2}],"depth":1}';function rt(j){return Ae(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ht extends De{constructor(o){super(),Ke(this,o,rt,ot,Pe,{})}}export{ht as component};
