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