import{S as rE,i as lE,s as iE,e as s,k as d,w as u,t as r,M as pE,c as n,d as o,m as h,a,x as m,h as l,b as f,F as t,g as p,y as g,q as _,o as v,B as w}from"../chunks/vendor-4833417e.js";import{T as gn}from"../chunks/Tip-fffd6df1.js";import{I as S}from"../chunks/IconCopyLink-4b81c553.js";import{C as D}from"../chunks/CodeBlock-6a3d1b46.js";import{C as aE}from"../chunks/CodeBlockFw-27a176a0.js";import"../chunks/CopyButton-dacfbfaf.js";function dE(L){let c,k,E,x,j,y,O,A;return{c(){c=s("p"),k=r("The features that have a "),E=s("code"),x=r("with-past"),j=r(" suffix (e.g. "),y=s("code"),O=r("causal-lm-with-past"),A=r(`)
correspond to model topologies with precomputed hidden states (key and values
in the attention blocks) that can be used for fast autoregressive decoding.`)},l(N){c=n(N,"P",{});var T=a(c);k=l(T,"The features that have a "),E=n(T,"CODE",{});var q=a(E);x=l(q,"with-past"),q.forEach(o),j=l(T," suffix (e.g. "),y=n(T,"CODE",{});var P=a(y);O=l(P,"causal-lm-with-past"),P.forEach(o),A=l(T,`)
correspond to model topologies with precomputed hidden states (key and values
in the attention blocks) that can be used for fast autoregressive decoding.`),T.forEach(o)},m(N,T){p(N,c,T),t(c,k),t(c,E),t(E,x),t(c,j),t(c,y),t(y,O),t(c,A)},d(N){N&&o(c)}}}function hE(L){let c,k,E,x,j;return{c(){c=s("p"),k=r(`A good way to implement a custom ONNX configuration is to look at the existing
implementation in the `),E=s("code"),x=r("configuration_<model_name>.py"),j=r(" file of a similar architecture.")},l(y){c=n(y,"P",{});var O=a(c);k=l(O,`A good way to implement a custom ONNX configuration is to look at the existing
implementation in the `),E=n(O,"CODE",{});var A=a(E);x=l(A,"configuration_<model_name>.py"),A.forEach(o),j=l(O," file of a similar architecture."),O.forEach(o)},m(y,O){p(y,c,O),t(c,k),t(c,E),t(E,x),t(c,j)},d(y){y&&o(c)}}}function fE(L){let c,k,E,x,j,y,O,A,N,T,q,P,z,X,J,F,zt,we,He,U,R,Ee,se;return{c(){c=s("p"),k=r("Notice that "),E=s("code"),x=r("inputs"),j=r(" property for "),y=s("code"),O=r("DistilBertOnnxConfig"),A=r(` returns an
`),N=s("code"),T=r("OrderedDict"),q=r(`. This ensures that the inputs are matched with their relative
position within the `),P=s("code"),z=r("PreTrainedModel.forward()"),X=r(` method when tracing the graph.
We recommend using an `),J=s("code"),F=r("OrderedDict"),zt=r(" for the "),we=s("code"),He=r("inputs"),U=r(" and "),R=s("code"),Ee=r("outputs"),se=r(` properties
when implementing custom ONNX configurations.`)},l($e){c=n($e,"P",{});var C=a(c);k=l(C,"Notice that "),E=n(C,"CODE",{});var hs=a(E);x=l(hs,"inputs"),hs.forEach(o),j=l(C," property for "),y=n(C,"CODE",{});var It=a(y);O=l(It,"DistilBertOnnxConfig"),It.forEach(o),A=l(C,` returns an
`),N=n(C,"CODE",{});var V=a(N);T=l(V,"OrderedDict"),V.forEach(o),q=l(C,`. This ensures that the inputs are matched with their relative
position within the `),P=n(C,"CODE",{});var fs=a(P);z=l(fs,"PreTrainedModel.forward()"),fs.forEach(o),X=l(C,` method when tracing the graph.
We recommend using an `),J=n(C,"CODE",{});var ne=a(J);F=l(ne,"OrderedDict"),ne.forEach(o),zt=l(C," for the "),we=n(C,"CODE",{});var cs=a(we);He=l(cs,"inputs"),cs.forEach(o),U=l(C," and "),R=n(C,"CODE",{});var us=a(R);Ee=l(us,"outputs"),us.forEach(o),se=l(C,` properties
when implementing custom ONNX configurations.`),C.forEach(o)},m($e,C){p($e,c,C),t(c,k),t(c,E),t(E,x),t(c,j),t(c,y),t(y,O),t(c,A),t(c,N),t(N,T),t(c,q),t(c,P),t(P,z),t(c,X),t(c,J),t(J,F),t(c,zt),t(c,we),t(we,He),t(c,U),t(c,R),t(R,Ee),t(c,se)},d($e){$e&&o(c)}}}function cE(L){let c,k,E,x,j,y,O,A;return{c(){c=s("p"),k=r("All of the base properties and methods associated with "),E=s("a"),x=r("OnnxConfig"),j=r(` and the
other configuration classes can be overriden if needed. Check out
`),y=s("code"),O=r("BartOnnxConfig"),A=r(" for an advanced example."),this.h()},l(N){c=n(N,"P",{});var T=a(c);k=l(T,"All of the base properties and methods associated with "),E=n(T,"A",{href:!0});var q=a(E);x=l(q,"OnnxConfig"),q.forEach(o),j=l(T,` and the
other configuration classes can be overriden if needed. Check out
`),y=n(T,"CODE",{});var P=a(y);O=l(P,"BartOnnxConfig"),P.forEach(o),A=l(T," for an advanced example."),T.forEach(o),this.h()},h(){f(E,"href","/docs/transformers/pr_15839/en/main_classes/onnx#transformers.onnx.OnnxConfig")},m(N,T){p(N,c,T),t(c,k),t(c,E),t(E,x),t(c,j),t(c,y),t(y,O),t(c,A)},d(N){N&&o(c)}}}function uE(L){let c,k,E,x,j,y,O,A,N,T,q;return{c(){c=s("p"),k=r(`If your model is larger than 2GB, you will see that many additional files are
created during the export. This is `),E=s("em"),x=r("expected"),j=r(" because ONNX uses "),y=s("a"),O=r(`Protocol
Buffers`),A=r(` to store the model and
these have a size limit of 2GB. See the `),N=s("a"),T=r(`ONNX
documentation`),q=r(`
for instructions on how to load models with external data.`),this.h()},l(P){c=n(P,"P",{});var z=a(c);k=l(z,`If your model is larger than 2GB, you will see that many additional files are
created during the export. This is `),E=n(z,"EM",{});var X=a(E);x=l(X,"expected"),X.forEach(o),j=l(z," because ONNX uses "),y=n(z,"A",{href:!0,rel:!0});var J=a(y);O=l(J,`Protocol
Buffers`),J.forEach(o),A=l(z,` to store the model and
these have a size limit of 2GB. See the `),N=n(z,"A",{href:!0,rel:!0});var F=a(N);T=l(F,`ONNX
documentation`),F.forEach(o),q=l(z,`
for instructions on how to load models with external data.`),z.forEach(o),this.h()},h(){f(y,"href","https://developers.google.com/protocol-buffers/"),f(y,"rel","nofollow"),f(N,"href","https://github.com/onnx/onnx/blob/master/docs/ExternalData.md"),f(N,"rel","nofollow")},m(P,z){p(P,c,z),t(c,k),t(c,E),t(E,x),t(c,j),t(c,y),t(y,O),t(c,A),t(c,N),t(N,T),t(c,q)},d(P){P&&o(c)}}}function mE(L){let c,k;return{c(){c=s("p"),k=r(`This is the very beginning of our experiments with TorchScript and we are still exploring its capabilities with
variable-input-size models. It is a focus of interest to us and we will deepen our analysis in upcoming releases,
with more code examples, a more flexible implementation, and benchmarks comparing python-based codes with compiled
TorchScript.`)},l(E){c=n(E,"P",{});var x=a(c);k=l(x,`This is the very beginning of our experiments with TorchScript and we are still exploring its capabilities with
variable-input-size models. It is a focus of interest to us and we will deepen our analysis in upcoming releases,
with more code examples, a more flexible implementation, and benchmarks comparing python-based codes with compiled
TorchScript.`),x.forEach(o)},m(E,x){p(E,c,x),t(c,k)},d(E){E&&o(c)}}}function gE(L){let c,k,E,x,j,y,O,A,N,T,q,P,z,X,J,F,zt,we,He,U,R,Ee,se,$e,C,hs,It,V,fs,ne,cs,us,_n,vd,wd,dl,ms,Ed,hl,We,$d,vn,bd,yd,fl,gs,xd,cl,$,wn,kd,Td,En,Nd,Od,$n,jd,Ad,bn,Cd,Dd,yn,Pd,Sd,xn,qd,zd,kn,Id,Md,Tn,Bd,Ld,Nn,Xd,Fd,On,Rd,Hd,jn,Wd,Kd,An,Ud,Vd,Cn,Gd,Jd,Dn,Yd,Qd,Pn,Zd,eh,Sn,th,oh,qn,sh,nh,zn,ah,rh,In,lh,ih,Mn,ph,ul,_s,dh,ml,Ke,Mt,hh,Bn,fh,ch,uh,Ln,mh,gl,be,Ue,Xn,Bt,gh,Fn,_h,_l,vs,vh,vl,Lt,wl,Ve,wh,Rn,Eh,$h,El,Xt,$l,ws,bh,bl,Ft,yl,Es,yh,xl,Rt,kl,ae,xh,Hn,kh,Th,Wn,Nh,Oh,Tl,Y,jh,Kn,Ah,Ch,Ht,Dh,Ph,Wt,Sh,qh,Nl,Kt,Ol,Ge,zh,Un,Ih,Mh,jl,Ut,Al,Je,Bh,Vt,Lh,Xh,Cl,Gt,Dl,$s,Fh,Pl,Jt,Sl,re,Rh,Vn,Hh,Wh,Gn,Kh,Uh,ql,Yt,zl,ye,Ye,Jn,Q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,gp,rs,_p,Qs,Ig,vp,ls,wp,Zs,Mg,Ep,Ct,Bg,is,Lg,Xg,$p;return y=new S({}),se=new S({}),Bt=new S({}),Lt=new D({props:{code:"pip install transformers[onnx]",highlighted:"pip install transformers[onnx]"}}),Xt=new D({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.`}}),Ft=new D({props:{code:"python -m transformers.onnx --model=distilbert-base-uncased onnx/",highlighted:"python -m transformers.onnx --model=distilbert-base-uncased onnx/"}}),Rt=new D({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`}}),Kt=new D({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))`}}),Ut=new D({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>]`}}),Gt=new D({props:{code:"python -m transformers.onnx --model=keras-io/transformers-qa onnx/",highlighted:"python -m transformers.onnx --model=keras-io/transformers-qa onnx/"}}),Jt=new aE({props:{group1:{id:"pt",code:`from transformers import AutoTokenizer, AutoModelForSequenceClassification

# Load tokenizer and PyTorch weights form the Hub
tokenizer = 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 = 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>)`},group2:{id:"tf",code:`from transformers import AutoTokenizer, TFAutoModelForSequenceClassification

# Load tokenizer and TensorFlow weights from the Hub
tokenizer = 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 = 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>)`}}}),Yt=new aE({props:{group1:{id:"pt",code:"python -m transformers.onnx --model=local-pt-checkpoint onnx/",highlighted:"python -m transformers.onnx --model=local-pt-checkpoint onnx/"},group2:{id:"tf",code:"python -m transformers.onnx --model=local-tf-checkpoint onnx/",highlighted:"python -m transformers.onnx --model=local-tf-checkpoint onnx/"}}}),Qt=new S({}),ho=new D({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>]`}}),fo=new D({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/`}}),co=new D({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`}}),tt=new gn({props:{$$slots:{default:[dE]},$$scope:{ctx:L}}}),uo=new S({}),mo=new S({}),nt=new gn({props:{$$slots:{default:[hE]},$$scope:{ctx:L}}}),go=new D({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>        )`}}),rt=new gn({props:{$$slots:{default:[fE]},$$scope:{ctx:L}}}),_o=new D({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)`}}),vo=new D({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>`}}),wo=new D({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>})])`}}),Eo=new D({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>})])`}}),lt=new gn({props:{$$slots:{default:[cE]},$$scope:{ctx:L}}}),$o=new S({}),bo=new D({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)`}}),yo=new D({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)`}}),pt=new gn({props:{$$slots:{default:[uE]},$$scope:{ctx:L}}}),xo=new S({}),ko=new D({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>)`}}),To=new S({}),jo=new S({}),mt=new gn({props:{$$slots:{default:[mE]},$$scope:{ctx:L}}}),Do=new S({}),Po=new S({}),So=new S({}),qo=new S({}),zo=new S({}),Io=new D({props:{code:`from transformers import BertModel, BertTokenizer, BertConfig
import torch

enc = BertTokenizer.from_pretrained("bert-base-uncased")

# Tokenizing input text
text = "[CLS] Who was Jim Henson ? [SEP] Jim Henson was a puppeteer [SEP]"
tokenized_text = enc.tokenize(text)

# Masking one of the input tokens
masked_index = 8
tokenized_text[masked_index] = "[MASK]"
indexed_tokens = enc.convert_tokens_to_ids(tokenized_text)
segments_ids = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1]

# Creating a dummy input
tokens_tensor = torch.tensor([indexed_tokens])
segments_tensors = torch.tensor([segments_ids])
dummy_input = [tokens_tensor, segments_tensors]

# Initializing the model with the torchscript flag
# Flag set to True even though it is not necessary as this model does not have an LM Head.
config = BertConfig(
    vocab_size_or_config_json_file=32000,
    hidden_size=768,
    num_hidden_layers=12,
    num_attention_heads=12,
    intermediate_size=3072,
    torchscript=True,
)

# Instantiating the model
model = BertModel(config)

# The model needs to be in evaluation mode
model.eval()

# If you are instantiating the model with *from_pretrained* you can also easily set the TorchScript flag
model = BertModel.from_pretrained("bert-base-uncased", torchscript=True)

