import{S as Rs,i as Zs,s as Cs,e as o,k as h,w as y,t as n,M as Gs,c as i,d as t,m as d,a as r,x as g,h as p,b as m,G as s,g as l,y as _,q as v,o as b,B as k,v as Ss}from"../chunks/vendor-hf-doc-builder.js";import{T as Ws}from"../chunks/Tip-hf-doc-builder.js";import{I as ss}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as S}from"../chunks/CodeBlock-hf-doc-builder.js";function Xs(Ue){let f,x;return{c(){f=o("p"),x=n("Note that the randomly created model is initialized with \u201Cempty\u201D tensors, which take the space in memory without filling it (thus the random values are whatever was in this chunk of memory at a given time). The random initialization following the appropriate distribution for the kind of model/parameters instantiated (like a normal distribution for instance) is only performed after step 3 on the non-initialized weights, to be as fast as possible!")},l(c){f=i(c,"P",{});var u=r(f);x=p(u,"Note that the randomly created model is initialized with \u201Cempty\u201D tensors, which take the space in memory without filling it (thus the random values are whatever was in this chunk of memory at a given time). The random initialization following the appropriate distribution for the kind of model/parameters instantiated (like a normal distribution for instance) is only performed after step 3 on the non-initialized weights, to be as fast as possible!"),u.forEach(t)},m(c,u){l(c,f,u),s(f,x)},d(c){c&&t(f)}}}function zs(Ue){let f,x,c,u,de,W,rt,me,pt,xe,K,ht,Te,j,fe,dt,mt,ce,ft,ct,ue,ut,Ee,T,wt,we,yt,gt,Je,E,Be,D,_t,Ie,$,J,ye,X,vt,ge,bt,Re,B,kt,_e,jt,Mt,Ze,I,$t,ve,Ut,xt,Ce,z,Ge,R,Tt,O,Et,Jt,Se,A,We,ee,Bt,Xe,P,ze,M,It,be,Rt,Zt,te,Ct,Gt,Ae,N,Pe,se,St,Ne,ae,Wt,Ve,V,Le,le,Xt,Fe,L,He,Z,zt,ke,At,Pt,qe,F,Qe,w,Nt,oe,Vt,Lt,je,Ft,Ht,ie,qt,Qt,Ye,H,Ke,U,C,Me,q,Yt,$e,Kt,De,ne,Dt,Oe,Q,Ot,re,es,et;return W=new ss({}),E=new Ws({props:{$$slots:{default:[Xs]},$$scope:{ctx:Ue}}}),X=new ss({}),z=new S({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbCUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsLmZyb21fcHJldHJhaW5lZCglMjJiZXJ0LWJhc2UtY2FzZWQlMjIp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModel

model = AutoModel.from_pretrained(<span class="hljs-string">&quot;bert-base-cased&quot;</span>)`}}),A=new S({props:{code:"aW1wb3J0JTIwb3MlMEFpbXBvcnQlMjB0ZW1wZmlsZSUwQSUwQXdpdGglMjB0ZW1wZmlsZS5UZW1wb3JhcnlEaXJlY3RvcnkoKSUyMGFzJTIwdG1wX2RpciUzQSUwQSUyMCUyMCUyMCUyMG1vZGVsLnNhdmVfcHJldHJhaW5lZCh0bXBfZGlyKSUwQSUyMCUyMCUyMCUyMHByaW50KHNvcnRlZChvcy5saXN0ZGlyKHRtcF9kaXIpKSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> os
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> tempfile

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> tempfile.TemporaryDirectory() <span class="hljs-keyword">as</span> tmp_dir:
<span class="hljs-meta">... </span>    model.save_pretrained(tmp_dir)
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-built_in">sorted</span>(os.listdir(tmp_dir)))
[<span class="hljs-string">&#x27;config.json&#x27;</span>, <span class="hljs-string">&#x27;pytorch_model.bin&#x27;</span>]`}}),P=new S({props:{code:"d2l0aCUyMHRlbXBmaWxlLlRlbXBvcmFyeURpcmVjdG9yeSgpJTIwYXMlMjB0bXBfZGlyJTNBJTBBJTIwJTIwJTIwJTIwbW9kZWwuc2F2ZV9wcmV0cmFpbmVkKHRtcF9kaXIlMkMlMjBtYXhfc2hhcmRfc2l6ZSUzRCUyMjIwME1CJTIyKSUwQSUyMCUyMCUyMCUyMHByaW50KHNvcnRlZChvcy5saXN0ZGlyKHRtcF9kaXIpKSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> tempfile.TemporaryDirectory() <span class="hljs-keyword">as</span> tmp_dir:
<span class="hljs-meta">... </span>    model.save_pretrained(tmp_dir, max_shard_size=<span class="hljs-string">&quot;200MB&quot;</span>)
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-built_in">sorted</span>(os.listdir(tmp_dir)))
[<span class="hljs-string">&#x27;config.json&#x27;</span>, <span class="hljs-string">&#x27;pytorch_model-00001-of-00003.bin&#x27;</span>, <span class="hljs-string">&#x27;pytorch_model-00002-of-00003.bin&#x27;</span>, <span class="hljs-string">&#x27;pytorch_model-00003-of-00003.bin&#x27;</span>, <span class="hljs-string">&#x27;pytorch_model.bin.index.json&#x27;</span>]`}}),N=new S({props:{code:"d2l0aCUyMHRlbXBmaWxlLlRlbXBvcmFyeURpcmVjdG9yeSgpJTIwYXMlMjB0bXBfZGlyJTNBJTBBJTIwJTIwJTIwJTIwbW9kZWwuc2F2ZV9wcmV0cmFpbmVkKHRtcF9kaXIlMkMlMjBtYXhfc2hhcmRfc2l6ZSUzRCUyMjIwME1CJTIyKSUwQSUyMCUyMCUyMCUyMG5ld19tb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbC5mcm9tX3ByZXRyYWluZWQodG1wX2Rpcik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> tempfile.TemporaryDirectory() <span class="hljs-keyword">as</span> tmp_dir:
<span class="hljs-meta">... </span>    model.save_pretrained(tmp_dir, max_shard_size=<span class="hljs-string">&quot;200MB&quot;</span>)
<span class="hljs-meta">... </span>    new_model = AutoModel.from_pretrained(tmp_dir)`}}),V=new S({props:{code:"aW1wb3J0JTIwanNvbiUwQSUwQXdpdGglMjB0ZW1wZmlsZS5UZW1wb3JhcnlEaXJlY3RvcnkoKSUyMGFzJTIwdG1wX2RpciUzQSUwQSUyMCUyMCUyMCUyMG1vZGVsLnNhdmVfcHJldHJhaW5lZCh0bXBfZGlyJTJDJTIwbWF4X3NoYXJkX3NpemUlM0QlMjIyMDBNQiUyMiklMEElMjAlMjAlMjAlMjB3aXRoJTIwb3Blbihvcy5wYXRoLmpvaW4odG1wX2RpciUyQyUyMCUyMnB5dG9yY2hfbW9kZWwuYmluLmluZGV4Lmpzb24lMjIpJTJDJTIwJTIyciUyMiklMjBhcyUyMGYlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpbmRleCUyMCUzRCUyMGpzb24ubG9hZChmKSUwQSUwQXByaW50KGluZGV4LmtleXMoKSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> json

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> tempfile.TemporaryDirectory() <span class="hljs-keyword">as</span> tmp_dir:
<span class="hljs-meta">... </span>    model.save_pretrained(tmp_dir, max_shard_size=<span class="hljs-string">&quot;200MB&quot;</span>)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(os.path.join(tmp_dir, <span class="hljs-string">&quot;pytorch_model.bin.index.json&quot;</span>), <span class="hljs-string">&quot;r&quot;</span>) <span class="hljs-keyword">as</span> f:
<span class="hljs-meta">... </span>        index = json.load(f)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(index.keys())
dict_keys([<span class="hljs-string">&#x27;metadata&#x27;</span>, <span class="hljs-string">&#x27;weight_map&#x27;</span>])`}}),L=new S({props:{code:"aW5kZXglNUIlMjJtZXRhZGF0YSUyMiU1RA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>index[<span class="hljs-string">&quot;metadata&quot;</span>]
{<span class="hljs-string">&#x27;total_size&#x27;</span>: <span class="hljs-number">433245184</span>}`}}),F=new S({props:{code:"aW5kZXglNUIlMjJ3ZWlnaHRfbWFwJTIyJTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>index[<span class="hljs-string">&quot;weight_map&quot;</span>]
{<span class="hljs-string">&#x27;embeddings.LayerNorm.bias&#x27;</span>: <span class="hljs-string">&#x27;pytorch_model-00001-of-00003.bin&#x27;</span>,
 <span class="hljs-string">&#x27;embeddings.LayerNorm.weight&#x27;</span>: <span class="hljs-string">&#x27;pytorch_model-00001-of-00003.bin&#x27;</span>,
 ...`}}),H=new S({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5tb2RlbGluZ191dGlscyUyMGltcG9ydCUyMGxvYWRfc2hhcmRlZF9jaGVja3BvaW50JTBBJTBBd2l0aCUyMHRlbXBmaWxlLlRlbXBvcmFyeURpcmVjdG9yeSgpJTIwYXMlMjB0bXBfZGlyJTNBJTBBJTIwJTIwJTIwJTIwbW9kZWwuc2F2ZV9wcmV0cmFpbmVkKHRtcF9kaXIlMkMlMjBtYXhfc2hhcmRfc2l6ZSUzRCUyMjIwME1CJTIyKSUwQSUyMCUyMCUyMCUyMGxvYWRfc2hhcmRlZF9jaGVja3BvaW50KG1vZGVsJTJDJTIwdG1wX2Rpcik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers.modeling_utils <span class="hljs-keyword">import</span> load_sharded_checkpoint

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> tempfile.TemporaryDirectory() <span class="hljs-keyword">as</span> tmp_dir:
<span class="hljs-meta">... </span>    model.save_pretrained(tmp_dir, max_shard_size=<span class="hljs-string">&quot;200MB&quot;</span>)
<span class="hljs-meta">... </span>    load_sharded_checkpoint(model, tmp_dir)`}}),q=new ss({}),{c(){f=o("meta"),x=h(),c=o("h1"),u=o("a"),de=o("span"),y(W.$$.fragment),rt=h(),me=o("span"),pt=n("Instantiating a big model"),xe=h(),K=o("p"),ht=n(`When you want to use a very big pretrained model, one challenge is to minimize the use of the RAM. The usual workflow
from PyTorch is:`),Te=h(),j=o("ol"),fe=o("li"),dt=n("Create your model with random weights."),mt=h(),ce=o("li"),ft=n("Load your pretrained weights."),ct=h(),ue=o("li"),ut=n("Put those pretrained weights in your random model."),Ee=h(),T=o("p"),wt=n("Step 1 and 2 both require a full version of the model in memory, which is not a problem in most cases, but if your model starts weighing several GigaBytes, those two copies can make you get out of RAM. Even worse, if you are using "),we=o("code"),yt=n("torch.distributed"),gt=n(" to launch a distributed training, each process will load the pretrained model and store these two copies in RAM."),Je=h(),y(E.$$.fragment),Be=h(),D=o("p"),_t=n("In this guide, we explore the solutions Transformers offer to deal with this issue. Note that this is an area of active development, so the APIs explained here may change slightly in the future."),Ie=h(),$=o("h2"),J=o("a"),ye=o("span"),y(X.$$.fragment),vt=h(),ge=o("span"),bt=n("Sharded checkpoints"),Re=h(),B=o("p"),kt=n("Since version 4.18.0, model checkpoints that end up taking more than 10GB of space are automatically sharded in smaller pieces. In terms of having one single checkpoint when you do "),_e=o("code"),jt=n("model.save_pretrained(save_dir)"),Mt=n(", you will end up with several partial checkpoints (each of which being of size < 10GB) and an index that maps parameter names to the files they are stored in."),Ze=h(),I=o("p"),$t=n("You can control the maximum size before sharding with the "),ve=o("code"),Ut=n("max_shard_size"),xt=n(" parameter, so for the sake of an example, we\u2019ll use a normal-size models with a small shard size: let\u2019s take a traditional BERT model."),Ce=h(),y(z.$$.fragment),Ge=h(),R=o("p"),Tt=n("If you save it using "),O=o("a"),Et=n("save_pretrained()"),Jt=n(", you will get a new folder with two files: the config of the model and its weights:"),Se=h(),y(A.$$.fragment),We=h(),ee=o("p"),Bt=n("Now let\u2019s use a maximum shard size of 200MB:"),Xe=h(),y(P.$$.fragment),ze=h(),M=o("p"),It=n("On top of the configuration of the model, we see three different weights files, and an "),be=o("code"),Rt=n("index.json"),Zt=n(" file which is our index. A checkpoint like this can be fully reloaded using the "),te=o("a"),Ct=n("from_pretrained()"),Gt=n(" method:"),Ae=h(),y(N.$$.fragment),Pe=h(),se=o("p"),St=n("The main advantage of doing this for big models is that during step 2 of the workflow shown above, each shard of the checkpoint is loaded after the previous one, capping the memory usage in RAM to the model size plus the size of the biggest shard."),Ne=h(),ae=o("p"),Wt=n("Behind the scenes, the index file is used to determine which keys are in the checkpoint, and where the corresponding weights are stored. We can load that index like any json and get a dictionary:"),Ve=h(),y(V.$$.fragment),Le=h(),le=o("p"),Xt=n("The metadata just consists of the total size of the model for now. We plan to add other information in the future:"),Fe=h(),y(L.$$.fragment),He=h(),Z=o("p"),zt=n("The weights map is the main part of this index, which maps each parameter name (as usually found in a PyTorch model "),ke=o("code"),At=n("state_dict"),Pt=n(") to the file it\u2019s stored in:"),qe=h(),y(F.$$.fragment),Qe=h(),w=o("p"),Nt=n("If you want to directly load such a sharded checkpoint inside a model without using "),oe=o("a"),Vt=n("from_pretrained()"),Lt=n(" (like you would do "),je=o("code"),Ft=n("model.load_state_dict()"),Ht=n(" for a full checkpoint) you should use "),ie=o("a"),qt=n("load_sharded_checkpoint()"),Qt=n(":"),Ye=h(),y(H.$$.fragment),Ke=h(),U=o("h2"),C=o("a"),Me=o("span"),y(q.$$.fragment),Yt=h(),$e=o("span"),Kt=n("Low memory loading"),De=h(),ne=o("p"),Dt=n("Sharded checkpoints reduce the memory usage during step 2 of the workflow mentioned above, but in order to use that model in a low memory setting, we recommend leveraging our tools based on the Accelerate library."),Oe=h(),Q=o("p"),Ot=n("Please read the following guide for more information: "),re=o("a"),es=n("Large model loading using Accelerate"),this.h()},l(e){const a=Gs('[data-svelte="svelte-1phssyn"]',document.head);f=i(a,"META",{name:!0,content:!0}),a.forEach(t),x=d(e),c=i(e,"H1",{class:!0});var Y=r(c);u=i(Y,"A",{id:!0,class:!0,href:!0});var as=r(u);de=i(as,"SPAN",{});var ls=r(de);g(W.$$.fragment,ls),ls.forEach(t),as.forEach(t),rt=d(Y),me=i(Y,"SPAN",{});var os=r(me);pt=p(os,"Instantiating a big model"),os.forEach(t),Y.forEach(t),xe=d(e),K=i(e,"P",{});var is=r(K);ht=p(is,`When you want to use a very big pretrained model, one challenge is to minimize the use of the RAM. The usual workflow
from PyTorch is:`),is.forEach(t),Te=d(e),j=i(e,"OL",{});var pe=r(j);fe=i(pe,"LI",{});var ns=r(fe);dt=p(ns,"Create your model with random weights."),ns.forEach(t),mt=d(pe),ce=i(pe,"LI",{});var rs=r(ce);ft=p(rs,"Load your pretrained weights."),rs.forEach(t),ct=d(pe),ue=i(pe,"LI",{});var ps=r(ue);ut=p(ps,"Put those pretrained weights in your random model."),ps.forEach(t),pe.forEach(t),Ee=d(e),T=i(e,"P",{});var tt=r(T);wt=p(tt,"Step 1 and 2 both require a full version of the model in memory, which is not a problem in most cases, but if your model starts weighing several GigaBytes, those two copies can make you get out of RAM. Even worse, if you are using "),we=i(tt,"CODE",{});var hs=r(we);yt=p(hs,"torch.distributed"),hs.forEach(t),gt=p(tt," to launch a distributed training, each process will load the pretrained model and store these two copies in RAM."),tt.forEach(t),Je=d(e),g(E.$$.fragment,e),Be=d(e),D=i(e,"P",{});var ds=r(D);_t=p(ds,"In this guide, we explore the solutions Transformers offer to deal with this issue. Note that this is an area of active development, so the APIs explained here may change slightly in the future."),ds.forEach(t),Ie=d(e),$=i(e,"H2",{class:!0});var st=r($);J=i(st,"A",{id:!0,class:!0,href:!0});var ms=r(J);ye=i(ms,"SPAN",{});var fs=r(ye);g(X.$$.fragment,fs),fs.forEach(t),ms.forEach(t),vt=d(st),ge=i(st,"SPAN",{});var cs=r(ge);bt=p(cs,"Sharded checkpoints"),cs.forEach(t),st.forEach(t),Re=d(e),B=i(e,"P",{});var at=r(B);kt=p(at,"Since version 4.18.0, model checkpoints that end up taking more than 10GB of space are automatically sharded in smaller pieces. In terms of having one single checkpoint when you do "),_e=i(at,"CODE",{});var us=r(_e);jt=p(us,"model.save_pretrained(save_dir)"),us.forEach(t),Mt=p(at,", you will end up with several partial checkpoints (each of which being of size < 10GB) and an index that maps parameter names to the files they are stored in."),at.forEach(t),Ze=d(e),I=i(e,"P",{});var lt=r(I);$t=p(lt,"You can control the maximum size before sharding with the "),ve=i(lt,"CODE",{});var ws=r(ve);Ut=p(ws,"max_shard_size"),ws.forEach(t),xt=p(lt," parameter, so for the sake of an example, we\u2019ll use a normal-size models with a small shard size: let\u2019s take a traditional BERT model."),lt.forEach(t),Ce=d(e),g(z.$$.fragment,e),Ge=d(e),R=i(e,"P",{});var ot=r(R);Tt=p(ot,"If you save it using "),O=i(ot,"A",{href:!0});var ys=r(O);Et=p(ys,"save_pretrained()"),ys.forEach(t),Jt=p(ot,", you will get a new folder with two files: the config of the model and its weights:"),ot.forEach(t),Se=d(e),g(A.$$.fragment,e),We=d(e),ee=i(e,"P",{});var gs=r(ee);Bt=p(gs,"Now let\u2019s use a maximum shard size of 200MB:"),gs.forEach(t),Xe=d(e),g(P.$$.fragment,e),ze=d(e),M=i(e,"P",{});var he=r(M);It=p(he,"On top of the configuration of the model, we see three different weights files, and an "),be=i(he,"CODE",{});var _s=r(be);Rt=p(_s,"index.json"),_s.forEach(t),Zt=p(he," file which is our index. A checkpoint like this can be fully reloaded using the "),te=i(he,"A",{href:!0});var vs=r(te);Ct=p(vs,"from_pretrained()"),vs.forEach(t),Gt=p(he," method:"),he.forEach(t),Ae=d(e),g(N.$$.fragment,e),Pe=d(e),se=i(e,"P",{});var bs=r(se);St=p(bs,"The main advantage of doing this for big models is that during step 2 of the workflow shown above, each shard of the checkpoint is loaded after the previous one, capping the memory usage in RAM to the model size plus the size of the biggest shard."),bs.forEach(t),Ne=d(e),ae=i(e,"P",{});var ks=r(ae);Wt=p(ks,"Behind the scenes, the index file is used to determine which keys are in the checkpoint, and where the corresponding weights are stored. We can load that index like any json and get a dictionary:"),ks.forEach(t),Ve=d(e),g(V.$$.fragment,e),Le=d(e),le=i(e,"P",{});var js=r(le);Xt=p(js,"The metadata just consists of the total size of the model for now. We plan to add other information in the future:"),js.forEach(t),Fe=d(e),g(L.$$.fragment,e),He=d(e),Z=i(e,"P",{});var it=r(Z);zt=p(it,"The weights map is the main part of this index, which maps each parameter name (as usually found in a PyTorch model "),ke=i(it,"CODE",{});var Ms=r(ke);At=p(Ms,"state_dict"),Ms.forEach(t),Pt=p(it,") to the file it\u2019s stored in:"),it.forEach(t),qe=d(e),g(F.$$.fragment,e),Qe=d(e),w=i(e,"P",{});var G=r(w);Nt=p(G,"If you want to directly load such a sharded checkpoint inside a model without using "),oe=i(G,"A",{href:!0});var $s=r(oe);Vt=p($s,"from_pretrained()"),$s.forEach(t),Lt=p(G," (like you would do "),je=i(G,"CODE",{});var Us=r(je);Ft=p(Us,"model.load_state_dict()"),Us.forEach(t),Ht=p(G," for a full checkpoint) you should use "),ie=i(G,"A",{href:!0});var xs=r(ie);qt=p(xs,"load_sharded_checkpoint()"),xs.forEach(t),Qt=p(G,":"),G.forEach(t),Ye=d(e),g(H.$$.fragment,e),Ke=d(e),U=i(e,"H2",{class:!0});var nt=r(U);C=i(nt,"A",{id:!0,class:!0,href:!0});var Ts=r(C);Me=i(Ts,"SPAN",{});var Es=r(Me);g(q.$$.fragment,Es),Es.forEach(t),Ts.forEach(t),Yt=d(nt),$e=i(nt,"SPAN",{});var Js=r($e);Kt=p(Js,"Low memory loading"),Js.forEach(t),nt.forEach(t),De=d(e),ne=i(e,"P",{});var Bs=r(ne);Dt=p(Bs,"Sharded checkpoints reduce the memory usage during step 2 of the workflow mentioned above, but in order to use that model in a low memory setting, we recommend leveraging our tools based on the Accelerate library."),Bs.forEach(t),Oe=d(e),Q=i(e,"P",{});var ts=r(Q);Ot=p(ts,"Please read the following guide for more information: "),re=i(ts,"A",{href:!0});var Is=r(re);es=p(Is,"Large model loading using Accelerate"),Is.forEach(t),ts.forEach(t),this.h()},h(){m(f,"name","hf:doc:metadata"),m(f,"content",JSON.stringify(As)),m(u,"id","instantiating-a-big-model"),m(u,"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(u,"href","#instantiating-a-big-model"),m(c,"class","relative group"),m(J,"id","sharded-checkpoints"),m(J,"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(J,"href","#sharded-checkpoints"),m($,"class","relative group"),m(O,"href","/docs/transformers/v4.33.0/en/main_classes/model#transformers.PreTrainedModel.save_pretrained"),m(te,"href","/docs/transformers/v4.33.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained"),m(oe,"href","/docs/transformers/v4.33.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained"),m(ie,"href","/docs/transformers/v4.33.0/en/main_classes/model#transformers.modeling_utils.load_sharded_checkpoint"),m(C,"id","low-memory-loading"),m(C,"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(C,"href","#low-memory-loading"),m(U,"class","relative group"),m(re,"href","./main_classes/model#large-model-loading")},m(e,a){s(document.head,f),l(e,x,a),l(e,c,a),s(c,u),s(u,de),_(W,de,null),s(c,rt),s(c,me),s(me,pt),l(e,xe,a),l(e,K,a),s(K,ht),l(e,Te,a),l(e,j,a),s(j,fe),s(fe,dt),s(j,mt),s(j,ce),s(ce,ft),s(j,ct),s(j,ue),s(ue,ut),l(e,Ee,a),l(e,T,a),s(T,wt),s(T,we),s(we,yt),s(T,gt),l(e,Je,a),_(E,e,a),l(e,Be,a),l(e,D,a),s(D,_t),l(e,Ie,a),l(e,$,a),s($,J),s(J,ye),_(X,ye,null),s($,vt),s($,ge),s(ge,bt),l(e,Re,a),l(e,B,a),s(B,kt),s(B,_e),s(_e,jt),s(B,Mt),l(e,Ze,a),l(e,I,a),s(I,$t),s(I,ve),s(ve,Ut),s(I,xt),l(e,Ce,a),_(z,e,a),l(e,Ge,a),l(e,R,a),s(R,Tt),s(R,O),s(O,Et),s(R,Jt),l(e,Se,a),_(A,e,a),l(e,We,a),l(e,ee,a),s(ee,Bt),l(e,Xe,a),_(P,e,a),l(e,ze,a),l(e,M,a),s(M,It),s(M,be),s(be,Rt),s(M,Zt),s(M,te),s(te,Ct),s(M,Gt),l(e,Ae,a),_(N,e,a),l(e,Pe,a),l(e,se,a),s(se,St),l(e,Ne,a),l(e,ae,a),s(ae,Wt),l(e,Ve,a),_(V,e,a),l(e,Le,a),l(e,le,a),s(le,Xt),l(e,Fe,a),_(L,e,a),l(e,He,a),l(e,Z,a),s(Z,zt),s(Z,ke),s(ke,At),s(Z,Pt),l(e,qe,a),_(F,e,a),l(e,Qe,a),l(e,w,a),s(w,Nt),s(w,oe),s(oe,Vt),s(w,Lt),s(w,je),s(je,Ft),s(w,Ht),s(w,ie),s(ie,qt),s(w,Qt),l(e,Ye,a),_(H,e,a),l(e,Ke,a),l(e,U,a),s(U,C),s(C,Me),_(q,Me,null),s(U,Yt),s(U,$e),s($e,Kt),l(e,De,a),l(e,ne,a),s(ne,Dt),l(e,Oe,a),l(e,Q,a),s(Q,Ot),s(Q,re),s(re,es),et=!0},p(e,[a]){const Y={};a&2&&(Y.$$scope={dirty:a,ctx:e}),E.$set(Y)},i(e){et||(v(W.$$.fragment,e),v(E.$$.fragment,e),v(X.$$.fragment,e),v(z.$$.fragment,e),v(A.$$.fragment,e),v(P.$$.fragment,e),v(N.$$.fragment,e),v(V.$$.fragment,e),v(L.$$.fragment,e),v(F.$$.fragment,e),v(H.$$.fragment,e),v(q.$$.fragment,e),et=!0)},o(e){b(W.$$.fragment,e),b(E.$$.fragment,e),b(X.$$.fragment,e),b(z.$$.fragment,e),b(A.$$.fragment,e),b(P.$$.fragment,e),b(N.$$.fragment,e),b(V.$$.fragment,e),b(L.$$.fragment,e),b(F.$$.fragment,e),b(H.$$.fragment,e),b(q.$$.fragment,e),et=!1},d(e){t(f),e&&t(x),e&&t(c),k(W),e&&t(xe),e&&t(K),e&&t(Te),e&&t(j),e&&t(Ee),e&&t(T),e&&t(Je),k(E,e),e&&t(Be),e&&t(D),e&&t(Ie),e&&t($),k(X),e&&t(Re),e&&t(B),e&&t(Ze),e&&t(I),e&&t(Ce),k(z,e),e&&t(Ge),e&&t(R),e&&t(Se),k(A,e),e&&t(We),e&&t(ee),e&&t(Xe),k(P,e),e&&t(ze),e&&t(M),e&&t(Ae),k(N,e),e&&t(Pe),e&&t(se),e&&t(Ne),e&&t(ae),e&&t(Ve),k(V,e),e&&t(Le),e&&t(le),e&&t(Fe),k(L,e),e&&t(He),e&&t(Z),e&&t(qe),k(F,e),e&&t(Qe),e&&t(w),e&&t(Ye),k(H,e),e&&t(Ke),e&&t(U),k(q),e&&t(De),e&&t(ne),e&&t(Oe),e&&t(Q)}}}const As={local:"instantiating-a-big-model",sections:[{local:"sharded-checkpoints",title:"Sharded checkpoints"},{local:"low-memory-loading",title:"Low memory loading"}],title:"Instantiating a big model"};function Ps(Ue){return Ss(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Hs extends Rs{constructor(f){super();Zs(this,f,Ps,zs,Cs,{})}}export{Hs as default,As as metadata};
