import{S as pt,i as st,s as dt,e as n,k as p,w as R,t as s,M as lt,c as r,d as o,m as d,a as i,x as T,h as l,b as m,G as e,g as P,y as w,L as ht,q as E,o as N,B as k,v as ct}from"../../chunks/vendor-hf-doc-builder.js";import{D as q}from"../../chunks/Docstring-hf-doc-builder.js";import{I as mt}from"../../chunks/IconCopyLink-hf-doc-builder.js";function ut(Be){let f,oe,_,x,G,L,_e,B,ge,ne,u,xe,J,ve,ze,D,Oe,be,re,g,v,W,U,$e,j,ye,ie,a,I,Re,K,Te,Pe,z,C,we,A,Ee,Q,Ne,ke,Le,O,X,De,S,Ue,Y,Ie,Ce,Ae,b,H,Xe,Z,Se,He,$,V,Ve,ee,Fe,Me,y,F,qe,te,Ge,ae;return L=new mt({}),U=new mt({}),I=new q({props:{name:"class optimum.onnxruntime.ORTOptimizer",anchor:"optimum.onnxruntime.ORTOptimizer",parameters:[{name:"preprocessor",val:": typing.Union[transformers.models.auto.feature_extraction_auto.AutoFeatureExtractor, transformers.models.auto.processing_auto.AutoProcessor, transformers.models.auto.tokenization_auto.AutoTokenizer]"},{name:"model",val:": PreTrainedModel"},{name:"feature",val:": str = 'default'"},{name:"opset",val:": typing.Optional[int] = None"}],source:"https://github.com/huggingface/optimum/blob/vr_277/src/optimum/onnxruntime/optimization.py#L35"}}),C=new q({props:{name:"export",anchor:"optimum.onnxruntime.ORTOptimizer.export",parameters:[{name:"onnx_model_path",val:": typing.Union[str, os.PathLike]"},{name:"onnx_optimized_model_output_path",val:": typing.Union[str, os.PathLike]"},{name:"optimization_config",val:": OptimizationConfig"},{name:"use_external_data_format",val:": bool = False"}],parametersDescription:[{anchor:"optimum.onnxruntime.ORTOptimizer.export.onnx_model_path",description:`<strong>onnx_model_path</strong> (<code>Union[str, os.PathLike]</code>) &#x2014;
The path used to save the model exported to an ONNX Intermediate Representation (IR).`,name:"onnx_model_path"},{anchor:"optimum.onnxruntime.ORTOptimizer.export.onnx_optimized_model_output_path",description:`<strong>onnx_optimized_model_output_path</strong> (<code>Union[str, os.PathLike]</code>) &#x2014;
The path used to save the optimized model exported to an ONNX Intermediate Representation (IR).`,name:"onnx_optimized_model_output_path"},{anchor:"optimum.onnxruntime.ORTOptimizer.export.optimization_config",description:`<strong>optimization_config</strong> (<code>OptimizationConfig</code>) &#x2014;
The configuration containing the parameters related to optimization.`,name:"optimization_config"},{anchor:"optimum.onnxruntime.ORTOptimizer.export.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"}],source:"https://github.com/huggingface/optimum/blob/vr_277/src/optimum/onnxruntime/optimization.py#L91",returnDescription:`
<p>The path of the resulting optimized model.</p>
`}}),X=new q({props:{name:"from_pretrained",anchor:"optimum.onnxruntime.ORTOptimizer.from_pretrained",parameters:[{name:"model_name_or_path",val:": typing.Union[str, os.PathLike]"},{name:"feature",val:": str"},{name:"opset",val:": typing.Optional[int] = None"}],parametersDescription:[{anchor:"optimum.onnxruntime.ORTOptimizer.from_pretrained.model_name_or_path",description:`<strong>model_name_or_path</strong> (<code>Union[str, os.PathLike]</code>) &#x2014;
Repository name in the Hugging Face Hub or path to a local directory hosting the model.`,name:"model_name_or_path"},{anchor:"optimum.onnxruntime.ORTOptimizer.from_pretrained.feature",description:`<strong>feature</strong> (<code>str</code>) &#x2014;
Feature to use when exporting the model.`,name:"feature"},{anchor:"optimum.onnxruntime.ORTOptimizer.from_pretrained.opset",description:`<strong>opset</strong> (<code>int</code>, <em>optional</em>) &#x2014;
ONNX opset version to export the model with.`,name:"opset"}],source:"https://github.com/huggingface/optimum/blob/vr_277/src/optimum/onnxruntime/optimization.py#L40",returnDescription:`
<p>An instance of <code>ORTOptimizer</code>.</p>
`}}),H=new q({props:{name:"get_fused_operators",anchor:"optimum.onnxruntime.ORTOptimizer.get_fused_operators",parameters:[{name:"onnx_model_path",val:": typing.Union[str, os.PathLike]"}],parametersDescription:[{anchor:"optimum.onnxruntime.ORTOptimizer.get_fused_operators.onnx_model_path",description:`<strong>onnx_model_path</strong> (<code>Union[str, os.PathLike]</code>) &#x2014;
Path of the ONNX model.`,name:"onnx_model_path"}],source:"https://github.com/huggingface/optimum/blob/vr_277/src/optimum/onnxruntime/optimization.py#L161",returnDescription:`
<p>The dictionary mapping the name of the fused operators to their number of apparition in the model.</p>
`}}),V=new q({props:{name:"get_nodes_number_difference",anchor:"optimum.onnxruntime.ORTOptimizer.get_nodes_number_difference",parameters:[{name:"onnx_model_path",val:": typing.Union[str, os.PathLike]"},{name:"onnx_optimized_model_path",val:": typing.Union[str, os.PathLike]"}],parametersDescription:[{anchor:"optimum.onnxruntime.ORTOptimizer.get_nodes_number_difference.onnx_model_path",description:`<strong>onnx_model_path</strong> (<code>Union[str, os.PathLike]</code>) &#x2014;
Path of the ONNX model.`,name:"onnx_model_path"},{anchor:"optimum.onnxruntime.ORTOptimizer.get_nodes_number_difference.onnx_optimized_model_path",description:`<strong>onnx_optimized_model_path</strong> (<code>Union[str, os.PathLike]</code>) &#x2014;
Path of the optimized ONNX model.`,name:"onnx_optimized_model_path"}],source:"https://github.com/huggingface/optimum/blob/vr_277/src/optimum/onnxruntime/optimization.py#L180",returnDescription:`
<p>The difference in the number of nodes between the original and the optimized model.</p>
`}}),F=new q({props:{name:"get_operators_difference",anchor:"optimum.onnxruntime.ORTOptimizer.get_operators_difference",parameters:[{name:"onnx_model_path",val:": typing.Union[str, os.PathLike]"},{name:"onnx_optimized_model_path",val:": typing.Union[str, os.PathLike]"}],parametersDescription:[{anchor:"optimum.onnxruntime.ORTOptimizer.get_operators_difference.onnx_model_path",description:`<strong>onnx_model_path</strong> (<code>Union[str, os.PathLike]</code>) &#x2014;
Path of the ONNX model.`,name:"onnx_model_path"},{anchor:"optimum.onnxruntime.ORTOptimizer.get_operators_difference.onnx_optimized_model_path",description:`<strong>onnx_optimized_model_path</strong> (<code>Union[str, os.PathLike]</code>) &#x2014;
Path of the optimized ONNX model.`,name:"onnx_optimized_model_path"}],source:"https://github.com/huggingface/optimum/blob/vr_277/src/optimum/onnxruntime/optimization.py#L209",returnDescription:`
<p>The dictionary mapping the operators name to the difference in the number of corresponding nodes between the
original and the optimized model.</p>
`}}),{c(){f=n("meta"),oe=p(),_=n("h1"),x=n("a"),G=n("span"),R(L.$$.fragment),_e=p(),B=n("span"),ge=s("Optimization"),ne=p(),u=n("p"),xe=s("\u{1F917} Optimum provides an "),J=n("code"),ve=s("optimum.onnxruntime"),ze=s(" package that enables you to apply graph optimization on many model hosted on the \u{1F917} hub using the "),D=n("a"),Oe=s("ONNX Runtime"),be=s(" model optimization tool."),re=p(),g=n("h2"),v=n("a"),W=n("span"),R(U.$$.fragment),$e=p(),j=n("span"),ye=s("ORTOptimizer"),ie=p(),a=n("div"),R(I.$$.fragment),Re=p(),K=n("p"),Te=s("Handles the ONNX Runtime optimization process for models shared on huggingface.co/models."),Pe=p(),z=n("div"),R(C.$$.fragment),we=p(),A=n("p"),Ee=s("Optimize a model given the optimization specifications defined in "),Q=n("code"),Ne=s("optimization_config"),ke=s("."),Le=p(),O=n("div"),R(X.$$.fragment),De=p(),S=n("p"),Ue=s("Instantiate a "),Y=n("code"),Ie=s("ORTOptimizer"),Ce=s(" from a pretrained pytorch model and preprocessor."),Ae=p(),b=n("div"),R(H.$$.fragment),Xe=p(),Z=n("p"),Se=s("Compute the dictionary mapping the name of the fused operators to their number of apparition in the model."),He=p(),$=n("div"),R(V.$$.fragment),Ve=p(),ee=n("p"),Fe=s("Compute the difference in the number of nodes between the original and the optimized model."),Me=p(),y=n("div"),R(F.$$.fragment),qe=p(),te=n("p"),Ge=s(`Compute the dictionary mapping the operators name to the difference in the number of corresponding nodes between
the original and the optimized model.`),this.h()},l(t){const c=lt('[data-svelte="svelte-1phssyn"]',document.head);f=r(c,"META",{name:!0,content:!0}),c.forEach(o),oe=d(t),_=r(t,"H1",{class:!0});var me=i(_);x=r(me,"A",{id:!0,class:!0,href:!0});var Je=i(x);G=r(Je,"SPAN",{});var We=i(G);T(L.$$.fragment,We),We.forEach(o),Je.forEach(o),_e=d(me),B=r(me,"SPAN",{});var je=i(B);ge=l(je,"Optimization"),je.forEach(o),me.forEach(o),ne=d(t),u=r(t,"P",{});var M=i(u);xe=l(M,"\u{1F917} Optimum provides an "),J=r(M,"CODE",{});var Ke=i(J);ve=l(Ke,"optimum.onnxruntime"),Ke.forEach(o),ze=l(M," package that enables you to apply graph optimization on many model hosted on the \u{1F917} hub using the "),D=r(M,"A",{href:!0,rel:!0});var Qe=i(D);Oe=l(Qe,"ONNX Runtime"),Qe.forEach(o),be=l(M," model optimization tool."),M.forEach(o),re=d(t),g=r(t,"H2",{class:!0});var pe=i(g);v=r(pe,"A",{id:!0,class:!0,href:!0});var Ye=i(v);W=r(Ye,"SPAN",{});var Ze=i(W);T(U.$$.fragment,Ze),Ze.forEach(o),Ye.forEach(o),$e=d(pe),j=r(pe,"SPAN",{});var et=i(j);ye=l(et,"ORTOptimizer"),et.forEach(o),pe.forEach(o),ie=d(t),a=r(t,"DIV",{class:!0});var h=i(a);T(I.$$.fragment,h),Re=d(h),K=r(h,"P",{});var tt=i(K);Te=l(tt,"Handles the ONNX Runtime optimization process for models shared on huggingface.co/models."),tt.forEach(o),Pe=d(h),z=r(h,"DIV",{class:!0});var se=i(z);T(C.$$.fragment,se),we=d(se),A=r(se,"P",{});var de=i(A);Ee=l(de,"Optimize a model given the optimization specifications defined in "),Q=r(de,"CODE",{});var ot=i(Q);Ne=l(ot,"optimization_config"),ot.forEach(o),ke=l(de,"."),de.forEach(o),se.forEach(o),Le=d(h),O=r(h,"DIV",{class:!0});var le=i(O);T(X.$$.fragment,le),De=d(le),S=r(le,"P",{});var he=i(S);Ue=l(he,"Instantiate a "),Y=r(he,"CODE",{});var nt=i(Y);Ie=l(nt,"ORTOptimizer"),nt.forEach(o),Ce=l(he," from a pretrained pytorch model and preprocessor."),he.forEach(o),le.forEach(o),Ae=d(h),b=r(h,"DIV",{class:!0});var ce=i(b);T(H.$$.fragment,ce),Xe=d(ce),Z=r(ce,"P",{});var rt=i(Z);Se=l(rt,"Compute the dictionary mapping the name of the fused operators to their number of apparition in the model."),rt.forEach(o),ce.forEach(o),He=d(h),$=r(h,"DIV",{class:!0});var ue=i($);T(V.$$.fragment,ue),Ve=d(ue),ee=r(ue,"P",{});var it=i(ee);Fe=l(it,"Compute the difference in the number of nodes between the original and the optimized model."),it.forEach(o),ue.forEach(o),Me=d(h),y=r(h,"DIV",{class:!0});var fe=i(y);T(F.$$.fragment,fe),qe=d(fe),te=r(fe,"P",{});var at=i(te);Ge=l(at,`Compute the dictionary mapping the operators name to the difference in the number of corresponding nodes between
the original and the optimized model.`),at.forEach(o),fe.forEach(o),h.forEach(o),this.h()},h(){m(f,"name","hf:doc:metadata"),m(f,"content",JSON.stringify(ft)),m(x,"id","optimization"),m(x,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(x,"href","#optimization"),m(_,"class","relative group"),m(D,"href","https://github.com/microsoft/onnxruntime/tree/master/onnxruntime/python/tools/transformers"),m(D,"rel","nofollow"),m(v,"id","optimum.onnxruntime.ORTOptimizer"),m(v,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(v,"href","#optimum.onnxruntime.ORTOptimizer"),m(g,"class","relative group"),m(z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(O,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(b,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(y,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(a,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(t,c){e(document.head,f),P(t,oe,c),P(t,_,c),e(_,x),e(x,G),w(L,G,null),e(_,_e),e(_,B),e(B,ge),P(t,ne,c),P(t,u,c),e(u,xe),e(u,J),e(J,ve),e(u,ze),e(u,D),e(D,Oe),e(u,be),P(t,re,c),P(t,g,c),e(g,v),e(v,W),w(U,W,null),e(g,$e),e(g,j),e(j,ye),P(t,ie,c),P(t,a,c),w(I,a,null),e(a,Re),e(a,K),e(K,Te),e(a,Pe),e(a,z),w(C,z,null),e(z,we),e(z,A),e(A,Ee),e(A,Q),e(Q,Ne),e(A,ke),e(a,Le),e(a,O),w(X,O,null),e(O,De),e(O,S),e(S,Ue),e(S,Y),e(Y,Ie),e(S,Ce),e(a,Ae),e(a,b),w(H,b,null),e(b,Xe),e(b,Z),e(Z,Se),e(a,He),e(a,$),w(V,$,null),e($,Ve),e($,ee),e(ee,Fe),e(a,Me),e(a,y),w(F,y,null),e(y,qe),e(y,te),e(te,Ge),ae=!0},p:ht,i(t){ae||(E(L.$$.fragment,t),E(U.$$.fragment,t),E(I.$$.fragment,t),E(C.$$.fragment,t),E(X.$$.fragment,t),E(H.$$.fragment,t),E(V.$$.fragment,t),E(F.$$.fragment,t),ae=!0)},o(t){N(L.$$.fragment,t),N(U.$$.fragment,t),N(I.$$.fragment,t),N(C.$$.fragment,t),N(X.$$.fragment,t),N(H.$$.fragment,t),N(V.$$.fragment,t),N(F.$$.fragment,t),ae=!1},d(t){o(f),t&&o(oe),t&&o(_),k(L),t&&o(ne),t&&o(u),t&&o(re),t&&o(g),k(U),t&&o(ie),t&&o(a),k(I),k(C),k(X),k(H),k(V),k(F)}}}const ft={local:"optimization",sections:[{local:"optimum.onnxruntime.ORTOptimizer",title:"ORTOptimizer"}],title:"Optimization"};function _t(Be){return ct(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class zt extends pt{constructor(f){super();st(this,f,_t,ut,dt,{})}}export{zt as default,ft as metadata};
