import{s as Hl,o as El,n as xe}from"../chunks/scheduler.9bc65507.js";import{S as Fl,i as Sl,g as i,s as n,r as c,A as Ll,h as r,f as l,c as a,j as Ql,u as m,x as M,k as zl,y as ql,a as s,v as d,d as y,t as u,w as f}from"../chunks/index.707bf1b6.js";import{T as Xe}from"../chunks/Tip.c2ecdbf4.js";import{C as J}from"../chunks/CodeBlock.54a9f38d.js";import{H as Be}from"../chunks/Heading.342b1fa6.js";function Pl(j){let o,h=`Models in the <code>transformers</code> library itself generally follow the convention that they accept a <code>config</code> object
in their <code>__init__</code> method, and then pass the whole <code>config</code> to sub-layers in the model, rather than breaking the
config object into multiple arguments that are all passed individually to sub-layers. Writing your model in this
style results in simpler code with a clear “source of truth” for any hyperparameters, and also makes it easier
to reuse code from other models in <code>transformers</code>.`;return{c(){o=i("p"),o.innerHTML=h},l(p){o=r(p,"P",{"data-svelte-h":!0}),M(o)!=="svelte-1qp2x4n"&&(o.innerHTML=h)},m(p,w){s(p,o,w)},p:xe,d(p){p&&l(o)}}}function Dl(j){let o,h="If your model is very similar to a model inside the library, you can re-use the same configuration as this model.";return{c(){o=i("p"),o.textContent=h},l(p){o=r(p,"P",{"data-svelte-h":!0}),M(o)!=="svelte-alg4p1"&&(o.textContent=h)},m(p,w){s(p,o,w)},p:xe,d(p){p&&l(o)}}}function Kl(j){let o,h="This API is experimental and may have some slight breaking changes in the next releases.";return{c(){o=i("p"),o.textContent=h},l(p){o=r(p,"P",{"data-svelte-h":!0}),M(o)!=="svelte-15rpg4"&&(o.textContent=h)},m(p,w){s(p,o,w)},p:xe,d(p){p&&l(o)}}}function Ol(j){let o,h=`If copying a modeling files from the library, you will need to replace all the relative imports at the top of the file
to import from the <code>transformers</code> package.`;return{c(){o=i("p"),o.innerHTML=h},l(p){o=r(p,"P",{"data-svelte-h":!0}),M(o)!=="svelte-1816fmc"&&(o.innerHTML=h)},m(p,w){s(p,o,w)},p:xe,d(p){p&&l(o)}}}function es(j){let o,h=`Use <code>register_for_auto_class()</code> if you want the code files to be copied. If you instead prefer to use code on the Hub from another repo,
you don’t need to call it. In cases where there’s more than one auto class, you can modify the <code>config.json</code> directly using the
following structure:`,p,w,U;return w=new J({props:{code:"JTIyYXV0b19tYXAlMjIlM0ElMjAlN0IlMjAlMjAlMjAlMjAlMjAlMEElMDklMjJBdXRvQ29uZmlnJTIyJTNBJTIwJTIyJTNDeW91ci1yZXBvLW5hbWUlM0UtLSUzQ2NvbmZpZy1uYW1lJTNFJTIyJTJDJTIwJTIwJTIwJTIwJTIwJTBBJTA5JTIyQXV0b01vZGVsJTIyJTNBJTIwJTIyJTNDeW91ci1yZXBvLW5hbWUlM0UtLSUzQ2NvbmZpZy1uYW1lJTNFJTIyJTJDJTBBJTA5JTIyQXV0b01vZGVsRm9yJTNDVGFzayUzRSUyMiUzQSUyMCUyMiUzQ3lvdXItcmVwby1uYW1lJTNFLS0lM0Njb25maWctbmFtZSUzRSUyMiUyQyUyMCUyMCUyMCUyMCUwQSU3RCUyQw==",highlighted:`<span class="hljs-attr">&quot;auto_map&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>     
	<span class="hljs-attr">&quot;AutoConfig&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;&lt;your-repo-name&gt;--&lt;config-name&gt;&quot;</span><span class="hljs-punctuation">,</span>     
	<span class="hljs-attr">&quot;AutoModel&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;&lt;your-repo-name&gt;--&lt;config-name&gt;&quot;</span><span class="hljs-punctuation">,</span>
	<span class="hljs-attr">&quot;AutoModelFor&lt;Task&gt;&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;&lt;your-repo-name&gt;--&lt;config-name&gt;&quot;</span><span class="hljs-punctuation">,</span>    
<span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>`,wrap:!1}}),{c(){o=i("p"),o.innerHTML=h,p=n(),c(w.$$.fragment)},l(T){o=r(T,"P",{"data-svelte-h":!0}),M(o)!=="svelte-1rexmhi"&&(o.innerHTML=h),p=a(T),m(w.$$.fragment,T)},m(T,b){s(T,o,b),s(T,p,b),d(w,T,b),U=!0},p:xe,i(T){U||(y(w.$$.fragment,T),U=!0)},o(T){u(w.$$.fragment,T),U=!1},d(T){T&&(l(o),l(p)),f(w,T)}}}function ts(j){let o,h,p,w,U,T,b,Kt=`The 🤗 Transformers library is designed to be easily extensible. Every model is fully coded in a given subfolder
of the repository with no abstraction, so you can easily copy a modeling file and tweak it to your needs.`,Ye,$,Ot=`If you are writing a brand new model, it might be easier to start from scratch. In this tutorial, we will show you
how to write a custom model and its configuration so it can be used inside Transformers, and how you can share it
with the community (with the code it relies on) so that anyone can use it, even if it’s not present in the 🤗
Transformers library. We’ll see how to build upon transformers and extend the framework with your hooks and
custom code.`,Ge,A,el=`We will illustrate all of this on a ResNet model, by wrapping the ResNet class of the
<a href="https://github.com/rwightman/pytorch-image-models" rel="nofollow">timm library</a> into a <a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>.`,Ve,k,Qe,v,tl=`Before we dive into the model, let’s first write its configuration. The configuration of a model is an object that
will contain all the necessary information to build the model. As we will see in the next section, the model can only
take a <code>config</code> to be initialized, so we really need that object to be as complete as possible.`,ze,C,He,N,ll=`In our example, we will take a couple of arguments of the ResNet class that we might want to tweak. Different
configurations will then give us the different types of ResNets that are possible. We then just store those arguments,
after checking the validity of a few of them.`,Ee,W,Fe,B,sl="The three important things to remember when writing you own configuration are the following:",Se,R,nl="<li>you have to inherit from <code>PretrainedConfig</code>,</li> <li>the <code>__init__</code> of your <code>PretrainedConfig</code> must accept any kwargs,</li> <li>those <code>kwargs</code> need to be passed to the superclass <code>__init__</code>.</li>",Le,X,al=`The inheritance is to make sure you get all the functionality from the 🤗 Transformers library, while the two other
constraints come from the fact a <code>PretrainedConfig</code> has more fields than the ones you are setting. When reloading a
config with the <code>from_pretrained</code> method, those fields need to be accepted by your config and then sent to the
superclass.`,qe,x,ol=`Defining a <code>model_type</code> for your configuration (here <code>model_type=&quot;resnet&quot;</code>) is not mandatory, unless you want to
register your model with the auto classes (see last section).`,Pe,Y,il=`With this done, you can easily create and save your configuration like you would do with any other model config of the
library. Here is how we can create a resnet50d config and save it:`,De,G,Ke,V,rl=`This will save a file named <code>config.json</code> inside the folder <code>custom-resnet</code>. You can then reload your config with the
<code>from_pretrained</code> method:`,Oe,Q,et,z,Ml=`You can also use any other method of the <a href="/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig">PretrainedConfig</a> class, like <a href="/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.push_to_hub">push_to_hub()</a> to
directly upload your config to the Hub.`,tt,H,lt,E,pl=`Now that we have our ResNet configuration, we can go on writing the model. We will actually write two: one that
extracts the hidden features from a batch of images (like <a href="/docs/transformers/main/en/model_doc/bert#transformers.BertModel">BertModel</a>) and one that is suitable for image
classification (like <a href="/docs/transformers/main/en/model_doc/bert#transformers.BertForSequenceClassification">BertForSequenceClassification</a>).`,st,F,cl=`As we mentioned before, we’ll only write a loose wrapper of the model to keep it simple for this example. The only
thing we need to do before writing this class is a map between the block types and actual block classes. Then the
model is defined from the configuration by passing everything to the <code>ResNet</code> class:`,nt,S,at,L,ml="For the model that will classify images, we just change the forward method:",ot,q,it,P,dl=`In both cases, notice how we inherit from <code>PreTrainedModel</code> and call the superclass initialization with the <code>config</code>
(a bit like when you write a regular <code>torch.nn.Module</code>). The line that sets the <code>config_class</code> is not mandatory, unless
you want to register your model with the auto classes (see last section).`,rt,g,Mt,D,yl=`You can have your model return anything you want, but returning a dictionary like we did for
<code>ResnetModelForImageClassification</code>, with the loss included when labels are passed, will make your model directly
usable inside the <a href="/docs/transformers/main/en/main_classes/trainer#transformers.Trainer">Trainer</a> class. Using another output format is fine as long as you are planning on using your own
training loop or another library for training.`,pt,K,ul="Now that we have our model class, let’s create one:",ct,O,mt,ee,fl=`Again, you can use any of the methods of <a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>, like <a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.save_pretrained">save_pretrained()</a> or
<a href="/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.push_to_hub">push_to_hub()</a>. We will use the second in the next section, and see how to push the model weights
with the code of our model. But first, let’s load some pretrained weights inside our model.`,dt,te,wl=`In your own use case, you will probably be training your custom model on your own data. To go fast for this tutorial,
we will use the pretrained version of the resnet50d. Since our model is just a wrapper around it, it’s going to be
easy to transfer those weights:`,yt,le,ut,se,hl=`Now let’s see how to make sure that when we do <a href="/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.save_pretrained">save_pretrained()</a> or <a href="/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast.push_to_hub">push_to_hub()</a>, the
code of the model is saved.`,ft,ne,wt,ae,Tl=`If you are writing a library that extends 🤗 Transformers, you may want to extend the auto classes to include your own
model. This is different from pushing the code to the Hub in the sense that users will need to import your library to
get the custom models (contrarily to automatically downloading the model code from the Hub).`,ht,oe,Jl=`As long as your config has a <code>model_type</code> attribute that is different from existing model types, and that your model
classes have the right <code>config_class</code> attributes, you can just add them to the auto classes like this:`,Tt,ie,Jt,re,jl=`Note that the first argument used when registering your custom config to <a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoConfig">AutoConfig</a> needs to match the <code>model_type</code>
of your custom config, and the first argument used when registering your custom models to any auto model class needs
to match the <code>config_class</code> of those models.`,jt,Me,Ut,I,bt,pe,Ul=`First, make sure your model is fully defined in a <code>.py</code> file. It can rely on relative imports to some other files as
long as all the files are in the same directory (we don’t support submodules for this feature yet). For our example,
we’ll define a <code>modeling_resnet.py</code> file and a <code>configuration_resnet.py</code> file in a folder of the current working
directory named <code>resnet_model</code>. The configuration file contains the code for <code>ResnetConfig</code> and the modeling file
contains the code of <code>ResnetModel</code> and <code>ResnetModelForImageClassification</code>.`,Ct,ce,gt,me,bl="The <code>__init__.py</code> can be empty, it’s just there so that Python detects <code>resnet_model</code> can be use as a module.",It,_,_t,de,Cl="Note that you can re-use (or subclass) an existing configuration/model.",Zt,ye,gl=`To share your model with the community, follow those steps: first import the ResNet model and config from the newly
created files:`,$t,ue,At,fe,Il=`Then you have to tell the library you want to copy the code files of those objects when using the <code>save_pretrained</code>
method and properly register them with a given Auto class (especially for models), just run:`,kt,we,vt,he,_l=`Note that there is no need to specify an auto class for the configuration (there is only one auto class for them,
<a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoConfig">AutoConfig</a>) but it’s different for models. Your custom model could be suitable for many different tasks, so you
have to specify which one of the auto classes is the correct one for your model.`,Nt,Z,Wt,Te,Zl="Next, let’s create the config and models as we did before:",Bt,Je,Rt,je,$l="Now to send the model to the Hub, make sure you are logged in. Either run in your terminal:",Xt,Ue,xt,be,Al="or from a notebook:",Yt,Ce,Gt,ge,kl="You can then push to your own namespace (or an organization you are a member of) like this:",Vt,Ie,Qt,_e,vl=`On top of the modeling weights and the configuration in json format, this also copied the modeling and
configuration <code>.py</code> files in the folder <code>custom-resnet50d</code> and uploaded the result to the Hub. You can check the result
in this <a href="https://huggingface.co/sgugger/custom-resnet50d" rel="nofollow">model repo</a>.`,zt,Ze,Nl='See the <a href="model_sharing">sharing tutorial</a> for more information on the push to Hub method.',Ht,$e,Et,Ae,Wl=`You can use any configuration, model or tokenizer with custom code files in its repository with the auto-classes and
the <code>from_pretrained</code> method. All files and code uploaded to the Hub are scanned for malware (refer to the <a href="https://huggingface.co/docs/hub/security#malware-scanning" rel="nofollow">Hub security</a> documentation for more information), but you should still
review the model code and author to avoid executing malicious code on your machine. Set <code>trust_remote_code=True</code> to use
a model with custom code:`,Ft,ke,St,ve,Bl=`It is also strongly encouraged to pass a commit hash as a <code>revision</code> to make sure the author of the models did not
update the code with some malicious new lines (unless you fully trust the authors of the models).`,Lt,Ne,qt,We,Rl=`Note that when browsing the commit history of the model repo on the Hub, there is a button to easily copy the commit
hash of any commit.`,Pt,Re,Dt;return U=new Be({props:{title:"Building custom models",local:"building-custom-models",headingTag:"h1"}}),k=new Be({props:{title:"Writing a custom configuration",local:"writing-a-custom-configuration",headingTag:"h2"}}),C=new Xe({props:{$$slots:{default:[Pl]},$$scope:{ctx:j}}}),W=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFByZXRyYWluZWRDb25maWclMEFmcm9tJTIwdHlwaW5nJTIwaW1wb3J0JTIwTGlzdCUwQSUwQSUwQWNsYXNzJTIwUmVzbmV0Q29uZmlnKFByZXRyYWluZWRDb25maWcpJTNBJTBBJTIwJTIwJTIwJTIwbW9kZWxfdHlwZSUyMCUzRCUyMCUyMnJlc25ldCUyMiUwQSUwQSUyMCUyMCUyMCUyMGRlZiUyMF9faW5pdF9fKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHNlbGYlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBibG9ja190eXBlJTNEJTIyYm90dGxlbmVjayUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxheWVycyUzQSUyMExpc3QlNUJpbnQlNUQlMjAlM0QlMjAlNUIzJTJDJTIwNCUyQyUyMDYlMkMlMjAzJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbnVtX2NsYXNzZXMlM0ElMjBpbnQlMjAlM0QlMjAxMDAwJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaW5wdXRfY2hhbm5lbHMlM0ElMjBpbnQlMjAlM0QlMjAzJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY2FyZGluYWxpdHklM0ElMjBpbnQlMjAlM0QlMjAxJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYmFzZV93aWR0aCUzQSUyMGludCUyMCUzRCUyMDY0JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc3RlbV93aWR0aCUzQ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ElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBzZWxmLmxheWVycyUyMCUzRCUyMGxheWVycyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHNlbGYubnVtX2NsYXNzZXMlMjAlM0QlMjBudW1fY2xhc3NlcyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHNlbGYuaW5wdXRfY2hhbm5lbHMlMjAlM0QlMjBpbnB1dF9jaGFubmVscyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHNlbGYuY2FyZGluYWxpdHklMjAlM0QlMjBjYXJkaW5hbGl0eSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHNlbGYuYmFzZV93aWR0aCUyMCUzRCUyMGJhc2Vfd2lkdGglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBzZWxmLnN0ZW1fd2lkdGglMjAlM0QlMjBzdGVtX3dpZHRoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2VsZi5zdGVtX3R5cGUlMjAlM0QlMjBzdGVtX3R5cGUlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBzZWxmLmF2Z19kb3duJTIwJTNEJTIwYXZnX2Rvd24lMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBzdXBlcigpLl9faW5pdF9fKCoqa3dhcmdzKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> PretrainedConfig
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> <span class="hljs-type">List</span>


<span class="hljs-keyword">class</span> <span class="hljs-title class_">ResnetConfig</span>(<span class="hljs-title class_ inherited__">PretrainedConfig</span>):
    model_type = <span class="hljs-string">&quot;resnet&quot;</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">
        self,
        block_type=<span class="hljs-string">&quot;bottleneck&quot;</span>,
        layers: <span class="hljs-type">List</span>[<span class="hljs-built_in">int</span>] = [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">6</span>, <span class="hljs-number">3</span>],
        num_classes: <span class="hljs-built_in">int</span> = <span class="hljs-number">1000</span>,
        input_channels: <span class="hljs-built_in">int</span> = <span class="hljs-number">3</span>,
        cardinality: <span class="hljs-built_in">int</span> = <span class="hljs-number">1</span>,
        base_width: <span class="hljs-built_in">int</span> = <span class="hljs-number">64</span>,
        stem_width: <span class="hljs-built_in">int</span> = <span class="hljs-number">64</span>,
        stem_type: <span class="hljs-built_in">str</span> = <span class="hljs-string">&quot;&quot;</span>,
        avg_down: <span class="hljs-built_in">bool</span> = <span class="hljs-literal">False</span>,
        **kwargs,
    </span>):
        <span class="hljs-keyword">if</span> block_type <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;basic&quot;</span>, <span class="hljs-string">&quot;bottleneck&quot;</span>]:
            <span class="hljs-keyword">raise</span> ValueError(<span class="hljs-string">f&quot;\`block_type\` must be &#x27;basic&#x27; or bottleneck&#x27;, got <span class="hljs-subst">{block_type}</span>.&quot;</span>)
        <span class="hljs-keyword">if</span> stem_type <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;&quot;</span>, <span class="hljs-string">&quot;deep&quot;</span>, <span class="hljs-string">&quot;deep-tiered&quot;</span>]:
            <span class="hljs-keyword">raise</span> ValueError(<span class="hljs-string">f&quot;\`stem_type\` must be &#x27;&#x27;, &#x27;deep&#x27; or &#x27;deep-tiered&#x27;, got <span class="hljs-subst">{stem_type}</span>.&quot;</span>)

        self.block_type = block_type
        self.layers = layers
        self.num_classes = num_classes
        self.input_channels = input_channels
        self.cardinality = cardinality
        self.base_width = base_width
        self.stem_width = stem_width
        self.stem_type = stem_type
        self.avg_down = avg_down
        <span class="hljs-built_in">super</span>().__init__(**kwargs)`,wrap:!1}}),G=new J({props:{code:"cmVzbmV0NTBkX2NvbmZpZyUyMCUzRCUyMFJlc25ldENvbmZpZyhibG9ja190eXBlJTNEJTIyYm90dGxlbmVjayUyMiUyQyUyMHN0ZW1fd2lkdGglM0QzMiUyQyUyMHN0ZW1fdHlwZSUzRCUyMmRlZXAlMjIlMkMlMjBhdmdfZG93biUzRFRydWUpJTBBcmVzbmV0NTBkX2NvbmZpZy5zYXZlX3ByZXRyYWluZWQoJTIyY3VzdG9tLXJlc25ldCUyMik=",highlighted:`resnet50d_config = ResnetConfig(block_type=<span class="hljs-string">&quot;bottleneck&quot;</span>, stem_width=<span class="hljs-number">32</span>, stem_type=<span class="hljs-string">&quot;deep&quot;</span>, avg_down=<span class="hljs-literal">True</span>)
resnet50d_config.save_pretrained(<span class="hljs-string">&quot;custom-resnet&quot;</span>)`,wrap:!1}}),Q=new J({props:{code:"cmVzbmV0NTBkX2NvbmZpZyUyMCUzRCUyMFJlc25ldENvbmZpZy5mcm9tX3ByZXRyYWluZWQoJTIyY3VzdG9tLXJlc25ldCUyMik=",highlighted:'resnet50d_config = ResnetConfig.from_pretrained(<span class="hljs-string">&quot;custom-resnet&quot;</span>)',wrap:!1}}),H=new Be({props:{title:"Writing a custom model",local:"writing-a-custom-model",headingTag:"h2"}}),S=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFByZVRyYWluZWRNb2RlbCUwQWZyb20lMjB0aW1tLm1vZGVscy5yZXNuZXQlMjBpbXBvcnQlMjBCYXNpY0Jsb2NrJTJDJTIwQm90dGxlbmVjayUyQyUyMFJlc05ldCUwQWZyb20lMjAuY29uZmlndXJhdGlvbl9yZXNuZXQlMjBpbXBvcnQlMjBSZXNuZXRDb25maWclMEElMEElMEFCTE9DS19NQVBQSU5HJTIwJTNEJTIwJTdCJTIyYmFzaWMlMjIlM0ElMjBCYXNpY0Jsb2NrJTJDJTIwJTIyYm90dGxlbmVjayUyMiUzQSUyMEJvdHRsZW5lY2slN0QlMEElMEElMEFjbGFzcyUyMFJlc25ldE1vZGVsKFByZVRyYWluZWRNb2RlbCklM0ElMEElM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VtX3R5cGUlM0Rjb25maWcuc3RlbV90eXBlJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYXZnX2Rvd24lM0Rjb25maWcuYXZnX2Rvd24lMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjApJTBBJTBBJTIwJTIwJTIwJTIwZGVmJTIwZm9yd2FyZChzZWxmJTJDJTIwdGVuc29yKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJldHVybiUyMHNlbGYubW9kZWwuZm9yd2FyZF9mZWF0dXJlcyh0ZW5zb3Ip",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> PreTrainedModel
<span class="hljs-keyword">from</span> timm.models.resnet <span class="hljs-keyword">import</span> BasicBlock, Bottleneck, ResNet
<span class="hljs-keyword">from</span> .configuration_resnet <span class="hljs-keyword">import</span> ResnetConfig


