import{S as Lw,i as Ow,s as Aw,e as a,k as h,w as k,t as r,M as Nw,c as s,d as o,m as c,a as n,x as F,h as l,b as f,G as e,g as d,y as $,q as P,o as I,B,v as Dw}from"../chunks/vendor-hf-doc-builder.js";import{T as Cw}from"../chunks/Tip-hf-doc-builder.js";import{I as ht}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as ct}from"../chunks/CodeBlock-hf-doc-builder.js";function Mw(to){let m,q,v,_,H,b,p,J,M,C,x,j,le,ft,V,Ae,ae,K,Ne,se;return{c(){m=a("p"),q=r("Are you unsure whether the model you wish to use already has a corresponding TensorFlow architecture?"),v=h(),_=a("p"),H=r("\xA0"),b=h(),p=a("p"),J=r("Check the "),M=a("code"),C=r("model_type"),x=r(" field of the "),j=a("code"),le=r("config.json"),ft=r(` of your model of choice
(`),V=a("a"),Ae=r("example"),ae=r(`). If the corresponding model folder in
\u{1F917} Transformers has a file whose name starts with \u201Cmodeling_tf\u201D, it means that it has a corresponding TensorFlow
architecture (`),K=a("a"),Ne=r("example"),se=r(")."),this.h()},l(y){m=s(y,"P",{});var G=n(m);q=l(G,"Are you unsure whether the model you wish to use already has a corresponding TensorFlow architecture?"),G.forEach(o),v=c(y),_=s(y,"P",{});var ee=n(_);H=l(ee,"\xA0"),ee.forEach(o),b=c(y),p=s(y,"P",{});var O=n(p);J=l(O,"Check the "),M=s(O,"CODE",{});var ve=n(M);C=l(ve,"model_type"),ve.forEach(o),x=l(O," field of the "),j=s(O,"CODE",{});var oo=n(j);le=l(oo,"config.json"),oo.forEach(o),ft=l(O,` of your model of choice
(`),V=s(O,"A",{href:!0,rel:!0});var ro=n(V);Ae=l(ro,"example"),ro.forEach(o),ae=l(O,`). If the corresponding model folder in
\u{1F917} Transformers has a file whose name starts with \u201Cmodeling_tf\u201D, it means that it has a corresponding TensorFlow
architecture (`),K=s(O,"A",{href:!0,rel:!0});var De=n(K);Ne=l(De,"example"),De.forEach(o),se=l(O,")."),O.forEach(o),this.h()},h(){f(V,"href","https://huggingface.co/bert-base-uncased/blob/main/config.json#L14"),f(V,"rel","nofollow"),f(K,"href","https://github.com/huggingface/transformers/tree/main/src/transformers/models/bert"),f(K,"rel","nofollow")},m(y,G){d(y,m,G),e(m,q),d(y,v,G),d(y,_,G),e(_,H),d(y,b,G),d(y,p,G),e(p,J),e(p,M),e(M,C),e(p,x),e(p,j),e(j,le),e(p,ft),e(p,V),e(V,Ae),e(p,ae),e(p,K),e(K,Ne),e(p,se)},d(y){y&&o(m),y&&o(v),y&&o(_),y&&o(b),y&&o(p)}}}function xw(to){let m,q,v,_,H,b,p,J;return{c(){m=a("p"),q=r(`Before starting the work on a TensorFlow model architecture, double-check that there is no ongoing effort to do so.
You can search for `),v=a("code"),_=r("BrandNewBert"),H=r(` on the
`),b=a("a"),p=r("pull request GitHub page"),J=r(` to confirm that there is no
TensorFlow-related pull request.`),this.h()},l(M){m=s(M,"P",{});var C=n(m);q=l(C,`Before starting the work on a TensorFlow model architecture, double-check that there is no ongoing effort to do so.
You can search for `),v=s(C,"CODE",{});var x=n(v);_=l(x,"BrandNewBert"),x.forEach(o),H=l(C,` on the
`),b=s(C,"A",{href:!0,rel:!0});var j=n(b);p=l(j,"pull request GitHub page"),j.forEach(o),J=l(C,` to confirm that there is no
TensorFlow-related pull request.`),C.forEach(o),this.h()},h(){f(b,"href","https://github.com/huggingface/transformers/pulls?q=is%3Apr"),f(b,"rel","nofollow")},m(M,C){d(M,m,C),e(m,q),e(m,v),e(v,_),e(m,H),e(m,b),e(b,p),e(m,J)},d(M){M&&o(m)}}}function Rw(to){let m,q,v,_,H,b,p,J,M,C,x,j,le,ft,V,Ae,ae,K,Ne,se,y,G,ee,O,ve,oo,ro,De,mt,hn,ya,lo,cn,va,Me,ba,be,xe,qo,ut,fn,jo,mn,ga,Re,un,ao,pn,wn,_a,ne,Xo,yn,vn,zo,bn,gn,Qo,_n,Ea,so,En,Ta,E,Vo,Tn,kn,Ko,Fn,$n,er,Pn,In,tr,Bn,Cn,or,Ln,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{default:[xw]},$$scope:{ctx:to}}}),bt=new ct({props:{code:"Z2l0JTIwY2xvbmUlMjBodHRwcyUzQSUyRiUyRmdpdGh1Yi5jb20lMkYlNUJ5b3VyJTIwR2l0aHViJTIwaGFuZGxlJTVEJTJGdHJhbnNmb3JtZXJzLmdpdCUwQWNkJTIwdHJhbnNmb3JtZXJzJTBBZ2l0JTIwcmVtb3RlJTIwYWRkJTIwdXBzdHJlYW0lMjBodHRwcyUzQSUyRiUyRmdpdGh1Yi5jb20lMkZodWdnaW5nZmFjZSUyRnRyYW5zZm9ybWVycy5naXQ=",highlighted:`git <span class="hljs-built_in">clone</span> https://github.com/[your Github handle]/transformers.git
<span class="hljs-built_in">cd</span> transformers
git remote add upstream https://github.com/huggingface/transformers.git`}}),_t=new ct({props:{code:"cHl0aG9uJTIwLW0lMjB2ZW52JTIwLmVudiUwQXNvdXJjZSUyMC5lbnYlMkZiaW4lMkZhY3RpdmF0ZSUwQXBpcCUyMGluc3RhbGwlMjAtZSUyMCUyMi4lNUJkZXYlNUQlMjI=",highlighted:`python -m venv .<span class="hljs-built_in">env</span>
<span class="hljs-built_in">source</span> .<span class="hljs-built_in">env</span>/bin/activate
pip install -e <span class="hljs-string">&quot;.[dev]&quot;</span>`}}),Et=new ct({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1lJTIwJTIyLiU1QnF1YWxpdHklNUQlMjI=",highlighted:'pip install -e <span class="hljs-string">&quot;.[quality]&quot;</span>'}}),Ft=new ct({props:{code:"Z2l0JTIwY2hlY2tvdXQlMjAtYiUyMGFkZF90Zl9icmFuZF9uZXdfYmVydA==",highlighted:"git checkout -b add_tf_brand_new_bert"}}),Pt=new ct({props:{code:"Z2l0JTIwZmV0Y2glMjB1cHN0cmVhbSUwQWdpdCUyMHJlYmFzZSUyMHVwc3RyZWFtJTJGbWFpbg==",highlighted:`git fetch upstream
git rebase upstream/main`}}),It=new ct({props:{code:"Z2l0JTIwYWRkJTIwLiUwQWdpdCUyMGNvbW1pdCUyMC1tJTIwJTIyaW5pdGlhbCUyMGNvbW1pdCUyMiUwQWdpdCUyMHB1c2glMjAtdSUyMG9yaWdpbiUyMGFkZF90Zl9icmFuZF9uZXdfYmVydA==",highlighted:`git add .
git commit -m <span class="hljs-string">&quot;initial commit&quot;</span>
git push -u origin add_tf_brand_new_bert`}}),Ct=new ht({}),Zt=new ht({}),Wt=new ct({props:{code:"TlZJRElBX1RGMzJfT1ZFUlJJREUlM0QwJTIwUlVOX1NMT1clM0QxJTIwUlVOX1BUX1RGX0NST1NTX1RFU1RTJTNEMSUyMCU1QyUwQXB5LnRlc3QlMjAtdnYlMjB0ZXN0cyUyRm1vZGVscyUyRmJyYW5kX25ld19iZXJ0JTJGdGVzdF9tb2RlbGluZ190Zl9icmFuZF9uZXdfYmVydC5weQ==",highlighted:`NVIDIA_TF32_OVERRIDE=0 RUN_SLOW=1 RUN_PT_TF_CROSS_TESTS=1 \\
py.test -vv tests/models/brand_new_bert/test_modeling_tf_brand_new_bert.py`}}),Yt=new ht({}),qt=new ct({props:{code:"TlZJRElBX1RGMzJfT1ZFUlJJREUlM0QwJTIwUlVOX1NMT1clM0QxJTIwUlVOX1BUX1RGX0NST1NTX1RFU1RTJTNEMSUyMCU1QyUwQXB5LnRlc3QlMjAtdnYlMjB0ZXN0cyUyRm1vZGVscyUyRmJyYW5kX25ld19iZXJ0JTJGdGVzdF9tb2RlbGluZ190Zl9icmFuZF9uZXdfYmVydC5weQ==",highlighted:`NVIDIA_TF32_OVERRIDE=0 RUN_SLOW=1 RUN_PT_TF_CROSS_TESTS=1 \\
py.test -vv tests/models/brand_new_bert/test_modeling_tf_brand_new_bert.py`}}),zt=new ht({}),Vt=new ht({}),{c(){m=a("meta"),q=h(),v=a("h1"),_=a("a"),H=a("span"),k(b.$$.fragment),p=h(),J=a("span"),M=r("How to convert a \u{1F917} Transformers model to TensorFlow?"),C=h(),x=a("p"),j=r(`Having multiple frameworks available to use with \u{1F917} Transformers gives you flexibility to play their strengths when
designing your application, but it implies that compatibility must be added on a per-model basis. The good news is that
adding TensorFlow compatibility to an existing model is simpler than `),le=a("a"),ft=r("adding a new model from scratch"),V=r(`!
Whether you wish to have a deeper understanding of large TensorFlow models, make a major open-source contribution, or
enable TensorFlow for your model of choice, this guide is for you.`),Ae=h(),ae=a("p"),K=r(`This guide empowers you, a member of our community, to contribute TensorFlow model weights and/or
architectures to be used in \u{1F917} Transformers, with minimal supervision from the Hugging Face team. Writing a new model
is no small feat, but hopefully this guide will make it less of a rollercoaster \u{1F3A2} and more of a walk in the park \u{1F6B6}.
Harnessing our collective experiences is absolutely critical to make this process increasingly easier, and thus we
highly encourage that you suggest improvements to this guide!`),Ne=h(),se=a("p"),y=r("Before you dive deeper, it is recommended that you check the following resources if you\u2019re new to \u{1F917} Transformers:"),G=h(),ee=a("ul"),O=a("li"),ve=a("a"),oo=r("General overview of \u{1F917} Transformers"),ro=h(),De=a("li"),mt=a("a"),hn=r("Hugging Face\u2019s TensorFlow Philosophy"),ya=h(),lo=a("p"),cn=r(`In the remainder of this guide, you will learn what\u2019s needed to add a new TensorFlow model architecture, the
procedure to convert PyTorch into TensorFlow model weights, and how to efficiently debug mismatches across ML
frameworks. Let\u2019s get started!`),va=h(),k(Me.$$.fragment),ba=h(),be=a("h2"),xe=a("a"),qo=a("span"),k(ut.$$.fragment),fn=h(),jo=a("span"),mn=r("Step-by-step guide to add TensorFlow model architecture code"),ga=h(),Re=a("p"),un=r(`There are many ways to design a large model architecture, and multiple ways of implementing said design. However,
you might recall from our `),ao=a("a"),pn=r("general overview of \u{1F917} Transformers"),wn=r(`
that we are an opinionated bunch - the ease of use of \u{1F917} Transformers relies on consistent design choices. From
experience, we can tell you a few important things about adding TensorFlow models:`),_a=h(),ne=a("ul"),Xo=a("li"),yn=r(`Don\u2019t reinvent the wheel! More often than not, there are at least two reference implementations you should check: the
PyTorch equivalent of the model you are implementing and other TensorFlow models for the same class of problems.`),vn=h(),zo=a("li"),bn=r(`Great model implementations survive the test of time. This doesn\u2019t happen because the code is pretty, but rather
because the code is clear, easy to debug and build upon. If you make the life of the maintainers easy with your
TensorFlow implementation, by replicating the same patterns as in other TensorFlow models and minimizing the mismatch
to the PyTorch implementation, you ensure your contribution will be long lived.`),gn=h(),Qo=a("li"),_n=r(`Ask for help when you\u2019re stuck! The \u{1F917} Transformers team is here to help, and we\u2019ve probably found solutions to the same
problems you\u2019re facing.`),Ea=h(),so=a("p"),En=r("Here\u2019s an overview of the steps needed to add a TensorFlow model architecture:"),Ta=h(),E=a("ol"),Vo=a("li"),Tn=r("Select the model you wish to convert"),kn=h(),Ko=a("li"),Fn=r("Prepare transformers dev environment"),$n=h(),er=a("li"),Pn=r("(Optional) Understand theoretical aspects and the existing implementation"),In=h(),tr=a("li"),Bn=r("Implement the model architecture"),Cn=h(),or=a("li"),Ln=r("Implement model tests"),On=h(),rr=a("li"),An=r("Submit the pull request"),Nn=h(),lr=a("li"),Dn=r("(Optional) Build demos and share with the world"),ka=h(),ge=a("h3"),Se=a("a"),ar=a("span"),k(pt.$$.fragment),Mn=h(),sr=a("span"),xn=r("1.-3. Prepare your model contribution"),Fa=h(),no=a("p"),nr=a("strong"),Rn=r("1. Select the model you wish to convert"),$a=h(),Ue=a("p"),Sn=r(`Let\u2019s start off with the basics: the first thing you need to know is the architecture you want to convert. If you
don\u2019t have your eyes set on a specific architecture, asking the \u{1F917} Transformers team for suggestions is a great way to
maximize your impact - we will guide you towards the most prominent architectures that are missing on the TensorFlow
side. If the specific model you want to use with TensorFlow already has a TensorFlow architecture implementation in
\u{1F917} Transformers but is lacking weights, feel free to jump straight into the
`),io=a("a"),Un=r("weight conversion section"),Hn=r(`
of this page.`),Pa=h(),ie=a("p"),Jn=r(`For simplicity, the remainder of this guide assumes you\u2019ve decided to contribute with the TensorFlow version of
`),ir=a("em"),Gn=r("BrandNewBert"),Zn=r(" (the same example as in the "),ho=a("a"),Wn=r("guide"),Yn=r(" to add a new model from scratch)."),Ia=h(),k(He.$$.fragment),Ba=h(),co=a("p"),dr=a("strong"),qn=r("2. Prepare transformers dev environment"),Ca=h(),fo=a("p"),jn=r(`Having selected the model architecture, open a draft PR to signal your intention to work on it. Follow the
instructions below to set up your environment and open a draft PR.`),La=h(),Je=a("ol"),hr=a("li"),wt=a("p"),Xn=r("Fork the "),yt=a("a"),zn=r("repository"),Qn=r(` by clicking on the \u2018Fork\u2019 button on the
repository\u2019s page. This creates a copy of the code under your GitHub user account.`),Vn=h(),cr=a("li"),vt=a("p"),Kn=r("Clone your "),fr=a("code"),ei=r("transformers"),ti=r(" fork to your local disk, and add the base repository as a remote:"),Oa=h(),k(bt.$$.fragment),Aa=h(),gt=a("ol"),mr=a("li"),oi=r("Set up a development environment, for instance by running the following command:"),Na=h(),k(_t.$$.fragment),Da=h(),mo=a("p"),ri=r(`Depending on your OS, and since the number of optional dependencies of Transformers is growing, you might get a
failure with this command. If that\u2019s the case make sure to install TensorFlow then do:`),Ma=h(),k(Et.$$.fragment),xa=h(),Tt=a("p"),ur=a("strong"),li=r("Note:"),ai=r(" You don\u2019t need to have CUDA installed. Making the new model work on CPU is sufficient."),Ra=h(),kt=a("ol"),pr=a("li"),si=r("Create a branch with a descriptive name from your main branch"),Sa=h(),k(Ft.$$.fragment),Ua=h(),$t=a("ol"),wr=a("li"),ni=r("Fetch and rebase to current main"),Ha=h(),k(Pt.$$.fragment),Ja=h(),_e=a("ol"),yr=a("li"),te=a("p"),ii=r("Add an empty "),vr=a("code"),di=r(".py"),hi=r(" file in "),br=a("code"),ci=r("transformers/src/models/brandnewbert/"),fi=r(" named "),gr=a("code"),mi=r("modeling_tf_brandnewbert.py"),ui=r(`. This will
be your TensorFlow model file.`),pi=h(),_r=a("li"),Er=a("p"),wi=r("Push the changes to your account using:"),Ga=h(),k(It.$$.fragment),Za=h(),Ee=a("ol"),Tr=a("li"),kr=a("p"),yi=r(`Once you are satisfied, go to the webpage of your fork on GitHub. Click on \u201CPull request\u201D. Make sure to add the
GitHub handle of some members of the Hugging Face team as reviewers, so that the Hugging Face team gets notified for
future changes.`),vi=h(),Fr=a("li"),$r=a("p"),bi=r("Change the PR into a draft by clicking on \u201CConvert to draft\u201D on the right of the GitHub pull request web page."),Wa=h(),Ge=a("p"),gi=r("Now you have set up a development environment to port "),Pr=a("em"),_i=r("BrandNewBert"),Ei=r(" to TensorFlow in \u{1F917} Transformers."),Ya=h(),uo=a("p"),Ir=a("strong"),Ti=r("3. (Optional) Understand theoretical aspects and the existing implementation"),qa=h(),de=a("p"),ki=r("You should take some time to read "),Br=a("em"),Fi=r("BrandNewBert\u2019s"),$i=r(` paper, if such descriptive work exists. There might be large
sections of the paper that are difficult to understand. If this is the case, this is fine - don\u2019t worry! The goal is
not to get a deep theoretical understanding of the paper, but to extract the necessary information required to
effectively re-implement the model in \u{1F917} Transformers using TensorFlow. That being said, you don\u2019t have to spend too
much time on the theoretical aspects, but rather focus on the practical ones, namely the existing model documentation
page (e.g. `),po=a("a"),Pi=r("model docs for BERT"),Ii=r(")."),ja=h(),wo=a("p"),Bi=r(`After you\u2019ve grasped the basics of the models you are about to implement, it\u2019s important to understand the existing
implementation. This is a great chance to confirm that a working implementation matches your expectations for the
model, as well as to foresee technical challenges on the TensorFlow side.`),Xa=h(),Ze=a("p"),Ci=r(`It\u2019s perfectly natural that you feel overwhelmed with the amount of information that you\u2019ve just absorbed. It is
definitely not a requirement that you understand all facets of the model at this stage. Nevertheless, we highly
encourage you to clear any pressing questions in our `),Bt=a("a"),Li=r("forum"),Oi=r("."),za=h(),Te=a("h3"),We=a("a"),Cr=a("span"),k(Ct.$$.fragment),Ai=h(),Lr=a("span"),Ni=r("4. Model implementation"),Qa=h(),T=a("p"),Di=r(`Now it\u2019s time to finally start coding. Our suggested starting point is the PyTorch file itself: copy the contents of
`),Or=a("code"),Mi=r("modeling_brand_new_bert.py"),xi=r(" inside "),Ar=a("code"),Ri=r("src/transformers/models/brand_new_bert/"),Si=r(` into
`),Nr=a("code"),Ui=r("modeling_tf_brand_new_bert.py"),Hi=r(`. The goal of this section is to modify the file and update the import structure of
\u{1F917} Transformers such that you can import `),Dr=a("code"),Ji=r("TFBrandNewBert"),Gi=r(` and
`),Mr=a("code"),Zi=r("TFBrandNewBert.from_pretrained(model_repo, from_pt=True)"),Wi=r(" successfully loads a working TensorFlow "),xr=a("em"),Yi=r("BrandNewBert"),qi=r(" model."),Va=h(),yo=a("p"),ji=r(`Sadly, there is no prescription to convert a PyTorch model into TensorFlow. You can, however, follow our selection of
tips to make the process as smooth as possible:`),Ka=h(),u=a("ul"),oe=a("li"),Xi=r("Prepend "),Rr=a("code"),zi=r("TF"),Qi=r(" to the name of all classes (e.g. "),Sr=a("code"),Vi=r("BrandNewBert"),Ki=r(" becomes "),Ur=a("code"),ed=r("TFBrandNewBert"),td=r(")."),od=h(),L=a("li"),rd=r("Most PyTorch operations have a direct TensorFlow replacement. For example, "),Hr=a("code"),ld=r("torch.nn.Linear"),ad=r(` corresponds to
`),Jr=a("code"),sd=r("tf.keras.layers.Dense"),nd=r(", "),Gr=a("code"),id=r("torch.nn.Dropout"),dd=r(" corresponds to "),Zr=a("code"),hd=r("tf.keras.layers.Dropout"),cd=r(`, etc. If you\u2019re not sure
about a specific operation, you can use the `),Lt=a("a"),fd=r("TensorFlow documentation"),md=r(`
or the `),Ot=a("a"),ud=r("PyTorch documentation"),pd=r("."),wd=h(),Wr=a("li"),yd=r(`Look for patterns in the \u{1F917} Transformers codebase. If you come across a certain operation that doesn\u2019t have a direct
replacement, the odds are that someone else already had the same problem.`),vd=h(),Yr=a("li"),bd=r(`By default, keep the same variable names and structure as in PyTorch. This will make it easier to debug, track
issues, and add fixes down the line.`),gd=h(),Z=a("li"),_d=r(`Some layers have different default values in each framework. A notable example is the batch normalization layer\u2019s
epsilon (`),qr=a("code"),Ed=r("1e-5"),Td=r(" in "),At=a("a"),kd=r("PyTorch"),Fd=r(`
and `),jr=a("code"),$d=r("1e-3"),Pd=r(" in "),Nt=a("a"),Id=r("TensorFlow"),Bd=r(`).
Double-check the documentation!`),Cd=h(),X=a("li"),Ld=r("PyTorch\u2019s "),Xr=a("code"),Od=r("nn.Parameter"),Ad=r(" variables typically need to be initialized within TF Layer\u2019s "),zr=a("code"),Nd=r("build()"),Dd=r(`. See the following
example: `),Dt=a("a"),Md=r("PyTorch"),xd=r(` /
`),Mt=a("a"),Rd=r("TensorFlow"),Sd=h(),xt=a("li"),Ud=r("If the PyTorch model has a "),Qr=a("code"),Hd=r("#copied from ..."),Jd=r(` on top of a function, the odds are that your TensorFlow model can also
borrow that function from the architecture it was copied from, assuming it has a TensorFlow architecture.`),Gd=h(),W=a("li"),Zd=r("Assigning the "),Vr=a("code"),Wd=r("name"),Yd=r(" attribute correctly in TensorFlow functions is critical to do the "),Kr=a("code"),qd=r("from_pt=True"),jd=r(` weight
cross-loading. `),el=a("code"),Xd=r("name"),zd=r(" is almost always the name of the corresponding variable in the PyTorch code. If "),tl=a("code"),Qd=r("name"),Vd=r(` is not
properly set, you will see it in the error message when loading the model weights.`),Kd=h(),Y=a("li"),eh=r("The logic of the base model class, "),ol=a("code"),th=r("BrandNewBertModel"),oh=r(", will actually reside in "),rl=a("code"),rh=r("TFBrandNewBertMainLayer"),lh=r(`, a Keras
layer subclass (`),Rt=a("a"),ah=r("example"),sh=r(`).
`),ll=a("code"),nh=r("TFBrandNewBertModel"),ih=r(" will simply be a wrapper around this layer."),dh=h(),re=a("li"),hh=r("Keras models need to be built in order to load pretrained weights. For that reason, "),al=a("code"),ch=r("TFBrandNewBertPreTrainedModel"),fh=r(`
will need to hold an example of inputs to the model, the `),sl=a("code"),mh=r("dummy_inputs"),uh=r(`
(`),St=a("a"),ph=r("example"),wh=r(")."),yh=h(),nl=a("li"),vh=r("If you get stuck, ask for help - we\u2019re here to help you! \u{1F917}"),es=h(),Ye=a("p"),bh=r(`In addition to the model file itself, you will also need to add the pointers to the model classes and related
documentation pages. You can complete this part entirely following the patterns in other PRs
(`),Ut=a("a"),gh=r("example"),_h=r(`). Here\u2019s a list of the needed manual
changes:`),ts=h(),g=a("ul"),qe=a("li"),Eh=r("Include all public classes of "),il=a("em"),Th=r("BrandNewBert"),kh=r(" in "),dl=a("code"),Fh=r("src/transformers/__init__.py"),$h=h(),je=a("li"),Ph=r("Add "),hl=a("em"),Ih=r("BrandNewBert"),Bh=r(" classes to the corresponding Auto classes in "),cl=a("code"),Ch=r("src/transformers/models/auto/modeling_tf_auto.py"),Lh=h(),vo=a("li"),Oh=r("Include the modeling file in the documentation test file list in "),fl=a("code"),Ah=r("utils/documentation_tests.txt"),Nh=h(),Xe=a("li"),Dh=r("Add the lazy loading classes related to "),ml=a("em"),Mh=r("BrandNewBert"),xh=r(" in "),ul=a("code"),Rh=r("src/transformers/utils/dummy_tf_objects.py"),Sh=h(),bo=a("li"),Uh=r("Update the import structures for the public classes in "),pl=a("code"),Hh=r("src/transformers/models/brand_new_bert/__init__.py"),Jh=h(),ze=a("li"),Gh=r("Add the documentation pointers to the public methods of "),wl=a("em"),Zh=r("BrandNewBert"),Wh=r(" in "),yl=a("code"),Yh=r("docs/source/en/model_doc/brand_new_bert.md"),qh=h(),Qe=a("li"),jh=r("Add yourself to the list of contributors to "),vl=a("em"),Xh=r("BrandNewBert"),zh=r(" in "),bl=a("code"),Qh=r("docs/source/en/model_doc/brand_new_bert.md"),Vh=h(),Ve=a("li"),Kh=r("Finally, add a green tick \u2705 to the TensorFlow column of "),gl=a("em"),ec=r("BrandNewBert"),tc=r(" in "),_l=a("code"),oc=r("docs/source/en/index.md"),os=h(),go=a("p"),rc=r(`When you\u2019re happy with your implementation, run the following checklist to confirm that your model architecture is
ready:`),rs=h(),A=a("ol"),Ht=a("li"),lc=r("All layers that behave differently at train time (e.g. Dropout) are called with a "),El=a("code"),ac=r("training"),sc=r(` argument, which is
propagated all the way from the top-level classes`),nc=h(),Jt=a("li"),ic=r("You have used "),Tl=a("code"),dc=r("#copied from ..."),hc=r(" whenever possible"),cc=h(),ke=a("li"),kl=a("code"),fc=r("TFBrandNewBertMainLayer"),mc=r(" and all classes that use it have their "),Fl=a("code"),uc=r("call"),pc=r(" function decorated with "),$l=a("code"),wc=r("@unpack_inputs"),yc=h(),Gt=a("li"),Pl=a("code"),vc=r("TFBrandNewBertMainLayer"),bc=r(" is decorated with "),Il=a("code"),gc=r("@keras_serializable"),_c=h(),_o=a("li"),Ec=r("A TensorFlow model can be loaded from PyTorch weights using "),Bl=a("code"),Tc=r("TFBrandNewBert.from_pretrained(model_repo, from_pt=True)"),kc=h(),Cl=a("li"),Fc=r("You can call the TensorFlow model using the expected input format"),ls=h(),Fe=a("h3"),Ke=a("a"),Ll=a("span"),k(Zt.$$.fragment),$c=h(),Ol=a("span"),Pc=r("5. Add model tests"),as=h(),N=a("p"),Ic=r(`Hurray, you\u2019ve implemented a TensorFlow model! Now it\u2019s time to add tests to make sure that your model behaves as
expected. As in the previous section, we suggest you start by copying the `),Al=a("code"),Bc=r("test_modeling_brand_new_bert.py"),Cc=r(` file in
`),Nl=a("code"),Lc=r("tests/models/brand_new_bert/"),Oc=r(" into "),Dl=a("code"),Ac=r("test_modeling_tf_brand_new_bert.py"),Nc=r(`, and continue by making the necessary
TensorFlow replacements. For now, in all `),Ml=a("code"),Dc=r(".from_pretrained()"),Mc=r(" calls, you should use the "),xl=a("code"),xc=r("from_pt=True"),Rc=r(` flag to load
the existing PyTorch weights.`),ss=h(),Eo=a("p"),Sc=r("After you\u2019re done, it\u2019s time for the moment of truth: run the tests! \u{1F62C}"),ns=h(),k(Wt.$$.fragment),is=h(),et=a("p"),Uc=r(`The most likely outcome is that you\u2019ll see a bunch of errors. Don\u2019t worry, this is expected! Debugging ML models is
notoriously hard, and the key ingredient to success is patience (and `),Rl=a("code"),Hc=r("breakpoint()"),Jc=r(`). In our experience, the hardest
problems arise from subtle mismatches between ML frameworks, for which we have a few pointers at the end of this guide.
In other cases, a general test might not be directly applicable to your model, in which case we suggest an override
at the model test class level. Regardless of the issue, don\u2019t hesitate to ask for help in your draft pull request if
you\u2019re stuck.`),ds=h(),To=a("p"),Gc=r("When all tests pass, congratulations, your model is nearly ready to be added to the \u{1F917} Transformers library! \u{1F389}"),hs=h(),$e=a("h3"),tt=a("a"),Sl=a("span"),k(Yt.$$.fragment),Zc=h(),Ul=a("span"),Wc=r("6.-7. Ensure everyone can use your model"),cs=h(),ko=a("p"),Hl=a("strong"),Yc=r("6. Submit the pull request"),fs=h(),ot=a("p"),qc=r(`Once you\u2019re done with the implementation and the tests, it\u2019s time to submit a pull request. Before pushing your code,
run our code formatting utility, `),Jl=a("code"),jc=r("make fixup"),Xc=r(` \u{1FA84}. This will automatically fix any formatting issues, which would cause
our automatic checks to fail.`),ms=h(),he=a("p"),zc=r(`It\u2019s now time to convert your draft pull request into a real pull request. To do so, click on the \u201CReady for
review\u201D button and add Joao (`),Gl=a("code"),Qc=r("@gante"),Vc=r(") and Matt ("),Zl=a("code"),Kc=r("@Rocketknight1"),ef=r(`) as reviewers. A model pull request will need
at least 3 reviewers, but they will take care of finding appropriate additional reviewers for your model.`),us=h(),ce=a("p"),tf=r("After all reviewers are happy with the state of your PR, the final action point is to remove the "),Wl=a("code"),of=r("from_pt=True"),rf=r(` flag in
`),Yl=a("code"),lf=r(".from_pretrained()"),af=r(` calls. Since there are no TensorFlow weights, you will have to add them! Check the section
below for instructions on how to do it.`),ps=h(),Fo=a("p"),sf=r(`Finally, when the TensorFlow weights get merged, you have at least 3 reviewer approvals, and all CI checks are
green, double-check the tests locally one last time`),ws=h(),k(qt.$$.fragment),ys=h(),$o=a("p"),nf=r("and we will merge your PR! Congratulations on the milestone \u{1F389}"),vs=h(),Po=a("p"),ql=a("strong"),df=r("7. (Optional) Build demos and share with the world"),bs=h(),Io=a("p"),hf=r(`One of the hardest parts about open-source is discovery. How can the other users learn about the existence of your
fabulous TensorFlow contribution? With proper communication, of course! \u{1F4E3}`),gs=h(),Bo=a("p"),cf=r("There are two main ways to share your model with the community:"),_s=h(),rt=a("ul"),jt=a("li"),ff=r(`Build demos. These include Gradio demos, notebooks, and other fun ways to show off your model. We highly
encourage you to add a notebook to our `),Xt=a("a"),mf=r("community-driven demos"),uf=r("."),pf=h(),jl=a("li"),wf=r(`Share stories on social media like Twitter and LinkedIn. You should be proud of your work and share
your achievement with the community - your model can now be used by thousands of engineers and researchers around
the world \u{1F30D}! We will be happy to retweet your posts and help you share your work with the community.`),Es=h(),Pe=a("h2"),lt=a("a"),Xl=a("span"),k(zt.$$.fragment),yf=h(),zl=a("span"),vf=r("Adding TensorFlow weights to \u{1F917} Hub"),Ts=h(),Co=a("p"),bf=r(`Assuming that the TensorFlow model architecture is available in \u{1F917} Transformers, converting PyTorch weights into
TensorFlow weights is a breeze!`),ks=h(),Lo=a("p"),gf=r("Here\u2019s how to do it:"),Fs=h(),fe=a("ol"),Ie=a("li"),_f=r(`Make sure you are logged into your Hugging Face account in your terminal. You can log in using the command
`),Ql=a("code"),Ef=r("huggingface-cli login"),Tf=r(" (you can find your access tokens "),Qt=a("a"),kf=r("here"),Ff=r(")"),$f=h(),Be=a("li"),Pf=r("Run "),Vl=a("code"),If=r("transformers-cli pt-to-tf --model-name foo/bar"),Bf=r(", where "),Kl=a("code"),Cf=r("foo/bar"),Lf=r(` is the name of the model repository
containing the PyTorch weights you want to convert`),Of=h(),Ce=a("li"),Af=r("Tag "),ea=a("code"),Nf=r("@joaogante"),Df=r(" and "),ta=a("code"),Mf=r("@Rocketknight1"),xf=r(" in the \u{1F917} Hub PR the command above has just created"),$s=h(),Oo=a("p"),Rf=r("That\u2019s it! \u{1F389}"),Ps=h(),Le=a("h2"),at=a("a"),oa=a("span"),k(Vt.$$.fragment),Sf=h(),ra=a("span"),Uf=r("Debugging mismatches across ML frameworks \u{1F41B}"),Is=h(),Ao=a("p"),Hf=r(`At some point, when adding a new architecture or when creating TensorFlow weights for an existing architecture, you
might come across errors complaining about mismatches between PyTorch and TensorFlow. You might even decide to open the
model architecture code for the two frameworks, and find that they look identical. What\u2019s going on? \u{1F914}`),Bs=h(),st=a("p"),Jf=r(`First of all, let\u2019s talk about why understanding these mismatches matters. Many community members will use \u{1F917}
Transformers models out of the box, and trust that our models behave as expected. When there is a large mismatch
between the two frameworks, it implies that the model is not following the reference implementation for at least one
of the frameworks. This might lead to silent failures, in which the model runs but has poor performance. This is
arguably worse than a model that fails to run at all! To that end, we aim at having a framework mismatch smaller than
`),la=a("code"),Gf=r("1e-5"),Zf=r(" at all stages of the model."),Cs=h(),No=a("p"),Wf=r(`As in other numerical problems, the devil is in the details. And as in any detail-oriented craft, the secret
ingredient here is patience. Here is our suggested workflow for when you come across this type of issues:`),Ls=h(),me=a("ol"),Kt=a("li"),Yf=r(`Locate the source of mismatches. The model you\u2019re converting probably has near identical inner variables up to a
certain point. Place `),aa=a("code"),qf=r("breakpoint()"),jf=r(` statements in the two frameworks\u2019 architectures, and compare the values of the
numerical variables in a top-down fashion until you find the source of the problems.`),Xf=h(),sa=a("li"),zf=r(`Now that you\u2019ve pinpointed the source of the issue, get in touch with the \u{1F917} Transformers team. It is possible
that we\u2019ve seen a similar problem before and can promptly provide a solution. As a fallback, scan popular pages
like StackOverflow and GitHub issues.`),Qf=h(),na=a("li"),Vf=r(`If there is no solution in sight, it means you\u2019ll have to go deeper. The good news is that you\u2019ve located the
issue, so you can focus on the problematic instruction, abstracting away the rest of the model! The bad news is
that you\u2019ll have to venture into the source implementation of said instruction. In some cases, you might find an
issue with a reference implementation - don\u2019t abstain from opening an issue in the upstream repository.`),Os=h(),ue=a("p"),Kf=r(`In some cases, in discussion with the \u{1F917} Transformers team, we might find that fixing the mismatch is infeasible.
When the mismatch is very small in the output layers of the model (but potentially large in the hidden states), we
might decide to ignore it in favor of distributing the model. The `),ia=a("code"),em=r("pt-to-tf"),tm=r(" CLI mentioned above has a "),da=a("code"),om=r("--max-error"),rm=r(`
flag to override the error message at weight conversion time.`),this.h()},l(t){const i=Nw('[data-svelte="svelte-1phssyn"]',document.head);m=s(i,"META",{name:!0,content:!0}),i.forEach(o),q=c(t),v=s(t,"H1",{class:!0});var eo=n(v);_=s(eo,"A",{id:!0,class:!0,href:!0});var ha=n(_);H=s(ha,"SPAN",{});var im=n(H);F(b.$$.fragment,im),im.forEach(o),ha.forEach(o),p=c(eo),J=s(eo,"SPAN",{});var dm=n(J);M=l(dm,"How to convert a \u{1F917} Transformers model to TensorFlow?"),dm.forEach(o),eo.forEach(o),C=c(t),x=s(t,"P",{});var Ns=n(x);j=l(Ns,`Having multiple frameworks available to use with \u{1F917} Transformers gives you flexibility to play their strengths when
designing your application, but it implies that compatibility must be added on a per-model basis. The good news is that
adding TensorFlow compatibility to an existing model is simpler than `),le=s(Ns,"A",{href:!0});var hm=n(le);ft=l(hm,"adding a new model from scratch"),hm.forEach(o),V=l(Ns,`!
Whether you wish to have a deeper understanding of large TensorFlow models, make a major open-source contribution, or
enable TensorFlow for your model of choice, this guide is for you.`),Ns.forEach(o),Ae=c(t),ae=s(t,"P",{});var cm=n(ae);K=l(cm,`This guide empowers you, a member of our community, to contribute TensorFlow model weights and/or
architectures to be used in \u{1F917} Transformers, with minimal supervision from the Hugging Face team. Writing a new model
is no small feat, but hopefully this guide will make it less of a rollercoaster \u{1F3A2} and more of a walk in the park \u{1F6B6}.
Harnessing our collective experiences is absolutely critical to make this process increasingly easier, and thus we
highly encourage that you suggest improvements to this guide!`),cm.forEach(o),Ne=c(t),se=s(t,"P",{});var fm=n(se);y=l(fm,"Before you dive deeper, it is recommended that you check the following resources if you\u2019re new to \u{1F917} Transformers:"),fm.forEach(o),G=c(t),ee=s(t,"UL",{});var Ds=n(ee);O=s(Ds,"LI",{});var mm=n(O);ve=s(mm,"A",{href:!0});var um=n(ve);oo=l(um,"General overview of \u{1F917} Transformers"),um.forEach(o),mm.forEach(o),ro=c(Ds),De=s(Ds,"LI",{});var pm=n(De);mt=s(pm,"A",{href:!0,rel:!0});var wm=n(mt);hn=l(wm,"Hugging Face\u2019s TensorFlow Philosophy"),wm.forEach(o),pm.forEach(o),Ds.forEach(o),ya=c(t),lo=s(t,"P",{});var ym=n(lo);cn=l(ym,`In the remainder of this guide, you will learn what\u2019s needed to add a new TensorFlow model architecture, the
procedure to convert PyTorch into TensorFlow model weights, and how to efficiently debug mismatches across ML
frameworks. Let\u2019s get started!`),ym.forEach(o),va=c(t),F(Me.$$.fragment,t),ba=c(t),be=s(t,"H2",{class:!0});var Ms=n(be);xe=s(Ms,"A",{id:!0,class:!0,href:!0});var vm=n(xe);qo=s(vm,"SPAN",{});var bm=n(qo);F(ut.$$.fragment,bm),bm.forEach(o),vm.forEach(o),fn=c(Ms),jo=s(Ms,"SPAN",{});var gm=n(jo);mn=l(gm,"Step-by-step guide to add TensorFlow model architecture code"),gm.forEach(o),Ms.forEach(o),ga=c(t),Re=s(t,"P",{});var xs=n(Re);un=l(xs,`There are many ways to design a large model architecture, and multiple ways of implementing said design. However,
you might recall from our `),ao=s(xs,"A",{href:!0});var _m=n(ao);pn=l(_m,"general overview of \u{1F917} Transformers"),_m.forEach(o),wn=l(xs,`
that we are an opinionated bunch - the ease of use of \u{1F917} Transformers relies on consistent design choices. From
experience, we can tell you a few important things about adding TensorFlow models:`),xs.forEach(o),_a=c(t),ne=s(t,"UL",{});var Do=n(ne);Xo=s(Do,"LI",{});var Em=n(Xo);yn=l(Em,`Don\u2019t reinvent the wheel! More often than not, there are at least two reference implementations you should check: the
PyTorch equivalent of the model you are implementing and other TensorFlow models for the same class of problems.`),Em.forEach(o),vn=c(Do),zo=s(Do,"LI",{});var Tm=n(zo);bn=l(Tm,`Great model implementations survive the test of time. This doesn\u2019t happen because the code is pretty, but rather
because the code is clear, easy to debug and build upon. If you make the life of the maintainers easy with your
TensorFlow implementation, by replicating the same patterns as in other TensorFlow models and minimizing the mismatch
to the PyTorch implementation, you ensure your contribution will be long lived.`),Tm.forEach(o),gn=c(Do),Qo=s(Do,"LI",{});var km=n(Qo);_n=l(km,`Ask for help when you\u2019re stuck! The \u{1F917} Transformers team is here to help, and we\u2019ve probably found solutions to the same
problems you\u2019re facing.`),km.forEach(o),Do.forEach(o),Ea=c(t),so=s(t,"P",{});var Fm=n(so);En=l(Fm,"Here\u2019s an overview of the steps needed to add a TensorFlow model architecture:"),Fm.forEach(o),Ta=c(t),E=s(t,"OL",{});var R=n(E);Vo=s(R,"LI",{});var $m=n(Vo);Tn=l($m,"Select the model you wish to convert"),$m.forEach(o),kn=c(R),Ko=s(R,"LI",{});var Pm=n(Ko);Fn=l(Pm,"Prepare transformers dev environment"),Pm.forEach(o),$n=c(R),er=s(R,"LI",{});var Im=n(er);Pn=l(Im,"(Optional) Understand theoretical aspects and the existing implementation"),Im.forEach(o),In=c(R),tr=s(R,"LI",{});var Bm=n(tr);Bn=l(Bm,"Implement the model architecture"),Bm.forEach(o),Cn=c(R),or=s(R,"LI",{});var Cm=n(or);Ln=l(Cm,"Implement model tests"),Cm.forEach(o),On=c(R),rr=s(R,"LI",{});var Lm=n(rr);An=l(Lm,"Submit the pull request"),Lm.forEach(o),Nn=c(R),lr=s(R,"LI",{});var Om=n(lr);Dn=l(Om,"(Optional) Build demos and share with the world"),Om.forEach(o),R.forEach(o),ka=c(t),ge=s(t,"H3",{class:!0});var Rs=n(ge);Se=s(Rs,"A",{id:!0,class:!0,href:!0});var Am=n(Se);ar=s(Am,"SPAN",{});var Nm=n(ar);F(pt.$$.fragment,Nm),Nm.forEach(o),Am.forEach(o),Mn=c(Rs),sr=s(Rs,"SPAN",{});var Dm=n(sr);xn=l(Dm,"1.-3. Prepare your model contribution"),Dm.forEach(o),Rs.forEach(o),Fa=c(t),no=s(t,"P",{});var Mm=n(no);nr=s(Mm,"STRONG",{});var xm=n(nr);Rn=l(xm,"1. Select the model you wish to convert"),xm.forEach(o),Mm.forEach(o),$a=c(t),Ue=s(t,"P",{});var Ss=n(Ue);Sn=l(Ss,`Let\u2019s start off with the basics: the first thing you need to know is the architecture you want to convert. If you
don\u2019t have your eyes set on a specific architecture, asking the \u{1F917} Transformers team for suggestions is a great way to
maximize your impact - we will guide you towards the most prominent architectures that are missing on the TensorFlow
side. If the specific model you want to use with TensorFlow already has a TensorFlow architecture implementation in
\u{1F917} Transformers but is lacking weights, feel free to jump straight into the
`),io=s(Ss,"A",{href:!0});var Rm=n(io);Un=l(Rm,"weight conversion section"),Rm.forEach(o),Hn=l(Ss,`
of this page.`),Ss.forEach(o),Pa=c(t),ie=s(t,"P",{});var Mo=n(ie);Jn=l(Mo,`For simplicity, the remainder of this guide assumes you\u2019ve decided to contribute with the TensorFlow version of
`),ir=s(Mo,"EM",{});var Sm=n(ir);Gn=l(Sm,"BrandNewBert"),Sm.forEach(o),Zn=l(Mo," (the same example as in the "),ho=s(Mo,"A",{href:!0});var Um=n(ho);Wn=l(Um,"guide"),Um.forEach(o),Yn=l(Mo," to add a new model from scratch)."),Mo.forEach(o),Ia=c(t),F(He.$$.fragment,t),Ba=c(t),co=s(t,"P",{});var Hm=n(co);dr=s(Hm,"STRONG",{});var Jm=n(dr);qn=l(Jm,"2. Prepare transformers dev environment"),Jm.forEach(o),Hm.forEach(o),Ca=c(t),fo=s(t,"P",{});var Gm=n(fo);jn=l(Gm,`Having selected the model architecture, open a draft PR to signal your intention to work on it. Follow the
instructions below to set up your environment and open a draft PR.`),Gm.forEach(o),La=c(t),Je=s(t,"OL",{});var Us=n(Je);hr=s(Us,"LI",{});var Zm=n(hr);wt=s(Zm,"P",{});var Hs=n(wt);Xn=l(Hs,"Fork the "),yt=s(Hs,"A",{href:!0,rel:!0});var Wm=n(yt);zn=l(Wm,"repository"),Wm.forEach(o),Qn=l(Hs,` by clicking on the \u2018Fork\u2019 button on the
repository\u2019s page. This creates a copy of the code under your GitHub user account.`),Hs.forEach(o),Zm.forEach(o),Vn=c(Us),cr=s(Us,"LI",{});var Ym=n(cr);vt=s(Ym,"P",{});var Js=n(vt);Kn=l(Js,"Clone your "),fr=s(Js,"CODE",{});var qm=n(fr);ei=l(qm,"transformers"),qm.forEach(o),ti=l(Js," fork to your local disk, and add the base repository as a remote:"),Js.forEach(o),Ym.forEach(o),Us.forEach(o),Oa=c(t),F(bt.$$.fragment,t),Aa=c(t),gt=s(t,"OL",{start:!0});var jm=n(gt);mr=s(jm,"LI",{});var Xm=n(mr);oi=l(Xm,"Set up a development environment, for instance by running the following command:"),Xm.forEach(o),jm.forEach(o),Na=c(t),F(_t.$$.fragment,t),Da=c(t),mo=s(t,"P",{});var zm=n(mo);ri=l(zm,`Depending on your OS, and since the number of optional dependencies of Transformers is growing, you might get a
failure with this command. If that\u2019s the case make sure to install TensorFlow then do:`),zm.forEach(o),Ma=c(t),F(Et.$$.fragment,t),xa=c(t),Tt=s(t,"P",{});var lm=n(Tt);ur=s(lm,"STRONG",{});var Qm=n(ur);li=l(Qm,"Note:"),Qm.forEach(o),ai=l(lm," You don\u2019t need to have CUDA installed. Making the new model work on CPU is sufficient."),lm.forEach(o),Ra=c(t),kt=s(t,"OL",{start:!0});var Vm=n(kt);pr=s(Vm,"LI",{});var Km=n(pr);si=l(Km,"Create a branch with a descriptive name from your main branch"),Km.forEach(o),Vm.forEach(o),Sa=c(t),F(Ft.$$.fragment,t),Ua=c(t),$t=s(t,"OL",{start:!0});var eu=n($t);wr=s(eu,"LI",{});var tu=n(wr);ni=l(tu,"Fetch and rebase to current main"),tu.forEach(o),eu.forEach(o),Ha=c(t),F(Pt.$$.fragment,t),Ja=c(t),_e=s(t,"OL",{start:!0});var Gs=n(_e);yr=s(Gs,"LI",{});var ou=n(yr);te=s(ou,"P",{});var nt=n(te);ii=l(nt,"Add an empty "),vr=s(nt,"CODE",{});var ru=n(vr);di=l(ru,".py"),ru.forEach(o),hi=l(nt," file in "),br=s(nt,"CODE",{});var lu=n(br);ci=l(lu,"transformers/src/models/brandnewbert/"),lu.forEach(o),fi=l(nt," named "),gr=s(nt,"CODE",{});var au=n(gr);mi=l(au,"modeling_tf_brandnewbert.py"),au.forEach(o),ui=l(nt,`. This will
be your TensorFlow model file.`),nt.forEach(o),ou.forEach(o),pi=c(Gs),_r=s(Gs,"LI",{});var su=n(_r);Er=s(su,"P",{});var nu=n(Er);wi=l(nu,"Push the changes to your account using:"),nu.forEach(o),su.forEach(o),Gs.forEach(o),Ga=c(t),F(It.$$.fragment,t),Za=c(t),Ee=s(t,"OL",{start:!0});var Zs=n(Ee);Tr=s(Zs,"LI",{});var iu=n(Tr);kr=s(iu,"P",{});var du=n(kr);yi=l(du,`Once you are satisfied, go to the webpage of your fork on GitHub. Click on \u201CPull request\u201D. Make sure to add the
GitHub handle of some members of the Hugging Face team as reviewers, so that the Hugging Face team gets notified for
future changes.`),du.forEach(o),iu.forEach(o),vi=c(Zs),Fr=s(Zs,"LI",{});var hu=n(Fr);$r=s(hu,"P",{});var cu=n($r);bi=l(cu,"Change the PR into a draft by clicking on \u201CConvert to draft\u201D on the right of the GitHub pull request web page."),cu.forEach(o),hu.forEach(o),Zs.forEach(o),Wa=c(t),Ge=s(t,"P",{});var Ws=n(Ge);gi=l(Ws,"Now you have set up a development environment to port "),Pr=s(Ws,"EM",{});var fu=n(Pr);_i=l(fu,"BrandNewBert"),fu.forEach(o),Ei=l(Ws," to TensorFlow in \u{1F917} Transformers."),Ws.forEach(o),Ya=c(t),uo=s(t,"P",{});var mu=n(uo);Ir=s(mu,"STRONG",{});var uu=n(Ir);Ti=l(uu,"3. (Optional) Understand theoretical aspects and the existing implementation"),uu.forEach(o),mu.forEach(o),qa=c(t),de=s(t,"P",{});var xo=n(de);ki=l(xo,"You should take some time to read "),Br=s(xo,"EM",{});var pu=n(Br);Fi=l(pu,"BrandNewBert\u2019s"),pu.forEach(o),$i=l(xo,` paper, if such descriptive work exists. There might be large
sections of the paper that are difficult to understand. If this is the case, this is fine - don\u2019t worry! The goal is
not to get a deep theoretical understanding of the paper, but to extract the necessary information required to
effectively re-implement the model in \u{1F917} Transformers using TensorFlow. That being said, you don\u2019t have to spend too
much time on the theoretical aspects, but rather focus on the practical ones, namely the existing model documentation
page (e.g. `),po=s(xo,"A",{href:!0});var wu=n(po);Pi=l(wu,"model docs for BERT"),wu.forEach(o),Ii=l(xo,")."),xo.forEach(o),ja=c(t),wo=s(t,"P",{});var yu=n(wo);Bi=l(yu,`After you\u2019ve grasped the basics of the models you are about to implement, it\u2019s important to understand the existing
implementation. This is a great chance to confirm that a working implementation matches your expectations for the
model, as well as to foresee technical challenges on the TensorFlow side.`),yu.forEach(o),Xa=c(t),Ze=s(t,"P",{});var Ys=n(Ze);Ci=l(Ys,`It\u2019s perfectly natural that you feel overwhelmed with the amount of information that you\u2019ve just absorbed. It is
definitely not a requirement that you understand all facets of the model at this stage. Nevertheless, we highly
encourage you to clear any pressing questions in our `),Bt=s(Ys,"A",{href:!0,rel:!0});var vu=n(Bt);Li=l(vu,"forum"),vu.forEach(o),Oi=l(Ys,"."),Ys.forEach(o),za=c(t),Te=s(t,"H3",{class:!0});var qs=n(Te);We=s(qs,"A",{id:!0,class:!0,href:!0});var bu=n(We);Cr=s(bu,"SPAN",{});var gu=n(Cr);F(Ct.$$.fragment,gu),gu.forEach(o),bu.forEach(o),Ai=c(qs),Lr=s(qs,"SPAN",{});var _u=n(Lr);Ni=l(_u,"4. Model implementation"),_u.forEach(o),qs.forEach(o),Qa=c(t),T=s(t,"P",{});var S=n(T);Di=l(S,`Now it\u2019s time to finally start coding. Our suggested starting point is the PyTorch file itself: copy the contents of
`),Or=s(S,"CODE",{});var Eu=n(Or);Mi=l(Eu,"modeling_brand_new_bert.py"),Eu.forEach(o),xi=l(S," inside "),Ar=s(S,"CODE",{});var Tu=n(Ar);Ri=l(Tu,"src/transformers/models/brand_new_bert/"),Tu.forEach(o),Si=l(S,` into
`),Nr=s(S,"CODE",{});var ku=n(Nr);Ui=l(ku,"modeling_tf_brand_new_bert.py"),ku.forEach(o),Hi=l(S,`. The goal of this section is to modify the file and update the import structure of
\u{1F917} Transformers such that you can import `),Dr=s(S,"CODE",{});var Fu=n(Dr);Ji=l(Fu,"TFBrandNewBert"),Fu.forEach(o),Gi=l(S,` and
`),Mr=s(S,"CODE",{});var $u=n(Mr);Zi=l($u,"TFBrandNewBert.from_pretrained(model_repo, from_pt=True)"),$u.forEach(o),Wi=l(S," successfully loads a working TensorFlow "),xr=s(S,"EM",{});var Pu=n(xr);Yi=l(Pu,"BrandNewBert"),Pu.forEach(o),qi=l(S," model."),S.forEach(o),Va=c(t),yo=s(t,"P",{});var Iu=n(yo);ji=l(Iu,`Sadly, there is no prescription to convert a PyTorch model into TensorFlow. You can, however, follow our selection of
tips to make the process as smooth as possible:`),Iu.forEach(o),Ka=c(t),u=s(t,"UL",{});var w=n(u);oe=s(w,"LI",{});var it=n(oe);Xi=l(it,"Prepend "),Rr=s(it,"CODE",{});var Bu=n(Rr);zi=l(Bu,"TF"),Bu.forEach(o),Qi=l(it," to the name of all classes (e.g. "),Sr=s(it,"CODE",{});var Cu=n(Sr);Vi=l(Cu,"BrandNewBert"),Cu.forEach(o),Ki=l(it," becomes "),Ur=s(it,"CODE",{});var Lu=n(Ur);ed=l(Lu,"TFBrandNewBert"),Lu.forEach(o),td=l(it,")."),it.forEach(o),od=c(w),L=s(w,"LI",{});var U=n(L);rd=l(U,"Most PyTorch operations have a direct TensorFlow replacement. For example, "),Hr=s(U,"CODE",{});var Ou=n(Hr);ld=l(Ou,"torch.nn.Linear"),Ou.forEach(o),ad=l(U,` corresponds to
`),Jr=s(U,"CODE",{});var Au=n(Jr);sd=l(Au,"tf.keras.layers.Dense"),Au.forEach(o),nd=l(U,", "),Gr=s(U,"CODE",{});var Nu=n(Gr);id=l(Nu,"torch.nn.Dropout"),Nu.forEach(o),dd=l(U," corresponds to "),Zr=s(U,"CODE",{});var Du=n(Zr);hd=l(Du,"tf.keras.layers.Dropout"),Du.forEach(o),cd=l(U,`, etc. If you\u2019re not sure
about a specific operation, you can use the `),Lt=s(U,"A",{href:!0,rel:!0});var Mu=n(Lt);fd=l(Mu,"TensorFlow documentation"),Mu.forEach(o),md=l(U,`
or the `),Ot=s(U,"A",{href:!0,rel:!0});var xu=n(Ot);ud=l(xu,"PyTorch documentation"),xu.forEach(o),pd=l(U,"."),U.forEach(o),wd=c(w),Wr=s(w,"LI",{});var Ru=n(Wr);yd=l(Ru,`Look for patterns in the \u{1F917} Transformers codebase. If you come across a certain operation that doesn\u2019t have a direct
replacement, the odds are that someone else already had the same problem.`),Ru.forEach(o),vd=c(w),Yr=s(w,"LI",{});var Su=n(Yr);bd=l(Su,`By default, keep the same variable names and structure as in PyTorch. This will make it easier to debug, track
issues, and add fixes down the line.`),Su.forEach(o),gd=c(w),Z=s(w,"LI",{});var pe=n(Z);_d=l(pe,`Some layers have different default values in each framework. A notable example is the batch normalization layer\u2019s
epsilon (`),qr=s(pe,"CODE",{});var Uu=n(qr);Ed=l(Uu,"1e-5"),Uu.forEach(o),Td=l(pe," in "),At=s(pe,"A",{href:!0,rel:!0});var Hu=n(At);kd=l(Hu,"PyTorch"),Hu.forEach(o),Fd=l(pe,`
and `),jr=s(pe,"CODE",{});var Ju=n(jr);$d=l(Ju,"1e-3"),Ju.forEach(o),Pd=l(pe," in "),Nt=s(pe,"A",{href:!0,rel:!0});var Gu=n(Nt);Id=l(Gu,"TensorFlow"),Gu.forEach(o),Bd=l(pe,`).
Double-check the documentation!`),pe.forEach(o),Cd=c(w),X=s(w,"LI",{});var Oe=n(X);Ld=l(Oe,"PyTorch\u2019s "),Xr=s(Oe,"CODE",{});var Zu=n(Xr);Od=l(Zu,"nn.Parameter"),Zu.forEach(o),Ad=l(Oe," variables typically need to be initialized within TF Layer\u2019s "),zr=s(Oe,"CODE",{});var Wu=n(zr);Nd=l(Wu,"build()"),Wu.forEach(o),Dd=l(Oe,`. See the following
example: `),Dt=s(Oe,"A",{href:!0,rel:!0});var Yu=n(Dt);Md=l(Yu,"PyTorch"),Yu.forEach(o),xd=l(Oe,` /
`),Mt=s(Oe,"A",{href:!0,rel:!0});var qu=n(Mt);Rd=l(qu,"TensorFlow"),qu.forEach(o),Oe.forEach(o),Sd=c(w),xt=s(w,"LI",{});var js=n(xt);Ud=l(js,"If the PyTorch model has a "),Qr=s(js,"CODE",{});var ju=n(Qr);Hd=l(ju,"#copied from ..."),ju.forEach(o),Jd=l(js,` on top of a function, the odds are that your TensorFlow model can also
borrow that function from the architecture it was copied from, assuming it has a TensorFlow architecture.`),js.forEach(o),Gd=c(w),W=s(w,"LI",{});var we=n(W);Zd=l(we,"Assigning the "),Vr=s(we,"CODE",{});var Xu=n(Vr);Wd=l(Xu,"name"),Xu.forEach(o),Yd=l(we," attribute correctly in TensorFlow functions is critical to do the "),Kr=s(we,"CODE",{});var zu=n(Kr);qd=l(zu,"from_pt=True"),zu.forEach(o),jd=l(we,` weight
cross-loading. `),el=s(we,"CODE",{});var Qu=n(el);Xd=l(Qu,"name"),Qu.forEach(o),zd=l(we," is almost always the name of the corresponding variable in the PyTorch code. If "),tl=s(we,"CODE",{});var Vu=n(tl);Qd=l(Vu,"name"),Vu.forEach(o),Vd=l(we,` is not
properly set, you will see it in the error message when loading the model weights.`),we.forEach(o),Kd=c(w),Y=s(w,"LI",{});var ye=n(Y);eh=l(ye,"The logic of the base model class, "),ol=s(ye,"CODE",{});var Ku=n(ol);th=l(Ku,"BrandNewBertModel"),Ku.forEach(o),oh=l(ye,", will actually reside in "),rl=s(ye,"CODE",{});var ep=n(rl);rh=l(ep,"TFBrandNewBertMainLayer"),ep.forEach(o),lh=l(ye,`, a Keras
layer subclass (`),Rt=s(ye,"A",{href:!0,rel:!0});var tp=n(Rt);ah=l(tp,"example"),tp.forEach(o),sh=l(ye,`).
`),ll=s(ye,"CODE",{});var op=n(ll);nh=l(op,"TFBrandNewBertModel"),op.forEach(o),ih=l(ye," will simply be a wrapper around this layer."),ye.forEach(o),dh=c(w),re=s(w,"LI",{});var dt=n(re);hh=l(dt,"Keras models need to be built in order to load pretrained weights. For that reason, "),al=s(dt,"CODE",{});var rp=n(al);ch=l(rp,"TFBrandNewBertPreTrainedModel"),rp.forEach(o),fh=l(dt,`
will need to hold an example of inputs to the model, the `),sl=s(dt,"CODE",{});var lp=n(sl);mh=l(lp,"dummy_inputs"),lp.forEach(o),uh=l(dt,`
(`),St=s(dt,"A",{href:!0,rel:!0});var ap=n(St);ph=l(ap,"example"),ap.forEach(o),wh=l(dt,")."),dt.forEach(o),yh=c(w),nl=s(w,"LI",{});var sp=n(nl);vh=l(sp,"If you get stuck, ask for help - we\u2019re here to help you! \u{1F917}"),sp.forEach(o),w.forEach(o),es=c(t),Ye=s(t,"P",{});var Xs=n(Ye);bh=l(Xs,`In addition to the model file itself, you will also need to add the pointers to the model classes and related
documentation pages. You can complete this part entirely following the patterns in other PRs
(`),Ut=s(Xs,"A",{href:!0,rel:!0});var np=n(Ut);gh=l(np,"example"),np.forEach(o),_h=l(Xs,`). Here\u2019s a list of the needed manual
changes:`),Xs.forEach(o),ts=c(t),g=s(t,"UL",{});var D=n(g);qe=s(D,"LI",{});var ca=n(qe);Eh=l(ca,"Include all public classes of "),il=s(ca,"EM",{});var ip=n(il);Th=l(ip,"BrandNewBert"),ip.forEach(o),kh=l(ca," in "),dl=s(ca,"CODE",{});var dp=n(dl);Fh=l(dp,"src/transformers/__init__.py"),dp.forEach(o),ca.forEach(o),$h=c(D),je=s(D,"LI",{});var fa=n(je);Ph=l(fa,"Add "),hl=s(fa,"EM",{});var hp=n(hl);Ih=l(hp,"BrandNewBert"),hp.forEach(o),Bh=l(fa," classes to the corresponding Auto classes in "),cl=s(fa,"CODE",{});var cp=n(cl);Ch=l(cp,"src/transformers/models/auto/modeling_tf_auto.py"),cp.forEach(o),fa.forEach(o),Lh=c(D),vo=s(D,"LI",{});var am=n(vo);Oh=l(am,"Include the modeling file in the documentation test file list in "),fl=s(am,"CODE",{});var fp=n(fl);Ah=l(fp,"utils/documentation_tests.txt"),fp.forEach(o),am.forEach(o),Nh=c(D),Xe=s(D,"LI",{});var ma=n(Xe);Dh=l(ma,"Add the lazy loading classes related to "),ml=s(ma,"EM",{});var mp=n(ml);Mh=l(mp,"BrandNewBert"),mp.forEach(o),xh=l(ma," in "),ul=s(ma,"CODE",{});var up=n(ul);Rh=l(up,"src/transformers/utils/dummy_tf_objects.py"),up.forEach(o),ma.forEach(o),Sh=c(D),bo=s(D,"LI",{});var sm=n(bo);Uh=l(sm,"Update the import structures for the public classes in "),pl=s(sm,"CODE",{});var pp=n(pl);Hh=l(pp,"src/transformers/models/brand_new_bert/__init__.py"),pp.forEach(o),sm.forEach(o),Jh=c(D),ze=s(D,"LI",{});var ua=n(ze);Gh=l(ua,"Add the documentation pointers to the public methods of "),wl=s(ua,"EM",{});var wp=n(wl);Zh=l(wp,"BrandNewBert"),wp.forEach(o),Wh=l(ua," in "),yl=s(ua,"CODE",{});var yp=n(yl);Yh=l(yp,"docs/source/en/model_doc/brand_new_bert.md"),yp.forEach(o),ua.forEach(o),qh=c(D),Qe=s(D,"LI",{});var pa=n(Qe);jh=l(pa,"Add yourself to the list of contributors to "),vl=s(pa,"EM",{});var vp=n(vl);Xh=l(vp,"BrandNewBert"),vp.forEach(o),zh=l(pa," in "),bl=s(pa,"CODE",{});var bp=n(bl);Qh=l(bp,"docs/source/en/model_doc/brand_new_bert.md"),bp.forEach(o),pa.forEach(o),Vh=c(D),Ve=s(D,"LI",{});var wa=n(Ve);Kh=l(wa,"Finally, add a green tick \u2705 to the TensorFlow column of "),gl=s(wa,"EM",{});var gp=n(gl);ec=l(gp,"BrandNewBert"),gp.forEach(o),tc=l(wa," in "),_l=s(wa,"CODE",{});var _p=n(_l);oc=l(_p,"docs/source/en/index.md"),_p.forEach(o),wa.forEach(o),D.forEach(o),os=c(t),go=s(t,"P",{});var Ep=n(go);rc=l(Ep,`When you\u2019re happy with your implementation, run the following checklist to confirm that your model architecture is
ready:`),Ep.forEach(o),rs=c(t),A=s(t,"OL",{});var z=n(A);Ht=s(z,"LI",{});var zs=n(Ht);lc=l(zs,"All layers that behave differently at train time (e.g. Dropout) are called with a "),El=s(zs,"CODE",{});var Tp=n(El);ac=l(Tp,"training"),Tp.forEach(o),sc=l(zs,` argument, which is
propagated all the way from the top-level classes`),zs.forEach(o),nc=c(z),Jt=s(z,"LI",{});var Qs=n(Jt);ic=l(Qs,"You have used "),Tl=s(Qs,"CODE",{});var kp=n(Tl);dc=l(kp,"#copied from ..."),kp.forEach(o),hc=l(Qs," whenever possible"),Qs.forEach(o),cc=c(z),ke=s(z,"LI",{});var Ro=n(ke);kl=s(Ro,"CODE",{});var Fp=n(kl);fc=l(Fp,"TFBrandNewBertMainLayer"),Fp.forEach(o),mc=l(Ro," and all classes that use it have their "),Fl=s(Ro,"CODE",{});var $p=n(Fl);uc=l($p,"call"),$p.forEach(o),pc=l(Ro," function decorated with "),$l=s(Ro,"CODE",{});var Pp=n($l);wc=l(Pp,"@unpack_inputs"),Pp.forEach(o),Ro.forEach(o),yc=c(z),Gt=s(z,"LI",{});var Vs=n(Gt);Pl=s(Vs,"CODE",{});var Ip=n(Pl);vc=l(Ip,"TFBrandNewBertMainLayer"),Ip.forEach(o),bc=l(Vs," is decorated with "),Il=s(Vs,"CODE",{});var Bp=n(Il);gc=l(Bp,"@keras_serializable"),Bp.forEach(o),Vs.forEach(o),_c=c(z),_o=s(z,"LI",{});var nm=n(_o);Ec=l(nm,"A TensorFlow model can be loaded from PyTorch weights using "),Bl=s(nm,"CODE",{});var Cp=n(Bl);Tc=l(Cp,"TFBrandNewBert.from_pretrained(model_repo, from_pt=True)"),Cp.forEach(o),nm.forEach(o),kc=c(z),Cl=s(z,"LI",{});var Lp=n(Cl);Fc=l(Lp,"You can call the TensorFlow model using the expected input format"),Lp.forEach(o),z.forEach(o),ls=c(t),Fe=s(t,"H3",{class:!0});var Ks=n(Fe);Ke=s(Ks,"A",{id:!0,class:!0,href:!0});var Op=n(Ke);Ll=s(Op,"SPAN",{});var Ap=n(Ll);F(Zt.$$.fragment,Ap),Ap.forEach(o),Op.forEach(o),$c=c(Ks),Ol=s(Ks,"SPAN",{});var Np=n(Ol);Pc=l(Np,"5. Add model tests"),Np.forEach(o),Ks.forEach(o),as=c(t),N=s(t,"P",{});var Q=n(N);Ic=l(Q,`Hurray, you\u2019ve implemented a TensorFlow model! Now it\u2019s time to add tests to make sure that your model behaves as
expected. As in the previous section, we suggest you start by copying the `),Al=s(Q,"CODE",{});var Dp=n(Al);Bc=l(Dp,"test_modeling_brand_new_bert.py"),Dp.forEach(o),Cc=l(Q,` file in
`),Nl=s(Q,"CODE",{});var Mp=n(Nl);Lc=l(Mp,"tests/models/brand_new_bert/"),Mp.forEach(o),Oc=l(Q," into "),Dl=s(Q,"CODE",{});var xp=n(Dl);Ac=l(xp,"test_modeling_tf_brand_new_bert.py"),xp.forEach(o),Nc=l(Q,`, and continue by making the necessary
TensorFlow replacements. For now, in all `),Ml=s(Q,"CODE",{});var Rp=n(Ml);Dc=l(Rp,".from_pretrained()"),Rp.forEach(o),Mc=l(Q," calls, you should use the "),xl=s(Q,"CODE",{});var Sp=n(xl);xc=l(Sp,"from_pt=True"),Sp.forEach(o),Rc=l(Q,` flag to load
the existing PyTorch weights.`),Q.forEach(o),ss=c(t),Eo=s(t,"P",{});var Up=n(Eo);Sc=l(Up,"After you\u2019re done, it\u2019s time for the moment of truth: run the tests! \u{1F62C}"),Up.forEach(o),ns=c(t),F(Wt.$$.fragment,t),is=c(t),et=s(t,"P",{});var en=n(et);Uc=l(en,`The most likely outcome is that you\u2019ll see a bunch of errors. Don\u2019t worry, this is expected! Debugging ML models is
notoriously hard, and the key ingredient to success is patience (and `),Rl=s(en,"CODE",{});var Hp=n(Rl);Hc=l(Hp,"breakpoint()"),Hp.forEach(o),Jc=l(en,`). In our experience, the hardest
problems arise from subtle mismatches between ML frameworks, for which we have a few pointers at the end of this guide.
In other cases, a general test might not be directly applicable to your model, in which case we suggest an override
at the model test class level. Regardless of the issue, don\u2019t hesitate to ask for help in your draft pull request if
you\u2019re stuck.`),en.forEach(o),ds=c(t),To=s(t,"P",{});var Jp=n(To);Gc=l(Jp,"When all tests pass, congratulations, your model is nearly ready to be added to the \u{1F917} Transformers library! \u{1F389}"),Jp.forEach(o),hs=c(t),$e=s(t,"H3",{class:!0});var tn=n($e);tt=s(tn,"A",{id:!0,class:!0,href:!0});var Gp=n(tt);Sl=s(Gp,"SPAN",{});var Zp=n(Sl);F(Yt.$$.fragment,Zp),Zp.forEach(o),Gp.forEach(o),Zc=c(tn),Ul=s(tn,"SPAN",{});var Wp=n(Ul);Wc=l(Wp,"6.-7. Ensure everyone can use your model"),Wp.forEach(o),tn.forEach(o),cs=c(t),ko=s(t,"P",{});var Yp=n(ko);Hl=s(Yp,"STRONG",{});var qp=n(Hl);Yc=l(qp,"6. Submit the pull request"),qp.forEach(o),Yp.forEach(o),fs=c(t),ot=s(t,"P",{});var on=n(ot);qc=l(on,`Once you\u2019re done with the implementation and the tests, it\u2019s time to submit a pull request. Before pushing your code,
run our code formatting utility, `),Jl=s(on,"CODE",{});var jp=n(Jl);jc=l(jp,"make fixup"),jp.forEach(o),Xc=l(on,` \u{1FA84}. This will automatically fix any formatting issues, which would cause
our automatic checks to fail.`),on.forEach(o),ms=c(t),he=s(t,"P",{});var So=n(he);zc=l(So,`It\u2019s now time to convert your draft pull request into a real pull request. To do so, click on the \u201CReady for
review\u201D button and add Joao (`),Gl=s(So,"CODE",{});var Xp=n(Gl);Qc=l(Xp,"@gante"),Xp.forEach(o),Vc=l(So,") and Matt ("),Zl=s(So,"CODE",{});var zp=n(Zl);Kc=l(zp,"@Rocketknight1"),zp.forEach(o),ef=l(So,`) as reviewers. A model pull request will need
at least 3 reviewers, but they will take care of finding appropriate additional reviewers for your model.`),So.forEach(o),us=c(t),ce=s(t,"P",{});var Uo=n(ce);tf=l(Uo,"After all reviewers are happy with the state of your PR, the final action point is to remove the "),Wl=s(Uo,"CODE",{});var Qp=n(Wl);of=l(Qp,"from_pt=True"),Qp.forEach(o),rf=l(Uo,` flag in
`),Yl=s(Uo,"CODE",{});var Vp=n(Yl);lf=l(Vp,".from_pretrained()"),Vp.forEach(o),af=l(Uo,` calls. Since there are no TensorFlow weights, you will have to add them! Check the section
below for instructions on how to do it.`),Uo.forEach(o),ps=c(t),Fo=s(t,"P",{});var Kp=n(Fo);sf=l(Kp,`Finally, when the TensorFlow weights get merged, you have at least 3 reviewer approvals, and all CI checks are
green, double-check the tests locally one last time`),Kp.forEach(o),ws=c(t),F(qt.$$.fragment,t),ys=c(t),$o=s(t,"P",{});var ew=n($o);nf=l(ew,"and we will merge your PR! Congratulations on the milestone \u{1F389}"),ew.forEach(o),vs=c(t),Po=s(t,"P",{});var tw=n(Po);ql=s(tw,"STRONG",{});var ow=n(ql);df=l(ow,"7. (Optional) Build demos and share with the world"),ow.forEach(o),tw.forEach(o),bs=c(t),Io=s(t,"P",{});var rw=n(Io);hf=l(rw,`One of the hardest parts about open-source is discovery. How can the other users learn about the existence of your
fabulous TensorFlow contribution? With proper communication, of course! \u{1F4E3}`),rw.forEach(o),gs=c(t),Bo=s(t,"P",{});var lw=n(Bo);cf=l(lw,"There are two main ways to share your model with the community:"),lw.forEach(o),_s=c(t),rt=s(t,"UL",{});var rn=n(rt);jt=s(rn,"LI",{});var ln=n(jt);ff=l(ln,`Build demos. These include Gradio demos, notebooks, and other fun ways to show off your model. We highly
encourage you to add a notebook to our `),Xt=s(ln,"A",{href:!0,rel:!0});var aw=n(Xt);mf=l(aw,"community-driven demos"),aw.forEach(o),uf=l(ln,"."),ln.forEach(o),pf=c(rn),jl=s(rn,"LI",{});var sw=n(jl);wf=l(sw,`Share stories on social media like Twitter and LinkedIn. You should be proud of your work and share
your achievement with the community - your model can now be used by thousands of engineers and researchers around
the world \u{1F30D}! We will be happy to retweet your posts and help you share your work with the community.`),sw.forEach(o),rn.forEach(o),Es=c(t),Pe=s(t,"H2",{class:!0});var an=n(Pe);lt=s(an,"A",{id:!0,class:!0,href:!0});var nw=n(lt);Xl=s(nw,"SPAN",{});var iw=n(Xl);F(zt.$$.fragment,iw),iw.forEach(o),nw.forEach(o),yf=c(an),zl=s(an,"SPAN",{});var dw=n(zl);vf=l(dw,"Adding TensorFlow weights to \u{1F917} Hub"),dw.forEach(o),an.forEach(o),Ts=c(t),Co=s(t,"P",{});var hw=n(Co);bf=l(hw,`Assuming that the TensorFlow model architecture is available in \u{1F917} Transformers, converting PyTorch weights into
TensorFlow weights is a breeze!`),hw.forEach(o),ks=c(t),Lo=s(t,"P",{});var cw=n(Lo);gf=l(cw,"Here\u2019s how to do it:"),cw.forEach(o),Fs=c(t),fe=s(t,"OL",{});var Ho=n(fe);Ie=s(Ho,"LI",{});var Jo=n(Ie);_f=l(Jo,`Make sure you are logged into your Hugging Face account in your terminal. You can log in using the command
`),Ql=s(Jo,"CODE",{});var fw=n(Ql);Ef=l(fw,"huggingface-cli login"),fw.forEach(o),Tf=l(Jo," (you can find your access tokens "),Qt=s(Jo,"A",{href:!0,rel:!0});var mw=n(Qt);kf=l(mw,"here"),mw.forEach(o),Ff=l(Jo,")"),Jo.forEach(o),$f=c(Ho),Be=s(Ho,"LI",{});var Go=n(Be);Pf=l(Go,"Run "),Vl=s(Go,"CODE",{});var uw=n(Vl);If=l(uw,"transformers-cli pt-to-tf --model-name foo/bar"),uw.forEach(o),Bf=l(Go,", where "),Kl=s(Go,"CODE",{});var pw=n(Kl);Cf=l(pw,"foo/bar"),pw.forEach(o),Lf=l(Go,` is the name of the model repository
containing the PyTorch weights you want to convert`),Go.forEach(o),Of=c(Ho),Ce=s(Ho,"LI",{});var Zo=n(Ce);Af=l(Zo,"Tag "),ea=s(Zo,"CODE",{});var ww=n(ea);Nf=l(ww,"@joaogante"),ww.forEach(o),Df=l(Zo," and "),ta=s(Zo,"CODE",{});var yw=n(ta);Mf=l(yw,"@Rocketknight1"),yw.forEach(o),xf=l(Zo," in the \u{1F917} Hub PR the command above has just created"),Zo.forEach(o),Ho.forEach(o),$s=c(t),Oo=s(t,"P",{});var vw=n(Oo);Rf=l(vw,"That\u2019s it! \u{1F389}"),vw.forEach(o),Ps=c(t),Le=s(t,"H2",{class:!0});var sn=n(Le);at=s(sn,"A",{id:!0,class:!0,href:!0});var bw=n(at);oa=s(bw,"SPAN",{});var gw=n(oa);F(Vt.$$.fragment,gw),gw.forEach(o),bw.forEach(o),Sf=c(sn),ra=s(sn,"SPAN",{});var _w=n(ra);Uf=l(_w,"Debugging mismatches across ML frameworks \u{1F41B}"),_w.forEach(o),sn.forEach(o),Is=c(t),Ao=s(t,"P",{});var Ew=n(Ao);Hf=l(Ew,`At some point, when adding a new architecture or when creating TensorFlow weights for an existing architecture, you
might come across errors complaining about mismatches between PyTorch and TensorFlow. You might even decide to open the
model architecture code for the two frameworks, and find that they look identical. What\u2019s going on? \u{1F914}`),Ew.forEach(o),Bs=c(t),st=s(t,"P",{});var nn=n(st);Jf=l(nn,`First of all, let\u2019s talk about why understanding these mismatches matters. Many community members will use \u{1F917}
Transformers models out of the box, and trust that our models behave as expected. When there is a large mismatch
between the two frameworks, it implies that the model is not following the reference implementation for at least one
of the frameworks. This might lead to silent failures, in which the model runs but has poor performance. This is
arguably worse than a model that fails to run at all! To that end, we aim at having a framework mismatch smaller than
`),la=s(nn,"CODE",{});var Tw=n(la);Gf=l(Tw,"1e-5"),Tw.forEach(o),Zf=l(nn," at all stages of the model."),nn.forEach(o),Cs=c(t),No=s(t,"P",{});var kw=n(No);Wf=l(kw,`As in other numerical problems, the devil is in the details. And as in any detail-oriented craft, the secret
ingredient here is patience. Here is our suggested workflow for when you come across this type of issues:`),kw.forEach(o),Ls=c(t),me=s(t,"OL",{});var Wo=n(me);Kt=s(Wo,"LI",{});var dn=n(Kt);Yf=l(dn,`Locate the source of mismatches. The model you\u2019re converting probably has near identical inner variables up to a
certain point. Place `),aa=s(dn,"CODE",{});var Fw=n(aa);qf=l(Fw,"breakpoint()"),Fw.forEach(o),jf=l(dn,` statements in the two frameworks\u2019 architectures, and compare the values of the
numerical variables in a top-down fashion until you find the source of the problems.`),dn.forEach(o),Xf=c(Wo),sa=s(Wo,"LI",{});var $w=n(sa);zf=l($w,`Now that you\u2019ve pinpointed the source of the issue, get in touch with the \u{1F917} Transformers team. It is possible
that we\u2019ve seen a similar problem before and can promptly provide a solution. As a fallback, scan popular pages
like StackOverflow and GitHub issues.`),$w.forEach(o),Qf=c(Wo),na=s(Wo,"LI",{});var Pw=n(na);Vf=l(Pw,`If there is no solution in sight, it means you\u2019ll have to go deeper. The good news is that you\u2019ve located the
issue, so you can focus on the problematic instruction, abstracting away the rest of the model! The bad news is
that you\u2019ll have to venture into the source implementation of said instruction. In some cases, you might find an
issue with a reference implementation - don\u2019t abstain from opening an issue in the upstream repository.`),Pw.forEach(o),Wo.forEach(o),Os=c(t),ue=s(t,"P",{});var Yo=n(ue);Kf=l(Yo,`In some cases, in discussion with the \u{1F917} Transformers team, we might find that fixing the mismatch is infeasible.
When the mismatch is very small in the output layers of the model (but potentially large in the hidden states), we
might decide to ignore it in favor of distributing the model. The `),ia=s(Yo,"CODE",{});var Iw=n(ia);em=l(Iw,"pt-to-tf"),Iw.forEach(o),tm=l(Yo," CLI mentioned above has a "),da=s(Yo,"CODE",{});var Bw=n(da);om=l(Bw,"--max-error"),Bw.forEach(o),rm=l(Yo,`
flag to override the error message at weight conversion time.`),Yo.forEach(o),this.h()},h(){f(m,"name","hf:doc:metadata"),f(m,"content",JSON.stringify(Sw)),f(_,"id","how-to-convert-a-transformers-model-to-tensorflow"),f(_,"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(_,"href","#how-to-convert-a-transformers-model-to-tensorflow"),f(v,"class","relative group"),f(le,"href","add_new_model"),f(ve,"href","add_new_model#general-overview-of-transformers"),f(mt,"href","https://huggingface.co/blog/tensorflow-philosophy"),f(mt,"rel","nofollow"),f(xe,"id","stepbystep-guide-to-add-tensorflow-model-architecture-code"),f(xe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(xe,"href","#stepbystep-guide-to-add-tensorflow-model-architecture-code"),f(be,"class","relative group"),f(ao,"href","add_new_model#general-overview-of-transformers"),f(Se,"id","13-prepare-your-model-contribution"),f(Se,"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(Se,"href","#13-prepare-your-model-contribution"),f(ge,"class","relative group"),f(io,"href","#adding-tensorflow-weights-to-hub"),f(ho,"href","add_new_model"),f(yt,"href","https://github.com/huggingface/transformers"),f(yt,"rel","nofollow"),f(gt,"start","3"),f(kt,"start","4"),f($t,"start","5"),f(_e,"start","6"),f(Ee,"start","8"),f(po,"href","model_doc/bert"),f(Bt,"href","https://discuss.huggingface.co/"),f(Bt,"rel","nofollow"),f(We,"id","4-model-implementation"),f(We,"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(We,"href","#4-model-implementation"),f(Te,"class","relative group"),f(Lt,"href","https://www.tensorflow.org/api_docs/python/tf"),f(Lt,"rel","nofollow"),f(Ot,"href","https://pytorch.org/docs/stable/"),f(Ot,"rel","nofollow"),f(At,"href","https://pytorch.org/docs/stable/generated/torch.nn.BatchNorm2d.html#torch.nn.BatchNorm2d"),f(At,"rel","nofollow"),f(Nt,"href","https://www.tensorflow.org/api_docs/python/tf/keras/layers/BatchNormalization"),f(Nt,"rel","nofollow"),f(Dt,"href","https://github.com/huggingface/transformers/blob/655f72a6896c0533b1bdee519ed65a059c2425ac/src/transformers/models/vit_mae/modeling_vit_mae.py#L212"),f(Dt,"rel","nofollow"),f(Mt,"href","https://github.com/huggingface/transformers/blob/655f72a6896c0533b1bdee519ed65a059c2425ac/src/transformers/models/vit_mae/modeling_tf_vit_mae.py#L220"),f(Mt,"rel","nofollow"),f(Rt,"href","https://github.com/huggingface/transformers/blob/4fd32a1f499e45f009c2c0dea4d81c321cba7e02/src/transformers/models/bert/modeling_tf_bert.py#L719"),f(Rt,"rel","nofollow"),f(St,"href","https://github.com/huggingface/transformers/blob/4fd32a1f499e45f009c2c0dea4d81c321cba7e02/src/transformers/models/bert/modeling_tf_bert.py#L916"),f(St,"rel","nofollow"),f(Ut,"href","https://github.com/huggingface/transformers/pull/18020/files"),f(Ut,"rel","nofollow"),f(Ke,"id","5-add-model-tests"),f(Ke,"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(Ke,"href","#5-add-model-tests"),f(Fe,"class","relative group"),f(tt,"id","67-ensure-everyone-can-use-your-model"),f(tt,"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(tt,"href","#67-ensure-everyone-can-use-your-model"),f($e,"class","relative group"),f(Xt,"href","https://huggingface.co/docs/transformers/community"),f(Xt,"rel","nofollow"),f(lt,"id","adding-tensorflow-weights-to-hub"),f(lt,"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(lt,"href","#adding-tensorflow-weights-to-hub"),f(Pe,"class","relative group"),f(Qt,"href","https://huggingface.co/settings/tokens"),f(Qt,"rel","nofollow"),f(at,"id","debugging-mismatches-across-ml-frameworks"),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","#debugging-mismatches-across-ml-frameworks"),f(Le,"class","relative group")},m(t,i){e(document.head,m),d(t,q,i),d(t,v,i),e(v,_),e(_,H),$(b,H,null),e(v,p),e(v,J),e(J,M),d(t,C,i),d(t,x,i),e(x,j),e(x,le),e(le,ft),e(x,V),d(t,Ae,i),d(t,ae,i),e(ae,K),d(t,Ne,i),d(t,se,i),e(se,y),d(t,G,i),d(t,ee,i),e(ee,O),e(O,ve),e(ve,oo),e(ee,ro),e(ee,De),e(De,mt),e(mt,hn),d(t,ya,i),d(t,lo,i),e(lo,cn),d(t,va,i),$(Me,t,i),d(t,ba,i),d(t,be,i),e(be,xe),e(xe,qo),$(ut,qo,null),e(be,fn),e(be,jo),e(jo,mn),d(t,ga,i),d(t,Re,i),e(Re,un),e(Re,ao),e(ao,pn),e(Re,wn),d(t,_a,i),d(t,ne,i),e(ne,Xo),e(Xo,yn),e(ne,vn),e(ne,zo),e(zo,bn),e(ne,gn),e(ne,Qo),e(Qo,_n),d(t,Ea,i),d(t,so,i),e(so,En),d(t,Ta,i),d(t,E,i),e(E,Vo),e(Vo,Tn),e(E,kn),e(E,Ko),e(Ko,Fn),e(E,$n),e(E,er),e(er,Pn),e(E,In),e(E,tr),e(tr,Bn),e(E,Cn),e(E,or),e(or,Ln),e(E,On),e(E,rr),e(rr,An),e(E,Nn),e(E,lr),e(lr,Dn),d(t,ka,i),d(t,ge,i),e(ge,Se),e(Se,ar),$(pt,ar,null),e(ge,Mn),e(ge,sr),e(sr,xn),d(t,Fa,i),d(t,no,i),e(no,nr),e(nr,Rn),d(t,$a,i),d(t,Ue,i),e(Ue,Sn),e(Ue,io),e(io,Un),e(Ue,Hn),d(t,Pa,i),d(t,ie,i),e(ie,Jn),e(ie,ir),e(ir,Gn),e(ie,Zn),e(ie,ho),e(ho,Wn),e(ie,Yn),d(t,Ia,i),$(He,t,i),d(t,Ba,i),d(t,co,i),e(co,dr),e(dr,qn),d(t,Ca,i),d(t,fo,i),e(fo,jn),d(t,La,i),d(t,Je,i),e(Je,hr),e(hr,wt),e(wt,Xn),e(wt,yt),e(yt,zn),e(wt,Qn),e(Je,Vn),e(Je,cr),e(cr,vt),e(vt,Kn),e(vt,fr),e(fr,ei),e(vt,ti),d(t,Oa,i),$(bt,t,i),d(t,Aa,i),d(t,gt,i),e(gt,mr),e(mr,oi),d(t,Na,i),$(_t,t,i),d(t,Da,i),d(t,mo,i),e(mo,ri),d(t,Ma,i),$(Et,t,i),d(t,xa,i),d(t,Tt,i),e(Tt,ur),e(ur,li),e(Tt,ai),d(t,Ra,i),d(t,kt,i),e(kt,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d(t,Bs,i),d(t,st,i),e(st,Jf),e(st,la),e(la,Gf),e(st,Zf),d(t,Cs,i),d(t,No,i),e(No,Wf),d(t,Ls,i),d(t,me,i),e(me,Kt),e(Kt,Yf),e(Kt,aa),e(aa,qf),e(Kt,jf),e(me,Xf),e(me,sa),e(sa,zf),e(me,Qf),e(me,na),e(na,Vf),d(t,Os,i),d(t,ue,i),e(ue,Kf),e(ue,ia),e(ia,em),e(ue,tm),e(ue,da),e(da,om),e(ue,rm),As=!0},p(t,[i]){const eo={};i&2&&(eo.$$scope={dirty:i,ctx:t}),Me.$set(eo);const ha={};i&2&&(ha.$$scope={dirty:i,ctx:t}),He.$set(ha)},i(t){As||(P(b.$$.fragment,t),P(Me.$$.fragment,t),P(ut.$$.fragment,t),P(pt.$$.fragment,t),P(He.$$.fragment,t),P(bt.$$.fragment,t),P(_t.$$.fragment,t),P(Et.$$.fragment,t),P(Ft.$$.fragment,t),P(Pt.$$.fragment,t),P(It.$$.fragment,t),P(Ct.$$.fragment,t),P(Zt.$$.fragment,t),P(Wt.$$.fragment,t),P(Yt.$$.fragment,t),P(qt.$$.fragment,t),P(zt.$$.fragment,t),P(Vt.$$.fragment,t),As=!0)},o(t){I(b.$$.fragment,t),I(Me.$$.fragment,t),I(ut.$$.fragment,t),I(pt.$$.fragment,t),I(He.$$.fragment,t),I(bt.$$.fragment,t),I(_t.$$.fragment,t),I(Et.$$.fragment,t),I(Ft.$$.fragment,t),I(Pt.$$.fragment,t),I(It.$$.fragment,t),I(Ct.$$.fragment,t),I(Zt.$$.fragment,t),I(Wt.$$.fragment,t),I(Yt.$$.fragment,t),I(qt.$$.fragment,t),I(zt.$$.fragment,t),I(Vt.$$.fragment,t),As=!1},d(t){o(m),t&&o(q),t&&o(v),B(b),t&&o(C),t&&o(x),t&&o(Ae),t&&o(ae),t&&o(Ne),t&&o(se),t&&o(G),t&&o(ee),t&&o(ya),t&&o(lo),t&&o(va),B(Me,t),t&&o(ba),t&&o(be),B(ut),t&&o(ga),t&&o(Re),t&&o(_a),t&&o(ne),t&&o(Ea),t&&o(so),t&&o(Ta),t&&o(E),t&&o(ka),t&&o(ge),B(pt),t&&o(Fa),t&&o(no),t&&o($a),t&&o(Ue),t&&o(Pa),t&&o(ie),t&&o(Ia),B(He,t),t&&o(Ba),t&&o(co),t&&o(Ca),t&&o(fo),t&&o(La),t&&o(Je),t&&o(Oa),B(bt,t),t&&o(Aa),t&&o(gt),t&&o(Na),B(_t,t),t&&o(Da),t&&o(mo),t&&o(Ma),B(Et,t),t&&o(xa),t&&o(Tt),t&&o(Ra),t&&o(kt),t&&o(Sa),B(Ft,t),t&&o(Ua),t&&o($t),t&&o(Ha),B(Pt,t),t&&o(Ja),t&&o(_e),t&&o(Ga),B(It,t),t&&o(Za),t&&o(Ee),t&&o(Wa),t&&o(Ge),t&&o(Ya),t&&o(uo),t&&o(qa),t&&o(de),t&&o(ja),t&&o(wo),t&&o(Xa),t&&o(Ze),t&&o(za),t&&o(Te),B(Ct),t&&o(Qa),t&&o(T),t&&o(Va),t&&o(yo),t&&o(Ka),t&&o(u),t&&o(es),t&&o(Ye),t&&o(ts),t&&o(g),t&&o(os),t&&o(go),t&&o(rs),t&&o(A),t&&o(ls),t&&o(Fe),B(Zt),t&&o(as),t&&o(N),t&&o(ss),t&&o(Eo),t&&o(ns),B(Wt,t),t&&o(is),t&&o(et),t&&o(ds),t&&o(To),t&&o(hs),t&&o($e),B(Yt),t&&o(cs),t&&o(ko),t&&o(fs),t&&o(ot),t&&o(ms),t&&o(he),t&&o(us),t&&o(ce),t&&o(ps),t&&o(Fo),t&&o(ws),B(qt,t),t&&o(ys),t&&o($o),t&&o(vs),t&&o(Po),t&&o(bs),t&&o(Io),t&&o(gs),t&&o(Bo),t&&o(_s),t&&o(rt),t&&o(Es),t&&o(Pe),B(zt),t&&o(Ts),t&&o(Co),t&&o(ks),t&&o(Lo),t&&o(Fs),t&&o(fe),t&&o($s),t&&o(Oo),t&&o(Ps),t&&o(Le),B(Vt),t&&o(Is),t&&o(Ao),t&&o(Bs),t&&o(st),t&&o(Cs),t&&o(No),t&&o(Ls),t&&o(me),t&&o(Os),t&&o(ue)}}}const Sw={local:"how-to-convert-a-transformers-model-to-tensorflow",sections:[{local:"stepbystep-guide-to-add-tensorflow-model-architecture-code",sections:[{local:"13-prepare-your-model-contribution",title:"1.-3. Prepare your model contribution"},{local:"4-model-implementation",title:"4. Model implementation"},{local:"5-add-model-tests",title:"5. Add model tests"},{local:"67-ensure-everyone-can-use-your-model",title:"6.-7. Ensure everyone can use your model"}],title:"Step-by-step guide to add TensorFlow model architecture code"},{local:"adding-tensorflow-weights-to-hub",title:"Adding TensorFlow weights to \u{1F917} Hub"},{local:"debugging-mismatches-across-ml-frameworks",title:"Debugging mismatches across ML frameworks \u{1F41B}"}],title:"How to convert a \u{1F917} Transformers model to TensorFlow?"};function Uw(to){return Dw(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ww extends Lw{constructor(m){super();Ow(this,m,Uw,Rw,Aw,{})}}export{Ww as default,Sw as metadata};
