import{s as ye,n as Ne,o as Ce}from"../chunks/scheduler.5f3e6389.js";import{S as we,i as Pe,e as i,s as a,c,h as De,a as s,d as o,b as r,f as h,g as u,j as M,k as x,l as t,m as b,n as l,t as p,o as g,p as _}from"../chunks/index.373ab25c.js";import{C as Le,H as Qe}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.84e44acb.js";import{D as H}from"../chunks/Docstring.5071903f.js";function Fe(be){let f,S,G,j,R,K,Q,B,y,J,n,N,ie,E,ze="Handles the ONNX Runtime quantization process for models shared on huggingface.co/models.",se,z,C,me,I,ve="Computes the quantization ranges.",de,v,w,ce,k,Te="Performs the calibration step and computes the quantization ranges.",ue,T,P,le,W,$e="Instantiates a <code>ORTQuantizer</code> from an ONNX model file or an <code>ORTModel</code>.",pe,$,D,ge,U,Oe="Creates the calibration <code>datasets.Dataset</code> to use for the post-training static quantization calibration step.",_e,O,L,fe,V,qe="Performs the calibration step and collects the quantization ranges without computing them.",he,q,F,xe,A,Re="Quantizes a model given the optimization specifications defined in <code>quantization_config</code>.",Y,X,Z;return R=new Le({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),Q=new Qe({props:{title:"Quantization",local:"quantization",headingTag:"h1"}}),y=new Qe({props:{title:"ORTQuantizer",local:"optimum.onnxruntime.ORTQuantizer",headingTag:"h2"}}),N=new H({props:{name:"class optimum.onnxruntime.ORTQuantizer",anchor:"optimum.onnxruntime.ORTQuantizer",parameters:[{name:"onnx_model_path",val:": Path"},{name:"config",val:": PretrainedConfig | None = None"}],source:"https://github.com/huggingface/optimum-onnx/blob/vr_79/optimum/onnxruntime/quantization.py#L85"}}),C=new H({props:{name:"compute_ranges",anchor:"optimum.onnxruntime.ORTQuantizer.compute_ranges",parameters:[],source:"https://github.com/huggingface/optimum-onnx/blob/vr_79/optimum/onnxruntime/quantization.py#L261",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>The dictionary mapping the nodes name to their quantization ranges.</p>
`}}),w=new H({props:{name:"fit",anchor:"optimum.onnxruntime.ORTQuantizer.fit",parameters:[{name:"dataset",val:": Dataset"},{name:"calibration_config",val:": CalibrationConfig"},{name:"onnx_augmented_model_name",val:": str | Path = 'augmented_model.onnx'"},{name:"operators_to_quantize",val:": list[str] | None = None"},{name:"batch_size",val:": int = 1"},{name:"use_external_data_format",val:": bool = False"},{name:"use_gpu",val:": bool = False"},{name:"force_symmetric_range",val:": bool = False"}],parametersDescription:[{anchor:"optimum.onnxruntime.ORTQuantizer.fit.dataset",description:`<strong>dataset</strong> (<code>Dataset</code>) &#x2014;
The dataset to use when performing the calibration step.`,name:"dataset"},{anchor:"optimum.onnxruntime.ORTQuantizer.fit.calibration_config",description:`<strong>calibration_config</strong> (<code>~CalibrationConfig</code>) &#x2014;
The configuration containing the parameters related to the calibration step.`,name:"calibration_config"},{anchor:"optimum.onnxruntime.ORTQuantizer.fit.onnx_augmented_model_name",description:`<strong>onnx_augmented_model_name</strong> (<code>Union[str, Path]</code>, defaults to <code>&quot;augmented_model.onnx&quot;</code>) &#x2014;
The path used to save the augmented model used to collect the quantization ranges.`,name:"onnx_augmented_model_name"},{anchor:"optimum.onnxruntime.ORTQuantizer.fit.operators_to_quantize",description:`<strong>operators_to_quantize</strong> (<code>Optional[List[str]]</code>, defaults to <code>None</code>) &#x2014;
List of the operators types to quantize.`,name:"operators_to_quantize"},{anchor:"optimum.onnxruntime.ORTQuantizer.fit.batch_size",description:`<strong>batch_size</strong> (<code>int</code>, defaults to 1) &#x2014;
The batch size to use when collecting the quantization ranges values.`,name:"batch_size"},{anchor:"optimum.onnxruntime.ORTQuantizer.fit.use_external_data_format",description:`<strong>use_external_data_format</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether to use external data format to store model which size is &gt;= 2Gb.`,name:"use_external_data_format"},{anchor:"optimum.onnxruntime.ORTQuantizer.fit.use_gpu",description:`<strong>use_gpu</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether to use the GPU when collecting the quantization ranges values.`,name:"use_gpu"},{anchor:"optimum.onnxruntime.ORTQuantizer.fit.force_symmetric_range",description:`<strong>force_symmetric_range</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether to make the quantization ranges symmetric.`,name:"force_symmetric_range"}],source:"https://github.com/huggingface/optimum-onnx/blob/vr_79/optimum/onnxruntime/quantization.py#L159",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>The dictionary mapping the nodes name to their quantization ranges.</p>
`}}),P=new H({props:{name:"from_pretrained",anchor:"optimum.onnxruntime.ORTQuantizer.from_pretrained",parameters:[{name:"model_or_path",val:": ORTModel | str | Path"},{name:"file_name",val:": str | None = None"}],parametersDescription:[{anchor:"optimum.onnxruntime.ORTQuantizer.from_pretrained.model_or_path",description:`<strong>model_or_path</strong> (<code>Union[ORTModel, str, Path]</code>) &#x2014;
Can be either:<ul>
<li>A path to a saved exported ONNX Intermediate Representation (IR) model, e.g., \`./my_model_directory/.</li>
<li>Or an <code>ORTModelForXX</code> class, e.g., <code>ORTModelForQuestionAnswering</code>.</li>
</ul>`,name:"model_or_path"},{anchor:"optimum.onnxruntime.ORTQuantizer.from_pretrained.file_name(Optional[str],",description:`<strong>file_name(<code>Optional[str]</code>,</strong> defaults to <code>None</code>) &#x2014;
Overwrites the default model file name from <code>&quot;model.onnx&quot;</code> to <code>file_name</code>.
This allows you to load different model files from the same repository or directory.`,name:"file_name(Optional[str],"}],source:"https://github.com/huggingface/optimum-onnx/blob/vr_79/optimum/onnxruntime/quantization.py#L111",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>An instance of <code>ORTQuantizer</code>.</p>
`}}),D=new H({props:{name:"get_calibration_dataset",anchor:"optimum.onnxruntime.ORTQuantizer.get_calibration_dataset",parameters:[{name:"dataset_name",val:": str"},{name:"num_samples",val:": int = 100"},{name:"dataset_config_name",val:": str | None = None"},{name:"dataset_split",val:": str | None = None"},{name:"preprocess_function",val:": Callable | None = None"},{name:"preprocess_batch",val:": bool = True"},{name:"seed",val:": int = 2016"},{name:"token",val:": bool | str | None = None"}],parametersDescription:[{anchor:"optimum.onnxruntime.ORTQuantizer.get_calibration_dataset.dataset_name",description:`<strong>dataset_name</strong> (<code>str</code>) &#x2014;
The dataset repository name on the Hugging Face Hub or path to a local directory containing data files
to load to use for the calibration step.`,name:"dataset_name"},{anchor:"optimum.onnxruntime.ORTQuantizer.get_calibration_dataset.num_samples",description:`<strong>num_samples</strong> (<code>int</code>, defaults to 100) &#x2014;
The maximum number of samples composing the calibration dataset.`,name:"num_samples"},{anchor:"optimum.onnxruntime.ORTQuantizer.get_calibration_dataset.dataset_config_name",description:`<strong>dataset_config_name</strong> (<code>Optional[str]</code>, defaults to <code>None</code>) &#x2014;
The name of the dataset configuration.`,name:"dataset_config_name"},{anchor:"optimum.onnxruntime.ORTQuantizer.get_calibration_dataset.dataset_split",description:`<strong>dataset_split</strong> (<code>Optional[str]</code>, defaults to <code>None</code>) &#x2014;
Which split of the dataset to use to perform the calibration step.`,name:"dataset_split"},{anchor:"optimum.onnxruntime.ORTQuantizer.get_calibration_dataset.preprocess_function",description:`<strong>preprocess_function</strong> (<code>Optional[Callable]</code>, defaults to <code>None</code>) &#x2014;
Processing function to apply to each example after loading dataset.`,name:"preprocess_function"},{anchor:"optimum.onnxruntime.ORTQuantizer.get_calibration_dataset.preprocess_batch",description:`<strong>preprocess_batch</strong> (<code>bool</code>, defaults to <code>True</code>) &#x2014;
Whether the <code>preprocess_function</code> should be batched.`,name:"preprocess_batch"},{anchor:"optimum.onnxruntime.ORTQuantizer.get_calibration_dataset.seed",description:`<strong>seed</strong> (<code>int</code>, defaults to 2016) &#x2014;
The random seed to use when shuffling the calibration dataset.`,name:"seed"},{anchor:"optimum.onnxruntime.ORTQuantizer.get_calibration_dataset.token",description:`<strong>token</strong> (<code>Optional[Union[bool,str]]</code>, defaults to <code>None</code>) &#x2014;
The token to use as HTTP bearer authorization for remote files. If <code>True</code>, will use the token generated
when running <code>huggingface-cli login</code> (stored in <code>huggingface_hub.constants.HF_TOKEN_PATH</code>).`,name:"token"}],source:"https://github.com/huggingface/optimum-onnx/blob/vr_79/optimum/onnxruntime/quantization.py#L416",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>The calibration <code>datasets.Dataset</code> to use for the post-training static quantization calibration
step.</p>
`}}),L=new H({props:{name:"partial_fit",anchor:"optimum.onnxruntime.ORTQuantizer.partial_fit",parameters:[{name:"dataset",val:": Dataset"},{name:"calibration_config",val:": CalibrationConfig"},{name:"onnx_augmented_model_name",val:": str | Path = 'augmented_model.onnx'"},{name:"operators_to_quantize",val:": list[str] | None = None"},{name:"batch_size",val:": int = 1"},{name:"use_external_data_format",val:": bool = False"},{name:"use_gpu",val:": bool = False"},{name:"force_symmetric_range",val:": bool = False"}],parametersDescription:[{anchor:"optimum.onnxruntime.ORTQuantizer.partial_fit.dataset",description:`<strong>dataset</strong> (<code>Dataset</code>) &#x2014;
The dataset to use when performing the calibration step.`,name:"dataset"},{anchor:"optimum.onnxruntime.ORTQuantizer.partial_fit.calibration_config",description:`<strong>calibration_config</strong> (<code>CalibrationConfig</code>) &#x2014;
The configuration containing the parameters related to the calibration step.`,name:"calibration_config"},{anchor:"optimum.onnxruntime.ORTQuantizer.partial_fit.onnx_augmented_model_name",description:`<strong>onnx_augmented_model_name</strong> (<code>Union[str, Path]</code>, defaults to <code>&quot;augmented_model.onnx&quot;</code>) &#x2014;
The path used to save the augmented model used to collect the quantization ranges.`,name:"onnx_augmented_model_name"},{anchor:"optimum.onnxruntime.ORTQuantizer.partial_fit.operators_to_quantize",description:`<strong>operators_to_quantize</strong> (<code>Optional[List[str]]</code>, defaults to <code>None</code>) &#x2014;
List of the operators types to quantize.`,name:"operators_to_quantize"},{anchor:"optimum.onnxruntime.ORTQuantizer.partial_fit.batch_size",description:`<strong>batch_size</strong> (<code>int</code>, defaults to 1) &#x2014;
The batch size to use when collecting the quantization ranges values.`,name:"batch_size"},{anchor:"optimum.onnxruntime.ORTQuantizer.partial_fit.use_external_data_format",description:`<strong>use_external_data_format</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether uto se external data format to store model which size is &gt;= 2Gb.`,name:"use_external_data_format"},{anchor:"optimum.onnxruntime.ORTQuantizer.partial_fit.use_gpu",description:`<strong>use_gpu</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether to use the GPU when collecting the quantization ranges values.`,name:"use_gpu"},{anchor:"optimum.onnxruntime.ORTQuantizer.partial_fit.force_symmetric_range",description:`<strong>force_symmetric_range</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether to make the quantization ranges symmetric.`,name:"force_symmetric_range"}],source:"https://github.com/huggingface/optimum-onnx/blob/vr_79/optimum/onnxruntime/quantization.py#L212"}}),F=new H({props:{name:"quantize",anchor:"optimum.onnxruntime.ORTQuantizer.quantize",parameters:[{name:"quantization_config",val:": QuantizationConfig"},{name:"save_dir",val:": str | Path"},{name:"file_suffix",val:": str | None = 'quantized'"},{name:"calibration_tensors_range",val:": dict[str, tuple[float, float]] | None = None"},{name:"use_external_data_format",val:": bool = False"},{name:"preprocessor",val:": QuantizationPreprocessor | None = None"}],parametersDescription:[{anchor:"optimum.onnxruntime.ORTQuantizer.quantize.quantization_config",description:`<strong>quantization_config</strong> (<code>QuantizationConfig</code>) &#x2014;
The configuration containing the parameters related to quantization.`,name:"quantization_config"},{anchor:"optimum.onnxruntime.ORTQuantizer.quantize.save_dir",description:`<strong>save_dir</strong> (<code>Union[str, Path]</code>) &#x2014;
The directory where the quantized model should be saved.`,name:"save_dir"},{anchor:"optimum.onnxruntime.ORTQuantizer.quantize.file_suffix",description:`<strong>file_suffix</strong> (<code>Optional[str]</code>, defaults to <code>&quot;quantized&quot;</code>) &#x2014;
The file_suffix used to save the quantized model.`,name:"file_suffix"},{anchor:"optimum.onnxruntime.ORTQuantizer.quantize.calibration_tensors_range",description:`<strong>calibration_tensors_range</strong> (<code>Optional[Dict[str, Tuple[float, float]]]</code>, defaults to <code>None</code>) &#x2014;
The dictionary mapping the nodes name to their quantization ranges, used and required only when applying static quantization.`,name:"calibration_tensors_range"},{anchor:"optimum.onnxruntime.ORTQuantizer.quantize.use_external_data_format",description:`<strong>use_external_data_format</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether to use external data format to store model which size is &gt;= 2Gb.`,name:"use_external_data_format"},{anchor:"optimum.onnxruntime.ORTQuantizer.quantize.preprocessor",description:`<strong>preprocessor</strong> (<code>Optional[QuantizationPreprocessor]</code>, defaults to <code>None</code>) &#x2014;
The preprocessor to use to collect the nodes to include or exclude from quantization.`,name:"preprocessor"}],source:"https://github.com/huggingface/optimum-onnx/blob/vr_79/optimum/onnxruntime/quantization.py#L279",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>The path of the resulting quantized model.</p>
`}}),{c(){f=i("meta"),S=a(),G=i("p"),j=a(),c(R.$$.fragment),K=a(),c(Q.$$.fragment),B=a(),c(y.$$.fragment),J=a(),n=i("div"),c(N.$$.fragment),ie=a(),E=i("p"),E.textContent=ze,se=a(),z=i("div"),c(C.$$.fragment),me=a(),I=i("p"),I.textContent=ve,de=a(),v=i("div"),c(w.$$.fragment),ce=a(),k=i("p"),k.textContent=Te,ue=a(),T=i("div"),c(P.$$.fragment),le=a(),W=i("p"),W.innerHTML=$e,pe=a(),$=i("div"),c(D.$$.fragment),ge=a(),U=i("p"),U.innerHTML=Oe,_e=a(),O=i("div"),c(L.$$.fragment),fe=a(),V=i("p"),V.textContent=qe,he=a(),q=i("div"),c(F.$$.fragment),xe=a(),A=i("p"),A.innerHTML=Re,Y=a(),X=i("p"),this.h()},l(e){const d=De("svelte-u9bgzb",document.head);f=s(d,"META",{name:!0,content:!0}),d.forEach(o),S=r(e),G=s(e,"P",{}),h(G).forEach(o),j=r(e),u(R.$$.fragment,e),K=r(e),u(Q.$$.fragment,e),B=r(e),u(y.$$.fragment,e),J=r(e),n=s(e,"DIV",{class:!0});var m=h(n);u(N.$$.fragment,m),ie=r(m),E=s(m,"P",{"data-svelte-h":!0}),M(E)!=="svelte-1tiz3jr"&&(E.textContent=ze),se=r(m),z=s(m,"DIV",{class:!0});var ee=h(z);u(C.$$.fragment,ee),me=r(ee),I=s(ee,"P",{"data-svelte-h":!0}),M(I)!=="svelte-1183xvy"&&(I.textContent=ve),ee.forEach(o),de=r(m),v=s(m,"DIV",{class:!0});var te=h(v);u(w.$$.fragment,te),ce=r(te),k=s(te,"P",{"data-svelte-h":!0}),M(k)!=="svelte-1tzjvze"&&(k.textContent=Te),te.forEach(o),ue=r(m),T=s(m,"DIV",{class:!0});var ne=h(T);u(P.$$.fragment,ne),le=r(ne),W=s(ne,"P",{"data-svelte-h":!0}),M(W)!=="svelte-p4e5on"&&(W.innerHTML=$e),ne.forEach(o),pe=r(m),$=s(m,"DIV",{class:!0});var oe=h($);u(D.$$.fragment,oe),ge=r(oe),U=s(oe,"P",{"data-svelte-h":!0}),M(U)!=="svelte-1xfi4es"&&(U.innerHTML=Oe),oe.forEach(o),_e=r(m),O=s(m,"DIV",{class:!0});var ae=h(O);u(L.$$.fragment,ae),fe=r(ae),V=s(ae,"P",{"data-svelte-h":!0}),M(V)!=="svelte-g6p4yh"&&(V.textContent=qe),ae.forEach(o),he=r(m),q=s(m,"DIV",{class:!0});var re=h(q);u(F.$$.fragment,re),xe=r(re),A=s(re,"P",{"data-svelte-h":!0}),M(A)!=="svelte-4dslow"&&(A.innerHTML=Re),re.forEach(o),m.forEach(o),Y=r(e),X=s(e,"P",{}),h(X).forEach(o),this.h()},h(){x(f,"name","hf:doc:metadata"),x(f,"content",Me),x(z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),x(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),x(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),x($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),x(O,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),x(q,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),x(n,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,d){t(document.head,f),b(e,S,d),b(e,G,d),b(e,j,d),l(R,e,d),b(e,K,d),l(Q,e,d),b(e,B,d),l(y,e,d),b(e,J,d),b(e,n,d),l(N,n,null),t(n,ie),t(n,E),t(n,se),t(n,z),l(C,z,null),t(z,me),t(z,I),t(n,de),t(n,v),l(w,v,null),t(v,ce),t(v,k),t(n,ue),t(n,T),l(P,T,null),t(T,le),t(T,W),t(n,pe),t(n,$),l(D,$,null),t($,ge),t($,U),t(n,_e),t(n,O),l(L,O,null),t(O,fe),t(O,V),t(n,he),t(n,q),l(F,q,null),t(q,xe),t(q,A),b(e,Y,d),b(e,X,d),Z=!0},p:Ne,i(e){Z||(p(R.$$.fragment,e),p(Q.$$.fragment,e),p(y.$$.fragment,e),p(N.$$.fragment,e),p(C.$$.fragment,e),p(w.$$.fragment,e),p(P.$$.fragment,e),p(D.$$.fragment,e),p(L.$$.fragment,e),p(F.$$.fragment,e),Z=!0)},o(e){g(R.$$.fragment,e),g(Q.$$.fragment,e),g(y.$$.fragment,e),g(N.$$.fragment,e),g(C.$$.fragment,e),g(w.$$.fragment,e),g(P.$$.fragment,e),g(D.$$.fragment,e),g(L.$$.fragment,e),g(F.$$.fragment,e),Z=!1},d(e){e&&(o(S),o(G),o(j),o(K),o(B),o(J),o(n),o(Y),o(X)),o(f),_(R,e),_(Q,e),_(y,e),_(N),_(C),_(w),_(P),_(D),_(L),_(F)}}}const Me='{"title":"Quantization","local":"quantization","sections":[{"title":"ORTQuantizer","local":"optimum.onnxruntime.ORTQuantizer","sections":[],"depth":2}],"depth":1}';function He(be){return Ce(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ue extends we{constructor(f){super(),Pe(this,f,He,Fe,ye,{})}}export{Ue as component};