BLOCK_MAPPING = {<span class="hljs-string">&quot;basic&quot;</span>: BasicBlock, <span class="hljs-string">&quot;bottleneck&quot;</span>: Bottleneck}


<span class="hljs-keyword">class</span> <span class="hljs-title class_">ResnetModel</span>(<span class="hljs-title class_ inherited__">PreTrainedModel</span>):
    config_class = ResnetConfig

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, config</span>):
        <span class="hljs-built_in">super</span>().__init__(config)
        block_layer = BLOCK_MAPPING[config.block_type]
        self.model = ResNet(
            block_layer,
            config.layers,
            num_classes=config.num_classes,
            in_chans=config.input_channels,
            cardinality=config.cardinality,
            base_width=config.base_width,
            stem_width=config.stem_width,
            stem_type=config.stem_type,
            avg_down=config.avg_down,
        )

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, tensor</span>):
        <span class="hljs-keyword">return</span> self.model.forward_features(tensor)`,wrap:!1}}),q=new J({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEElMEFjbGFzcyUyMFJlc25ldE1vZ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pZy5zdGVtX3dpZHRoJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc3RlbV90eXBlJTNEY29uZmlnLnN0ZW1fdHlwZSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGF2Z19kb3duJTNEY29uZmlnLmF2Z19kb3duJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUwQSUwQSUyMCUyMCUyMCUyMGRlZiUyMGZvcndhcmQoc2VsZiUyQyUyMHRlbnNvciUyQyUyMGxhYmVscyUzRE5vbmUpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbG9naXRzJTIwJTNEJTIwc2VsZi5tb2RlbCh0ZW5zb3IpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaWYlMjBsYWJlbHMlMjBpcyUyMG5vdCUyME5vbmUlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsb3NzJTIwJTNEJTIwdG9yY2gubm4uY3Jvc3NfZW50cm9weShsb2dpdHMlMkMlMjBsYWJlbHMpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmV0dXJuJTIwJTdCJTIybG9zcyUyMiUzQSUyMGxvc3MlMkMlMjAlMjJsb2dpdHMlMjIlM0ElMjBsb2dpdHMlN0QlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXR1cm4lMjAlN0IlMjJsb2dpdHMlMjIlM0ElMjBsb2dpdHMlN0Q=",highlighted:`<span class="hljs-keyword">import</span> torch


