import{s as be,o as Te,n as we}from"../chunks/scheduler.5f3e6389.js";import{S as ge,i as je,e as s,s as a,c as M,h as Je,a as o,d as l,b as n,f as fe,g as r,j as p,k as Lt,l as Ce,m as i,n as d,t as c,o as y,p as u}from"../chunks/index.373ab25c.js";import{T as ze}from"../chunks/Tip.3e202241.js";import{C as Ge,H as nt}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.315d5a08.js";import{C as h}from"../chunks/CodeBlock.fbe06bf8.js";function Ze(ot){let m,T="Attention fusion is designed for right-side padding for BERT-like architectures (eg. BERT, RoBERTa, VIT, etc.) and for left-side padding for generative models (GPT-like). If you are not following the convention, please set <code>use_raw_attention_mask=True</code> to avoid potential accuracy issues but sacrifice the performance.";return{c(){m=s("p"),m.innerHTML=T},l(U){m=o(U,"P",{"data-svelte-h":!0}),p(m)!=="svelte-t2hyhe"&&(m.innerHTML=T)},m(U,at){i(U,m,at)},p:we,d(U){U&&l(m)}}}function We(ot){let m,T,U,at,w,pt,g,mt,j,Yt='🤗 Optimum provides an <code>optimum.onnxruntime</code> package that enables you to apply graph optimization on many model hosted on the 🤗 hub using the <a href="https://github.com/microsoft/onnxruntime/tree/master/onnxruntime/python/tools/transformers" rel="nofollow">ONNX Runtime</a> model optimization tool.',Mt,J,rt,C,Pt="The ONNX model can be directly optimized during the ONNX export using Optimum CLI, by passing the argument <code>--optimize {O1,O2,O3,O4}</code> in the CLI, for example:",dt,z,ct,G,qt="The optimization levels are:",yt,Z,Kt="<li>O1: basic general optimizations.</li> <li>O2: basic and extended general optimizations, transformers-specific fusions.</li> <li>O3: same as O2 with GELU approximation.</li> <li>O4: same as O3 with mixed precision (fp16, GPU-only, requires <code>--device cuda</code>).</li>",ut,W,Ut,v,Dt='ONNX models can be optimized with the <a href="/docs/optimum/v0.0.2/en/onnxruntime/package_reference/optimization#optimum.onnxruntime.ORTOptimizer">ORTOptimizer</a>. The class can be initialized using the <a href="/docs/optimum/v0.0.2/en/onnxruntime/package_reference/optimization#optimum.onnxruntime.ORTOptimizer.from_pretrained">from_pretrained()</a> method, which supports different checkpoint formats.',ht,I,te='<li>Using an already initialized <a href="/docs/optimum/v0.0.2/en/onnxruntime/package_reference/modeling#optimum.onnxruntime.ORTModel">ORTModel</a> class.</li>',ft,B,bt,f,ee="<li>Using a local ONNX model from a directory.</li>",Tt,R,wt,X,gt,_,le='The <a href="/docs/optimum/v0.0.2/en/onnxruntime/package_reference/configuration#optimum.onnxruntime.OptimizationConfig">OptimizationConfig</a> class allows to specify how the optimization should be performed by the <a href="/docs/optimum/v0.0.2/en/onnxruntime/package_reference/optimization#optimum.onnxruntime.ORTOptimizer">ORTOptimizer</a>.',jt,O,ie="In the optimization configuration, there are 4 possible optimization levels:",Jt,$,ae="<li><code>optimization_level=0</code>: to disable all optimizations</li> <li><code>optimization_level=1</code>: to enable basic optimizations such as constant folding or redundant node eliminations</li> <li><code>optimization_level=2</code>: to enable extended graph optimizations such as node fusions</li> <li><code>optimization_level=99</code>: to enable data layout optimizations</li>",Ct,x,ne=`Choosing a level enables the optimizations of that level, as well as the optimizations of all preceding levels.
More information <a href="https://onnxruntime.ai/docs/performance/graph-optimizations.html" rel="nofollow">here</a>.`,zt,k,se=`<code>enable_transformers_specific_optimizations=True</code> means that <code>transformers</code>-specific graph fusion and approximation are performed in addition to the ONNX Runtime optimizations described above.
Here is a list of the possible optimizations you can enable:`,Gt,N,oe="<li>Gelu fusion with <code>disable_gelu_fusion=False</code>,</li> <li>Layer Normalization fusion with <code>disable_layer_norm_fusion=False</code>,</li> <li>Attention fusion with <code>disable_attention_fusion=False</code>,</li> <li>SkipLayerNormalization fusion with <code>disable_skip_layer_norm_fusion=False</code>,</li> <li>Add Bias and SkipLayerNormalization fusion with <code>disable_bias_skip_layer_norm_fusion=False</code>,</li> <li>Add Bias and Gelu / FastGelu fusion with <code>disable_bias_gelu_fusion=False</code>,</li> <li>Gelu approximation with <code>enable_gelu_approximation=True</code>.</li>",Zt,b,Wt,V,pe='While <a href="/docs/optimum/v0.0.2/en/onnxruntime/package_reference/configuration#optimum.onnxruntime.OptimizationConfig">OptimizationConfig</a> gives you full control on how to do optimization, it can be hard to know what to enable / disable. Instead, you can use <a href="/docs/optimum/v0.0.2/en/onnxruntime/package_reference/configuration#optimum.onnxruntime.AutoOptimizationConfig">AutoOptimizationConfig</a> which provides four common optimization levels:',vt,S,me="<li>O1: basic general optimizations.</li> <li>O2: basic and extended general optimizations, transformers-specific fusions.</li> <li>O3: same as O2 with GELU approximation.</li> <li>O4: same as O3 with mixed precision (fp16, GPU-only).</li>",It,H,Me='Example: Loading a O2 <a href="/docs/optimum/v0.0.2/en/onnxruntime/package_reference/configuration#optimum.onnxruntime.OptimizationConfig">OptimizationConfig</a>',Bt,A,Rt,E,re="You can also specify custom argument that were not defined in the O2 configuration, for instance:",Xt,Q,_t,F,Ot,L,de='Below you will find an easy end-to-end example on how to optimize <a href="https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english" rel="nofollow">distilbert-base-uncased-finetuned-sst-2-english</a>.',$t,Y,xt,P,ce='Below you will find an easy end-to-end example on how to optimize a Seq2Seq model <a href="https://huggingface.co/sshleifer/distilbart-cnn-12-6" rel="nofollow">sshleifer/distilbart-cnn-12-6</a>.',kt,q,Nt,K,Vt,D,ye="The Optimum ONNX Runtime optimization tools can be used directly through Optimum command-line interface:",St,tt,Ht,et,ue="Optimizing an ONNX model can be done as follows:",At,lt,Et,it,Ue="This optimizes all the ONNX files in <code>onnx_model_location</code> with the basic general optimizations.",Qt,st,Ft;return w=new Ge({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),g=new nt({props:{title:"Optimization",local:"optimization",headingTag:"h1"}}),J=new nt({props:{title:"Optimizing a model during the ONNX export",local:"optimizing-a-model-during-the-onnx-export",headingTag:"h2"}}),z=new h({props:{code:"b3B0aW11bS1jbGklMjBleHBvcnQlMjBvbm54JTIwLS1tb2RlbCUyMGdwdDIlMjAtLW9wdGltaXplJTIwTzMlMjBncHQyX29ubnglMkY=",highlighted:'<span class="hljs-title">optimum</span>-cli ex<span class="hljs-keyword">port</span> onnx <span class="hljs-comment">--model gpt2 --optimize O3 gpt2_onnx/</span>',wrap:!1}}),W=new nt({props:{title:"Optimizing a model programmatically with ORTOptimizer",local:"optimizing-a-model-programmatically-with-ortoptimizer",headingTag:"h2"}}),B=new h({props:{code:"ZnJvbSUyMG9wdGltdW0ub25ueHJ1bnRpbWUlMjBpbXBvcnQlMjBPUlRPcHRpbWl6ZXIlMkMlMjBPUlRNb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyME9SVE1vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyb3B0aW11bSUyRmRpc3RpbGJlcnQtYmFzZS11bmNhc2VkLWZpbmV0dW5lZC1zc3QtMi1lbmdsaXNoJTIyJTBBKSUwQSUwQW9wdGltaXplciUyMCUzRCUyME9SVE9wdGltaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWwp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> optimum.onnxruntime <span class="hljs-keyword">import</span> ORTOptimizer, ORTModelForSequenceClassification

<span class="hljs-comment"># Loading ONNX Model from the Hub</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = ORTModelForSequenceClassification.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;optimum/distilbert-base-uncased-finetuned-sst-2-english&quot;</span>
<span class="hljs-meta">... </span>)

<span class="hljs-comment"># Create an optimizer from an ORTModelForXXX</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer = ORTOptimizer.from_pretrained(model)`,wrap:!1}}),R=new h({props:{code:"ZnJvbSUyMG9wdGltdW0ub25ueHJ1bnRpbWUlMjBpbXBvcnQlMjBPUlRPcHRpbWl6ZXIlMEElMEFvcHRpbWl6ZXIlMjAlM0QlMjBPUlRPcHRpbWl6ZXIuZnJvbV9wcmV0cmFpbmVkKCUyMnBhdGglMkZ0byUyRm1vZGVsJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> optimum.onnxruntime <span class="hljs-keyword">import</span> ORTOptimizer

<span class="hljs-comment"># This assumes a model.onnx exists in path/to/model</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer = ORTOptimizer.from_pretrained(<span class="hljs-string">&quot;path/to/model&quot;</span>)`,wrap:!1}}),X=new nt({props:{title:"Optimization Configuration",local:"optimization-configuration",headingTag:"h3"}}),b=new ze({props:{$$slots:{default:[Ze]},$$scope:{ctx:ot}}}),A=new h({props:{code:"ZnJvbSUyMG9wdGltdW0ub25ueHJ1bnRpbWUlMjBpbXBvcnQlMjBBdXRvT3B0aW1pemF0aW9uQ29uZmlnJTBBb3B0aW1pemF0aW9uX2NvbmZpZyUyMCUzRCUyMEF1dG9PcHRpbWl6YXRpb25Db25maWcuTzIoKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> optimum.onnxruntime <span class="hljs-keyword">import</span> AutoOptimizationConfig
<span class="hljs-meta">&gt;&gt;&gt; </span>optimization_config = AutoOptimizationConfig.O2()`,wrap:!1}}),Q=new h({props:{code:"ZnJvbSUyMG9wdGltdW0ub25ueHJ1bnRpbWUlMjBpbXBvcnQlMjBBdXRvT3B0aW1pemF0aW9uQ29uZmlnJTBBb3B0aW1pemF0aW9uX2NvbmZpZyUyMCUzRCUyMEF1dG9PcHRpbWl6YXRpb25Db25maWcuTzIoZGlzYWJsZV9lbWJlZF9sYXllcl9ub3JtX2Z1c2lvbiUzREZhbHNlKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> optimum.onnxruntime <span class="hljs-keyword">import</span> AutoOptimizationConfig
<span class="hljs-meta">&gt;&gt;&gt; </span>optimization_config = AutoOptimizationConfig.O2(disable_embed_layer_norm_fusion=<span class="hljs-literal">False</span>)`,wrap:!1}}),F=new nt({props:{title:"Optimization examples",local:"optimization-examples",headingTag:"h3"}}),Y=new h({props:{code:"ZnJvbSUyMG9wdGltdW0ub25ueHJ1bnRpbWUlMjBpbXBvcnQlMjAoJTBBJTIwJTIwJTIwJTIwQXV0b09wdGltaXphdGlvbkNvbmZpZyUyQyUyME9SVE9wdGltaXplciUyQyUyME9SVE1vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSklMEElMEFtb2RlbF9pZCUyMCUzRCUyMCUyMmRpc3RpbGJlcnQtYmFzZS11bmNhc2VkLWZpbmV0dW5lZC1zc3QtMi1lbmdsaXNoJTIyJTBBc2F2ZV9kaXIlMjAlM0QlMjAlMjJkaXN0aWxiZXJ0X29wdGltaXplZCUyMiUwQSUwQSUyMyUyMExvYWQlMjBhJTIwUHlUb3JjaCUyMG1vZGVsJTIwYW5kJTIwZXhwb3J0JTIwaXQlMjB0byUyMHRoZSUyME9OTlglMjBmb3JtYXQlMEFtb2RlbCUyMCUzRCUyME9SVE1vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbi5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQlMkMlMjBleHBvcnQlM0RUcnVlKSUwQSUwQSUyMyUyMENyZWF0ZSUyMHRoZSUyMG9wdGltaXplciUwQW9wdGltaXplciUyMCUzRCUyME9SVE9wdGltaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWwpJTBBJTBBJTIzJTIwRGVmaW5lJTIwdGhlJTIwb3B0aW1pemF0aW9uJTIwc3RyYXRlZ3klMjBieSUyMGNyZWF0aW5nJTIwdGhlJTIwYXBwcm9wcmlhdGUlMjBjb25maWd1cmF0aW9uJTBBb3B0aW1pemF0aW9uX2NvbmZpZyUyMCUzRCUyMEF1dG9PcHRpbWl6YXRpb25Db25maWcuTzIoKSUwQSUwQSUyMyUyME9wdGltaXplJTIwdGhlJTIwbW9kZWwlMEFvcHRpbWl6ZXIub3B0aW1pemUoc2F2ZV9kaXIlM0RzYXZlX2RpciUyQyUyMG9wdGltaXphdGlvbl9jb25maWclM0RvcHRpbWl6YXRpb25fY29uZmlnKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> optimum.onnxruntime <span class="hljs-keyword">import</span> (
<span class="hljs-meta">... </span>    AutoOptimizationConfig, ORTOptimizer, ORTModelForSequenceClassification
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model_id = <span class="hljs-string">&quot;distilbert-base-uncased-finetuned-sst-2-english&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>save_dir = <span class="hljs-string">&quot;distilbert_optimized&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Load a PyTorch model and export it to the ONNX format</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = ORTModelForSequenceClassification.from_pretrained(model_id, export=<span class="hljs-literal">True</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Create the optimizer</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer = ORTOptimizer.from_pretrained(model)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Define the optimization strategy by creating the appropriate configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>optimization_config = AutoOptimizationConfig.O2()

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Optimize the model</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer.optimize(save_dir=save_dir, optimization_config=optimization_config)`,wrap:!1}}),q=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEFmcm9tJTIwb3B0aW11bS5vbm54cnVudGltZSUyMGltcG9ydCUyMCUyME9wdGltaXphdGlvbkNvbmZpZyUyQyUyME9SVE9wdGltaXplciUyQyUyME9SV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b25fY29uZmlnKSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkKSUwQW9wdGltaXplZF9tb2RlbCUyMCUzRCUyME9SVE1vZGVsRm9yU2VxMlNlcUxNLmZyb21fcHJldHJhaW5lZChzYXZlX2RpciklMEF0b2tlbnMlMjAlM0QlMjB0b2tlbml6ZXIoJTIyVGhpcyUyMGlzJTIwYSUyMHNhbXBsZSUyMGlucHV0JTIyJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEFvdXRwdXRzJTIwJTNEJTIwb3B0aW1pemVkX21vZGVsLmdlbmVyYXRlKCoqdG9rZW5zKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> optimum.onnxruntime <span class="hljs-keyword">import</span>  OptimizationConfig, ORTOptimizer, ORTModelForSeq2SeqLM

<span class="hljs-meta">&gt;&gt;&gt; </span>model_id = <span class="hljs-string">&quot;sshleifer/distilbart-cnn-12-6&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>save_dir = <span class="hljs-string">&quot;distilbart_optimized&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Load a PyTorch model and export it to the ONNX format</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = ORTModelForSeq2SeqLM.from_pretrained(model_id, export=<span class="hljs-literal">True</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Create the optimizer</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer = ORTOptimizer.from_pretrained(model)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Define the optimization strategy by creating the appropriate configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>optimization_config = OptimizationConfig(
<span class="hljs-meta">... </span>    optimization_level=<span class="hljs-number">2</span>,
<span class="hljs-meta">... </span>    enable_transformers_specific_optimizations=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    optimize_for_gpu=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Optimize the model</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer.optimize(save_dir=save_dir, optimization_config=optimization_config)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(model_id)
<span class="hljs-meta">&gt;&gt;&gt; </span>optimized_model = ORTModelForSeq2SeqLM.from_pretrained(save_dir)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokens = tokenizer(<span class="hljs-string">&quot;This is a sample input&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = optimized_model.generate(**tokens)`,wrap:!1}}),K=new nt({props:{title:"Optimizing a model with Optimum CLI",local:"optimizing-a-model-with-optimum-cli",headingTag:"h2"}}),tt=new h({props:{code:"b3B0aW11bS1jbGklMjBvbm54cnVudGltZSUyMG9wdGltaXplJTIwLS1oZWxwJTBBdXNhZ2UlM0ElMjBvcHRpbXVtLWNsaSUyMCUzQ2NvbW1hbmQlM0UlMjAlNUIlM0NhcmdzJTNFJTVEJTIwb25ueHJ1bnRpbWUlMjBvcHRpbWl6ZSUyMCU1Qi1oJTVEJTIwLS1vbm54X21vZGVsJTIwT05OWF9NT0RFTCUyMC1vJTIwT1VUUFVUJTIwKC1PMSUyMCU3QyUyMC1PMiUyMCU3QyUyMC1PMyUyMCU3QyUyMC1PNCUyMCU3QyUyMC1jJTIwQ09ORklHKSUwQSUwQW9wdGlvbnMlM0ElMEElMjAlMjAtaCUyQyUyMC0taGVscCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHNob3clMjB0aGlzJTIwaGVsc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lMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBQYXRoJTIwdG8lMjB0aGUlMjBkaXJlY3RvcnklMjB3aGVyZSUyMHRvJTIwc3RvcmUlMjBnZW5lcmF0ZWQlMjBPTk5YJTIwbW9kZWwu",highlighted:`optimum-cli onnxruntime optimize --<span class="hljs-built_in">help</span>
usage: optimum-cli &lt;<span class="hljs-built_in">command</span>&gt; [&lt;args&gt;] onnxruntime optimize [-h] --onnx_model ONNX_MODEL -o OUTPUT (-O1 | -O2 | -O3 | -O4 | -c CONFIG)

options:
  -h, --<span class="hljs-built_in">help</span>            show this <span class="hljs-built_in">help</span> message and <span class="hljs-built_in">exit</span>
  -O1                   Basic general optimizations (see: https://huggingface.co/docs/optimum/onnxruntime/usage_guides/optimization <span class="hljs-keyword">for</span> more details).
  -O2                   Basic and extended general optimizations, transformers-specific fusions (see: https://huggingface.co/docs/optimum/onnxruntime/usage_guides/optimization <span class="hljs-keyword">for</span> more
                        details).
  -O3                   Same as O2 with Gelu approximation (see: https://huggingface.co/docs/optimum/onnxruntime/usage_guides/optimization <span class="hljs-keyword">for</span> more details).
  -O4                   Same as O3 with mixed precision (see: https://huggingface.co/docs/optimum/onnxruntime/usage_guides/optimization <span class="hljs-keyword">for</span> more details).
  -c CONFIG, --config CONFIG
                        \`ORTConfig\` file to use to optimize the model.

Required arguments:
  --onnx_model ONNX_MODEL
                        Path to the repository <span class="hljs-built_in">where</span> the ONNX models to optimize are located.
  -o OUTPUT, --output OUTPUT
                        Path to the directory <span class="hljs-built_in">where</span> to store generated ONNX model.`,wrap:!1}}),lt=new h({props:{code:"JTIwb3B0aW11bS1jbGklMjBvbm54cnVudGltZSUyMG9wdGltaXplJTIwLS1vbm54X21vZGVsJTIwb25ueF9tb2RlbF9sb2NhdGlvbiUyRiUyMC1PMSUyMC1vJTIwb3B0aW1pemVkX21vZGVsJTJG",highlighted:" optimum-cli onnxruntime optimize --onnx_model onnx_model_location/ -O1 -o optimized_model/",wrap:!1}}),{c(){m=s("meta"),T=a(),U=s("p"),at=a(),M(w.$$.fragment),pt=a(),M(g.$$.fragment),mt=a(),j=s("p"),j.innerHTML=Yt,Mt=a(),M(J.$$.fragment),rt=a(),C=s("p"),C.innerHTML=Pt,dt=a(),M(z.$$.fragment),ct=a(),G=s("p"),G.textContent=qt,yt=a(),Z=s("ul"),Z.innerHTML=Kt,ut=a(),M(W.$$.fragment),Ut=a(),v=s("p"),v.innerHTML=Dt,ht=a(),I=s("ol"),I.innerHTML=te,ft=a(),M(B.$$.fragment),bt=a(),f=s("ol"),f.innerHTML=ee,Tt=a(),M(R.$$.fragment),wt=a(),M(X.$$.fragment),gt=a(),_=s("p"),_.innerHTML=le,jt=a(),O=s("p"),O.textContent=ie,Jt=a(),$=s("ul"),$.innerHTML=ae,Ct=a(),x=s("p"),x.innerHTML=ne,zt=a(),k=s("p"),k.innerHTML=se,Gt=a(),N=s("ul"),N.innerHTML=oe,Zt=a(),M(b.$$.fragment),Wt=a(),V=s("p"),V.innerHTML=pe,vt=a(),S=s("ul"),S.innerHTML=me,It=a(),H=s("p"),H.innerHTML=Me,Bt=a(),M(A.$$.fragment),Rt=a(),E=s("p"),E.textContent=re,Xt=a(),M(Q.$$.fragment),_t=a(),M(F.$$.fragment),Ot=a(),L=s("p"),L.innerHTML=de,$t=a(),M(Y.$$.fragment),xt=a(),P=s("p"),P.innerHTML=ce,kt=a(),M(q.$$.fragment),Nt=a(),M(K.$$.fragment),Vt=a(),D=s("p"),D.textContent=ye,St=a(),M(tt.$$.fragment),Ht=a(),et=s("p"),et.textContent=ue,At=a(),M(lt.$$.fragment),Et=a(),it=s("p"),it.innerHTML=Ue,Qt=a(),st=s("p"),this.h()},l(t){const e=Je("svelte-u9bgzb",document.head);m=o(e,"META",{name:!0,content:!0}),e.forEach(l),T=n(t),U=o(t,"P",{}),fe(U).forEach(l),at=n(t),r(w.$$.fragment,t),pt=n(t),r(g.$$.fragment,t),mt=n(t),j=o(t,"P",{"data-svelte-h":!0}),p(j)!=="svelte-d5af43"&&(j.innerHTML=Yt),Mt=n(t),r(J.$$.fragment,t),rt=n(t),C=o(t,"P",{"data-svelte-h":!0}),p(C)!=="svelte-o2at96"&&(C.innerHTML=Pt),dt=n(t),r(z.$$.fragment,t),ct=n(t),G=o(t,"P",{"data-svelte-h":!0}),p(G)!=="svelte-1o0731n"&&(G.textContent=qt),yt=n(t),Z=o(t,"UL",{"data-svelte-h":!0}),p(Z)!=="svelte-1r3jeqb"&&(Z.innerHTML=Kt),ut=n(t),r(W.$$.fragment,t),Ut=n(t),v=o(t,"P",{"data-svelte-h":!0}),p(v)!=="svelte-7selz1"&&(v.innerHTML=Dt),ht=n(t),I=o(t,"OL",{"data-svelte-h":!0}),p(I)!=="svelte-7x24py"&&(I.innerHTML=te),ft=n(t),r(B.$$.fragment,t),bt=n(t),f=o(t,"OL",{start:!0,"data-svelte-h":!0}),p(f)!=="svelte-s0fljy"&&(f.innerHTML=ee),Tt=n(t),r(R.$$.fragment,t),wt=n(t),r(X.$$.fragment,t),gt=n(t),_=o(t,"P",{"data-svelte-h":!0}),p(_)!=="svelte-c7c4d6"&&(_.innerHTML=le),jt=n(t),O=o(t,"P",{"data-svelte-h":!0}),p(O)!=="svelte-1dpoxba"&&(O.textContent=ie),Jt=n(t),$=o(t,"UL",{"data-svelte-h":!0}),p($)!=="svelte-o45rsi"&&($.innerHTML=ae),Ct=n(t),x=o(t,"P",{"data-svelte-h":!0}),p(x)!=="svelte-1dyt65t"&&(x.innerHTML=ne),zt=n(t),k=o(t,"P",{"data-svelte-h":!0}),p(k)!=="svelte-4bipj7"&&(k.innerHTML=se),Gt=n(t),N=o(t,"UL",{"data-svelte-h":!0}),p(N)!=="svelte-19j884u"&&(N.innerHTML=oe),Zt=n(t),r(b.$$.fragment,t),Wt=n(t),V=o(t,"P",{"data-svelte-h":!0}),p(V)!=="svelte-160iae0"&&(V.innerHTML=pe),vt=n(t),S=o(t,"UL",{"data-svelte-h":!0}),p(S)!=="svelte-1okf1dh"&&(S.innerHTML=me),It=n(t),H=o(t,"P",{"data-svelte-h":!0}),p(H)!=="svelte-1sdq3gv"&&(H.innerHTML=Me),Bt=n(t),r(A.$$.fragment,t),Rt=n(t),E=o(t,"P",{"data-svelte-h":!0}),p(E)!=="svelte-12zpihs"&&(E.textContent=re),Xt=n(t),r(Q.$$.fragment,t),_t=n(t),r(F.$$.fragment,t),Ot=n(t),L=o(t,"P",{"data-svelte-h":!0}),p(L)!=="svelte-np22ir"&&(L.innerHTML=de),$t=n(t),r(Y.$$.fragment,t),xt=n(t),P=o(t,"P",{"data-svelte-h":!0}),p(P)!=="svelte-33ogqd"&&(P.innerHTML=ce),kt=n(t),r(q.$$.fragment,t),Nt=n(t),r(K.$$.fragment,t),Vt=n(t),D=o(t,"P",{"data-svelte-h":!0}),p(D)!=="svelte-k6kyac"&&(D.textContent=ye),St=n(t),r(tt.$$.fragment,t),Ht=n(t),et=o(t,"P",{"data-svelte-h":!0}),p(et)!=="svelte-1ucr6zy"&&(et.textContent=ue),At=n(t),r(lt.$$.fragment,t),Et=n(t),it=o(t,"P",{"data-svelte-h":!0}),p(it)!=="svelte-1e94zh6"&&(it.innerHTML=Ue),Qt=n(t),st=o(t,"P",{}),fe(st).forEach(l),this.h()},h(){Lt(m,"name","hf:doc:metadata"),Lt(m,"content",ve),Lt(f,"start","2")},m(t,e){Ce(document.head,m),i(t,T,e),i(t,U,e),i(t,at,e),d(w,t,e),i(t,pt,e),d(g,t,e),i(t,mt,e),i(t,j,e),i(t,Mt,e),d(J,t,e),i(t,rt,e),i(t,C,e),i(t,dt,e),d(z,t,e),i(t,ct,e),i(t,G,e),i(t,yt,e),i(t,Z,e),i(t,ut,e),d(W,t,e),i(t,Ut,e),i(t,v,e),i(t,ht,e),i(t,I,e),i(t,ft,e),d(B,t,e),i(t,bt,e),i(t,f,e),i(t,Tt,e),d(R,t,e),i(t,wt,e),d(X,t,e),i(t,gt,e),i(t,_,e),i(t,jt,e),i(t,O,e),i(t,Jt,e),i(t,$,e),i(t,Ct,e),i(t,x,e),i(t,zt,e),i(t,k,e),i(t,Gt,e),i(t,N,e),i(t,Zt,e),d(b,t,e),i(t,Wt,e),i(t,V,e),i(t,vt,e),i(t,S,e),i(t,It,e),i(t,H,e),i(t,Bt,e),d(A,t,e),i(t,Rt,e),i(t,E,e),i(t,Xt,e),d(Q,t,e),i(t,_t,e),d(F,t,e),i(t,Ot,e),i(t,L,e),i(t,$t,e),d(Y,t,e),i(t,xt,e),i(t,P,e),i(t,kt,e),d(q,t,e),i(t,Nt,e),d(K,t,e),i(t,Vt,e),i(t,D,e),i(t,St,e),d(tt,t,e),i(t,Ht,e),i(t,et,e),i(t,At,e),d(lt,t,e),i(t,Et,e),i(t,it,e),i(t,Qt,e),i(t,st,e),Ft=!0},p(t,[e]){const he={};e&2&&(he.$$scope={dirty:e,ctx:t}),b.$set(he)},i(t){Ft||(c(w.$$.fragment,t),c(g.$$.fragment,t),c(J.$$.fragment,t),c(z.$$.fragment,t),c(W.$$.fragment,t),c(B.$$.fragment,t),c(R.$$.fragment,t),c(X.$$.fragment,t),c(b.$$.fragment,t),c(A.$$.fragment,t),c(Q.$$.fragment,t),c(F.$$.fragment,t),c(Y.$$.fragment,t),c(q.$$.fragment,t),c(K.$$.fragment,t),c(tt.$$.fragment,t),c(lt.$$.fragment,t),Ft=!0)},o(t){y(w.$$.fragment,t),y(g.$$.fragment,t),y(J.$$.fragment,t),y(z.$$.fragment,t),y(W.$$.fragment,t),y(B.$$.fragment,t),y(R.$$.fragment,t),y(X.$$.fragment,t),y(b.$$.fragment,t),y(A.$$.fragment,t),y(Q.$$.fragment,t),y(F.$$.fragment,t),y(Y.$$.fragment,t),y(q.$$.fragment,t),y(K.$$.fragment,t),y(tt.$$.fragment,t),y(lt.$$.fragment,t),Ft=!1},d(t){t&&(l(T),l(U),l(at),l(pt),l(mt),l(j),l(Mt),l(rt),l(C),l(dt),l(ct),l(G),l(yt),l(Z),l(ut),l(Ut),l(v),l(ht),l(I),l(ft),l(bt),l(f),l(Tt),l(wt),l(gt),l(_),l(jt),l(O),l(Jt),l($),l(Ct),l(x),l(zt),l(k),l(Gt),l(N),l(Zt),l(Wt),l(V),l(vt),l(S),l(It),l(H),l(Bt),l(Rt),l(E),l(Xt),l(_t),l(Ot),l(L),l($t),l(xt),l(P),l(kt),l(Nt),l(Vt),l(D),l(St),l(Ht),l(et),l(At),l(Et),l(it),l(Qt),l(st)),l(m),u(w,t),u(g,t),u(J,t),u(z,t),u(W,t),u(B,t),u(R,t),u(X,t),u(b,t),u(A,t),u(Q,t),u(F,t),u(Y,t),u(q,t),u(K,t),u(tt,t),u(lt,t)}}}const ve='{"title":"Optimization","local":"optimization","sections":[{"title":"Optimizing a model during the ONNX export","local":"optimizing-a-model-during-the-onnx-export","sections":[],"depth":2},{"title":"Optimizing a model programmatically with ORTOptimizer","local":"optimizing-a-model-programmatically-with-ortoptimizer","sections":[{"title":"Optimization Configuration","local":"optimization-configuration","sections":[],"depth":3},{"title":"Optimization examples","local":"optimization-examples","sections":[],"depth":3}],"depth":2},{"title":"Optimizing a model with Optimum CLI","local":"optimizing-a-model-with-optimum-cli","sections":[],"depth":2}],"depth":1}';function Ie(ot){return Te(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class $e extends ge{constructor(m){super(),je(this,m,Ie,We,be,{})}}export{$e as component};
