import{s as Ae,o as De,n as We}from"../chunks/scheduler.8c3d61f6.js";import{S as Ke,i as Oe,g as c,s as r,r as M,A as et,h as d,f as a,c as p,j as Le,u as J,x as h,k as D,y as tt,a as l,v as T,d as w,t as y,w as b}from"../chunks/index.da70eac4.js";import{T as Qe}from"../chunks/Tip.1d9b8c37.js";import{C as O}from"../chunks/CodeBlock.a9c4becf.js";import{H as K,E as at}from"../chunks/getInferenceSnippets.4986d68f.js";import{H as lt,a as Pe}from"../chunks/HfOption.6ab18950.js";function st(g){let s,u='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.';return{c(){s=c("p"),s.innerHTML=u},l(i){s=d(i,"P",{"data-svelte-h":!0}),h(s)!=="svelte-1rhkn9f"&&(s.innerHTML=u)},m(i,m){l(i,s,m)},p:We,d(i){i&&a(s)}}}function nt(g){let s,u="We can load and evaluate an optimized model by using the <code>EvaluationAgent</code> and pass it to the <code>Task</code>.",i,m,o;return m=new O({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmx1eFBpcGVsaW5lJTBBJTBBZnJvbSUyMHBydW5hJTIwaW1wb3J0JTIwUHJ1bmFNb2RlbCUwQWZyb20lMjBwcnVuYS5kYXRhLnBydW5hX2RhdGFtb2R1bGUlMjBpbXBvcnQlMjBQcnVuYURhdGFNb2R1bGUlMEFmcm9tJTIwcHJ1bmEuZXZhbHVhdGlvbi5ldmFsdWF0aW9uX2FnZW50JTIwaW1wb3J0JTIwRXZhbHVhdGlvbkFnZW50JTBBZnJvbSUyMHBydW5hLmV2YWx1YXRpb24ubWV0cmljcyUyMGltcG9ydCUyMCglMEElMjAlMjAlMjAlMjBUaHJvdWdocHV0TWV0cmljJTJDJTBBJTIwJTIwJTIwJTIwVG9yY2hNZXRyaWNXcmFwcGVyJTJDJTBBJTIwJTIwJTIwJTIwVG90YWxU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JTIwUHJ1bmFEYXRhTW9kdWxlLmZyb21fc3RyaW5nKCUyMkxBSU9OMjU2JTIyKSUwQWRhdGFtb2R1bGUubGltaXRfZGF0YXNldHMoMTApJTBBJTBBJTIzJTIwRGVmaW5lJTIwdGhlJTIwdGFzayUyMGFuZCUyMGV2YWx1YXRpb24lMjBhZ2VudCUwQXRhc2slMjAlM0QlMjBUYXNrKG1ldHJpY3MlMkMlMjBkYXRhbW9kdWxlJTNEZGF0YW1vZHVsZSUyQyUyMGRldmljZSUzRGRldmljZSklMEFldmFsX2FnZW50JTIwJTNEJTIwRXZhbHVhdGlvbkFnZW50KHRhc2spJTBBJTBBJTIzJTIwRXZhbHVhdGUlMjBzbWFzaGVkJTIwbW9kZWwlMjBhbmQlMjBvZmZsb2FkJTIwaXQlMjB0byUyMENQVSUwQXNtYXNoZWRfcGlwZS5tb3ZlX3RvX2RldmljZShkZXZpY2UpJTBBc21hc2hlZF9waXBlX3Jlc3VsdHMlMjAlM0QlMjBldmFsX2FnZW50LmV2YWx1YXRlKHNtYXNoZWRfcGlwZSklMEFzbWFzaGVkX3BpcGUubW92ZV90b19kZXZpY2UoJTIyY3B1JTIyKQ==",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(){s=c("p"),s.innerHTML=u,i=r(),M(m.$$.fragment)},l(n){s=d(n,"P",{"data-svelte-h":!0}),h(s)!=="svelte-1yv4f30"&&(s.innerHTML=u),i=p(n),J(m.$$.fragment,n)},m(n,f){l(n,s,f),l(n,i,f),T(m,n,f),o=!0},p:We,i(n){o||(w(m.$$.fragment,n),o=!0)},o(n){y(m.$$.fragment,n),o=!1},d(n){n&&(a(s),a(i)),b(m,n)}}}function ot(g){let s,u="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.",i,m,o;return m=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(){s=c("p"),s.innerHTML=u,i=r(),M(m.$$.fragment)},l(n){s=d(n,"P",{"data-svelte-h":!0}),h(s)!=="svelte-1atmw9b"&&(s.innerHTML=u),i=p(n),J(m.$$.fragment,n)},m(n,f){l(n,s,f),l(n,i,f),T(m,n,f),o=!0},p:We,i(n){o||(w(m.$$.fragment,n),o=!0)},o(n){y(m.$$.fragment,n),o=!1},d(n){n&&(a(s),a(i)),b(m,n)}}}function it(g){let s,u,i,m;return s=new Pe({props:{id:"eval",option:"optimized model",$$slots:{default:[nt]},$$scope:{ctx:g}}}),i=new Pe({props:{id:"eval",option:"standalone model",$$slots:{default:[ot]},$$scope:{ctx:g}}}),{c(){M(s.$$.fragment),u=r(),M(i.$$.fragment)},l(o){J(s.$$.fragment,o),u=p(o),J(i.$$.fragment,o)},m(o,n){T(s,o,n),l(o,u,n),T(i,o,n),m=!0},p(o,n){const f={};n&2&&(f.$$scope={dirty:n,ctx:o}),s.$set(f);const P={};n&2&&(P.$$scope={dirty:n,ctx:o}),i.$set(P)},i(o){m||(w(s.$$.fragment,o),w(i.$$.fragment,o),m=!0)},o(o){y(s.$$.fragment,o),y(i.$$.fragment,o),m=!1},d(o){o&&a(u),b(s,o),b(i,o)}}}function rt(g){let s,u='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.';return{c(){s=c("p"),s.innerHTML=u},l(i){s=d(i,"P",{"data-svelte-h":!0}),h(s)!=="svelte-lzgn6c"&&(s.innerHTML=u)},m(i,m){l(i,s,m)},p:We,d(i){i&&a(s)}}}function pt(g){let s,u,i,m,o,n,f,P='<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,B,Be='<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,Z,Ze="✅ (improves), ➖ (approx. the same), ❌ (worsens)",ae,G,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>.',le,F,se,_,Fe="Install Pruna with the following command.",ne,k,oe,V,ie,X,_e="A broad range of optimization algorithms are supported for Diffusers models as shown below.",re,j,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,z,Ve=`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,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,R,ze="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,Re='<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,$,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.",ge,W,je,S,Ue,L,Ne='<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,A,$e;return o=new K({props:{title:"Pruna",local:"pruna",headingTag:"h1"}}),F=new K({props:{title:"Installation",local:"installation",headingTag:"h2"}}),k=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"}}),U=new Qe({props:{warning:!1,$$slots:{default:[st]},$$scope:{ctx:g}}}),C=new O({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmx1eFBpcGVsaW5lJTBBJTBBZnJvbSUyMHBydW5hJTIwaW1wb3J0JTIwUHJ1bmFNb2RlbCUyQyUyMFNtYXNoQ29uZmlnJTJDJTIwc21hc2glMEElMEElMjMlMjBsb2FkJTIwdGhlJTIwbW9kZWwlMEElMjMlMjBUcnklMjBzZWdtaW5kJTJGU2VnbWluZC1WZWdhJTIwb3IlMjBibGFjay1mb3Jlc3QtbGFicyUyRkZMVVguMS1zY2huZWxsJTIwd2l0aCUyMGElMjBzbWFsbCUyMEdQVSUyMG1lbW9yeSUwQXBpcGUlMjAlM0QlMjBGbHV4UGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMmJsYWNrLWZvcmVzdC1sYWJzJTJGRkxVWC4xLWRldiUyMiUyQyUwQSUyMCUyMCUyMCUyMHRvcmNoX2R0eXBlJTNEdG9yY2guYmZsb2F0MTYlMEEpLnRvKCUyMmN1ZGElMjIpJTBBJTBBJTIzJTIwZGVmaW5lJTIwdGhlJTIwY29uZmlndXJhdGlvbiUwQXNtYXNoX2NvbmZpZyUyMCUzRCUyMFNtYXNoQ29uZmlnKCklMEFzbWFzaF9jb25maWclNUIlMjJmYWN0b3JpemVyJTIyJTVEJTIwJTNEJTIwJTIycWt2X2RpZmZ1c2VycyUyMiUwQXNtYXNoX2NvbmZpZyU1QiUyMmNvbXBp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jBzbWFzaF9jb25maWcpJTBBJTBBJTIzJTIwcnVuJTIwdGhlJTIwbW9kZWwlMEFzbWFzaGVkX3BpcGUoJTIyYSUyMGtuaXR0ZWQlMjBwdXJwbGUlMjBwcnVuZSUyMikuaW1hZ2VzJTVCMCU1RA==",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"}}),$=new lt({props:{id:"eval",options:["optimized model","standalone model"],$$slots:{default:[it]},$$scope:{ctx:g}}}),W=new Qe({props:{warning:!1,$$slots:{default:[rt]},$$scope:{ctx:g}}}),S=new K({props:{title:"Reference",local:"reference",headingTag:"h2"}}),Q=new at({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/optimization/pruna.md"}}),{c(){s=c("meta"),u=r(),i=c("p"),m=r(),M(o.$$.fragment),n=r(),f=c("p"),f.innerHTML=P,ee=r(),B=c("table"),B.innerHTML=Be,te=r(),Z=c("p"),Z.textContent=Ze,ae=r(),G=c("p"),G.innerHTML=Ge,le=r(),M(F.$$.fragment),se=r(),_=c("p"),_.textContent=Fe,ne=r(),M(k.$$.fragment),oe=r(),M(V.$$.fragment),ie=r(),X=c("p"),X.textContent=_e,re=r(),j=c("div"),j.innerHTML=ke,pe=r(),z=c("p"),z.innerHTML=Ve,me=r(),M(U.$$.fragment),ce=r(),I=c("div"),I.innerHTML=Xe,de=r(),R=c("p"),R.innerHTML=ze,ue=r(),M(C.$$.fragment),he=r(),v=c("div"),v.innerHTML=Re,fe=r(),E=c("p"),E.textContent=Ce,Me=r(),M(H.$$.fragment),Je=r(),M(x.$$.fragment),Te=r(),N=c("p"),N.innerHTML=Ee,we=r(),Y=c("p"),Y.innerHTML=He,ye=r(),M($.$$.fragment),be=r(),q=c("p"),q.textContent=xe,ge=r(),M(W.$$.fragment),je=r(),M(S.$$.fragment),Ue=r(),L=c("ul"),L.innerHTML=Ne,Ie=r(),M(Q.$$.fragment),ve=r(),A=c("p"),this.h()},l(e){const t=et("svelte-u9bgzb",document.head);s=d(t,"META",{name:!0,content:!0}),t.forEach(a),u=p(e),i=d(e,"P",{}),Le(i).forEach(a),m=p(e),J(o.$$.fragment,e),n=p(e),f=d(e,"P",{"data-svelte-h":!0}),h(f)!=="svelte-doimg4"&&(f.innerHTML=P),ee=p(e),B=d(e,"TABLE",{"data-svelte-h":!0}),h(B)!=="svelte-ct3fez"&&(B.innerHTML=Be),te=p(e),Z=d(e,"P",{"data-svelte-h":!0}),h(Z)!=="svelte-vkdhl3"&&(Z.textContent=Ze),ae=p(e),G=d(e,"P",{"data-svelte-h":!0}),h(G)!=="svelte-gicf0n"&&(G.innerHTML=Ge),le=p(e),J(F.$$.fragment,e),se=p(e),_=d(e,"P",{"data-svelte-h":!0}),h(_)!=="svelte-1mhda9e"&&(_.textContent=Fe),ne=p(e),J(k.$$.fragment,e),oe=p(e),J(V.$$.fragment,e),ie=p(e),X=d(e,"P",{"data-svelte-h":!0}),h(X)!=="svelte-19uf75c"&&(X.textContent=_e),re=p(e),j=d(e,"DIV",{class:!0,"data-svelte-h":!0}),h(j)!=="svelte-1diaiat"&&(j.innerHTML=ke),pe=p(e),z=d(e,"P",{"data-svelte-h":!0}),h(z)!=="svelte-2q15d4"&&(z.innerHTML=Ve),me=p(e),J(U.$$.fragment,e),ce=p(e),I=d(e,"DIV",{class:!0,"data-svelte-h":!0}),h(I)!=="svelte-4p98l1"&&(I.innerHTML=Xe),de=p(e),R=d(e,"P",{"data-svelte-h":!0}),h(R)!=="svelte-9w0h81"&&(R.innerHTML=ze),ue=p(e),J(C.$$.fragment,e),he=p(e),v=d(e,"DIV",{class:!0,"data-svelte-h":!0}),h(v)!=="svelte-1or519q"&&(v.innerHTML=Re),fe=p(e),E=d(e,"P",{"data-svelte-h":!0}),h(E)!=="svelte-i3s1re"&&(E.textContent=Ce),Me=p(e),J(H.$$.fragment,e),Je=p(e),J(x.$$.fragment,e),Te=p(e),N=d(e,"P",{"data-svelte-h":!0}),h(N)!=="svelte-ocu867"&&(N.innerHTML=Ee),we=p(e),Y=d(e,"P",{"data-svelte-h":!0}),h(Y)!=="svelte-sdkumj"&&(Y.innerHTML=He),ye=p(e),J($.$$.fragment,e),be=p(e),q=d(e,"P",{"data-svelte-h":!0}),h(q)!=="svelte-10l7kab"&&(q.textContent=xe),ge=p(e),J(W.$$.fragment,e),je=p(e),J(S.$$.fragment,e),Ue=p(e),L=d(e,"UL",{"data-svelte-h":!0}),h(L)!=="svelte-e63z7a"&&(L.innerHTML=Ne),Ie=p(e),J(Q.$$.fragment,e),ve=p(e),A=d(e,"P",{}),Le(A).forEach(a),this.h()},h(){D(s,"name","hf:doc:metadata"),D(s,"content",mt),D(j,"class","flex justify-center"),D(I,"class","flex justify-center"),D(v,"class","flex justify-center")},m(e,t){tt(document.head,s),l(e,u,t),l(e,i,t),l(e,m,t),T(o,e,t),l(e,n,t),l(e,f,t),l(e,ee,t),l(e,B,t),l(e,te,t),l(e,Z,t),l(e,ae,t),l(e,G,t),l(e,le,t),T(F,e,t),l(e,se,t),l(e,_,t),l(e,ne,t),T(k,e,t),l(e,oe,t),T(V,e,t),l(e,ie,t),l(e,X,t),l(e,re,t),l(e,j,t),l(e,pe,t),l(e,z,t),l(e,me,t),T(U,e,t),l(e,ce,t),l(e,I,t),l(e,de,t),l(e,R,t),l(e,ue,t),T(C,e,t),l(e,he,t),l(e,v,t),l(e,fe,t),l(e,E,t),l(e,Me,t),T(H,e,t),l(e,Je,t),T(x,e,t),l(e,Te,t),l(e,N,t),l(e,we,t),l(e,Y,t),l(e,ye,t),T($,e,t),l(e,be,t),l(e,q,t),l(e,ge,t),T(W,e,t),l(e,je,t),T(S,e,t),l(e,Ue,t),l(e,L,t),l(e,Ie,t),T(Q,e,t),l(e,ve,t),l(e,A,t),$e=!0},p(e,[t]){const Ye={};t&2&&(Ye.$$scope={dirty:t,ctx:e}),U.$set(Ye);const qe={};t&2&&(qe.$$scope={dirty:t,ctx:e}),$.$set(qe);const Se={};t&2&&(Se.$$scope={dirty:t,ctx:e}),W.$set(Se)},i(e){$e||(w(o.$$.fragment,e),w(F.$$.fragment,e),w(k.$$.fragment,e),w(V.$$.fragment,e),w(U.$$.fragment,e),w(C.$$.fragment,e),w(H.$$.fragment,e),w(x.$$.fragment,e),w($.$$.fragment,e),w(W.$$.fragment,e),w(S.$$.fragment,e),w(Q.$$.fragment,e),$e=!0)},o(e){y(o.$$.fragment,e),y(F.$$.fragment,e),y(k.$$.fragment,e),y(V.$$.fragment,e),y(U.$$.fragment,e),y(C.$$.fragment,e),y(H.$$.fragment,e),y(x.$$.fragment,e),y($.$$.fragment,e),y(W.$$.fragment,e),y(S.$$.fragment,e),y(Q.$$.fragment,e),$e=!1},d(e){e&&(a(u),a(i),a(m),a(n),a(f),a(ee),a(B),a(te),a(Z),a(ae),a(G),a(le),a(se),a(_),a(ne),a(oe),a(ie),a(X),a(re),a(j),a(pe),a(z),a(me),a(ce),a(I),a(de),a(R),a(ue),a(he),a(v),a(fe),a(E),a(Me),a(Je),a(Te),a(N),a(we),a(Y),a(ye),a(be),a(q),a(ge),a(je),a(Ue),a(L),a(Ie),a(ve),a(A)),a(s),b(o,e),b(F,e),b(k,e),b(V,e),b(U,e),b(C,e),b(H,e),b(x,e),b($,e),b(W,e),b(S,e),b(Q,e)}}}const mt='{"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 De(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Tt extends Ke{constructor(s){super(),Oe(this,s,ct,pt,Ae,{})}}export{Tt as component};