<span class="hljs-keyword">class</span> <span class="hljs-title class_">ResnetModelForImageClassification</span>(<span class="hljs-title class_ inherited__">PreTrainedModel</span>):
    config_class = ResnetConfig

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, config</span>):
        <span class="hljs-built_in">super</span>().__init__(config)
        block_layer = BLOCK_MAPPING[config.block_type]
        self.model = ResNet(
            block_layer,
            config.layers,
            num_classes=config.num_classes,
            in_chans=config.input_channels,
            cardinality=config.cardinality,
            base_width=config.base_width,
            stem_width=config.stem_width,
            stem_type=config.stem_type,
            avg_down=config.avg_down,
        )

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, tensor, labels=<span class="hljs-literal">None</span></span>):
        logits = self.model(tensor)
        <span class="hljs-keyword">if</span> labels <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>:
            loss = torch.nn.cross_entropy(logits, labels)
            <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;loss&quot;</span>: loss, <span class="hljs-string">&quot;logits&quot;</span>: logits}
        <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;logits&quot;</span>: logits}`,wrap:!1}}),g=new Xe({props:{$$slots:{default:[Dl]},$$scope:{ctx:j}}}),O=new J({props:{code:"cmVzbmV0NTBkJTIwJTNEJTIwUmVzbmV0TW9kZWxGb3JJbWFnZUNsYXNzaWZpY2F0aW9uKHJlc25ldDUwZF9jb25maWcp",highlighted:"resnet50d = ResnetModelForImageClassification(resnet50d_config)",wrap:!1}}),le=new J({props:{code:"aW1wb3J0JTIwdGltbSUwQSUwQXByZXRyYWluZWRfbW9kZWwlMjAlM0QlMjB0aW1tLmNyZWF0ZV9tb2RlbCglMjJyZXNuZXQ1MGQlMjIlMkMlMjBwcmV0cmFpbmVkJTNEVHJ1ZSklMEFyZXNuZXQ1MGQubW9kZWwubG9hZF9zdGF0ZV9kaWN0KHByZXRyYWluZWRfbW9kZWwuc3RhdGVfZGljdCgpKQ==",highlighted:`<span class="hljs-keyword">import</span> timm

