import{S as XT,i as KT,s as QT,e as a,k as h,w as p,t as r,M as VT,c as s,d as o,m as f,a as i,x as u,h as n,b as m,N as ZT,G as t,g as d,y as c,q as y,o as g,B as w,v as e9}from"../chunks/vendor-hf-doc-builder.js";import{T as JT}from"../chunks/Tip-hf-doc-builder.js";import{I as ge}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as k}from"../chunks/CodeBlock-hf-doc-builder.js";function t9(Gr){let T,U,P,A,z;return{c(){T=a("p"),U=r("If you\u2019re interested in implementing a TensorFlow model, take a look at the "),P=a("a"),A=r("How to convert a \u{1F917} Transformers model to TensorFlow"),z=r(" guide!"),this.h()},l(B){T=s(B,"P",{});var C=i(T);U=n(C,"If you\u2019re interested in implementing a TensorFlow model, take a look at the "),P=s(C,"A",{href:!0});var L=i(P);A=n(L,"How to convert a \u{1F917} Transformers model to TensorFlow"),L.forEach(o),z=n(C," guide!"),C.forEach(o),this.h()},h(){m(P,"href","add_tensorflow_model")},m(B,C){d(B,T,C),t(T,U),t(T,P),t(P,A),t(T,z)},d(B){B&&o(T)}}}function o9(Gr){let T,U,P,A,z,B,C;return{c(){T=a("p"),U=r("In case you are using Windows, you should replace "),P=a("code"),A=r("RUN_SLOW=1"),z=r(" with "),B=a("code"),C=r("SET RUN_SLOW=1")},l(L){T=s(L,"P",{});var fe=i(T);U=n(fe,"In case you are using Windows, you should replace "),P=s(fe,"CODE",{});var uo=i(P);A=n(uo,"RUN_SLOW=1"),uo.forEach(o),z=n(fe," with "),B=s(fe,"CODE",{});var me=i(B);C=n(me,"SET RUN_SLOW=1"),me.forEach(o),fe.forEach(o)},m(L,fe){d(L,T,fe),t(T,U),t(T,P),t(P,A),t(T,z),t(T,B),t(B,C)},d(L){L&&o(T)}}}function r9(Gr){let T,U,P,A,z,B,C,L,fe,uo,me,Tu,co,$u,Pu,oh,it,rh,Ur,Iu,nh,Y,Da,Bu,Au,Fa,Nu,Mu,Ha,ju,xu,pe,Ou,za,Cu,Lu,Wa,qu,Ru,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,ok,Ud,rk,nk,cp,Hr,yp,Jt,ak,Yd,sk,ik,gp,pa,Jd,lk,wp,Xt,dk,Xd,hk,fk,vp,ua,Kd,mk,bp,ca,pk,_p,at,Kt,Qd,zr,uk,Vd,ck,Ep,ya,yk,kp,ga,Zd,gk,Tp;return B=new ge({}),it=new JT({props:{$$slots:{default:[t9]},$$scope:{ctx:Gr}}}),wo=new ge({}),bo=new ge({}),_o=new k({props:{code:`model = BrandNewBertModel.from_pretrained("brandy/brand_new_bert")
model.config  # model has access to its config`,highlighted:`model = BrandNewBertModel.from_pretrained(<span class="hljs-string">&quot;brandy/brand_new_bert&quot;</span>)
model.config  <span class="hljs-comment"># model has access to its config</span>`}}),Eo=new ge({}),To=new ge({}),$o=new ge({}),Oo=new ge({}),Lo=new ge({}),Do=new k({props:{code:`git clone https://github.com/[your Github handle]/transformers.git
cd transformers
git remote add upstream https://github.com/huggingface/transformers.git`,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`}}),Ho=new k({props:{code:`python -m venv .env
source .env/bin/activate
pip install -e ".[dev]"`,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>`}}),zo=new k({props:{code:"cd ..",highlighted:'<span class="hljs-built_in">cd</span> ..'}}),Xo=new k({props:{code:`git clone https://github.com/org_that_created_brand_new_bert_org/brand_new_bert.git
cd brand_new_bert
pip install -e .`,highlighted:`git <span class="hljs-built_in">clone</span> https://github.com/org_that_created_brand_new_bert_org/brand_new_bert.git
<span class="hljs-built_in">cd</span> brand_new_bert
pip install -e .`}}),Ko=new ge({}),er=new k({props:{code:`model = BrandNewBertModel.load_pretrained_checkpoint("/path/to/checkpoint/")
input_ids = [0, 4, 5, 2, 3, 7, 9]  # vector of input ids
original_output = model.predict(input_ids)`,highlighted:`model = BrandNewBertModel.load_pretrained_checkpoint(<span class="hljs-string">&quot;/path/to/checkpoint/&quot;</span>)
input_ids = [<span class="hljs-number">0</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">7</span>, <span class="hljs-number">9</span>]  <span class="hljs-comment"># vector of input ids</span>
original_output = model.predict(input_ids)`}}),nr=new k({props:{code:`[[
 [-0.1465, -0.6501,  0.1993,  ...,  0.1451,  0.3430,  0.6024],
 [-0.4417, -0.5920,  0.3450,  ..., -0.3062,  0.6182,  0.7132],
 [-0.5009, -0.7122,  0.4548,  ..., -0.3662,  0.6091,  0.7648],
 ...,
 [-0.5613, -0.6332,  0.4324,  ..., -0.3792,  0.7372,  0.9288],
 [-0.5416, -0.6345,  0.4180,  ..., -0.3564,  0.6992,  0.9191],
 [-0.5334, -0.6403,  0.4271,  ..., -0.3339,  0.6533,  0.8694]]],`,highlighted:`<span class="hljs-comment">[<span class="hljs-comment">[
 <span class="hljs-comment">[-0.1465, -0.6501,  0.1993,  ...,  0.1451,  0.3430,  0.6024]</span>,
 <span class="hljs-comment">[-0.4417, -0.5920,  0.3450,  ..., -0.3062,  0.6182,  0.7132]</span>,
 <span class="hljs-comment">[-0.5009, -0.7122,  0.4548,  ..., -0.3662,  0.6091,  0.7648]</span>,
 ...,
 <span class="hljs-comment">[-0.5613, -0.6332,  0.4324,  ..., -0.3792,  0.7372,  0.9288]</span>,
 <span class="hljs-comment">[-0.5416, -0.6345,  0.4180,  ..., -0.3564,  0.6992,  0.9191]</span>,
 <span class="hljs-comment">[-0.5334, -0.6403,  0.4271,  ..., -0.3339,  0.6533,  0.8694]</span>]</span>]</span>,`}}),lr=new ge({}),dr=new k({props:{code:"cd transformers",highlighted:'<span class="hljs-built_in">cd</span> transformers'}}),fr=new k({props:{code:"git checkout -b add_brand_new_bert",highlighted:"git checkout -b add_brand_new_bert"}}),pr=new k({props:{code:`git add .
git commit`,highlighted:`git add .
git commit`}}),cr=new k({props:{code:`git fetch upstream
git rebase upstream/main`,highlighted:`git fetch upstream
git rebase upstream/main`}}),gr=new k({props:{code:"git push -u origin a-descriptive-name-for-my-changes",highlighted:"git push -u origin a-descriptive-name-for-my-changes"}}),wr=new k({props:{code:`git fetch upstream
git merge upstream/main`,highlighted:`git fetch upstream
git merge upstream/main`}}),vr=new k({props:{code:`from transformers import BrandNewBertModel, BrandNewBertConfig

model = BrandNewBertModel(BrandNewBertConfig())`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BrandNewBertModel, BrandNewBertConfig

model = BrandNewBertModel(BrandNewBertConfig())`}}),Er=new k({props:{code:`from torch import nn


class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.dense = nn.Linear(10, 10)
        self.intermediate = nn.Linear(10, 10)
        self.layer_norm = nn.LayerNorm(10)`,highlighted:`<span class="hljs-keyword">from</span> torch <span class="hljs-keyword">import</span> nn


<span class="hljs-keyword">class</span> <span class="hljs-title class_">SimpleModel</span>(nn.Module):
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self</span>):
        <span class="hljs-built_in">super</span>().__init__()
        self.dense = nn.Linear(<span class="hljs-number">10</span>, <span class="hljs-number">10</span>)
        self.intermediate = nn.Linear(<span class="hljs-number">10</span>, <span class="hljs-number">10</span>)
        self.layer_norm = nn.LayerNorm(<span class="hljs-number">10</span>)`}}),kr=new k({props:{code:`model = SimpleModel()

print(model)`,highlighted:`model = SimpleModel()

<span class="hljs-built_in">print</span>(model)`}}),Tr=new k({props:{code:`SimpleModel(
  (dense): Linear(in_features=10, out_features=10, bias=True)
  (intermediate): Linear(in_features=10, out_features=10, bias=True)
  (layer_norm): LayerNorm((10,), eps=1e-05, elementwise_affine=True)
)`,highlighted:`SimpleModel(
  (dense): Linear(<span class="hljs-attribute">in_features</span>=10, <span class="hljs-attribute">out_features</span>=10, <span class="hljs-attribute">bias</span>=<span class="hljs-literal">True</span>)
  (intermediate): Linear(<span class="hljs-attribute">in_features</span>=10, <span class="hljs-attribute">out_features</span>=10, <span class="hljs-attribute">bias</span>=<span class="hljs-literal">True</span>)
  (layer_norm): LayerNorm((10,), <span class="hljs-attribute">eps</span>=1e-05, <span class="hljs-attribute">elementwise_affine</span>=<span class="hljs-literal">True</span>)
)`}}),$r=new k({props:{code:"print(model.dense.weight.data)",highlighted:'<span class="hljs-built_in">print</span>(model.dense.weight.data)'}}),Pr=new k({props:{code:`tensor([[-0.0818,  0.2207, -0.0749, -0.0030,  0.0045, -0.1569, -0.1598,  0.0212,
         -0.2077,  0.2157],
        [ 0.1044,  0.0201,  0.0990,  0.2482,  0.3116,  0.2509,  0.2866, -0.2190,
          0.2166, -0.0212],
        [-0.2000,  0.1107, -0.1999, -0.3119,  0.1559,  0.0993,  0.1776, -0.1950,
         -0.1023, -0.0447],
        [-0.0888, -0.1092,  0.2281,  0.0336,  0.1817, -0.0115,  0.2096,  0.1415,
         -0.1876, -0.2467],
        [ 0.2208, -0.2352, -0.1426, -0.2636, -0.2889, -0.2061, -0.2849, -0.0465,
          0.2577,  0.0402],
        [ 0.1502,  0.2465,  0.2566,  0.0693,  0.2352, -0.0530,  0.1859, -0.0604,
          0.2132,  0.1680],
        [ 0.1733, -0.2407, -0.1721,  0.1484,  0.0358, -0.0633, -0.0721, -0.0090,
          0.2707, -0.2509],
        [-0.1173,  0.1561,  0.2945,  0.0595, -0.1996,  0.2988, -0.0802,  0.0407,
          0.1829, -0.1568],
        [-0.1164, -0.2228, -0.0403,  0.0428,  0.1339,  0.0047,  0.1967,  0.2923,
          0.0333, -0.0536],
        [-0.1492, -0.1616,  0.1057,  0.1950, -0.2807, -0.2710, -0.1586,  0.0739,
          0.2220,  0.2358]]).`,highlighted:`tensor([[<span class="hljs-string">-0</span>.0818,  0.2207, <span class="hljs-string">-0</span>.0749, <span class="hljs-string">-0</span>.0030,  0.0045, <span class="hljs-string">-0</span>.1569, <span class="hljs-string">-0</span>.1598,  0.0212,
         <span class="hljs-string">-0</span>.2077,  0.2157],
        [ 0.1044,  0.0201,  0.0990,  0.2482,  0.3116,  0.2509,  0.2866, <span class="hljs-string">-0</span>.2190,
          0.2166, <span class="hljs-string">-0</span>.0212],
        [<span class="hljs-string">-0</span>.2000,  0.1107, <span class="hljs-string">-0</span>.1999, <span class="hljs-string">-0</span>.3119,  0.1559,  0.0993,  0.1776, <span class="hljs-string">-0</span>.1950,
         <span class="hljs-string">-0</span>.1023, <span class="hljs-string">-0</span>.0447],
        [<span class="hljs-string">-0</span>.0888, <span class="hljs-string">-0</span>.1092,  0.2281,  0.0336,  0.1817, <span class="hljs-string">-0</span>.0115,  0.2096,  0.1415,
         <span class="hljs-string">-0</span>.1876, <span class="hljs-string">-0</span>.2467],
        [ 0.2208, <span class="hljs-string">-0</span>.2352, <span class="hljs-string">-0</span>.1426, <span class="hljs-string">-0</span>.2636, <span class="hljs-string">-0</span>.2889, <span class="hljs-string">-0</span>.2061, <span class="hljs-string">-0</span>.2849, <span class="hljs-string">-0</span>.0465,
          0.2577,  0.0402],
        [ 0.1502,  0.2465,  0.2566,  0.0693,  0.2352, <span class="hljs-string">-0</span>.0530,  0.1859, <span class="hljs-string">-0</span>.0604,
          0.2132,  0.1680],
        [ 0.1733, <span class="hljs-string">-0</span>.2407, <span class="hljs-string">-0</span>.1721,  0.1484,  0.0358, <span class="hljs-string">-0</span>.0633, <span class="hljs-string">-0</span>.0721, <span class="hljs-string">-0</span>.0090,
          0.2707, <span class="hljs-string">-0</span>.2509],
        [<span class="hljs-string">-0</span>.1173,  0.1561,  0.2945,  0.0595, <span class="hljs-string">-0</span>.1996,  0.2988, <span class="hljs-string">-0</span>.0802,  0.0407,
          0.1829, <span class="hljs-string">-0</span>.1568],
        [<span class="hljs-string">-0</span>.1164, <span class="hljs-string">-0</span>.2228, <span class="hljs-string">-0</span>.0403,  0.0428,  0.1339,  0.0047,  0.1967,  0.2923,
          0.0333, <span class="hljs-string">-0</span>.0536],
        [<span class="hljs-string">-0</span>.1492, <span class="hljs-string">-0</span>.1616,  0.1057,  0.1950, <span class="hljs-string">-0</span>.2807, <span class="hljs-string">-0</span>.2710, <span class="hljs-string">-0</span>.1586,  0.0739,
          0.2220,  0.2358]]).`}}),Br=new k({props:{code:`# retrieve matching layer weights, e.g. by
# recursive algorithm
layer_name = "dense"
pretrained_weight = array_of_dense_layer

model_pointer = getattr(model, "dense")

model_pointer.weight.data = torch.from_numpy(pretrained_weight)`,highlighted:`<span class="hljs-comment"># retrieve matching layer weights, e.g. by</span>
<span class="hljs-comment"># recursive algorithm</span>
layer_name = <span class="hljs-string">&quot;dense&quot;</span>
pretrained_weight = array_of_dense_layer

model_pointer = <span class="hljs-built_in">getattr</span>(model, <span class="hljs-string">&quot;dense&quot;</span>)

model_pointer.weight.data = torch.from_numpy(pretrained_weight)`}}),Ar=new k({props:{code:`assert (
    model_pointer.weight.shape == pretrained_weight.shape
), f"Pointer shape of random weight {model_pointer.shape} and array shape of checkpoint weight {pretrained_weight.shape} mismatched"`,highlighted:`<span class="hljs-keyword">assert</span> (
    model_pointer.weight.shape == pretrained_weight.shape
), <span class="hljs-string">f&quot;Pointer shape of random weight <span class="hljs-subst">{model_pointer.shape}</span> and array shape of checkpoint weight <span class="hljs-subst">{pretrained_weight.shape}</span> mismatched&quot;</span>`}}),Mr=new k({props:{code:'logger.info(f"Initialize PyTorch weight {layer_name} from {pretrained_weight.name}")',highlighted:'logger.info(<span class="hljs-string">f&quot;Initialize PyTorch weight <span class="hljs-subst">{layer_name}</span> from <span class="hljs-subst">{pretrained_weight.name}</span>&quot;</span>)'}}),jr=new k({props:{code:'model.save_pretrained("/path/to/converted/checkpoint/folder")',highlighted:'model.save_pretrained(<span class="hljs-string">&quot;/path/to/converted/checkpoint/folder&quot;</span>)'}}),xr=new k({props:{code:`model = BrandNewBertModel.from_pretrained("/path/to/converted/checkpoint/folder")
input_ids = [0, 4, 4, 3, 2, 4, 1, 7, 19]
output = model(input_ids).last_hidden_states`,highlighted:`model = BrandNewBertModel.from_pretrained(<span class="hljs-string">&quot;/path/to/converted/checkpoint/folder&quot;</span>)
input_ids = [<span class="hljs-number">0</span>, <span class="hljs-number">4</span>, <span class="hljs-number">4</span>, <span class="hljs-number">3</span>, <span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">1</span>, <span class="hljs-number">7</span>, <span class="hljs-number">19</span>]
output = model(input_ids).last_hidden_states`}}),Cr=new k({props:{code:"pytest tests/models/brand_new_bert/test_modeling_brand_new_bert.py",highlighted:"pytest tests/models/brand_new_bert/test_modeling_brand_new_bert.py"}}),Lr=new k({props:{code:"RUN_SLOW=1 pytest -sv tests/models/brand_new_bert/test_modeling_brand_new_bert.py::BrandNewBertModelIntegrationTests",highlighted:"RUN_SLOW=1 pytest -sv tests/models/brand_new_bert/test_modeling_brand_new_bert.py::BrandNewBertModelIntegrationTests"}}),Ht=new JT({props:{$$slots:{default:[o9]},$$scope:{ctx:Gr}}}),Rr=new k({props:{code:`input_str = "This is a long example input string containing special characters .$?-, numbers 2872 234 12 and words."
model = BrandNewBertModel.load_pretrained_checkpoint("/path/to/checkpoint/")
input_ids = model.tokenize(input_str)`,highlighted:`input_str = <span class="hljs-string">&quot;This is a long example input string containing special characters .$?-, numbers 2872 234 12 and words.&quot;</span>
model = BrandNewBertModel.load_pretrained_checkpoint(<span class="hljs-string">&quot;/path/to/checkpoint/&quot;</span>)
input_ids = model.tokenize(input_str)`}}),Sr=new k({props:{code:`from transformers import BrandNewBertTokenizer

input_str = "This is a long example input string containing special characters .$?-, numbers 2872 234 12 and words."

tokenizer = BrandNewBertTokenizer.from_pretrained("/path/to/tokenizer/folder/")

input_ids = tokenizer(input_str).input_ids`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BrandNewBertTokenizer

input_str = <span class="hljs-string">&quot;This is a long example input string containing special characters .$?-, numbers 2872 234 12 and words.&quot;</span>

tokenizer = BrandNewBertTokenizer.from_pretrained(<span class="hljs-string">&quot;/path/to/tokenizer/folder/&quot;</span>)

input_ids = tokenizer(input_str).input_ids`}}),Dr=new k({props:{code:"make style",highlighted:"make style"}}),Fr=new k({props:{code:"make quality",highlighted:"make quality"}}),Hr=new k({props:{code:`brand_new_bert.push_to_hub("brand_new_bert")
# Uncomment the following line to push to an organization.
# brand_new_bert.push_to_hub("<organization>/brand_new_bert")`,highlighted:`brand_new_bert.push_to_hub(<span class="hljs-string">&quot;brand_new_bert&quot;</span>)
<span class="hljs-comment"># Uncomment the following line to push to an organization.</span>
<span class="hljs-comment"># brand_new_bert.push_to_hub(&quot;&lt;organization&gt;/brand_new_bert&quot;)</span>`}}),zr=new ge({}),{c(){T=a("meta"),U=h(),P=a("h1"),A=a("a"),z=a("span"),p(B.$$.fragment),C=h(),L=a("span"),fe=r("How to add a model to \u{1F917} Transformers?"),uo=h(),me=a("p"),Tu=r("The \u{1F917} Transformers library is often able to offer new models thanks to community contributors. But this can be a challenging project and requires an in-depth knowledge of the \u{1F917} Transformers library and the model to implement. At Hugging Face, we\u2019re trying to empower more of the community to actively add models and we\u2019ve put together this guide to walk you through the process of adding a PyTorch model (make sure you have "),co=a("a"),$u=r("PyTorch installed"),Pu=r(")."),oh=h(),p(it.$$.fragment),rh=h(),Ur=a("p"),Iu=r("Along the way, you\u2019ll:"),nh=h(),Y=a("ul"),Da=a("li"),Bu=r("get insights into open-source best practices"),Au=h(),Fa=a("li"),Nu=r("understand the design principles behind one of the most popular deep learning libraries"),Mu=h(),Ha=a("li"),ju=r("learn how to efficiently test large models"),xu=h(),pe=a("li"),Ou=r("learn how to integrate Python utilities like "),za=a("code"),Cu=r("black"),Lu=r(", "),Wa=a("code"),qu=r("isort"),Ru=r(", and "),Ga=a("code"),Su=r("make fix-copies"),Du=r(" to ensure clean and readable code"),ah=h(),Yr=a("p"),Fu=r("A Hugging Face team member will be available to help you along the way so you\u2019ll never be alone. \u{1F917} \u2764\uFE0F"),sh=h(),we=a("p"),Hu=r("To get started, open a "),yo=a("a"),zu=r("New model addition"),Wu=r(" issue for the model you want to see in \u{1F917} Transformers. If you\u2019re not especially picky about contributing a specific model, you can filter by the "),go=a("a"),Gu=r("New model label"),Uu=r(" to see if there are any unclaimed model requests and work on it."),ih=h(),Jr=a("p"),Yu=r("Once you\u2019ve opened a new model request, the first step is to get familiar with \u{1F917} Transformers if you aren\u2019t already!"),lh=h(),Re=a("h2"),lt=a("a"),Ua=a("span"),p(wo.$$.fragment),Ju=h(),Ya=a("span"),Xu=r("General overview of \u{1F917} Transformers"),dh=h(),Xr=a("p"),Ku=r(`First, you should get a general overview of \u{1F917} Transformers. \u{1F917} Transformers is a very opinionated library, so there is a
chance that you don\u2019t agree with some of the library\u2019s philosophies or design choices. From our experience, however, we
found that the fundamental design choices and philosophies of the library are crucial to efficiently scale \u{1F917}
Transformers while keeping maintenance costs at a reasonable level.`),hh=h(),dt=a("p"),Qu=r("A good first starting point to better understand the library is to read the "),Kr=a("a"),Vu=r("documentation of our philosophy"),Zu=r(". As a result of our way of working, there are some choices that we try to apply to all models:"),fh=h(),ve=a("ul"),Ja=a("li"),ec=r("Composition is generally favored over-abstraction"),tc=h(),Xa=a("li"),oc=r("Duplicating code is not always bad if it strongly improves the readability or accessibility of a model"),rc=h(),vo=a("li"),nc=r(`Model files are as self-contained as possible so that when you read the code of a specific model, you ideally only
have to look into the respective `),Ka=a("code"),ac=r("modeling_....py"),sc=r(" file."),mh=h(),ht=a("p"),ic=r("In our opinion, the library\u2019s code is not just a means to provide a product, "),Qa=a("em"),lc=r("e.g."),dc=r(` the ability to use BERT for
inference, but also as the very product that we want to improve. Hence, when adding a model, the user is not only the
person that will use your model, but also everybody that will read, try to understand, and possibly tweak your code.`),ph=h(),Qr=a("p"),hc=r("With this in mind, let\u2019s go a bit deeper into the general library design."),uh=h(),Se=a("h3"),ft=a("a"),Va=a("span"),p(bo.$$.fragment),fc=h(),Za=a("span"),mc=r("Overview of models"),ch=h(),J=a("p"),pc=r(`To successfully add a model, it is important to understand the interaction between your model and its config,
`),Vr=a("a"),uc=r("PreTrainedModel"),cc=r(", and "),Zr=a("a"),yc=r("PretrainedConfig"),gc=r(`. For exemplary purposes, we will
call the model to be added to \u{1F917} Transformers `),es=a("code"),wc=r("BrandNewBert"),vc=r("."),yh=h(),en=a("p"),bc=r("Let\u2019s take a look:"),gh=h(),tn=a("img"),wh=h(),v=a("p"),_c=r(`As you can see, we do make use of inheritance in \u{1F917} Transformers, but we keep the level of abstraction to an absolute
minimum. There are never more than two levels of abstraction for any model in the library. `),ts=a("code"),Ec=r("BrandNewBertModel"),kc=r(`
inherits from `),os=a("code"),Tc=r("BrandNewBertPreTrainedModel"),$c=r(" which in turn inherits from "),on=a("a"),Pc=r("PreTrainedModel"),Ic=r(` and
that\u2019s it. As a general rule, we want to make sure that a new model only depends on
`),rn=a("a"),Bc=r("PreTrainedModel"),Ac=r(`. The important functionalities that are automatically provided to every new
model are `),nn=a("a"),Nc=r("from_pretrained()"),Mc=r(` and
`),an=a("a"),jc=r("save_pretrained()"),xc=r(`, which are used for serialization and deserialization. All of the
other important functionalities, such as `),rs=a("code"),Oc=r("BrandNewBertModel.forward"),Cc=r(` should be completely defined in the new
`),ns=a("code"),Lc=r("modeling_brand_new_bert.py"),qc=r(` script. Next, we want to make sure that a model with a specific head layer, such as
`),as=a("code"),Rc=r("BrandNewBertForMaskedLM"),Sc=r(" does not inherit from "),ss=a("code"),Dc=r("BrandNewBertModel"),Fc=r(", but rather uses "),is=a("code"),Hc=r("BrandNewBertModel"),zc=r(`
as a component that can be called in its forward pass to keep the level of abstraction low. Every new model requires a
configuration class, called `),ls=a("code"),Wc=r("BrandNewBertConfig"),Gc=r(`. This configuration is always stored as an attribute in
`),sn=a("a"),Uc=r("PreTrainedModel"),Yc=r(", and thus can be accessed via the "),ds=a("code"),Jc=r("config"),Xc=r(` attribute for all classes
inheriting from `),hs=a("code"),Kc=r("BrandNewBertPreTrainedModel"),Qc=r(":"),vh=h(),p(_o.$$.fragment),bh=h(),N=a("p"),Vc=r(`Similar to the model, the configuration inherits basic serialization and deserialization functionalities from
`),ln=a("a"),Zc=r("PretrainedConfig"),ey=r(`. Note that the configuration and the model are always serialized into two
different formats - the model to a `),fs=a("em"),ty=r("pytorch_model.bin"),oy=r(" file and the configuration to a "),ms=a("em"),ry=r("config.json"),ny=r(` file. Calling
`),dn=a("a"),ay=r("save_pretrained()"),sy=r(` will automatically call
`),hn=a("a"),iy=r("save_pretrained()"),ly=r(", so that both model and configuration are saved."),_h=h(),De=a("h3"),mt=a("a"),ps=a("span"),p(Eo.$$.fragment),dy=h(),us=a("span"),hy=r("Code style"),Eh=h(),fn=a("p"),fy=r(`When coding your new model, keep in mind that Transformers is an opinionated library and we have a few quirks of our
own regarding how code should be written :-)`),kh=h(),q=a("ol"),Fe=a("li"),my=r(`The forward pass of your model should be fully written in the modeling file while being fully independent of other
models in the library. If you want to reuse a block from another model, copy the code and paste it with a
`),cs=a("code"),py=r("# Copied from"),uy=r(" comment on top (see "),ko=a("a"),cy=r("here"),yy=r(`
for a good example).`),gy=h(),He=a("li"),wy=r(`The code should be fully understandable, even by a non-native English speaker. This means you should pick
descriptive variable names and avoid abbreviations. As an example, `),ys=a("code"),vy=r("activation"),by=r(" is preferred to "),gs=a("code"),_y=r("act"),Ey=r(`.
One-letter variable names are strongly discouraged unless it\u2019s an index in a for loop.`),ky=h(),ws=a("li"),Ty=r("More generally we prefer longer explicit code to short magical one."),$y=h(),ze=a("li"),Py=r("Avoid subclassing "),vs=a("code"),Iy=r("nn.Sequential"),By=r(" in PyTorch but subclass "),bs=a("code"),Ay=r("nn.Module"),Ny=r(` and write the forward pass, so that anyone
using your code can quickly debug it by adding print statements or breaking points.`),My=h(),_s=a("li"),jy=r(`Your function signature should be type-annotated. For the rest, good variable names are way more readable and
understandable than type annotations.`),Th=h(),We=a("h3"),pt=a("a"),Es=a("span"),p(To.$$.fragment),xy=h(),ks=a("span"),Oy=r("Overview of tokenizers"),$h=h(),mn=a("p"),Cy=r("Not quite ready yet :-( This section will be added soon!"),Ph=h(),Ge=a("h2"),ut=a("a"),Ts=a("span"),p($o.$$.fragment),Ly=h(),$s=a("span"),qy=r("Step-by-step recipe to add a model to \u{1F917} Transformers"),Ih=h(),pn=a("p"),Ry=r(`Everyone has different preferences of how to port a model so it can be very helpful for you to take a look at summaries
of how other contributors ported models to Hugging Face. Here is a list of community blog posts on how to port a model:`),Bh=h(),ct=a("ol"),Po=a("li"),Io=a("a"),Sy=r("Porting GPT2 Model"),Dy=r(" by "),Bo=a("a"),Fy=r("Thomas"),Hy=h(),Ao=a("li"),No=a("a"),zy=r("Porting WMT19 MT Model"),Wy=r(" by "),Mo=a("a"),Gy=r("Stas"),Ah=h(),un=a("p"),Uy=r("From experience, we can tell you that the most important things to keep in mind when adding a model are:"),Nh=h(),be=a("ul"),ue=a("li"),Yy=r(`Don\u2019t reinvent the wheel! Most parts of the code you will add for the new \u{1F917} Transformers model already exist
somewhere in \u{1F917} Transformers. Take some time to find similar, already existing models and tokenizers you can copy
from. `),jo=a("a"),Jy=r("grep"),Xy=r(" and "),xo=a("a"),Ky=r("rg"),Qy=r(` are your
friends. Note that it might very well happen that your model\u2019s tokenizer is based on one model implementation, and
your model\u2019s modeling code on another one. `),Ps=a("em"),Vy=r("E.g."),Zy=r(` FSMT\u2019s modeling code is based on BART, while FSMT\u2019s tokenizer code
is based on XLM.`),eg=h(),Is=a("li"),tg=r(`It\u2019s more of an engineering challenge than a scientific challenge. You should spend more time on creating an
efficient debugging environment than trying to understand all theoretical aspects of the model in the paper.`),og=h(),Bs=a("li"),rg=r(`Ask for help, when you\u2019re stuck! Models are the core component of \u{1F917} Transformers so that we at Hugging Face are more
than happy to help you at every step to add your model. Don\u2019t hesitate to ask if you notice you are not making
progress.`),Mh=h(),cn=a("p"),ng=r("In the following, we try to give you a general recipe that we found most useful when porting a model to \u{1F917} Transformers."),jh=h(),yn=a("p"),ag=r(`The following list is a summary of everything that has to be done to add a model and can be used by you as a To-Do
List:`),xh=h(),b=a("p"),sg=r("\u2610 (Optional) Understood the model\u2019s theoretical aspects"),ig=a("br"),lg=r(`
\u2610 Prepared \u{1F917} Transformers dev environment`),dg=a("br"),hg=r(`
\u2610 Set up debugging environment of the original repository`),fg=a("br"),mg=r(`
\u2610 Created script that successfully runs the `),As=a("code"),pg=r("forward()"),ug=r(" pass using the original repository and checkpoint"),cg=a("br"),yg=r(`
\u2610 Successfully added the model skeleton to \u{1F917} Transformers`),gg=a("br"),wg=r(`
\u2610 Successfully converted original checkpoint to \u{1F917} Transformers checkpoint`),vg=a("br"),bg=r(`
\u2610 Successfully ran `),Ns=a("code"),_g=r("forward()"),Eg=r(" pass in \u{1F917} Transformers that gives identical output to original checkpoint"),kg=a("br"),Tg=r(`
\u2610 Finished model tests in \u{1F917} Transformers`),$g=a("br"),Pg=r(`
\u2610 Successfully added tokenizer in \u{1F917} Transformers`),Ig=a("br"),Bg=r(`
\u2610 Run end-to-end integration tests`),Ag=a("br"),Ng=r(`
\u2610 Finished docs`),Mg=a("br"),jg=r(`
\u2610 Uploaded model weights to the Hub`),xg=a("br"),Og=r(`
\u2610 Submitted the pull request`),Cg=a("br"),Lg=r(`
\u2610 (Optional) Added a demo notebook`),Oh=h(),R=a("p"),qg=r("To begin with, we usually recommend to start by getting a good theoretical understanding of "),Ms=a("code"),Rg=r("BrandNewBert"),Sg=r(`. However,
if you prefer to understand the theoretical aspects of the model `),js=a("em"),Dg=r("on-the-job"),Fg=r(`, then it is totally fine to directly dive
into the `),xs=a("code"),Hg=r("BrandNewBert"),zg=r(`\u2019s code-base. This option might suit you better, if your engineering skills are better than
your theoretical skill, if you have trouble understanding `),Os=a("code"),Wg=r("BrandNewBert"),Gg=r(`\u2019s paper, or if you just enjoy programming
much more than reading scientific papers.`),Ch=h(),Ue=a("h3"),yt=a("a"),Cs=a("span"),p(Oo.$$.fragment),Ug=h(),Ls=a("span"),Yg=r("1. (Optional) Theoretical aspects of BrandNewBert"),Lh=h(),gt=a("p"),Jg=r("You should take some time to read "),qs=a("em"),Xg=r("BrandNewBert\u2019s"),Kg=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. That being said, you don\u2019t have to spend too much time on the
theoretical aspects, but rather focus on the practical ones, namely:`),qh=h(),S=a("ul"),Ye=a("li"),Qg=r("What type of model is "),Rs=a("em"),Vg=r("brand_new_bert"),Zg=r(`? BERT-like encoder-only model? GPT2-like decoder-only model? BART-like
encoder-decoder model? Look at the `),gn=a("a"),ew=r("model_summary"),tw=r(" if you\u2019re not familiar with the differences between those."),ow=h(),Je=a("li"),rw=r("What are the applications of "),Ss=a("em"),nw=r("brand_new_bert"),aw=r("? Text classification? Text generation? Seq2Seq tasks, "),Ds=a("em"),sw=r("e.g.,"),iw=r(`
summarization?`),lw=h(),Fs=a("li"),dw=r("What is the novel feature of the model making it different from BERT/GPT-2/BART?"),hw=h(),Xe=a("li"),fw=r("Which of the already existing "),Co=a("a"),mw=r("\u{1F917} Transformers models"),pw=r(` is most
similar to `),Hs=a("em"),uw=r("brand_new_bert"),cw=r("?"),yw=h(),zs=a("li"),gw=r(`What type of tokenizer is used? A sentencepiece tokenizer? Word piece tokenizer? Is it the same tokenizer as used
for BERT or BART?`),Rh=h(),wn=a("p"),ww=r(`After you feel like you have gotten a good overview of the architecture of the model, you might want to write to the
Hugging Face team with any questions you might have. This might include questions regarding the model\u2019s architecture,
its attention layer, etc. We will be more than happy to help you.`),Sh=h(),Ke=a("h3"),wt=a("a"),Ws=a("span"),p(Lo.$$.fragment),vw=h(),Gs=a("span"),bw=r("2. Next prepare your environment"),Dh=h(),vt=a("ol"),Us=a("li"),qo=a("p"),_w=r("Fork the "),Ro=a("a"),Ew=r("repository"),kw=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.`),Tw=h(),Ys=a("li"),So=a("p"),$w=r("Clone your "),Js=a("code"),Pw=r("transformers"),Iw=r(" fork to your local disk, and add the base repository as a remote:"),Fh=h(),p(Do.$$.fragment),Hh=h(),Fo=a("ol"),Xs=a("li"),Bw=r("Set up a development environment, for instance by running the following command:"),zh=h(),p(Ho.$$.fragment),Wh=h(),vn=a("p"),Aw=r("and return to the parent directory"),Gh=h(),p(zo.$$.fragment),Uh=h(),Wo=a("ol"),Qe=a("li"),Nw=r("We recommend adding the PyTorch version of "),Ks=a("em"),Mw=r("brand_new_bert"),jw=r(` to Transformers. To install PyTorch, please follow the
instructions on `),Go=a("a"),xw=r("https://pytorch.org/get-started/locally/"),Ow=r("."),Yh=h(),Uo=a("p"),Qs=a("strong"),Cw=r("Note:"),Lw=r(" You don\u2019t need to have CUDA installed. Making the new model work on CPU is sufficient."),Jh=h(),Yo=a("ol"),Jo=a("li"),qw=r("To port "),Vs=a("em"),Rw=r("brand_new_bert"),Sw=r(", you will also need access to its original repository:"),Xh=h(),p(Xo.$$.fragment),Kh=h(),bt=a("p"),Dw=r("Now you have set up a development environment to port "),Zs=a("em"),Fw=r("brand_new_bert"),Hw=r(" to \u{1F917} Transformers."),Qh=h(),Ve=a("h3"),_t=a("a"),ei=a("span"),p(Ko.$$.fragment),zw=h(),ti=a("span"),Ww=r("3.-4. Run a pretrained checkpoint using the original repository"),Vh=h(),M=a("p"),Gw=r("At first, you will work on the original "),oi=a("em"),Uw=r("brand_new_bert"),Yw=r(` repository. Often, the original implementation is very
\u201Cresearchy\u201D. Meaning that documentation might be lacking and the code can be difficult to understand. But this should
be exactly your motivation to reimplement `),ri=a("em"),Jw=r("brand_new_bert"),Xw=r(". At Hugging Face, one of our main goals is to "),ni=a("em"),Kw=r(`make people
stand on the shoulders of giants`),Qw=r(` which translates here very well into taking a working model and rewriting it to make
it as `),ai=a("strong"),Vw=r("accessible, user-friendly, and beautiful"),Zw=r(` as possible. This is the number-one motivation to re-implement
models into \u{1F917} Transformers - trying to make complex new NLP technology accessible to `),si=a("strong"),ev=r("everybody"),tv=r("."),Zh=h(),bn=a("p"),ov=r("You should start thereby by diving into the original repository."),ef=h(),Et=a("p"),rv=r("Successfully running the official pretrained model in the original repository is often "),ii=a("strong"),nv=r("the most difficult"),av=r(` step.
From our experience, it is very important to spend some time getting familiar with the original code-base. You need to
figure out the following:`),tf=h(),j=a("ul"),li=a("li"),sv=r("Where to find the pretrained weights?"),iv=h(),di=a("li"),lv=r("How to load the pretrained weights into the corresponding model?"),dv=h(),hi=a("li"),hv=r("How to run the tokenizer independently from the model?"),fv=h(),fi=a("li"),mv=r(`Trace one forward pass so that you know which classes and functions are required for a simple forward pass. Usually,
you only have to reimplement those functions.`),pv=h(),W=a("li"),uv=r(`Be able to locate the important components of the model: Where is the model\u2019s class? Are there model sub-classes,
`),mi=a("em"),cv=r("e.g."),yv=r(` EncoderModel, DecoderModel? Where is the self-attention layer? Are there multiple different attention layers,
`),pi=a("em"),gv=r("e.g."),wv=h(),ui=a("em"),vv=r("self-attention"),bv=r(", "),ci=a("em"),_v=r("cross-attention"),Ev=r("\u2026?"),kv=h(),Ze=a("li"),Tv=r("How can you debug the model in the original environment of the repo? Do you have to add "),yi=a("em"),$v=r("print"),Pv=r(` statements, can you
work with an interactive debugger like `),gi=a("em"),Iv=r("ipdb"),Bv=r(", or should you use an efficient IDE to debug the model, like PyCharm?"),of=h(),kt=a("p"),Av=r("It is very important that before you start the porting process, that you can "),wi=a("strong"),Nv=r("efficiently"),Mv=r(` debug code in the original
repository! Also, remember that you are working with an open-source library, so do not hesitate to open an issue, or
even a pull request in the original repository. The maintainers of this repository are most likely very happy about
someone looking into their code!`),rf=h(),_n=a("p"),jv=r(`At this point, it is really up to you which debugging environment and strategy you prefer to use to debug the original
model. We strongly advise against setting up a costly GPU environment, but simply work on a CPU both when starting to
dive into the original repository and also when starting to write the \u{1F917} Transformers implementation of the model. Only
at the very end, when the model has already been successfully ported to \u{1F917} Transformers, one should verify that the
model also works as expected on GPU.`),nf=h(),En=a("p"),xv=r("In general, there are two possible debugging environments for running the original model"),af=h(),Tt=a("ul"),Qo=a("li"),Vo=a("a"),Ov=r("Jupyter notebooks"),Cv=r(" / "),Zo=a("a"),Lv=r("google colab"),qv=h(),vi=a("li"),Rv=r("Local python scripts."),sf=h(),kn=a("p"),Sv=r(`Jupyter notebooks have the advantage that they allow for cell-by-cell execution which can be helpful to better split
logical components from one another and to have faster debugging cycles as intermediate results can be stored. Also,
notebooks are often easier to share with other contributors, which might be very helpful if you want to ask the Hugging
Face team for help. If you are familiar with Jupiter notebooks, we strongly recommend you to work with them.`),lf=h(),$t=a("p"),Dv=r(`The obvious disadvantage of Jupyter notebooks is that if you are not used to working with them you will have to spend
some time adjusting to the new programming environment and that you might not be able to use your known debugging tools
anymore, like `),bi=a("code"),Fv=r("ipdb"),Hv=r("."),df=h(),Pt=a("p"),zv=r("For each code-base, a good first step is always to load a "),_i=a("strong"),Wv=r("small"),Gv=r(` pretrained checkpoint and to be able to reproduce a
single forward pass using a dummy integer vector of input IDs as an input. Such a script could look like this (in
pseudocode):`),hf=h(),p(er.$$.fragment),ff=h(),Tn=a("p"),Uv=r("Next, regarding the debugging strategy, there are generally a few from which to choose from:"),mf=h(),It=a("ul"),Ei=a("li"),Yv=r(`Decompose the original model into many small testable components and run a forward pass on each of those for
verification`),Jv=h(),et=a("li"),Xv=r("Decompose the original model only into the original "),ki=a("em"),Kv=r("tokenizer"),Qv=r(" and the original "),Ti=a("em"),Vv=r("model"),Zv=r(`, run a forward pass on
those, and use intermediate print statements or breakpoints for verification`),pf=h(),$n=a("p"),eb=r(`Again, it is up to you which strategy to choose. Often, one or the other is advantageous depending on the original code
base.`),uf=h(),Bt=a("p"),tb=r("If the original code-base allows you to decompose the model into smaller sub-components, "),$i=a("em"),ob=r("e.g."),rb=r(` if the original
code-base can easily be run in eager mode, it is usually worth the effort to do so. There are some important advantages
to taking the more difficult road in the beginning:`),cf=h(),X=a("ul"),Pi=a("li"),nb=r(`at a later stage when comparing the original model to the Hugging Face implementation, you can verify automatically
for each component individually that the corresponding component of the \u{1F917} Transformers implementation matches instead
of relying on visual comparison via print statements`),ab=h(),Ii=a("li"),sb=r(`it can give you some rope to decompose the big problem of porting a model into smaller problems of just porting
individual components and thus structure your work better`),ib=h(),Bi=a("li"),lb=r(`separating the model into logical meaningful components will help you to get a better overview of the model\u2019s design
and thus to better understand the model`),db=h(),Ai=a("li"),hb=r(`at a later stage those component-by-component tests help you to ensure that no regression occurs as you continue
changing your code`),yf=h(),tr=a("p"),or=a("a"),fb=r("Lysandre\u2019s"),mb=r(` integration checks for ELECTRA
gives a nice example of how this can be done.`),gf=h(),At=a("p"),pb=r(`However, if the original code-base is very complex or only allows intermediate components to be run in a compiled mode,
it might be too time-consuming or even impossible to separate the model into smaller testable sub-components. A good
example is `),rr=a("a"),ub=r("T5\u2019s MeshTensorFlow"),cb=r(` library which is
very complex and does not offer a simple way to decompose the model into its sub-components. For such libraries, one
often relies on verifying print statements.`),wf=h(),Pn=a("p"),yb=r(`No matter which strategy you choose, the recommended procedure is often the same in that you should start to debug the
starting layers first and the ending layers last.`),vf=h(),In=a("p"),gb=r(`It is recommended that you retrieve the output, either by print statements or sub-component functions, of the following
layers in the following order:`),bf=h(),x=a("ol"),Ni=a("li"),wb=r("Retrieve the input IDs passed to the model"),vb=h(),Mi=a("li"),bb=r("Retrieve the word embeddings"),_b=h(),ji=a("li"),Eb=r("Retrieve the input of the first Transformer layer"),kb=h(),xi=a("li"),Tb=r("Retrieve the output of the first Transformer layer"),$b=h(),Oi=a("li"),Pb=r("Retrieve the output of the following n - 1 Transformer layers"),Ib=h(),Ci=a("li"),Bb=r("Retrieve the output of the whole BrandNewBert Model"),_f=h(),tt=a("p"),Ab=r("Input IDs should thereby consists of an array of integers, "),Li=a("em"),Nb=r("e.g."),Mb=h(),qi=a("code"),jb=r("input_ids = [0, 4, 4, 3, 2, 4, 1, 7, 19]"),Ef=h(),Bn=a("p"),xb=r("The outputs of the following layers often consist of multi-dimensional float arrays and can look like this:"),kf=h(),p(nr.$$.fragment),Tf=h(),_e=a("p"),Ob=r(`We expect that every model added to \u{1F917} Transformers passes a couple of integration tests, meaning that the original
model and the reimplemented version in \u{1F917} Transformers have to give the exact same output up to a precision of 0.001!
Since it is normal that the exact same model written in different libraries can give a slightly different output
depending on the library framework, we accept an error tolerance of 1e-3 (0.001). It is not enough if the model gives
nearly the same output, they have to be the almost identical. Therefore, you will certainly compare the intermediate
outputs of the \u{1F917} Transformers version multiple times against the intermediate outputs of the original implementation of
`),Ri=a("em"),Cb=r("brand_new_bert"),Lb=r(" in which case an "),Si=a("strong"),qb=r("efficient"),Rb=r(` debugging environment of the original repository is absolutely
important. Here is some advice is to make your debugging environment as efficient as possible.`),$f=h(),D=a("ul"),G=a("li"),Sb=r(`Find the best way of debugging intermediate results. Is the original repository written in PyTorch? Then you should
probably take the time to write a longer script that decomposes the original model into smaller sub-components to
retrieve intermediate values. Is the original repository written in Tensorflow 1? Then you might have to rely on
TensorFlow print operations like `),ar=a("a"),Db=r("tf.print"),Fb=r(` to output
intermediate values. Is the original repository written in Jax? Then make sure that the model is `),Di=a("strong"),Hb=r("not jitted"),zb=r(` when
running the forward pass, `),Fi=a("em"),Wb=r("e.g."),Gb=r(" check-out "),sr=a("a"),Ub=r("this link"),Yb=r("."),Jb=h(),Hi=a("li"),Xb=r(`Use the smallest pretrained checkpoint you can find. The smaller the checkpoint, the faster your debug cycle
becomes. It is not efficient if your pretrained model is so big that your forward pass takes more than 10 seconds.
In case only very large checkpoints are available, it might make more sense to create a dummy model in the new
environment with randomly initialized weights and save those weights for comparison with the \u{1F917} Transformers version
of your model`),Kb=h(),$=a("li"),Qb=r(`Make sure you are using the easiest way of calling a forward pass in the original repository. Ideally, you want to
find the function in the original repository that `),zi=a("strong"),Vb=r("only"),Zb=r(" calls a single forward pass, "),Wi=a("em"),e_=r("i.e."),t_=r(` that is often called
`),Gi=a("code"),o_=r("predict"),r_=r(", "),Ui=a("code"),n_=r("evaluate"),a_=r(", "),Yi=a("code"),s_=r("forward"),i_=r(" or "),Ji=a("code"),l_=r("__call__"),d_=r(". You don\u2019t want to debug a function that calls "),Xi=a("code"),h_=r("forward"),f_=r(`
multiple times, `),Ki=a("em"),m_=r("e.g."),p_=r(" to generate text, like "),Qi=a("code"),u_=r("autoregressive_sample"),c_=r(", "),Vi=a("code"),y_=r("generate"),g_=r("."),w_=h(),ir=a("li"),v_=r("Try to separate the tokenization from the model\u2019s "),Zi=a("em"),b_=r("forward"),__=r(` pass. If the original repository shows examples where
you have to input a string, then try to find out where in the forward call the string input is changed to input ids
and start from this point. This might mean that you have to possibly write a small script yourself or change the
original code so that you can directly input the ids instead of an input string.`),E_=h(),ce=a("li"),k_=r("Make sure that the model in your debugging setup is "),el=a("strong"),T_=r("not"),$_=r(` in training mode, which often causes the model to yield
random outputs due to multiple dropout layers in the model. Make sure that the forward pass in your debugging
environment is `),tl=a("strong"),P_=r("deterministic"),I_=r(" so that the dropout layers are not used. Or use "),ol=a("em"),B_=r("transformers.utils.set_seed"),A_=r(`
if the old and new implementations are in the same framework.`),Pf=h(),Nt=a("p"),N_=r("The following section gives you more specific details/tips on how you can do this for "),rl=a("em"),M_=r("brand_new_bert"),j_=r("."),If=h(),ot=a("h3"),Mt=a("a"),nl=a("span"),p(lr.$$.fragment),x_=h(),al=a("span"),O_=r("5.-14. Port BrandNewBert to \u{1F917} Transformers"),Bf=h(),An=a("p"),C_=r("Next, you can finally start adding new code to \u{1F917} Transformers. Go into the clone of your \u{1F917} Transformers\u2019 fork:"),Af=h(),p(dr.$$.fragment),Nf=h(),jt=a("p"),L_=r(`In the special case that you are adding a model whose architecture exactly matches the model architecture of an
existing model you only have to add a conversion script as described in `),Nn=a("a"),q_=r("this section"),R_=r(`.
In this case, you can just re-use the whole model architecture of the already existing model.`),Mf=h(),Mn=a("p"),S_=r("Otherwise, let\u2019s start generating a new model. You have two choices here:"),jf=h(),xt=a("ul"),jn=a("li"),sl=a("code"),D_=r("transformers-cli add-new-model-like"),F_=r(" to add a new model like an existing one"),H_=h(),xn=a("li"),il=a("code"),z_=r("transformers-cli add-new-model"),W_=r(" to add a new model from our template (will look like BERT or Bart depending on the type of model you select)"),xf=h(),Ee=a("p"),G_=r("In both cases, you will be prompted with a questionnaire to fill the basic information of your model. The second command requires to install "),ll=a("code"),U_=r("cookiecutter"),Y_=r(", you can find more information on it "),hr=a("a"),J_=r("here"),X_=r("."),Of=h(),On=a("p"),dl=a("strong"),K_=r("Open a Pull Request on the main huggingface/transformers repo"),Cf=h(),ke=a("p"),Q_=r(`Before starting to adapt the automatically generated code, now is the time to open a \u201CWork in progress (WIP)\u201D pull
request, `),hl=a("em"),V_=r("e.g."),Z_=r(" \u201C[WIP] Add "),fl=a("em"),e1=r("brand_new_bert"),t1=r(`\u201D, in \u{1F917} Transformers so that you and the Hugging Face team can work
side-by-side on integrating the model into \u{1F917} Transformers.`),Lf=h(),Cn=a("p"),o1=r("You should do the following:"),qf=h(),Ln=a("ol"),ml=a("li"),r1=r("Create a branch with a descriptive name from your main branch"),Rf=h(),p(fr.$$.fragment),Sf=h(),mr=a("ol"),pl=a("li"),n1=r("Commit the automatically generated code:"),Df=h(),p(pr.$$.fragment),Ff=h(),ur=a("ol"),ul=a("li"),a1=r("Fetch and rebase to current main"),Hf=h(),p(cr.$$.fragment),zf=h(),yr=a("ol"),cl=a("li"),s1=r("Push the changes to your account using:"),Wf=h(),p(gr.$$.fragment),Gf=h(),rt=a("ol"),yl=a("li"),gl=a("p"),i1=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.`),l1=h(),wl=a("li"),vl=a("p"),d1=r("Change the PR into a draft by clicking on \u201CConvert to draft\u201D on the right of the GitHub pull request web page."),Uf=h(),qn=a("p"),h1=r(`In the following, whenever you have done some progress, don\u2019t forget to commit your work and push it to your account so
that it shows in the pull request. Additionally, you should make sure to update your work with the current main from
time to time by doing:`),Yf=h(),p(wr.$$.fragment),Jf=h(),Rn=a("p"),f1=r(`In general, all questions you might have regarding the model or your implementation should be asked in your PR and
discussed/solved in the PR. This way, the Hugging Face team will always be notified when you are committing new code or
if you have a question. It is often very helpful to point the Hugging Face team to your added code so that the Hugging
Face team can efficiently understand your problem or question.`),Xf=h(),Sn=a("p"),m1=r(`To do so, you can go to the \u201CFiles changed\u201D tab where you see all of your changes, go to a line regarding which you
want to ask a question, and click on the \u201C+\u201D symbol to add a comment. Whenever a question or problem has been solved,
you can click on the \u201CResolve\u201D button of the created comment.`),Kf=h(),Dn=a("p"),p1=r(`In the same way, the Hugging Face team will open comments when reviewing your code. We recommend asking most questions
on GitHub on your PR. For some very general questions that are not very useful for the public, feel free to ping the
Hugging Face team by Slack or email.`),Qf=h(),Fn=a("p"),bl=a("strong"),u1=r("5. Adapt the generated models code for brand_new_bert"),Vf=h(),Te=a("p"),c1=r(`At first, we will focus only on the model itself and not care about the tokenizer. All the relevant code should be
found in the generated files `),_l=a("code"),y1=r("src/transformers/models/brand_new_bert/modeling_brand_new_bert.py"),g1=r(` and
`),El=a("code"),w1=r("src/transformers/models/brand_new_bert/configuration_brand_new_bert.py"),v1=r("."),Zf=h(),K=a("p"),b1=r(`Now you can finally start coding :). The generated code in
`),kl=a("code"),_1=r("src/transformers/models/brand_new_bert/modeling_brand_new_bert.py"),E1=r(` will either have the same architecture as BERT if
it\u2019s an encoder-only model or BART if it\u2019s an encoder-decoder model. At this point, you should remind yourself what
you\u2019ve learned in the beginning about the theoretical aspects of the model: `),Tl=a("em"),k1=r(`How is the model different from BERT or
BART?`),T1=r("\u201D. Implement those changes which often means to change the "),$l=a("em"),$1=r("self-attention"),P1=r(` layer, the order of the normalization
layer, etc\u2026 Again, it is often useful to look at the similar architecture of already existing models in Transformers to
get a better feeling of how your model should be implemented.`),em=h(),O=a("p"),Pl=a("strong"),I1=r("Note"),B1=r(` that at this point, you don\u2019t have to be very sure that your code is fully correct or clean. Rather, it is
advised to add a first `),Il=a("em"),A1=r("unclean"),N1=r(`, copy-pasted version of the original code to
`),Bl=a("code"),M1=r("src/transformers/models/brand_new_bert/modeling_brand_new_bert.py"),j1=r(` until you feel like all the necessary code is
added. From our experience, it is much more efficient to quickly add a first version of the required code and
improve/correct the code iteratively with the conversion script as described in the next section. The only thing that
has to work at this point is that you can instantiate the \u{1F917} Transformers implementation of `),Al=a("em"),x1=r("brand_new_bert"),O1=r(", "),Nl=a("em"),C1=r("i.e."),L1=r(` the
following command should work:`),tm=h(),p(vr.$$.fragment),om=h(),$e=a("p"),q1=r("The above command will create a model according to the default parameters as defined in "),Ml=a("code"),R1=r("BrandNewBertConfig()"),S1=r(` with
random weights, thus making sure that the `),jl=a("code"),D1=r("init()"),F1=r(" methods of all components works."),rm=h(),Hn=a("p"),xl=a("strong"),H1=r("6. Write a conversion script"),nm=h(),Q=a("p"),z1=r("Next, you should write a conversion script that lets you convert the checkpoint you used to debug "),Ol=a("em"),W1=r("brand_new_bert"),G1=r(` in
the original repository to a checkpoint compatible with your just created \u{1F917} Transformers implementation of
`),Cl=a("em"),U1=r("brand_new_bert"),Y1=r(`. It is not advised to write the conversion script from scratch, but rather to look through already
existing conversion scripts in \u{1F917} Transformers for one that has been used to convert a similar model that was written in
the same framework as `),Ll=a("em"),J1=r("brand_new_bert"),X1=r(`. Usually, it is enough to copy an already existing conversion script and
slightly adapt it for your use case. Don\u2019t hesitate to ask the Hugging Face team to point you to a similar already
existing conversion script for your model.`),am=h(),Ot=a("ul"),zn=a("li"),K1=r("If you are porting a model from TensorFlow to PyTorch, a good starting point might be BERT\u2019s conversion script "),br=a("a"),Q1=r("here"),V1=h(),Wn=a("li"),Z1=r("If you are porting a model from PyTorch to PyTorch, a good starting point might be BART\u2019s conversion script "),_r=a("a"),e0=r("here"),sm=h(),Ct=a("p"),t0=r(`In the following, we\u2019ll quickly explain how PyTorch models store layer weights and define layer names. In PyTorch, the
name of a layer is defined by the name of the class attribute you give the layer. Let\u2019s define a dummy model in
PyTorch, called `),ql=a("code"),o0=r("SimpleModel"),r0=r(" as follows:"),im=h(),p(Er.$$.fragment),lm=h(),V=a("p"),n0=r("Now we can create an instance of this model definition which will fill all weights: "),Rl=a("code"),a0=r("dense"),s0=r(", "),Sl=a("code"),i0=r("intermediate"),l0=r(`,
`),Dl=a("code"),d0=r("layer_norm"),h0=r(" with random weights. We can print the model to see its architecture"),dm=h(),p(kr.$$.fragment),hm=h(),Gn=a("p"),f0=r("This will print out the following:"),fm=h(),p(Tr.$$.fragment),mm=h(),Un=a("p"),m0=r(`We can see that the layer names are defined by the name of the class attribute in PyTorch. You can print out the weight
values of a specific layer:`),pm=h(),p($r.$$.fragment),um=h(),Yn=a("p"),p0=r("to see that the weights were randomly initialized"),cm=h(),p(Pr.$$.fragment),ym=h(),Ir=a("p"),u0=r(`In the conversion script, you should fill those randomly initialized weights with the exact weights of the
corresponding layer in the checkpoint. `),Fl=a("em"),c0=r("E.g."),gm=h(),p(Br.$$.fragment),wm=h(),Pe=a("p"),y0=r(`While doing so, you must verify that each randomly initialized weight of your PyTorch model and its corresponding
pretrained checkpoint weight exactly match in both `),Hl=a("strong"),g0=r("shape and name"),w0=r(". To do so, it is "),zl=a("strong"),v0=r("necessary"),b0=r(` to add assert
statements for the shape and print out the names of the checkpoints weights. E.g. you should add statements like:`),vm=h(),p(Ar.$$.fragment),bm=h(),Nr=a("p"),_0=r("Besides, you should also print out the names of both weights to make sure they match, "),Wl=a("em"),E0=r("e.g."),_m=h(),p(Mr.$$.fragment),Em=h(),Jn=a("p"),k0=r(`If either the shape or the name doesn\u2019t match, you probably assigned the wrong checkpoint weight to a randomly
initialized layer of the \u{1F917} Transformers implementation.`),km=h(),Lt=a("p"),T0=r("An incorrect shape is most likely due to an incorrect setting of the config parameters in "),Gl=a("code"),$0=r("BrandNewBertConfig()"),P0=r(` that
do not exactly match those that were used for the checkpoint you want to convert. However, it could also be that
PyTorch\u2019s implementation of a layer requires the weight to be transposed beforehand.`),Tm=h(),Z=a("p"),I0=r("Finally, you should also check that "),Ul=a("strong"),B0=r("all"),A0=r(` required weights are initialized and print out all checkpoint weights that
were not used for initialization to make sure the model is correctly converted. It is completely normal, that the
conversion trials fail with either a wrong shape statement or wrong name assignment. This is most likely because either
you used incorrect parameters in `),Yl=a("code"),N0=r("BrandNewBertConfig()"),M0=r(`, have a wrong architecture in the \u{1F917} Transformers
implementation, you have a bug in the `),Jl=a("code"),j0=r("init()"),x0=r(` functions of one of the components of the \u{1F917} Transformers
implementation or you need to transpose one of the checkpoint weights.`),$m=h(),ee=a("p"),O0=r(`This step should be iterated with the previous step until all weights of the checkpoint are correctly loaded in the
Transformers model. Having correctly loaded the checkpoint into the \u{1F917} Transformers implementation, you can then save
the model under a folder of your choice `),Xl=a("code"),C0=r("/path/to/converted/checkpoint/folder"),L0=r(` that should then contain both a
`),Kl=a("code"),q0=r("pytorch_model.bin"),R0=r(" file and a "),Ql=a("code"),S0=r("config.json"),D0=r(" file:"),Pm=h(),p(jr.$$.fragment),Im=h(),Xn=a("p"),Vl=a("strong"),F0=r("7. Implement the forward pass"),Bm=h(),qt=a("p"),H0=r(`Having managed to correctly load the pretrained weights into the \u{1F917} Transformers implementation, you should now make
sure that the forward pass is correctly implemented. In `),Kn=a("a"),z0=r("Get familiar with the original repository"),W0=r(`, you have already created a script that runs a forward
pass of the model using the original repository. Now you should write an analogous script using the \u{1F917} Transformers
implementation instead of the original one. It should look as follows:`),Am=h(),p(xr.$$.fragment),Nm=h(),F=a("p"),G0=r(`It is very likely that the \u{1F917} Transformers implementation and the original model implementation don\u2019t give the exact
same output the very first time or that the forward pass throws an error. Don\u2019t be disappointed - it\u2019s expected! First,
you should make sure that the forward pass doesn\u2019t throw any errors. It often happens that the wrong dimensions are
used leading to a `),Zl=a("em"),U0=r("Dimensionality mismatch"),Y0=r(" error or that the wrong data type object is used, "),ed=a("em"),J0=r("e.g."),X0=h(),td=a("code"),K0=r("torch.long"),Q0=r(`
instead of `),od=a("code"),V0=r("torch.float32"),Z0=r(`. Don\u2019t hesitate to ask the Hugging Face team for help, if you don\u2019t manage to solve
certain errors.`),Mm=h(),te=a("p"),e2=r(`The final part to make sure the \u{1F917} Transformers implementation works correctly is to ensure that the outputs are
equivalent to a precision of `),rd=a("code"),t2=r("1e-3"),o2=r(". First, you should ensure that the output shapes are identical, "),nd=a("em"),r2=r("i.e."),n2=h(),ad=a("code"),a2=r("outputs.shape"),s2=r(` should yield the same value for the script of the \u{1F917} Transformers implementation and the original
implementation. Next, you should make sure that the output values are identical as well. This one of the most difficult
parts of adding a new model. Common mistakes why the outputs are not identical are:`),jm=h(),oe=a("ul"),nt=a("li"),i2=r("Some layers were not added, "),sd=a("em"),l2=r("i.e."),d2=r(" an "),id=a("em"),h2=r("activation"),f2=r(" layer was not added, or the residual connection was forgotten"),m2=h(),ld=a("li"),p2=r("The word embedding matrix was not tied"),u2=h(),dd=a("li"),c2=r("The wrong positional embeddings are used because the original implementation uses on offset"),y2=h(),re=a("li"),g2=r("Dropout is applied during the forward pass. To fix this make sure "),hd=a("em"),w2=r("model.training is False"),v2=r(` and that no dropout
layer is falsely activated during the forward pass, `),fd=a("em"),b2=r("i.e."),_2=r(" pass "),md=a("em"),E2=r("self.training"),k2=r(" to "),Or=a("a"),T2=r("PyTorch\u2019s functional dropout"),xm=h(),Ie=a("p"),$2=r(`The best way to fix the problem is usually to look at the forward pass of the original implementation and the \u{1F917}
Transformers implementation side-by-side and check if there are any differences. Ideally, you should debug/print out
intermediate outputs of both implementations of the forward pass to find the exact position in the network where the \u{1F917}
Transformers implementation shows a different output than the original implementation. First, make sure that the
hard-coded `),pd=a("code"),P2=r("input_ids"),I2=r(` in both scripts are identical. Next, verify that the outputs of the first transformation of
the `),ud=a("code"),B2=r("input_ids"),A2=r(` (usually the word embeddings) are identical. And then work your way up to the very last layer of the
network. At some point, you will notice a difference between the two implementations, which should point you to the bug
in the \u{1F917} Transformers implementation. From our experience, a simple and efficient way is to add many print statements
in both the original implementation and \u{1F917} Transformers implementation, at the same positions in the network
respectively, and to successively remove print statements showing the same values for intermediate presentations.`),Om=h(),Rt=a("p"),N2=r(`When you\u2019re confident that both implementations yield the same output, verifying the outputs with
`),cd=a("code"),M2=r("torch.allclose(original_output, output, atol=1e-3)"),j2=r(`, you\u2019re done with the most difficult part! Congratulations - the
work left to be done should be a cakewalk \u{1F60A}.`),Cm=h(),Qn=a("p"),yd=a("strong"),x2=r("8. Adding all necessary model tests"),Lm=h(),St=a("p"),O2=r(`At this point, you have successfully added a new model. However, it is very much possible that the model does not yet
fully comply with the required design. To make sure, the implementation is fully compatible with \u{1F917} Transformers, all
common tests should pass. The Cookiecutter should have automatically added a test file for your model, probably under
the same `),gd=a("code"),C2=r("tests/models/brand_new_bert/test_modeling_brand_new_bert.py"),L2=r(`. Run this test file to verify that all common
tests pass:`),qm=h(),p(Cr.$$.fragment),Rm=h(),Vn=a("p"),q2=r("Having fixed all common tests, it is now crucial to ensure that all the nice work you have done is well tested, so that"),Sm=h(),Dt=a("ul"),Zn=a("li"),R2=r("a) The community can easily understand your work by looking at specific tests of "),wd=a("em"),S2=r("brand_new_bert"),D2=h(),vd=a("li"),F2=r("b) Future changes to your model will not break any important feature of the model."),Dm=h(),Ft=a("p"),H2=r(`At first, integration tests should be added. Those integration tests essentially do the same as the debugging scripts
you used earlier to implement the model to \u{1F917} Transformers. A template of those model tests is already added by the
Cookiecutter, called `),bd=a("code"),z2=r("BrandNewBertModelIntegrationTests"),W2=r(` and only has to be filled out by you. To ensure that those
tests are passing, run`),Fm=h(),p(Lr.$$.fragment),Hm=h(),p(Ht.$$.fragment),zm=h(),ne=a("p"),G2=r("Second, all features that are special to "),_d=a("em"),U2=r("brand_new_bert"),Y2=r(` should be tested additionally in a separate test under
`),Ed=a("code"),J2=r("BrandNewBertModelTester"),X2=r("/`"),kd=a("code"),K2=r("BrandNewBertModelTest"),Q2=r(`. This part is often forgotten but is extremely useful in two
ways:`),Wm=h(),zt=a("ul"),qr=a("li"),V2=r(`It helps to transfer the knowledge you have acquired during the model addition to the community by showing how the
special features of `),Td=a("em"),Z2=r("brand_new_bert"),eE=r(" should work."),tE=h(),$d=a("li"),oE=r("Future contributors can quickly test changes to the model by running those special tests."),Gm=h(),ea=a("p"),Pd=a("strong"),rE=r("9. Implement the tokenizer"),Um=h(),Wt=a("p"),nE=r("Next, we should add the tokenizer of "),Id=a("em"),aE=r("brand_new_bert"),sE=r(`. Usually, the tokenizer is equivalent or very similar to an
already existing tokenizer of \u{1F917} Transformers.`),Ym=h(),ta=a("p"),iE=r(`It is very important to find/extract the original tokenizer file and to manage to load this file into the \u{1F917}
Transformers\u2019 implementation of the tokenizer.`),Jm=h(),oa=a("p"),lE=r("To ensure that the tokenizer works correctly, it is recommended to first create a script in the original repository\nthat inputs a string and returns the `input_ids\u201C. It could look similar to this (in pseudo-code):"),Xm=h(),p(Rr.$$.fragment),Km=h(),Gt=a("p"),dE=r(`You might have to take a deeper look again into the original repository to find the correct tokenizer function or you
might even have to do changes to your clone of the original repository to only output the `),Bd=a("code"),hE=r("input_ids"),fE=r(`. Having written
a functional tokenization script that uses the original repository, an analogous script for \u{1F917} Transformers should be
created. It should look similar to this:`),Qm=h(),p(Sr.$$.fragment),Vm=h(),Ut=a("p"),mE=r("When both "),Ad=a("code"),pE=r("input_ids"),uE=r(" yield the same values, as a final step a tokenizer test file should also be added."),Zm=h(),Be=a("p"),cE=r("Analogous to the modeling test files of "),Nd=a("em"),yE=r("brand_new_bert"),gE=r(", the tokenization test files of "),Md=a("em"),wE=r("brand_new_bert"),vE=r(` should
contain a couple of hard-coded integration tests.`),ep=h(),ra=a("p"),jd=a("strong"),bE=r("10. Run End-to-end integration tests"),tp=h(),ae=a("p"),_E=r(`Having added the tokenizer, you should also add a couple of end-to-end integration tests using both the model and the
tokenizer to `),xd=a("code"),EE=r("tests/models/brand_new_bert/test_modeling_brand_new_bert.py"),kE=r(` in \u{1F917} Transformers.
Such a test should show on a meaningful
text-to-text sample that the \u{1F917} Transformers implementation works as expected. A meaningful text-to-text sample can
include `),Od=a("em"),TE=r("e.g."),$E=r(` a source-to-target-translation pair, an article-to-summary pair, a question-to-answer pair, etc\u2026 If none
of the ported checkpoints has been fine-tuned on a downstream task it is enough to simply rely on the model tests. In a
final step to ensure that the model is fully functional, it is advised that you also run all tests on GPU. It can
happen that you forgot to add some `),Cd=a("code"),PE=r(".to(self.device)"),IE=r(` statements to internal tensors of the model, which in such a
test would show in an error. In case you have no access to a GPU, the Hugging Face team can take care of running those
tests for you.`),op=h(),na=a("p"),Ld=a("strong"),BE=r("11. Add Docstring"),rp=h(),se=a("p"),AE=r("Now, all the necessary functionality for "),qd=a("em"),NE=r("brand_new_bert"),ME=r(` is added - you\u2019re almost done! The only thing left to add is
a nice docstring and a doc page. The Cookiecutter should have added a template file called
`),Rd=a("code"),jE=r("docs/source/model_doc/brand_new_bert.mdx"),xE=r(` that you should fill out. Users of your model will usually first look at
this page before using your model. Hence, the documentation must be understandable and concise. It is very useful for
the community to add some `),Sd=a("em"),OE=r("Tips"),CE=r(` to show how the model should be used. Don\u2019t hesitate to ping the Hugging Face team
regarding the docstrings.`),np=h(),Ae=a("p"),LE=r("Next, make sure that the docstring added to "),Dd=a("code"),qE=r("src/transformers/models/brand_new_bert/modeling_brand_new_bert.py"),RE=r(` is
correct and included all necessary inputs and outputs. We have a detailed guide about writing documentation and our docstring format `),aa=a("a"),SE=r("here"),DE=r(`. It is always to good to remind oneself that documentation should
be treated at least as carefully as the code in \u{1F917} Transformers since the documentation is usually the first contact
point of the community with the model.`),ap=h(),sa=a("p"),Fd=a("strong"),FE=r("Code refactor"),sp=h(),Yt=a("p"),HE=r("Great, now you have added all the necessary code for "),Hd=a("em"),zE=r("brand_new_bert"),WE=r(`. At this point, you should correct some potential
incorrect code style by running:`),ip=h(),p(Dr.$$.fragment),lp=h(),ia=a("p"),GE=r("and verify that your coding style passes the quality check:"),dp=h(),p(Fr.$$.fragment),hp=h(),la=a("p"),UE=r(`There are a couple of other very strict design tests in \u{1F917} Transformers that might still be failing, which shows up in
the tests of your pull request. This is often because of some missing information in the docstring or some incorrect
naming. The Hugging Face team will surely help you if you\u2019re stuck here.`),fp=h(),da=a("p"),YE=r(`Lastly, it is always a good idea to refactor one\u2019s code after having ensured that the code works correctly. With all
tests passing, now it\u2019s a good time to go over the added code again and do some refactoring.`),mp=h(),ha=a("p"),JE=r("You have now finished the coding part, congratulation! \u{1F389} You are Awesome! \u{1F60E}"),pp=h(),fa=a("p"),zd=a("strong"),XE=r("12. Upload the models to the model hub"),up=h(),H=a("p"),KE=r(`In this final part, you should convert and upload all checkpoints to the model hub and add a model card for each
uploaded model checkpoint. You can get familiar with the hub functionalities by reading our `),ma=a("a"),QE=r("Model sharing and uploading Page"),VE=r(`. You should work alongside the Hugging Face team here to decide on a fitting name for each
checkpoint and to get the required access rights to be able to upload the model under the author\u2019s organization of
`),Wd=a("em"),ZE=r("brand_new_bert"),ek=r(". The "),Gd=a("code"),tk=r("push_to_hub"),ok=r(" method, present in all models in "),Ud=a("code"),rk=r("transformers"),nk=r(", is a quick and efficient way to push your checkpoint to the hub. A little snippet is pasted below:"),cp=h(),p(Hr.$$.fragment),yp=h(),Jt=a("p"),ak=r(`It is worth spending some time to create fitting model cards for each checkpoint. The model cards should highlight the
specific characteristics of this particular checkpoint, `),Yd=a("em"),sk=r("e.g."),ik=r(` On which dataset was the checkpoint
pretrained/fine-tuned on? On what down-stream task should the model be used? And also include some code on how to
correctly use the model.`),gp=h(),pa=a("p"),Jd=a("strong"),lk=r("13. (Optional) Add notebook"),wp=h(),Xt=a("p"),dk=r("It is very helpful to add a notebook that showcases in-detail how "),Xd=a("em"),hk=r("brand_new_bert"),fk=r(` can be used for inference and/or
fine-tuned on a downstream task. This is not mandatory to merge your PR, but very useful for the community.`),vp=h(),ua=a("p"),Kd=a("strong"),mk=r("14. Submit your finished PR"),bp=h(),ca=a("p"),pk=r(`You\u2019re done programming now and can move to the last step, which is getting your PR merged into main. Usually, the
Hugging Face team should have helped you already at this point, but it is worth taking some time to give your finished
PR a nice description and eventually add comments to your code, if you want to point out certain design choices to your
reviewer.`),_p=h(),at=a("h3"),Kt=a("a"),Qd=a("span"),p(zr.$$.fragment),uk=h(),Vd=a("span"),ck=r("Share your work!!"),Ep=h(),ya=a("p"),yk=r(`Now, it\u2019s time to get some credit from the community for your work! Having completed a model addition is a major
contribution to Transformers and the whole NLP community. Your code and the ported pre-trained models will certainly be
used by hundreds and possibly even thousands of developers and researchers. You should be proud of your work and share
your achievement with the community.`),kp=h(),ga=a("p"),Zd=a("strong"),gk=r("You have made another model that is super easy to access for everyone in the community! \u{1F92F}"),this.h()},l(e){const l=VT('[data-svelte="svelte-1phssyn"]',document.head);T=s(l,"META",{name:!0,content:!0}),l.forEach(o),U=f(e),P=s(e,"H1",{class:!0});var Wr=i(P);A=s(Wr,"A",{id:!0,class:!0,href:!0});var eh=i(A);z=s(eh,"SPAN",{});var Bk=i(z);u(B.$$.fragment,Bk),Bk.forEach(o),eh.forEach(o),C=f(Wr),L=s(Wr,"SPAN",{});var Ak=i(L);fe=n(Ak,"How to add a model to \u{1F917} Transformers?"),Ak.forEach(o),Wr.forEach(o),uo=f(e),me=s(e,"P",{});var $p=i(me);Tu=n($p,"The \u{1F917} Transformers library is often able to offer new models thanks to community contributors. But this can be a challenging project and requires an in-depth knowledge of the \u{1F917} Transformers library and the model to implement. At Hugging Face, we\u2019re trying to empower more of the community to actively add models and we\u2019ve put together this guide to walk you through the process of adding a PyTorch model (make sure you have "),co=s($p,"A",{href:!0,rel:!0});var Nk=i(co);$u=n(Nk,"PyTorch installed"),Nk.forEach(o),Pu=n($p,")."),$p.forEach(o),oh=f(e),u(it.$$.fragment,e),rh=f(e),Ur=s(e,"P",{});var Mk=i(Ur);Iu=n(Mk,"Along the way, you\u2019ll:"),Mk.forEach(o),nh=f(e),Y=s(e,"UL",{});var Qt=i(Y);Da=s(Qt,"LI",{});var jk=i(Da);Bu=n(jk,"get insights into open-source best practices"),jk.forEach(o),Au=f(Qt),Fa=s(Qt,"LI",{});var xk=i(Fa);Nu=n(xk,"understand the design principles behind one of the most popular deep learning libraries"),xk.forEach(o),Mu=f(Qt),Ha=s(Qt,"LI",{});var Ok=i(Ha);ju=n(Ok,"learn how to efficiently test large models"),Ok.forEach(o),xu=f(Qt),pe=s(Qt,"LI",{});var Vt=i(pe);Ou=n(Vt,"learn how to integrate Python utilities like "),za=s(Vt,"CODE",{});var Ck=i(za);Cu=n(Ck,"black"),Ck.forEach(o),Lu=n(Vt,", "),Wa=s(Vt,"CODE",{});var Lk=i(Wa);qu=n(Lk,"isort"),Lk.forEach(o),Ru=n(Vt,", and "),Ga=s(Vt,"CODE",{});var qk=i(Ga);Su=n(qk,"make fix-copies"),qk.forEach(o),Du=n(Vt," to ensure clean and readable code"),Vt.forEach(o),Qt.forEach(o),ah=f(e),Yr=s(e,"P",{});var Rk=i(Yr);Fu=n(Rk,"A Hugging Face team member will be available to help you along the way so you\u2019ll never be alone. \u{1F917} \u2764\uFE0F"),Rk.forEach(o),sh=f(e),we=s(e,"P",{});var wa=i(we);Hu=n(wa,"To get started, open a "),yo=s(wa,"A",{href:!0,rel:!0});var Sk=i(yo);zu=n(Sk,"New model addition"),Sk.forEach(o),Wu=n(wa," issue for the model you want to see in \u{1F917} Transformers. If you\u2019re not especially picky about contributing a specific model, you can filter by the "),go=s(wa,"A",{href:!0,rel:!0});var Dk=i(go);Gu=n(Dk,"New model label"),Dk.forEach(o),Uu=n(wa," to see if there are any unclaimed model requests and work on it."),wa.forEach(o),ih=f(e),Jr=s(e,"P",{});var Fk=i(Jr);Yu=n(Fk,"Once you\u2019ve opened a new model request, the first step is to get familiar with \u{1F917} Transformers if you aren\u2019t already!"),Fk.forEach(o),lh=f(e),Re=s(e,"H2",{class:!0});var Pp=i(Re);lt=s(Pp,"A",{id:!0,class:!0,href:!0});var Hk=i(lt);Ua=s(Hk,"SPAN",{});var zk=i(Ua);u(wo.$$.fragment,zk),zk.forEach(o),Hk.forEach(o),Ju=f(Pp),Ya=s(Pp,"SPAN",{});var Wk=i(Ya);Xu=n(Wk,"General overview of \u{1F917} Transformers"),Wk.forEach(o),Pp.forEach(o),dh=f(e),Xr=s(e,"P",{});var Gk=i(Xr);Ku=n(Gk,`First, you should get a general overview of \u{1F917} Transformers. \u{1F917} Transformers is a very opinionated library, so there is a
chance that you don\u2019t agree with some of the library\u2019s philosophies or design choices. From our experience, however, we
found that the fundamental design choices and philosophies of the library are crucial to efficiently scale \u{1F917}
Transformers while keeping maintenance costs at a reasonable level.`),Gk.forEach(o),hh=f(e),dt=s(e,"P",{});var Ip=i(dt);Qu=n(Ip,"A good first starting point to better understand the library is to read the "),Kr=s(Ip,"A",{href:!0});var Uk=i(Kr);Vu=n(Uk,"documentation of our philosophy"),Uk.forEach(o),Zu=n(Ip,". As a result of our way of working, there are some choices that we try to apply to all models:"),Ip.forEach(o),fh=f(e),ve=s(e,"UL",{});var va=i(ve);Ja=s(va,"LI",{});var Yk=i(Ja);ec=n(Yk,"Composition is generally favored over-abstraction"),Yk.forEach(o),tc=f(va),Xa=s(va,"LI",{});var Jk=i(Xa);oc=n(Jk,"Duplicating code is not always bad if it strongly improves the readability or accessibility of a model"),Jk.forEach(o),rc=f(va),vo=s(va,"LI",{});var Bp=i(vo);nc=n(Bp,`Model files are as self-contained as possible so that when you read the code of a specific model, you ideally only
have to look into the respective `),Ka=s(Bp,"CODE",{});var Xk=i(Ka);ac=n(Xk,"modeling_....py"),Xk.forEach(o),sc=n(Bp," file."),Bp.forEach(o),va.forEach(o),mh=f(e),ht=s(e,"P",{});var Ap=i(ht);ic=n(Ap,"In our opinion, the library\u2019s code is not just a means to provide a product, "),Qa=s(Ap,"EM",{});var Kk=i(Qa);lc=n(Kk,"e.g."),Kk.forEach(o),dc=n(Ap,` the ability to use BERT for
inference, but also as the very product that we want to improve. Hence, when adding a model, the user is not only the
person that will use your model, but also everybody that will read, try to understand, and possibly tweak your code.`),Ap.forEach(o),ph=f(e),Qr=s(e,"P",{});var Qk=i(Qr);hc=n(Qk,"With this in mind, let\u2019s go a bit deeper into the general library design."),Qk.forEach(o),uh=f(e),Se=s(e,"H3",{class:!0});var Np=i(Se);ft=s(Np,"A",{id:!0,class:!0,href:!0});var Vk=i(ft);Va=s(Vk,"SPAN",{});var Zk=i(Va);u(bo.$$.fragment,Zk),Zk.forEach(o),Vk.forEach(o),fc=f(Np),Za=s(Np,"SPAN",{});var e3=i(Za);mc=n(e3,"Overview of models"),e3.forEach(o),Np.forEach(o),ch=f(e),J=s(e,"P",{});var Zt=i(J);pc=n(Zt,`To successfully add a model, it is important to understand the interaction between your model and its config,
`),Vr=s(Zt,"A",{href:!0});var t3=i(Vr);uc=n(t3,"PreTrainedModel"),t3.forEach(o),cc=n(Zt,", and "),Zr=s(Zt,"A",{href:!0});var o3=i(Zr);yc=n(o3,"PretrainedConfig"),o3.forEach(o),gc=n(Zt,`. For exemplary purposes, we will
call the model to be added to \u{1F917} Transformers `),es=s(Zt,"CODE",{});var r3=i(es);wc=n(r3,"BrandNewBert"),r3.forEach(o),vc=n(Zt,"."),Zt.forEach(o),yh=f(e),en=s(e,"P",{});var n3=i(en);bc=n(n3,"Let\u2019s take a look:"),n3.forEach(o),gh=f(e),tn=s(e,"IMG",{src:!0}),wh=f(e),v=s(e,"P",{});var _=i(v);_c=n(_,`As you can see, we do make use of inheritance in \u{1F917} Transformers, but we keep the level of abstraction to an absolute
minimum. There are never more than two levels of abstraction for any model in the library. `),ts=s(_,"CODE",{});var a3=i(ts);Ec=n(a3,"BrandNewBertModel"),a3.forEach(o),kc=n(_,`
inherits from `),os=s(_,"CODE",{});var s3=i(os);Tc=n(s3,"BrandNewBertPreTrainedModel"),s3.forEach(o),$c=n(_," which in turn inherits from "),on=s(_,"A",{href:!0});var i3=i(on);Pc=n(i3,"PreTrainedModel"),i3.forEach(o),Ic=n(_,` and
that\u2019s it. As a general rule, we want to make sure that a new model only depends on
`),rn=s(_,"A",{href:!0});var l3=i(rn);Bc=n(l3,"PreTrainedModel"),l3.forEach(o),Ac=n(_,`. The important functionalities that are automatically provided to every new
model are `),nn=s(_,"A",{href:!0});var d3=i(nn);Nc=n(d3,"from_pretrained()"),d3.forEach(o),Mc=n(_,` and
`),an=s(_,"A",{href:!0});var h3=i(an);jc=n(h3,"save_pretrained()"),h3.forEach(o),xc=n(_,`, which are used for serialization and deserialization. All of the
other important functionalities, such as `),rs=s(_,"CODE",{});var f3=i(rs);Oc=n(f3,"BrandNewBertModel.forward"),f3.forEach(o),Cc=n(_,` should be completely defined in the new
`),ns=s(_,"CODE",{});var m3=i(ns);Lc=n(m3,"modeling_brand_new_bert.py"),m3.forEach(o),qc=n(_,` script. Next, we want to make sure that a model with a specific head layer, such as
`),as=s(_,"CODE",{});var p3=i(as);Rc=n(p3,"BrandNewBertForMaskedLM"),p3.forEach(o),Sc=n(_," does not inherit from "),ss=s(_,"CODE",{});var u3=i(ss);Dc=n(u3,"BrandNewBertModel"),u3.forEach(o),Fc=n(_,", but rather uses "),is=s(_,"CODE",{});var c3=i(is);Hc=n(c3,"BrandNewBertModel"),c3.forEach(o),zc=n(_,`
as a component that can be called in its forward pass to keep the level of abstraction low. Every new model requires a
configuration class, called `),ls=s(_,"CODE",{});var y3=i(ls);Wc=n(y3,"BrandNewBertConfig"),y3.forEach(o),Gc=n(_,`. This configuration is always stored as an attribute in
`),sn=s(_,"A",{href:!0});var g3=i(sn);Uc=n(g3,"PreTrainedModel"),g3.forEach(o),Yc=n(_,", and thus can be accessed via the "),ds=s(_,"CODE",{});var w3=i(ds);Jc=n(w3,"config"),w3.forEach(o),Xc=n(_,` attribute for all classes
inheriting from `),hs=s(_,"CODE",{});var v3=i(hs);Kc=n(v3,"BrandNewBertPreTrainedModel"),v3.forEach(o),Qc=n(_,":"),_.forEach(o),vh=f(e),u(_o.$$.fragment,e),bh=f(e),N=s(e,"P",{});var ie=i(N);Vc=n(ie,`Similar to the model, the configuration inherits basic serialization and deserialization functionalities from
`),ln=s(ie,"A",{href:!0});var b3=i(ln);Zc=n(b3,"PretrainedConfig"),b3.forEach(o),ey=n(ie,`. Note that the configuration and the model are always serialized into two
different formats - the model to a `),fs=s(ie,"EM",{});var _3=i(fs);ty=n(_3,"pytorch_model.bin"),_3.forEach(o),oy=n(ie," file and the configuration to a "),ms=s(ie,"EM",{});var E3=i(ms);ry=n(E3,"config.json"),E3.forEach(o),ny=n(ie,` file. Calling
`),dn=s(ie,"A",{href:!0});var k3=i(dn);ay=n(k3,"save_pretrained()"),k3.forEach(o),sy=n(ie,` will automatically call
`),hn=s(ie,"A",{href:!0});var T3=i(hn);iy=n(T3,"save_pretrained()"),T3.forEach(o),ly=n(ie,", so that both model and configuration are saved."),ie.forEach(o),_h=f(e),De=s(e,"H3",{class:!0});var Mp=i(De);mt=s(Mp,"A",{id:!0,class:!0,href:!0});var $3=i(mt);ps=s($3,"SPAN",{});var P3=i(ps);u(Eo.$$.fragment,P3),P3.forEach(o),$3.forEach(o),dy=f(Mp),us=s(Mp,"SPAN",{});var I3=i(us);hy=n(I3,"Code style"),I3.forEach(o),Mp.forEach(o),Eh=f(e),fn=s(e,"P",{});var B3=i(fn);fy=n(B3,`When coding your new model, keep in mind that Transformers is an opinionated library and we have a few quirks of our
own regarding how code should be written :-)`),B3.forEach(o),kh=f(e),q=s(e,"OL",{});var Ne=i(q);Fe=s(Ne,"LI",{});var ba=i(Fe);my=n(ba,`The forward pass of your model should be fully written in the modeling file while being fully independent of other
models in the library. If you want to reuse a block from another model, copy the code and paste it with a
`),cs=s(ba,"CODE",{});var A3=i(cs);py=n(A3,"# Copied from"),A3.forEach(o),uy=n(ba," comment on top (see "),ko=s(ba,"A",{href:!0,rel:!0});var N3=i(ko);cy=n(N3,"here"),N3.forEach(o),yy=n(ba,`
for a good example).`),ba.forEach(o),gy=f(Ne),He=s(Ne,"LI",{});var _a=i(He);wy=n(_a,`The code should be fully understandable, even by a non-native English speaker. This means you should pick
descriptive variable names and avoid abbreviations. As an example, `),ys=s(_a,"CODE",{});var M3=i(ys);vy=n(M3,"activation"),M3.forEach(o),by=n(_a," is preferred to "),gs=s(_a,"CODE",{});var j3=i(gs);_y=n(j3,"act"),j3.forEach(o),Ey=n(_a,`.
One-letter variable names are strongly discouraged unless it\u2019s an index in a for loop.`),_a.forEach(o),ky=f(Ne),ws=s(Ne,"LI",{});var x3=i(ws);Ty=n(x3,"More generally we prefer longer explicit code to short magical one."),x3.forEach(o),$y=f(Ne),ze=s(Ne,"LI",{});var Ea=i(ze);Py=n(Ea,"Avoid subclassing "),vs=s(Ea,"CODE",{});var O3=i(vs);Iy=n(O3,"nn.Sequential"),O3.forEach(o),By=n(Ea," in PyTorch but subclass "),bs=s(Ea,"CODE",{});var C3=i(bs);Ay=n(C3,"nn.Module"),C3.forEach(o),Ny=n(Ea,` and write the forward pass, so that anyone
using your code can quickly debug it by adding print statements or breaking points.`),Ea.forEach(o),My=f(Ne),_s=s(Ne,"LI",{});var L3=i(_s);jy=n(L3,`Your function signature should be type-annotated. For the rest, good variable names are way more readable and
understandable than type annotations.`),L3.forEach(o),Ne.forEach(o),Th=f(e),We=s(e,"H3",{class:!0});var jp=i(We);pt=s(jp,"A",{id:!0,class:!0,href:!0});var q3=i(pt);Es=s(q3,"SPAN",{});var R3=i(Es);u(To.$$.fragment,R3),R3.forEach(o),q3.forEach(o),xy=f(jp),ks=s(jp,"SPAN",{});var S3=i(ks);Oy=n(S3,"Overview of tokenizers"),S3.forEach(o),jp.forEach(o),$h=f(e),mn=s(e,"P",{});var D3=i(mn);Cy=n(D3,"Not quite ready yet :-( This section will be added soon!"),D3.forEach(o),Ph=f(e),Ge=s(e,"H2",{class:!0});var xp=i(Ge);ut=s(xp,"A",{id:!0,class:!0,href:!0});var F3=i(ut);Ts=s(F3,"SPAN",{});var H3=i(Ts);u($o.$$.fragment,H3),H3.forEach(o),F3.forEach(o),Ly=f(xp),$s=s(xp,"SPAN",{});var z3=i($s);qy=n(z3,"Step-by-step recipe to add a model to \u{1F917} Transformers"),z3.forEach(o),xp.forEach(o),Ih=f(e),pn=s(e,"P",{});var W3=i(pn);Ry=n(W3,`Everyone has different preferences of how to port a model so it can be very helpful for you to take a look at summaries
of how other contributors ported models to Hugging Face. Here is a list of community blog posts on how to port a model:`),W3.forEach(o),Bh=f(e),ct=s(e,"OL",{});var Op=i(ct);Po=s(Op,"LI",{});var Cp=i(Po);Io=s(Cp,"A",{href:!0,rel:!0});var G3=i(Io);Sy=n(G3,"Porting GPT2 Model"),G3.forEach(o),Dy=n(Cp," by "),Bo=s(Cp,"A",{href:!0,rel:!0});var U3=i(Bo);Fy=n(U3,"Thomas"),U3.forEach(o),Cp.forEach(o),Hy=f(Op),Ao=s(Op,"LI",{});var Lp=i(Ao);No=s(Lp,"A",{href:!0,rel:!0});var Y3=i(No);zy=n(Y3,"Porting WMT19 MT Model"),Y3.forEach(o),Wy=n(Lp," by "),Mo=s(Lp,"A",{href:!0,rel:!0});var J3=i(Mo);Gy=n(J3,"Stas"),J3.forEach(o),Lp.forEach(o),Op.forEach(o),Ah=f(e),un=s(e,"P",{});var X3=i(un);Uy=n(X3,"From experience, we can tell you that the most important things to keep in mind when adding a model are:"),X3.forEach(o),Nh=f(e),be=s(e,"UL",{});var ka=i(be);ue=s(ka,"LI",{});var eo=i(ue);Yy=n(eo,`Don\u2019t reinvent the wheel! Most parts of the code you will add for the new \u{1F917} Transformers model already exist
somewhere in \u{1F917} Transformers. Take some time to find similar, already existing models and tokenizers you can copy
from. `),jo=s(eo,"A",{href:!0,rel:!0});var K3=i(jo);Jy=n(K3,"grep"),K3.forEach(o),Xy=n(eo," and "),xo=s(eo,"A",{href:!0,rel:!0});var Q3=i(xo);Ky=n(Q3,"rg"),Q3.forEach(o),Qy=n(eo,` are your
friends. Note that it might very well happen that your model\u2019s tokenizer is based on one model implementation, and
your model\u2019s modeling code on another one. `),Ps=s(eo,"EM",{});var V3=i(Ps);Vy=n(V3,"E.g."),V3.forEach(o),Zy=n(eo,` FSMT\u2019s modeling code is based on BART, while FSMT\u2019s tokenizer code
is based on XLM.`),eo.forEach(o),eg=f(ka),Is=s(ka,"LI",{});var Z3=i(Is);tg=n(Z3,`It\u2019s more of an engineering challenge than a scientific challenge. You should spend more time on creating an
efficient debugging environment than trying to understand all theoretical aspects of the model in the paper.`),Z3.forEach(o),og=f(ka),Bs=s(ka,"LI",{});var e4=i(Bs);rg=n(e4,`Ask for help, when you\u2019re stuck! Models are the core component of \u{1F917} Transformers so that we at Hugging Face are more
than happy to help you at every step to add your model. Don\u2019t hesitate to ask if you notice you are not making
progress.`),e4.forEach(o),ka.forEach(o),Mh=f(e),cn=s(e,"P",{});var t4=i(cn);ng=n(t4,"In the following, we try to give you a general recipe that we found most useful when porting a model to \u{1F917} Transformers."),t4.forEach(o),jh=f(e),yn=s(e,"P",{});var o4=i(yn);ag=n(o4,`The following list is a summary of everything that has to be done to add a model and can be used by you as a To-Do
List:`),o4.forEach(o),xh=f(e),b=s(e,"P",{});var E=i(b);sg=n(E,"\u2610 (Optional) Understood the model\u2019s theoretical aspects"),ig=s(E,"BR",{}),lg=n(E,`
\u2610 Prepared \u{1F917} Transformers dev environment`),dg=s(E,"BR",{}),hg=n(E,`
\u2610 Set up debugging environment of the original repository`),fg=s(E,"BR",{}),mg=n(E,`
\u2610 Created script that successfully runs the `),As=s(E,"CODE",{});var r4=i(As);pg=n(r4,"forward()"),r4.forEach(o),ug=n(E," pass using the original repository and checkpoint"),cg=s(E,"BR",{}),yg=n(E,`
\u2610 Successfully added the model skeleton to \u{1F917} Transformers`),gg=s(E,"BR",{}),wg=n(E,`
\u2610 Successfully converted original checkpoint to \u{1F917} Transformers checkpoint`),vg=s(E,"BR",{}),bg=n(E,`
\u2610 Successfully ran `),Ns=s(E,"CODE",{});var n4=i(Ns);_g=n(n4,"forward()"),n4.forEach(o),Eg=n(E," pass in \u{1F917} Transformers that gives identical output to original checkpoint"),kg=s(E,"BR",{}),Tg=n(E,`
\u2610 Finished model tests in \u{1F917} Transformers`),$g=s(E,"BR",{}),Pg=n(E,`
\u2610 Successfully added tokenizer in \u{1F917} Transformers`),Ig=s(E,"BR",{}),Bg=n(E,`
\u2610 Run end-to-end integration tests`),Ag=s(E,"BR",{}),Ng=n(E,`
\u2610 Finished docs`),Mg=s(E,"BR",{}),jg=n(E,`
\u2610 Uploaded model weights to the Hub`),xg=s(E,"BR",{}),Og=n(E,`
\u2610 Submitted the pull request`),Cg=s(E,"BR",{}),Lg=n(E,`
\u2610 (Optional) Added a demo notebook`),E.forEach(o),Oh=f(e),R=s(e,"P",{});var Me=i(R);qg=n(Me,"To begin with, we usually recommend to start by getting a good theoretical understanding of "),Ms=s(Me,"CODE",{});var a4=i(Ms);Rg=n(a4,"BrandNewBert"),a4.forEach(o),Sg=n(Me,`. However,
if you prefer to understand the theoretical aspects of the model `),js=s(Me,"EM",{});var s4=i(js);Dg=n(s4,"on-the-job"),s4.forEach(o),Fg=n(Me,`, then it is totally fine to directly dive
into the `),xs=s(Me,"CODE",{});var i4=i(xs);Hg=n(i4,"BrandNewBert"),i4.forEach(o),zg=n(Me,`\u2019s code-base. This option might suit you better, if your engineering skills are better than
your theoretical skill, if you have trouble understanding `),Os=s(Me,"CODE",{});var l4=i(Os);Wg=n(l4,"BrandNewBert"),l4.forEach(o),Gg=n(Me,`\u2019s paper, or if you just enjoy programming
much more than reading scientific papers.`),Me.forEach(o),Ch=f(e),Ue=s(e,"H3",{class:!0});var qp=i(Ue);yt=s(qp,"A",{id:!0,class:!0,href:!0});var d4=i(yt);Cs=s(d4,"SPAN",{});var h4=i(Cs);u(Oo.$$.fragment,h4),h4.forEach(o),d4.forEach(o),Ug=f(qp),Ls=s(qp,"SPAN",{});var f4=i(Ls);Yg=n(f4,"1. (Optional) Theoretical aspects of BrandNewBert"),f4.forEach(o),qp.forEach(o),Lh=f(e),gt=s(e,"P",{});var Rp=i(gt);Jg=n(Rp,"You should take some time to read "),qs=s(Rp,"EM",{});var m4=i(qs);Xg=n(m4,"BrandNewBert\u2019s"),m4.forEach(o),Kg=n(Rp,` 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. That being said, you don\u2019t have to spend too much time on the
theoretical aspects, but rather focus on the practical ones, namely:`),Rp.forEach(o),qh=f(e),S=s(e,"UL",{});var je=i(S);Ye=s(je,"LI",{});var Ta=i(Ye);Qg=n(Ta,"What type of model is "),Rs=s(Ta,"EM",{});var p4=i(Rs);Vg=n(p4,"brand_new_bert"),p4.forEach(o),Zg=n(Ta,`? BERT-like encoder-only model? GPT2-like decoder-only model? BART-like
encoder-decoder model? Look at the `),gn=s(Ta,"A",{href:!0});var u4=i(gn);ew=n(u4,"model_summary"),u4.forEach(o),tw=n(Ta," if you\u2019re not familiar with the differences between those."),Ta.forEach(o),ow=f(je),Je=s(je,"LI",{});var $a=i(Je);rw=n($a,"What are the applications of "),Ss=s($a,"EM",{});var c4=i(Ss);nw=n(c4,"brand_new_bert"),c4.forEach(o),aw=n($a,"? Text classification? Text generation? Seq2Seq tasks, "),Ds=s($a,"EM",{});var y4=i(Ds);sw=n(y4,"e.g.,"),y4.forEach(o),iw=n($a,`
summarization?`),$a.forEach(o),lw=f(je),Fs=s(je,"LI",{});var g4=i(Fs);dw=n(g4,"What is the novel feature of the model making it different from BERT/GPT-2/BART?"),g4.forEach(o),hw=f(je),Xe=s(je,"LI",{});var Pa=i(Xe);fw=n(Pa,"Which of the already existing "),Co=s(Pa,"A",{href:!0,rel:!0});var w4=i(Co);mw=n(w4,"\u{1F917} Transformers models"),w4.forEach(o),pw=n(Pa,` is most
similar to `),Hs=s(Pa,"EM",{});var v4=i(Hs);uw=n(v4,"brand_new_bert"),v4.forEach(o),cw=n(Pa,"?"),Pa.forEach(o),yw=f(je),zs=s(je,"LI",{});var b4=i(zs);gw=n(b4,`What type of tokenizer is used? A sentencepiece tokenizer? Word piece tokenizer? Is it the same tokenizer as used
for BERT or BART?`),b4.forEach(o),je.forEach(o),Rh=f(e),wn=s(e,"P",{});var _4=i(wn);ww=n(_4,`After you feel like you have gotten a good overview of the architecture of the model, you might want to write to the
Hugging Face team with any questions you might have. This might include questions regarding the model\u2019s architecture,
its attention layer, etc. We will be more than happy to help you.`),_4.forEach(o),Sh=f(e),Ke=s(e,"H3",{class:!0});var Sp=i(Ke);wt=s(Sp,"A",{id:!0,class:!0,href:!0});var E4=i(wt);Ws=s(E4,"SPAN",{});var k4=i(Ws);u(Lo.$$.fragment,k4),k4.forEach(o),E4.forEach(o),vw=f(Sp),Gs=s(Sp,"SPAN",{});var T4=i(Gs);bw=n(T4,"2. Next prepare your environment"),T4.forEach(o),Sp.forEach(o),Dh=f(e),vt=s(e,"OL",{});var Dp=i(vt);Us=s(Dp,"LI",{});var $4=i(Us);qo=s($4,"P",{});var Fp=i(qo);_w=n(Fp,"Fork the "),Ro=s(Fp,"A",{href:!0,rel:!0});var P4=i(Ro);Ew=n(P4,"repository"),P4.forEach(o),kw=n(Fp,` by clicking on the \u2018Fork\u2019 button on the
repository\u2019s page. This creates a copy of the code under your GitHub user account.`),Fp.forEach(o),$4.forEach(o),Tw=f(Dp),Ys=s(Dp,"LI",{});var I4=i(Ys);So=s(I4,"P",{});var Hp=i(So);$w=n(Hp,"Clone your "),Js=s(Hp,"CODE",{});var B4=i(Js);Pw=n(B4,"transformers"),B4.forEach(o),Iw=n(Hp," fork to your local disk, and add the base repository as a remote:"),Hp.forEach(o),I4.forEach(o),Dp.forEach(o),Fh=f(e),u(Do.$$.fragment,e),Hh=f(e),Fo=s(e,"OL",{start:!0});var A4=i(Fo);Xs=s(A4,"LI",{});var N4=i(Xs);Bw=n(N4,"Set up a development environment, for instance by running the following command:"),N4.forEach(o),A4.forEach(o),zh=f(e),u(Ho.$$.fragment,e),Wh=f(e),vn=s(e,"P",{});var M4=i(vn);Aw=n(M4,"and return to the parent directory"),M4.forEach(o),Gh=f(e),u(zo.$$.fragment,e),Uh=f(e),Wo=s(e,"OL",{start:!0});var j4=i(Wo);Qe=s(j4,"LI",{});var Ia=i(Qe);Nw=n(Ia,"We recommend adding the PyTorch version of "),Ks=s(Ia,"EM",{});var x4=i(Ks);Mw=n(x4,"brand_new_bert"),x4.forEach(o),jw=n(Ia,` to Transformers. To install PyTorch, please follow the
instructions on `),Go=s(Ia,"A",{href:!0,rel:!0});var O4=i(Go);xw=n(O4,"https://pytorch.org/get-started/locally/"),O4.forEach(o),Ow=n(Ia,"."),Ia.forEach(o),j4.forEach(o),Yh=f(e),Uo=s(e,"P",{});var wk=i(Uo);Qs=s(wk,"STRONG",{});var C4=i(Qs);Cw=n(C4,"Note:"),C4.forEach(o),Lw=n(wk," You don\u2019t need to have CUDA installed. Making the new model work on CPU is sufficient."),wk.forEach(o),Jh=f(e),Yo=s(e,"OL",{start:!0});var L4=i(Yo);Jo=s(L4,"LI",{});var zp=i(Jo);qw=n(zp,"To port "),Vs=s(zp,"EM",{});var q4=i(Vs);Rw=n(q4,"brand_new_bert"),q4.forEach(o),Sw=n(zp,", you will also need access to its original repository:"),zp.forEach(o),L4.forEach(o),Xh=f(e),u(Xo.$$.fragment,e),Kh=f(e),bt=s(e,"P",{});var Wp=i(bt);Dw=n(Wp,"Now you have set up a development environment to port "),Zs=s(Wp,"EM",{});var R4=i(Zs);Fw=n(R4,"brand_new_bert"),R4.forEach(o),Hw=n(Wp," to \u{1F917} Transformers."),Wp.forEach(o),Qh=f(e),Ve=s(e,"H3",{class:!0});var Gp=i(Ve);_t=s(Gp,"A",{id:!0,class:!0,href:!0});var S4=i(_t);ei=s(S4,"SPAN",{});var D4=i(ei);u(Ko.$$.fragment,D4),D4.forEach(o),S4.forEach(o),zw=f(Gp),ti=s(Gp,"SPAN",{});var F4=i(ti);Ww=n(F4,"3.-4. Run a pretrained checkpoint using the original repository"),F4.forEach(o),Gp.forEach(o),Vh=f(e),M=s(e,"P",{});var le=i(M);Gw=n(le,"At first, you will work on the original "),oi=s(le,"EM",{});var H4=i(oi);Uw=n(H4,"brand_new_bert"),H4.forEach(o),Yw=n(le,` repository. Often, the original implementation is very
\u201Cresearchy\u201D. Meaning that documentation might be lacking and the code can be difficult to understand. But this should
be exactly your motivation to reimplement `),ri=s(le,"EM",{});var z4=i(ri);Jw=n(z4,"brand_new_bert"),z4.forEach(o),Xw=n(le,". At Hugging Face, one of our main goals is to "),ni=s(le,"EM",{});var W4=i(ni);Kw=n(W4,`make people
stand on the shoulders of giants`),W4.forEach(o),Qw=n(le,` which translates here very well into taking a working model and rewriting it to make
it as `),ai=s(le,"STRONG",{});var G4=i(ai);Vw=n(G4,"accessible, user-friendly, and beautiful"),G4.forEach(o),Zw=n(le,` as possible. This is the number-one motivation to re-implement
models into \u{1F917} Transformers - trying to make complex new NLP technology accessible to `),si=s(le,"STRONG",{});var U4=i(si);ev=n(U4,"everybody"),U4.forEach(o),tv=n(le,"."),le.forEach(o),Zh=f(e),bn=s(e,"P",{});var Y4=i(bn);ov=n(Y4,"You should start thereby by diving into the original repository."),Y4.forEach(o),ef=f(e),Et=s(e,"P",{});var Up=i(Et);rv=n(Up,"Successfully running the official pretrained model in the original repository is often "),ii=s(Up,"STRONG",{});var J4=i(ii);nv=n(J4,"the most difficult"),J4.forEach(o),av=n(Up,` step.
From our experience, it is very important to spend some time getting familiar with the original code-base. You need to
figure out the following:`),Up.forEach(o),tf=f(e),j=s(e,"UL",{});var de=i(j);li=s(de,"LI",{});var X4=i(li);sv=n(X4,"Where to find the pretrained weights?"),X4.forEach(o),iv=f(de),di=s(de,"LI",{});var K4=i(di);lv=n(K4,"How to load the pretrained weights into the corresponding model?"),K4.forEach(o),dv=f(de),hi=s(de,"LI",{});var Q4=i(hi);hv=n(Q4,"How to run the tokenizer independently from the model?"),Q4.forEach(o),fv=f(de),fi=s(de,"LI",{});var V4=i(fi);mv=n(V4,`Trace one forward pass so that you know which classes and functions are required for a simple forward pass. Usually,
you only have to reimplement those functions.`),V4.forEach(o),pv=f(de),W=s(de,"LI",{});var xe=i(W);uv=n(xe,`Be able to locate the important components of the model: Where is the model\u2019s class? Are there model sub-classes,
`),mi=s(xe,"EM",{});var Z4=i(mi);cv=n(Z4,"e.g."),Z4.forEach(o),yv=n(xe,` EncoderModel, DecoderModel? Where is the self-attention layer? Are there multiple different attention layers,
`),pi=s(xe,"EM",{});var e5=i(pi);gv=n(e5,"e.g."),e5.forEach(o),wv=f(xe),ui=s(xe,"EM",{});var t5=i(ui);vv=n(t5,"self-attention"),t5.forEach(o),bv=n(xe,", "),ci=s(xe,"EM",{});var o5=i(ci);_v=n(o5,"cross-attention"),o5.forEach(o),Ev=n(xe,"\u2026?"),xe.forEach(o),kv=f(de),Ze=s(de,"LI",{});var Ba=i(Ze);Tv=n(Ba,"How can you debug the model in the original environment of the repo? Do you have to add "),yi=s(Ba,"EM",{});var r5=i(yi);$v=n(r5,"print"),r5.forEach(o),Pv=n(Ba,` statements, can you
work with an interactive debugger like `),gi=s(Ba,"EM",{});var n5=i(gi);Iv=n(n5,"ipdb"),n5.forEach(o),Bv=n(Ba,", or should you use an efficient IDE to debug the model, like PyCharm?"),Ba.forEach(o),de.forEach(o),of=f(e),kt=s(e,"P",{});var Yp=i(kt);Av=n(Yp,"It is very important that before you start the porting process, that you can "),wi=s(Yp,"STRONG",{});var a5=i(wi);Nv=n(a5,"efficiently"),a5.forEach(o),Mv=n(Yp,` debug code in the original
repository! Also, remember that you are working with an open-source library, so do not hesitate to open an issue, or
even a pull request in the original repository. The maintainers of this repository are most likely very happy about
someone looking into their code!`),Yp.forEach(o),rf=f(e),_n=s(e,"P",{});var s5=i(_n);jv=n(s5,`At this point, it is really up to you which debugging environment and strategy you prefer to use to debug the original
model. We strongly advise against setting up a costly GPU environment, but simply work on a CPU both when starting to
dive into the original repository and also when starting to write the \u{1F917} Transformers implementation of the model. Only
at the very end, when the model has already been successfully ported to \u{1F917} Transformers, one should verify that the
model also works as expected on GPU.`),s5.forEach(o),nf=f(e),En=s(e,"P",{});var i5=i(En);xv=n(i5,"In general, there are two possible debugging environments for running the original model"),i5.forEach(o),af=f(e),Tt=s(e,"UL",{});var Jp=i(Tt);Qo=s(Jp,"LI",{});var Xp=i(Qo);Vo=s(Xp,"A",{href:!0,rel:!0});var l5=i(Vo);Ov=n(l5,"Jupyter notebooks"),l5.forEach(o),Cv=n(Xp," / "),Zo=s(Xp,"A",{href:!0,rel:!0});var d5=i(Zo);Lv=n(d5,"google colab"),d5.forEach(o),Xp.forEach(o),qv=f(Jp),vi=s(Jp,"LI",{});var h5=i(vi);Rv=n(h5,"Local python scripts."),h5.forEach(o),Jp.forEach(o),sf=f(e),kn=s(e,"P",{});var f5=i(kn);Sv=n(f5,`Jupyter notebooks have the advantage that they allow for cell-by-cell execution which can be helpful to better split
logical components from one another and to have faster debugging cycles as intermediate results can be stored. Also,
notebooks are often easier to share with other contributors, which might be very helpful if you want to ask the Hugging
Face team for help. If you are familiar with Jupiter notebooks, we strongly recommend you to work with them.`),f5.forEach(o),lf=f(e),$t=s(e,"P",{});var Kp=i($t);Dv=n(Kp,`The obvious disadvantage of Jupyter notebooks is that if you are not used to working with them you will have to spend
some time adjusting to the new programming environment and that you might not be able to use your known debugging tools
anymore, like `),bi=s(Kp,"CODE",{});var m5=i(bi);Fv=n(m5,"ipdb"),m5.forEach(o),Hv=n(Kp,"."),Kp.forEach(o),df=f(e),Pt=s(e,"P",{});var Qp=i(Pt);zv=n(Qp,"For each code-base, a good first step is always to load a "),_i=s(Qp,"STRONG",{});var p5=i(_i);Wv=n(p5,"small"),p5.forEach(o),Gv=n(Qp,` pretrained checkpoint and to be able to reproduce a
single forward pass using a dummy integer vector of input IDs as an input. Such a script could look like this (in
pseudocode):`),Qp.forEach(o),hf=f(e),u(er.$$.fragment,e),ff=f(e),Tn=s(e,"P",{});var u5=i(Tn);Uv=n(u5,"Next, regarding the debugging strategy, there are generally a few from which to choose from:"),u5.forEach(o),mf=f(e),It=s(e,"UL",{});var Vp=i(It);Ei=s(Vp,"LI",{});var c5=i(Ei);Yv=n(c5,`Decompose the original model into many small testable components and run a forward pass on each of those for
verification`),c5.forEach(o),Jv=f(Vp),et=s(Vp,"LI",{});var Aa=i(et);Xv=n(Aa,"Decompose the original model only into the original "),ki=s(Aa,"EM",{});var y5=i(ki);Kv=n(y5,"tokenizer"),y5.forEach(o),Qv=n(Aa," and the original "),Ti=s(Aa,"EM",{});var g5=i(Ti);Vv=n(g5,"model"),g5.forEach(o),Zv=n(Aa,`, run a forward pass on
those, and use intermediate print statements or breakpoints for verification`),Aa.forEach(o),Vp.forEach(o),pf=f(e),$n=s(e,"P",{});var w5=i($n);eb=n(w5,`Again, it is up to you which strategy to choose. Often, one or the other is advantageous depending on the original code
base.`),w5.forEach(o),uf=f(e),Bt=s(e,"P",{});var Zp=i(Bt);tb=n(Zp,"If the original code-base allows you to decompose the model into smaller sub-components, "),$i=s(Zp,"EM",{});var v5=i($i);ob=n(v5,"e.g."),v5.forEach(o),rb=n(Zp,` if the original
code-base can easily be run in eager mode, it is usually worth the effort to do so. There are some important advantages
to taking the more difficult road in the beginning:`),Zp.forEach(o),cf=f(e),X=s(e,"UL",{});var to=i(X);Pi=s(to,"LI",{});var b5=i(Pi);nb=n(b5,`at a later stage when comparing the original model to the Hugging Face implementation, you can verify automatically
for each component individually that the corresponding component of the \u{1F917} Transformers implementation matches instead
of relying on visual comparison via print statements`),b5.forEach(o),ab=f(to),Ii=s(to,"LI",{});var _5=i(Ii);sb=n(_5,`it can give you some rope to decompose the big problem of porting a model into smaller problems of just porting
individual components and thus structure your work better`),_5.forEach(o),ib=f(to),Bi=s(to,"LI",{});var E5=i(Bi);lb=n(E5,`separating the model into logical meaningful components will help you to get a better overview of the model\u2019s design
and thus to better understand the model`),E5.forEach(o),db=f(to),Ai=s(to,"LI",{});var k5=i(Ai);hb=n(k5,`at a later stage those component-by-component tests help you to ensure that no regression occurs as you continue
changing your code`),k5.forEach(o),to.forEach(o),yf=f(e),tr=s(e,"P",{});var vk=i(tr);or=s(vk,"A",{href:!0,rel:!0});var T5=i(or);fb=n(T5,"Lysandre\u2019s"),T5.forEach(o),mb=n(vk,` integration checks for ELECTRA
gives a nice example of how this can be done.`),vk.forEach(o),gf=f(e),At=s(e,"P",{});var eu=i(At);pb=n(eu,`However, if the original code-base is very complex or only allows intermediate components to be run in a compiled mode,
it might be too time-consuming or even impossible to separate the model into smaller testable sub-components. A good
example is `),rr=s(eu,"A",{href:!0,rel:!0});var $5=i(rr);ub=n($5,"T5\u2019s MeshTensorFlow"),$5.forEach(o),cb=n(eu,` library which is
very complex and does not offer a simple way to decompose the model into its sub-components. For such libraries, one
often relies on verifying print statements.`),eu.forEach(o),wf=f(e),Pn=s(e,"P",{});var P5=i(Pn);yb=n(P5,`No matter which strategy you choose, the recommended procedure is often the same in that you should start to debug the
starting layers first and the ending layers last.`),P5.forEach(o),vf=f(e),In=s(e,"P",{});var I5=i(In);gb=n(I5,`It is recommended that you retrieve the output, either by print statements or sub-component functions, of the following
layers in the following order:`),I5.forEach(o),bf=f(e),x=s(e,"OL",{});var he=i(x);Ni=s(he,"LI",{});var B5=i(Ni);wb=n(B5,"Retrieve the input IDs passed to the model"),B5.forEach(o),vb=f(he),Mi=s(he,"LI",{});var A5=i(Mi);bb=n(A5,"Retrieve the word embeddings"),A5.forEach(o),_b=f(he),ji=s(he,"LI",{});var N5=i(ji);Eb=n(N5,"Retrieve the input of the first Transformer layer"),N5.forEach(o),kb=f(he),xi=s(he,"LI",{});var M5=i(xi);Tb=n(M5,"Retrieve the output of the first Transformer layer"),M5.forEach(o),$b=f(he),Oi=s(he,"LI",{});var j5=i(Oi);Pb=n(j5,"Retrieve the output of the following n - 1 Transformer layers"),j5.forEach(o),Ib=f(he),Ci=s(he,"LI",{});var x5=i(Ci);Bb=n(x5,"Retrieve the output of the whole BrandNewBert Model"),x5.forEach(o),he.forEach(o),_f=f(e),tt=s(e,"P",{});var th=i(tt);Ab=n(th,"Input IDs should thereby consists of an array of integers, "),Li=s(th,"EM",{});var O5=i(Li);Nb=n(O5,"e.g."),O5.forEach(o),Mb=f(th),qi=s(th,"CODE",{});var C5=i(qi);jb=n(C5,"input_ids = [0, 4, 4, 3, 2, 4, 1, 7, 19]"),C5.forEach(o),th.forEach(o),Ef=f(e),Bn=s(e,"P",{});var L5=i(Bn);xb=n(L5,"The outputs of the following layers often consist of multi-dimensional float arrays and can look like this:"),L5.forEach(o),kf=f(e),u(nr.$$.fragment,e),Tf=f(e),_e=s(e,"P",{});var Na=i(_e);Ob=n(Na,`We expect that every model added to \u{1F917} Transformers passes a couple of integration tests, meaning that the original
model and the reimplemented version in \u{1F917} Transformers have to give the exact same output up to a precision of 0.001!
Since it is normal that the exact same model written in different libraries can give a slightly different output
depending on the library framework, we accept an error tolerance of 1e-3 (0.001). It is not enough if the model gives
nearly the same output, they have to be the almost identical. Therefore, you will certainly compare the intermediate
outputs of the \u{1F917} Transformers version multiple times against the intermediate outputs of the original implementation of
`),Ri=s(Na,"EM",{});var q5=i(Ri);Cb=n(q5,"brand_new_bert"),q5.forEach(o),Lb=n(Na," in which case an "),Si=s(Na,"STRONG",{});var R5=i(Si);qb=n(R5,"efficient"),R5.forEach(o),Rb=n(Na,` debugging environment of the original repository is absolutely
important. Here is some advice is to make your debugging environment as efficient as possible.`),Na.forEach(o),$f=f(e),D=s(e,"UL",{});var Oe=i(D);G=s(Oe,"LI",{});var Ce=i(G);Sb=n(Ce,`Find the best way of debugging intermediate results. Is the original repository written in PyTorch? Then you should
probably take the time to write a longer script that decomposes the original model into smaller sub-components to
retrieve intermediate values. Is the original repository written in Tensorflow 1? Then you might have to rely on
TensorFlow print operations like `),ar=s(Ce,"A",{href:!0,rel:!0});var S5=i(ar);Db=n(S5,"tf.print"),S5.forEach(o),Fb=n(Ce,` to output
intermediate values. Is the original repository written in Jax? Then make sure that the model is `),Di=s(Ce,"STRONG",{});var D5=i(Di);Hb=n(D5,"not jitted"),D5.forEach(o),zb=n(Ce,` when
running the forward pass, `),Fi=s(Ce,"EM",{});var F5=i(Fi);Wb=n(F5,"e.g."),F5.forEach(o),Gb=n(Ce," check-out "),sr=s(Ce,"A",{href:!0,rel:!0});var H5=i(sr);Ub=n(H5,"this link"),H5.forEach(o),Yb=n(Ce,"."),Ce.forEach(o),Jb=f(Oe),Hi=s(Oe,"LI",{});var z5=i(Hi);Xb=n(z5,`Use the smallest pretrained checkpoint you can find. The smaller the checkpoint, the faster your debug cycle
becomes. It is not efficient if your pretrained model is so big that your forward pass takes more than 10 seconds.
In case only very large checkpoints are available, it might make more sense to create a dummy model in the new
environment with randomly initialized weights and save those weights for comparison with the \u{1F917} Transformers version
of your model`),z5.forEach(o),Kb=f(Oe),$=s(Oe,"LI",{});var I=i($);Qb=n(I,`Make sure you are using the easiest way of calling a forward pass in the original repository. Ideally, you want to
find the function in the original repository that `),zi=s(I,"STRONG",{});var W5=i(zi);Vb=n(W5,"only"),W5.forEach(o),Zb=n(I," calls a single forward pass, "),Wi=s(I,"EM",{});var G5=i(Wi);e_=n(G5,"i.e."),G5.forEach(o),t_=n(I,` that is often called
`),Gi=s(I,"CODE",{});var U5=i(Gi);o_=n(U5,"predict"),U5.forEach(o),r_=n(I,", "),Ui=s(I,"CODE",{});var Y5=i(Ui);n_=n(Y5,"evaluate"),Y5.forEach(o),a_=n(I,", "),Yi=s(I,"CODE",{});var J5=i(Yi);s_=n(J5,"forward"),J5.forEach(o),i_=n(I," or "),Ji=s(I,"CODE",{});var X5=i(Ji);l_=n(X5,"__call__"),X5.forEach(o),d_=n(I,". You don\u2019t want to debug a function that calls "),Xi=s(I,"CODE",{});var K5=i(Xi);h_=n(K5,"forward"),K5.forEach(o),f_=n(I,`
multiple times, `),Ki=s(I,"EM",{});var Q5=i(Ki);m_=n(Q5,"e.g."),Q5.forEach(o),p_=n(I," to generate text, like "),Qi=s(I,"CODE",{});var V5=i(Qi);u_=n(V5,"autoregressive_sample"),V5.forEach(o),c_=n(I,", "),Vi=s(I,"CODE",{});var Z5=i(Vi);y_=n(Z5,"generate"),Z5.forEach(o),g_=n(I,"."),I.forEach(o),w_=f(Oe),ir=s(Oe,"LI",{});var tu=i(ir);v_=n(tu,"Try to separate the tokenization from the model\u2019s "),Zi=s(tu,"EM",{});var e6=i(Zi);b_=n(e6,"forward"),e6.forEach(o),__=n(tu,` pass. If the original repository shows examples where
you have to input a string, then try to find out where in the forward call the string input is changed to input ids
and start from this point. This might mean that you have to possibly write a small script yourself or change the
original code so that you can directly input the ids instead of an input string.`),tu.forEach(o),E_=f(Oe),ce=s(Oe,"LI",{});var oo=i(ce);k_=n(oo,"Make sure that the model in your debugging setup is "),el=s(oo,"STRONG",{});var t6=i(el);T_=n(t6,"not"),t6.forEach(o),$_=n(oo,` in training mode, which often causes the model to yield
random outputs due to multiple dropout layers in the model. Make sure that the forward pass in your debugging
environment is `),tl=s(oo,"STRONG",{});var o6=i(tl);P_=n(o6,"deterministic"),o6.forEach(o),I_=n(oo," so that the dropout layers are not used. Or use "),ol=s(oo,"EM",{});var r6=i(ol);B_=n(r6,"transformers.utils.set_seed"),r6.forEach(o),A_=n(oo,`
if the old and new implementations are in the same framework.`),oo.forEach(o),Oe.forEach(o),Pf=f(e),Nt=s(e,"P",{});var ou=i(Nt);N_=n(ou,"The following section gives you more specific details/tips on how you can do this for "),rl=s(ou,"EM",{});var n6=i(rl);M_=n(n6,"brand_new_bert"),n6.forEach(o),j_=n(ou,"."),ou.forEach(o),If=f(e),ot=s(e,"H3",{class:!0});var ru=i(ot);Mt=s(ru,"A",{id:!0,class:!0,href:!0});var a6=i(Mt);nl=s(a6,"SPAN",{});var s6=i(nl);u(lr.$$.fragment,s6),s6.forEach(o),a6.forEach(o),x_=f(ru),al=s(ru,"SPAN",{});var i6=i(al);O_=n(i6,"5.-14. Port BrandNewBert to \u{1F917} Transformers"),i6.forEach(o),ru.forEach(o),Bf=f(e),An=s(e,"P",{});var l6=i(An);C_=n(l6,"Next, you can finally start adding new code to \u{1F917} Transformers. Go into the clone of your \u{1F917} Transformers\u2019 fork:"),l6.forEach(o),Af=f(e),u(dr.$$.fragment,e),Nf=f(e),jt=s(e,"P",{});var nu=i(jt);L_=n(nu,`In the special case that you are adding a model whose architecture exactly matches the model architecture of an
existing model you only have to add a conversion script as described in `),Nn=s(nu,"A",{href:!0});var d6=i(Nn);q_=n(d6,"this section"),d6.forEach(o),R_=n(nu,`.
In this case, you can just re-use the whole model architecture of the already existing model.`),nu.forEach(o),Mf=f(e),Mn=s(e,"P",{});var h6=i(Mn);S_=n(h6,"Otherwise, let\u2019s start generating a new model. You have two choices here:"),h6.forEach(o),jf=f(e),xt=s(e,"UL",{});var au=i(xt);jn=s(au,"LI",{});var bk=i(jn);sl=s(bk,"CODE",{});var f6=i(sl);D_=n(f6,"transformers-cli add-new-model-like"),f6.forEach(o),F_=n(bk," to add a new model like an existing one"),bk.forEach(o),H_=f(au),xn=s(au,"LI",{});var _k=i(xn);il=s(_k,"CODE",{});var m6=i(il);z_=n(m6,"transformers-cli add-new-model"),m6.forEach(o),W_=n(_k," to add a new model from our template (will look like BERT or Bart depending on the type of model you select)"),_k.forEach(o),au.forEach(o),xf=f(e),Ee=s(e,"P",{});var Ma=i(Ee);G_=n(Ma,"In both cases, you will be prompted with a questionnaire to fill the basic information of your model. The second command requires to install "),ll=s(Ma,"CODE",{});var p6=i(ll);U_=n(p6,"cookiecutter"),p6.forEach(o),Y_=n(Ma,", you can find more information on it "),hr=s(Ma,"A",{href:!0,rel:!0});var u6=i(hr);J_=n(u6,"here"),u6.forEach(o),X_=n(Ma,"."),Ma.forEach(o),Of=f(e),On=s(e,"P",{});var c6=i(On);dl=s(c6,"STRONG",{});var y6=i(dl);K_=n(y6,"Open a Pull Request on the main huggingface/transformers repo"),y6.forEach(o),c6.forEach(o),Cf=f(e),ke=s(e,"P",{});var ja=i(ke);Q_=n(ja,`Before starting to adapt the automatically generated code, now is the time to open a \u201CWork in progress (WIP)\u201D pull
request, `),hl=s(ja,"EM",{});var g6=i(hl);V_=n(g6,"e.g."),g6.forEach(o),Z_=n(ja," \u201C[WIP] Add "),fl=s(ja,"EM",{});var w6=i(fl);e1=n(w6,"brand_new_bert"),w6.forEach(o),t1=n(ja,`\u201D, in \u{1F917} Transformers so that you and the Hugging Face team can work
side-by-side on integrating the model into \u{1F917} Transformers.`),ja.forEach(o),Lf=f(e),Cn=s(e,"P",{});var v6=i(Cn);o1=n(v6,"You should do the following:"),v6.forEach(o),qf=f(e),Ln=s(e,"OL",{});var b6=i(Ln);ml=s(b6,"LI",{});var _6=i(ml);r1=n(_6,"Create a branch with a descriptive name from your main branch"),_6.forEach(o),b6.forEach(o),Rf=f(e),u(fr.$$.fragment,e),Sf=f(e),mr=s(e,"OL",{start:!0});var E6=i(mr);pl=s(E6,"LI",{});var k6=i(pl);n1=n(k6,"Commit the automatically generated code:"),k6.forEach(o),E6.forEach(o),Df=f(e),u(pr.$$.fragment,e),Ff=f(e),ur=s(e,"OL",{start:!0});var T6=i(ur);ul=s(T6,"LI",{});var $6=i(ul);a1=n($6,"Fetch and rebase to current main"),$6.forEach(o),T6.forEach(o),Hf=f(e),u(cr.$$.fragment,e),zf=f(e),yr=s(e,"OL",{start:!0});var P6=i(yr);cl=s(P6,"LI",{});var I6=i(cl);s1=n(I6,"Push the changes to your account using:"),I6.forEach(o),P6.forEach(o),Wf=f(e),u(gr.$$.fragment,e),Gf=f(e),rt=s(e,"OL",{start:!0});var su=i(rt);yl=s(su,"LI",{});var B6=i(yl);gl=s(B6,"P",{});var A6=i(gl);i1=n(A6,`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.`),A6.forEach(o),B6.forEach(o),l1=f(su),wl=s(su,"LI",{});var N6=i(wl);vl=s(N6,"P",{});var M6=i(vl);d1=n(M6,"Change the PR into a draft by clicking on \u201CConvert to draft\u201D on the right of the GitHub pull request web page."),M6.forEach(o),N6.forEach(o),su.forEach(o),Uf=f(e),qn=s(e,"P",{});var j6=i(qn);h1=n(j6,`In the following, whenever you have done some progress, don\u2019t forget to commit your work and push it to your account so
that it shows in the pull request. Additionally, you should make sure to update your work with the current main from
time to time by doing:`),j6.forEach(o),Yf=f(e),u(wr.$$.fragment,e),Jf=f(e),Rn=s(e,"P",{});var x6=i(Rn);f1=n(x6,`In general, all questions you might have regarding the model or your implementation should be asked in your PR and
discussed/solved in the PR. This way, the Hugging Face team will always be notified when you are committing new code or
if you have a question. It is often very helpful to point the Hugging Face team to your added code so that the Hugging
Face team can efficiently understand your problem or question.`),x6.forEach(o),Xf=f(e),Sn=s(e,"P",{});var O6=i(Sn);m1=n(O6,`To do so, you can go to the \u201CFiles changed\u201D tab where you see all of your changes, go to a line regarding which you
want to ask a question, and click on the \u201C+\u201D symbol to add a comment. Whenever a question or problem has been solved,
you can click on the \u201CResolve\u201D button of the created comment.`),O6.forEach(o),Kf=f(e),Dn=s(e,"P",{});var C6=i(Dn);p1=n(C6,`In the same way, the Hugging Face team will open comments when reviewing your code. We recommend asking most questions
on GitHub on your PR. For some very general questions that are not very useful for the public, feel free to ping the
Hugging Face team by Slack or email.`),C6.forEach(o),Qf=f(e),Fn=s(e,"P",{});var L6=i(Fn);bl=s(L6,"STRONG",{});var q6=i(bl);u1=n(q6,"5. Adapt the generated models code for brand_new_bert"),q6.forEach(o),L6.forEach(o),Vf=f(e),Te=s(e,"P",{});var xa=i(Te);c1=n(xa,`At first, we will focus only on the model itself and not care about the tokenizer. All the relevant code should be
found in the generated files `),_l=s(xa,"CODE",{});var R6=i(_l);y1=n(R6,"src/transformers/models/brand_new_bert/modeling_brand_new_bert.py"),R6.forEach(o),g1=n(xa,` and
`),El=s(xa,"CODE",{});var S6=i(El);w1=n(S6,"src/transformers/models/brand_new_bert/configuration_brand_new_bert.py"),S6.forEach(o),v1=n(xa,"."),xa.forEach(o),Zf=f(e),K=s(e,"P",{});var ro=i(K);b1=n(ro,`Now you can finally start coding :). The generated code in
`),kl=s(ro,"CODE",{});var D6=i(kl);_1=n(D6,"src/transformers/models/brand_new_bert/modeling_brand_new_bert.py"),D6.forEach(o),E1=n(ro,` will either have the same architecture as BERT if
it\u2019s an encoder-only model or BART if it\u2019s an encoder-decoder model. At this point, you should remind yourself what
you\u2019ve learned in the beginning about the theoretical aspects of the model: `),Tl=s(ro,"EM",{});var F6=i(Tl);k1=n(F6,`How is the model different from BERT or
BART?`),F6.forEach(o),T1=n(ro,"\u201D. Implement those changes which often means to change the "),$l=s(ro,"EM",{});var H6=i($l);$1=n(H6,"self-attention"),H6.forEach(o),P1=n(ro,` layer, the order of the normalization
layer, etc\u2026 Again, it is often useful to look at the similar architecture of already existing models in Transformers to
get a better feeling of how your model should be implemented.`),ro.forEach(o),em=f(e),O=s(e,"P",{});var ye=i(O);Pl=s(ye,"STRONG",{});var z6=i(Pl);I1=n(z6,"Note"),z6.forEach(o),B1=n(ye,` that at this point, you don\u2019t have to be very sure that your code is fully correct or clean. Rather, it is
advised to add a first `),Il=s(ye,"EM",{});var W6=i(Il);A1=n(W6,"unclean"),W6.forEach(o),N1=n(ye,`, copy-pasted version of the original code to
`),Bl=s(ye,"CODE",{});var G6=i(Bl);M1=n(G6,"src/transformers/models/brand_new_bert/modeling_brand_new_bert.py"),G6.forEach(o),j1=n(ye,` until you feel like all the necessary code is
added. From our experience, it is much more efficient to quickly add a first version of the required code and
improve/correct the code iteratively with the conversion script as described in the next section. The only thing that
has to work at this point is that you can instantiate the \u{1F917} Transformers implementation of `),Al=s(ye,"EM",{});var U6=i(Al);x1=n(U6,"brand_new_bert"),U6.forEach(o),O1=n(ye,", "),Nl=s(ye,"EM",{});var Y6=i(Nl);C1=n(Y6,"i.e."),Y6.forEach(o),L1=n(ye,` the
following command should work:`),ye.forEach(o),tm=f(e),u(vr.$$.fragment,e),om=f(e),$e=s(e,"P",{});var Oa=i($e);q1=n(Oa,"The above command will create a model according to the default parameters as defined in "),Ml=s(Oa,"CODE",{});var J6=i(Ml);R1=n(J6,"BrandNewBertConfig()"),J6.forEach(o),S1=n(Oa,` with
random weights, thus making sure that the `),jl=s(Oa,"CODE",{});var X6=i(jl);D1=n(X6,"init()"),X6.forEach(o),F1=n(Oa," methods of all components works."),Oa.forEach(o),rm=f(e),Hn=s(e,"P",{});var K6=i(Hn);xl=s(K6,"STRONG",{});var Q6=i(xl);H1=n(Q6,"6. Write a conversion script"),Q6.forEach(o),K6.forEach(o),nm=f(e),Q=s(e,"P",{});var no=i(Q);z1=n(no,"Next, you should write a conversion script that lets you convert the checkpoint you used to debug "),Ol=s(no,"EM",{});var V6=i(Ol);W1=n(V6,"brand_new_bert"),V6.forEach(o),G1=n(no,` in
the original repository to a checkpoint compatible with your just created \u{1F917} Transformers implementation of
`),Cl=s(no,"EM",{});var Z6=i(Cl);U1=n(Z6,"brand_new_bert"),Z6.forEach(o),Y1=n(no,`. It is not advised to write the conversion script from scratch, but rather to look through already
existing conversion scripts in \u{1F917} Transformers for one that has been used to convert a similar model that was written in
the same framework as `),Ll=s(no,"EM",{});var e7=i(Ll);J1=n(e7,"brand_new_bert"),e7.forEach(o),X1=n(no,`. Usually, it is enough to copy an already existing conversion script and
slightly adapt it for your use case. Don\u2019t hesitate to ask the Hugging Face team to point you to a similar already
existing conversion script for your model.`),no.forEach(o),am=f(e),Ot=s(e,"UL",{});var iu=i(Ot);zn=s(iu,"LI",{});var Ek=i(zn);K1=n(Ek,"If you are porting a model from TensorFlow to PyTorch, a good starting point might be BERT\u2019s conversion script "),br=s(Ek,"A",{href:!0,rel:!0});var t7=i(br);Q1=n(t7,"here"),t7.forEach(o),Ek.forEach(o),V1=f(iu),Wn=s(iu,"LI",{});var kk=i(Wn);Z1=n(kk,"If you are porting a model from PyTorch to PyTorch, a good starting point might be BART\u2019s conversion script "),_r=s(kk,"A",{href:!0,rel:!0});var o7=i(_r);e0=n(o7,"here"),o7.forEach(o),kk.forEach(o),iu.forEach(o),sm=f(e),Ct=s(e,"P",{});var lu=i(Ct);t0=n(lu,`In the following, we\u2019ll quickly explain how PyTorch models store layer weights and define layer names. In PyTorch, the
name of a layer is defined by the name of the class attribute you give the layer. Let\u2019s define a dummy model in
PyTorch, called `),ql=s(lu,"CODE",{});var r7=i(ql);o0=n(r7,"SimpleModel"),r7.forEach(o),r0=n(lu," as follows:"),lu.forEach(o),im=f(e),u(Er.$$.fragment,e),lm=f(e),V=s(e,"P",{});var ao=i(V);n0=n(ao,"Now we can create an instance of this model definition which will fill all weights: "),Rl=s(ao,"CODE",{});var n7=i(Rl);a0=n(n7,"dense"),n7.forEach(o),s0=n(ao,", "),Sl=s(ao,"CODE",{});var a7=i(Sl);i0=n(a7,"intermediate"),a7.forEach(o),l0=n(ao,`,
`),Dl=s(ao,"CODE",{});var s7=i(Dl);d0=n(s7,"layer_norm"),s7.forEach(o),h0=n(ao," with random weights. We can print the model to see its architecture"),ao.forEach(o),dm=f(e),u(kr.$$.fragment,e),hm=f(e),Gn=s(e,"P",{});var i7=i(Gn);f0=n(i7,"This will print out the following:"),i7.forEach(o),fm=f(e),u(Tr.$$.fragment,e),mm=f(e),Un=s(e,"P",{});var l7=i(Un);m0=n(l7,`We can see that the layer names are defined by the name of the class attribute in PyTorch. You can print out the weight
values of a specific layer:`),l7.forEach(o),pm=f(e),u($r.$$.fragment,e),um=f(e),Yn=s(e,"P",{});var d7=i(Yn);p0=n(d7,"to see that the weights were randomly initialized"),d7.forEach(o),cm=f(e),u(Pr.$$.fragment,e),ym=f(e),Ir=s(e,"P",{});var Tk=i(Ir);u0=n(Tk,`In the conversion script, you should fill those randomly initialized weights with the exact weights of the
corresponding layer in the checkpoint. `),Fl=s(Tk,"EM",{});var h7=i(Fl);c0=n(h7,"E.g."),h7.forEach(o),Tk.forEach(o),gm=f(e),u(Br.$$.fragment,e),wm=f(e),Pe=s(e,"P",{});var Ca=i(Pe);y0=n(Ca,`While doing so, you must verify that each randomly initialized weight of your PyTorch model and its corresponding
pretrained checkpoint weight exactly match in both `),Hl=s(Ca,"STRONG",{});var f7=i(Hl);g0=n(f7,"shape and name"),f7.forEach(o),w0=n(Ca,". To do so, it is "),zl=s(Ca,"STRONG",{});var m7=i(zl);v0=n(m7,"necessary"),m7.forEach(o),b0=n(Ca,` to add assert
statements for the shape and print out the names of the checkpoints weights. E.g. you should add statements like:`),Ca.forEach(o),vm=f(e),u(Ar.$$.fragment,e),bm=f(e),Nr=s(e,"P",{});var $k=i(Nr);_0=n($k,"Besides, you should also print out the names of both weights to make sure they match, "),Wl=s($k,"EM",{});var p7=i(Wl);E0=n(p7,"e.g."),p7.forEach(o),$k.forEach(o),_m=f(e),u(Mr.$$.fragment,e),Em=f(e),Jn=s(e,"P",{});var u7=i(Jn);k0=n(u7,`If either the shape or the name doesn\u2019t match, you probably assigned the wrong checkpoint weight to a randomly
initialized layer of the \u{1F917} Transformers implementation.`),u7.forEach(o),km=f(e),Lt=s(e,"P",{});var du=i(Lt);T0=n(du,"An incorrect shape is most likely due to an incorrect setting of the config parameters in "),Gl=s(du,"CODE",{});var c7=i(Gl);$0=n(c7,"BrandNewBertConfig()"),c7.forEach(o),P0=n(du,` that
do not exactly match those that were used for the checkpoint you want to convert. However, it could also be that
PyTorch\u2019s implementation of a layer requires the weight to be transposed beforehand.`),du.forEach(o),Tm=f(e),Z=s(e,"P",{});var so=i(Z);I0=n(so,"Finally, you should also check that "),Ul=s(so,"STRONG",{});var y7=i(Ul);B0=n(y7,"all"),y7.forEach(o),A0=n(so,` required weights are initialized and print out all checkpoint weights that
were not used for initialization to make sure the model is correctly converted. It is completely normal, that the
conversion trials fail with either a wrong shape statement or wrong name assignment. This is most likely because either
you used incorrect parameters in `),Yl=s(so,"CODE",{});var g7=i(Yl);N0=n(g7,"BrandNewBertConfig()"),g7.forEach(o),M0=n(so,`, have a wrong architecture in the \u{1F917} Transformers
implementation, you have a bug in the `),Jl=s(so,"CODE",{});var w7=i(Jl);j0=n(w7,"init()"),w7.forEach(o),x0=n(so,` functions of one of the components of the \u{1F917} Transformers
implementation or you need to transpose one of the checkpoint weights.`),so.forEach(o),$m=f(e),ee=s(e,"P",{});var io=i(ee);O0=n(io,`This step should be iterated with the previous step until all weights of the checkpoint are correctly loaded in the
Transformers model. Having correctly loaded the checkpoint into the \u{1F917} Transformers implementation, you can then save
the model under a folder of your choice `),Xl=s(io,"CODE",{});var v7=i(Xl);C0=n(v7,"/path/to/converted/checkpoint/folder"),v7.forEach(o),L0=n(io,` that should then contain both a
`),Kl=s(io,"CODE",{});var b7=i(Kl);q0=n(b7,"pytorch_model.bin"),b7.forEach(o),R0=n(io," file and a "),Ql=s(io,"CODE",{});var _7=i(Ql);S0=n(_7,"config.json"),_7.forEach(o),D0=n(io," file:"),io.forEach(o),Pm=f(e),u(jr.$$.fragment,e),Im=f(e),Xn=s(e,"P",{});var E7=i(Xn);Vl=s(E7,"STRONG",{});var k7=i(Vl);F0=n(k7,"7. Implement the forward pass"),k7.forEach(o),E7.forEach(o),Bm=f(e),qt=s(e,"P",{});var hu=i(qt);H0=n(hu,`Having managed to correctly load the pretrained weights into the \u{1F917} Transformers implementation, you should now make
sure that the forward pass is correctly implemented. In `),Kn=s(hu,"A",{href:!0});var T7=i(Kn);z0=n(T7,"Get familiar with the original repository"),T7.forEach(o),W0=n(hu,`, you have already created a script that runs a forward
pass of the model using the original repository. Now you should write an analogous script using the \u{1F917} Transformers
implementation instead of the original one. It should look as follows:`),hu.forEach(o),Am=f(e),u(xr.$$.fragment,e),Nm=f(e),F=s(e,"P",{});var Le=i(F);G0=n(Le,`It is very likely that the \u{1F917} Transformers implementation and the original model implementation don\u2019t give the exact
same output the very first time or that the forward pass throws an error. Don\u2019t be disappointed - it\u2019s expected! First,
you should make sure that the forward pass doesn\u2019t throw any errors. It often happens that the wrong dimensions are
used leading to a `),Zl=s(Le,"EM",{});var $7=i(Zl);U0=n($7,"Dimensionality mismatch"),$7.forEach(o),Y0=n(Le," error or that the wrong data type object is used, "),ed=s(Le,"EM",{});var P7=i(ed);J0=n(P7,"e.g."),P7.forEach(o),X0=f(Le),td=s(Le,"CODE",{});var I7=i(td);K0=n(I7,"torch.long"),I7.forEach(o),Q0=n(Le,`
instead of `),od=s(Le,"CODE",{});var B7=i(od);V0=n(B7,"torch.float32"),B7.forEach(o),Z0=n(Le,`. Don\u2019t hesitate to ask the Hugging Face team for help, if you don\u2019t manage to solve
certain errors.`),Le.forEach(o),Mm=f(e),te=s(e,"P",{});var lo=i(te);e2=n(lo,`The final part to make sure the \u{1F917} Transformers implementation works correctly is to ensure that the outputs are
equivalent to a precision of `),rd=s(lo,"CODE",{});var A7=i(rd);t2=n(A7,"1e-3"),A7.forEach(o),o2=n(lo,". First, you should ensure that the output shapes are identical, "),nd=s(lo,"EM",{});var N7=i(nd);r2=n(N7,"i.e."),N7.forEach(o),n2=f(lo),ad=s(lo,"CODE",{});var M7=i(ad);a2=n(M7,"outputs.shape"),M7.forEach(o),s2=n(lo,` should yield the same value for the script of the \u{1F917} Transformers implementation and the original
implementation. Next, you should make sure that the output values are identical as well. This one of the most difficult
parts of adding a new model. Common mistakes why the outputs are not identical are:`),lo.forEach(o),jm=f(e),oe=s(e,"UL",{});var ho=i(oe);nt=s(ho,"LI",{});var La=i(nt);i2=n(La,"Some layers were not added, "),sd=s(La,"EM",{});var j7=i(sd);l2=n(j7,"i.e."),j7.forEach(o),d2=n(La," an "),id=s(La,"EM",{});var x7=i(id);h2=n(x7,"activation"),x7.forEach(o),f2=n(La," layer was not added, or the residual connection was forgotten"),La.forEach(o),m2=f(ho),ld=s(ho,"LI",{});var O7=i(ld);p2=n(O7,"The word embedding matrix was not tied"),O7.forEach(o),u2=f(ho),dd=s(ho,"LI",{});var C7=i(dd);c2=n(C7,"The wrong positional embeddings are used because the original implementation uses on offset"),C7.forEach(o),y2=f(ho),re=s(ho,"LI",{});var st=i(re);g2=n(st,"Dropout is applied during the forward pass. To fix this make sure "),hd=s(st,"EM",{});var L7=i(hd);w2=n(L7,"model.training is False"),L7.forEach(o),v2=n(st,` and that no dropout
layer is falsely activated during the forward pass, `),fd=s(st,"EM",{});var q7=i(fd);b2=n(q7,"i.e."),q7.forEach(o),_2=n(st," pass "),md=s(st,"EM",{});var R7=i(md);E2=n(R7,"self.training"),R7.forEach(o),k2=n(st," to "),Or=s(st,"A",{href:!0,rel:!0});var S7=i(Or);T2=n(S7,"PyTorch\u2019s functional dropout"),S7.forEach(o),st.forEach(o),ho.forEach(o),xm=f(e),Ie=s(e,"P",{});var qa=i(Ie);$2=n(qa,`The best way to fix the problem is usually to look at the forward pass of the original implementation and the \u{1F917}
Transformers implementation side-by-side and check if there are any differences. Ideally, you should debug/print out
intermediate outputs of both implementations of the forward pass to find the exact position in the network where the \u{1F917}
Transformers implementation shows a different output than the original implementation. First, make sure that the
hard-coded `),pd=s(qa,"CODE",{});var D7=i(pd);P2=n(D7,"input_ids"),D7.forEach(o),I2=n(qa,` in both scripts are identical. Next, verify that the outputs of the first transformation of
the `),ud=s(qa,"CODE",{});var F7=i(ud);B2=n(F7,"input_ids"),F7.forEach(o),A2=n(qa,` (usually the word embeddings) are identical. And then work your way up to the very last layer of the
network. At some point, you will notice a difference between the two implementations, which should point you to the bug
in the \u{1F917} Transformers implementation. From our experience, a simple and efficient way is to add many print statements
in both the original implementation and \u{1F917} Transformers implementation, at the same positions in the network
respectively, and to successively remove print statements showing the same values for intermediate presentations.`),qa.forEach(o),Om=f(e),Rt=s(e,"P",{});var fu=i(Rt);N2=n(fu,`When you\u2019re confident that both implementations yield the same output, verifying the outputs with
`),cd=s(fu,"CODE",{});var H7=i(cd);M2=n(H7,"torch.allclose(original_output, output, atol=1e-3)"),H7.forEach(o),j2=n(fu,`, you\u2019re done with the most difficult part! Congratulations - the
work left to be done should be a cakewalk \u{1F60A}.`),fu.forEach(o),Cm=f(e),Qn=s(e,"P",{});var z7=i(Qn);yd=s(z7,"STRONG",{});var W7=i(yd);x2=n(W7,"8. Adding all necessary model tests"),W7.forEach(o),z7.forEach(o),Lm=f(e),St=s(e,"P",{});var mu=i(St);O2=n(mu,`At this point, you have successfully added a new model. However, it is very much possible that the model does not yet
fully comply with the required design. To make sure, the implementation is fully compatible with \u{1F917} Transformers, all
common tests should pass. The Cookiecutter should have automatically added a test file for your model, probably under
the same `),gd=s(mu,"CODE",{});var G7=i(gd);C2=n(G7,"tests/models/brand_new_bert/test_modeling_brand_new_bert.py"),G7.forEach(o),L2=n(mu,`. Run this test file to verify that all common
tests pass:`),mu.forEach(o),qm=f(e),u(Cr.$$.fragment,e),Rm=f(e),Vn=s(e,"P",{});var U7=i(Vn);q2=n(U7,"Having fixed all common tests, it is now crucial to ensure that all the nice work you have done is well tested, so that"),U7.forEach(o),Sm=f(e),Dt=s(e,"UL",{});var pu=i(Dt);Zn=s(pu,"LI",{});var Pk=i(Zn);R2=n(Pk,"a) The community can easily understand your work by looking at specific tests of "),wd=s(Pk,"EM",{});var Y7=i(wd);S2=n(Y7,"brand_new_bert"),Y7.forEach(o),Pk.forEach(o),D2=f(pu),vd=s(pu,"LI",{});var J7=i(vd);F2=n(J7,"b) Future changes to your model will not break any important feature of the model."),J7.forEach(o),pu.forEach(o),Dm=f(e),Ft=s(e,"P",{});var uu=i(Ft);H2=n(uu,`At first, integration tests should be added. Those integration tests essentially do the same as the debugging scripts
you used earlier to implement the model to \u{1F917} Transformers. A template of those model tests is already added by the
Cookiecutter, called `),bd=s(uu,"CODE",{});var X7=i(bd);z2=n(X7,"BrandNewBertModelIntegrationTests"),X7.forEach(o),W2=n(uu,` and only has to be filled out by you. To ensure that those
tests are passing, run`),uu.forEach(o),Fm=f(e),u(Lr.$$.fragment,e),Hm=f(e),u(Ht.$$.fragment,e),zm=f(e),ne=s(e,"P",{});var fo=i(ne);G2=n(fo,"Second, all features that are special to "),_d=s(fo,"EM",{});var K7=i(_d);U2=n(K7,"brand_new_bert"),K7.forEach(o),Y2=n(fo,` should be tested additionally in a separate test under
`),Ed=s(fo,"CODE",{});var Q7=i(Ed);J2=n(Q7,"BrandNewBertModelTester"),Q7.forEach(o),X2=n(fo,"/`"),kd=s(fo,"CODE",{});var V7=i(kd);K2=n(V7,"BrandNewBertModelTest"),V7.forEach(o),Q2=n(fo,`. This part is often forgotten but is extremely useful in two
ways:`),fo.forEach(o),Wm=f(e),zt=s(e,"UL",{});var cu=i(zt);qr=s(cu,"LI",{});var yu=i(qr);V2=n(yu,`It helps to transfer the knowledge you have acquired during the model addition to the community by showing how the
special features of `),Td=s(yu,"EM",{});var Z7=i(Td);Z2=n(Z7,"brand_new_bert"),Z7.forEach(o),eE=n(yu," should work."),yu.forEach(o),tE=f(cu),$d=s(cu,"LI",{});var eT=i($d);oE=n(eT,"Future contributors can quickly test changes to the model by running those special tests."),eT.forEach(o),cu.forEach(o),Gm=f(e),ea=s(e,"P",{});var tT=i(ea);Pd=s(tT,"STRONG",{});var oT=i(Pd);rE=n(oT,"9. Implement the tokenizer"),oT.forEach(o),tT.forEach(o),Um=f(e),Wt=s(e,"P",{});var gu=i(Wt);nE=n(gu,"Next, we should add the tokenizer of "),Id=s(gu,"EM",{});var rT=i(Id);aE=n(rT,"brand_new_bert"),rT.forEach(o),sE=n(gu,`. Usually, the tokenizer is equivalent or very similar to an
already existing tokenizer of \u{1F917} Transformers.`),gu.forEach(o),Ym=f(e),ta=s(e,"P",{});var nT=i(ta);iE=n(nT,`It is very important to find/extract the original tokenizer file and to manage to load this file into the \u{1F917}
Transformers\u2019 implementation of the tokenizer.`),nT.forEach(o),Jm=f(e),oa=s(e,"P",{});var aT=i(oa);lE=n(aT,"To ensure that the tokenizer works correctly, it is recommended to first create a script in the original repository\nthat inputs a string and returns the `input_ids\u201C. It could look similar to this (in pseudo-code):"),aT.forEach(o),Xm=f(e),u(Rr.$$.fragment,e),Km=f(e),Gt=s(e,"P",{});var wu=i(Gt);dE=n(wu,`You might have to take a deeper look again into the original repository to find the correct tokenizer function or you
might even have to do changes to your clone of the original repository to only output the `),Bd=s(wu,"CODE",{});var sT=i(Bd);hE=n(sT,"input_ids"),sT.forEach(o),fE=n(wu,`. Having written
a functional tokenization script that uses the original repository, an analogous script for \u{1F917} Transformers should be
created. It should look similar to this:`),wu.forEach(o),Qm=f(e),u(Sr.$$.fragment,e),Vm=f(e),Ut=s(e,"P",{});var vu=i(Ut);mE=n(vu,"When both "),Ad=s(vu,"CODE",{});var iT=i(Ad);pE=n(iT,"input_ids"),iT.forEach(o),uE=n(vu," yield the same values, as a final step a tokenizer test file should also be added."),vu.forEach(o),Zm=f(e),Be=s(e,"P",{});var Ra=i(Be);cE=n(Ra,"Analogous to the modeling test files of "),Nd=s(Ra,"EM",{});var lT=i(Nd);yE=n(lT,"brand_new_bert"),lT.forEach(o),gE=n(Ra,", the tokenization test files of "),Md=s(Ra,"EM",{});var dT=i(Md);wE=n(dT,"brand_new_bert"),dT.forEach(o),vE=n(Ra,` should
contain a couple of hard-coded integration tests.`),Ra.forEach(o),ep=f(e),ra=s(e,"P",{});var hT=i(ra);jd=s(hT,"STRONG",{});var fT=i(jd);bE=n(fT,"10. Run End-to-end integration tests"),fT.forEach(o),hT.forEach(o),tp=f(e),ae=s(e,"P",{});var mo=i(ae);_E=n(mo,`Having added the tokenizer, you should also add a couple of end-to-end integration tests using both the model and the
tokenizer to `),xd=s(mo,"CODE",{});var mT=i(xd);EE=n(mT,"tests/models/brand_new_bert/test_modeling_brand_new_bert.py"),mT.forEach(o),kE=n(mo,` in \u{1F917} Transformers.
Such a test should show on a meaningful
text-to-text sample that the \u{1F917} Transformers implementation works as expected. A meaningful text-to-text sample can
include `),Od=s(mo,"EM",{});var pT=i(Od);TE=n(pT,"e.g."),pT.forEach(o),$E=n(mo,` a source-to-target-translation pair, an article-to-summary pair, a question-to-answer pair, etc\u2026 If none
of the ported checkpoints has been fine-tuned on a downstream task it is enough to simply rely on the model tests. In a
final step to ensure that the model is fully functional, it is advised that you also run all tests on GPU. It can
happen that you forgot to add some `),Cd=s(mo,"CODE",{});var uT=i(Cd);PE=n(uT,".to(self.device)"),uT.forEach(o),IE=n(mo,` statements to internal tensors of the model, which in such a
test would show in an error. In case you have no access to a GPU, the Hugging Face team can take care of running those
tests for you.`),mo.forEach(o),op=f(e),na=s(e,"P",{});var cT=i(na);Ld=s(cT,"STRONG",{});var yT=i(Ld);BE=n(yT,"11. Add Docstring"),yT.forEach(o),cT.forEach(o),rp=f(e),se=s(e,"P",{});var po=i(se);AE=n(po,"Now, all the necessary functionality for "),qd=s(po,"EM",{});var gT=i(qd);NE=n(gT,"brand_new_bert"),gT.forEach(o),ME=n(po,` is added - you\u2019re almost done! The only thing left to add is
a nice docstring and a doc page. The Cookiecutter should have added a template file called
`),Rd=s(po,"CODE",{});var wT=i(Rd);jE=n(wT,"docs/source/model_doc/brand_new_bert.mdx"),wT.forEach(o),xE=n(po,` that you should fill out. Users of your model will usually first look at
this page before using your model. Hence, the documentation must be understandable and concise. It is very useful for
the community to add some `),Sd=s(po,"EM",{});var vT=i(Sd);OE=n(vT,"Tips"),vT.forEach(o),CE=n(po,` to show how the model should be used. Don\u2019t hesitate to ping the Hugging Face team
regarding the docstrings.`),po.forEach(o),np=f(e),Ae=s(e,"P",{});var Sa=i(Ae);LE=n(Sa,"Next, make sure that the docstring added to "),Dd=s(Sa,"CODE",{});var bT=i(Dd);qE=n(bT,"src/transformers/models/brand_new_bert/modeling_brand_new_bert.py"),bT.forEach(o),RE=n(Sa,` is
correct and included all necessary inputs and outputs. We have a detailed guide about writing documentation and our docstring format `),aa=s(Sa,"A",{href:!0});var _T=i(aa);SE=n(_T,"here"),_T.forEach(o),DE=n(Sa,`. It is always to good to remind oneself that documentation should
be treated at least as carefully as the code in \u{1F917} Transformers since the documentation is usually the first contact
point of the community with the model.`),Sa.forEach(o),ap=f(e),sa=s(e,"P",{});var ET=i(sa);Fd=s(ET,"STRONG",{});var kT=i(Fd);FE=n(kT,"Code refactor"),kT.forEach(o),ET.forEach(o),sp=f(e),Yt=s(e,"P",{});var bu=i(Yt);HE=n(bu,"Great, now you have added all the necessary code for "),Hd=s(bu,"EM",{});var TT=i(Hd);zE=n(TT,"brand_new_bert"),TT.forEach(o),WE=n(bu,`. At this point, you should correct some potential
incorrect code style by running:`),bu.forEach(o),ip=f(e),u(Dr.$$.fragment,e),lp=f(e),ia=s(e,"P",{});var $T=i(ia);GE=n($T,"and verify that your coding style passes the quality check:"),$T.forEach(o),dp=f(e),u(Fr.$$.fragment,e),hp=f(e),la=s(e,"P",{});var PT=i(la);UE=n(PT,`There are a couple of other very strict design tests in \u{1F917} Transformers that might still be failing, which shows up in
the tests of your pull request. This is often because of some missing information in the docstring or some incorrect
naming. The Hugging Face team will surely help you if you\u2019re stuck here.`),PT.forEach(o),fp=f(e),da=s(e,"P",{});var IT=i(da);YE=n(IT,`Lastly, it is always a good idea to refactor one\u2019s code after having ensured that the code works correctly. With all
tests passing, now it\u2019s a good time to go over the added code again and do some refactoring.`),IT.forEach(o),mp=f(e),ha=s(e,"P",{});var BT=i(ha);JE=n(BT,"You have now finished the coding part, congratulation! \u{1F389} You are Awesome! \u{1F60E}"),BT.forEach(o),pp=f(e),fa=s(e,"P",{});var AT=i(fa);zd=s(AT,"STRONG",{});var NT=i(zd);XE=n(NT,"12. Upload the models to the model hub"),NT.forEach(o),AT.forEach(o),up=f(e),H=s(e,"P",{});var qe=i(H);KE=n(qe,`In this final part, you should convert and upload all checkpoints to the model hub and add a model card for each
uploaded model checkpoint. You can get familiar with the hub functionalities by reading our `),ma=s(qe,"A",{href:!0});var MT=i(ma);QE=n(MT,"Model sharing and uploading Page"),MT.forEach(o),VE=n(qe,`. You should work alongside the Hugging Face team here to decide on a fitting name for each
checkpoint and to get the required access rights to be able to upload the model under the author\u2019s organization of
`),Wd=s(qe,"EM",{});var jT=i(Wd);ZE=n(jT,"brand_new_bert"),jT.forEach(o),ek=n(qe,". The "),Gd=s(qe,"CODE",{});var xT=i(Gd);tk=n(xT,"push_to_hub"),xT.forEach(o),ok=n(qe," method, present in all models in "),Ud=s(qe,"CODE",{});var OT=i(Ud);rk=n(OT,"transformers"),OT.forEach(o),nk=n(qe,", is a quick and efficient way to push your checkpoint to the hub. A little snippet is pasted below:"),qe.forEach(o),cp=f(e),u(Hr.$$.fragment,e),yp=f(e),Jt=s(e,"P",{});var _u=i(Jt);ak=n(_u,`It is worth spending some time to create fitting model cards for each checkpoint. The model cards should highlight the
specific characteristics of this particular checkpoint, `),Yd=s(_u,"EM",{});var CT=i(Yd);sk=n(CT,"e.g."),CT.forEach(o),ik=n(_u,` On which dataset was the checkpoint
pretrained/fine-tuned on? On what down-stream task should the model be used? And also include some code on how to
correctly use the model.`),_u.forEach(o),gp=f(e),pa=s(e,"P",{});var LT=i(pa);Jd=s(LT,"STRONG",{});var qT=i(Jd);lk=n(qT,"13. (Optional) Add notebook"),qT.forEach(o),LT.forEach(o),wp=f(e),Xt=s(e,"P",{});var Eu=i(Xt);dk=n(Eu,"It is very helpful to add a notebook that showcases in-detail how "),Xd=s(Eu,"EM",{});var RT=i(Xd);hk=n(RT,"brand_new_bert"),RT.forEach(o),fk=n(Eu,` can be used for inference and/or
fine-tuned on a downstream task. This is not mandatory to merge your PR, but very useful for the community.`),Eu.forEach(o),vp=f(e),ua=s(e,"P",{});var ST=i(ua);Kd=s(ST,"STRONG",{});var DT=i(Kd);mk=n(DT,"14. Submit your finished PR"),DT.forEach(o),ST.forEach(o),bp=f(e),ca=s(e,"P",{});var FT=i(ca);pk=n(FT,`You\u2019re done programming now and can move to the last step, which is getting your PR merged into main. Usually, the
Hugging Face team should have helped you already at this point, but it is worth taking some time to give your finished
PR a nice description and eventually add comments to your code, if you want to point out certain design choices to your
reviewer.`),FT.forEach(o),_p=f(e),at=s(e,"H3",{class:!0});var ku=i(at);Kt=s(ku,"A",{id:!0,class:!0,href:!0});var HT=i(Kt);Qd=s(HT,"SPAN",{});var zT=i(Qd);u(zr.$$.fragment,zT),zT.forEach(o),HT.forEach(o),uk=f(ku),Vd=s(ku,"SPAN",{});var WT=i(Vd);ck=n(WT,"Share your work!!"),WT.forEach(o),ku.forEach(o),Ep=f(e),ya=s(e,"P",{});var GT=i(ya);yk=n(GT,`Now, it\u2019s time to get some credit from the community for your work! Having completed a model addition is a major
contribution to Transformers and the whole NLP community. Your code and the ported pre-trained models will certainly be
used by hundreds and possibly even thousands of developers and researchers. You should be proud of your work and share
your achievement with the community.`),GT.forEach(o),kp=f(e),ga=s(e,"P",{});var UT=i(ga);Zd=s(UT,"STRONG",{});var YT=i(Zd);gk=n(YT,"You have made another model that is super easy to access for everyone in the community! \u{1F92F}"),YT.forEach(o),UT.forEach(o),this.h()},h(){m(T,"name","hf:doc:metadata"),m(T,"content",JSON.stringify(n9)),m(A,"id","how-to-add-a-model-to-transformers"),m(A,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(A,"href","#how-to-add-a-model-to-transformers"),m(P,"class","relative group"),m(co,"href","https://pytorch.org/get-started/locally/"),m(co,"rel","nofollow"),m(yo,"href","https://github.com/huggingface/transformers/issues/new?assignees=&labels=New+model&template=new-model-addition.yml"),m(yo,"rel","nofollow"),m(go,"href","https://github.com/huggingface/transformers/labels/New%20model"),m(go,"rel","nofollow"),m(lt,"id","general-overview-of-transformers"),m(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"),m(lt,"href","#general-overview-of-transformers"),m(Re,"class","relative group"),m(Kr,"href","philosophy"),m(ft,"id","overview-of-models"),m(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"),m(ft,"href","#overview-of-models"),m(Se,"class","relative group"),m(Vr,"href","/docs/transformers/pr_19907/en/main_classes/model#transformers.PreTrainedModel"),m(Zr,"href","/docs/transformers/pr_19907/en/main_classes/configuration#transformers.PretrainedConfig"),ZT(tn.src,Ik="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers_overview.png")||m(tn,"src",Ik),m(on,"href","/docs/transformers/pr_19907/en/main_classes/model#transformers.PreTrainedModel"),m(rn,"href","/docs/transformers/pr_19907/en/main_classes/model#transformers.PreTrainedModel"),m(nn,"href","/docs/transformers/pr_19907/en/main_classes/model#transformers.PreTrainedModel.from_pretrained"),m(an,"href","/docs/transformers/pr_19907/en/main_classes/model#transformers.PreTrainedModel.save_pretrained"),m(sn,"href","/docs/transformers/pr_19907/en/main_classes/model#transformers.PreTrainedModel"),m(ln,"href","/docs/transformers/pr_19907/en/main_classes/configuration#transformers.PretrainedConfig"),m(dn,"href","/docs/transformers/pr_19907/en/main_classes/model#transformers.PreTrainedModel.save_pretrained"),m(hn,"href","/docs/transformers/pr_19907/en/main_classes/configuration#transformers.PretrainedConfig.save_pretrained"),m(mt,"id","code-style"),m(mt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(mt,"href","#code-style"),m(De,"class","relative group"),m(ko,"href","https://github.com/huggingface/transformers/blob/v4.17.0/src/transformers/models/roberta/modeling_roberta.py#L160"),m(ko,"rel","nofollow"),m(pt,"id","overview-of-tokenizers"),m(pt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(pt,"href","#overview-of-tokenizers"),m(We,"class","relative group"),m(ut,"id","stepbystep-recipe-to-add-a-model-to-transformers"),m(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"),m(ut,"href","#stepbystep-recipe-to-add-a-model-to-transformers"),m(Ge,"class","relative group"),m(Io,"href","https://medium.com/huggingface/from-tensorflow-to-pytorch-265f40ef2a28"),m(Io,"rel","nofollow"),m(Bo,"href","https://huggingface.co/thomwolf"),m(Bo,"rel","nofollow"),m(No,"href","https://huggingface.co/blog/porting-fsmt"),m(No,"rel","nofollow"),m(Mo,"href","https://huggingface.co/stas"),m(Mo,"rel","nofollow"),m(jo,"href","https://www.gnu.org/software/grep/"),m(jo,"rel","nofollow"),m(xo,"href","https://github.com/BurntSushi/ripgrep"),m(xo,"rel","nofollow"),m(yt,"id","1-optional-theoretical-aspects-of-brandnewbert"),m(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"),m(yt,"href","#1-optional-theoretical-aspects-of-brandnewbert"),m(Ue,"class","relative group"),m(gn,"href","model_summary"),m(Co,"href","https://huggingface.co/transformers/#contents"),m(Co,"rel","nofollow"),m(wt,"id","2-next-prepare-your-environment"),m(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"),m(wt,"href","#2-next-prepare-your-environment"),m(Ke,"class","relative group"),m(Ro,"href","https://github.com/huggingface/transformers"),m(Ro,"rel","nofollow"),m(Fo,"start","3"),m(Go,"href","https://pytorch.org/get-started/locally/"),m(Go,"rel","nofollow"),m(Wo,"start","4"),m(Yo,"start","5"),m(_t,"id","34-run-a-pretrained-checkpoint-using-the-original-repository"),m(_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"),m(_t,"href","#34-run-a-pretrained-checkpoint-using-the-original-repository"),m(Ve,"class","relative group"),m(Vo,"href","https://jupyter.org/"),m(Vo,"rel","nofollow"),m(Zo,"href","https://colab.research.google.com/notebooks/intro.ipynb"),m(Zo,"rel","nofollow"),m(or,"href","https://gist.github.com/LysandreJik/db4c948f6b4483960de5cbac598ad4ed"),m(or,"rel","nofollow"),m(rr,"href","https://github.com/tensorflow/mesh/tree/master/mesh_tensorflow"),m(rr,"rel","nofollow"),m(ar,"href","https://www.tensorflow.org/api_docs/python/tf/print"),m(ar,"rel","nofollow"),m(sr,"href","https://github.com/google/jax/issues/196"),m(sr,"rel","nofollow"),m(Mt,"id","514-port-brandnewbert-to-transformers"),m(Mt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(Mt,"href","#514-port-brandnewbert-to-transformers"),m(ot,"class","relative group"),m(Nn,"href","#write-a-conversion-script"),m(hr,"href","https://github.com/huggingface/transformers/tree/main/templates/adding_a_new_model"),m(hr,"rel","nofollow"),m(mr,"start","2"),m(ur,"start","3"),m(yr,"start","4"),m(rt,"start","5"),m(br,"href","https://github.com/huggingface/transformers/blob/7acfa95afb8194f8f9c1f4d2c6028224dbed35a2/src/transformers/models/bert/modeling_bert.py#L91"),m(br,"rel","nofollow"),m(_r,"href","https://github.com/huggingface/transformers/blob/main/src/transformers/models/bart/convert_bart_original_pytorch_checkpoint_to_pytorch.py"),m(_r,"rel","nofollow"),m(Kn,"href","#run-a-pretrained-checkpoint-using-the-original-repository"),m(Or,"href","https://pytorch.org/docs/stable/nn.functional.html?highlight=dropout#torch.nn.functional.dropout"),m(Or,"rel","nofollow"),m(aa,"href","writing-documentation"),m(ma,"href","model_sharing"),m(Kt,"id","share-your-work"),m(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"),m(Kt,"href","#share-your-work"),m(at,"class","relative group")},m(e,l){t(document.head,T),d(e,U,l),d(e,P,l),t(P,A),t(A,z),c(B,z,null),t(P,C),t(P,L),t(L,fe),d(e,uo,l),d(e,me,l),t(me,Tu),t(me,co),t(co,$u),t(me,Pu),d(e,oh,l),c(it,e,l),d(e,rh,l),d(e,Ur,l),t(Ur,Iu),d(e,nh,l),d(e,Y,l),t(Y,Da),t(Da,Bu),t(Y,Au),t(Y,Fa),t(Fa,Nu),t(Y,Mu),t(Y,Ha),t(Ha,ju),t(Y,xu),t(Y,pe),t(pe,Ou),t(pe,za),t(za,Cu),t(pe,Lu),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,Gc),t(v,sn),t(sn,Uc),t(v,Yc),t(v,ds),t(ds,Jc),t(v,Xc),t(v,hs),t(hs,Kc),t(v,Qc),d(e,vh,l),c(_o,e,l),d(e,bh,l),d(e,N,l),t(N,Vc),t(N,ln),t(ln,Zc),t(N,ey),t(N,fs),t(fs,ty),t(N,oy),t(N,ms),t(ms,ry),t(N,ny),t(N,dn),t(dn,ay),t(N,sy),t(N,hn),t(hn,iy),t(N,ly),d(e,_h,l),d(e,De,l),t(De,mt),t(mt,ps),c(Eo,ps,null),t(De,dy),t(De,us),t(us,hy),d(e,Eh,l),d(e,fn,l),t(fn,fy),d(e,kh,l),d(e,q,l),t(q,Fe),t(Fe,my),t(Fe,cs),t(cs,py),t(Fe,uy),t(Fe,ko),t(ko,cy),t(Fe,yy),t(q,gy),t(q,He),t(He,wy),t(He,ys),t(ys,vy),t(He,by),t(He,gs),t(gs,_y),t(He,Ey),t(q,ky),t(q,ws),t(ws,Ty),t(q,$y),t(q,ze),t(ze,Py),t(ze,vs),t(vs,Iy),t(ze,By),t(ze,bs),t(bs,Ay),t(ze,Ny),t(q,My),t(q,_s),t(_s,jy),d(e,Th,l),d(e,We,l),t(We,pt),t(pt,Es),c(To,Es,null),t(We,xy),t(We,ks),t(ks,Oy),d(e,$h,l),d(e,mn,l),t(mn,Cy),d(e,Ph,l),d(e,Ge,l),t(Ge,ut),t(ut,Ts),c($o,Ts,null),t(Ge,Ly),t(Ge,$s),t($s,qy),d(e,Ih,l),d(e,pn,l),t(pn,Ry),d(e,Bh,l),d(e,ct,l),t(ct,Po),t(Po,Io),t(Io,Sy),t(Po,Dy),t(Po,Bo),t(Bo,Fy),t(ct,Hy),t(ct,Ao),t(Ao,No),t(No,zy),t(Ao,Wy),t(Ao,Mo),t(Mo,Gy),d(e,Ah,l),d(e,un,l),t(un,Uy),d(e,Nh,l),d(e,be,l),t(be,ue),t(ue,Yy),t(ue,jo),t(jo,Jy),t(ue,Xy),t(ue,xo),t(xo,Ky),t(ue,Qy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dd),t(Dd,qE),t(Ae,RE),t(Ae,aa),t(aa,SE),t(Ae,DE),d(e,ap,l),d(e,sa,l),t(sa,Fd),t(Fd,FE),d(e,sp,l),d(e,Yt,l),t(Yt,HE),t(Yt,Hd),t(Hd,zE),t(Yt,WE),d(e,ip,l),c(Dr,e,l),d(e,lp,l),d(e,ia,l),t(ia,GE),d(e,dp,l),c(Fr,e,l),d(e,hp,l),d(e,la,l),t(la,UE),d(e,fp,l),d(e,da,l),t(da,YE),d(e,mp,l),d(e,ha,l),t(ha,JE),d(e,pp,l),d(e,fa,l),t(fa,zd),t(zd,XE),d(e,up,l),d(e,H,l),t(H,KE),t(H,ma),t(ma,QE),t(H,VE),t(H,Wd),t(Wd,ZE),t(H,ek),t(H,Gd),t(Gd,tk),t(H,ok),t(H,Ud),t(Ud,rk),t(H,nk),d(e,cp,l),c(Hr,e,l),d(e,yp,l),d(e,Jt,l),t(Jt,ak),t(Jt,Yd),t(Yd,sk),t(Jt,ik),d(e,gp,l),d(e,pa,l),t(pa,Jd),t(Jd,lk),d(e,wp,l),d(e,Xt,l),t(Xt,dk),t(Xt,Xd),t(Xd,hk),t(Xt,fk),d(e,vp,l),d(e,ua,l),t(ua,Kd),t(Kd,mk),d(e,bp,l),d(e,ca,l),t(ca,pk),d(e,_p,l),d(e,at,l),t(at,Kt),t(Kt,Qd),c(zr,Qd,null),t(at,uk),t(at,Vd),t(Vd,ck),d(e,Ep,l),d(e,ya,l),t(ya,yk),d(e,kp,l),d(e,ga,l),t(ga,Zd),t(Zd,gk),Tp=!0},p(e,[l]){const Wr={};l&2&&(Wr.$$scope={dirty:l,ctx:e}),it.$set(Wr);const eh={};l&2&&(eh.$$scope={dirty:l,ctx:e}),Ht.$set(eh)},i(e){Tp||(y(B.$$.fragment,e),y(it.$$.fragment,e),y(wo.$$.fragment,e),y(bo.$$.fragment,e),y(_o.$$.fragment,e),y(Eo.$$.fragment,e),y(To.$$.fragment,e),y($o.$$.fragment,e),y(Oo.$$.fragment,e),y(Lo.$$.fragment,e),y(Do.$$.fragment,e),y(Ho.$$.fragment,e),y(zo.$$.fragment,e),y(Xo.$$.fragment,e),y(Ko.$$.fragment,e),y(er.$$.fragment,e),y(nr.$$.fragment,e),y(lr.$$.fragment,e),y(dr.$$.fragment,e),y(fr.$$.fragment,e),y(pr.$$.fragment,e),y(cr.$$.fragment,e),y(gr.$$.fragment,e),y(wr.$$.fragment,e),y(vr.$$.fragment,e),y(Er.$$.fragment,e),y(kr.$$.fragment,e),y(Tr.$$.fragment,e),y($r.$$.fragment,e),y(Pr.$$.fragment,e),y(Br.$$.fragment,e),y(Ar.$$.fragment,e),y(Mr.$$.fragment,e),y(jr.$$.fragment,e),y(xr.$$.fragment,e),y(Cr.$$.fragment,e),y(Lr.$$.fragment,e),y(Ht.$$.fragment,e),y(Rr.$$.fragment,e),y(Sr.$$.fragment,e),y(Dr.$$.fragment,e),y(Fr.$$.fragment,e),y(Hr.$$.fragment,e),y(zr.$$.fragment,e),Tp=!0)},o(e){g(B.$$.fragment,e),g(it.$$.fragment,e),g(wo.$$.fragment,e),g(bo.$$.fragment,e),g(_o.$$.fragment,e),g(Eo.$$.fragment,e),g(To.$$.fragment,e),g($o.$$.fragment,e),g(Oo.$$.fragment,e),g(Lo.$$.fragment,e),g(Do.$$.fragment,e),g(Ho.$$.fragment,e),g(zo.$$.fragment,e),g(Xo.$$.fragment,e),g(Ko.$$.fragment,e),g(er.$$.fragment,e),g(nr.$$.fragment,e),g(lr.$$.fragment,e),g(dr.$$.fragment,e),g(fr.$$.fragment,e),g(pr.$$.fragment,e),g(cr.$$.fragment,e),g(gr.$$.fragment,e),g(wr.$$.fragment,e),g(vr.$$.fragment,e),g(Er.$$.fragment,e),g(kr.$$.fragment,e),g(Tr.$$.fragment,e),g($r.$$.fragment,e),g(Pr.$$.fragment,e),g(Br.$$.fragment,e),g(Ar.$$.fragment,e),g(Mr.$$.fragment,e),g(jr.$$.fragment,e),g(xr.$$.fragment,e),g(Cr.$$.fragment,e),g(Lr.$$.fragment,e),g(Ht.$$.fragment,e),g(Rr.$$.fragment,e),g(Sr.$$.fragment,e),g(Dr.$$.fragment,e),g(Fr.$$.fragment,e),g(Hr.$$.fragment,e),g(zr.$$.fragment,e),Tp=!1},d(e){o(T),e&&o(U),e&&o(P),w(B),e&&o(uo),e&&o(me),e&&o(oh),w(it,e),e&&o(rh),e&&o(Ur),e&&o(nh),e&&o(Y),e&&o(ah),e&&o(Yr),e&&o(sh),e&&o(we),e&&o(ih),e&&o(Jr),e&&o(lh),e&&o(Re),w(wo),e&&o(dh),e&&o(Xr),e&&o(hh),e&&o(dt),e&&o(fh),e&&o(ve),e&&o(mh),e&&o(ht),e&&o(ph),e&&o(Qr),e&&o(uh),e&&o(Se),w(bo),e&&o(ch),e&&o(J),e&&o(yh),e&&o(en),e&&o(gh),e&&o(tn),e&&o(wh),e&&o(v),e&&o(vh),w(_o,e),e&&o(bh),e&&o(N),e&&o(_h),e&&o(De),w(Eo),e&&o(Eh),e&&o(fn),e&&o(kh),e&&o(q),e&&o(Th),e&&o(We),w(To),e&&o($h),e&&o(mn),e&&o(Ph),e&&o(Ge),w($o),e&&o(Ih),e&&o(pn),e&&o(Bh),e&&o(ct),e&&o(Ah),e&&o(un),e&&o(Nh),e&&o(be),e&&o(Mh),e&&o(cn),e&&o(jh),e&&o(yn),e&&o(xh),e&&o(b),e&&o(Oh),e&&o(R),e&&o(Ch),e&&o(Ue),w(Oo),e&&o(Lh),e&&o(gt),e&&o(qh),e&&o(S),e&&o(Rh),e&&o(wn),e&&o(Sh),e&&o(Ke),w(Lo),e&&o(Dh),e&&o(vt),e&&o(Fh),w(Do,e),e&&o(Hh),e&&o(Fo),e&&o(zh),w(Ho,e),e&&o(Wh),e&&o(vn),e&&o(Gh),w(zo,e),e&&o(Uh),e&&o(Wo),e&&o(Yh),e&&o(Uo),e&&o(Jh),e&&o(Yo),e&&o(Xh),w(Xo,e),e&&o(Kh),e&&o(bt),e&&o(Qh),e&&o(Ve),w(Ko),e&&o(Vh),e&&o(M),e&&o(Zh),e&&o(bn),e&&o(ef),e&&o(Et),e&&o(tf),e&&o(j),e&&o(of),e&&o(kt),e&&o(rf),e&&o(_n),e&&o(nf),e&&o(En),e&&o(af),e&&o(Tt),e&&o(sf),e&&o(kn),e&&o(lf),e&&o($t),e&&o(df),e&&o(Pt),e&&o(hf),w(er,e),e&&o(ff),e&&o(Tn),e&&o(mf),e&&o(It),e&&o(pf),e&&o($n),e&&o(uf),e&&o(Bt),e&&o(cf),e&&o(X),e&&o(yf),e&&o(tr),e&&o(gf),e&&o(At),e&&o(wf),e&&o(Pn),e&&o(vf),e&&o(In),e&&o(bf),e&&o(x),e&&o(_f),e&&o(tt),e&&o(Ef),e&&o(Bn),e&&o(kf),w(nr,e),e&&o(Tf),e&&o(_e),e&&o($f),e&&o(D),e&&o(Pf),e&&o(Nt),e&&o(If),e&&o(ot),w(lr),e&&o(Bf),e&&o(An),e&&o(Af),w(dr,e),e&&o(Nf),e&&o(jt),e&&o(Mf),e&&o(Mn),e&&o(jf),e&&o(xt),e&&o(xf),e&&o(Ee),e&&o(Of),e&&o(On),e&&o(Cf),e&&o(ke),e&&o(Lf),e&&o(Cn),e&&o(qf),e&&o(Ln),e&&o(Rf),w(fr,e),e&&o(Sf),e&&o(mr),e&&o(Df),w(pr,e),e&&o(Ff),e&&o(ur),e&&o(Hf),w(cr,e),e&&o(zf),e&&o(yr),e&&o(Wf),w(gr,e),e&&o(Gf),e&&o(rt),e&&o(Uf),e&&o(qn),e&&o(Yf),w(wr,e),e&&o(Jf),e&&o(Rn),e&&o(Xf),e&&o(Sn),e&&o(Kf),e&&o(Dn),e&&o(Qf),e&&o(Fn),e&&o(Vf),e&&o(Te),e&&o(Zf),e&&o(K),e&&o(em),e&&o(O),e&&o(tm),w(vr,e),e&&o(om),e&&o($e),e&&o(rm),e&&o(Hn),e&&o(nm),e&&o(Q),e&&o(am),e&&o(Ot),e&&o(sm),e&&o(Ct),e&&o(im),w(Er,e),e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t),e&&o(gp),e&&o(pa),e&&o(wp),e&&o(Xt),e&&o(vp),e&&o(ua),e&&o(bp),e&&o(ca),e&&o(_p),e&&o(at),w(zr),e&&o(Ep),e&&o(ya),e&&o(kp),e&&o(ga)}}}const n9={local:"how-to-add-a-model-to-transformers",sections:[{local:"general-overview-of-transformers",sections:[{local:"overview-of-models",title:"Overview of models"},{local:"code-style",title:"Code style"},{local:"overview-of-tokenizers",title:"Overview of tokenizers"}],title:"General overview of \u{1F917} Transformers"},{local:"stepbystep-recipe-to-add-a-model-to-transformers",sections:[{local:"1-optional-theoretical-aspects-of-brandnewbert",title:"1. (Optional) Theoretical aspects of BrandNewBert"},{local:"2-next-prepare-your-environment",title:"2. Next prepare your environment"},{local:"34-run-a-pretrained-checkpoint-using-the-original-repository",title:"3.-4. Run a pretrained checkpoint using the original repository"},{local:"514-port-brandnewbert-to-transformers",title:"5.-14. Port BrandNewBert to \u{1F917} Transformers"},{local:"share-your-work",title:"Share your work!!"}],title:"Step-by-step recipe to add a model to \u{1F917} Transformers"}],title:"How to add a model to \u{1F917} Transformers?"};function a9(Gr){return e9(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class h9 extends XT{constructor(T){super();KT(this,T,a9,r9,QT,{})}}export{h9 as default,n9 as metadata};