# Creating the trace
traced_model = torch.jit.trace(model, [tokens_tensor, segments_tensors])
torch.jit.save(traced_model, "traced_bert.pt")`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BertModel, BertTokenizer, BertConfig
<span class="hljs-keyword">import</span> torch

enc = BertTokenizer.from_pretrained(<span class="hljs-string">&quot;bert-base-uncased&quot;</span>)

<span class="hljs-comment"># Tokenizing input text</span>
text = <span class="hljs-string">&quot;[CLS] Who was Jim Henson ? [SEP] Jim Henson was a puppeteer [SEP]&quot;</span>
tokenized_text = enc.tokenize(text)

<span class="hljs-comment"># Masking one of the input tokens</span>
masked_index = <span class="hljs-number">8</span>
tokenized_text[masked_index] = <span class="hljs-string">&quot;[MASK]&quot;</span>
indexed_tokens = enc.convert_tokens_to_ids(tokenized_text)
segments_ids = [<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>]

<span class="hljs-comment"># Creating a dummy input</span>
tokens_tensor = torch.tensor([indexed_tokens])
segments_tensors = torch.tensor([segments_ids])
dummy_input = [tokens_tensor, segments_tensors]

<span class="hljs-comment"># Initializing the model with the torchscript flag</span>
<span class="hljs-comment"># Flag set to True even though it is not necessary as this model does not have an LM Head.</span>
config = BertConfig(
    vocab_size_or_config_json_file=<span class="hljs-number">32000</span>,
    hidden_size=<span class="hljs-number">768</span>,
    num_hidden_layers=<span class="hljs-number">12</span>,
    num_attention_heads=<span class="hljs-number">12</span>,
    intermediate_size=<span class="hljs-number">3072</span>,
    torchscript=<span class="hljs-literal">True</span>,
)

<span class="hljs-comment"># Instantiating the model</span>
model = BertModel(config)

<span class="hljs-comment"># The model needs to be in evaluation mode</span>
model.<span class="hljs-built_in">eval</span>()

<span class="hljs-comment"># If you are instantiating the model with *from_pretrained* you can also easily set the TorchScript flag</span>
model = BertModel.from_pretrained(<span class="hljs-string">&quot;bert-base-uncased&quot;</span>, torchscript=<span class="hljs-literal">True</span>)

<span class="hljs-comment"># Creating the trace</span>
traced_model = torch.jit.trace(model, [tokens_tensor, segments_tensors])
torch.jit.save(traced_model, <span class="hljs-string">&quot;traced_bert.pt&quot;</span>)`}}),Mo=new S({}),Bo=new D({props:{code:`loaded_model = torch.jit.load("traced_bert.pt")
loaded_model.eval()

all_encoder_layers, pooled_output = loaded_model(*dummy_input)`,highlighted:`loaded_model = torch.jit.load(<span class="hljs-string">&quot;traced_bert.pt&quot;</span>)
loaded_model.<span class="hljs-built_in">eval</span>()

all_encoder_layers, pooled_output = loaded_model(*dummy_input)`}}),Lo=new S({}),Xo=new D({props:{code:"traced_model(tokens_tensor, segments_tensors)",highlighted:"traced_model(tokens_tensor, segments_tensors)"}}),Fo=new S({}),Vo=new S({}),es=new S({}),ss=new S({}),as=new D({props:{code:`from transformers import BertModel, BertTokenizer, BertConfig
import torch
import torch.neuron`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BertModel, BertTokenizer, BertConfig
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> torch.neuron`}}),rs=new D({props:{code:"torch.jit.trace(model, [tokens_tensor, segments_tensors])",highlighted:"torch.jit.trace(model, [tokens_tensor, segments_tensors])"}}),ls=new D({props:{code:"torch.neuron.trace(model, [token_tensor, segments_tensors])",highlighted:"torch.neuron.trace(model, [token_tensor, segments_tensors])"}}),{c(){c=s("meta"),k=d(),E=s("h1"),x=s("a"),j=s("span"),u(y.$$.fragment),O=d(),A=s("span"),N=r("Exporting \u{1F917} Transformers Models"),T=d(),q=s("p"),P=r(`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 in two widely used formats: ONNX and TorchScript.`),z=d(),X=s("p"),J=r(`Once exported, a model can 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 `),F=s("a"),zt=r(`\u{1F917} Optimum
library`),we=r("."),He=d(),U=s("h2"),R=s("a"),Ee=s("span"),u(se.$$.fragment),$e=d(),C=s("span"),hs=r("ONNX"),It=d(),V=s("p"),fs=r("The "),ne=s("a"),cs=r("ONNX (Open Neural Network eXchange)"),us=r(` project 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
`),_n=s("em"),vd=r("intermediate representation"),wd=r(`) which represents the flow of data through the
neural network.`),dl=d(),ms=s("p"),Ed=r(`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).`),hl=d(),We=s("p"),$d=r("\u{1F917} Transformers provides a "),vn=s("code"),bd=r("transformers.onnx"),yd=r(` 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.`),fl=d(),gs=s("p"),xd=r("Ready-made configurations include the following architectures:"),cl=d(),$=s("ul"),wn=s("li"),kd=r("ALBERT"),Td=d(),En=s("li"),Nd=r("BART"),Od=d(),$n=s("li"),jd=r("BERT"),Ad=d(),bn=s("li"),Cd=r("CamemBERT"),Dd=d(),yn=s("li"),Pd=r("Data2VecText"),Sd=d(),xn=s("li"),qd=r("DistilBERT"),zd=d(),kn=s("li"),Id=r("ELECTRA"),Md=d(),Tn=s("li"),Bd=r("GPT Neo"),Ld=d(),Nn=s("li"),Xd=r("I-BERT"),Fd=d(),On=s("li"),Rd=r("LayoutLM"),Hd=d(),jn=s("li"),Wd=r("M2M100"),Kd=d(),An=s("li"),Ud=r("Marian"),Vd=d(),Cn=s("li"),Gd=r("mBART"),Jd=d(),Dn=s("li"),Yd=r("OpenAI GPT-2"),Qd=d(),Pn=s("li"),Zd=r("PLBart"),eh=d(),Sn=s("li"),th=r("RoBERTa"),oh=d(),qn=s("li"),sh=r("T5"),nh=d(),zn=s("li"),ah=r("ViT"),rh=d(),In=s("li"),lh=r("XLM-RoBERTa"),ih=d(),Mn=s("li"),ph=r("XLM-RoBERTa-XL"),ul=d(),_s=s("p"),dh=r("In the next two sections, we\u2019ll show you how to:"),ml=d(),Ke=s("ul"),Mt=s("li"),hh=r("Export a supported model using the "),Bn=s("code"),fh=r("transformers.onnx"),ch=r(" package."),uh=d(),Ln=s("li"),mh=r("Export a custom model for an unsupported architecture."),gl=d(),be=s("h3"),Ue=s("a"),Xn=s("span"),u(Bt.$$.fragment),gh=d(),Fn=s("span"),_h=r("Exporting a model to ONNX"),_l=d(),vs=s("p"),vh=r(`To export a \u{1F917} Transformers model to ONNX, you\u2019ll first need to install some
extra dependencies:`),vl=d(),u(Lt.$$.fragment),wl=d(),Ve=s("p"),wh=r("The "),Rn=s("code"),Eh=r("transformers.onnx"),$h=r(" package can then be used as a Python module:"),El=d(),u(Xt.$$.fragment),$l=d(),ws=s("p"),bh=r("Exporting a checkpoint using a ready-made configuration can be done as follows:"),bl=d(),u(Ft.$$.fragment),yl=d(),Es=s("p"),yh=r("which should show the following logs:"),xl=d(),u(Rt.$$.fragment),kl=d(),ae=s("p"),xh=r("This exports an ONNX graph of the checkpoint defined by the "),Hn=s("code"),kh=r("--model"),Th=r(` argument.
In this example it is `),Wn=s("code"),Nh=r("distilbert-base-uncased"),Oh=r(`, but it can be any checkpoint on
the Hugging Face Hub or one that\u2019s stored locally.`),Tl=d(),Y=s("p"),jh=r("The resulting "),Kn=s("code"),Ah=r("model.onnx"),Ch=r(" file can then be run on one of the "),Ht=s("a"),Dh=r(`many
accelerators`),Ph=r(` that support the
ONNX standard. For example, we can load and run the model with `),Wt=s("a"),Sh=r(`ONNX
Runtime`),qh=r(" as follows:"),Nl=d(),u(Kt.$$.fragment),Ol=d(),Ge=s("p"),zh=r("The required output names (i.e. "),Un=s("code"),Ih=r('["last_hidden_state"]'),Mh=r(`) can be obtained by
taking a look at the ONNX configuration of each model. For example, for
DistilBERT we have:`),jl=d(),u(Ut.$$.fragment),Al=d(),Je=s("p"),Bh=r(`The process is identical for TensorFlow checkpoints on the Hub. For example, we
can export a pure TensorFlow checkpoint from the `),Vt=s("a"),Lh=r(`Keras
organization`),Xh=r(" as follows:"),Cl=d(),u(Gt.$$.fragment),Dl=d(),$s=s("p"),Fh=r(`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:`),Pl=d(),u(Jt.$$.fragment),Sl=d(),re=s("p"),Rh=r("Once the checkpoint is saved, we can export it to ONNX by pointing the "),Vn=s("code"),Hh=r("--model"),Wh=r(`
argument of the `),Gn=s("code"),Kh=r("transformers.onnx"),Uh=r(" package to the desired directory:"),ql=d(),u(Yt.$$.fragment),zl=d(),ye=s("h3"),Ye=s("a"),Jn=s("span"),u(Qt.$$.fragment),Vh=d(),Yn=s("span"),Gh=r("Selecting features for different model topologies"),Il=d(),Qe=s("p"),Jh=r("Each ready-made configuration comes with a set of "),Qn=s("em"),Yh=r("features"),Qh=r(` that enable you to
export models for different types of topologies or tasks. As shown in the table
below, each feature is associated with a different auto class:`),Ml=d(),Ze=s("table"),Zn=s("thead"),Zt=s("tr"),ea=s("th"),Zh=r("Feature"),ef=d(),ta=s("th"),tf=r("Auto Class"),of=d(),I=s("tbody"),eo=s("tr"),to=s("td"),oa=s("code"),sf=r("causal-lm"),nf=r(", "),sa=s("code"),af=r("causal-lm-with-past"),rf=d(),na=s("td"),aa=s("code"),lf=r("AutoModelForCausalLM"),pf=d(),oo=s("tr"),so=s("td"),ra=s("code"),df=r("default"),hf=r(", "),la=s("code"),ff=r("default-with-past"),cf=d(),ia=s("td"),pa=s("code"),uf=r("AutoModel"),mf=d(),no=s("tr"),da=s("td"),ha=s("code"),gf=r("masked-lm"),_f=d(),fa=s("td"),ca=s("code"),vf=r("AutoModelForMaskedLM"),wf=d(),ao=s("tr"),ua=s("td"),ma=s("code"),Ef=r("question-answering"),$f=d(),ga=s("td"),_a=s("code"),bf=r("AutoModelForQuestionAnswering"),yf=d(),ro=s("tr"),lo=s("td"),va=s("code"),xf=r("seq2seq-lm"),kf=r(", "),wa=s("code"),Tf=r("seq2seq-lm-with-past"),Nf=d(),Ea=s("td"),$a=s("code"),Of=r("AutoModelForSeq2SeqLM"),jf=d(),io=s("tr"),ba=s("td"),ya=s("code"),Af=r("sequence-classification"),Cf=d(),xa=s("td"),ka=s("code"),Df=r("AutoModelForSequenceClassification"),Pf=d(),po=s("tr"),Ta=s("td"),Na=s("code"),Sf=r("token-classification"),qf=d(),Oa=s("td"),ja=s("code"),zf=r("AutoModelForTokenClassification"),Bl=d(),et=s("p"),If=r(`For each configuration, you can find the list of supported features via the
`),Aa=s("code"),Mf=r("FeaturesManager"),Bf=r(". For example, for DistilBERT we have:"),Ll=d(),u(ho.$$.fragment),Xl=d(),le=s("p"),Lf=r("You can then pass one of these features to the "),Ca=s("code"),Xf=r("--feature"),Ff=r(` argument in the
`),Da=s("code"),Rf=r("transformers.onnx"),Hf=r(` package. For example, to export a text-classification model
we can pick a fine-tuned model from the Hub and run:`),Fl=d(),u(fo.$$.fragment),Rl=d(),bs=s("p"),Wf=r("which will display the following logs:"),Hl=d(),u(co.$$.fragment),Wl=d(),Q=s("p"),Kf=r(`Notice that in this case, the output names from the fine-tuned model are
`),Pa=s("code"),Uf=r("logits"),Vf=r(" instead of the "),Sa=s("code"),Gf=r("last_hidden_state"),Jf=r(` we saw with the
`),qa=s("code"),Yf=r("distilbert-base-uncased"),Qf=r(` checkpoint earlier. This is expected since the
fine-tuned model has a sequence classification head.`),Kl=d(),u(tt.$$.fragment),Ul=d(),xe=s("h3"),ot=s("a"),za=s("span"),u(uo.$$.fragment),Zf=d(),Ia=s("span"),ec=r("Exporting a model for an unsupported architecture"),Vl=d(),ys=s("p"),tc=r(`If you wish to export a model whose architecture is not natively supported by
the library, there are three main steps to follow:`),Gl=d(),ie=s("ol"),Ma=s("li"),oc=r("Implement a custom ONNX configuration."),sc=d(),Ba=s("li"),nc=r("Export the model to ONNX."),ac=d(),La=s("li"),rc=r("Validate the outputs of the PyTorch and exported models."),Jl=d(),xs=s("p"),lc=r(`In this section, we\u2019ll look at how DistilBERT was implemented to show what\u2019s
involved with each step.`),Yl=d(),ke=s("h4"),st=s("a"),Xa=s("span"),u(mo.$$.fragment),ic=d(),Fa=s("span"),pc=r("Implementing a custom ONNX configuration"),Ql=d(),ks=s("p"),dc=r(`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:`),Zl=d(),pe=s("ul"),Ts=s("li"),hc=r("Encoder-based models inherit from "),Ns=s("a"),fc=r("OnnxConfig"),cc=d(),Os=s("li"),uc=r("Decoder-based models inherit from "),js=s("a"),mc=r("OnnxConfigWithPast"),gc=d(),As=s("li"),_c=r("Encoder-decoder models inherit from "),Cs=s("a"),vc=r("OnnxSeq2SeqConfigWithPast"),ei=d(),u(nt.$$.fragment),ti=d(),at=s("p"),wc=r(`Since DistilBERT is an encoder-based model, its configuration inherits from
`),Ra=s("code"),Ec=r("OnnxConfig"),$c=r(":"),oi=d(),u(go.$$.fragment),si=d(),H=s("p"),bc=r("Every configuration object must implement the "),Ha=s("code"),yc=r("inputs"),xc=r(` 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: `),Wa=s("code"),kc=r("input_ids"),Tc=r(" and "),Ka=s("code"),Nc=r("attention_mask"),Oc=r(`. These inputs have the same shape of
`),Ua=s("code"),jc=r("(batch_size, sequence_length)"),Ac=r(` which is why we see the same axes used in the
configuration.`),ni=d(),u(rt.$$.fragment),ai=d(),Ds=s("p"),Cc=r(`Once you have implemented an ONNX configuration, you can instantiate it by
providing the base model\u2019s configuration as follows:`),ri=d(),u(_o.$$.fragment),li=d(),Ps=s("p"),Dc=r(`The resulting object has several useful properties. For example you can view the
ONNX operator set that will be used during the export:`),ii=d(),u(vo.$$.fragment),pi=d(),Ss=s("p"),Pc=r("You can also view the outputs associated with the model as follows:"),di=d(),u(wo.$$.fragment),hi=d(),W=s("p"),Sc=r(`Notice that the outputs property follows the same structure as the inputs; it
returns an `),Va=s("code"),qc=r("OrderedDict"),zc=r(` 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 `),Ga=s("code"),Ic=r("default"),Mc=r(` feature
that corresponds to exporting a model loaded with the `),Ja=s("code"),Bc=r("AutoModel"),Lc=r(` class. If you
want to export a different model topology, just provide a different feature to
the `),Ya=s("code"),Xc=r("task"),Fc=r(` argument when you initialize the ONNX configuration. For example, if
we wished to export DistilBERT with a sequence classification head, we could
use:`),fi=d(),u(Eo.$$.fragment),ci=d(),u(lt.$$.fragment),ui=d(),Te=s("h4"),it=s("a"),Qa=s("span"),u($o.$$.fragment),Rc=d(),Za=s("span"),Hc=r("Exporting the model"),mi=d(),de=s("p"),Wc=r(`Once you have implemented the ONNX configuration, the next step is to export the
model. Here we can use the `),er=s("code"),Kc=r("export()"),Uc=r(` function provided by the
`),tr=s("code"),Vc=r("transformers.onnx"),Gc=r(` package. This function expects the ONNX configuration, along
with the base model and tokenizer, and the path to save the exported file:`),gi=d(),u(bo.$$.fragment),_i=d(),M=s("p"),Jc=r("The "),or=s("code"),Yc=r("onnx_inputs"),Qc=r(" and "),sr=s("code"),Zc=r("onnx_outputs"),eu=r(" returned by the "),nr=s("code"),tu=r("export()"),ou=r(` function are
lists of the keys defined in the `),ar=s("code"),su=r("inputs"),nu=r(" and "),rr=s("code"),au=r("outputs"),ru=r(` properties of the
configuration. Once the model is exported, you can test that the model is well
formed as follows:`),vi=d(),u(yo.$$.fragment),wi=d(),u(pt.$$.fragment),Ei=d(),Ne=s("h4"),dt=s("a"),lr=s("span"),u(xo.$$.fragment),lu=d(),ir=s("span"),iu=r("Validating the model outputs"),$i=d(),he=s("p"),pu=r(`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
`),pr=s("code"),du=r("validate_model_outputs()"),hu=r(" function provided by the "),dr=s("code"),fu=r("transformers.onnx"),cu=r(` package
as follows:`),bi=d(),u(ko.$$.fragment),yi=d(),ht=s("p"),uu=r("This function uses the "),hr=s("code"),mu=r("OnnxConfig.generate_dummy_inputs()"),gu=r(` 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.`),xi=d(),Oe=s("h3"),ft=s("a"),fr=s("span"),u(To.$$.fragment),_u=d(),cr=s("span"),vu=r("Contributing a new configuration to \u{1F917} Transformers"),ki=d(),qs=s("p"),wu=r(`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:`),Ti=d(),fe=s("ul"),No=s("li"),Eu=r("Implement the ONNX configuration in the corresponding "),ur=s("code"),$u=r("configuration_<model_name>.py"),bu=r(`
file`),yu=d(),zs=s("li"),xu=r("Include the model architecture and corresponding features in "),mr=s("code"),ku=r("FeatureManager"),Tu=d(),Is=s("li"),Nu=r("Add your model architecture to the tests in "),gr=s("code"),Ou=r("test_onnx_v2.py"),Ni=d(),ct=s("p"),ju=r("Check out how the configuration for "),Oo=s("a"),Au=r(`IBERT was
contributed`),Cu=r(` to
get an idea of what\u2019s involved.`),Oi=d(),je=s("h2"),ut=s("a"),_r=s("span"),u(jo.$$.fragment),Du=d(),vr=s("span"),Pu=r("TorchScript"),ji=d(),u(mt.$$.fragment),Ai=d(),gt=s("p"),Su=r(`According to Pytorch\u2019s documentation: \u201CTorchScript is a way to create serializable and optimizable models from PyTorch
code\u201D. Pytorch\u2019s two modules `),Ao=s("a"),qu=r("JIT and TRACE"),zu=r(` allow the developer to export
their model to be re-used in other programs, such as efficiency-oriented C++ programs.`),Ci=d(),Ms=s("p"),Iu=r(`We have provided an interface that allows the export of \u{1F917} Transformers models to TorchScript so that they can be reused
in a different environment than a Pytorch-based python program. Here we explain how to export and use our models using
TorchScript.`),Di=d(),Bs=s("p"),Mu=r("Exporting a model requires two things:"),Pi=d(),_t=s("ul"),wr=s("li"),Bu=r("a forward pass with dummy inputs."),Lu=d(),Co=s("li"),Xu=r("model instantiation with the "),Er=s("code"),Fu=r("torchscript"),Ru=r(" flag."),Si=d(),Ls=s("p"),Hu=r("These necessities imply several things developers should be careful about. These are detailed below."),qi=d(),Ae=s("h3"),vt=s("a"),$r=s("span"),u(Do.$$.fragment),Wu=d(),br=s("span"),Ku=r("Implications"),zi=d(),Ce=s("h3"),wt=s("a"),yr=s("span"),u(Po.$$.fragment),Uu=d(),xr=s("span"),Vu=r("TorchScript flag and tied weights"),Ii=d(),ce=s("p"),Gu=r(`This flag is necessary because most of the language models in this repository have tied weights between their
`),kr=s("code"),Ju=r("Embedding"),Yu=r(" layer and their "),Tr=s("code"),Qu=r("Decoding"),Zu=r(` layer. TorchScript does not allow the export of models that have tied
weights, therefore it is necessary to untie and clone the weights beforehand.`),Mi=d(),Z=s("p"),em=r("This implies that models instantiated with the "),Nr=s("code"),tm=r("torchscript"),om=r(" flag have their "),Or=s("code"),sm=r("Embedding"),nm=r(" layer and "),jr=s("code"),am=r("Decoding"),rm=r(`
layer separate, which means that they should not be trained down the line. Training would de-synchronize the two
layers, leading to unexpected results.`),Bi=d(),Et=s("p"),lm=r(`This is not the case for models that do not have a Language Model head, as those do not have tied weights. These models
can be safely exported without the `),Ar=s("code"),im=r("torchscript"),pm=r(" flag."),Li=d(),De=s("h3"),$t=s("a"),Cr=s("span"),u(So.$$.fragment),dm=d(),Dr=s("span"),hm=r("Dummy inputs and standard lengths"),Xi=d(),Xs=s("p"),fm=r(`The dummy inputs are used to do a model forward pass. While the inputs\u2019 values are propagating through the layers,
Pytorch keeps track of the different operations executed on each tensor. These recorded operations are then used to
create the \u201Ctrace\u201D of the model.`),Fi=d(),Fs=s("p"),cm=r(`The trace is created relatively to the inputs\u2019 dimensions. It is therefore constrained by the dimensions of the dummy
input, and will not work for any other sequence length or batch size. When trying with a different size, an error such
as:`),Ri=d(),Rs=s("p"),Pr=s("code"),um=r("The expanded size of the tensor (3) must match the existing size (7) at non-singleton dimension 2"),Hi=d(),Hs=s("p"),mm=r(`will be raised. It is therefore recommended to trace the model with a dummy input size at least as large as the largest
input that will be fed to the model during inference. Padding can be performed to fill the missing values. As the model
will have been traced with a large input size however, the dimensions of the different matrix will be large as well,
resulting in more calculations.`),Wi=d(),Ws=s("p"),gm=r(`It is recommended to be careful of the total number of operations done on each input and to follow performance closely
when exporting varying sequence-length models.`),Ki=d(),Pe=s("h3"),bt=s("a"),Sr=s("span"),u(qo.$$.fragment),_m=d(),qr=s("span"),vm=r("Using TorchScript in Python"),Ui=d(),Ks=s("p"),wm=r("Below is an example, showing how to save, load models as well as how to use the trace for inference."),Vi=d(),Se=s("h4"),yt=s("a"),zr=s("span"),u(zo.$$.fragment),Em=d(),Ir=s("span"),$m=r("Saving a model"),Gi=d(),G=s("p"),bm=r("This snippet shows how to use TorchScript to export a "),Mr=s("code"),ym=r("BertModel"),xm=r(". Here the "),Br=s("code"),km=r("BertModel"),Tm=r(` is instantiated according
to a `),Lr=s("code"),Nm=r("BertConfig"),Om=r(" class and then saved to disk under the filename "),Xr=s("code"),jm=r("traced_bert.pt"),Ji=d(),u(Io.$$.fragment),Yi=d(),qe=s("h4"),xt=s("a"),Fr=s("span"),u(Mo.$$.fragment),Am=d(),Rr=s("span"),Cm=r("Loading a model"),Qi=d(),ee=s("p"),Dm=r("This snippet shows how to load the "),Hr=s("code"),Pm=r("BertModel"),Sm=r(" that was previously saved to disk under the name "),Wr=s("code"),qm=r("traced_bert.pt"),zm=r(`.
We are re-using the previously initialised `),Kr=s("code"),Im=r("dummy_input"),Mm=r("."),Zi=d(),u(Bo.$$.fragment),ep=d(),ze=s("h4"),kt=s("a"),Ur=s("span"),u(Lo.$$.fragment),Bm=d(),Vr=s("span"),Lm=r("Using a traced model for inference"),tp=d(),Tt=s("p"),Xm=r("Using the traced model for inference is as simple as using its "),Gr=s("code"),Fm=r("__call__"),Rm=r(" dunder method:"),op=d(),u(Xo.$$.fragment),sp=d(),Ie=s("h3"),Nt=s("a"),Jr=s("span"),u(Fo.$$.fragment),Hm=d(),Yr=s("span"),Wm=r("Deploying HuggingFace TorchScript models on AWS using the Neuron SDK"),np=d(),ue=s("p"),Km=r("AWS introduced the "),Ro=s("a"),Um=r("Amazon EC2 Inf1"),Vm=r(`
instance family for low cost, high performance machine learning inference in the cloud.
The Inf1 instances are powered by the AWS Inferentia chip, a custom-built hardware accelerator,
specializing in deep learning inferencing workloads.
`),Ho=s("a"),Gm=r("AWS Neuron"),Jm=r(`
is the SDK for Inferentia that supports tracing and optimizing transformers models for
deployment on Inf1. The Neuron SDK provides:`),ap=d(),me=s("ol"),Qr=s("li"),Ym=r("Easy-to-use API with one line of code change to trace and optimize a TorchScript model for inference in the cloud."),Qm=d(),Us=s("li"),Zm=r("Out of the box performance optimizations for "),Wo=s("a"),eg=r("improved cost-performance"),tg=d(),Me=s("li"),og=r("Support for HuggingFace transformers models built with either "),Ko=s("a"),sg=r("PyTorch"),ng=r(`
or `),Uo=s("a"),ag=r("TensorFlow"),rg=r("."),rp=d(),Be=s("h4"),Ot=s("a"),Zr=s("span"),u(Vo.$$.fragment),lg=d(),el=s("span"),ig=r("Implications"),lp=d(),B=s("p"),pg=r("Transformers Models based on the "),Go=s("a"),dg=r("BERT (Bidirectional Encoder Representations from Transformers)"),hg=r(`
architecture, or its variants such as `),Jo=s("a"),fg=r("distilBERT"),cg=r(`
and `),Yo=s("a"),ug=r("roBERTa"),mg=r(`
will run best on Inf1 for non-generative tasks such as Extractive Question Answering,
Sequence Classification, Token Classification. Alternatively, text generation
tasks can be adapted to run on Inf1, according to this `),Qo=s("a"),gg=r("AWS Neuron MarianMT tutorial"),_g=r(`.
More information about models that can be converted out of the box on Inferentia can be
found in the `),Zo=s("a"),vg=r("Model Architecture Fit section of the Neuron documentation"),wg=r("."),ip=d(),Le=s("h4"),jt=s("a"),tl=s("span"),u(es.$$.fragment),Eg=d(),ol=s("span"),$g=r("Dependencies"),pp=d(),Vs=s("p"),bg=r("Using AWS Neuron to convert models requires the following dependencies and environment:"),dp=d(),Gs=s("ul"),Xe=s("li"),yg=r("A "),ts=s("a"),xg=r("Neuron SDK environment"),kg=r(`,
which comes pre-configured on `),os=s("a"),Tg=r("AWS Deep Learning AMI"),Ng=r("."),hp=d(),Fe=s("h4"),At=s("a"),sl=s("span"),u(ss.$$.fragment),Og=d(),nl=s("span"),jg=r("Converting a Model for AWS Neuron"),fp=d(),ge=s("p"),Ag=r("Using the same script as in "),ns=s("a"),Cg=r("Using TorchScript in Python"),Dg=r(`
to trace a \u201CBertModel\u201D, you import `),al=s("code"),Pg=r("torch.neuron"),Sg=r(` framework extension to access
the components of the Neuron SDK through a Python API.`),cp=d(),u(as.$$.fragment),up=d(),Js=s("p"),qg=r("And only modify the tracing line of code"),mp=d(),Ys=s("p"),zg=r("from:"),gp=d(),u(rs.$$.fragment),_p=d(),Qs=s("p"),Ig=r("to:"),vp=d(),u(ls.$$.fragment),wp=d(),Zs=s("p"),Mg=r("This change enables Neuron SDK to trace the model and optimize it to run in Inf1 instances."),Ep=d(),Ct=s("p"),Bg=r(`To learn more about AWS Neuron SDK features, tools, example tutorials and latest updates,
please see the `),is=s("a"),Lg=r("AWS NeuronSDK documentation"),Xg=r("."),this.h()},l(e){const i=pE('[data-svelte="svelte-1phssyn"]',document.head);c=n(i,"META",{name:!0,content:!0}),i.forEach(o),k=h(e),E=n(e,"H1",{class:!0});var ps=a(E);x=n(ps,"A",{id:!0,class:!0,href:!0});var rl=a(x);j=n(rl,"SPAN",{});var ll=a(j);m(y.$$.fragment,ll),ll.forEach(o),rl.forEach(o),O=h(ps),A=n(ps,"SPAN",{});var il=a(A);N=l(il,"Exporting \u{1F917} Transformers Models"),il.forEach(o),ps.forEach(o),T=h(e),q=n(e,"P",{});var pl=a(q);P=l(pl,`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 in two widely used formats: ONNX and TorchScript.`),pl.forEach(o),z=h(e),X=n(e,"P",{});var ds=a(X);J=l(ds,`Once exported, a model can 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 `),F=n(ds,"A",{href:!0,rel:!0});var Vg=a(F);zt=l(Vg,`\u{1F917} Optimum
library`),Vg.forEach(o),we=l(ds,"."),ds.forEach(o),He=h(e),U=n(e,"H2",{class:!0});var bp=a(U);R=n(bp,"A",{id:!0,class:!0,href:!0});var Gg=a(R);Ee=n(Gg,"SPAN",{});var Jg=a(Ee);m(se.$$.fragment,Jg),Jg.forEach(o),Gg.forEach(o),$e=h(bp),C=n(bp,"SPAN",{});var Yg=a(C);hs=l(Yg,"ONNX"),Yg.forEach(o),bp.forEach(o),It=h(e),V=n(e,"P",{});var en=a(V);fs=l(en,"The "),ne=n(en,"A",{href:!0,rel:!0});var Qg=a(ne);cs=l(Qg,"ONNX (Open Neural Network eXchange)"),Qg.forEach(o),us=l(en,` project 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
`),_n=n(en,"EM",{});var Zg=a(_n);vd=l(Zg,"intermediate representation"),Zg.forEach(o),wd=l(en,`) which represents the flow of data through the
neural network.`),en.forEach(o),dl=h(e),ms=n(e,"P",{});var e_=a(ms);Ed=l(e_,`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).`),e_.forEach(o),hl=h(e),We=n(e,"P",{});var yp=a(We);$d=l(yp,"\u{1F917} Transformers provides a "),vn=n(yp,"CODE",{});var t_=a(vn);bd=l(t_,"transformers.onnx"),t_.forEach(o),yd=l(yp,` 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.`),yp.forEach(o),fl=h(e),gs=n(e,"P",{});var o_=a(gs);xd=l(o_,"Ready-made configurations include the following architectures:"),o_.forEach(o),cl=h(e),$=n(e,"UL",{});var b=a($);wn=n(b,"LI",{});var s_=a(wn);kd=l(s_,"ALBERT"),s_.forEach(o),Td=h(b),En=n(b,"LI",{});var n_=a(En);Nd=l(n_,"BART"),n_.forEach(o),Od=h(b),$n=n(b,"LI",{});var a_=a($n);jd=l(a_,"BERT"),a_.forEach(o),Ad=h(b),bn=n(b,"LI",{});var r_=a(bn);Cd=l(r_,"CamemBERT"),r_.forEach(o),Dd=h(b),yn=n(b,"LI",{});var l_=a(yn);Pd=l(l_,"Data2VecText"),l_.forEach(o),Sd=h(b),xn=n(b,"LI",{});var i_=a(xn);qd=l(i_,"DistilBERT"),i_.forEach(o),zd=h(b),kn=n(b,"LI",{});var p_=a(kn);Id=l(p_,"ELECTRA"),p_.forEach(o),Md=h(b),Tn=n(b,"LI",{});var d_=a(Tn);Bd=l(d_,"GPT Neo"),d_.forEach(o),Ld=h(b),Nn=n(b,"LI",{});var h_=a(Nn);Xd=l(h_,"I-BERT"),h_.forEach(o),Fd=h(b),On=n(b,"LI",{});var f_=a(On);Rd=l(f_,"LayoutLM"),f_.forEach(o),Hd=h(b),jn=n(b,"LI",{});var c_=a(jn);Wd=l(c_,"M2M100"),c_.forEach(o),Kd=h(b),An=n(b,"LI",{});var u_=a(An);Ud=l(u_,"Marian"),u_.forEach(o),Vd=h(b),Cn=n(b,"LI",{});var m_=a(Cn);Gd=l(m_,"mBART"),m_.forEach(o),Jd=h(b),Dn=n(b,"LI",{});var g_=a(Dn);Yd=l(g_,"OpenAI GPT-2"),g_.forEach(o),Qd=h(b),Pn=n(b,"LI",{});var __=a(Pn);Zd=l(__,"PLBart"),__.forEach(o),eh=h(b),Sn=n(b,"LI",{});var v_=a(Sn);th=l(v_,"RoBERTa"),v_.forEach(o),oh=h(b),qn=n(b,"LI",{});var w_=a(qn);sh=l(w_,"T5"),w_.forEach(o),nh=h(b),zn=n(b,"LI",{});var E_=a(zn);ah=l(E_,"ViT"),E_.forEach(o),rh=h(b),In=n(b,"LI",{});var $_=a(In);lh=l($_,"XLM-RoBERTa"),$_.forEach(o),ih=h(b),Mn=n(b,"LI",{});var b_=a(Mn);ph=l(b_,"XLM-RoBERTa-XL"),b_.forEach(o),b.forEach(o),ul=h(e),_s=n(e,"P",{});var y_=a(_s);dh=l(y_,"In the next two sections, we\u2019ll show you how to:"),y_.forEach(o),ml=h(e),Ke=n(e,"UL",{});var xp=a(Ke);Mt=n(xp,"LI",{});var kp=a(Mt);hh=l(kp,"Export a supported model using the "),Bn=n(kp,"CODE",{});var x_=a(Bn);fh=l(x_,"transformers.onnx"),x_.forEach(o),ch=l(kp," package."),kp.forEach(o),uh=h(xp),Ln=n(xp,"LI",{});var k_=a(Ln);mh=l(k_,"Export a custom model for an unsupported architecture."),k_.forEach(o),xp.forEach(o),gl=h(e),be=n(e,"H3",{class:!0});var Tp=a(be);Ue=n(Tp,"A",{id:!0,class:!0,href:!0});var T_=a(Ue);Xn=n(T_,"SPAN",{});var N_=a(Xn);m(Bt.$$.fragment,N_),N_.forEach(o),T_.forEach(o),gh=h(Tp),Fn=n(Tp,"SPAN",{});var O_=a(Fn);_h=l(O_,"Exporting a model to ONNX"),O_.forEach(o),Tp.forEach(o),_l=h(e),vs=n(e,"P",{});var j_=a(vs);vh=l(j_,`To export a \u{1F917} Transformers model to ONNX, you\u2019ll first need to install some
extra dependencies:`),j_.forEach(o),vl=h(e),m(Lt.$$.fragment,e),wl=h(e),Ve=n(e,"P",{});var Np=a(Ve);wh=l(Np,"The "),Rn=n(Np,"CODE",{});var A_=a(Rn);Eh=l(A_,"transformers.onnx"),A_.forEach(o),$h=l(Np," package can then be used as a Python module:"),Np.forEach(o),El=h(e),m(Xt.$$.fragment,e),$l=h(e),ws=n(e,"P",{});var C_=a(ws);bh=l(C_,"Exporting a checkpoint using a ready-made configuration can be done as follows:"),C_.forEach(o),bl=h(e),m(Ft.$$.fragment,e),yl=h(e),Es=n(e,"P",{});var D_=a(Es);yh=l(D_,"which should show the following logs:"),D_.forEach(o),xl=h(e),m(Rt.$$.fragment,e),kl=h(e),ae=n(e,"P",{});var tn=a(ae);xh=l(tn,"This exports an ONNX graph of the checkpoint defined by the "),Hn=n(tn,"CODE",{});var P_=a(Hn);kh=l(P_,"--model"),P_.forEach(o),Th=l(tn,` argument.
In this example it is `),Wn=n(tn,"CODE",{});var S_=a(Wn);Nh=l(S_,"distilbert-base-uncased"),S_.forEach(o),Oh=l(tn,`, but it can be any checkpoint on
the Hugging Face Hub or one that\u2019s stored locally.`),tn.forEach(o),Tl=h(e),Y=n(e,"P",{});var Dt=a(Y);jh=l(Dt,"The resulting "),Kn=n(Dt,"CODE",{});var q_=a(Kn);Ah=l(q_,"model.onnx"),q_.forEach(o),Ch=l(Dt," file can then be run on one of the "),Ht=n(Dt,"A",{href:!0,rel:!0});var z_=a(Ht);Dh=l(z_,`many
accelerators`),z_.forEach(o),Ph=l(Dt,` that support the
ONNX standard. For example, we can load and run the model with `),Wt=n(Dt,"A",{href:!0,rel:!0});var I_=a(Wt);Sh=l(I_,`ONNX
Runtime`),I_.forEach(o),qh=l(Dt," as follows:"),Dt.forEach(o),Nl=h(e),m(Kt.$$.fragment,e),Ol=h(e),Ge=n(e,"P",{});var Op=a(Ge);zh=l(Op,"The required output names (i.e. "),Un=n(Op,"CODE",{});var M_=a(Un);Ih=l(M_,'["last_hidden_state"]'),M_.forEach(o),Mh=l(Op,`) can be obtained by
taking a look at the ONNX configuration of each model. For example, for
DistilBERT we have:`),Op.forEach(o),jl=h(e),m(Ut.$$.fragment,e),Al=h(e),Je=n(e,"P",{});var jp=a(Je);Bh=l(jp,`The process is identical for TensorFlow checkpoints on the Hub. For example, we
can export a pure TensorFlow checkpoint from the `),Vt=n(jp,"A",{href:!0,rel:!0});var B_=a(Vt);Lh=l(B_,`Keras
organization`),B_.forEach(o),Xh=l(jp," as follows:"),jp.forEach(o),Cl=h(e),m(Gt.$$.fragment,e),Dl=h(e),$s=n(e,"P",{});var L_=a($s);Fh=l(L_,`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:`),L_.forEach(o),Pl=h(e),m(Jt.$$.fragment,e),Sl=h(e),re=n(e,"P",{});var on=a(re);Rh=l(on,"Once the checkpoint is saved, we can export it to ONNX by pointing the "),Vn=n(on,"CODE",{});var X_=a(Vn);Hh=l(X_,"--model"),X_.forEach(o),Wh=l(on,`
argument of the `),Gn=n(on,"CODE",{});var F_=a(Gn);Kh=l(F_,"transformers.onnx"),F_.forEach(o),Uh=l(on," package to the desired directory:"),on.forEach(o),ql=h(e),m(Yt.$$.fragment,e),zl=h(e),ye=n(e,"H3",{class:!0});var Ap=a(ye);Ye=n(Ap,"A",{id:!0,class:!0,href:!0});var R_=a(Ye);Jn=n(R_,"SPAN",{});var H_=a(Jn);m(Qt.$$.fragment,H_),H_.forEach(o),R_.forEach(o),Vh=h(Ap),Yn=n(Ap,"SPAN",{});var W_=a(Yn);Gh=l(W_,"Selecting features for different model topologies"),W_.forEach(o),Ap.forEach(o),Il=h(e),Qe=n(e,"P",{});var Cp=a(Qe);Jh=l(Cp,"Each ready-made configuration comes with a set of "),Qn=n(Cp,"EM",{});var K_=a(Qn);Yh=l(K_,"features"),K_.forEach(o),Qh=l(Cp,` that enable you to
export models for different types of topologies or tasks. As shown in the table
below, each feature is associated with a different auto class:`),Cp.forEach(o),Ml=h(e),Ze=n(e,"TABLE",{});var Dp=a(Ze);Zn=n(Dp,"THEAD",{});var U_=a(Zn);Zt=n(U_,"TR",{});var Pp=a(Zt);ea=n(Pp,"TH",{});var V_=a(ea);Zh=l(V_,"Feature"),V_.forEach(o),ef=h(Pp),ta=n(Pp,"TH",{});var G_=a(ta);tf=l(G_,"Auto Class"),G_.forEach(o),Pp.forEach(o),U_.forEach(o),of=h(Dp),I=n(Dp,"TBODY",{});var K=a(I);eo=n(K,"TR",{});var Sp=a(eo);to=n(Sp,"TD",{});var qp=a(to);oa=n(qp,"CODE",{});var J_=a(oa);sf=l(J_,"causal-lm"),J_.forEach(o),nf=l(qp,", "),sa=n(qp,"CODE",{});var Y_=a(sa);af=l(Y_,"causal-lm-with-past"),Y_.forEach(o),qp.forEach(o),rf=h(Sp),na=n(Sp,"TD",{});var Q_=a(na);aa=n(Q_,"CODE",{});var Z_=a(aa);lf=l(Z_,"AutoModelForCausalLM"),Z_.forEach(o),Q_.forEach(o),Sp.forEach(o),pf=h(K),oo=n(K,"TR",{});var zp=a(oo);so=n(zp,"TD",{});var Ip=a(so);ra=n(Ip,"CODE",{});var ev=a(ra);df=l(ev,"default"),ev.forEach(o),hf=l(Ip,", "),la=n(Ip,"CODE",{});var tv=a(la);ff=l(tv,"default-with-past"),tv.forEach(o),Ip.forEach(o),cf=h(zp),ia=n(zp,"TD",{});var ov=a(ia);pa=n(ov,"CODE",{});var sv=a(pa);uf=l(sv,"AutoModel"),sv.forEach(o),ov.forEach(o),zp.forEach(o),mf=h(K),no=n(K,"TR",{});var Mp=a(no);da=n(Mp,"TD",{});var nv=a(da);ha=n(nv,"CODE",{});var av=a(ha);gf=l(av,"masked-lm"),av.forEach(o),nv.forEach(o),_f=h(Mp),fa=n(Mp,"TD",{});var rv=a(fa);ca=n(rv,"CODE",{});var lv=a(ca);vf=l(lv,"AutoModelForMaskedLM"),lv.forEach(o),rv.forEach(o),Mp.forEach(o),wf=h(K),ao=n(K,"TR",{});var Bp=a(ao);ua=n(Bp,"TD",{});var iv=a(ua);ma=n(iv,"CODE",{});var pv=a(ma);Ef=l(pv,"question-answering"),pv.forEach(o),iv.forEach(o),$f=h(Bp),ga=n(Bp,"TD",{});var dv=a(ga);_a=n(dv,"CODE",{});var hv=a(_a);bf=l(hv,"AutoModelForQuestionAnswering"),hv.forEach(o),dv.forEach(o),Bp.forEach(o),yf=h(K),ro=n(K,"TR",{});var Lp=a(ro);lo=n(Lp,"TD",{});var Xp=a(lo);va=n(Xp,"CODE",{});var fv=a(va);xf=l(fv,"seq2seq-lm"),fv.forEach(o),kf=l(Xp,", "),wa=n(Xp,"CODE",{});var cv=a(wa);Tf=l(cv,"seq2seq-lm-with-past"),cv.forEach(o),Xp.forEach(o),Nf=h(Lp),Ea=n(Lp,"TD",{});var uv=a(Ea);$a=n(uv,"CODE",{});var mv=a($a);Of=l(mv,"AutoModelForSeq2SeqLM"),mv.forEach(o),uv.forEach(o),Lp.forEach(o),jf=h(K),io=n(K,"TR",{});var Fp=a(io);ba=n(Fp,"TD",{});var gv=a(ba);ya=n(gv,"CODE",{});var _v=a(ya);Af=l(_v,"sequence-classification"),_v.forEach(o),gv.forEach(o),Cf=h(Fp),xa=n(Fp,"TD",{});var vv=a(xa);ka=n(vv,"CODE",{});var wv=a(ka);Df=l(wv,"AutoModelForSequenceClassification"),wv.forEach(o),vv.forEach(o),Fp.forEach(o),Pf=h(K),po=n(K,"TR",{});var Rp=a(po);Ta=n(Rp,"TD",{});var Ev=a(Ta);Na=n(Ev,"CODE",{});var $v=a(Na);Sf=l($v,"token-classification"),$v.forEach(o),Ev.forEach(o),qf=h(Rp),Oa=n(Rp,"TD",{});var bv=a(Oa);ja=n(bv,"CODE",{});var yv=a(ja);zf=l(yv,"AutoModelForTokenClassification"),yv.forEach(o),bv.forEach(o),Rp.forEach(o),K.forEach(o),Dp.forEach(o),Bl=h(e),et=n(e,"P",{});var Hp=a(et);If=l(Hp,`For each configuration, you can find the list of supported features via the
`),Aa=n(Hp,"CODE",{});var xv=a(Aa);Mf=l(xv,"FeaturesManager"),xv.forEach(o),Bf=l(Hp,". For example, for DistilBERT we have:"),Hp.forEach(o),Ll=h(e),m(ho.$$.fragment,e),Xl=h(e),le=n(e,"P",{});var sn=a(le);Lf=l(sn,"You can then pass one of these features to the "),Ca=n(sn,"CODE",{});var kv=a(Ca);Xf=l(kv,"--feature"),kv.forEach(o),Ff=l(sn,` argument in the
`),Da=n(sn,"CODE",{});var Tv=a(Da);Rf=l(Tv,"transformers.onnx"),Tv.forEach(o),Hf=l(sn,` package. For example, to export a text-classification model
we can pick a fine-tuned model from the Hub and run:`),sn.forEach(o),Fl=h(e),m(fo.$$.fragment,e),Rl=h(e),bs=n(e,"P",{});var Nv=a(bs);Wf=l(Nv,"which will display the following logs:"),Nv.forEach(o),Hl=h(e),m(co.$$.fragment,e),Wl=h(e),Q=n(e,"P",{});var Pt=a(Q);Kf=l(Pt,`Notice that in this case, the output names from the fine-tuned model are
`),Pa=n(Pt,"CODE",{});var Ov=a(Pa);Uf=l(Ov,"logits"),Ov.forEach(o),Vf=l(Pt," instead of the "),Sa=n(Pt,"CODE",{});var jv=a(Sa);Gf=l(jv,"last_hidden_state"),jv.forEach(o),Jf=l(Pt,` we saw with the
`),qa=n(Pt,"CODE",{});var Av=a(qa);Yf=l(Av,"distilbert-base-uncased"),Av.forEach(o),Qf=l(Pt,` checkpoint earlier. This is expected since the
fine-tuned model has a sequence classification head.`),Pt.forEach(o),Kl=h(e),m(tt.$$.fragment,e),Ul=h(e),xe=n(e,"H3",{class:!0});var Wp=a(xe);ot=n(Wp,"A",{id:!0,class:!0,href:!0});var Cv=a(ot);za=n(Cv,"SPAN",{});var Dv=a(za);m(uo.$$.fragment,Dv),Dv.forEach(o),Cv.forEach(o),Zf=h(Wp),Ia=n(Wp,"SPAN",{});var Pv=a(Ia);ec=l(Pv,"Exporting a model for an unsupported architecture"),Pv.forEach(o),Wp.forEach(o),Vl=h(e),ys=n(e,"P",{});var Sv=a(ys);tc=l(Sv,`If you wish to export a model whose architecture is not natively supported by
the library, there are three main steps to follow:`),Sv.forEach(o),Gl=h(e),ie=n(e,"OL",{});var nn=a(ie);Ma=n(nn,"LI",{});var qv=a(Ma);oc=l(qv,"Implement a custom ONNX configuration."),qv.forEach(o),sc=h(nn),Ba=n(nn,"LI",{});var zv=a(Ba);nc=l(zv,"Export the model to ONNX."),zv.forEach(o),ac=h(nn),La=n(nn,"LI",{});var Iv=a(La);rc=l(Iv,"Validate the outputs of the PyTorch and exported models."),Iv.forEach(o),nn.forEach(o),Jl=h(e),xs=n(e,"P",{});var Mv=a(xs);lc=l(Mv,`In this section, we\u2019ll look at how DistilBERT was implemented to show what\u2019s
involved with each step.`),Mv.forEach(o),Yl=h(e),ke=n(e,"H4",{class:!0});var Kp=a(ke);st=n(Kp,"A",{id:!0,class:!0,href:!0});var Bv=a(st);Xa=n(Bv,"SPAN",{});var Lv=a(Xa);m(mo.$$.fragment,Lv),Lv.forEach(o),Bv.forEach(o),ic=h(Kp),Fa=n(Kp,"SPAN",{});var Xv=a(Fa);pc=l(Xv,"Implementing a custom ONNX configuration"),Xv.forEach(o),Kp.forEach(o),Ql=h(e),ks=n(e,"P",{});var Fv=a(ks);dc=l(Fv,`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:`),Fv.forEach(o),Zl=h(e),pe=n(e,"UL",{});var an=a(pe);Ts=n(an,"LI",{});var Fg=a(Ts);hc=l(Fg,"Encoder-based models inherit from "),Ns=n(Fg,"A",{href:!0});var Rv=a(Ns);fc=l(Rv,"OnnxConfig"),Rv.forEach(o),Fg.forEach(o),cc=h(an),Os=n(an,"LI",{});var Rg=a(Os);uc=l(Rg,"Decoder-based models inherit from "),js=n(Rg,"A",{href:!0});var Hv=a(js);mc=l(Hv,"OnnxConfigWithPast"),Hv.forEach(o),Rg.forEach(o),gc=h(an),As=n(an,"LI",{});var Hg=a(As);_c=l(Hg,"Encoder-decoder models inherit from "),Cs=n(Hg,"A",{href:!0});var Wv=a(Cs);vc=l(Wv,"OnnxSeq2SeqConfigWithPast"),Wv.forEach(o),Hg.forEach(o),an.forEach(o),ei=h(e),m(nt.$$.fragment,e),ti=h(e),at=n(e,"P",{});var Up=a(at);wc=l(Up,`Since DistilBERT is an encoder-based model, its configuration inherits from
`),Ra=n(Up,"CODE",{});var Kv=a(Ra);Ec=l(Kv,"OnnxConfig"),Kv.forEach(o),$c=l(Up,":"),Up.forEach(o),oi=h(e),m(go.$$.fragment,e),si=h(e),H=n(e,"P",{});var _e=a(H);bc=l(_e,"Every configuration object must implement the "),Ha=n(_e,"CODE",{});var Uv=a(Ha);yc=l(Uv,"inputs"),Uv.forEach(o),xc=l(_e,` 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: `),Wa=n(_e,"CODE",{});var Vv=a(Wa);kc=l(Vv,"input_ids"),Vv.forEach(o),Tc=l(_e," and "),Ka=n(_e,"CODE",{});var Gv=a(Ka);Nc=l(Gv,"attention_mask"),Gv.forEach(o),Oc=l(_e,`. These inputs have the same shape of
`),Ua=n(_e,"CODE",{});var Jv=a(Ua);jc=l(Jv,"(batch_size, sequence_length)"),Jv.forEach(o),Ac=l(_e,` which is why we see the same axes used in the
configuration.`),_e.forEach(o),ni=h(e),m(rt.$$.fragment,e),ai=h(e),Ds=n(e,"P",{});var Yv=a(Ds);Cc=l(Yv,`Once you have implemented an ONNX configuration, you can instantiate it by
providing the base model\u2019s configuration as follows:`),Yv.forEach(o),ri=h(e),m(_o.$$.fragment,e),li=h(e),Ps=n(e,"P",{});var Qv=a(Ps);Dc=l(Qv,`The resulting object has several useful properties. For example you can view the
ONNX operator set that will be used during the export:`),Qv.forEach(o),ii=h(e),m(vo.$$.fragment,e),pi=h(e),Ss=n(e,"P",{});var Zv=a(Ss);Pc=l(Zv,"You can also view the outputs associated with the model as follows:"),Zv.forEach(o),di=h(e),m(wo.$$.fragment,e),hi=h(e),W=n(e,"P",{});var ve=a(W);Sc=l(ve,`Notice that the outputs property follows the same structure as the inputs; it
returns an `),Va=n(ve,"CODE",{});var ew=a(Va);qc=l(ew,"OrderedDict"),ew.forEach(o),zc=l(ve,` 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 `),Ga=n(ve,"CODE",{});var tw=a(Ga);Ic=l(tw,"default"),tw.forEach(o),Mc=l(ve,` feature
that corresponds to exporting a model loaded with the `),Ja=n(ve,"CODE",{});var ow=a(Ja);Bc=l(ow,"AutoModel"),ow.forEach(o),Lc=l(ve,` class. If you
want to export a different model topology, just provide a different feature to
the `),Ya=n(ve,"CODE",{});var sw=a(Ya);Xc=l(sw,"task"),sw.forEach(o),Fc=l(ve,` argument when you initialize the ONNX configuration. For example, if
we wished to export DistilBERT with a sequence classification head, we could
use:`),ve.forEach(o),fi=h(e),m(Eo.$$.fragment,e),ci=h(e),m(lt.$$.fragment,e),ui=h(e),Te=n(e,"H4",{class:!0});var Vp=a(Te);it=n(Vp,"A",{id:!0,class:!0,href:!0});var nw=a(it);Qa=n(nw,"SPAN",{});var aw=a(Qa);m($o.$$.fragment,aw),aw.forEach(o),nw.forEach(o),Rc=h(Vp),Za=n(Vp,"SPAN",{});var rw=a(Za);Hc=l(rw,"Exporting the model"),rw.forEach(o),Vp.forEach(o),mi=h(e),de=n(e,"P",{});var rn=a(de);Wc=l(rn,`Once you have implemented the ONNX configuration, the next step is to export the
model. Here we can use the `),er=n(rn,"CODE",{});var lw=a(er);Kc=l(lw,"export()"),lw.forEach(o),Uc=l(rn,` function provided by the
`),tr=n(rn,"CODE",{});var iw=a(tr);Vc=l(iw,"transformers.onnx"),iw.forEach(o),Gc=l(rn,` package. This function expects the ONNX configuration, along
with the base model and tokenizer, and the path to save the exported file:`),rn.forEach(o),gi=h(e),m(bo.$$.fragment,e),_i=h(e),M=n(e,"P",{});var te=a(M);Jc=l(te,"The "),or=n(te,"CODE",{});var pw=a(or);Yc=l(pw,"onnx_inputs"),pw.forEach(o),Qc=l(te," and "),sr=n(te,"CODE",{});var dw=a(sr);Zc=l(dw,"onnx_outputs"),dw.forEach(o),eu=l(te," returned by the "),nr=n(te,"CODE",{});var hw=a(nr);tu=l(hw,"export()"),hw.forEach(o),ou=l(te,` function are
lists of the keys defined in the `),ar=n(te,"CODE",{});var fw=a(ar);su=l(fw,"inputs"),fw.forEach(o),nu=l(te," and "),rr=n(te,"CODE",{});var cw=a(rr);au=l(cw,"outputs"),cw.forEach(o),ru=l(te,` properties of the
configuration. Once the model is exported, you can test that the model is well
formed as follows:`),te.forEach(o),vi=h(e),m(yo.$$.fragment,e),wi=h(e),m(pt.$$.fragment,e),Ei=h(e),Ne=n(e,"H4",{class:!0});var Gp=a(Ne);dt=n(Gp,"A",{id:!0,class:!0,href:!0});var uw=a(dt);lr=n(uw,"SPAN",{});var mw=a(lr);m(xo.$$.fragment,mw),mw.forEach(o),uw.forEach(o),lu=h(Gp),ir=n(Gp,"SPAN",{});var gw=a(ir);iu=l(gw,"Validating the model outputs"),gw.forEach(o),Gp.forEach(o),$i=h(e),he=n(e,"P",{});var ln=a(he);pu=l(ln,`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
`),pr=n(ln,"CODE",{});var _w=a(pr);du=l(_w,"validate_model_outputs()"),_w.forEach(o),hu=l(ln," function provided by the "),dr=n(ln,"CODE",{});var vw=a(dr);fu=l(vw,"transformers.onnx"),vw.forEach(o),cu=l(ln,` package
as follows:`),ln.forEach(o),bi=h(e),m(ko.$$.fragment,e),yi=h(e),ht=n(e,"P",{});var Jp=a(ht);uu=l(Jp,"This function uses the "),hr=n(Jp,"CODE",{});var ww=a(hr);mu=l(ww,"OnnxConfig.generate_dummy_inputs()"),ww.forEach(o),gu=l(Jp,` 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.`),Jp.forEach(o),xi=h(e),Oe=n(e,"H3",{class:!0});var Yp=a(Oe);ft=n(Yp,"A",{id:!0,class:!0,href:!0});var Ew=a(ft);fr=n(Ew,"SPAN",{});var $w=a(fr);m(To.$$.fragment,$w),$w.forEach(o),Ew.forEach(o),_u=h(Yp),cr=n(Yp,"SPAN",{});var bw=a(cr);vu=l(bw,"Contributing a new configuration to \u{1F917} Transformers"),bw.forEach(o),Yp.forEach(o),ki=h(e),qs=n(e,"P",{});var yw=a(qs);wu=l(yw,`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:`),yw.forEach(o),Ti=h(e),fe=n(e,"UL",{});var pn=a(fe);No=n(pn,"LI",{});var Qp=a(No);Eu=l(Qp,"Implement the ONNX configuration in the corresponding "),ur=n(Qp,"CODE",{});var xw=a(ur);$u=l(xw,"configuration_<model_name>.py"),xw.forEach(o),bu=l(Qp,`
file`),Qp.forEach(o),yu=h(pn),zs=n(pn,"LI",{});var Wg=a(zs);xu=l(Wg,"Include the model architecture and corresponding features in "),mr=n(Wg,"CODE",{});var kw=a(mr);ku=l(kw,"FeatureManager"),kw.forEach(o),Wg.forEach(o),Tu=h(pn),Is=n(pn,"LI",{});var Kg=a(Is);Nu=l(Kg,"Add your model architecture to the tests in "),gr=n(Kg,"CODE",{});var Tw=a(gr);Ou=l(Tw,"test_onnx_v2.py"),Tw.forEach(o),Kg.forEach(o),pn.forEach(o),Ni=h(e),ct=n(e,"P",{});var Zp=a(ct);ju=l(Zp,"Check out how the configuration for "),Oo=n(Zp,"A",{href:!0,rel:!0});var Nw=a(Oo);Au=l(Nw,`IBERT was
contributed`),Nw.forEach(o),Cu=l(Zp,` to
get an idea of what\u2019s involved.`),Zp.forEach(o),Oi=h(e),je=n(e,"H2",{class:!0});var ed=a(je);ut=n(ed,"A",{id:!0,class:!0,href:!0});var Ow=a(ut);_r=n(Ow,"SPAN",{});var jw=a(_r);m(jo.$$.fragment,jw),jw.forEach(o),Ow.forEach(o),Du=h(ed),vr=n(ed,"SPAN",{});var Aw=a(vr);Pu=l(Aw,"TorchScript"),Aw.forEach(o),ed.forEach(o),ji=h(e),m(mt.$$.fragment,e),Ai=h(e),gt=n(e,"P",{});var td=a(gt);Su=l(td,`According to Pytorch\u2019s documentation: \u201CTorchScript is a way to create serializable and optimizable models from PyTorch
code\u201D. Pytorch\u2019s two modules `),Ao=n(td,"A",{href:!0,rel:!0});var Cw=a(Ao);qu=l(Cw,"JIT and TRACE"),Cw.forEach(o),zu=l(td,` allow the developer to export
their model to be re-used in other programs, such as efficiency-oriented C++ programs.`),td.forEach(o),Ci=h(e),Ms=n(e,"P",{});var Dw=a(Ms);Iu=l(Dw,`We have provided an interface that allows the export of \u{1F917} Transformers models to TorchScript so that they can be reused
in a different environment than a Pytorch-based python program. Here we explain how to export and use our models using
TorchScript.`),Dw.forEach(o),Di=h(e),Bs=n(e,"P",{});var Pw=a(Bs);Mu=l(Pw,"Exporting a model requires two things:"),Pw.forEach(o),Pi=h(e),_t=n(e,"UL",{});var od=a(_t);wr=n(od,"LI",{});var Sw=a(wr);Bu=l(Sw,"a forward pass with dummy inputs."),Sw.forEach(o),Lu=h(od),Co=n(od,"LI",{});var sd=a(Co);Xu=l(sd,"model instantiation with the "),Er=n(sd,"CODE",{});var qw=a(Er);Fu=l(qw,"torchscript"),qw.forEach(o),Ru=l(sd," flag."),sd.forEach(o),od.forEach(o),Si=h(e),Ls=n(e,"P",{});var zw=a(Ls);Hu=l(zw,"These necessities imply several things developers should be careful about. These are detailed below."),zw.forEach(o),qi=h(e),Ae=n(e,"H3",{class:!0});var nd=a(Ae);vt=n(nd,"A",{id:!0,class:!0,href:!0});var Iw=a(vt);$r=n(Iw,"SPAN",{});var Mw=a($r);m(Do.$$.fragment,Mw),Mw.forEach(o),Iw.forEach(o),Wu=h(nd),br=n(nd,"SPAN",{});var Bw=a(br);Ku=l(Bw,"Implications"),Bw.forEach(o),nd.forEach(o),zi=h(e),Ce=n(e,"H3",{class:!0});var ad=a(Ce);wt=n(ad,"A",{id:!0,class:!0,href:!0});var Lw=a(wt);yr=n(Lw,"SPAN",{});var Xw=a(yr);m(Po.$$.fragment,Xw),Xw.forEach(o),Lw.forEach(o),Uu=h(ad),xr=n(ad,"SPAN",{});var Fw=a(xr);Vu=l(Fw,"TorchScript flag and tied weights"),Fw.forEach(o),ad.forEach(o),Ii=h(e),ce=n(e,"P",{});var dn=a(ce);Gu=l(dn,`This flag is necessary because most of the language models in this repository have tied weights between their
`),kr=n(dn,"CODE",{});var Rw=a(kr);Ju=l(Rw,"Embedding"),Rw.forEach(o),Yu=l(dn," layer and their "),Tr=n(dn,"CODE",{});var Hw=a(Tr);Qu=l(Hw,"Decoding"),Hw.forEach(o),Zu=l(dn,` layer. TorchScript does not allow the export of models that have tied
weights, therefore it is necessary to untie and clone the weights beforehand.`),dn.forEach(o),Mi=h(e),Z=n(e,"P",{});var St=a(Z);em=l(St,"This implies that models instantiated with the "),Nr=n(St,"CODE",{});var Ww=a(Nr);tm=l(Ww,"torchscript"),Ww.forEach(o),om=l(St," flag have their "),Or=n(St,"CODE",{});var Kw=a(Or);sm=l(Kw,"Embedding"),Kw.forEach(o),nm=l(St," layer and "),jr=n(St,"CODE",{});var Uw=a(jr);am=l(Uw,"Decoding"),Uw.forEach(o),rm=l(St,`
layer separate, which means that they should not be trained down the line. Training would de-synchronize the two
layers, leading to unexpected results.`),St.forEach(o),Bi=h(e),Et=n(e,"P",{});var rd=a(Et);lm=l(rd,`This is not the case for models that do not have a Language Model head, as those do not have tied weights. These models
can be safely exported without the `),Ar=n(rd,"CODE",{});var Vw=a(Ar);im=l(Vw,"torchscript"),Vw.forEach(o),pm=l(rd," flag."),rd.forEach(o),Li=h(e),De=n(e,"H3",{class:!0});var ld=a(De);$t=n(ld,"A",{id:!0,class:!0,href:!0});var Gw=a($t);Cr=n(Gw,"SPAN",{});var Jw=a(Cr);m(So.$$.fragment,Jw),Jw.forEach(o),Gw.forEach(o),dm=h(ld),Dr=n(ld,"SPAN",{});var Yw=a(Dr);hm=l(Yw,"Dummy inputs and standard lengths"),Yw.forEach(o),ld.forEach(o),Xi=h(e),Xs=n(e,"P",{});var Qw=a(Xs);fm=l(Qw,`The dummy inputs are used to do a model forward pass. While the inputs\u2019 values are propagating through the layers,
Pytorch keeps track of the different operations executed on each tensor. These recorded operations are then used to
create the \u201Ctrace\u201D of the model.`),Qw.forEach(o),Fi=h(e),Fs=n(e,"P",{});var Zw=a(Fs);cm=l(Zw,`The trace is created relatively to the inputs\u2019 dimensions. It is therefore constrained by the dimensions of the dummy
input, and will not work for any other sequence length or batch size. When trying with a different size, an error such
as:`),Zw.forEach(o),Ri=h(e),Rs=n(e,"P",{});var e1=a(Rs);Pr=n(e1,"CODE",{});var t1=a(Pr);um=l(t1,"The expanded size of the tensor (3) must match the existing size (7) at non-singleton dimension 2"),t1.forEach(o),e1.forEach(o),Hi=h(e),Hs=n(e,"P",{});var o1=a(Hs);mm=l(o1,`will be raised. It is therefore recommended to trace the model with a dummy input size at least as large as the largest
input that will be fed to the model during inference. Padding can be performed to fill the missing values. As the model
will have been traced with a large input size however, the dimensions of the different matrix will be large as well,
resulting in more calculations.`),o1.forEach(o),Wi=h(e),Ws=n(e,"P",{});var s1=a(Ws);gm=l(s1,`It is recommended to be careful of the total number of operations done on each input and to follow performance closely
when exporting varying sequence-length models.`),s1.forEach(o),Ki=h(e),Pe=n(e,"H3",{class:!0});var id=a(Pe);bt=n(id,"A",{id:!0,class:!0,href:!0});var n1=a(bt);Sr=n(n1,"SPAN",{});var a1=a(Sr);m(qo.$$.fragment,a1),a1.forEach(o),n1.forEach(o),_m=h(id),qr=n(id,"SPAN",{});var r1=a(qr);vm=l(r1,"Using TorchScript in Python"),r1.forEach(o),id.forEach(o),Ui=h(e),Ks=n(e,"P",{});var l1=a(Ks);wm=l(l1,"Below is an example, showing how to save, load models as well as how to use the trace for inference."),l1.forEach(o),Vi=h(e),Se=n(e,"H4",{class:!0});var pd=a(Se);yt=n(pd,"A",{id:!0,class:!0,href:!0});var i1=a(yt);zr=n(i1,"SPAN",{});var p1=a(zr);m(zo.$$.fragment,p1),p1.forEach(o),i1.forEach(o),Em=h(pd),Ir=n(pd,"SPAN",{});var d1=a(Ir);$m=l(d1,"Saving a model"),d1.forEach(o),pd.forEach(o),Gi=h(e),G=n(e,"P",{});var Re=a(G);bm=l(Re,"This snippet shows how to use TorchScript to export a "),Mr=n(Re,"CODE",{});var h1=a(Mr);ym=l(h1,"BertModel"),h1.forEach(o),xm=l(Re,". Here the "),Br=n(Re,"CODE",{});var f1=a(Br);km=l(f1,"BertModel"),f1.forEach(o),Tm=l(Re,` is instantiated according
to a `),Lr=n(Re,"CODE",{});var c1=a(Lr);Nm=l(c1,"BertConfig"),c1.forEach(o),Om=l(Re," class and then saved to disk under the filename "),Xr=n(Re,"CODE",{});var u1=a(Xr);jm=l(u1,"traced_bert.pt"),u1.forEach(o),Re.forEach(o),Ji=h(e),m(Io.$$.fragment,e),Yi=h(e),qe=n(e,"H4",{class:!0});var dd=a(qe);xt=n(dd,"A",{id:!0,class:!0,href:!0});var m1=a(xt);Fr=n(m1,"SPAN",{});var g1=a(Fr);m(Mo.$$.fragment,g1),g1.forEach(o),m1.forEach(o),Am=h(dd),Rr=n(dd,"SPAN",{});var _1=a(Rr);Cm=l(_1,"Loading a model"),_1.forEach(o),dd.forEach(o),Qi=h(e),ee=n(e,"P",{});var qt=a(ee);Dm=l(qt,"This snippet shows how to load the "),Hr=n(qt,"CODE",{});var v1=a(Hr);Pm=l(v1,"BertModel"),v1.forEach(o),Sm=l(qt," that was previously saved to disk under the name "),Wr=n(qt,"CODE",{});var w1=a(Wr);qm=l(w1,"traced_bert.pt"),w1.forEach(o),zm=l(qt,`.
We are re-using the previously initialised `),Kr=n(qt,"CODE",{});var E1=a(Kr);Im=l(E1,"dummy_input"),E1.forEach(o),Mm=l(qt,"."),qt.forEach(o),Zi=h(e),m(Bo.$$.fragment,e),ep=h(e),ze=n(e,"H4",{class:!0});var hd=a(ze);kt=n(hd,"A",{id:!0,class:!0,href:!0});var $1=a(kt);Ur=n($1,"SPAN",{});var b1=a(Ur);m(Lo.$$.fragment,b1),b1.forEach(o),$1.forEach(o),Bm=h(hd),Vr=n(hd,"SPAN",{});var y1=a(Vr);Lm=l(y1,"Using a traced model for inference"),y1.forEach(o),hd.forEach(o),tp=h(e),Tt=n(e,"P",{});var fd=a(Tt);Xm=l(fd,"Using the traced model for inference is as simple as using its "),Gr=n(fd,"CODE",{});var x1=a(Gr);Fm=l(x1,"__call__"),x1.forEach(o),Rm=l(fd," dunder method:"),fd.forEach(o),op=h(e),m(Xo.$$.fragment,e),sp=h(e),Ie=n(e,"H3",{class:!0});var cd=a(Ie);Nt=n(cd,"A",{id:!0,class:!0,href:!0});var k1=a(Nt);Jr=n(k1,"SPAN",{});var T1=a(Jr);m(Fo.$$.fragment,T1),T1.forEach(o),k1.forEach(o),Hm=h(cd),Yr=n(cd,"SPAN",{});var N1=a(Yr);Wm=l(N1,"Deploying HuggingFace TorchScript models on AWS using the Neuron SDK"),N1.forEach(o),cd.forEach(o),np=h(e),ue=n(e,"P",{});var hn=a(ue);Km=l(hn,"AWS introduced the "),Ro=n(hn,"A",{href:!0,rel:!0});var O1=a(Ro);Um=l(O1,"Amazon EC2 Inf1"),O1.forEach(o),Vm=l(hn,`
instance family for low cost, high performance machine learning inference in the cloud.
The Inf1 instances are powered by the AWS Inferentia chip, a custom-built hardware accelerator,
specializing in deep learning inferencing workloads.
`),Ho=n(hn,"A",{href:!0,rel:!0});var j1=a(Ho);Gm=l(j1,"AWS Neuron"),j1.forEach(o),Jm=l(hn,`
is the SDK for Inferentia that supports tracing and optimizing transformers models for
deployment on Inf1. The Neuron SDK provides:`),hn.forEach(o),ap=h(e),me=n(e,"OL",{});var fn=a(me);Qr=n(fn,"LI",{});var A1=a(Qr);Ym=l(A1,"Easy-to-use API with one line of code change to trace and optimize a TorchScript model for inference in the cloud."),A1.forEach(o),Qm=h(fn),Us=n(fn,"LI",{});var Ug=a(Us);Zm=l(Ug,"Out of the box performance optimizations for "),Wo=n(Ug,"A",{href:!0,rel:!0});var C1=a(Wo);eg=l(C1,"improved cost-performance"),C1.forEach(o),Ug.forEach(o),tg=h(fn),Me=n(fn,"LI",{});var cn=a(Me);og=l(cn,"Support for HuggingFace transformers models built with either "),Ko=n(cn,"A",{href:!0,rel:!0});var D1=a(Ko);sg=l(D1,"PyTorch"),D1.forEach(o),ng=l(cn,`
or `),Uo=n(cn,"A",{href:!0,rel:!0});var P1=a(Uo);ag=l(P1,"TensorFlow"),P1.forEach(o),rg=l(cn,"."),cn.forEach(o),fn.forEach(o),rp=h(e),Be=n(e,"H4",{class:!0});var ud=a(Be);Ot=n(ud,"A",{id:!0,class:!0,href:!0});var S1=a(Ot);Zr=n(S1,"SPAN",{});var q1=a(Zr);m(Vo.$$.fragment,q1),q1.forEach(o),S1.forEach(o),lg=h(ud),el=n(ud,"SPAN",{});var z1=a(el);ig=l(z1,"Implications"),z1.forEach(o),ud.forEach(o),lp=h(e),B=n(e,"P",{});var oe=a(B);pg=l(oe,"Transformers Models based on the "),Go=n(oe,"A",{href:!0,rel:!0});var I1=a(Go);dg=l(I1,"BERT (Bidirectional Encoder Representations from Transformers)"),I1.forEach(o),hg=l(oe,`
architecture, or its variants such as `),Jo=n(oe,"A",{href:!0,rel:!0});var M1=a(Jo);fg=l(M1,"distilBERT"),M1.forEach(o),cg=l(oe,`
and `),Yo=n(oe,"A",{href:!0,rel:!0});var B1=a(Yo);ug=l(B1,"roBERTa"),B1.forEach(o),mg=l(oe,`
will run best on Inf1 for non-generative tasks such as Extractive Question Answering,
Sequence Classification, Token Classification. Alternatively, text generation
tasks can be adapted to run on Inf1, according to this `),Qo=n(oe,"A",{href:!0,rel:!0});var L1=a(Qo);gg=l(L1,"AWS Neuron MarianMT tutorial"),L1.forEach(o),_g=l(oe,`.
More information about models that can be converted out of the box on Inferentia can be
found in the `),Zo=n(oe,"A",{href:!0,rel:!0});var X1=a(Zo);vg=l(X1,"Model Architecture Fit section of the Neuron documentation"),X1.forEach(o),wg=l(oe,"."),oe.forEach(o),ip=h(e),Le=n(e,"H4",{class:!0});var md=a(Le);jt=n(md,"A",{id:!0,class:!0,href:!0});var F1=a(jt);tl=n(F1,"SPAN",{});var R1=a(tl);m(es.$$.fragment,R1),R1.forEach(o),F1.forEach(o),Eg=h(md),ol=n(md,"SPAN",{});var H1=a(ol);$g=l(H1,"Dependencies"),H1.forEach(o),md.forEach(o),pp=h(e),Vs=n(e,"P",{});var W1=a(Vs);bg=l(W1,"Using AWS Neuron to convert models requires the following dependencies and environment:"),W1.forEach(o),dp=h(e),Gs=n(e,"UL",{});var K1=a(Gs);Xe=n(K1,"LI",{});var un=a(Xe);yg=l(un,"A "),ts=n(un,"A",{href:!0,rel:!0});var U1=a(ts);xg=l(U1,"Neuron SDK environment"),U1.forEach(o),kg=l(un,`,
which comes pre-configured on `),os=n(un,"A",{href:!0,rel:!0});var V1=a(os);Tg=l(V1,"AWS Deep Learning AMI"),V1.forEach(o),Ng=l(un,"."),un.forEach(o),K1.forEach(o),hp=h(e),Fe=n(e,"H4",{class:!0});var gd=a(Fe);At=n(gd,"A",{id:!0,class:!0,href:!0});var G1=a(At);sl=n(G1,"SPAN",{});var J1=a(sl);m(ss.$$.fragment,J1),J1.forEach(o),G1.forEach(o),Og=h(gd),nl=n(gd,"SPAN",{});var Y1=a(nl);jg=l(Y1,"Converting a Model for AWS Neuron"),Y1.forEach(o),gd.forEach(o),fp=h(e),ge=n(e,"P",{});var mn=a(ge);Ag=l(mn,"Using the same script as in "),ns=n(mn,"A",{href:!0,rel:!0});var Q1=a(ns);Cg=l(Q1,"Using TorchScript in Python"),Q1.forEach(o),Dg=l(mn,`
to trace a \u201CBertModel\u201D, you import `),al=n(mn,"CODE",{});var Z1=a(al);Pg=l(Z1,"torch.neuron"),Z1.forEach(o),Sg=l(mn,` framework extension to access
the components of the Neuron SDK through a Python API.`),mn.forEach(o),cp=h(e),m(as.$$.fragment,e),up=h(e),Js=n(e,"P",{});var eE=a(Js);qg=l(eE,"And only modify the tracing line of code"),eE.forEach(o),mp=h(e),Ys=n(e,"P",{});var tE=a(Ys);zg=l(tE,"from:"),tE.forEach(o),gp=h(e),m(rs.$$.fragment,e),_p=h(e),Qs=n(e,"P",{});var oE=a(Qs);Ig=l(oE,"to:"),oE.forEach(o),vp=h(e),m(ls.$$.fragment,e),wp=h(e),Zs=n(e,"P",{});var sE=a(Zs);Mg=l(sE,"This change enables Neuron SDK to trace the model and optimize it to run in Inf1 instances."),sE.forEach(o),Ep=h(e),Ct=n(e,"P",{});var _d=a(Ct);Bg=l(_d,`To learn more about AWS Neuron SDK features, tools, example tutorials and latest updates,
please see the `),is=n(_d,"A",{href:!0,rel:!0});var nE=a(is);Lg=l(nE,"AWS NeuronSDK documentation"),nE.forEach(o),Xg=l(_d,"."),_d.forEach(o),this.h()},h(){f(c,"name","hf:doc:metadata"),f(c,"content",JSON.stringify(_E)),f(x,"id","exporting-transformers-models"),f(x,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(x,"href","#exporting-transformers-models"),f(E,"class","relative group"),f(F,"href","https://github.com/huggingface/optimum"),f(F,"rel","nofollow"),f(R,"id","onnx"),f(R,"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"),f(R,"href","#onnx"),f(U,"class","relative group"),f(ne,"href","http://onnx.ai"),f(ne,"rel","nofollow"),f(Ue,"id","exporting-a-model-to-onnx"),f(Ue,"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"),f(Ue,"href","#exporting-a-model-to-onnx"),f(be,"class","relative group"),f(Ht,"href","https://onnx.ai/supported-tools.html#deployModel"),f(Ht,"rel","nofollow"),f(Wt,"href","https://onnxruntime.ai/"),f(Wt,"rel","nofollow"),f(Vt,"href","https://huggingface.co/keras-io"),f(Vt,"rel","nofollow"),f(Ye,"id","selecting-features-for-different-model-topologies"),f(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"),f(Ye,"href","#selecting-features-for-different-model-topologies"),f(ye,"class","relative group"),f(ot,"id","exporting-a-model-for-an-unsupported-architecture"),f(ot,"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"),f(ot,"href","#exporting-a-model-for-an-unsupported-architecture"),f(xe,"class","relative group"),f(st,"id","implementing-a-custom-onnx-configuration"),f(st,"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"),f(st,"href","#implementing-a-custom-onnx-configuration"),f(ke,"class","relative group"),f(Ns,"href","/docs/transformers/pr_15839/en/main_classes/onnx#transformers.onnx.OnnxConfig"),f(js,"href","/docs/transformers/pr_15839/en/main_classes/onnx#transformers.onnx.OnnxConfigWithPast"),f(Cs,"href","/docs/transformers/pr_15839/en/main_classes/onnx#transformers.onnx.OnnxSeq2SeqConfigWithPast"),f(it,"id","exporting-the-model"),f(it,"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"),f(it,"href","#exporting-the-model"),f(Te,"class","relative group"),f(dt,"id","validating-the-model-outputs"),f(dt,"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"),f(dt,"href","#validating-the-model-outputs"),f(Ne,"class","relative group"),f(ft,"id","contributing-a-new-configuration-to-transformers"),f(ft,"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"),f(ft,"href","#contributing-a-new-configuration-to-transformers"),f(Oe,"class","relative group"),f(Oo,"href","https://github.com/huggingface/transformers/pull/14868/files"),f(Oo,"rel","nofollow"),f(ut,"id","torchscript"),f(ut,"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"),f(ut,"href","#torchscript"),f(je,"class","relative group"),f(Ao,"href","https://pytorch.org/docs/stable/jit.html"),f(Ao,"rel","nofollow"),f(vt,"id","implications"),f(vt,"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"),f(vt,"href","#implications"),f(Ae,"class","relative group"),f(wt,"id","torchscript-flag-and-tied-weights"),f(wt,"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"),f(wt,"href","#torchscript-flag-and-tied-weights"),f(Ce,"class","relative group"),f($t,"id","dummy-inputs-and-standard-lengths"),f($t,"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"),f($t,"href","#dummy-inputs-and-standard-lengths"),f(De,"class","relative group"),f(bt,"id","using-torchscript-in-python"),f(bt,"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"),f(bt,"href","#using-torchscript-in-python"),f(Pe,"class","relative group"),f(yt,"id","saving-a-model"),f(yt,"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"),f(yt,"href","#saving-a-model"),f(Se,"class","relative group"),f(xt,"id","loading-a-model"),f(xt,"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"),f(xt,"href","#loading-a-model"),f(qe,"class","relative group"),f(kt,"id","using-a-traced-model-for-inference"),f(kt,"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"),f(kt,"href","#using-a-traced-model-for-inference"),f(ze,"class","relative group"),f(Nt,"id","deploying-huggingface-torchscript-models-on-aws-using-the-neuron-sdk"),f(Nt,"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"),f(Nt,"href","#deploying-huggingface-torchscript-models-on-aws-using-the-neuron-sdk"),f(Ie,"class","relative group"),f(Ro,"href","https://aws.amazon.com/ec2/instance-types/inf1/"),f(Ro,"rel","nofollow"),f(Ho,"href","https://awsdocs-neuron.readthedocs-hosted.com/en/latest/#"),f(Ho,"rel","nofollow"),f(Wo,"href","https://awsdocs-neuron.readthedocs-hosted.com/en/latest/neuron-guide/benchmark/%3E"),f(Wo,"rel","nofollow"),f(Ko,"href","https://awsdocs-neuron.readthedocs-hosted.com/en/latest/src/examples/pytorch/bert_tutorial/tutorial_pretrained_bert.html"),f(Ko,"rel","nofollow"),f(Uo,"href","https://awsdocs-neuron.readthedocs-hosted.com/en/latest/src/examples/tensorflow/huggingface_bert/huggingface_bert.html"),f(Uo,"rel","nofollow"),f(Ot,"id","implications"),f(Ot,"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"),f(Ot,"href","#implications"),f(Be,"class","relative group"),f(Go,"href","https://huggingface.co/docs/transformers/master/model_doc/bert"),f(Go,"rel","nofollow"),f(Jo,"href","https://huggingface.co/docs/transformers/master/model_doc/distilbert"),f(Jo,"rel","nofollow"),f(Yo,"href","https://huggingface.co/docs/transformers/master/model_doc/roberta"),f(Yo,"rel","nofollow"),f(Qo,"href","https://awsdocs-neuron.readthedocs-hosted.com/en/latest/src/examples/pytorch/transformers-marianmt.html"),f(Qo,"rel","nofollow"),f(Zo,"href","https://awsdocs-neuron.readthedocs-hosted.com/en/latest/neuron-guide/models/models-inferentia.html#models-inferentia"),f(Zo,"rel","nofollow"),f(jt,"id","dependencies"),f(jt,"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"),f(jt,"href","#dependencies"),f(Le,"class","relative group"),f(ts,"href","https://awsdocs-neuron.readthedocs-hosted.com/en/latest/neuron-guide/neuron-frameworks/pytorch-neuron/index.html#installation-guide"),f(ts,"rel","nofollow"),f(os,"href","https://docs.aws.amazon.com/dlami/latest/devguide/tutorial-inferentia-launching.html"),f(os,"rel","nofollow"),f(At,"id","converting-a-model-for-aws-neuron"),f(At,"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"),f(At,"href","#converting-a-model-for-aws-neuron"),f(Fe,"class","relative group"),f(ns,"href","https://huggingface.co/docs/transformers/master/en/serialization#using-torchscript-in-python"),f(ns,"rel","nofollow"),f(is,"href","https://awsdocs-neuron.readthedocs-hosted.com/en/latest/index.html"),f(is,"rel","nofollow")},m(e,i){t(document.head,c),p(e,k,i),p(e,E,i),t(E,x),t(x,j),g(y,j,null),t(E,O),t(E,A),t(A,N),p(e,T,i),p(e,q,i),t(q,P),p(e,z,i),p(e,X,i),t(X,J),t(X,F),t(F,zt),t(X,we),p(e,He,i),p(e,U,i),t(U,R),t(R,Ee),g(se,Ee,null),t(U,$e),t(U,C),t(C,hs),p(e,It,i),p(e,V,i),t(V,fs),t(V,ne),t(ne,cs),t(V,us),t(V,_n),t(_n,vd),t(V,wd),p(e,dl,i),p(e,ms,i),t(ms,Ed),p(e,hl,i),p(e,We,i),t(We,$d),t(We,vn),t(vn,bd),t(We,yd),p(e,fl,i),p(e,gs,i),t(gs,xd),p(e,cl,i),p(e,$,i),t($,wn),t(wn,kd),t($,Td),t($,En),t(En,Nd),t($,Od),t($,$n),t($n,jd),t($,Ad),t($,bn),t(bn,Cd),t($,Dd),t($,yn),t(yn,Pd),t($,Sd),t($,xn),t(xn,qd),t($,zd),t($,k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),t(Je,Xh),p(e,Cl,i),g(Gt,e,i),p(e,Dl,i),p(e,$s,i),t($s,Fh),p(e,Pl,i),g(Jt,e,i),p(e,Sl,i),p(e,re,i),t(re,Rh),t(re,Vn),t(Vn,Hh),t(re,Wh),t(re,Gn),t(Gn,Kh),t(re,Uh),p(e,ql,i),g(Yt,e,i),p(e,zl,i),p(e,ye,i),t(ye,Ye),t(Ye,Jn),g(Qt,Jn,null),t(ye,Vh),t(ye,Yn),t(Yn,Gh),p(e,Il,i),p(e,Qe,i),t(Qe,Jh),t(Qe,Qn),t(Qn,Yh),t(Qe,Qh),p(e,Ml,i),p(e,Ze,i),t(Ze,Zn),t(Zn,Zt),t(Zt,ea),t(ea,Zh),t(Zt,ef),t(Zt,ta),t(ta,tf),t(Ze,of),t(Ze,I),t(I,eo),t(eo,to),t(to,oa),t(oa,sf),t(to,nf),t(to,sa),t(sa,af),t(eo,rf),t(eo,na),t(na,aa),t(aa,lf),t(I,pf),t(I,oo),t(oo,so),t(so,ra),t(ra,df),t(so,hf),t(so,la),t(la,ff),t(oo,cf),t(oo,ia),t(ia,pa),t(pa,uf),t(I,mf),t(I,no),t(no,da),t(da,ha),t(ha,gf),t(no,_f),t(no,fa),t(fa,ca),t(ca,vf),t(I,wf),t(I,ao),t(ao,ua),t(ua,ma),t(ma,Ef),t(ao,$f),t(ao,ga),t(ga,_a),t(_a,bf),t(I,yf),t(I,ro),t(ro,lo),t(lo,va),t(va,xf),t(lo,kf),t(lo,wa),t(wa,Tf),t(ro,Nf),t(ro,Ea),t(Ea,$a),t($a,Of),t(I,jf),t(I,io),t(io,ba),t(ba,ya),t(ya,Af),t(io,Cf),t(io,xa),t(xa,ka),t(ka,Df),t(I,Pf),t(I,po),t(po,Ta),t(Ta,Na),t(Na,Sf),t(po,qf),t(po,Oa),t(Oa,ja),t(ja,zf),p(e,Bl,i),p(e,et,i),t(et,If),t(et,Aa),t(Aa,Mf),t(et,Bf),p(e,Ll,i),g(ho,e,i),p(e,Xl,i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i,i),p(e,Ss,i),t(Ss,Pc),p(e,di,i),g(wo,e,i),p(e,hi,i),p(e,W,i),t(W,Sc),t(W,Va),t(Va,qc),t(W,zc),t(W,Ga),t(Ga,Ic),t(W,Mc),t(W,Ja),t(Ja,Bc),t(W,Lc),t(W,Ya),t(Ya,Xc),t(W,Fc),p(e,fi,i),g(Eo,e,i),p(e,ci,i),g(lt,e,i),p(e,ui,i),p(e,Te,i),t(Te,it),t(it,Qa),g($o,Qa,null),t(Te,Rc),t(Te,Za),t(Za,Hc),p(e,mi,i),p(e,de,i),t(de,Wc),t(de,er),t(er,Kc),t(de,Uc),t(de,tr),t(tr,Vc),t(de,Gc),p(e,gi,i),g(bo,e,i),p(e,_i,i),p(e,M,i),t(M,Jc),t(M,or),t(or,Yc),t(M,Qc),t(M,sr),t(sr,Zc),t(M,eu),t(M,nr),t(nr,tu),t(M,ou),t(M,ar),t(ar,su),t(M,nu),t(M,rr),t(rr,au),t(M,ru),p(e,vi,i),g(yo,e,i),p(e,wi,i),g(pt,e,i),p(e,Ei,i),p(e,Ne,i),t(Ne,dt),t(dt,lr),g(xo,lr,null),t(Ne,lu),t(Ne,ir),t(ir,iu),p(e,$i,i),p(e,he,i),t(he,pu),t(he,pr),t(pr,du),t(he,hu),t(he,dr),t(dr,fu),t(he,cu),p(e,bi,i),g(ko,e,i),p(e,yi,i),p(e,ht,i),t(ht,uu),t(ht,hr),t(hr,mu),t(ht,gu),p(e,xi,i),p(e,Oe,i),t(Oe,ft),t(ft,fr),g(To,fr,null),t(Oe,_u),t(Oe,cr),t(cr,vu),p(e,ki,i),p(e,qs,i),t(qs,wu),p(e,Ti,i),p(e,fe,i),t(fe,No),t(No,Eu),t(No,ur),t(ur,$u),t(No,bu),t(fe,yu),t(fe,zs),t(zs,xu),t(zs,mr),t(mr,ku),t(fe,Tu),t(fe,Is),t(Is,Nu),t(Is,gr),t(gr,Ou),p(e,Ni,i),p(e,ct,i),t(ct,ju),t(ct,Oo),t(Oo,Au),t(ct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t(B,mg),t(B,Qo),t(Qo,gg),t(B,_g),t(B,Zo),t(Zo,vg),t(B,wg),p(e,ip,i),p(e,Le,i),t(Le,jt),t(jt,tl),g(es,tl,null),t(Le,Eg),t(Le,ol),t(ol,$g),p(e,pp,i),p(e,Vs,i),t(Vs,bg),p(e,dp,i),p(e,Gs,i),t(Gs,Xe),t(Xe,yg),t(Xe,ts),t(ts,xg),t(Xe,kg),t(Xe,os),t(os,Tg),t(Xe,Ng),p(e,hp,i),p(e,Fe,i),t(Fe,At),t(At,sl),g(ss,sl,null),t(Fe,Og),t(Fe,nl),t(nl,jg),p(e,fp,i),p(e,ge,i),t(ge,Ag),t(ge,ns),t(ns,Cg),t(ge,Dg),t(ge,al),t(al,Pg),t(ge,Sg),p(e,cp,i),g(as,e,i),p(e,up,i),p(e,Js,i),t(Js,qg),p(e,mp,i),p(e,Ys,i),t(Ys,zg),p(e,gp,i),g(rs,e,i),p(e,_p,i),p(e,Qs,i),t(Qs,Ig),p(e,vp,i),g(ls,e,i),p(e,wp,i),p(e,Zs,i),t(Zs,Mg),p(e,Ep,i),p(e,Ct,i),t(Ct,Bg),t(Ct,is),t(is,Lg),t(Ct,Xg),$p=!0},p(e,[i]){const ps={};i&2&&(ps.$$scope={dirty:i,ctx:e}),tt.$set(ps);const rl={};i&2&&(rl.$$scope={dirty:i,ctx:e}),nt.$set(rl);const ll={};i&2&&(ll.$$scope={dirty:i,ctx:e}),rt.$set(ll);const il={};i&2&&(il.$$scope={dirty:i,ctx:e}),lt.$set(il);const pl={};i&2&&(pl.$$scope={dirty:i,ctx:e}),pt.$set(pl);const ds={};i&2&&(ds.$$scope={dirty:i,ctx:e}),mt.$set(ds)},i(e){$p||(_(y.$$.fragment,e),_(se.$$.fragment,e),_(Bt.$$.fragment,e),_(Lt.$$.fragment,e),_(Xt.$$.fragment,e),_(Ft.$$.fragment,e),_(Rt.$$.fragment,e),_(Kt.$$.fragment,e),_(Ut.$$.fragment,e),_(Gt.$$.fragment,e),_(Jt.$$.fragment,e),_(Yt.$$.fragment,e),_(Qt.$$.fragment,e),_(ho.$$.fragment,e),_(fo.$$.fragment,e),_(co.$$.fragment,e),_(tt.$$.fragment,e),_(uo.$$.fragment,e),_(mo.$$.fragment,e),_(nt.$$.fragment,e),_(go.$$.fragment,e),_(rt.$$.fragment,e),_(_o.$$.fragment,e),_(vo.$$.fragment,e),_(wo.$$.fragment,e),_(Eo.$$.fragment,e),_(lt.$$.fragment,e),_($o.$$.fragment,e),_(bo.$$.fragment,e),_(yo.$$.fragment,e),_(pt.$$.fragment,e),_(xo.$$.fragment,e),_(ko.$$.fragment,e),_(To.$$.fragment,e),_(jo.$$.fragment,e),_(mt.$$.fragment,e),_(Do.$$.fragment,e),_(Po.$$.fragment,e),_(So.$$.fragment,e),_(qo.$$.fragment,e),_(zo.$$.fragment,e),_(Io.$$.fragment,e),_(Mo.$$.fragment,e),_(Bo.$$.fragment,e),_(Lo.$$.fragment,e),_(Xo.$$.fragment,e),_(Fo.$$.fragment,e),_(Vo.$$.fragment,e),_(es.$$.fragment,e),_(ss.$$.fragment,e),_(as.$$.fragment,e),_(rs.$$.fragment,e),_(ls.$$.fragment,e),$p=!0)},o(e){v(y.$$.fragment,e),v(se.$$.fragment,e),v(Bt.$$.fragment,e),v(Lt.$$.fragment,e),v(Xt.$$.fragment,e),v(Ft.$$.fragment,e),v(Rt.$$.fragment,e),v(Kt.$$.fragment,e),v(Ut.$$.fragment,e),v(Gt.$$.fragment,e),v(Jt.$$.fragment,e),v(Yt.$$.fragment,e),v(Qt.$$.fragment,e),v(ho.$$.fragment,e),v(fo.$$.fragment,e),v(co.$$.fragment,e),v(tt.$$.fragment,e),v(uo.$$.fragment,e),v(mo.$$.fragment,e),v(nt.$$.fragment,e),v(go.$$.fragment,e),v(rt.$$.fragment,e),v(_o.$$.fragment,e),v(vo.$$.fragment,e),v(wo.$$.fragment,e),v(Eo.$$.fragment,e),v(lt.$$.fragment,e),v($o.$$.fragment,e),v(bo.$$.fragment,e),v(yo.$$.fragment,e),v(pt.$$.fragment,e),v(xo.$$.fragment,e),v(ko.$$.fragment,e),v(To.$$.fragment,e),v(jo.$$.fragment,e),v(mt.$$.fragment,e),v(Do.$$.fragment,e),v(Po.$$.fragment,e),v(So.$$.fragment,e),v(qo.$$.fragment,e),v(zo.$$.fragment,e),v(Io.$$.fragment,e),v(Mo.$$.fragment,e),v(Bo.$$.fragment,e),v(Lo.$$.fragment,e),v(Xo.$$.fragment,e),v(Fo.$$.fragment,e),v(Vo.$$.fragment,e),v(es.$$.fragment,e),v(ss.$$.fragment,e),v(as.$$.fragment,e),v(rs.$$.fragment,e),v(ls.$$.fragment,e),$p=!1},d(e){o(c),e&&o(k),e&&o(E),w(y),e&&o(T),e&&o(q),e&&o(z),e&&o(X),e&&o(He),e&&o(U),w(se),e&&o(It),e&&o(V),e&&o(dl),e&&o(ms),e&&o(hl),e&&o(We),e&&o(fl),e&&o(gs),e&&o(cl),e&&o($),e&&o(ul),e&&o(_s),e&&o(ml),e&&o(Ke),e&&o(gl),e&&o(be),w(Bt),e&&o(_l),e&&o(vs),e&&o(vl),w(Lt,e),e&&o(wl),e&&o(Ve),e&&o(El),w(Xt,e),e&&o($l),e&&o(ws),e&&o(bl),w(Ft,e),e&&o(yl),e&&o(Es),e&&o(xl),w(Rt,e),e&&o(kl),e&&o(ae),e&&o(Tl),e&&o(Y),e&&o(Nl),w(Kt,e),e&&o(Ol),e&&o(Ge),e&&o(jl),w(Ut,e),e&&o(Al),e&&o(Je),e&&o(Cl),w(Gt,e),e&&o(Dl),e&&o($s),e&&o(Pl),w(Jt,e),e&&o(Sl),e&&o(re),e&&o(ql),w(Yt,e),e&&o(zl),e&&o(ye),w(Qt),e&&o(Il),e&&o(Qe),e&&o(Ml),e&&o(Ze),e&&o(Bl),e&&o(et),e&&o(Ll),w(ho,e),e&&o(Xl),e&&o(le),e&&o(Fl),w(fo,e),e&&o(Rl),e&&o(bs),e&&o(Hl),w(co,e),e&&o(Wl),e&&o(Q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&&o(qe),w(Mo),e&&o(Qi),e&&o(ee),e&&o(Zi),w(Bo,e),e&&o(ep),e&&o(ze),w(Lo),e&&o(tp),e&&o(Tt),e&&o(op),w(Xo,e),e&&o(sp),e&&o(Ie),w(Fo),e&&o(np),e&&o(ue),e&&o(ap),e&&o(me),e&&o(rp),e&&o(Be),w(Vo),e&&o(lp),e&&o(B),e&&o(ip),e&&o(Le),w(es),e&&o(pp),e&&o(Vs),e&&o(dp),e&&o(Gs),e&&o(hp),e&&o(Fe),w(ss),e&&o(fp),e&&o(ge),e&&o(cp),w(as,e),e&&o(up),e&&o(Js),e&&o(mp),e&&o(Ys),e&&o(gp),w(rs,e),e&&o(_p),e&&o(Qs),e&&o(vp),w(ls,e),e&&o(wp),e&&o(Zs),e&&o(Ep),e&&o(Ct)}}}const _E={local:"exporting-transformers-models",sections:[{local:"onnx",sections:[{local:"exporting-a-model-to-onnx",title:"Exporting a model to ONNX"},{local:"selecting-features-for-different-model-topologies",title:"Selecting features for different model topologies"},{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:"ONNX"},{local:"torchscript",sections:[{local:"implications",title:"Implications"},{local:"torchscript-flag-and-tied-weights",title:"TorchScript flag and tied weights"},{local:"dummy-inputs-and-standard-lengths",title:"Dummy inputs and standard lengths"},{local:"using-torchscript-in-python",sections:[{local:"saving-a-model",title:"Saving a model"},{local:"loading-a-model",title:"Loading a model"},{local:"using-a-traced-model-for-inference",title:"Using a traced model for inference"}],title:"Using TorchScript in Python"},{local:"deploying-huggingface-torchscript-models-on-aws-using-the-neuron-sdk",sections:[{local:"implications",title:"Implications"},{local:"dependencies",title:"Dependencies"},{local:"converting-a-model-for-aws-neuron",title:"Converting a Model for AWS Neuron"}],title:"Deploying HuggingFace TorchScript models on AWS using the Neuron SDK"}],title:"TorchScript"}],title:"Exporting \u{1F917} Transformers Models"};function vE(L,c,k){let{fw:E}=c;return L.$$set=x=>{"fw"in x&&k(0,E=x.fw)},[E]}class kE extends rE{constructor(c){super();lE(this,c,vE,gE,iE,{fw:0})}}export{kE as default,_E as metadata};
