import{s as De,o as Ke,n as Ae}from"../chunks/scheduler.53228c21.js";import{S as Oe,i as et,e as c,s as i,c as M,h as tt,a as d,d as l,b as r,f as Qe,g as J,j as u,k as D,l as lt,m as a,n as T,t as w,o as y,p as b}from"../chunks/index.100fac89.js";import{C as at}from"../chunks/CopyLLMTxtMenu.999d3d86.js";import{C as ee}from"../chunks/CodeBlock.d30a6509.js";import{H as O,E as st}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.d27ae4df.js";import{H as nt,a as Pe}from"../chunks/HfOption.fad27e59.js";function ot(g){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>.",p,m,n;return m=new ee({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmx1eFBpcGVsaW5lJTBBJTBBZnJvbSUyMHBydW5hJTIwaW1wb3J0JTIwUHJ1bmFNb2RlbCUwQWZyb20lMjBwcnVuYS5kYXRhLnBydW5hX2RhdGFtb2R1bGUlMjBpbXBvcnQlMjBQcnVuYURhdGFNb2R1bGUlMEFmcm9tJTIwcHJ1bmEuZXZhbHVhdGlvbi5ldmFsdWF0aW9uX2FnZW50JTIwaW1wb3J0JTIwRXZhbHVhdGlvbkFnZW50JTBBZnJvbSUyMHBydW5hLmV2YWx1YXRpb24ubWV0cmljcyUyMGltcG9ydCUyMCglMEElMjAlMjAlMjAlMjBUaHJvdWdocHV0TWV0cmljJTJDJTBBJTIwJTIwJTIwJTIwVG9yY2hNZXRyaWNXcmFwcGVyJTJDJTBBJTIwJTIwJTIwJTIwVG90YWxUaW1lTWV0cmljJTJDJTBBKSUwQWZyb20lMjBwcnVuYS5ldmFsdWF0aW9uLnRhc2slMjBpbXBvcnQlMjBUYXNrJTBBJTBBJTIzJTIwZGVmaW5lJTIwdGhlJTIwZGV2aWNlJTBBZGV2aWNlJTIwJTNEJTIwJTIyY3VkYSUyMiUyMGlmJTIwdG9yY2guY3VkYS5pc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M0QlMjBUYXNrKG1ldHJpY3MlMkMlMjBkYXRhbW9kdWxlJTNEZGF0YW1vZHVsZSUyQyUyMGRldmljZSUzRGRldmljZSklMEFldmFsX2FnZW50JTIwJTNEJTIwRXZhbHVhdGlvbkFnZW50KHRhc2spJTBBJTBBJTIzJTIwRXZhbHVhdGUlMjBzbWFzaGVkJTIwbW9kZWwlMjBhbmQlMjBvZmZsb2FkJTIwaXQlMjB0byUyMENQVSUwQXNtYXNoZWRfcGlwZS5tb3ZlX3RvX2RldmljZShkZXZpY2UpJTBBc21hc2hlZF9waXBlX3Jlc3VsdHMlMjAlM0QlMjBldmFsX2FnZW50LmV2YWx1YXRlKHNtYXNoZWRfcGlwZSklMEFzbWFzaGVkX3BpcGUubW92ZV90b19kZXZpY2UoJTIyY3B1JTIyKQ==",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,p=i(),M(m.$$.fragment)},l(s){o=d(s,"P",{"data-svelte-h":!0}),u(o)!=="svelte-1yv4f30"&&(o.innerHTML=f),p=r(s),J(m.$$.fragment,s)},m(s,h){a(s,o,h),a(s,p,h),T(m,s,h),n=!0},p:Ae,i(s){n||(w(m.$$.fragment,s),n=!0)},o(s){y(m.$$.fragment,s),n=!1},d(s){s&&(l(o),l(p)),b(m,s)}}}function it(g){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.",p,m,n;return m=new ee({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,p=i(),M(m.$$.fragment)},l(s){o=d(s,"P",{"data-svelte-h":!0}),u(o)!=="svelte-1atmw9b"&&(o.innerHTML=f),p=r(s),J(m.$$.fragment,s)},m(s,h){a(s,o,h),a(s,p,h),T(m,s,h),n=!0},p:Ae,i(s){n||(w(m.$$.fragment,s),n=!0)},o(s){y(m.$$.fragment,s),n=!1},d(s){s&&(l(o),l(p)),b(m,s)}}}function rt(g){let o,f,p,m;return o=new Pe({props:{id:"eval",option:"optimized model",$$slots:{default:[ot]},$$scope:{ctx:g}}}),p=new Pe({props:{id:"eval",option:"standalone model",$$slots:{default:[it]},$$scope:{ctx:g}}}),{c(){M(o.$$.fragment),f=i(),M(p.$$.fragment)},l(n){J(o.$$.fragment,n),f=r(n),J(p.$$.fragment,n)},m(n,s){T(o,n,s),a(n,f,s),T(p,n,s),m=!0},p(n,s){const h={};s&2&&(h.$$scope={dirty:s,ctx:n}),o.$set(h);const Z={};s&2&&(Z.$$scope={dirty:s,ctx:n}),p.$set(Z)},i(n){m||(w(o.$$.fragment,n),w(p.$$.fragment,n),m=!0)},o(n){y(o.$$.fragment,n),y(p.$$.fragment,n),m=!1},d(n){n&&l(f),b(o,n),b(p,n)}}}function mt(g){let o,f,p,m,n,s,h,Z,G,Ze='<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.',te,$,Ge='<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>',le,F,$e="✅ (improves), ➖ (approx. the same), ❌ (worsens)",ae,k,Fe='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>.',se,_,ne,V,ke="Install Pruna with the following command.",oe,X,ie,C,re,z,_e="A broad range of optimization algorithms are supported for Diffusers models as shown below.",me,j,Ve='<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,Xe=`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.`,ce,U,Ce='<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>',de,I,ze='<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"/>',ue,E,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.",he,x,fe,v,Ee='<img src="https://huggingface.co/datasets/PrunaAI/documentation-images/resolve/main/diffusers/flux_smashed_comparison.png"/>',Me,H,xe="After optimization, we can share and load the optimized model using the Hugging Face Hub.",Je,N,Te,Y,we,q,He='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.',ye,L,Ne="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>.",be,B,ge,S,Ye="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,qe='<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>',Ue,Q,Ie,P,Le='<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>',ve,A,Be,K,We;return n=new at({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),h=new O({props:{title:"Pruna",local:"pruna",headingTag:"h1"}}),_=new O({props:{title:"Installation",local:"installation",headingTag:"h2"}}),X=new ee({props:{code:"cGlwJTIwaW5zdGFsbCUyMHBydW5h",highlighted:"pip install pruna",wrap:!1}}),C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0QlMjAlMjJmb3JhJTIyJTBBc21hc2hfY29uZmlnJTVCJTIyZm9yYV9pbnRlcnZhbCUyMiU1RCUyMCUzRCUyMDIlMEElMEElMjMlMjBmb3IlMjB0aGUlMjBiZXN0JTIwcmVzdWx0cyUyMGluJTIwdGVybXMlMjBvZiUyMHNwZWVkJTIweW91JTIwY2FuJTIwYWRkJTIwdGhlc2UlMjBjb25maWdzJTBBJTIzJTIwaG93ZXZlciUyMHRoZXklMjB3aWxsJTIwaW5jcmVhc2UlMjB5b3VyJTIwd2FybXVwJTIwdGltZSUyMGZyb20lMjAxLjUlMjBtaW4lMjB0byUyMDEwJTIwbWluJTBBJTIzJTIwc21hc2hfY29uZmlnJTVCJTIydG9yY2hfY29tcGlsZV9tb2RlJTIyJTVEJTIwJTNEJTIwJTIybWF4LWF1dG90dW5lLW5vLWN1ZGFncmFwaHMlMjIlMEElMjMlMjBzbWFzaF9jb25maWclNUIlMjJxdWFudGl6ZXIlMjIlNUQlMjAlM0QlMjAlMjJ0b3JjaGFvJTIyJTBBJTIzJTIwc21hc2hfY29uZmlnJTVCJTIydG9yY2hhb19xdWFudF90eXBlJTIyJTVEJTIwJTNEJTIwJTIyZnA4ZHElMjIlMEElMjMlMjBzbWFzaF9jb25maWclNUIlMjJ0b3JjaGFvX2V4Y2x1ZGVkX21vZHVsZXMlMjIlNUQlMjAlM0QlMjAlMjJub3JtJTJCZW1iZWRkaW5nJTIyJTBBJTBBJTIzJTIwb3B0aW1pemUlMjB0aGUlMjBtb2RlbCUwQXNtYXNoZWRfcGlwZSUyMCUzRCUyMHNtYXNoKHBpcGUlMkMlMjBzbWFzaF9jb25maWcpJTBBJTBBJTIzJTIwcnVuJTIwdGhlJTIwbW9kZWwlMEFzbWFzaGVkX3BpcGUoJTIyYSUyMGtuaXR0ZWQlMjBwdXJwbGUlMjBwcnVuZSUyMikuaW1hZ2VzJTVCMCU1RA==",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}}),N=new ee({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}}),Y=new O({props:{title:"Evaluate and benchmark Diffusers models",local:"evaluate-and-benchmark-diffusers-models",headingTag:"h2"}}),B=new nt({props:{id:"eval",options:["optimized model","standalone model"],$$slots:{default:[rt]},$$scope:{ctx:g}}}),Q=new O({props:{title:"Reference",local:"reference",headingTag:"h2"}}),A=new st({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/optimization/pruna.md"}}),{c(){o=c("meta"),f=i(),p=c("p"),m=i(),M(n.$$.fragment),s=i(),M(h.$$.fragment),Z=i(),G=c("p"),G.innerHTML=Ze,te=i(),$=c("table"),$.innerHTML=Ge,le=i(),F=c("p"),F.textContent=$e,ae=i(),k=c("p"),k.innerHTML=Fe,se=i(),M(_.$$.fragment),ne=i(),V=c("p"),V.textContent=ke,oe=i(),M(X.$$.fragment),ie=i(),M(C.$$.fragment),re=i(),z=c("p"),z.textContent=_e,me=i(),j=c("div"),j.innerHTML=Ve,pe=i(),R=c("p"),R.innerHTML=Xe,ce=i(),U=c("blockquote"),U.innerHTML=Ce,de=i(),I=c("div"),I.innerHTML=ze,ue=i(),E=c("p"),E.innerHTML=Re,he=i(),M(x.$$.fragment),fe=i(),v=c("div"),v.innerHTML=Ee,Me=i(),H=c("p"),H.textContent=xe,Je=i(),M(N.$$.fragment),Te=i(),M(Y.$$.fragment),we=i(),q=c("p"),q.innerHTML=He,ye=i(),L=c("p"),L.innerHTML=Ne,be=i(),M(B.$$.fragment),ge=i(),S=c("p"),S.textContent=Ye,je=i(),W=c("blockquote"),W.innerHTML=qe,Ue=i(),M(Q.$$.fragment),Ie=i(),P=c("ul"),P.innerHTML=Le,ve=i(),M(A.$$.fragment),Be=i(),K=c("p"),this.h()},l(e){const t=tt("svelte-u9bgzb",document.head);o=d(t,"META",{name:!0,content:!0}),t.forEach(l),f=r(e),p=d(e,"P",{}),Qe(p).forEach(l),m=r(e),J(n.$$.fragment,e),s=r(e),J(h.$$.fragment,e),Z=r(e),G=d(e,"P",{"data-svelte-h":!0}),u(G)!=="svelte-doimg4"&&(G.innerHTML=Ze),te=r(e),$=d(e,"TABLE",{"data-svelte-h":!0}),u($)!=="svelte-ct3fez"&&($.innerHTML=Ge),le=r(e),F=d(e,"P",{"data-svelte-h":!0}),u(F)!=="svelte-vkdhl3"&&(F.textContent=$e),ae=r(e),k=d(e,"P",{"data-svelte-h":!0}),u(k)!=="svelte-gicf0n"&&(k.innerHTML=Fe),se=r(e),J(_.$$.fragment,e),ne=r(e),V=d(e,"P",{"data-svelte-h":!0}),u(V)!=="svelte-1mhda9e"&&(V.textContent=ke),oe=r(e),J(X.$$.fragment,e),ie=r(e),J(C.$$.fragment,e),re=r(e),z=d(e,"P",{"data-svelte-h":!0}),u(z)!=="svelte-19uf75c"&&(z.textContent=_e),me=r(e),j=d(e,"DIV",{class:!0,"data-svelte-h":!0}),u(j)!=="svelte-1diaiat"&&(j.innerHTML=Ve),pe=r(e),R=d(e,"P",{"data-svelte-h":!0}),u(R)!=="svelte-2q15d4"&&(R.innerHTML=Xe),ce=r(e),U=d(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),u(U)!=="svelte-yl1m4o"&&(U.innerHTML=Ce),de=r(e),I=d(e,"DIV",{class:!0,"data-svelte-h":!0}),u(I)!=="svelte-4p98l1"&&(I.innerHTML=ze),ue=r(e),E=d(e,"P",{"data-svelte-h":!0}),u(E)!=="svelte-9w0h81"&&(E.innerHTML=Re),he=r(e),J(x.$$.fragment,e),fe=r(e),v=d(e,"DIV",{class:!0,"data-svelte-h":!0}),u(v)!=="svelte-1or519q"&&(v.innerHTML=Ee),Me=r(e),H=d(e,"P",{"data-svelte-h":!0}),u(H)!=="svelte-i3s1re"&&(H.textContent=xe),Je=r(e),J(N.$$.fragment,e),Te=r(e),J(Y.$$.fragment,e),we=r(e),q=d(e,"P",{"data-svelte-h":!0}),u(q)!=="svelte-ocu867"&&(q.innerHTML=He),ye=r(e),L=d(e,"P",{"data-svelte-h":!0}),u(L)!=="svelte-sdkumj"&&(L.innerHTML=Ne),be=r(e),J(B.$$.fragment,e),ge=r(e),S=d(e,"P",{"data-svelte-h":!0}),u(S)!=="svelte-10l7kab"&&(S.textContent=Ye),je=r(e),W=d(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),u(W)!=="svelte-pwj0k3"&&(W.innerHTML=qe),Ue=r(e),J(Q.$$.fragment,e),Ie=r(e),P=d(e,"UL",{"data-svelte-h":!0}),u(P)!=="svelte-e63z7a"&&(P.innerHTML=Le),ve=r(e),J(A.$$.fragment,e),Be=r(e),K=d(e,"P",{}),Qe(K).forEach(l),this.h()},h(){D(o,"name","hf:doc:metadata"),D(o,"content",pt),D(j,"class","flex justify-center"),D(U,"class","tip"),D(I,"class","flex justify-center"),D(v,"class","flex justify-center"),D(W,"class","tip")},m(e,t){lt(document.head,o),a(e,f,t),a(e,p,t),a(e,m,t),T(n,e,t),a(e,s,t),T(h,e,t),a(e,Z,t),a(e,G,t),a(e,te,t),a(e,$,t),a(e,le,t),a(e,F,t),a(e,ae,t),a(e,k,t),a(e,se,t),T(_,e,t),a(e,ne,t),a(e,V,t),a(e,oe,t),T(X,e,t),a(e,ie,t),T(C,e,t),a(e,re,t),a(e,z,t),a(e,me,t),a(e,j,t),a(e,pe,t),a(e,R,t),a(e,ce,t),a(e,U,t),a(e,de,t),a(e,I,t),a(e,ue,t),a(e,E,t),a(e,he,t),T(x,e,t),a(e,fe,t),a(e,v,t),a(e,Me,t),a(e,H,t),a(e,Je,t),T(N,e,t),a(e,Te,t),T(Y,e,t),a(e,we,t),a(e,q,t),a(e,ye,t),a(e,L,t),a(e,be,t),T(B,e,t),a(e,ge,t),a(e,S,t),a(e,je,t),a(e,W,t),a(e,Ue,t),T(Q,e,t),a(e,Ie,t),a(e,P,t),a(e,ve,t),T(A,e,t),a(e,Be,t),a(e,K,t),We=!0},p(e,[t]){const Se={};t&2&&(Se.$$scope={dirty:t,ctx:e}),B.$set(Se)},i(e){We||(w(n.$$.fragment,e),w(h.$$.fragment,e),w(_.$$.fragment,e),w(X.$$.fragment,e),w(C.$$.fragment,e),w(x.$$.fragment,e),w(N.$$.fragment,e),w(Y.$$.fragment,e),w(B.$$.fragment,e),w(Q.$$.fragment,e),w(A.$$.fragment,e),We=!0)},o(e){y(n.$$.fragment,e),y(h.$$.fragment,e),y(_.$$.fragment,e),y(X.$$.fragment,e),y(C.$$.fragment,e),y(x.$$.fragment,e),y(N.$$.fragment,e),y(Y.$$.fragment,e),y(B.$$.fragment,e),y(Q.$$.fragment,e),y(A.$$.fragment,e),We=!1},d(e){e&&(l(f),l(p),l(m),l(s),l(Z),l(G),l(te),l($),l(le),l(F),l(ae),l(k),l(se),l(ne),l(V),l(oe),l(ie),l(re),l(z),l(me),l(j),l(pe),l(R),l(ce),l(U),l(de),l(I),l(ue),l(E),l(he),l(fe),l(v),l(Me),l(H),l(Je),l(Te),l(we),l(q),l(ye),l(L),l(be),l(ge),l(S),l(je),l(W),l(Ue),l(Ie),l(P),l(ve),l(Be),l(K)),l(o),b(n,e),b(h,e),b(_,e),b(X,e),b(C,e),b(x,e),b(N,e),b(Y,e),b(B,e),b(Q,e),b(A,e)}}}const pt='{"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 ct(g){return Ke(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Tt extends Oe{constructor(o){super(),et(this,o,ct,mt,De,{})}}export{Tt as component};