pretrained_model = timm.create_model(<span class="hljs-string">&quot;resnet50d&quot;</span>, pretrained=<span class="hljs-literal">True</span>)
resnet50d.model.load_state_dict(pretrained_model.state_dict())`,wrap:!1}}),ne=new Be({props:{title:"Registering a model with custom code to the auto classes",local:"registering-a-model-with-custom-code-to-the-auto-classes",headingTag:"h2"}}),ie=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Db25maWclMkMlMjBBdXRvTW9kZWwlMkMlMjBBdXRvTW9kZWxGb3JJbWFnZUNsYXNzaWZpY2F0aW9uJTBBJTBBQXV0b0NvbmZpZy5yZWdpc3RlciglMjJyZXNuZXQlMjIlMkMlMjBSZXNuZXRDb25maWcpJTBBQXV0b01vZGVsLnJlZ2lzdGVyKFJlc25ldENvbmZpZyUyQyUyMFJlc25ldE1vZGVsKSUwQUF1dG9Nb2RlbEZvckltYWdlQ2xhc3NpZmljYXRpb24ucmVnaXN0ZXIoUmVzbmV0Q29uZmlnJTJDJTIwUmVzbmV0TW9kZWxGb3JJbWFnZUNsYXNzaWZpY2F0aW9uKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoConfig, AutoModel, AutoModelForImageClassification

AutoConfig.register(<span class="hljs-string">&quot;resnet&quot;</span>, ResnetConfig)
AutoModel.register(ResnetConfig, ResnetModel)
AutoModelForImageClassification.register(ResnetConfig, ResnetModelForImageClassification)`,wrap:!1}}),Me=new Be({props:{title:"Sending the code to the Hub",local:"sending-the-code-to-the-hub",headingTag:"h2"}}),I=new Xe({props:{warning:!0,$$slots:{default:[Kl]},$$scope:{ctx:j}}}),ce=new J({props:{code:"LiUwQSVFMiU5NCU5NCVFMiU5NCU4MCVFMiU5NCU4MCUyMHJlc25ldF9tb2RlbCUwQSUyMCUyMCUyMCUyMCVFMiU5NCU5QyVFMiU5NCU4MCVFMiU5NCU4MCUyMF9faW5pdF9fLnB5JTBBJTIwJTIwJTIwJTIwJUUyJTk0JTlDJUUyJTk0JTgwJUUyJTk0JTgwJTIwY29uZmlndXJhdGlvbl9yZXNuZXQucHklMEElMjAlMjAlMjAlMjAlRTIlOTQlOTQlRTIlOTQlODAlRTIlOTQlODAlMjBtb2RlbGluZ19yZXNuZXQucHk=",highlighted:`.
└── resnet_model
    ├── __init__.<span class="hljs-keyword">py</span>
    ├── configuration_resnet.<span class="hljs-keyword">py</span>
    └── modeling_resnet.<span class="hljs-keyword">py</span>`,wrap:!1}}),_=new Xe({props:{warning:!0,$$slots:{default:[Ol]},$$scope:{ctx:j}}}),ue=new J({props:{code:"ZnJvbSUyMHJlc25ldF9tb2RlbC5jb25maWd1cmF0aW9uX3Jlc25ldCUyMGltcG9ydCUyMFJlc25ldENvbmZpZyUwQWZyb20lMjByZXNuZXRfbW9kZWwubW9kZWxpbmdfcmVzbmV0JTIwaW1wb3J0JTIwUmVzbmV0TW9kZWwlMkMlMjBSZXNuZXRNb2RlbEZvckltYWdlQ2xhc3NpZmljYXRpb24=",highlighted:`<span class="hljs-keyword">from</span> resnet_model.configuration_resnet <span class="hljs-keyword">import</span> ResnetConfig
<span class="hljs-keyword">from</span> resnet_model.modeling_resnet <span class="hljs-keyword">import</span> ResnetModel, ResnetModelForImageClassification`,wrap:!1}}),we=new J({props:{code:"UmVzbmV0Q29uZmlnLnJlZ2lzdGVyX2Zvcl9hdXRvX2NsYXNzKCklMEFSZXNuZXRNb2RlbC5yZWdpc3Rlcl9mb3JfYXV0b19jbGFzcyglMjJBdXRvTW9kZWwlMjIpJTBBUmVzbmV0TW9kZWxGb3JJbWFnZUNsYXNzaWZpY2F0aW9uLnJlZ2lzdGVyX2Zvcl9hdXRvX2NsYXNzKCUyMkF1dG9Nb2RlbEZvckltYWdlQ2xhc3NpZmljYXRpb24lMjIp",highlighted:`ResnetConfig.register_for_auto_class()
ResnetModel.register_for_auto_class(<span class="hljs-string">&quot;AutoModel&quot;</span>)
ResnetModelForImageClassification.register_for_auto_class(<span class="hljs-string">&quot;AutoModelForImageClassification&quot;</span>)`,wrap:!1}}),Z=new Xe({props:{$$slots:{default:[es]},$$scope:{ctx:j}}}),Je=new J({props:{code:"cmVzbmV0NTBkX2NvbmZpZyUyMCUzRCUyMFJlc25ldENvbmZpZyhibG9ja190eXBlJTNEJTIyYm90dGxlbmVjayUyMiUyQyUyMHN0ZW1fd2lkdGglM0QzMiUyQyUyMHN0ZW1fdHlwZSUzRCUyMmRlZXAlMjIlMkMlMjBhdmdfZG93biUzRFRydWUpJTBBcmVzbmV0NTBkJTIwJTNEJTIwUmVzbmV0TW9kZWxGb3JJbWFnZUNsYXNzaWZpY2F0aW9uKHJlc25ldDUwZF9jb25maWcpJTBBJTBBcHJldHJhaW5lZF9tb2RlbCUyMCUzRCUyMHRpbW0uY3JlYXRlX21vZGVsKCUyMnJlc25ldDUwZCUyMiUyQyUyMHByZXRyYWluZWQlM0RUcnVlKSUwQXJlc25ldDUwZC5tb2RlbC5sb2FkX3N0YXRlX2RpY3QocHJldHJhaW5lZF9tb2RlbC5zdGF0ZV9kaWN0KCkp",highlighted:`resnet50d_config = ResnetConfig(block_type=<span class="hljs-string">&quot;bottleneck&quot;</span>, stem_width=<span class="hljs-number">32</span>, stem_type=<span class="hljs-string">&quot;deep&quot;</span>, avg_down=<span class="hljs-literal">True</span>)
resnet50d = ResnetModelForImageClassification(resnet50d_config)

pretrained_model = timm.create_model(<span class="hljs-string">&quot;resnet50d&quot;</span>, pretrained=<span class="hljs-literal">True</span>)
resnet50d.model.load_state_dict(pretrained_model.state_dict())`,wrap:!1}}),Ue=new J({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}}),Ce=new J({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),Ie=new J({props:{code:"cmVzbmV0NTBkLnB1c2hfdG9faHViKCUyMmN1c3RvbS1yZXNuZXQ1MGQlMjIp",highlighted:'resnet50d.push_to_hub(<span class="hljs-string">&quot;custom-resnet50d&quot;</span>)',wrap:!1}}),$e=new Be({props:{title:"Using a model with custom code",local:"using-a-model-with-custom-code",headingTag:"h2"}}),ke=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckltYWdlQ2xhc3NpZmljYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckltYWdlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMnNndWdnZXIlMkZjdXN0b20tcmVzbmV0NTBkJTIyJTJDJTIwdHJ1c3RfcmVtb3RlX2NvZGUlM0RUcnVlKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForImageClassification

model = AutoModelForImageClassification.from_pretrained(<span class="hljs-string">&quot;sgugger/custom-resnet50d&quot;</span>, trust_remote_code=<span class="hljs-literal">True</span>)`,wrap:!1}}),Ne=new J({props:{code:"Y29tbWl0X2hhc2glMjAlM0QlMjAlMjJlZDk0YTdjNjI0N2Q4YWVkY2U0NjQ3ZjAwZjIwZGU2ODc1YjViMjkyJTIyJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JJbWFnZUNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJzZ3VnZ2VyJTJGY3VzdG9tLXJlc25ldDUwZCUyMiUyQyUyMHRydXN0X3JlbW90ZV9jb2RlJTNEVHJ1ZSUyQyUyMHJldmlzaW9uJTNEY29tbWl0X2hhc2glMEEp",highlighted:`commit_hash = <span class="hljs-string">&quot;ed94a7c6247d8aedce4647f00f20de6875b5b292&quot;</span>
model = AutoModelForImageClassification.from_pretrained(
    <span class="hljs-string">&quot;sgugger/custom-resnet50d&quot;</span>, trust_remote_code=<span class="hljs-literal">True</span>, revision=commit_hash
)`,wrap:!1}}),{c(){o=i("meta"),h=n(),p=i("p"),w=n(),c(U.$$.fragment),T=n(),b=i("p"),b.textContent=Kt,Ye=n(),$=i("p"),$.textContent=Ot,Ge=n(),A=i("p"),A.innerHTML=el,Ve=n(),c(k.$$.fragment),Qe=n(),v=i("p"),v.innerHTML=tl,ze=n(),c(C.$$.fragment),He=n(),N=i("p"),N.textContent=ll,Ee=n(),c(W.$$.fragment),Fe=n(),B=i("p"),B.textContent=sl,Se=n(),R=i("ul"),R.innerHTML=nl,Le=n(),X=i("p"),X.innerHTML=al,qe=n(),x=i("p"),x.innerHTML=ol,Pe=n(),Y=i("p"),Y.textContent=il,De=n(),c(G.$$.fragment),Ke=n(),V=i("p"),V.innerHTML=rl,Oe=n(),c(Q.$$.fragment),et=n(),z=i("p"),z.innerHTML=Ml,tt=n(),c(H.$$.fragment),lt=n(),E=i("p"),E.innerHTML=pl,st=n(),F=i("p"),F.innerHTML=cl,nt=n(),c(S.$$.fragment),at=n(),L=i("p"),L.textContent=ml,ot=n(),c(q.$$.fragment),it=n(),P=i("p"),P.innerHTML=dl,rt=n(),c(g.$$.fragment),Mt=n(),D=i("p"),D.innerHTML=yl,pt=n(),K=i("p"),K.textContent=ul,ct=n(),c(O.$$.fragment),mt=n(),ee=i("p"),ee.innerHTML=fl,dt=n(),te=i("p"),te.textContent=wl,yt=n(),c(le.$$.fragment),ut=n(),se=i("p"),se.innerHTML=hl,ft=n(),c(ne.$$.fragment),wt=n(),ae=i("p"),ae.textContent=Tl,ht=n(),oe=i("p"),oe.innerHTML=Jl,Tt=n(),c(ie.$$.fragment),Jt=n(),re=i("p"),re.innerHTML=jl,jt=n(),c(Me.$$.fragment),Ut=n(),c(I.$$.fragment),bt=n(),pe=i("p"),pe.innerHTML=Ul,Ct=n(),c(ce.$$.fragment),gt=n(),me=i("p"),me.innerHTML=bl,It=n(),c(_.$$.fragment),_t=n(),de=i("p"),de.textContent=Cl,Zt=n(),ye=i("p"),ye.textContent=gl,$t=n(),c(ue.$$.fragment),At=n(),fe=i("p"),fe.innerHTML=Il,kt=n(),c(we.$$.fragment),vt=n(),he=i("p"),he.innerHTML=_l,Nt=n(),c(Z.$$.fragment),Wt=n(),Te=i("p"),Te.textContent=Zl,Bt=n(),c(Je.$$.fragment),Rt=n(),je=i("p"),je.textContent=$l,Xt=n(),c(Ue.$$.fragment),xt=n(),be=i("p"),be.textContent=Al,Yt=n(),c(Ce.$$.fragment),Gt=n(),ge=i("p"),ge.textContent=kl,Vt=n(),c(Ie.$$.fragment),Qt=n(),_e=i("p"),_e.innerHTML=vl,zt=n(),Ze=i("p"),Ze.innerHTML=Nl,Ht=n(),c($e.$$.fragment),Et=n(),Ae=i("p"),Ae.innerHTML=Wl,Ft=n(),c(ke.$$.fragment),St=n(),ve=i("p"),ve.innerHTML=Bl,Lt=n(),c(Ne.$$.fragment),qt=n(),We=i("p"),We.textContent=Rl,Pt=n(),Re=i("p"),this.h()},l(e){const t=Ll("svelte-u9bgzb",document.head);o=r(t,"META",{name:!0,content:!0}),t.forEach(l),h=a(e),p=r(e,"P",{}),Ql(p).forEach(l),w=a(e),m(U.$$.fragment,e),T=a(e),b=r(e,"P",{"data-svelte-h":!0}),M(b)!=="svelte-1bvx2nz"&&(b.textContent=Kt),Ye=a(e),$=r(e,"P",{"data-svelte-h":!0}),M($)!=="svelte-12q72ch"&&($.textContent=Ot),Ge=a(e),A=r(e,"P",{"data-svelte-h":!0}),M(A)!=="svelte-1wz3qo4"&&(A.innerHTML=el),Ve=a(e),m(k.$$.fragment,e),Qe=a(e),v=r(e,"P",{"data-svelte-h":!0}),M(v)!=="svelte-15o85x"&&(v.innerHTML=tl),ze=a(e),m(C.$$.fragment,e),He=a(e),N=r(e,"P",{"data-svelte-h":!0}),M(N)!=="svelte-1u8fbq1"&&(N.textContent=ll),Ee=a(e),m(W.$$.fragment,e),Fe=a(e),B=r(e,"P",{"data-svelte-h":!0}),M(B)!=="svelte-9tm0xv"&&(B.textContent=sl),Se=a(e),R=r(e,"UL",{"data-svelte-h":!0}),M(R)!=="svelte-1l985bz"&&(R.innerHTML=nl),Le=a(e),X=r(e,"P",{"data-svelte-h":!0}),M(X)!=="svelte-ttxucl"&&(X.innerHTML=al),qe=a(e),x=r(e,"P",{"data-svelte-h":!0}),M(x)!=="svelte-9uxjnq"&&(x.innerHTML=ol),Pe=a(e),Y=r(e,"P",{"data-svelte-h":!0}),M(Y)!=="svelte-1229zpx"&&(Y.textContent=il),De=a(e),m(G.$$.fragment,e),Ke=a(e),V=r(e,"P",{"data-svelte-h":!0}),M(V)!=="svelte-1hshoid"&&(V.innerHTML=rl),Oe=a(e),m(Q.$$.fragment,e),et=a(e),z=r(e,"P",{"data-svelte-h":!0}),M(z)!=="svelte-1o1xgyg"&&(z.innerHTML=Ml),tt=a(e),m(H.$$.fragment,e),lt=a(e),E=r(e,"P",{"data-svelte-h":!0}),M(E)!=="svelte-1mzp5zp"&&(E.innerHTML=pl),st=a(e),F=r(e,"P",{"data-svelte-h":!0}),M(F)!=="svelte-13oyc7x"&&(F.innerHTML=cl),nt=a(e),m(S.$$.fragment,e),at=a(e),L=r(e,"P",{"data-svelte-h":!0}),M(L)!=="svelte-85b6xb"&&(L.textContent=ml),ot=a(e),m(q.$$.fragment,e),it=a(e),P=r(e,"P",{"data-svelte-h":!0}),M(P)!=="svelte-1vktyut"&&(P.innerHTML=dl),rt=a(e),m(g.$$.fragment,e),Mt=a(e),D=r(e,"P",{"data-svelte-h":!0}),M(D)!=="svelte-hidw7f"&&(D.innerHTML=yl),pt=a(e),K=r(e,"P",{"data-svelte-h":!0}),M(K)!=="svelte-zsjn9b"&&(K.textContent=ul),ct=a(e),m(O.$$.fragment,e),mt=a(e),ee=r(e,"P",{"data-svelte-h":!0}),M(ee)!=="svelte-1s8ow2p"&&(ee.innerHTML=fl),dt=a(e),te=r(e,"P",{"data-svelte-h":!0}),M(te)!=="svelte-kn8bw1"&&(te.textContent=wl),yt=a(e),m(le.$$.fragment,e),ut=a(e),se=r(e,"P",{"data-svelte-h":!0}),M(se)!=="svelte-ato8p9"&&(se.innerHTML=hl),ft=a(e),m(ne.$$.fragment,e),wt=a(e),ae=r(e,"P",{"data-svelte-h":!0}),M(ae)!=="svelte-bccbz6"&&(ae.textContent=Tl),ht=a(e),oe=r(e,"P",{"data-svelte-h":!0}),M(oe)!=="svelte-uijzdg"&&(oe.innerHTML=Jl),Tt=a(e),m(ie.$$.fragment,e),Jt=a(e),re=r(e,"P",{"data-svelte-h":!0}),M(re)!=="svelte-scwjfy"&&(re.innerHTML=jl),jt=a(e),m(Me.$$.fragment,e),Ut=a(e),m(I.$$.fragment,e),bt=a(e),pe=r(e,"P",{"data-svelte-h":!0}),M(pe)!=="svelte-w79o0g"&&(pe.innerHTML=Ul),Ct=a(e),m(ce.$$.fragment,e),gt=a(e),me=r(e,"P",{"data-svelte-h":!0}),M(me)!=="svelte-1orsl60"&&(me.innerHTML=bl),It=a(e),m(_.$$.fragment,e),_t=a(e),de=r(e,"P",{"data-svelte-h":!0}),M(de)!=="svelte-miae0j"&&(de.textContent=Cl),Zt=a(e),ye=r(e,"P",{"data-svelte-h":!0}),M(ye)!=="svelte-1kyhtnz"&&(ye.textContent=gl),$t=a(e),m(ue.$$.fragment,e),At=a(e),fe=r(e,"P",{"data-svelte-h":!0}),M(fe)!=="svelte-1ce24vd"&&(fe.innerHTML=Il),kt=a(e),m(we.$$.fragment,e),vt=a(e),he=r(e,"P",{"data-svelte-h":!0}),M(he)!=="svelte-xxqbm1"&&(he.innerHTML=_l),Nt=a(e),m(Z.$$.fragment,e),Wt=a(e),Te=r(e,"P",{"data-svelte-h":!0}),M(Te)!=="svelte-19txhag"&&(Te.textContent=Zl),Bt=a(e),m(Je.$$.fragment,e),Rt=a(e),je=r(e,"P",{"data-svelte-h":!0}),M(je)!=="svelte-1w2dqml"&&(je.textContent=$l),Xt=a(e),m(Ue.$$.fragment,e),xt=a(e),be=r(e,"P",{"data-svelte-h":!0}),M(be)!=="svelte-11lw65d"&&(be.textContent=Al),Yt=a(e),m(Ce.$$.fragment,e),Gt=a(e),ge=r(e,"P",{"data-svelte-h":!0}),M(ge)!=="svelte-1c2397x"&&(ge.textContent=kl),Vt=a(e),m(Ie.$$.fragment,e),Qt=a(e),_e=r(e,"P",{"data-svelte-h":!0}),M(_e)!=="svelte-djed3h"&&(_e.innerHTML=vl),zt=a(e),Ze=r(e,"P",{"data-svelte-h":!0}),M(Ze)!=="svelte-1sdq6eg"&&(Ze.innerHTML=Nl),Ht=a(e),m($e.$$.fragment,e),Et=a(e),Ae=r(e,"P",{"data-svelte-h":!0}),M(Ae)!=="svelte-nao5c0"&&(Ae.innerHTML=Wl),Ft=a(e),m(ke.$$.fragment,e),St=a(e),ve=r(e,"P",{"data-svelte-h":!0}),M(ve)!=="svelte-1i8vto1"&&(ve.innerHTML=Bl),Lt=a(e),m(Ne.$$.fragment,e),qt=a(e),We=r(e,"P",{"data-svelte-h":!0}),M(We)!=="svelte-1y2zx54"&&(We.textContent=Rl),Pt=a(e),Re=r(e,"P",{}),Ql(Re).forEach(l),this.h()},h(){zl(o,"name","hf:doc:metadata"),zl(o,"content",ls)},m(e,t){ql(document.head,o),s(e,h,t),s(e,p,t),s(e,w,t),d(U,e,t),s(e,T,t),s(e,b,t),s(e,Ye,t),s(e,$,t),s(e,Ge,t),s(e,A,t),s(e,Ve,t),d(k,e,t),s(e,Qe,t),s(e,v,t),s(e,ze,t),d(C,e,t),s(e,He,t),s(e,N,t),s(e,Ee,t),d(W,e,t),s(e,Fe,t),s(e,B,t),s(e,Se,t),s(e,R,t),s(e,Le,t),s(e,X,t),s(e,qe,t),s(e,x,t),s(e,Pe,t),s(e,Y,t),s(e,De,t),d(G,e,t),s(e,Ke,t),s(e,V,t),s(e,Oe,t),d(Q,e,t),s(e,et,t),s(e,z,t),s(e,tt,t),d(H,e,t),s(e,lt,t),s(e,E,t),s(e,st,t),s(e,F,t),s(e,nt,t),d(S,e,t),s(e,at,t),s(e,L,t),s(e,ot,t),d(q,e,t),s(e,it,t),s(e,P,t),s(e,rt,t),d(g,e,t),s(e,Mt,t),s(e,D,t),s(e,pt,t),s(e,K,t),s(e,ct,t),d(O,e,t),s(e,mt,t),s(e,ee,t),s(e,dt,t),s(e,te,t),s(e,yt,t),d(le,e,t),s(e,ut,t),s(e,se,t),s(e,ft,t),d(ne,e,t),s(e,wt,t),s(e,ae,t),s(e,ht,t),s(e,oe,t),s(e,Tt,t),d(ie,e,t),s(e,Jt,t),s(e,re,t),s(e,jt,t),d(Me,e,t),s(e,Ut,t),d(I,e,t),s(e,bt,t),s(e,pe,t),s(e,Ct,t),d(ce,e,t),s(e,gt,t),s(e,me,t),s(e,It,t),d(_,e,t),s(e,_t,t),s(e,de,t),s(e,Zt,t),s(e,ye,t),s(e,$t,t),d(ue,e,t),s(e,At,t),s(e,fe,t),s(e,kt,t),d(we,e,t),s(e,vt,t),s(e,he,t),s(e,Nt,t),d(Z,e,t),s(e,Wt,t),s(e,Te,t),s(e,Bt,t),d(Je,e,t),s(e,Rt,t),s(e,je,t),s(e,Xt,t),d(Ue,e,t),s(e,xt,t),s(e,be,t),s(e,Yt,t),d(Ce,e,t),s(e,Gt,t),s(e,ge,t),s(e,Vt,t),d(Ie,e,t),s(e,Qt,t),s(e,_e,t),s(e,zt,t),s(e,Ze,t),s(e,Ht,t),d($e,e,t),s(e,Et,t),s(e,Ae,t),s(e,Ft,t),d(ke,e,t),s(e,St,t),s(e,ve,t),s(e,Lt,t),d(Ne,e,t),s(e,qt,t),s(e,We,t),s(e,Pt,t),s(e,Re,t),Dt=!0},p(e,[t]){const Xl={};t&2&&(Xl.$$scope={dirty:t,ctx:e}),C.$set(Xl);const xl={};t&2&&(xl.$$scope={dirty:t,ctx:e}),g.$set(xl);const Yl={};t&2&&(Yl.$$scope={dirty:t,ctx:e}),I.$set(Yl);const Gl={};t&2&&(Gl.$$scope={dirty:t,ctx:e}),_.$set(Gl);const Vl={};t&2&&(Vl.$$scope={dirty:t,ctx:e}),Z.$set(Vl)},i(e){Dt||(y(U.$$.fragment,e),y(k.$$.fragment,e),y(C.$$.fragment,e),y(W.$$.fragment,e),y(G.$$.fragment,e),y(Q.$$.fragment,e),y(H.$$.fragment,e),y(S.$$.fragment,e),y(q.$$.fragment,e),y(g.$$.fragment,e),y(O.$$.fragment,e),y(le.$$.fragment,e),y(ne.$$.fragment,e),y(ie.$$.fragment,e),y(Me.$$.fragment,e),y(I.$$.fragment,e),y(ce.$$.fragment,e),y(_.$$.fragment,e),y(ue.$$.fragment,e),y(we.$$.fragment,e),y(Z.$$.fragment,e),y(Je.$$.fragment,e),y(Ue.$$.fragment,e),y(Ce.$$.fragment,e),y(Ie.$$.fragment,e),y($e.$$.fragment,e),y(ke.$$.fragment,e),y(Ne.$$.fragment,e),Dt=!0)},o(e){u(U.$$.fragment,e),u(k.$$.fragment,e),u(C.$$.fragment,e),u(W.$$.fragment,e),u(G.$$.fragment,e),u(Q.$$.fragment,e),u(H.$$.fragment,e),u(S.$$.fragment,e),u(q.$$.fragment,e),u(g.$$.fragment,e),u(O.$$.fragment,e),u(le.$$.fragment,e),u(ne.$$.fragment,e),u(ie.$$.fragment,e),u(Me.$$.fragment,e),u(I.$$.fragment,e),u(ce.$$.fragment,e),u(_.$$.fragment,e),u(ue.$$.fragment,e),u(we.$$.fragment,e),u(Z.$$.fragment,e),u(Je.$$.fragment,e),u(Ue.$$.fragment,e),u(Ce.$$.fragment,e),u(Ie.$$.fragment,e),u($e.$$.fragment,e),u(ke.$$.fragment,e),u(Ne.$$.fragment,e),Dt=!1},d(e){e&&(l(h),l(p),l(w),l(T),l(b),l(Ye),l($),l(Ge),l(A),l(Ve),l(Qe),l(v),l(ze),l(He),l(N),l(Ee),l(Fe),l(B),l(Se),l(R),l(Le),l(X),l(qe),l(x),l(Pe),l(Y),l(De),l(Ke),l(V),l(Oe),l(et),l(z),l(tt),l(lt),l(E),l(st),l(F),l(nt),l(at),l(L),l(ot),l(it),l(P),l(rt),l(Mt),l(D),l(pt),l(K),l(ct),l(mt),l(ee),l(dt),l(te),l(yt),l(ut),l(se),l(ft),l(wt),l(ae),l(ht),l(oe),l(Tt),l(Jt),l(re),l(jt),l(Ut),l(bt),l(pe),l(Ct),l(gt),l(me),l(It),l(_t),l(de),l(Zt),l(ye),l($t),l(At),l(fe),l(kt),l(vt),l(he),l(Nt),l(Wt),l(Te),l(Bt),l(Rt),l(je),l(Xt),l(xt),l(be),l(Yt),l(Gt),l(ge),l(Vt),l(Qt),l(_e),l(zt),l(Ze),l(Ht),l(Et),l(Ae),l(Ft),l(St),l(ve),l(Lt),l(qt),l(We),l(Pt),l(Re)),l(o),f(U,e),f(k,e),f(C,e),f(W,e),f(G,e),f(Q,e),f(H,e),f(S,e),f(q,e),f(g,e),f(O,e),f(le,e),f(ne,e),f(ie,e),f(Me,e),f(I,e),f(ce,e),f(_,e),f(ue,e),f(we,e),f(Z,e),f(Je,e),f(Ue,e),f(Ce,e),f(Ie,e),f($e,e),f(ke,e),f(Ne,e)}}}const ls='{"title":"Building custom models","local":"building-custom-models","sections":[{"title":"Writing a custom configuration","local":"writing-a-custom-configuration","sections":[],"depth":2},{"title":"Writing a custom model","local":"writing-a-custom-model","sections":[],"depth":2},{"title":"Registering a model with custom code to the auto classes","local":"registering-a-model-with-custom-code-to-the-auto-classes","sections":[],"depth":2},{"title":"Sending the code to the Hub","local":"sending-the-code-to-the-hub","sections":[],"depth":2},{"title":"Using a model with custom code","local":"using-a-model-with-custom-code","sections":[],"depth":2}],"depth":1}';function ss(j){return El(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ms extends Fl{constructor(o){super(),Sl(this,o,ss,ts,Hl,{})}}export{Ms as component};
