import{S as hg,i as ug,s as mg,e as a,k as i,w as j,t as s,M as gg,c as l,d as o,m as p,a as r,x as C,h as n,b as v,G as e,g as d,y as D,q,o as L,B as A,v as _g,L as dg}from"../chunks/vendor-hf-doc-builder.js";import{T as Rt}from"../chunks/Tip-hf-doc-builder.js";import{I as Ve}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as X}from"../chunks/CodeBlock-hf-doc-builder.js";import{F as vg,M as cg}from"../chunks/Markdown-hf-doc-builder.js";function Eg(M){let c,$,m,E,w;return{c(){c=a("p"),$=s(`Once exported, a model can be optimized for inference via techniques such as
quantization and pruning. If you are interested in optimizing your models to run with
maximum efficiency, check out the `),m=a("a"),E=s(`\u{1F917} Optimum
library`),w=s("."),this.h()},l(_){c=l(_,"P",{});var x=r(c);$=n(x,`Once exported, a model can be optimized for inference via techniques such as
quantization and pruning. If you are interested in optimizing your models to run with
maximum efficiency, check out the `),m=l(x,"A",{href:!0,rel:!0});var b=r(m);E=n(b,`\u{1F917} Optimum
library`),b.forEach(o),w=n(x,"."),x.forEach(o),this.h()},h(){v(m,"href","https://github.com/huggingface/optimum"),v(m,"rel","nofollow")},m(_,x){d(_,c,x),e(c,$),e(c,m),e(m,E),e(c,w)},d(_){_&&o(c)}}}function $g(M){let c,$,m,E,w,_,x,b,k,T,I,y,O;return c=new X({props:{code:`from transformers import AutoTokenizer, AutoModelForSequenceClassification

# Load tokenizer and PyTorch weights form the Hub
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
pt_model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased")
# Save to disk
tokenizer.save_pretrained("local-pt-checkpoint")
pt_model.save_pretrained("local-pt-checkpoint")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Load tokenizer and PyTorch weights form the Hub</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>pt_model = AutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Save to disk</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.save_pretrained(<span class="hljs-string">&quot;local-pt-checkpoint&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>pt_model.save_pretrained(<span class="hljs-string">&quot;local-pt-checkpoint&quot;</span>)`}}),y=new X({props:{code:"python -m transformers.onnx --model=local-pt-checkpoint onnx/",highlighted:"python -m transformers.onnx --model=local-pt-checkpoint onnx/"}}),{c(){j(c.$$.fragment),$=i(),m=a("p"),E=s("Once the checkpoint is saved, we can export it to ONNX by pointing the "),w=a("code"),_=s("--model"),x=s(`
argument of the `),b=a("code"),k=s("transformers.onnx"),T=s(" package to the desired directory:"),I=i(),j(y.$$.fragment)},l(g){C(c.$$.fragment,g),$=p(g),m=l(g,"P",{});var N=r(m);E=n(N,"Once the checkpoint is saved, we can export it to ONNX by pointing the "),w=l(N,"CODE",{});var B=r(w);_=n(B,"--model"),B.forEach(o),x=n(N,`
argument of the `),b=l(N,"CODE",{});var R=r(b);k=n(R,"transformers.onnx"),R.forEach(o),T=n(N," package to the desired directory:"),N.forEach(o),I=p(g),C(y.$$.fragment,g)},m(g,N){D(c,g,N),d(g,$,N),d(g,m,N),e(m,E),e(m,w),e(w,_),e(m,x),e(m,b),e(b,k),e(m,T),d(g,I,N),D(y,g,N),O=!0},p:dg,i(g){O||(q(c.$$.fragment,g),q(y.$$.fragment,g),O=!0)},o(g){L(c.$$.fragment,g),L(y.$$.fragment,g),O=!1},d(g){A(c,g),g&&o($),g&&o(m),g&&o(I),A(y,g)}}}function wg(M){let c,$;return c=new cg({props:{$$slots:{default:[$g]},$$scope:{ctx:M}}}),{c(){j(c.$$.fragment)},l(m){C(c.$$.fragment,m)},m(m,E){D(c,m,E),$=!0},p(m,E){const w={};E&2&&(w.$$scope={dirty:E,ctx:m}),c.$set(w)},i(m){$||(q(c.$$.fragment,m),$=!0)},o(m){L(c.$$.fragment,m),$=!1},d(m){A(c,m)}}}function xg(M){let c,$,m,E,w,_,x,b,k,T,I,y,O;return c=new X({props:{code:`from transformers import AutoTokenizer, TFAutoModelForSequenceClassification

# Load tokenizer and TensorFlow weights from the Hub
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
tf_model = TFAutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased")
# Save to disk
tokenizer.save_pretrained("local-tf-checkpoint")
tf_model.save_pretrained("local-tf-checkpoint")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFAutoModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Load tokenizer and TensorFlow weights from the Hub</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tf_model = TFAutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Save to disk</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.save_pretrained(<span class="hljs-string">&quot;local-tf-checkpoint&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tf_model.save_pretrained(<span class="hljs-string">&quot;local-tf-checkpoint&quot;</span>)`}}),y=new X({props:{code:"python -m transformers.onnx --model=local-tf-checkpoint onnx/",highlighted:"python -m transformers.onnx --model=local-tf-checkpoint onnx/"}}),{c(){j(c.$$.fragment),$=i(),m=a("p"),E=s("Once the checkpoint is saved, we can export it to ONNX by pointing the "),w=a("code"),_=s("--model"),x=s(`
argument of the `),b=a("code"),k=s("transformers.onnx"),T=s(" package to the desired directory:"),I=i(),j(y.$$.fragment)},l(g){C(c.$$.fragment,g),$=p(g),m=l(g,"P",{});var N=r(m);E=n(N,"Once the checkpoint is saved, we can export it to ONNX by pointing the "),w=l(N,"CODE",{});var B=r(w);_=n(B,"--model"),B.forEach(o),x=n(N,`
argument of the `),b=l(N,"CODE",{});var R=r(b);k=n(R,"transformers.onnx"),R.forEach(o),T=n(N," package to the desired directory:"),N.forEach(o),I=p(g),C(y.$$.fragment,g)},m(g,N){D(c,g,N),d(g,$,N),d(g,m,N),e(m,E),e(m,w),e(w,_),e(m,x),e(m,b),e(b,k),e(m,T),d(g,I,N),D(y,g,N),O=!0},p:dg,i(g){O||(q(c.$$.fragment,g),q(y.$$.fragment,g),O=!0)},o(g){L(c.$$.fragment,g),L(y.$$.fragment,g),O=!1},d(g){A(c,g),g&&o($),g&&o(m),g&&o(I),A(y,g)}}}function bg(M){let c,$;return c=new cg({props:{$$slots:{default:[xg]},$$scope:{ctx:M}}}),{c(){j(c.$$.fragment)},l(m){C(c.$$.fragment,m)},m(m,E){D(c,m,E),$=!0},p(m,E){const w={};E&2&&(w.$$scope={dirty:E,ctx:m}),c.$set(w)},i(m){$||(q(c.$$.fragment,m),$=!0)},o(m){L(c.$$.fragment,m),$=!1},d(m){A(c,m)}}}function kg(M){let c,$,m,E,w,_,x,b;return{c(){c=a("p"),$=s("The features that have a "),m=a("code"),E=s("with-past"),w=s(" suffix (like "),_=a("code"),x=s("causal-lm-with-past"),b=s(`) correspond to
model classes with precomputed hidden states (key and values in the attention blocks)
that can be used for fast autoregressive decoding.`)},l(k){c=l(k,"P",{});var T=r(c);$=n(T,"The features that have a "),m=l(T,"CODE",{});var I=r(m);E=n(I,"with-past"),I.forEach(o),w=n(T," suffix (like "),_=l(T,"CODE",{});var y=r(_);x=n(y,"causal-lm-with-past"),y.forEach(o),b=n(T,`) correspond to
model classes with precomputed hidden states (key and values in the attention blocks)
that can be used for fast autoregressive decoding.`),T.forEach(o)},m(k,T){d(k,c,T),e(c,$),e(c,m),e(m,E),e(c,w),e(c,_),e(_,x),e(c,b)},d(k){k&&o(c)}}}function yg(M){let c,$,m,E,w,_,x,b,k,T,I;return{c(){c=a("p"),$=s("For "),m=a("code"),E=s("VisionEncoderDecoder"),w=s(` type models, the encoder and decoder parts are
exported separately as two ONNX files named `),_=a("code"),x=s("encoder_model.onnx"),b=s(" and "),k=a("code"),T=s("decoder_model.onnx"),I=s(" respectively.")},l(y){c=l(y,"P",{});var O=r(c);$=n(O,"For "),m=l(O,"CODE",{});var g=r(m);E=n(g,"VisionEncoderDecoder"),g.forEach(o),w=n(O,` type models, the encoder and decoder parts are
exported separately as two ONNX files named `),_=l(O,"CODE",{});var N=r(_);x=n(N,"encoder_model.onnx"),N.forEach(o),b=n(O," and "),k=l(O,"CODE",{});var B=r(k);T=n(B,"decoder_model.onnx"),B.forEach(o),I=n(O," respectively."),O.forEach(o)},m(y,O){d(y,c,O),e(c,$),e(c,m),e(m,E),e(c,w),e(c,_),e(_,x),e(c,b),e(c,k),e(k,T),e(c,I)},d(y){y&&o(c)}}}function Og(M){let c,$,m,E,w;return{c(){c=a("p"),$=s(`A good way to implement a custom ONNX configuration is to look at the existing
implementation in the `),m=a("code"),E=s("configuration_<model_name>.py"),w=s(" file of a similar architecture.")},l(_){c=l(_,"P",{});var x=r(c);$=n(x,`A good way to implement a custom ONNX configuration is to look at the existing
implementation in the `),m=l(x,"CODE",{});var b=r(m);E=n(b,"configuration_<model_name>.py"),b.forEach(o),w=n(x," file of a similar architecture."),x.forEach(o)},m(_,x){d(_,c,x),e(c,$),e(c,m),e(m,E),e(c,w)},d(_){_&&o(c)}}}function Tg(M){let c,$,m,E,w,_,x,b,k,T,I,y,O,g,N,B,R,Q,W,He,K,We,Ge;return{c(){c=a("p"),$=s("Notice that "),m=a("code"),E=s("inputs"),w=s(" property for "),_=a("code"),x=s("DistilBertOnnxConfig"),b=s(" returns an "),k=a("code"),T=s("OrderedDict"),I=s(`. This
ensures that the inputs are matched with their relative position within the
`),y=a("code"),O=s("PreTrainedModel.forward()"),g=s(` method when tracing the graph. We recommend using an
`),N=a("code"),B=s("OrderedDict"),R=s(" for the "),Q=a("code"),W=s("inputs"),He=s(" and "),K=a("code"),We=s("outputs"),Ge=s(` properties when implementing custom ONNX
configurations.`)},l(Z){c=l(Z,"P",{});var P=r(c);$=n(P,"Notice that "),m=l(P,"CODE",{});var Ft=r(m);E=n(Ft,"inputs"),Ft.forEach(o),w=n(P," property for "),_=l(P,"CODE",{});var Ye=r(_);x=n(Ye,"DistilBertOnnxConfig"),Ye.forEach(o),b=n(P," returns an "),k=l(P,"CODE",{});var J=r(k);T=n(J,"OrderedDict"),J.forEach(o),I=n(P,`. This
ensures that the inputs are matched with their relative position within the
`),y=l(P,"CODE",{});var St=r(y);O=n(St,"PreTrainedModel.forward()"),St.forEach(o),g=n(P,` method when tracing the graph. We recommend using an
`),N=l(P,"CODE",{});var fe=r(N);B=n(fe,"OrderedDict"),fe.forEach(o),R=n(P," for the "),Q=l(P,"CODE",{});var ve=r(Q);W=n(ve,"inputs"),ve.forEach(o),He=n(P," and "),K=l(P,"CODE",{});var zt=r(K);We=n(zt,"outputs"),zt.forEach(o),Ge=n(P,` properties when implementing custom ONNX
configurations.`),P.forEach(o)},m(Z,P){d(Z,c,P),e(c,$),e(c,m),e(m,E),e(c,w),e(c,_),e(_,x),e(c,b),e(c,k),e(k,T),e(c,I),e(c,y),e(y,O),e(c,g),e(c,N),e(N,B),e(c,R),e(c,Q),e(Q,W),e(c,He),e(c,K),e(K,We),e(c,Ge)},d(Z){Z&&o(c)}}}function Ng(M){let c,$,m,E,w,_,x,b;return{c(){c=a("p"),$=s("All of the base properties and methods associated with "),m=a("a"),E=s("OnnxConfig"),w=s(` and
the other configuration classes can be overridden if needed. Check out `),_=a("code"),x=s("BartOnnxConfig"),b=s(`
for an advanced example.`),this.h()},l(k){c=l(k,"P",{});var T=r(c);$=n(T,"All of the base properties and methods associated with "),m=l(T,"A",{href:!0});var I=r(m);E=n(I,"OnnxConfig"),I.forEach(o),w=n(T,` and
the other configuration classes can be overridden if needed. Check out `),_=l(T,"CODE",{});var y=r(_);x=n(y,"BartOnnxConfig"),y.forEach(o),b=n(T,`
for an advanced example.`),T.forEach(o),this.h()},h(){v(m,"href","/docs/transformers/v4.25.1/en/main_classes/onnx#transformers.onnx.OnnxConfig")},m(k,T){d(k,c,T),e(c,$),e(c,m),e(m,E),e(c,w),e(c,_),e(_,x),e(c,b)},d(k){k&&o(c)}}}function jg(M){let c,$,m,E,w,_,x,b,k,T,I;return{c(){c=a("p"),$=s(`If your model is larger than 2GB, you will see that many additional files are created
during the export. This is `),m=a("em"),E=s("expected"),w=s(" because ONNX uses "),_=a("a"),x=s(`Protocol
Buffers`),b=s(` to store the model and these
have a size limit of 2GB. See the `),k=a("a"),T=s(`ONNX
documentation`),I=s(` for
instructions on how to load models with external data.`),this.h()},l(y){c=l(y,"P",{});var O=r(c);$=n(O,`If your model is larger than 2GB, you will see that many additional files are created
during the export. This is `),m=l(O,"EM",{});var g=r(m);E=n(g,"expected"),g.forEach(o),w=n(O," because ONNX uses "),_=l(O,"A",{href:!0,rel:!0});var N=r(_);x=n(N,`Protocol
Buffers`),N.forEach(o),b=n(O,` to store the model and these
have a size limit of 2GB. See the `),k=l(O,"A",{href:!0,rel:!0});var B=r(k);T=n(B,`ONNX
documentation`),B.forEach(o),I=n(O,` for
instructions on how to load models with external data.`),O.forEach(o),this.h()},h(){v(_,"href","https://developers.google.com/protocol-buffers/"),v(_,"rel","nofollow"),v(k,"href","https://github.com/onnx/onnx/blob/master/docs/ExternalData.md"),v(k,"rel","nofollow")},m(y,O){d(y,c,O),e(c,$),e(c,m),e(m,E),e(c,w),e(c,_),e(_,x),e(c,b),e(c,k),e(k,T),e(c,I)},d(y){y&&o(c)}}}function Cg(M){let c,$,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,yl,co,Cc,Ol,re,It,Dc,aa,qc,Lc,Ac,ho,Ic,la,Pc,Mc,uo,Xc,ra,Bc,Tl,Fe,Rc,Pt,Fc,Sc,Nl;return _=new Ve({}),R=new Rt({props:{$$slots:{default:[Eg]},$$scope:{ctx:M}}}),Ke=new Ve({}),Je=new X({props:{code:"pip install transformers[onnx]",highlighted:"pip install transformers[onnx]"}}),Qe=new X({props:{code:`python -m transformers.onnx --help

usage: Hugging Face Transformers ONNX exporter [-h] -m MODEL [--feature {causal-lm, ...}] [--opset OPSET] [--atol ATOL] output

positional arguments:
  output                Path indicating where to store generated ONNX model.

optional arguments:
  -h, --help            show this help message and exit
  -m MODEL, --model MODEL
                        Model ID on huggingface.co or path on disk to load model from.
  --feature {causal-lm, ...}
                        The type of features to export the model with.
  --opset OPSET         ONNX opset version to export the model with.
  --atol ATOL           Absolute difference tolerance when validating the model.`,highlighted:`python -m transformers.onnx --<span class="hljs-built_in">help</span>

usage: Hugging Face Transformers ONNX exporter [-h] -m MODEL [--feature {causal-lm, ...}] [--opset OPSET] [--atol ATOL] output

positional arguments:
  output                Path indicating <span class="hljs-built_in">where</span> to store generated ONNX model.

optional arguments:
  -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>
  -m MODEL, --model MODEL
                        Model ID on huggingface.co or path on disk to load model from.
  --feature {causal-lm, ...}
                        The <span class="hljs-built_in">type</span> of features to <span class="hljs-built_in">export</span> the model with.
  --opset OPSET         ONNX opset version to <span class="hljs-built_in">export</span> the model with.
  --atol ATOL           Absolute difference tolerance when validating the model.`}}),Ze=new X({props:{code:"python -m transformers.onnx --model=distilbert-base-uncased onnx/",highlighted:"python -m transformers.onnx --model=distilbert-base-uncased onnx/"}}),et=new X({props:{code:`Validating ONNX model...
        -[\u2713] ONNX model output names match reference model ({'last_hidden_state'})
        - Validating ONNX Model output "last_hidden_state":
                -[\u2713] (2, 8, 768) matches (2, 8, 768)
                -[\u2713] all values close (atol: 1e-05)
All good, model saved at: onnx/model.onnx`,highlighted:`Validating ONNX model...
        -[\u2713] ONNX model output names match reference model ({<span class="hljs-string">&#x27;last_hidden_state&#x27;</span>})
        - Validating ONNX Model output <span class="hljs-string">&quot;last_hidden_state&quot;</span>:
                -[\u2713] (2, 8, 768) matches (2, 8, 768)
                -[\u2713] all values close (atol: 1e-05)
All good, model saved at: onnx/model.onnx`}}),st=new X({props:{code:`from transformers import AutoTokenizer
from onnxruntime import InferenceSession

tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
session = InferenceSession("onnx/model.onnx")
# ONNX Runtime expects NumPy arrays as input
inputs = tokenizer("Using DistilBERT with ONNX Runtime!", return_tensors="np")
outputs = session.run(output_names=["last_hidden_state"], input_feed=dict(inputs))`,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> onnxruntime <span class="hljs-keyword">import</span> InferenceSession

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>session = InferenceSession(<span class="hljs-string">&quot;onnx/model.onnx&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># ONNX Runtime expects NumPy arrays as input</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(<span class="hljs-string">&quot;Using DistilBERT with ONNX Runtime!&quot;</span>, return_tensors=<span class="hljs-string">&quot;np&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = session.run(output_names=[<span class="hljs-string">&quot;last_hidden_state&quot;</span>], input_feed=<span class="hljs-built_in">dict</span>(inputs))`}}),nt=new X({props:{code:`from transformers.models.distilbert import DistilBertConfig, DistilBertOnnxConfig

config = DistilBertConfig()
onnx_config = DistilBertOnnxConfig(config)
print(list(onnx_config.outputs.keys()))`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers.models.distilbert <span class="hljs-keyword">import</span> DistilBertConfig, DistilBertOnnxConfig

<span class="hljs-meta">&gt;&gt;&gt; </span>config = DistilBertConfig()
<span class="hljs-meta">&gt;&gt;&gt; </span>onnx_config = DistilBertOnnxConfig(config)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-built_in">list</span>(onnx_config.outputs.keys()))
[<span class="hljs-string">&quot;last_hidden_state&quot;</span>]`}}),lt=new X({props:{code:"python -m transformers.onnx --model=keras-io/transformers-qa onnx/",highlighted:"python -m transformers.onnx --model=keras-io/transformers-qa onnx/"}}),ke=new vg({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[bg],pytorch:[wg]},$$scope:{ctx:M}}}),rt=new Ve({}),Et=new X({props:{code:`from transformers.onnx.features import FeaturesManager

distilbert_features = list(FeaturesManager.get_supported_features_for_model_type("distilbert").keys())
print(distilbert_features)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers.onnx.features <span class="hljs-keyword">import</span> FeaturesManager

<span class="hljs-meta">&gt;&gt;&gt; </span>distilbert_features = <span class="hljs-built_in">list</span>(FeaturesManager.get_supported_features_for_model_type(<span class="hljs-string">&quot;distilbert&quot;</span>).keys())
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(distilbert_features)
[<span class="hljs-string">&quot;default&quot;</span>, <span class="hljs-string">&quot;masked-lm&quot;</span>, <span class="hljs-string">&quot;causal-lm&quot;</span>, <span class="hljs-string">&quot;sequence-classification&quot;</span>, <span class="hljs-string">&quot;token-classification&quot;</span>, <span class="hljs-string">&quot;question-answering&quot;</span>]`}}),$t=new X({props:{code:`python -m transformers.onnx --model=distilbert-base-uncased-finetuned-sst-2-english \\
                            --feature=sequence-classification onnx/`,highlighted:`python -m transformers.onnx --model=distilbert-base-uncased-finetuned-sst-2-english \\
                            --feature=sequence-classification onnx/`}}),wt=new X({props:{code:`Validating ONNX model...
        -[\u2713] ONNX model output names match reference model ({'logits'})
        - Validating ONNX Model output "logits":
                -[\u2713] (2, 2) matches (2, 2)
                -[\u2713] all values close (atol: 1e-05)
All good, model saved at: onnx/model.onnx`,highlighted:`Validating ONNX model...
        -[\u2713] ONNX model output names match reference model ({<span class="hljs-string">&#x27;logits&#x27;</span>})
        - Validating ONNX Model output <span class="hljs-string">&quot;logits&quot;</span>:
                -[\u2713] (2, 2) matches (2, 2)
                -[\u2713] all values close (atol: 1e-05)
All good, model saved at: onnx/model.onnx`}}),Ne=new Rt({props:{$$slots:{default:[kg]},$$scope:{ctx:M}}}),je=new Rt({props:{$$slots:{default:[yg]},$$scope:{ctx:M}}}),xt=new Ve({}),bt=new Ve({}),qe=new Rt({props:{$$slots:{default:[Og]},$$scope:{ctx:M}}}),kt=new X({props:{code:`from typing import Mapping, OrderedDict
from transformers.onnx import OnnxConfig


class DistilBertOnnxConfig(OnnxConfig):
    @property
    def inputs(self) -> Mapping[str, Mapping[int, str]]:
        return OrderedDict(
            [
                ("input_ids", {0: "batch", 1: "sequence"}),
                ("attention_mask", {0: "batch", 1: "sequence"}),
            ]
        )`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> Mapping, OrderedDict
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers.onnx <span class="hljs-keyword">import</span> OnnxConfig


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">class</span> <span class="hljs-title class_">DistilBertOnnxConfig</span>(<span class="hljs-title class_ inherited__">OnnxConfig</span>):
<span class="hljs-meta">... </span>    @<span class="hljs-built_in">property</span>
<span class="hljs-meta">... </span>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">inputs</span>(<span class="hljs-params">self</span>) -&gt; Mapping[<span class="hljs-built_in">str</span>, Mapping[<span class="hljs-built_in">int</span>, <span class="hljs-built_in">str</span>]]:
<span class="hljs-meta">... </span>        <span class="hljs-keyword">return</span> OrderedDict(
<span class="hljs-meta">... </span>            [
<span class="hljs-meta">... </span>                (<span class="hljs-string">&quot;input_ids&quot;</span>, {<span class="hljs-number">0</span>: <span class="hljs-string">&quot;batch&quot;</span>, <span class="hljs-number">1</span>: <span class="hljs-string">&quot;sequence&quot;</span>}),
<span class="hljs-meta">... </span>                (<span class="hljs-string">&quot;attention_mask&quot;</span>, {<span class="hljs-number">0</span>: <span class="hljs-string">&quot;batch&quot;</span>, <span class="hljs-number">1</span>: <span class="hljs-string">&quot;sequence&quot;</span>}),
<span class="hljs-meta">... </span>            ]
<span class="hljs-meta">... </span>        )`}}),Ae=new Rt({props:{$$slots:{default:[Tg]},$$scope:{ctx:M}}}),yt=new X({props:{code:`from transformers import AutoConfig

config = AutoConfig.from_pretrained("distilbert-base-uncased")
onnx_config = DistilBertOnnxConfig(config)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoConfig

<span class="hljs-meta">&gt;&gt;&gt; </span>config = AutoConfig.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>onnx_config = DistilBertOnnxConfig(config)`}}),Ot=new X({props:{code:"print(onnx_config.default_onnx_opset)",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(onnx_config.default_onnx_opset)
<span class="hljs-number">11</span>`}}),Tt=new X({props:{code:"print(onnx_config.outputs)",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(onnx_config.outputs)
OrderedDict([(<span class="hljs-string">&quot;last_hidden_state&quot;</span>, {<span class="hljs-number">0</span>: <span class="hljs-string">&quot;batch&quot;</span>, <span class="hljs-number">1</span>: <span class="hljs-string">&quot;sequence&quot;</span>})])`}}),Nt=new X({props:{code:`from transformers import AutoConfig

config = AutoConfig.from_pretrained("distilbert-base-uncased")
onnx_config_for_seq_clf = DistilBertOnnxConfig(config, task="sequence-classification")
print(onnx_config_for_seq_clf.outputs)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoConfig

<span class="hljs-meta">&gt;&gt;&gt; </span>config = AutoConfig.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>onnx_config_for_seq_clf = DistilBertOnnxConfig(config, task=<span class="hljs-string">&quot;sequence-classification&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(onnx_config_for_seq_clf.outputs)
OrderedDict([(<span class="hljs-string">&#x27;logits&#x27;</span>, {<span class="hljs-number">0</span>: <span class="hljs-string">&#x27;batch&#x27;</span>})])`}}),Ie=new Rt({props:{$$slots:{default:[Ng]},$$scope:{ctx:M}}}),jt=new Ve({}),Ct=new X({props:{code:`from pathlib import Path
from transformers.onnx import export
from transformers import AutoTokenizer, AutoModel

onnx_path = Path("model.onnx")
model_ckpt = "distilbert-base-uncased"
base_model = AutoModel.from_pretrained(model_ckpt)
tokenizer = AutoTokenizer.from_pretrained(model_ckpt)

onnx_inputs, onnx_outputs = export(tokenizer, base_model, onnx_config, onnx_config.default_onnx_opset, onnx_path)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> pathlib <span class="hljs-keyword">import</span> Path
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers.onnx <span class="hljs-keyword">import</span> export
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModel

<span class="hljs-meta">&gt;&gt;&gt; </span>onnx_path = Path(<span class="hljs-string">&quot;model.onnx&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model_ckpt = <span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>base_model = AutoModel.from_pretrained(model_ckpt)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(model_ckpt)

<span class="hljs-meta">&gt;&gt;&gt; </span>onnx_inputs, onnx_outputs = export(tokenizer, base_model, onnx_config, onnx_config.default_onnx_opset, onnx_path)`}}),Dt=new X({props:{code:`import onnx

onnx_model = onnx.load("model.onnx")
onnx.checker.check_model(onnx_model)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> onnx

<span class="hljs-meta">&gt;&gt;&gt; </span>onnx_model = onnx.load(<span class="hljs-string">&quot;model.onnx&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>onnx.checker.check_model(onnx_model)`}}),Me=new Rt({props:{$$slots:{default:[jg]},$$scope:{ctx:M}}}),qt=new Ve({}),Lt=new X({props:{code:`from transformers.onnx import validate_model_outputs

validate_model_outputs(
    onnx_config, tokenizer, base_model, onnx_path, onnx_outputs, onnx_config.atol_for_validation
)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers.onnx <span class="hljs-keyword">import</span> validate_model_outputs

<span class="hljs-meta">&gt;&gt;&gt; </span>validate_model_outputs(
<span class="hljs-meta">... </span>    onnx_config, tokenizer, base_model, onnx_path, onnx_outputs, onnx_config.atol_for_validation
<span class="hljs-meta">... </span>)`}}),At=new Ve({}),{c(){c=a("meta"),$=i(),m=a("h1"),E=a("a"),w=a("span"),j(_.$$.fragment),x=i(),b=a("span"),k=s("Export to ONNX"),T=i(),I=a("p"),y=s(`If you need to deploy \u{1F917} Transformers models in production environments, we recommend
exporting them to a serialized format that can be loaded and executed on specialized
runtimes and hardware. In this guide, we\u2019ll show you how to export \u{1F917} Transformers
models to `),O=a("a"),g=s("ONNX (Open Neural Network eXchange)"),N=s("."),B=i(),j(R.$$.fragment),Q=i(),W=a("p"),He=s(`ONNX is an open standard that defines a common set of operators and a common file format
to represent deep learning models in a wide variety of frameworks, including PyTorch and
TensorFlow. When a model is exported to the ONNX format, these operators are used to
construct a computational graph (often called an `),K=a("em"),We=s("intermediate representation"),Ge=s(`) which
represents the flow of data through the neural network.`),Z=i(),P=a("p"),Ft=s(`By exposing a graph with standardized operators and data types, ONNX makes it easy to
switch between frameworks. For example, a model trained in PyTorch can be exported to
ONNX format and then imported in TensorFlow (and vice versa).`),Ye=i(),J=a("p"),St=s("\u{1F917} Transformers provides a "),fe=a("a"),ve=a("code"),zt=s("transformers.onnx"),ar=s(` package that enables
you to convert model checkpoints to an ONNX graph by leveraging configuration objects.
These configuration objects come ready made for a number of model architectures, and are
designed to be easily extendable to other architectures.`),ha=i(),Vt=a("p"),lr=s("Ready-made configurations include the following architectures:"),ua=i(),h=a("ul"),bo=a("li"),rr=s("ALBERT"),ir=i(),ko=a("li"),pr=s("BART"),fr=i(),yo=a("li"),dr=s("BEiT"),cr=i(),Oo=a("li"),hr=s("BERT"),ur=i(),To=a("li"),mr=s("BigBird"),gr=i(),No=a("li"),_r=s("BigBird-Pegasus"),vr=i(),jo=a("li"),Er=s("Blenderbot"),$r=i(),Co=a("li"),wr=s("BlenderbotSmall"),xr=i(),Do=a("li"),br=s("BLOOM"),kr=i(),qo=a("li"),yr=s("CamemBERT"),Or=i(),Lo=a("li"),Tr=s("Chinese-CLIP"),Nr=i(),Ao=a("li"),jr=s("CLIP"),Cr=i(),Io=a("li"),Dr=s("CodeGen"),qr=i(),Po=a("li"),Lr=s("Conditional DETR"),Ar=i(),Mo=a("li"),Ir=s("ConvBERT"),Pr=i(),Xo=a("li"),Mr=s("ConvNeXT"),Xr=i(),Bo=a("li"),Br=s("Data2VecText"),Rr=i(),Ro=a("li"),Fr=s("Data2VecVision"),Sr=i(),Fo=a("li"),zr=s("DeBERTa"),Vr=i(),So=a("li"),Hr=s("DeBERTa-v2"),Wr=i(),zo=a("li"),Gr=s("DeiT"),Yr=i(),Vo=a("li"),Ur=s("DETR"),Kr=i(),Ho=a("li"),Jr=s("DistilBERT"),Qr=i(),Wo=a("li"),Zr=s("ELECTRA"),ei=i(),Go=a("li"),ti=s("ERNIE"),oi=i(),Yo=a("li"),si=s("FlauBERT"),ni=i(),Uo=a("li"),ai=s("GPT Neo"),li=i(),Ko=a("li"),ri=s("GPT-J"),ii=i(),Jo=a("li"),pi=s("GroupViT"),fi=i(),Qo=a("li"),di=s("I-BERT"),ci=i(),Zo=a("li"),hi=s("ImageGPT"),ui=i(),es=a("li"),mi=s("LayoutLM"),gi=i(),ts=a("li"),_i=s("LayoutLMv3"),vi=i(),os=a("li"),Ei=s("LeViT"),$i=i(),ss=a("li"),wi=s("Longformer"),xi=i(),ns=a("li"),bi=s("LongT5"),ki=i(),as=a("li"),yi=s("M2M100"),Oi=i(),ls=a("li"),Ti=s("Marian"),Ni=i(),rs=a("li"),ji=s("mBART"),Ci=i(),is=a("li"),Di=s("MobileBERT"),qi=i(),ps=a("li"),Li=s("MobileNetV1"),Ai=i(),fs=a("li"),Ii=s("MobileNetV2"),Pi=i(),ds=a("li"),Mi=s("MobileViT"),Xi=i(),cs=a("li"),Bi=s("MT5"),Ri=i(),hs=a("li"),Fi=s("OpenAI GPT-2"),Si=i(),us=a("li"),zi=s("OWL-ViT"),Vi=i(),ms=a("li"),Hi=s("Perceiver"),Wi=i(),gs=a("li"),Gi=s("PLBart"),Yi=i(),_s=a("li"),Ui=s("ResNet"),Ki=i(),vs=a("li"),Ji=s("RoBERTa"),Qi=i(),Es=a("li"),Zi=s("RoFormer"),ep=i(),$s=a("li"),tp=s("SegFormer"),op=i(),ws=a("li"),sp=s("SqueezeBERT"),np=i(),xs=a("li"),ap=s("Swin Transformer"),lp=i(),bs=a("li"),rp=s("T5"),ip=i(),ks=a("li"),pp=s("Table Transformer"),fp=i(),ys=a("li"),dp=s("Vision Encoder decoder"),cp=i(),Os=a("li"),hp=s("ViT"),up=i(),Ts=a("li"),mp=s("Whisper"),gp=i(),Ns=a("li"),_p=s("XLM"),vp=i(),js=a("li"),Ep=s("XLM-RoBERTa"),$p=i(),Cs=a("li"),wp=s("XLM-RoBERTa-XL"),xp=i(),Ds=a("li"),bp=s("YOLOS"),ma=i(),Ht=a("p"),kp=s("In the next two sections, we\u2019ll show you how to:"),ga=i(),Ee=a("ul"),Ue=a("li"),yp=s("Export a supported model using the "),qs=a("code"),Op=s("transformers.onnx"),Tp=s(" package."),Np=i(),Ls=a("li"),jp=s("Export a custom model for an unsupported architecture."),_a=i(),de=a("h2"),$e=a("a"),As=a("span"),j(Ke.$$.fragment),Cp=i(),Is=a("span"),Dp=s("Exporting a model to ONNX"),va=i(),Wt=a("p"),qp=s(`To export a \u{1F917} Transformers model to ONNX, you\u2019ll first need to install some extra
dependencies:`),Ea=i(),j(Je.$$.fragment),$a=i(),we=a("p"),Lp=s("The "),Ps=a("code"),Ap=s("transformers.onnx"),Ip=s(" package can then be used as a Python module:"),wa=i(),j(Qe.$$.fragment),xa=i(),Gt=a("p"),Pp=s("Exporting a checkpoint using a ready-made configuration can be done as follows:"),ba=i(),j(Ze.$$.fragment),ka=i(),Yt=a("p"),Mp=s("You should see the following logs:"),ya=i(),j(et.$$.fragment),Oa=i(),ee=a("p"),Xp=s("This exports an ONNX graph of the checkpoint defined by the "),Ms=a("code"),Bp=s("--model"),Rp=s(` argument. In this
example, it is `),Xs=a("code"),Fp=s("distilbert-base-uncased"),Sp=s(`, but it can be any checkpoint on the Hugging
Face Hub or one that\u2019s stored locally.`),Ta=i(),G=a("p"),zp=s("The resulting "),Bs=a("code"),Vp=s("model.onnx"),Hp=s(" file can then be run on one of the "),tt=a("a"),Wp=s(`many
accelerators`),Gp=s(` that support the ONNX
standard. For example, we can load and run the model with `),ot=a("a"),Yp=s(`ONNX
Runtime`),Up=s(" as follows:"),Na=i(),j(st.$$.fragment),ja=i(),xe=a("p"),Kp=s("The required output names (like "),Rs=a("code"),Jp=s('["last_hidden_state"]'),Qp=s(`) can be obtained by taking a
look at the ONNX configuration of each model. For example, for DistilBERT we have:`),Ca=i(),j(nt.$$.fragment),Da=i(),be=a("p"),Zp=s(`The process is identical for TensorFlow checkpoints on the Hub. For example, we can
export a pure TensorFlow checkpoint from the `),at=a("a"),ef=s(`Keras
organization`),tf=s(" as follows:"),qa=i(),j(lt.$$.fragment),La=i(),Ut=a("p"),of=s(`To export a model that\u2019s stored locally, you\u2019ll need to have the model\u2019s weights and
tokenizer files stored in a directory. For example, we can load and save a checkpoint as
follows:`),Aa=i(),j(ke.$$.fragment),Ia=i(),ce=a("h2"),ye=a("a"),Fs=a("span"),j(rt.$$.fragment),sf=i(),Ss=a("span"),nf=s("Selecting features for different model tasks"),Pa=i(),te=a("p"),af=s("Each ready-made configuration comes with a set of "),zs=a("em"),lf=s("features"),rf=s(` that enable you to export
models for different types of tasks. As shown in the table below, each feature is
associated with a different `),Vs=a("code"),pf=s("AutoClass"),ff=s(":"),Ma=i(),Oe=a("table"),Hs=a("thead"),it=a("tr"),Ws=a("th"),df=s("Feature"),cf=i(),Gs=a("th"),hf=s("Auto Class"),uf=i(),F=a("tbody"),pt=a("tr"),ft=a("td"),Ys=a("code"),mf=s("causal-lm"),gf=s(", "),Us=a("code"),_f=s("causal-lm-with-past"),vf=i(),Ks=a("td"),Js=a("code"),Ef=s("AutoModelForCausalLM"),$f=i(),dt=a("tr"),ct=a("td"),Qs=a("code"),wf=s("default"),xf=s(", "),Zs=a("code"),bf=s("default-with-past"),kf=i(),en=a("td"),tn=a("code"),yf=s("AutoModel"),Of=i(),ht=a("tr"),on=a("td"),sn=a("code"),Tf=s("masked-lm"),Nf=i(),nn=a("td"),an=a("code"),jf=s("AutoModelForMaskedLM"),Cf=i(),ut=a("tr"),ln=a("td"),rn=a("code"),Df=s("question-answering"),qf=i(),pn=a("td"),fn=a("code"),Lf=s("AutoModelForQuestionAnswering"),Af=i(),mt=a("tr"),gt=a("td"),dn=a("code"),If=s("seq2seq-lm"),Pf=s(", "),cn=a("code"),Mf=s("seq2seq-lm-with-past"),Xf=i(),hn=a("td"),un=a("code"),Bf=s("AutoModelForSeq2SeqLM"),Rf=i(),_t=a("tr"),mn=a("td"),gn=a("code"),Ff=s("sequence-classification"),Sf=i(),_n=a("td"),vn=a("code"),zf=s("AutoModelForSequenceClassification"),Vf=i(),vt=a("tr"),En=a("td"),$n=a("code"),Hf=s("token-classification"),Wf=i(),wn=a("td"),xn=a("code"),Gf=s("AutoModelForTokenClassification"),Xa=i(),Te=a("p"),Yf=s(`For each configuration, you can find the list of supported features via the
`),Kt=a("a"),Uf=s("FeaturesManager"),Kf=s(". For example, for DistilBERT we have:"),Ba=i(),j(Et.$$.fragment),Ra=i(),oe=a("p"),Jf=s("You can then pass one of these features to the "),bn=a("code"),Qf=s("--feature"),Zf=s(` argument in the
`),kn=a("code"),ed=s("transformers.onnx"),td=s(` package. For example, to export a text-classification model we can
pick a fine-tuned model from the Hub and run:`),Fa=i(),j($t.$$.fragment),Sa=i(),Jt=a("p"),od=s("This displays the following logs:"),za=i(),j(wt.$$.fragment),Va=i(),Y=a("p"),sd=s("Notice that in this case, the output names from the fine-tuned model are "),yn=a("code"),nd=s("logits"),ad=s(`
instead of the `),On=a("code"),ld=s("last_hidden_state"),rd=s(" we saw with the "),Tn=a("code"),id=s("distilbert-base-uncased"),pd=s(` checkpoint
earlier. This is expected since the fine-tuned model has a sequence classification head.`),Ha=i(),j(Ne.$$.fragment),Wa=i(),j(je.$$.fragment),Ga=i(),he=a("h2"),Ce=a("a"),Nn=a("span"),j(xt.$$.fragment),fd=i(),jn=a("span"),dd=s("Exporting a model for an unsupported architecture"),Ya=i(),Qt=a("p"),cd=s(`If you wish to export a model whose architecture is not natively supported by the
library, there are three main steps to follow:`),Ua=i(),se=a("ol"),Cn=a("li"),hd=s("Implement a custom ONNX configuration."),ud=i(),Dn=a("li"),md=s("Export the model to ONNX."),gd=i(),qn=a("li"),_d=s("Validate the outputs of the PyTorch and exported models."),Ka=i(),Zt=a("p"),vd=s(`In this section, we\u2019ll look at how DistilBERT was implemented to show what\u2019s involved
with each step.`),Ja=i(),ue=a("h3"),De=a("a"),Ln=a("span"),j(bt.$$.fragment),Ed=i(),An=a("span"),$d=s("Implementing a custom ONNX configuration"),Qa=i(),eo=a("p"),wd=s(`Let\u2019s start with the ONNX configuration object. We provide three abstract classes that
you should inherit from, depending on the type of model architecture you wish to export:`),Za=i(),ne=a("ul"),to=a("li"),xd=s("Encoder-based models inherit from "),oo=a("a"),bd=s("OnnxConfig"),kd=i(),so=a("li"),yd=s("Decoder-based models inherit from "),no=a("a"),Od=s("OnnxConfigWithPast"),Td=i(),ao=a("li"),Nd=s("Encoder-decoder models inherit from "),lo=a("a"),jd=s("OnnxSeq2SeqConfigWithPast"),el=i(),j(qe.$$.fragment),tl=i(),Le=a("p"),Cd=s(`Since DistilBERT is an encoder-based model, its configuration inherits from
`),In=a("code"),Dd=s("OnnxConfig"),qd=s(":"),ol=i(),j(kt.$$.fragment),sl=i(),z=a("p"),Ld=s("Every configuration object must implement the "),Pn=a("code"),Ad=s("inputs"),Id=s(` property and return a mapping,
where each key corresponds to an expected input, and each value indicates the axis of
that input. For DistilBERT, we can see that two inputs are required: `),Mn=a("code"),Pd=s("input_ids"),Md=s(` and
`),Xn=a("code"),Xd=s("attention_mask"),Bd=s(". These inputs have the same shape of "),Bn=a("code"),Rd=s("(batch_size, sequence_length)"),Fd=s(`
which is why we see the same axes used in the configuration.`),nl=i(),j(Ae.$$.fragment),al=i(),ro=a("p"),Sd=s(`Once you have implemented an ONNX configuration, you can instantiate it by providing the
base model\u2019s configuration as follows:`),ll=i(),j(yt.$$.fragment),rl=i(),io=a("p"),zd=s(`The resulting object has several useful properties. For example, you can view the ONNX
operator set that will be used during the export:`),il=i(),j(Ot.$$.fragment),pl=i(),po=a("p"),Vd=s("You can also view the outputs associated with the model as follows:"),fl=i(),j(Tt.$$.fragment),dl=i(),V=a("p"),Hd=s(`Notice that the outputs property follows the same structure as the inputs; it returns an
`),Rn=a("code"),Wd=s("OrderedDict"),Gd=s(` of named outputs and their shapes. The output structure is linked to the
choice of feature that the configuration is initialised with. By default, the ONNX
configuration is initialized with the `),Fn=a("code"),Yd=s("default"),Ud=s(` feature that corresponds to exporting a
model loaded with the `),Sn=a("code"),Kd=s("AutoModel"),Jd=s(` class. If you want to export a model for another task,
just provide a different feature to the `),zn=a("code"),Qd=s("task"),Zd=s(` argument when you initialize the ONNX
configuration. For example, if we wished to export DistilBERT with a sequence
classification head, we could use:`),cl=i(),j(Nt.$$.fragment),hl=i(),j(Ie.$$.fragment),ul=i(),me=a("h3"),Pe=a("a"),Vn=a("span"),j(jt.$$.fragment),ec=i(),Hn=a("span"),tc=s("Exporting the model"),ml=i(),ae=a("p"),oc=s(`Once you have implemented the ONNX configuration, the next step is to export the model.
Here we can use the `),Wn=a("code"),sc=s("export()"),nc=s(" function provided by the "),Gn=a("code"),ac=s("transformers.onnx"),lc=s(` package.
This function expects the ONNX configuration, along with the base model and tokenizer,
and the path to save the exported file:`),gl=i(),j(Ct.$$.fragment),_l=i(),S=a("p"),rc=s("The "),Yn=a("code"),ic=s("onnx_inputs"),pc=s(" and "),Un=a("code"),fc=s("onnx_outputs"),dc=s(" returned by the "),Kn=a("code"),cc=s("export()"),hc=s(` function are lists of
the keys defined in the `),Jn=a("code"),uc=s("inputs"),mc=s(" and "),Qn=a("code"),gc=s("outputs"),_c=s(` properties of the configuration. Once the
model is exported, you can test that the model is well formed as follows:`),vl=i(),j(Dt.$$.fragment),El=i(),j(Me.$$.fragment),$l=i(),ge=a("h3"),Xe=a("a"),Zn=a("span"),j(qt.$$.fragment),vc=i(),ea=a("span"),Ec=s("Validating the model outputs"),wl=i(),le=a("p"),$c=s(`The final step is to validate that the outputs from the base and exported model agree
within some absolute tolerance. Here we can use the `),ta=a("code"),wc=s("validate_model_outputs()"),xc=s(` function
provided by the `),oa=a("code"),bc=s("transformers.onnx"),kc=s(" package as follows:"),xl=i(),j(Lt.$$.fragment),bl=i(),Be=a("p"),yc=s("This function uses the "),fo=a("a"),Oc=s("generate_dummy_inputs()"),Tc=s(` method to
generate inputs for the base and exported model, and the absolute tolerance can be
defined in the configuration. We generally find numerical agreement in the 1e-6 to 1e-4
range, although anything smaller than 1e-3 is likely to be OK.`),kl=i(),_e=a("h2"),Re=a("a"),sa=a("span"),j(At.$$.fragment),Nc=i(),na=a("span"),jc=s("Contributing a new configuration to \u{1F917} Transformers"),yl=i(),co=a("p"),Cc=s(`We are looking to expand the set of ready-made configurations and welcome contributions
from the community! If you would like to contribute your addition to the library, you
will need to:`),Ol=i(),re=a("ul"),It=a("li"),Dc=s("Implement the ONNX configuration in the corresponding "),aa=a("code"),qc=s("configuration_<model_name>.py"),Lc=s(`
file`),Ac=i(),ho=a("li"),Ic=s(`Include the model architecture and corresponding features in
`),la=a("code"),Pc=s("~onnx.features.FeatureManager"),Mc=i(),uo=a("li"),Xc=s("Add your model architecture to the tests in "),ra=a("code"),Bc=s("test_onnx_v2.py"),Tl=i(),Fe=a("p"),Rc=s("Check out how the configuration for "),Pt=a("a"),Fc=s(`IBERT was
contributed`),Sc=s(` to get an
idea of what\u2019s involved.`),this.h()},l(t){const f=gg('[data-svelte="svelte-1phssyn"]',document.head);c=l(f,"META",{name:!0,content:!0}),f.forEach(o),$=p(t),m=l(t,"H1",{class:!0});var Mt=r(m);E=l(Mt,"A",{id:!0,class:!0,href:!0});var ia=r(E);w=l(ia,"SPAN",{});var pa=r(w);C(_.$$.fragment,pa),pa.forEach(o),ia.forEach(o),x=p(Mt),b=l(Mt,"SPAN",{});var fa=r(b);k=n(fa,"Export to ONNX"),fa.forEach(o),Mt.forEach(o),T=p(t),I=l(t,"P",{});var Xt=r(I);y=n(Xt,`If you need to deploy \u{1F917} Transformers models in production environments, we recommend
exporting them to a serialized format that can be loaded and executed on specialized
runtimes and hardware. In this guide, we\u2019ll show you how to export \u{1F917} Transformers
models to `),O=l(Xt,"A",{href:!0,rel:!0});var da=r(O);g=n(da,"ONNX (Open Neural Network eXchange)"),da.forEach(o),N=n(Xt,"."),Xt.forEach(o),B=p(t),C(R.$$.fragment,t),Q=p(t),W=l(t,"P",{});var Bt=r(W);He=n(Bt,`ONNX is an open standard that defines a common set of operators and a common file format
to represent deep learning models in a wide variety of frameworks, including PyTorch and
TensorFlow. When a model is exported to the ONNX format, these operators are used to
construct a computational graph (often called an `),K=l(Bt,"EM",{});var ca=r(K);We=n(ca,"intermediate representation"),ca.forEach(o),Ge=n(Bt,`) which
represents the flow of data through the neural network.`),Bt.forEach(o),Z=p(t),P=l(t,"P",{});var Yc=r(P);Ft=n(Yc,`By exposing a graph with standardized operators and data types, ONNX makes it easy to
switch between frameworks. For example, a model trained in PyTorch can be exported to
ONNX format and then imported in TensorFlow (and vice versa).`),Yc.forEach(o),Ye=p(t),J=l(t,"P",{});var jl=r(J);St=n(jl,"\u{1F917} Transformers provides a "),fe=l(jl,"A",{href:!0});var Uc=r(fe);ve=l(Uc,"CODE",{});var Kc=r(ve);zt=n(Kc,"transformers.onnx"),Kc.forEach(o),Uc.forEach(o),ar=n(jl,` package that enables
you to convert model checkpoints to an ONNX graph by leveraging configuration objects.
These configuration objects come ready made for a number of model architectures, and are
designed to be easily extendable to other architectures.`),jl.forEach(o),ha=p(t),Vt=l(t,"P",{});var Jc=r(Vt);lr=n(Jc,"Ready-made configurations include the following architectures:"),Jc.forEach(o),ua=p(t),h=l(t,"UL",{});var u=r(h);bo=l(u,"LI",{});var Qc=r(bo);rr=n(Qc,"ALBERT"),Qc.forEach(o),ir=p(u),ko=l(u,"LI",{});var Zc=r(ko);pr=n(Zc,"BART"),Zc.forEach(o),fr=p(u),yo=l(u,"LI",{});var eh=r(yo);dr=n(eh,"BEiT"),eh.forEach(o),cr=p(u),Oo=l(u,"LI",{});var th=r(Oo);hr=n(th,"BERT"),th.forEach(o),ur=p(u),To=l(u,"LI",{});var oh=r(To);mr=n(oh,"BigBird"),oh.forEach(o),gr=p(u),No=l(u,"LI",{});var sh=r(No);_r=n(sh,"BigBird-Pegasus"),sh.forEach(o),vr=p(u),jo=l(u,"LI",{});var nh=r(jo);Er=n(nh,"Blenderbot"),nh.forEach(o),$r=p(u),Co=l(u,"LI",{});var ah=r(Co);wr=n(ah,"BlenderbotSmall"),ah.forEach(o),xr=p(u),Do=l(u,"LI",{});var lh=r(Do);br=n(lh,"BLOOM"),lh.forEach(o),kr=p(u),qo=l(u,"LI",{});var rh=r(qo);yr=n(rh,"CamemBERT"),rh.forEach(o),Or=p(u),Lo=l(u,"LI",{});var ih=r(Lo);Tr=n(ih,"Chinese-CLIP"),ih.forEach(o),Nr=p(u),Ao=l(u,"LI",{});var ph=r(Ao);jr=n(ph,"CLIP"),ph.forEach(o),Cr=p(u),Io=l(u,"LI",{});var fh=r(Io);Dr=n(fh,"CodeGen"),fh.forEach(o),qr=p(u),Po=l(u,"LI",{});var dh=r(Po);Lr=n(dh,"Conditional DETR"),dh.forEach(o),Ar=p(u),Mo=l(u,"LI",{});var ch=r(Mo);Ir=n(ch,"ConvBERT"),ch.forEach(o),Pr=p(u),Xo=l(u,"LI",{});var hh=r(Xo);Mr=n(hh,"ConvNeXT"),hh.forEach(o),Xr=p(u),Bo=l(u,"LI",{});var uh=r(Bo);Br=n(uh,"Data2VecText"),uh.forEach(o),Rr=p(u),Ro=l(u,"LI",{});var mh=r(Ro);Fr=n(mh,"Data2VecVision"),mh.forEach(o),Sr=p(u),Fo=l(u,"LI",{});var gh=r(Fo);zr=n(gh,"DeBERTa"),gh.forEach(o),Vr=p(u),So=l(u,"LI",{});var _h=r(So);Hr=n(_h,"DeBERTa-v2"),_h.forEach(o),Wr=p(u),zo=l(u,"LI",{});var vh=r(zo);Gr=n(vh,"DeiT"),vh.forEach(o),Yr=p(u),Vo=l(u,"LI",{});var Eh=r(Vo);Ur=n(Eh,"DETR"),Eh.forEach(o),Kr=p(u),Ho=l(u,"LI",{});var $h=r(Ho);Jr=n($h,"DistilBERT"),$h.forEach(o),Qr=p(u),Wo=l(u,"LI",{});var wh=r(Wo);Zr=n(wh,"ELECTRA"),wh.forEach(o),ei=p(u),Go=l(u,"LI",{});var xh=r(Go);ti=n(xh,"ERNIE"),xh.forEach(o),oi=p(u),Yo=l(u,"LI",{});var bh=r(Yo);si=n(bh,"FlauBERT"),bh.forEach(o),ni=p(u),Uo=l(u,"LI",{});var kh=r(Uo);ai=n(kh,"GPT Neo"),kh.forEach(o),li=p(u),Ko=l(u,"LI",{});var yh=r(Ko);ri=n(yh,"GPT-J"),yh.forEach(o),ii=p(u),Jo=l(u,"LI",{});var Oh=r(Jo);pi=n(Oh,"GroupViT"),Oh.forEach(o),fi=p(u),Qo=l(u,"LI",{});var Th=r(Qo);di=n(Th,"I-BERT"),Th.forEach(o),ci=p(u),Zo=l(u,"LI",{});var Nh=r(Zo);hi=n(Nh,"ImageGPT"),Nh.forEach(o),ui=p(u),es=l(u,"LI",{});var jh=r(es);mi=n(jh,"LayoutLM"),jh.forEach(o),gi=p(u),ts=l(u,"LI",{});var Ch=r(ts);_i=n(Ch,"LayoutLMv3"),Ch.forEach(o),vi=p(u),os=l(u,"LI",{});var Dh=r(os);Ei=n(Dh,"LeViT"),Dh.forEach(o),$i=p(u),ss=l(u,"LI",{});var qh=r(ss);wi=n(qh,"Longformer"),qh.forEach(o),xi=p(u),ns=l(u,"LI",{});var Lh=r(ns);bi=n(Lh,"LongT5"),Lh.forEach(o),ki=p(u),as=l(u,"LI",{});var Ah=r(as);yi=n(Ah,"M2M100"),Ah.forEach(o),Oi=p(u),ls=l(u,"LI",{});var Ih=r(ls);Ti=n(Ih,"Marian"),Ih.forEach(o),Ni=p(u),rs=l(u,"LI",{});var Ph=r(rs);ji=n(Ph,"mBART"),Ph.forEach(o),Ci=p(u),is=l(u,"LI",{});var Mh=r(is);Di=n(Mh,"MobileBERT"),Mh.forEach(o),qi=p(u),ps=l(u,"LI",{});var Xh=r(ps);Li=n(Xh,"MobileNetV1"),Xh.forEach(o),Ai=p(u),fs=l(u,"LI",{});var Bh=r(fs);Ii=n(Bh,"MobileNetV2"),Bh.forEach(o),Pi=p(u),ds=l(u,"LI",{});var Rh=r(ds);Mi=n(Rh,"MobileViT"),Rh.forEach(o),Xi=p(u),cs=l(u,"LI",{});var Fh=r(cs);Bi=n(Fh,"MT5"),Fh.forEach(o),Ri=p(u),hs=l(u,"LI",{});var Sh=r(hs);Fi=n(Sh,"OpenAI GPT-2"),Sh.forEach(o),Si=p(u),us=l(u,"LI",{});var zh=r(us);zi=n(zh,"OWL-ViT"),zh.forEach(o),Vi=p(u),ms=l(u,"LI",{});var Vh=r(ms);Hi=n(Vh,"Perceiver"),Vh.forEach(o),Wi=p(u),gs=l(u,"LI",{});var Hh=r(gs);Gi=n(Hh,"PLBart"),Hh.forEach(o),Yi=p(u),_s=l(u,"LI",{});var Wh=r(_s);Ui=n(Wh,"ResNet"),Wh.forEach(o),Ki=p(u),vs=l(u,"LI",{});var Gh=r(vs);Ji=n(Gh,"RoBERTa"),Gh.forEach(o),Qi=p(u),Es=l(u,"LI",{});var Yh=r(Es);Zi=n(Yh,"RoFormer"),Yh.forEach(o),ep=p(u),$s=l(u,"LI",{});var Uh=r($s);tp=n(Uh,"SegFormer"),Uh.forEach(o),op=p(u),ws=l(u,"LI",{});var Kh=r(ws);sp=n(Kh,"SqueezeBERT"),Kh.forEach(o),np=p(u),xs=l(u,"LI",{});var Jh=r(xs);ap=n(Jh,"Swin Transformer"),Jh.forEach(o),lp=p(u),bs=l(u,"LI",{});var Qh=r(bs);rp=n(Qh,"T5"),Qh.forEach(o),ip=p(u),ks=l(u,"LI",{});var Zh=r(ks);pp=n(Zh,"Table Transformer"),Zh.forEach(o),fp=p(u),ys=l(u,"LI",{});var eu=r(ys);dp=n(eu,"Vision Encoder decoder"),eu.forEach(o),cp=p(u),Os=l(u,"LI",{});var tu=r(Os);hp=n(tu,"ViT"),tu.forEach(o),up=p(u),Ts=l(u,"LI",{});var ou=r(Ts);mp=n(ou,"Whisper"),ou.forEach(o),gp=p(u),Ns=l(u,"LI",{});var su=r(Ns);_p=n(su,"XLM"),su.forEach(o),vp=p(u),js=l(u,"LI",{});var nu=r(js);Ep=n(nu,"XLM-RoBERTa"),nu.forEach(o),$p=p(u),Cs=l(u,"LI",{});var au=r(Cs);wp=n(au,"XLM-RoBERTa-XL"),au.forEach(o),xp=p(u),Ds=l(u,"LI",{});var lu=r(Ds);bp=n(lu,"YOLOS"),lu.forEach(o),u.forEach(o),ma=p(t),Ht=l(t,"P",{});var ru=r(Ht);kp=n(ru,"In the next two sections, we\u2019ll show you how to:"),ru.forEach(o),ga=p(t),Ee=l(t,"UL",{});var Cl=r(Ee);Ue=l(Cl,"LI",{});var Dl=r(Ue);yp=n(Dl,"Export a supported model using the "),qs=l(Dl,"CODE",{});var iu=r(qs);Op=n(iu,"transformers.onnx"),iu.forEach(o),Tp=n(Dl," package."),Dl.forEach(o),Np=p(Cl),Ls=l(Cl,"LI",{});var pu=r(Ls);jp=n(pu,"Export a custom model for an unsupported architecture."),pu.forEach(o),Cl.forEach(o),_a=p(t),de=l(t,"H2",{class:!0});var ql=r(de);$e=l(ql,"A",{id:!0,class:!0,href:!0});var fu=r($e);As=l(fu,"SPAN",{});var du=r(As);C(Ke.$$.fragment,du),du.forEach(o),fu.forEach(o),Cp=p(ql),Is=l(ql,"SPAN",{});var cu=r(Is);Dp=n(cu,"Exporting a model to ONNX"),cu.forEach(o),ql.forEach(o),va=p(t),Wt=l(t,"P",{});var hu=r(Wt);qp=n(hu,`To export a \u{1F917} Transformers model to ONNX, you\u2019ll first need to install some extra
dependencies:`),hu.forEach(o),Ea=p(t),C(Je.$$.fragment,t),$a=p(t),we=l(t,"P",{});var Ll=r(we);Lp=n(Ll,"The "),Ps=l(Ll,"CODE",{});var uu=r(Ps);Ap=n(uu,"transformers.onnx"),uu.forEach(o),Ip=n(Ll," package can then be used as a Python module:"),Ll.forEach(o),wa=p(t),C(Qe.$$.fragment,t),xa=p(t),Gt=l(t,"P",{});var mu=r(Gt);Pp=n(mu,"Exporting a checkpoint using a ready-made configuration can be done as follows:"),mu.forEach(o),ba=p(t),C(Ze.$$.fragment,t),ka=p(t),Yt=l(t,"P",{});var gu=r(Yt);Mp=n(gu,"You should see the following logs:"),gu.forEach(o),ya=p(t),C(et.$$.fragment,t),Oa=p(t),ee=l(t,"P",{});var mo=r(ee);Xp=n(mo,"This exports an ONNX graph of the checkpoint defined by the "),Ms=l(mo,"CODE",{});var _u=r(Ms);Bp=n(_u,"--model"),_u.forEach(o),Rp=n(mo,` argument. In this
example, it is `),Xs=l(mo,"CODE",{});var vu=r(Xs);Fp=n(vu,"distilbert-base-uncased"),vu.forEach(o),Sp=n(mo,`, but it can be any checkpoint on the Hugging
Face Hub or one that\u2019s stored locally.`),mo.forEach(o),Ta=p(t),G=l(t,"P",{});var Se=r(G);zp=n(Se,"The resulting "),Bs=l(Se,"CODE",{});var Eu=r(Bs);Vp=n(Eu,"model.onnx"),Eu.forEach(o),Hp=n(Se," file can then be run on one of the "),tt=l(Se,"A",{href:!0,rel:!0});var $u=r(tt);Wp=n($u,`many
accelerators`),$u.forEach(o),Gp=n(Se,` that support the ONNX
standard. For example, we can load and run the model with `),ot=l(Se,"A",{href:!0,rel:!0});var wu=r(ot);Yp=n(wu,`ONNX
Runtime`),wu.forEach(o),Up=n(Se," as follows:"),Se.forEach(o),Na=p(t),C(st.$$.fragment,t),ja=p(t),xe=l(t,"P",{});var Al=r(xe);Kp=n(Al,"The required output names (like "),Rs=l(Al,"CODE",{});var xu=r(Rs);Jp=n(xu,'["last_hidden_state"]'),xu.forEach(o),Qp=n(Al,`) can be obtained by taking a
look at the ONNX configuration of each model. For example, for DistilBERT we have:`),Al.forEach(o),Ca=p(t),C(nt.$$.fragment,t),Da=p(t),be=l(t,"P",{});var Il=r(be);Zp=n(Il,`The process is identical for TensorFlow checkpoints on the Hub. For example, we can
export a pure TensorFlow checkpoint from the `),at=l(Il,"A",{href:!0,rel:!0});var bu=r(at);ef=n(bu,`Keras
organization`),bu.forEach(o),tf=n(Il," as follows:"),Il.forEach(o),qa=p(t),C(lt.$$.fragment,t),La=p(t),Ut=l(t,"P",{});var ku=r(Ut);of=n(ku,`To export a model that\u2019s stored locally, you\u2019ll need to have the model\u2019s weights and
tokenizer files stored in a directory. For example, we can load and save a checkpoint as
follows:`),ku.forEach(o),Aa=p(t),C(ke.$$.fragment,t),Ia=p(t),ce=l(t,"H2",{class:!0});var Pl=r(ce);ye=l(Pl,"A",{id:!0,class:!0,href:!0});var yu=r(ye);Fs=l(yu,"SPAN",{});var Ou=r(Fs);C(rt.$$.fragment,Ou),Ou.forEach(o),yu.forEach(o),sf=p(Pl),Ss=l(Pl,"SPAN",{});var Tu=r(Ss);nf=n(Tu,"Selecting features for different model tasks"),Tu.forEach(o),Pl.forEach(o),Pa=p(t),te=l(t,"P",{});var go=r(te);af=n(go,"Each ready-made configuration comes with a set of "),zs=l(go,"EM",{});var Nu=r(zs);lf=n(Nu,"features"),Nu.forEach(o),rf=n(go,` that enable you to export
models for different types of tasks. As shown in the table below, each feature is
associated with a different `),Vs=l(go,"CODE",{});var ju=r(Vs);pf=n(ju,"AutoClass"),ju.forEach(o),ff=n(go,":"),go.forEach(o),Ma=p(t),Oe=l(t,"TABLE",{});var Ml=r(Oe);Hs=l(Ml,"THEAD",{});var Cu=r(Hs);it=l(Cu,"TR",{});var Xl=r(it);Ws=l(Xl,"TH",{});var Du=r(Ws);df=n(Du,"Feature"),Du.forEach(o),cf=p(Xl),Gs=l(Xl,"TH",{});var qu=r(Gs);hf=n(qu,"Auto Class"),qu.forEach(o),Xl.forEach(o),Cu.forEach(o),uf=p(Ml),F=l(Ml,"TBODY",{});var H=r(F);pt=l(H,"TR",{});var Bl=r(pt);ft=l(Bl,"TD",{});var Rl=r(ft);Ys=l(Rl,"CODE",{});var Lu=r(Ys);mf=n(Lu,"causal-lm"),Lu.forEach(o),gf=n(Rl,", "),Us=l(Rl,"CODE",{});var Au=r(Us);_f=n(Au,"causal-lm-with-past"),Au.forEach(o),Rl.forEach(o),vf=p(Bl),Ks=l(Bl,"TD",{});var Iu=r(Ks);Js=l(Iu,"CODE",{});var Pu=r(Js);Ef=n(Pu,"AutoModelForCausalLM"),Pu.forEach(o),Iu.forEach(o),Bl.forEach(o),$f=p(H),dt=l(H,"TR",{});var Fl=r(dt);ct=l(Fl,"TD",{});var Sl=r(ct);Qs=l(Sl,"CODE",{});var Mu=r(Qs);wf=n(Mu,"default"),Mu.forEach(o),xf=n(Sl,", "),Zs=l(Sl,"CODE",{});var Xu=r(Zs);bf=n(Xu,"default-with-past"),Xu.forEach(o),Sl.forEach(o),kf=p(Fl),en=l(Fl,"TD",{});var Bu=r(en);tn=l(Bu,"CODE",{});var Ru=r(tn);yf=n(Ru,"AutoModel"),Ru.forEach(o),Bu.forEach(o),Fl.forEach(o),Of=p(H),ht=l(H,"TR",{});var zl=r(ht);on=l(zl,"TD",{});var Fu=r(on);sn=l(Fu,"CODE",{});var Su=r(sn);Tf=n(Su,"masked-lm"),Su.forEach(o),Fu.forEach(o),Nf=p(zl),nn=l(zl,"TD",{});var zu=r(nn);an=l(zu,"CODE",{});var Vu=r(an);jf=n(Vu,"AutoModelForMaskedLM"),Vu.forEach(o),zu.forEach(o),zl.forEach(o),Cf=p(H),ut=l(H,"TR",{});var Vl=r(ut);ln=l(Vl,"TD",{});var Hu=r(ln);rn=l(Hu,"CODE",{});var Wu=r(rn);Df=n(Wu,"question-answering"),Wu.forEach(o),Hu.forEach(o),qf=p(Vl),pn=l(Vl,"TD",{});var Gu=r(pn);fn=l(Gu,"CODE",{});var Yu=r(fn);Lf=n(Yu,"AutoModelForQuestionAnswering"),Yu.forEach(o),Gu.forEach(o),Vl.forEach(o),Af=p(H),mt=l(H,"TR",{});var Hl=r(mt);gt=l(Hl,"TD",{});var Wl=r(gt);dn=l(Wl,"CODE",{});var Uu=r(dn);If=n(Uu,"seq2seq-lm"),Uu.forEach(o),Pf=n(Wl,", "),cn=l(Wl,"CODE",{});var Ku=r(cn);Mf=n(Ku,"seq2seq-lm-with-past"),Ku.forEach(o),Wl.forEach(o),Xf=p(Hl),hn=l(Hl,"TD",{});var Ju=r(hn);un=l(Ju,"CODE",{});var Qu=r(un);Bf=n(Qu,"AutoModelForSeq2SeqLM"),Qu.forEach(o),Ju.forEach(o),Hl.forEach(o),Rf=p(H),_t=l(H,"TR",{});var Gl=r(_t);mn=l(Gl,"TD",{});var Zu=r(mn);gn=l(Zu,"CODE",{});var em=r(gn);Ff=n(em,"sequence-classification"),em.forEach(o),Zu.forEach(o),Sf=p(Gl),_n=l(Gl,"TD",{});var tm=r(_n);vn=l(tm,"CODE",{});var om=r(vn);zf=n(om,"AutoModelForSequenceClassification"),om.forEach(o),tm.forEach(o),Gl.forEach(o),Vf=p(H),vt=l(H,"TR",{});var Yl=r(vt);En=l(Yl,"TD",{});var sm=r(En);$n=l(sm,"CODE",{});var nm=r($n);Hf=n(nm,"token-classification"),nm.forEach(o),sm.forEach(o),Wf=p(Yl),wn=l(Yl,"TD",{});var am=r(wn);xn=l(am,"CODE",{});var lm=r(xn);Gf=n(lm,"AutoModelForTokenClassification"),lm.forEach(o),am.forEach(o),Yl.forEach(o),H.forEach(o),Ml.forEach(o),Xa=p(t),Te=l(t,"P",{});var Ul=r(Te);Yf=n(Ul,`For each configuration, you can find the list of supported features via the
`),Kt=l(Ul,"A",{href:!0});var rm=r(Kt);Uf=n(rm,"FeaturesManager"),rm.forEach(o),Kf=n(Ul,". For example, for DistilBERT we have:"),Ul.forEach(o),Ba=p(t),C(Et.$$.fragment,t),Ra=p(t),oe=l(t,"P",{});var _o=r(oe);Jf=n(_o,"You can then pass one of these features to the "),bn=l(_o,"CODE",{});var im=r(bn);Qf=n(im,"--feature"),im.forEach(o),Zf=n(_o,` argument in the
`),kn=l(_o,"CODE",{});var pm=r(kn);ed=n(pm,"transformers.onnx"),pm.forEach(o),td=n(_o,` package. For example, to export a text-classification model we can
pick a fine-tuned model from the Hub and run:`),_o.forEach(o),Fa=p(t),C($t.$$.fragment,t),Sa=p(t),Jt=l(t,"P",{});var fm=r(Jt);od=n(fm,"This displays the following logs:"),fm.forEach(o),za=p(t),C(wt.$$.fragment,t),Va=p(t),Y=l(t,"P",{});var ze=r(Y);sd=n(ze,"Notice that in this case, the output names from the fine-tuned model are "),yn=l(ze,"CODE",{});var dm=r(yn);nd=n(dm,"logits"),dm.forEach(o),ad=n(ze,`
instead of the `),On=l(ze,"CODE",{});var cm=r(On);ld=n(cm,"last_hidden_state"),cm.forEach(o),rd=n(ze," we saw with the "),Tn=l(ze,"CODE",{});var hm=r(Tn);id=n(hm,"distilbert-base-uncased"),hm.forEach(o),pd=n(ze,` checkpoint
earlier. This is expected since the fine-tuned model has a sequence classification head.`),ze.forEach(o),Ha=p(t),C(Ne.$$.fragment,t),Wa=p(t),C(je.$$.fragment,t),Ga=p(t),he=l(t,"H2",{class:!0});var Kl=r(he);Ce=l(Kl,"A",{id:!0,class:!0,href:!0});var um=r(Ce);Nn=l(um,"SPAN",{});var mm=r(Nn);C(xt.$$.fragment,mm),mm.forEach(o),um.forEach(o),fd=p(Kl),jn=l(Kl,"SPAN",{});var gm=r(jn);dd=n(gm,"Exporting a model for an unsupported architecture"),gm.forEach(o),Kl.forEach(o),Ya=p(t),Qt=l(t,"P",{});var _m=r(Qt);cd=n(_m,`If you wish to export a model whose architecture is not natively supported by the
library, there are three main steps to follow:`),_m.forEach(o),Ua=p(t),se=l(t,"OL",{});var vo=r(se);Cn=l(vo,"LI",{});var vm=r(Cn);hd=n(vm,"Implement a custom ONNX configuration."),vm.forEach(o),ud=p(vo),Dn=l(vo,"LI",{});var Em=r(Dn);md=n(Em,"Export the model to ONNX."),Em.forEach(o),gd=p(vo),qn=l(vo,"LI",{});var $m=r(qn);_d=n($m,"Validate the outputs of the PyTorch and exported models."),$m.forEach(o),vo.forEach(o),Ka=p(t),Zt=l(t,"P",{});var wm=r(Zt);vd=n(wm,`In this section, we\u2019ll look at how DistilBERT was implemented to show what\u2019s involved
with each step.`),wm.forEach(o),Ja=p(t),ue=l(t,"H3",{class:!0});var Jl=r(ue);De=l(Jl,"A",{id:!0,class:!0,href:!0});var xm=r(De);Ln=l(xm,"SPAN",{});var bm=r(Ln);C(bt.$$.fragment,bm),bm.forEach(o),xm.forEach(o),Ed=p(Jl),An=l(Jl,"SPAN",{});var km=r(An);$d=n(km,"Implementing a custom ONNX configuration"),km.forEach(o),Jl.forEach(o),Qa=p(t),eo=l(t,"P",{});var ym=r(eo);wd=n(ym,`Let\u2019s start with the ONNX configuration object. We provide three abstract classes that
you should inherit from, depending on the type of model architecture you wish to export:`),ym.forEach(o),Za=p(t),ne=l(t,"UL",{});var Eo=r(ne);to=l(Eo,"LI",{});var zc=r(to);xd=n(zc,"Encoder-based models inherit from "),oo=l(zc,"A",{href:!0});var Om=r(oo);bd=n(Om,"OnnxConfig"),Om.forEach(o),zc.forEach(o),kd=p(Eo),so=l(Eo,"LI",{});var Vc=r(so);yd=n(Vc,"Decoder-based models inherit from "),no=l(Vc,"A",{href:!0});var Tm=r(no);Od=n(Tm,"OnnxConfigWithPast"),Tm.forEach(o),Vc.forEach(o),Td=p(Eo),ao=l(Eo,"LI",{});var Hc=r(ao);Nd=n(Hc,"Encoder-decoder models inherit from "),lo=l(Hc,"A",{href:!0});var Nm=r(lo);jd=n(Nm,"OnnxSeq2SeqConfigWithPast"),Nm.forEach(o),Hc.forEach(o),Eo.forEach(o),el=p(t),C(qe.$$.fragment,t),tl=p(t),Le=l(t,"P",{});var Ql=r(Le);Cd=n(Ql,`Since DistilBERT is an encoder-based model, its configuration inherits from
`),In=l(Ql,"CODE",{});var jm=r(In);Dd=n(jm,"OnnxConfig"),jm.forEach(o),qd=n(Ql,":"),Ql.forEach(o),ol=p(t),C(kt.$$.fragment,t),sl=p(t),z=l(t,"P",{});var ie=r(z);Ld=n(ie,"Every configuration object must implement the "),Pn=l(ie,"CODE",{});var Cm=r(Pn);Ad=n(Cm,"inputs"),Cm.forEach(o),Id=n(ie,` property and return a mapping,
where each key corresponds to an expected input, and each value indicates the axis of
that input. For DistilBERT, we can see that two inputs are required: `),Mn=l(ie,"CODE",{});var Dm=r(Mn);Pd=n(Dm,"input_ids"),Dm.forEach(o),Md=n(ie,` and
`),Xn=l(ie,"CODE",{});var qm=r(Xn);Xd=n(qm,"attention_mask"),qm.forEach(o),Bd=n(ie,". These inputs have the same shape of "),Bn=l(ie,"CODE",{});var Lm=r(Bn);Rd=n(Lm,"(batch_size, sequence_length)"),Lm.forEach(o),Fd=n(ie,`
which is why we see the same axes used in the configuration.`),ie.forEach(o),nl=p(t),C(Ae.$$.fragment,t),al=p(t),ro=l(t,"P",{});var Am=r(ro);Sd=n(Am,`Once you have implemented an ONNX configuration, you can instantiate it by providing the
base model\u2019s configuration as follows:`),Am.forEach(o),ll=p(t),C(yt.$$.fragment,t),rl=p(t),io=l(t,"P",{});var Im=r(io);zd=n(Im,`The resulting object has several useful properties. For example, you can view the ONNX
operator set that will be used during the export:`),Im.forEach(o),il=p(t),C(Ot.$$.fragment,t),pl=p(t),po=l(t,"P",{});var Pm=r(po);Vd=n(Pm,"You can also view the outputs associated with the model as follows:"),Pm.forEach(o),fl=p(t),C(Tt.$$.fragment,t),dl=p(t),V=l(t,"P",{});var pe=r(V);Hd=n(pe,`Notice that the outputs property follows the same structure as the inputs; it returns an
`),Rn=l(pe,"CODE",{});var Mm=r(Rn);Wd=n(Mm,"OrderedDict"),Mm.forEach(o),Gd=n(pe,` of named outputs and their shapes. The output structure is linked to the
choice of feature that the configuration is initialised with. By default, the ONNX
configuration is initialized with the `),Fn=l(pe,"CODE",{});var Xm=r(Fn);Yd=n(Xm,"default"),Xm.forEach(o),Ud=n(pe,` feature that corresponds to exporting a
model loaded with the `),Sn=l(pe,"CODE",{});var Bm=r(Sn);Kd=n(Bm,"AutoModel"),Bm.forEach(o),Jd=n(pe,` class. If you want to export a model for another task,
just provide a different feature to the `),zn=l(pe,"CODE",{});var Rm=r(zn);Qd=n(Rm,"task"),Rm.forEach(o),Zd=n(pe,` argument when you initialize the ONNX
configuration. For example, if we wished to export DistilBERT with a sequence
classification head, we could use:`),pe.forEach(o),cl=p(t),C(Nt.$$.fragment,t),hl=p(t),C(Ie.$$.fragment,t),ul=p(t),me=l(t,"H3",{class:!0});var Zl=r(me);Pe=l(Zl,"A",{id:!0,class:!0,href:!0});var Fm=r(Pe);Vn=l(Fm,"SPAN",{});var Sm=r(Vn);C(jt.$$.fragment,Sm),Sm.forEach(o),Fm.forEach(o),ec=p(Zl),Hn=l(Zl,"SPAN",{});var zm=r(Hn);tc=n(zm,"Exporting the model"),zm.forEach(o),Zl.forEach(o),ml=p(t),ae=l(t,"P",{});var $o=r(ae);oc=n($o,`Once you have implemented the ONNX configuration, the next step is to export the model.
Here we can use the `),Wn=l($o,"CODE",{});var Vm=r(Wn);sc=n(Vm,"export()"),Vm.forEach(o),nc=n($o," function provided by the "),Gn=l($o,"CODE",{});var Hm=r(Gn);ac=n(Hm,"transformers.onnx"),Hm.forEach(o),lc=n($o,` package.
This function expects the ONNX configuration, along with the base model and tokenizer,
and the path to save the exported file:`),$o.forEach(o),gl=p(t),C(Ct.$$.fragment,t),_l=p(t),S=l(t,"P",{});var U=r(S);rc=n(U,"The "),Yn=l(U,"CODE",{});var Wm=r(Yn);ic=n(Wm,"onnx_inputs"),Wm.forEach(o),pc=n(U," and "),Un=l(U,"CODE",{});var Gm=r(Un);fc=n(Gm,"onnx_outputs"),Gm.forEach(o),dc=n(U," returned by the "),Kn=l(U,"CODE",{});var Ym=r(Kn);cc=n(Ym,"export()"),Ym.forEach(o),hc=n(U,` function are lists of
the keys defined in the `),Jn=l(U,"CODE",{});var Um=r(Jn);uc=n(Um,"inputs"),Um.forEach(o),mc=n(U," and "),Qn=l(U,"CODE",{});var Km=r(Qn);gc=n(Km,"outputs"),Km.forEach(o),_c=n(U,` properties of the configuration. Once the
model is exported, you can test that the model is well formed as follows:`),U.forEach(o),vl=p(t),C(Dt.$$.fragment,t),El=p(t),C(Me.$$.fragment,t),$l=p(t),ge=l(t,"H3",{class:!0});var er=r(ge);Xe=l(er,"A",{id:!0,class:!0,href:!0});var Jm=r(Xe);Zn=l(Jm,"SPAN",{});var Qm=r(Zn);C(qt.$$.fragment,Qm),Qm.forEach(o),Jm.forEach(o),vc=p(er),ea=l(er,"SPAN",{});var Zm=r(ea);Ec=n(Zm,"Validating the model outputs"),Zm.forEach(o),er.forEach(o),wl=p(t),le=l(t,"P",{});var wo=r(le);$c=n(wo,`The final step is to validate that the outputs from the base and exported model agree
within some absolute tolerance. Here we can use the `),ta=l(wo,"CODE",{});var eg=r(ta);wc=n(eg,"validate_model_outputs()"),eg.forEach(o),xc=n(wo,` function
provided by the `),oa=l(wo,"CODE",{});var tg=r(oa);bc=n(tg,"transformers.onnx"),tg.forEach(o),kc=n(wo," package as follows:"),wo.forEach(o),xl=p(t),C(Lt.$$.fragment,t),bl=p(t),Be=l(t,"P",{});var tr=r(Be);yc=n(tr,"This function uses the "),fo=l(tr,"A",{href:!0});var og=r(fo);Oc=n(og,"generate_dummy_inputs()"),og.forEach(o),Tc=n(tr,` method to
generate inputs for the base and exported model, and the absolute tolerance can be
defined in the configuration. We generally find numerical agreement in the 1e-6 to 1e-4
range, although anything smaller than 1e-3 is likely to be OK.`),tr.forEach(o),kl=p(t),_e=l(t,"H2",{class:!0});var or=r(_e);Re=l(or,"A",{id:!0,class:!0,href:!0});var sg=r(Re);sa=l(sg,"SPAN",{});var ng=r(sa);C(At.$$.fragment,ng),ng.forEach(o),sg.forEach(o),Nc=p(or),na=l(or,"SPAN",{});var ag=r(na);jc=n(ag,"Contributing a new configuration to \u{1F917} Transformers"),ag.forEach(o),or.forEach(o),yl=p(t),co=l(t,"P",{});var lg=r(co);Cc=n(lg,`We are looking to expand the set of ready-made configurations and welcome contributions
from the community! If you would like to contribute your addition to the library, you
will need to:`),lg.forEach(o),Ol=p(t),re=l(t,"UL",{});var xo=r(re);It=l(xo,"LI",{});var sr=r(It);Dc=n(sr,"Implement the ONNX configuration in the corresponding "),aa=l(sr,"CODE",{});var rg=r(aa);qc=n(rg,"configuration_<model_name>.py"),rg.forEach(o),Lc=n(sr,`
file`),sr.forEach(o),Ac=p(xo),ho=l(xo,"LI",{});var Wc=r(ho);Ic=n(Wc,`Include the model architecture and corresponding features in
`),la=l(Wc,"CODE",{});var ig=r(la);Pc=n(ig,"~onnx.features.FeatureManager"),ig.forEach(o),Wc.forEach(o),Mc=p(xo),uo=l(xo,"LI",{});var Gc=r(uo);Xc=n(Gc,"Add your model architecture to the tests in "),ra=l(Gc,"CODE",{});var pg=r(ra);Bc=n(pg,"test_onnx_v2.py"),pg.forEach(o),Gc.forEach(o),xo.forEach(o),Tl=p(t),Fe=l(t,"P",{});var nr=r(Fe);Rc=n(nr,"Check out how the configuration for "),Pt=l(nr,"A",{href:!0,rel:!0});var fg=r(Pt);Fc=n(fg,`IBERT was
contributed`),fg.forEach(o),Sc=n(nr,` to get an
idea of what\u2019s involved.`),nr.forEach(o),this.h()},h(){v(c,"name","hf:doc:metadata"),v(c,"content",JSON.stringify(Dg)),v(E,"id","export-to-onnx"),v(E,"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"),v(E,"href","#export-to-onnx"),v(m,"class","relative group"),v(O,"href","http://onnx.ai"),v(O,"rel","nofollow"),v(fe,"href","main_classes/onnx"),v($e,"id","exporting-a-model-to-onnx"),v($e,"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"),v($e,"href","#exporting-a-model-to-onnx"),v(de,"class","relative group"),v(tt,"href","https://onnx.ai/supported-tools.html#deployModel"),v(tt,"rel","nofollow"),v(ot,"href","https://onnxruntime.ai/"),v(ot,"rel","nofollow"),v(at,"href","https://huggingface.co/keras-io"),v(at,"rel","nofollow"),v(ye,"id","selecting-features-for-different-model-tasks"),v(ye,"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"),v(ye,"href","#selecting-features-for-different-model-tasks"),v(ce,"class","relative group"),v(Kt,"href","/docs/transformers/v4.25.1/en/main_classes/onnx#transformers.onnx.FeaturesManager"),v(Ce,"id","exporting-a-model-for-an-unsupported-architecture"),v(Ce,"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"),v(Ce,"href","#exporting-a-model-for-an-unsupported-architecture"),v(he,"class","relative group"),v(De,"id","implementing-a-custom-onnx-configuration"),v(De,"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"),v(De,"href","#implementing-a-custom-onnx-configuration"),v(ue,"class","relative group"),v(oo,"href","/docs/transformers/v4.25.1/en/main_classes/onnx#transformers.onnx.OnnxConfig"),v(no,"href","/docs/transformers/v4.25.1/en/main_classes/onnx#transformers.onnx.OnnxConfigWithPast"),v(lo,"href","/docs/transformers/v4.25.1/en/main_classes/onnx#transformers.onnx.OnnxSeq2SeqConfigWithPast"),v(Pe,"id","exporting-the-model"),v(Pe,"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"),v(Pe,"href","#exporting-the-model"),v(me,"class","relative group"),v(Xe,"id","validating-the-model-outputs"),v(Xe,"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"),v(Xe,"href","#validating-the-model-outputs"),v(ge,"class","relative group"),v(fo,"href","/docs/transformers/v4.25.1/en/main_classes/onnx#transformers.onnx.OnnxConfig.generate_dummy_inputs"),v(Re,"id","contributing-a-new-configuration-to-transformers"),v(Re,"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"),v(Re,"href","#contributing-a-new-configuration-to-transformers"),v(_e,"class","relative group"),v(Pt,"href","https://github.com/huggingface/transformers/pull/14868/files"),v(Pt,"rel","nofollow")},m(t,f){e(document.head,c),d(t,$,f),d(t,m,f),e(m,E),e(E,w),D(_,w,null),e(m,x),e(m,b),e(b,k),d(t,T,f),d(t,I,f),e(I,y),e(I,O),e(O,g),e(I,N),d(t,B,f),D(R,t,f),d(t,Q,f),d(t,W,f),e(W,He),e(W,K),e(K,We),e(W,Ge),d(t,Z,f),d(t,P,f),e(P,Ft),d(t,Ye,f),d(t,J,f),e(J,St),e(J,fe),e(fe,ve),e(ve,zt),e(J,ar),d(t,ha,f),d(t,Vt,f),e(Vt,lr),d(t,ua,f),d(t,h,f),e(h,bo),e(bo,rr),e(h,ir),e(h,ko),e(ko,pr),e(h,fr),e(h,yo),e(yo,dr),e(h,cr),e(h,Oo),e(Oo,hr),e(h,ur),e(h,To),e(To,mr),e(h,gr),e(h,No),e(No,_r),e(h,vr),e(h,jo),e(jo,Er),e(h,$r),e(h,Co),e(Co,wr),e(h,xr),e(h,Do),e(Do,br),e(h,kr),e(h,qo),e(qo,yr),e(h,Or),e(h,Lo),e(Lo,Tr),e(h,Nr),e(h,Ao),e(Ao,jr),e(h,Cr),e(h,Io),e(Io,Dr),e(h,qr),e(h,Po),e(Po,Lr),e(h,Ar),e(h,Mo),e(Mo,Ir),e(h,Pr),e(h,Xo),e(Xo,Mr),e(h,Xr),e(h,Bo),e(Bo,Br),e(h,Rr),e(h,Ro),e(Ro,Fr),e(h,Sr),e(h,Fo),e(Fo,zr),e(h,Vr),e(h,So),e(So,Hr),e(h,Wr),e(h,zo),e(zo,Gr),e(h,Yr),e(h,Vo),e(Vo,Ur),e(h,Kr),e(h,Ho),e(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gc),e(S,_c),d(t,vl,f),D(Dt,t,f),d(t,El,f),D(Me,t,f),d(t,$l,f),d(t,ge,f),e(ge,Xe),e(Xe,Zn),D(qt,Zn,null),e(ge,vc),e(ge,ea),e(ea,Ec),d(t,wl,f),d(t,le,f),e(le,$c),e(le,ta),e(ta,wc),e(le,xc),e(le,oa),e(oa,bc),e(le,kc),d(t,xl,f),D(Lt,t,f),d(t,bl,f),d(t,Be,f),e(Be,yc),e(Be,fo),e(fo,Oc),e(Be,Tc),d(t,kl,f),d(t,_e,f),e(_e,Re),e(Re,sa),D(At,sa,null),e(_e,Nc),e(_e,na),e(na,jc),d(t,yl,f),d(t,co,f),e(co,Cc),d(t,Ol,f),d(t,re,f),e(re,It),e(It,Dc),e(It,aa),e(aa,qc),e(It,Lc),e(re,Ac),e(re,ho),e(ho,Ic),e(ho,la),e(la,Pc),e(re,Mc),e(re,uo),e(uo,Xc),e(uo,ra),e(ra,Bc),d(t,Tl,f),d(t,Fe,f),e(Fe,Rc),e(Fe,Pt),e(Pt,Fc),e(Fe,Sc),Nl=!0},p(t,[f]){const Mt={};f&2&&(Mt.$$scope={dirty:f,ctx:t}),R.$set(Mt);const ia={};f&2&&(ia.$$scope={dirty:f,ctx:t}),ke.$set(ia);const pa={};f&2&&(pa.$$scope={dirty:f,ctx:t}),Ne.$set(pa);const fa={};f&2&&(fa.$$scope={dirty:f,ctx:t}),je.$set(fa);const Xt={};f&2&&(Xt.$$scope={dirty:f,ctx:t}),qe.$set(Xt);const da={};f&2&&(da.$$scope={dirty:f,ctx:t}),Ae.$set(da);const Bt={};f&2&&(Bt.$$scope={dirty:f,ctx:t}),Ie.$set(Bt);const ca={};f&2&&(ca.$$scope={dirty:f,ctx:t}),Me.$set(ca)},i(t){Nl||(q(_.$$.fragment,t),q(R.$$.fragment,t),q(Ke.$$.fragment,t),q(Je.$$.fragment,t),q(Qe.$$.fragment,t),q(Ze.$$.fragment,t),q(et.$$.fragment,t),q(st.$$.fragment,t),q(nt.$$.fragment,t),q(lt.$$.fragment,t),q(ke.$$.fragment,t),q(rt.$$.fragment,t),q(Et.$$.fragment,t),q($t.$$.fragment,t),q(wt.$$.fragment,t),q(Ne.$$.fragment,t),q(je.$$.fragment,t),q(xt.$$.fragment,t),q(bt.$$.fragment,t),q(qe.$$.fragment,t),q(kt.$$.fragment,t),q(Ae.$$.fragment,t),q(yt.$$.fragment,t),q(Ot.$$.fragment,t),q(Tt.$$.fragment,t),q(Nt.$$.fragment,t),q(Ie.$$.fragment,t),q(jt.$$.fragment,t),q(Ct.$$.fragment,t),q(Dt.$$.fragment,t),q(Me.$$.fragment,t),q(qt.$$.fragment,t),q(Lt.$$.fragment,t),q(At.$$.fragment,t),Nl=!0)},o(t){L(_.$$.fragment,t),L(R.$$.fragment,t),L(Ke.$$.fragment,t),L(Je.$$.fragment,t),L(Qe.$$.fragment,t),L(Ze.$$.fragment,t),L(et.$$.fragment,t),L(st.$$.fragment,t),L(nt.$$.fragment,t),L(lt.$$.fragment,t),L(ke.$$.fragment,t),L(rt.$$.fragment,t),L(Et.$$.fragment,t),L($t.$$.fragment,t),L(wt.$$.fragment,t),L(Ne.$$.fragment,t),L(je.$$.fragment,t),L(xt.$$.fragment,t),L(bt.$$.fragment,t),L(qe.$$.fragment,t),L(kt.$$.fragment,t),L(Ae.$$.fragment,t),L(yt.$$.fragment,t),L(Ot.$$.fragment,t),L(Tt.$$.fragment,t),L(Nt.$$.fragment,t),L(Ie.$$.fragment,t),L(jt.$$.fragment,t),L(Ct.$$.fragment,t),L(Dt.$$.fragment,t),L(Me.$$.fragment,t),L(qt.$$.fragment,t),L(Lt.$$.fragment,t),L(At.$$.fragment,t),Nl=!1},d(t){o(c),t&&o($),t&&o(m),A(_),t&&o(T),t&&o(I),t&&o(B),A(R,t),t&&o(Q),t&&o(W),t&&o(Z),t&&o(P),t&&o(Ye),t&&o(J),t&&o(ha),t&&o(Vt),t&&o(ua),t&&o(h),t&&o(ma),t&&o(Ht),t&&o(ga),t&&o(Ee),t&&o(_a),t&&o(de),A(Ke),t&&o(va),t&&o(Wt),t&&o(Ea),A(Je,t),t&&o($a),t&&o(we),t&&o(wa),A(Qe,t),t&&o(xa),t&&o(Gt),t&&o(ba),A(Ze,t),t&&o(ka),t&&o(Yt),t&&o(ya),A(et,t),t&&o(Oa),t&&o(ee),t&&o(Ta),t&&o(G),t&&o(Na),A(st,t),t&&o(ja),t&&o(xe),t&&o(Ca),A(nt,t),t&&o(Da),t&&o(be),t&&o(qa),A(lt,t),t&&o(La),t&&o(Ut),t&&o(Aa),A(ke,t),t&&o(Ia),t&&o(ce),A(rt),t&&o(Pa),t&&o(te),t&&o(Ma),t&&o(Oe),t&&o(Xa),t&&o(Te),t&&o(Ba),A(Et,t),t&&o(Ra),t&&o(oe),t&&o(Fa),A($t,t),t&&o(Sa),t&&o(Jt),t&&o(za),A(wt,t),t&&o(Va),t&&o(Y),t&&o(Ha),A(Ne,t),t&&o(Wa),A(je,t),t&&o(Ga),t&&o(he),A(xt),t&&o(Ya),t&&o(Qt),t&&o(Ua),t&&o(se),t&&o(Ka),t&&o(Zt),t&&o(Ja),t&&o(ue),A(bt),t&&o(Qa),t&&o(eo),t&&o(Za),t&&o(ne),t&&o(el),A(qe,t),t&&o(tl),t&&o(Le),t&&o(ol),A(kt,t),t&&o(sl),t&&o(z),t&&o(nl),A(Ae,t),t&&o(al),t&&o(ro),t&&o(ll),A(yt,t),t&&o(rl),t&&o(io),t&&o(il),A(Ot,t),t&&o(pl),t&&o(po),t&&o(fl),A(Tt,t),t&&o(dl),t&&o(V),t&&o(cl),A(Nt,t),t&&o(hl),A(Ie,t),t&&o(ul),t&&o(me),A(jt),t&&o(ml),t&&o(ae),t&&o(gl),A(Ct,t),t&&o(_l),t&&o(S),t&&o(vl),A(Dt,t),t&&o(El),A(Me,t),t&&o($l),t&&o(ge),A(qt),t&&o(wl),t&&o(le),t&&o(xl),A(Lt,t),t&&o(bl),t&&o(Be),t&&o(kl),t&&o(_e),A(At),t&&o(yl),t&&o(co),t&&o(Ol),t&&o(re),t&&o(Tl),t&&o(Fe)}}}const Dg={local:"export-to-onnx",sections:[{local:"exporting-a-model-to-onnx",title:"Exporting a model to ONNX"},{local:"selecting-features-for-different-model-tasks",title:"Selecting features for different model tasks"},{local:"exporting-a-model-for-an-unsupported-architecture",sections:[{local:"implementing-a-custom-onnx-configuration",title:"Implementing a custom ONNX configuration"},{local:"exporting-the-model",title:"Exporting the model"},{local:"validating-the-model-outputs",title:"Validating the model outputs"}],title:"Exporting a model for an unsupported architecture"},{local:"contributing-a-new-configuration-to-transformers",title:"Contributing a new configuration to \u{1F917} Transformers"}],title:"Export to ONNX"};function qg(M){return _g(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Xg extends hg{constructor(c){super();ug(this,c,qg,Cg,mg,{})}}export{Xg as default,Dg as metadata};
