import{S as mu,i as bu,s as yu,e as a,k as h,w as u,t as n,M as vu,c as s,d as o,m as f,a as l,x as p,h as r,b as c,G as t,g as d,y as m,q as b,o as y,B as v,v as _u}from"../../chunks/vendor-hf-doc-builder.js";import{T as jh}from"../../chunks/Tip-hf-doc-builder.js";import{D as lo}from"../../chunks/Docstring-hf-doc-builder.js";import{C as W}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as T}from"../../chunks/IconCopyLink-hf-doc-builder.js";function gu(ke){let _,k;return{c(){_=a("p"),k=n("Note that once a model has been loaded in 4-bit it is currently not possible to push the quantized weights on the Hub. Note also that you cannot train 4-bit weights as this is not supported yet. However you can use 4-bit models to train extra parameters, this will be covered in the next section.")},l(g){_=s(g,"P",{});var E=l(_);k=r(E,"Note that once a model has been loaded in 4-bit it is currently not possible to push the quantized weights on the Hub. Note also that you cannot train 4-bit weights as this is not supported yet. However you can use 4-bit models to train extra parameters, this will be covered in the next section."),E.forEach(o)},m(g,E){d(g,_,E),t(_,k)},d(g){g&&o(_)}}}function wu(ke){let _,k,g,E,te,z,ft,oe,ae,Je,N,A,se,V;return{c(){_=a("p"),k=n("Note that once a model has been loaded in 8-bit it is currently not possible to push the quantized weights on the Hub except if you use the latest "),g=a("code"),E=n("transformers"),te=n(" and "),z=a("code"),ft=n("bitsandbytes"),oe=n(`. Note also that you cannot train 8-bit weights as this is not supported yet. However you can use 8-bit models to train extra parameters, this will be covered in the next section.
Note also that `),ae=a("code"),Je=n("device_map"),N=n(" is optional but setting "),A=a("code"),se=n("device_map = 'auto'"),V=n(" is prefered for inference as it will dispatch efficiently the model on the available ressources.")},l(le){_=s(le,"P",{});var M=l(_);k=r(M,"Note that once a model has been loaded in 8-bit it is currently not possible to push the quantized weights on the Hub except if you use the latest "),g=s(M,"CODE",{});var Ce=l(g);E=r(Ce,"transformers"),Ce.forEach(o),te=r(M," and "),z=s(M,"CODE",{});var no=l(z);ft=r(no,"bitsandbytes"),no.forEach(o),oe=r(M,`. Note also that you cannot train 8-bit weights as this is not supported yet. However you can use 8-bit models to train extra parameters, this will be covered in the next section.
Note also that `),ae=s(M,"CODE",{});var ro=l(ae);Je=r(ro,"device_map"),ro.forEach(o),N=r(M," is optional but setting "),A=s(M,"CODE",{});var ct=l(A);se=r(ct,"device_map = 'auto'"),ct.forEach(o),V=r(M," is prefered for inference as it will dispatch efficiently the model on the available ressources."),M.forEach(o)},m(le,M){d(le,_,M),t(_,k),t(_,g),t(g,E),t(_,te),t(_,z),t(z,ft),t(_,oe),t(_,ae),t(ae,Je),t(_,N),t(_,A),t(A,se),t(_,V)},d(le){le&&o(_)}}}function Eu(ke){let _,k;return{c(){_=a("p"),k=n("Pushing 8bit models on the Hub is strongely encouraged for large models. This will allow the community to benefit from the memory footprint reduction and loading for example large models on a Google Colab.")},l(g){_=s(g,"P",{});var E=l(_);k=r(E,"Pushing 8bit models on the Hub is strongely encouraged for large models. This will allow the community to benefit from the memory footprint reduction and loading for example large models on a Google Colab."),E.forEach(o)},m(g,E){d(g,_,E),t(_,k)},d(g){g&&o(_)}}}function $u(ke){let _,k,g,E,te,z,ft,oe,ae,Je,N,A,se,V,le,M,Ce,no,ro,ct,q,En,No,$n,Mn,Zo,Tn,kn,Wo,Jn,Cn,Ws,I,An,ut,Bn,Un,pt,zn,Nn,qs,R,Zn,qo,Wn,qn,jo,jn,Xn,js,Ae,Fn,Xo,Pn,Vn,Xs,ne,Be,Fo,mt,In,Po,Rn,Fs,re,Ue,Vo,bt,Qn,Io,xn,Ps,io,Gn,Vs,Q,Ro,ze,Dn,Qo,Sn,Yn,xo,On,Hn,Go,Ne,Ln,Do,Kn,er,So,tr,or,Yo,Ze,ar,Oo,sr,lr,Ho,nr,Is,ie,We,Lo,yt,rr,Ko,ir,Rs,x,dr,ea,hr,fr,ta,cr,ur,Qs,vt,xs,qe,Gs,de,je,oa,_t,pr,aa,mr,Ds,G,br,sa,yr,vr,la,_r,gr,Ss,gt,Ys,Xe,wr,ho,Er,$r,Os,Fe,Mr,na,Tr,kr,Hs,wt,Ls,fo,Jr,Ks,Pe,el,he,Ve,ra,Et,Cr,ia,Ar,tl,co,Br,ol,fe,Ie,da,$t,Ur,ha,zr,al,D,Nr,fa,Zr,Wr,ca,qr,jr,sl,Mt,ll,ce,Re,ua,Tt,Xr,pa,Fr,nl,uo,Pr,rl,kt,il,ue,Qe,ma,Jt,Vr,ba,Ir,dl,po,Rr,hl,Ct,fl,pe,xe,ya,At,Qr,va,xr,cl,j,Gr,_a,Dr,Sr,ga,Yr,Or,wa,Hr,Lr,ul,Bt,pl,Ge,ml,me,De,Ea,Ut,Kr,$a,ei,bl,S,ti,Ma,oi,ai,Ta,si,li,yl,zt,vl,J,ni,ka,ri,ii,Ja,di,hi,Ca,fi,ci,Aa,ui,pi,Ba,mi,bi,_l,be,Se,Ua,Nt,yi,za,vi,gl,mo,_i,wl,ye,Ye,Na,Zt,gi,Oe,wi,Za,Ei,$i,Wa,Mi,El,B,Ti,qa,ki,Ji,ja,Ci,Ai,Xa,Bi,Ui,Fa,zi,Ni,$l,U,Zi,Pa,Wi,qi,Va,ji,Xi,Ia,Fi,Pi,Ra,Vi,Ii,Ml,Wt,Tl,Y,Ri,Qa,Qi,xi,xa,Gi,Di,kl,qt,Jl,bo,Si,Cl,jt,Al,yo,Yi,Bl,ve,He,Ga,Xt,Oi,vo,Hi,Da,Li,Ul,O,Ki,Sa,ed,td,Ya,od,ad,zl,Ft,Nl,_e,Le,Oa,Pt,sd,Ha,ld,Zl,ge,nd,La,rd,id,Ka,dd,Wl,Vt,ql,we,Ke,es,It,hd,ts,fd,jl,X,cd,os,ud,pd,as,md,bd,Rt,ss,yd,vd,Xl,C,_d,ls,gd,wd,ns,Ed,$d,rs,Md,Td,is,kd,Jd,ds,Cd,Ad,Fl,Ee,et,hs,Qt,Bd,fs,Ud,Pl,w,xt,zd,Gt,Nd,cs,Zd,Wd,qd,$e,jd,us,Xd,Fd,ps,Pd,Vd,Id,Z,Rd,ms,Qd,xd,bs,Gd,Dd,ys,Sd,Yd,vs,Od,Hd,Ld,tt,Dt,Kd,St,eh,_o,th,oh,ah,ot,Yt,sh,Me,lh,_s,nh,rh,gs,ih,dh,hh,at,Ot,fh,ws,ch,uh,st,Ht,ph,Lt,mh,Es,bh,yh,vh,lt,Kt,_h,eo,gh,$s,wh,Eh,$h,nt,to,Mh,Ms,Th,Vl,Te,rt,Ts,oo,kh,go,Jh,ks,Ch,Il,H,Ah,ao,Bh,Uh,Js,zh,Nh,Rl;return z=new T({}),V=new T({}),mt=new T({}),bt=new T({}),yt=new T({}),vt=new W({props:{code:"JTIzJTIwcGlwJTIwaW5zdGFsbCUyMHRyYW5zZm9ybWVycyUyMGFjY2VsZXJhdGUlMjBiaXRzYW5kYnl0ZXMlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0lMkMlMjBBdXRvVG9rZW5pemVyJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJiaWdzY2llbmNlJTJGYmxvb20tMWI3JTIyJTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQlMkMlMjBkZXZpY2VfbWFwJTNEJTIyYXV0byUyMiUyQyUyMGxvYWRfaW5fNGJpdCUzRFRydWUp",highlighted:`<span class="hljs-comment"># pip install transformers accelerate bitsandbytes</span>
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer

model_id = <span class="hljs-string">&quot;bigscience/bloom-1b7&quot;</span>

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map=<span class="hljs-string">&quot;auto&quot;</span>, load_in_4bit=<span class="hljs-literal">True</span>)`}}),qe=new jh({props:{warning:!0,$$slots:{default:[gu]},$$scope:{ctx:ke}}}),_t=new T({}),gt=new W({props:{code:"JTIzJTIwcGlwJTIwaW5zdGFsbCUyMHRyYW5zZm9ybWVycyUyMGFjY2VsZXJhdGUlMjBiaXRzYW5kYnl0ZXMlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0lMkMlMjBBdXRvVG9rZW5pemVyJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJiaWdzY2llbmNlJTJGYmxvb20tMWI3JTIyJTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQlMkMlMjBkZXZpY2VfbWFwJTNEJTIyYXV0byUyMiUyQyUyMGxvYWRfaW5fOGJpdCUzRFRydWUp",highlighted:`<span class="hljs-comment"># pip install transformers accelerate bitsandbytes</span>
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer

model_id = <span class="hljs-string">&quot;bigscience/bloom-1b7&quot;</span>

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map=<span class="hljs-string">&quot;auto&quot;</span>, load_in_8bit=<span class="hljs-literal">True</span>)`}}),wt=new W({props:{code:"cHJpbnQobW9kZWwuZ2V0X21lbW9yeV9mb290cHJpbnQoKSk=",highlighted:'<span class="hljs-built_in">print</span>(model.get_memory_footprint())'}}),Pe=new jh({props:{warning:!0,$$slots:{default:[wu]},$$scope:{ctx:ke}}}),Et=new T({}),$t=new T({}),Mt=new W({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQml0c0FuZEJ5dGVzQ29uZmlnJTBBJTBBcXVhbnRpemF0aW9uX2NvbmZpZyUyMCUzRCUyMEJpdHNBbmRCeXRlc0NvbmZpZyhsb2FkX2luXzRiaXQlM0RUcnVlJTJDJTIwYm5iXzRiaXRfY29tcHV0ZV9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2KQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(load_in_4bit=<span class="hljs-literal">True</span>, bnb_4bit_compute_dtype=torch.bfloat16)`}}),Tt=new T({}),kt=new W({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEJpdHNBbmRCeXRlc0NvbmZpZyUwQSUwQW5mNF9jb25maWclMjAlM0QlMjBCaXRzQW5kQnl0ZXNDb25maWcoJTBBJTIwJTIwJTIwJTIwbG9hZF9pbl80Yml0JTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGJuYl80Yml0X3F1YW50X3R5cGUlM0QlMjJuZjQlMjIlMkMlMEEpJTBBJTBBbW9kZWxfbmY0JTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkJTJDJTIwcXVhbnRpemF0aW9uX2NvbmZpZyUzRG5mNF9jb25maWcp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BitsAndBytesConfig

nf4_config = BitsAndBytesConfig(
    load_in_4bit=<span class="hljs-literal">True</span>,
    bnb_4bit_quant_type=<span class="hljs-string">&quot;nf4&quot;</span>,
)

model_nf4 = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=nf4_config)`}}),Jt=new T({}),Ct=new W({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEJpdHNBbmRCeXRlc0NvbmZpZyUwQSUwQWRvdWJsZV9xdWFudF9jb25maWclMjAlM0QlMjBCaXRzQW5kQnl0ZXNDb25maWcoJTBBJTIwJTIwJTIwJTIwbG9hZF9pbl80Yml0JTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGJuYl80Yml0X3VzZV9kb3VibGVfcXVhbnQlM0RUcnVlJTJDJTBBKSUwQSUwQW1vZGVsX2RvdWJsZV9xdWFudCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHF1YW50aXphdGlvbl9jb25maWclM0Rkb3VibGVfcXVhbnRfY29uZmlnKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BitsAndBytesConfig

double_quant_config = BitsAndBytesConfig(
    load_in_4bit=<span class="hljs-literal">True</span>,
    bnb_4bit_use_double_quant=<span class="hljs-literal">True</span>,
)

model_double_quant = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=double_quant_config)`}}),At=new T({}),Bt=new W({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKCUyMmJpZ3NjaWVuY2UlMkZibG9vbS01NjBtJTIyJTJDJTIwZGV2aWNlX21hcCUzRCUyMmF1dG8lMjIlMkMlMjBsb2FkX2luXzhiaXQlM0RUcnVlKSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKCUyMmJpZ3NjaWVuY2UlMkZibG9vbS01NjBtJTIyKSUwQSUwQW1vZGVsLnB1c2hfdG9faHViKCUyMmJsb29tLTU2MG0tOGJpdCUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;bigscience/bloom-560m&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>, load_in_8bit=<span class="hljs-literal">True</span>)
tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;bigscience/bloom-560m&quot;</span>)

model.push_to_hub(<span class="hljs-string">&quot;bloom-560m-8bit&quot;</span>)`}}),Ge=new jh({props:{warning:!0,$$slots:{default:[Eu]},$$scope:{ctx:ke}}}),Ut=new T({}),zt=new W({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKCUyMiU3QnlvdXJfdXNlcm5hbWUlN0QlMkZibG9vbS01NjBtLThiaXQlMjIlMkMlMjBkZXZpY2VfbWFwJTNEJTIyYXV0byUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;{your_username}/bloom-560m-8bit&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>)`}}),Nt=new T({}),Zt=new T({}),Wt=new W({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUyQyUyMEJpdHNBbmRCeXRlc0NvbmZpZyUwQSUwQXF1YW50aXphdGlvbl9jb25maWclMjAlM0QlMjBCaXRzQW5kQnl0ZXNDb25maWcobGxtX2ludDhfZW5hYmxlX2ZwMzJfY3B1X29mZmxvYWQlM0RUcnVlKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(llm_int8_enable_fp32_cpu_offload=<span class="hljs-literal">True</span>)`}}),qt=new W({props:{code:"ZGV2aWNlX21hcCUyMCUzRCUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMnRyYW5zZm9ybWVyLndvcmRfZW1iZWRkaW5ncyUyMiUzQSUyMDAlMkMlMEElMjAlMjAlMjAlMjAlMjJ0cmFuc2Zvcm1lci53b3JkX2VtYmVkZGluZ3NfbGF5ZXJub3JtJTIyJTNBJTIwMCUyQyUwQSUyMCUyMCUyMCUyMCUyMmxtX2hlYWQlMjIlM0ElMjAlMjJjcHUlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJ0cmFuc2Zvcm1lci5oJTIyJTNBJTIwMCUyQyUwQSUyMCUyMCUyMCUyMCUyMnRyYW5zZm9ybWVyLmxuX2YlMjIlM0ElMjAwJTJDJTBBJTdE",highlighted:`device_map = {
    <span class="hljs-string">&quot;transformer.word_embeddings&quot;</span>: <span class="hljs-number">0</span>,
    <span class="hljs-string">&quot;transformer.word_embeddings_layernorm&quot;</span>: <span class="hljs-number">0</span>,
    <span class="hljs-string">&quot;lm_head&quot;</span>: <span class="hljs-string">&quot;cpu&quot;</span>,
    <span class="hljs-string">&quot;transformer.h&quot;</span>: <span class="hljs-number">0</span>,
    <span class="hljs-string">&quot;transformer.ln_f&quot;</span>: <span class="hljs-number">0</span>,
}`}}),jt=new W({props:{code:"bW9kZWxfOGJpdCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJiaWdzY2llbmNlJTJGYmxvb20tMWI3JTIyJTJDJTBBJTIwJTIwJTIwJTIwZGV2aWNlX21hcCUzRGRldmljZV9tYXAlMkMlMEElMjAlMjAlMjAlMjBxdWFudGl6YXRpb25fY29uZmlnJTNEcXVhbnRpemF0aW9uX2NvbmZpZyUyQyUwQSk=",highlighted:`model_8bit = AutoModelForCausalLM.from_pretrained(
    <span class="hljs-string">&quot;bigscience/bloom-1b7&quot;</span>,
    device_map=device_map,
    quantization_config=quantization_config,
)`}}),Xt=new T({}),Ft=new W({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUyQyUyMEJpdHNBbmRCeXRlc0NvbmZpZyUwQSUwQW1vZGVsX2lkJTIwJTNEJTIwJTIyYmlnc2NpZW5jZSUyRmJsb29tLTFiNyUyMiUwQSUwQXF1YW50aXphdGlvbl9jb25maWclMjAlM0QlMjBCaXRzQW5kQnl0ZXNDb25maWcoJTBBJTIwJTIwJTIwJTIwbGxtX2ludDhfdGhyZXNob2xkJTNEMTAlMkMlMEEpJTBBJTBBbW9kZWxfOGJpdCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9pZCUyQyUwQSUyMCUyMCUyMCUyMGRldmljZV9tYXAlM0RkZXZpY2VfbWFwJTJDJTBBJTIwJTIwJTIwJTIwcXVhbnRpemF0aW9uX2NvbmZpZyUzRHF1YW50aXphdGlvbl9jb25maWclMkMlMEEpJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig

model_id = <span class="hljs-string">&quot;bigscience/bloom-1b7&quot;</span>

quantization_config = BitsAndBytesConfig(
    llm_int8_threshold=<span class="hljs-number">10</span>,
)

model_8bit = AutoModelForCausalLM.from_pretrained(
    model_id,
    device_map=device_map,
    quantization_config=quantization_config,
)
tokenizer = AutoTokenizer.from_pretrained(model_id)`}}),Pt=new T({}),Vt=new W({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUyQyUyMEJpdHNBbmRCeXRlc0NvbmZpZyUwQSUwQW1vZGVsX2lkJTIwJTNEJTIwJTIyYmlnc2NpZW5jZSUyRmJsb29tLTFiNyUyMiUwQSUwQXF1YW50aXphdGlvbl9jb25maWclMjAlM0QlMjBCaXRzQW5kQnl0ZXNDb25maWcoJTBBJTIwJTIwJTIwJTIwbGxtX2ludDhfc2tpcF9tb2R1bGVzJTNEJTVCJTIybG1faGVhZCUyMiU1RCUyQyUwQSklMEElMEFtb2RlbF84Yml0JTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMG1vZGVsX2lkJTJDJTBBJTIwJTIwJTIwJTIwZGV2aWNlX21hcCUzRGRldmljZV9tYXAlMkMlMEElMjAlMjAlMjAlMjBxdWFudGl6YXRpb25fY29uZmlnJTNEcXVhbnRpemF0aW9uX2NvbmZpZyUyQyUwQSklMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig

model_id = <span class="hljs-string">&quot;bigscience/bloom-1b7&quot;</span>

quantization_config = BitsAndBytesConfig(
    llm_int8_skip_modules=[<span class="hljs-string">&quot;lm_head&quot;</span>],
)

model_8bit = AutoModelForCausalLM.from_pretrained(
    model_id,
    device_map=device_map,
    quantization_config=quantization_config,
)
tokenizer = AutoTokenizer.from_pretrained(model_id)`}}),It=new T({}),Qt=new T({}),xt=new lo({props:{name:"class transformers.BitsAndBytesConfig",anchor:"transformers.BitsAndBytesConfig",parameters:[{name:"load_in_8bit",val:" = False"},{name:"load_in_4bit",val:" = False"},{name:"llm_int8_threshold",val:" = 6.0"},{name:"llm_int8_skip_modules",val:" = None"},{name:"llm_int8_enable_fp32_cpu_offload",val:" = False"},{name:"llm_int8_has_fp16_weight",val:" = False"},{name:"bnb_4bit_compute_dtype",val:" = None"},{name:"bnb_4bit_quant_type",val:" = 'fp4'"},{name:"bnb_4bit_use_double_quant",val:" = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.BitsAndBytesConfig.load_in_8bit",description:`<strong>load_in_8bit</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
This flag is used to enable 8-bit quantization with LLM.int8().`,name:"load_in_8bit"},{anchor:"transformers.BitsAndBytesConfig.load_in_4bit",description:`<strong>load_in_4bit</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
This flag is used to enable 4-bit quantization by replacing the Linear layers with FP4/NF4 layers from
<code>bitsandbytes</code>.`,name:"load_in_4bit"},{anchor:"transformers.BitsAndBytesConfig.llm_int8_threshold",description:`<strong>llm_int8_threshold</strong> (<code>float</code>, <em>optional</em>, defaults to 6) &#x2014;
This corresponds to the outlier threshold for outlier detection as described in <code>LLM.int8() : 8-bit Matrix Multiplication for Transformers at Scale</code> paper: <a href="https://arxiv.org/abs/2208.07339" rel="nofollow">https://arxiv.org/abs/2208.07339</a> Any hidden states value
that is above this threshold will be considered an outlier and the operation on those values will be done
in fp16. Values are usually normally distributed, that is, most values are in the range [-3.5, 3.5], but
there are some exceptional systematic outliers that are very differently distributed for large models.
These outliers are often in the interval [-60, -6] or [6, 60]. Int8 quantization works well for values of
magnitude ~5, but beyond that, there is a significant performance penalty. A good default threshold is 6,
but a lower threshold might be needed for more unstable models (small models, fine-tuning).`,name:"llm_int8_threshold"},{anchor:"transformers.BitsAndBytesConfig.llm_int8_skip_modules",description:`<strong>llm_int8_skip_modules</strong> (<code>List[str]</code>, <em>optional</em>) &#x2014;
An explicit list of the modules that we do not want to convert in 8-bit. This is useful for models such as
Jukebox that has several heads in different places and not necessarily at the last position. For example
for <code>CausalLM</code> models, the last <code>lm_head</code> is kept in its original <code>dtype</code>.`,name:"llm_int8_skip_modules"},{anchor:"transformers.BitsAndBytesConfig.llm_int8_enable_fp32_cpu_offload",description:`<strong>llm_int8_enable_fp32_cpu_offload</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
This flag is used for advanced use cases and users that are aware of this feature. If you want to split
your model in different parts and run some parts in int8 on GPU and some parts in fp32 on CPU, you can use
this flag. This is useful for offloading large models such as <code>google/flan-t5-xxl</code>. Note that the int8
operations will not be run on CPU.`,name:"llm_int8_enable_fp32_cpu_offload"},{anchor:"transformers.BitsAndBytesConfig.llm_int8_has_fp16_weight",description:`<strong>llm_int8_has_fp16_weight</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
This flag runs LLM.int8() with 16-bit main weights. This is useful for fine-tuning as the weights do not
have to be converted back and forth for the backward pass.`,name:"llm_int8_has_fp16_weight"},{anchor:"transformers.BitsAndBytesConfig.bnb_4bit_compute_dtype",description:`<strong>bnb_4bit_compute_dtype</strong> (<code>torch.dtype</code> or str, <em>optional</em>, defaults to <code>torch.float32</code>) &#x2014;
This sets the computational type which might be different than the input time. For example, inputs might be
fp32, but computation can be set to bf16 for speedups.`,name:"bnb_4bit_compute_dtype"},{anchor:"transformers.BitsAndBytesConfig.bnb_4bit_quant_type",description:`<strong>bnb_4bit_quant_type</strong> (<code>str</code>, {fp4, nf4}, defaults to <code>fp4</code>) &#x2014;
This sets the quantization data type in the bnb.nn.Linear4Bit layers. Options are FP4 and NF4 data types
which are specified by <code>fp4</code> or <code>nf4</code>.`,name:"bnb_4bit_quant_type"},{anchor:"transformers.BitsAndBytesConfig.bnb_4bit_use_double_quant",description:`<strong>bnb_4bit_use_double_quant</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
This flag is used for nested quantization where the quantization constants from the first quantization are
quantized again.`,name:"bnb_4bit_use_double_quant"},{anchor:"transformers.BitsAndBytesConfig.kwargs",description:`<strong>kwargs</strong> (<code>Dict[str, Any]</code>, <em>optional</em>) &#x2014;
Additional parameters from which to initialize the configuration object.`,name:"kwargs"}],source:"https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/quantization_config.py#L37"}}),Dt=new lo({props:{name:"from_dict",anchor:"transformers.BitsAndBytesConfig.from_dict",parameters:[{name:"config_dict",val:""},{name:"return_unused_kwargs",val:""},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.BitsAndBytesConfig.from_dict.config_dict",description:`<strong>config_dict</strong> (<code>Dict[str, Any]</code>) &#x2014;
Dictionary that will be used to instantiate the configuration object.`,name:"config_dict"},{anchor:"transformers.BitsAndBytesConfig.from_dict.return_unused_kwargs",description:`<strong>return_unused_kwargs</strong> (<code>bool</code>) &#x2014;
Whether or not to return a list of unused keyword arguments. Used for <code>from_pretrained</code> method in
<code>PreTrainedModel</code>.`,name:"return_unused_kwargs"},{anchor:"transformers.BitsAndBytesConfig.from_dict.kwargs",description:`<strong>kwargs</strong> (<code>Dict[str, Any]</code>) &#x2014;
Additional parameters from which to initialize the configuration object.`,name:"kwargs"}],source:"https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/quantization_config.py#L171",returnDescription:`
<p>The configuration object instantiated from those parameters.</p>
`,returnType:`
<p><a
  href="/docs/transformers/v4.30.0/en/main_classes/quantization#transformers.BitsAndBytesConfig"
>BitsAndBytesConfig</a></p>
`}}),Yt=new lo({props:{name:"is_quantizable",anchor:"transformers.BitsAndBytesConfig.is_quantizable",parameters:[],source:"https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/quantization_config.py#L151"}}),Ot=new lo({props:{name:"post_init",anchor:"transformers.BitsAndBytesConfig.post_init",parameters:[],source:"https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/quantization_config.py#L120"}}),Ht=new lo({props:{name:"quantization_method",anchor:"transformers.BitsAndBytesConfig.quantization_method",parameters:[],source:"https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/quantization_config.py#L157"}}),Kt=new lo({props:{name:"to_dict",anchor:"transformers.BitsAndBytesConfig.to_dict",parameters:[],source:"https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/quantization_config.py#L221"}}),to=new lo({props:{name:"to_json_file",anchor:"transformers.BitsAndBytesConfig.to_json_file",parameters:[{name:"json_file_path",val:": typing.Union[str, os.PathLike]"}],parametersDescription:[{anchor:"transformers.BitsAndBytesConfig.to_json_file.json_file_path",description:`<strong>json_file_path</strong> (<code>str</code> or <code>os.PathLike</code>) &#x2014;
Path to the JSON file in which this configuration instance&#x2019;s parameters will be saved.`,name:"json_file_path"},{anchor:"transformers.BitsAndBytesConfig.to_json_file.use_diff",description:`<strong>use_diff</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
If set to <code>True</code>, only the difference between the config instance and the default
<code>BitsAndBytesConfig()</code> is serialized to JSON file.`,name:"use_diff"}],source:"https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/quantization_config.py#L204"}}),oo=new T({}),{c(){_=a("meta"),k=h(),g=a("h1"),E=a("a"),te=a("span"),u(z.$$.fragment),ft=h(),oe=a("span"),ae=n("Quantize \u{1F917} Transformers models"),Je=h(),N=a("h2"),A=a("a"),se=a("span"),u(V.$$.fragment),le=h(),M=a("span"),Ce=a("code"),no=n("bitsandbytes"),ro=n(" Integration"),ct=h(),q=a("p"),En=n("\u{1F917} Transformers is closely integrated with most used modules on "),No=a("code"),$n=n("bitsandbytes"),Mn=n(`. You can load your model in 8-bit precision with few lines of code.
This is supported by most of the GPU hardwares since the `),Zo=a("code"),Tn=n("0.37.0"),kn=n(" release of "),Wo=a("code"),Jn=n("bitsandbytes"),Cn=n("."),Ws=h(),I=a("p"),An=n("Learn more about the quantization method in the "),ut=a("a"),Bn=n("LLM.int8()"),Un=n(" paper, or the "),pt=a("a"),zn=n("blogpost"),Nn=n(" about the collaboration."),qs=h(),R=a("p"),Zn=n("Since its "),qo=a("code"),Wn=n("0.39.0"),qn=n(" release, you can load any model that supports "),jo=a("code"),jn=n("device_map"),Xn=n(" using 4-bit quantization, leveraging FP4 data type."),js=h(),Ae=a("p"),Fn=n("Here are the things you can do using "),Xo=a("code"),Pn=n("bitsandbytes"),Vn=n(" integration"),Xs=h(),ne=a("h3"),Be=a("a"),Fo=a("span"),u(mt.$$.fragment),In=h(),Po=a("span"),Rn=n("FP4 quantization"),Fs=h(),re=a("h4"),Ue=a("a"),Vo=a("span"),u(bt.$$.fragment),Qn=h(),Io=a("span"),xn=n("Requirements"),Ps=h(),io=a("p"),Gn=n("Make sure that you have installed the requirements below before running any of the code snippets below."),Vs=h(),Q=a("ul"),Ro=a("li"),ze=a("p"),Dn=n("Latest "),Qo=a("code"),Sn=n("bitsandbytes"),Yn=n(` library
`),xo=a("code"),On=n("pip install bitsandbytes>=0.39.0"),Hn=h(),Go=a("li"),Ne=a("p"),Ln=n("Install latest "),Do=a("code"),Kn=n("accelerate"),er=n(` from source
`),So=a("code"),tr=n("pip install git+https://github.com/huggingface/accelerate.git"),or=h(),Yo=a("li"),Ze=a("p"),ar=n("Install latest "),Oo=a("code"),sr=n("transformers"),lr=n(` from source
`),Ho=a("code"),nr=n("pip install git+https://github.com/huggingface/transformers.git"),Is=h(),ie=a("h4"),We=a("a"),Lo=a("span"),u(yt.$$.fragment),rr=h(),Ko=a("span"),ir=n("Load a large model in 4bit"),Rs=h(),x=a("p"),dr=n("By using "),ea=a("code"),hr=n("load_in_4bit=True"),fr=n(" when calling the "),ta=a("code"),cr=n(".from_pretrained"),ur=n(" method, you can divide your memory use by 4 (roughly)."),Qs=h(),u(vt.$$.fragment),xs=h(),u(qe.$$.fragment),Gs=h(),de=a("h3"),je=a("a"),oa=a("span"),u(_t.$$.fragment),pr=h(),aa=a("span"),mr=n("Load a large model in 8bit"),Ds=h(),G=a("p"),br=n("You can load a model by roughly halving the memory requirements by using "),sa=a("code"),yr=n("load_in_8bit=True"),vr=n(" argument when calling "),la=a("code"),_r=n(".from_pretrained"),gr=n(" method"),Ss=h(),u(gt.$$.fragment),Ys=h(),Xe=a("p"),wr=n("Then, use your model as you would usually use a "),ho=a("a"),Er=n("PreTrainedModel"),$r=n("."),Os=h(),Fe=a("p"),Mr=n("You can check the memory footprint of your model with "),na=a("code"),Tr=n("get_memory_footprint"),kr=n(" method."),Hs=h(),u(wt.$$.fragment),Ls=h(),fo=a("p"),Jr=n("With this integration we were able to load large models on smaller devices and run them without any issue."),Ks=h(),u(Pe.$$.fragment),el=h(),he=a("h4"),Ve=a("a"),ra=a("span"),u(Et.$$.fragment),Cr=h(),ia=a("span"),Ar=n("Advanced usecases"),tl=h(),co=a("p"),Br=n("Here we will cover some advanced usecases you can perform with FP4 quantization"),ol=h(),fe=a("h5"),Ie=a("a"),da=a("span"),u($t.$$.fragment),Ur=h(),ha=a("span"),zr=n("Change the compute dtype"),al=h(),D=a("p"),Nr=n("The compute dtype is used to change the dtype that will be used during computation. For example, hidden states could be in "),fa=a("code"),Zr=n("float32"),Wr=n(" but computation can be set to bf16 for speedups. By default, the compute dtype is set to "),ca=a("code"),qr=n("float32"),jr=n("."),sl=h(),u(Mt.$$.fragment),ll=h(),ce=a("h5"),Re=a("a"),ua=a("span"),u(Tt.$$.fragment),Xr=h(),pa=a("span"),Fr=n("Using NF4 (Normal Float 4) data type"),nl=h(),uo=a("p"),Pr=n("You can also use the NF4 data type, which is a new 4bit datatype adapted for weights that have been initialized using a normal distribution. For that run:"),rl=h(),u(kt.$$.fragment),il=h(),ue=a("h5"),Qe=a("a"),ma=a("span"),u(Jt.$$.fragment),Vr=h(),ba=a("span"),Ir=n("Use nested quantization for more memory efficient inference"),dl=h(),po=a("p"),Rr=n("We also advise users to use the nested quantization technique. This saves more memory at no additional performance - from our empirical observations, this enables fine-tuning llama-13b model on an NVIDIA-T4 16GB with a sequence length of 1024, batch size of 1 and gradient accumulation steps of 4."),hl=h(),u(Ct.$$.fragment),fl=h(),pe=a("h3"),xe=a("a"),ya=a("span"),u(At.$$.fragment),Qr=h(),va=a("span"),xr=n("Push quantized models on the \u{1F917} Hub"),cl=h(),j=a("p"),Gr=n("You can push a quantized model on the Hub by naively using "),_a=a("code"),Dr=n("push_to_hub"),Sr=n(` method. This will first push the quantization configuration file, then push the quantized model weights.
Make sure to use `),ga=a("code"),Yr=n("bitsandbytes>0.37.2"),Or=n(" (at this time of writing, we tested it on "),wa=a("code"),Hr=n("bitsandbytes==0.38.0.post1"),Lr=n(") to be able to use this feature."),ul=h(),u(Bt.$$.fragment),pl=h(),u(Ge.$$.fragment),ml=h(),me=a("h3"),De=a("a"),Ea=a("span"),u(Ut.$$.fragment),Kr=h(),$a=a("span"),ei=n("Load a quantized model from the \u{1F917} Hub"),bl=h(),S=a("p"),ti=n("You can load a quantized model from the Hub by using "),Ma=a("code"),oi=n("from_pretrained"),ai=n(" method. Make sure that the pushed weights are quantized, by checking that the attribute "),Ta=a("code"),si=n("quantization_config"),li=n(" is present in the model configuration object."),yl=h(),u(zt.$$.fragment),vl=h(),J=a("p"),ni=n("Note that in this case, you don\u2019t need to specify the arguments "),ka=a("code"),ri=n("load_in_8bit=True"),ii=n(", but you need to make sure that "),Ja=a("code"),di=n("bitsandbytes"),hi=n(" and "),Ca=a("code"),fi=n("accelerate"),ci=n(` are installed.
Note also that `),Aa=a("code"),ui=n("device_map"),pi=n(" is optional but setting "),Ba=a("code"),mi=n("device_map = 'auto'"),bi=n(" is prefered for inference as it will dispatch efficiently the model on the available ressources."),_l=h(),be=a("h3"),Se=a("a"),Ua=a("span"),u(Nt.$$.fragment),yi=h(),za=a("span"),vi=n("Advanced usecases"),gl=h(),mo=a("p"),_i=n("This section is intended to advanced users, that want to explore what it is possible to do beyond loading and running 8-bit models."),wl=h(),ye=a("h4"),Ye=a("a"),Na=a("span"),u(Zt.$$.fragment),gi=h(),Oe=a("span"),wi=n("Offload between "),Za=a("code"),Ei=n("cpu"),$i=n(" and "),Wa=a("code"),Mi=n("gpu"),El=h(),B=a("p"),Ti=n("One of the advanced usecase of this is being able to load a model and dispatch the weights between "),qa=a("code"),ki=n("CPU"),Ji=n(" and "),ja=a("code"),Ci=n("GPU"),Ai=n(". Note that the weights that will be dispatched on CPU "),Xa=a("strong"),Bi=n("will not"),Ui=n(" be converted in 8-bit, thus kept in "),Fa=a("code"),zi=n("float32"),Ni=n(". This feature is intended for users that want to fit a very large model and dispatch the model between GPU and CPU."),$l=h(),U=a("p"),Zi=n("First, load a "),Pa=a("code"),Wi=n("BitsAndBytesConfig"),qi=n(" from "),Va=a("code"),ji=n("transformers"),Xi=n(" and set the attribute "),Ia=a("code"),Fi=n("llm_int8_enable_fp32_cpu_offload"),Pi=n(" to "),Ra=a("code"),Vi=n("True"),Ii=n(":"),Ml=h(),u(Wt.$$.fragment),Tl=h(),Y=a("p"),Ri=n("Let\u2019s say you want to load "),Qa=a("code"),Qi=n("bigscience/bloom-1b7"),xi=n(" model, and you have just enough GPU RAM to fit the entire model except the "),xa=a("code"),Gi=n("lm_head"),Di=n(". Therefore write a custom device_map as follows:"),kl=h(),u(qt.$$.fragment),Jl=h(),bo=a("p"),Si=n("And load your model as follows:"),Cl=h(),u(jt.$$.fragment),Al=h(),yo=a("p"),Yi=n("And that\u2019s it! Enjoy your model!"),Bl=h(),ve=a("h4"),He=a("a"),Ga=a("span"),u(Xt.$$.fragment),Oi=h(),vo=a("span"),Hi=n("Play with "),Da=a("code"),Li=n("llm_int8_threshold"),Ul=h(),O=a("p"),Ki=n("You can play with the "),Sa=a("code"),ed=n("llm_int8_threshold"),td=n(` argument to change the threshold of the outliers. An \u201Coutlier\u201D is a hidden state value that is greater than a certain threshold.
This corresponds to the outlier threshold for outlier detection as described in `),Ya=a("code"),od=n("LLM.int8()"),ad=n(` paper. Any hidden states value that is above this threshold will be considered an outlier and the operation on those values will be done in fp16. Values are usually normally distributed, that is, most values are in the range [-3.5, 3.5], but there are some exceptional systematic outliers that are very differently distributed for large models. These outliers are often in the interval [-60, -6] or [6, 60]. Int8 quantization works well for values of magnitude ~5, but beyond that, there is a significant performance penalty. A good default threshold is 6, but a lower threshold might be needed for more unstable models (small models, fine-tuning).
This argument can impact the inference speed of the model. We suggest to play with this parameter to find which one is the best for your usecase.`),zl=h(),u(Ft.$$.fragment),Nl=h(),_e=a("h4"),Le=a("a"),Oa=a("span"),u(Pt.$$.fragment),sd=h(),Ha=a("span"),ld=n("Skip the conversion of some modules"),Zl=h(),ge=a("p"),nd=n("Some models has several modules that needs to be not converted in 8-bit to ensure stability. For example Jukebox model has several "),La=a("code"),rd=n("lm_head"),id=n(" modules that should be skipped. Play with "),Ka=a("code"),dd=n("llm_int8_skip_modules"),Wl=h(),u(Vt.$$.fragment),ql=h(),we=a("h4"),Ke=a("a"),es=a("span"),u(It.$$.fragment),hd=h(),ts=a("span"),fd=n("Fine-tune a model that has been loaded in 8-bit"),jl=h(),X=a("p"),cd=n(`With the official support of adapters in the Hugging Face ecosystem, you can fine-tune models that have been loaded in 8-bit.
This enables fine-tuning large models such as `),os=a("code"),ud=n("flan-t5-large"),pd=n(" or "),as=a("code"),md=n("facebook/opt-6.7b"),bd=n(" in a single google Colab. Please have a look at "),Rt=a("a"),ss=a("code"),yd=n("peft"),vd=n(" library for more details."),Xl=h(),C=a("p"),_d=n("Note that you don\u2019t need to pass "),ls=a("code"),gd=n("device_map"),wd=n(" when loading the model for training. It will automatically load your model on your GPU. You can also set the device map to a specific device if needed (e.g. "),ns=a("code"),Ed=n("cuda:0"),$d=n(", "),rs=a("code"),Md=n("0"),Td=n(", "),is=a("code"),kd=n("torch.device('cuda:0')"),Jd=n("). Please note that "),ds=a("code"),Cd=n("device_map=auto"),Ad=n(" should be used for inference only."),Fl=h(),Ee=a("h3"),et=a("a"),hs=a("span"),u(Qt.$$.fragment),Bd=h(),fs=a("span"),Ud=n("BitsAndBytesConfig"),Pl=h(),w=a("div"),u(xt.$$.fragment),zd=h(),Gt=a("p"),Nd=n(`This is a wrapper class about all possible attributes and features that you can play with a model that has been
loaded using `),cs=a("code"),Zd=n("bitsandbytes"),Wd=n("."),qd=h(),$e=a("p"),jd=n("This replaces "),us=a("code"),Xd=n("load_in_8bit"),Fd=n(" or "),ps=a("code"),Pd=n("load_in_4bit"),Vd=n("therefore both options are mutually exclusive."),Id=h(),Z=a("p"),Rd=n("Currently only supports "),ms=a("code"),Qd=n("LLM.int8()"),xd=n(", "),bs=a("code"),Gd=n("FP4"),Dd=n(", and "),ys=a("code"),Sd=n("NF4"),Yd=n(" quantization. If more methods are added to "),vs=a("code"),Od=n("bitsandbytes"),Hd=n(`,
then more arguments will be added to this class.`),Ld=h(),tt=a("div"),u(Dt.$$.fragment),Kd=h(),St=a("p"),eh=n("Instantiates a "),_o=a("a"),th=n("BitsAndBytesConfig"),oh=n(" from a Python dictionary of parameters."),ah=h(),ot=a("div"),u(Yt.$$.fragment),sh=h(),Me=a("p"),lh=n("Returns "),_s=a("code"),nh=n("True"),rh=n(" if the model is quantizable, "),gs=a("code"),ih=n("False"),dh=n(" otherwise."),hh=h(),at=a("div"),u(Ot.$$.fragment),fh=h(),ws=a("p"),ch=n("Safety checker that arguments are correct - also replaces some NoneType arguments with their default values."),uh=h(),st=a("div"),u(Ht.$$.fragment),ph=h(),Lt=a("p"),mh=n(`This method returns the quantization method used for the model. If the model is not quantizable, it returns
`),Es=a("code"),bh=n("None"),yh=n("."),vh=h(),lt=a("div"),u(Kt.$$.fragment),_h=h(),eo=a("p"),gh=n(`Serializes this instance to a Python dictionary. Returns:
`),$s=a("code"),wh=n("Dict[str, Any]"),Eh=n(": Dictionary of all the attributes that make up this configuration instance."),$h=h(),nt=a("div"),u(to.$$.fragment),Mh=h(),Ms=a("p"),Th=n("Save this instance to a JSON file."),Vl=h(),Te=a("h2"),rt=a("a"),Ts=a("span"),u(oo.$$.fragment),kh=h(),go=a("span"),Jh=n("Quantization with \u{1F917} "),ks=a("code"),Ch=n("optimum"),Il=h(),H=a("p"),Ah=n("Please have a look at "),ao=a("a"),Bh=n("Optimum documentation"),Uh=n(" to learn more about quantization methods that are supported by "),Js=a("code"),zh=n("optimum"),Nh=n(" and see if these are applicable for your usecase."),this.h()},l(e){const i=vu('[data-svelte="svelte-1phssyn"]',document.head);_=s(i,"META",{name:!0,content:!0}),i.forEach(o),k=f(e),g=s(e,"H1",{class:!0});var so=l(g);E=s(so,"A",{id:!0,class:!0,href:!0});var Cs=l(E);te=s(Cs,"SPAN",{});var As=l(te);p(z.$$.fragment,As),As.forEach(o),Cs.forEach(o),ft=f(so),oe=s(so,"SPAN",{});var Xh=l(oe);ae=r(Xh,"Quantize \u{1F917} Transformers models"),Xh.forEach(o),so.forEach(o),Je=f(e),N=s(e,"H2",{class:!0});var Ql=l(N);A=s(Ql,"A",{id:!0,class:!0,href:!0});var Fh=l(A);se=s(Fh,"SPAN",{});var Ph=l(se);p(V.$$.fragment,Ph),Ph.forEach(o),Fh.forEach(o),le=f(Ql),M=s(Ql,"SPAN",{});var Zh=l(M);Ce=s(Zh,"CODE",{});var Vh=l(Ce);no=r(Vh,"bitsandbytes"),Vh.forEach(o),ro=r(Zh," Integration"),Zh.forEach(o),Ql.forEach(o),ct=f(e),q=s(e,"P",{});var it=l(q);En=r(it,"\u{1F917} Transformers is closely integrated with most used modules on "),No=s(it,"CODE",{});var Ih=l(No);$n=r(Ih,"bitsandbytes"),Ih.forEach(o),Mn=r(it,`. You can load your model in 8-bit precision with few lines of code.
This is supported by most of the GPU hardwares since the `),Zo=s(it,"CODE",{});var Rh=l(Zo);Tn=r(Rh,"0.37.0"),Rh.forEach(o),kn=r(it," release of "),Wo=s(it,"CODE",{});var Qh=l(Wo);Jn=r(Qh,"bitsandbytes"),Qh.forEach(o),Cn=r(it,"."),it.forEach(o),Ws=f(e),I=s(e,"P",{});var wo=l(I);An=r(wo,"Learn more about the quantization method in the "),ut=s(wo,"A",{href:!0,rel:!0});var xh=l(ut);Bn=r(xh,"LLM.int8()"),xh.forEach(o),Un=r(wo," paper, or the "),pt=s(wo,"A",{href:!0,rel:!0});var Gh=l(pt);zn=r(Gh,"blogpost"),Gh.forEach(o),Nn=r(wo," about the collaboration."),wo.forEach(o),qs=f(e),R=s(e,"P",{});var Eo=l(R);Zn=r(Eo,"Since its "),qo=s(Eo,"CODE",{});var Dh=l(qo);Wn=r(Dh,"0.39.0"),Dh.forEach(o),qn=r(Eo," release, you can load any model that supports "),jo=s(Eo,"CODE",{});var Sh=l(jo);jn=r(Sh,"device_map"),Sh.forEach(o),Xn=r(Eo," using 4-bit quantization, leveraging FP4 data type."),Eo.forEach(o),js=f(e),Ae=s(e,"P",{});var xl=l(Ae);Fn=r(xl,"Here are the things you can do using "),Xo=s(xl,"CODE",{});var Yh=l(Xo);Pn=r(Yh,"bitsandbytes"),Yh.forEach(o),Vn=r(xl," integration"),xl.forEach(o),Xs=f(e),ne=s(e,"H3",{class:!0});var Gl=l(ne);Be=s(Gl,"A",{id:!0,class:!0,href:!0});var Oh=l(Be);Fo=s(Oh,"SPAN",{});var Hh=l(Fo);p(mt.$$.fragment,Hh),Hh.forEach(o),Oh.forEach(o),In=f(Gl),Po=s(Gl,"SPAN",{});var Lh=l(Po);Rn=r(Lh,"FP4 quantization"),Lh.forEach(o),Gl.forEach(o),Fs=f(e),re=s(e,"H4",{class:!0});var Dl=l(re);Ue=s(Dl,"A",{id:!0,class:!0,href:!0});var Kh=l(Ue);Vo=s(Kh,"SPAN",{});var ef=l(Vo);p(bt.$$.fragment,ef),ef.forEach(o),Kh.forEach(o),Qn=f(Dl),Io=s(Dl,"SPAN",{});var tf=l(Io);xn=r(tf,"Requirements"),tf.forEach(o),Dl.forEach(o),Ps=f(e),io=s(e,"P",{});var of=l(io);Gn=r(of,"Make sure that you have installed the requirements below before running any of the code snippets below."),of.forEach(o),Vs=f(e),Q=s(e,"UL",{});var $o=l(Q);Ro=s($o,"LI",{});var af=l(Ro);ze=s(af,"P",{});var Bs=l(ze);Dn=r(Bs,"Latest "),Qo=s(Bs,"CODE",{});var sf=l(Qo);Sn=r(sf,"bitsandbytes"),sf.forEach(o),Yn=r(Bs,` library
`),xo=s(Bs,"CODE",{});var lf=l(xo);On=r(lf,"pip install bitsandbytes>=0.39.0"),lf.forEach(o),Bs.forEach(o),af.forEach(o),Hn=f($o),Go=s($o,"LI",{});var nf=l(Go);Ne=s(nf,"P",{});var Us=l(Ne);Ln=r(Us,"Install latest "),Do=s(Us,"CODE",{});var rf=l(Do);Kn=r(rf,"accelerate"),rf.forEach(o),er=r(Us,` from source
`),So=s(Us,"CODE",{});var df=l(So);tr=r(df,"pip install git+https://github.com/huggingface/accelerate.git"),df.forEach(o),Us.forEach(o),nf.forEach(o),or=f($o),Yo=s($o,"LI",{});var hf=l(Yo);Ze=s(hf,"P",{});var zs=l(Ze);ar=r(zs,"Install latest "),Oo=s(zs,"CODE",{});var ff=l(Oo);sr=r(ff,"transformers"),ff.forEach(o),lr=r(zs,` from source
`),Ho=s(zs,"CODE",{});var cf=l(Ho);nr=r(cf,"pip install git+https://github.com/huggingface/transformers.git"),cf.forEach(o),zs.forEach(o),hf.forEach(o),$o.forEach(o),Is=f(e),ie=s(e,"H4",{class:!0});var Sl=l(ie);We=s(Sl,"A",{id:!0,class:!0,href:!0});var uf=l(We);Lo=s(uf,"SPAN",{});var pf=l(Lo);p(yt.$$.fragment,pf),pf.forEach(o),uf.forEach(o),rr=f(Sl),Ko=s(Sl,"SPAN",{});var mf=l(Ko);ir=r(mf,"Load a large model in 4bit"),mf.forEach(o),Sl.forEach(o),Rs=f(e),x=s(e,"P",{});var Mo=l(x);dr=r(Mo,"By using "),ea=s(Mo,"CODE",{});var bf=l(ea);hr=r(bf,"load_in_4bit=True"),bf.forEach(o),fr=r(Mo," when calling the "),ta=s(Mo,"CODE",{});var yf=l(ta);cr=r(yf,".from_pretrained"),yf.forEach(o),ur=r(Mo," method, you can divide your memory use by 4 (roughly)."),Mo.forEach(o),Qs=f(e),p(vt.$$.fragment,e),xs=f(e),p(qe.$$.fragment,e),Gs=f(e),de=s(e,"H3",{class:!0});var Yl=l(de);je=s(Yl,"A",{id:!0,class:!0,href:!0});var vf=l(je);oa=s(vf,"SPAN",{});var _f=l(oa);p(_t.$$.fragment,_f),_f.forEach(o),vf.forEach(o),pr=f(Yl),aa=s(Yl,"SPAN",{});var gf=l(aa);mr=r(gf,"Load a large model in 8bit"),gf.forEach(o),Yl.forEach(o),Ds=f(e),G=s(e,"P",{});var To=l(G);br=r(To,"You can load a model by roughly halving the memory requirements by using "),sa=s(To,"CODE",{});var wf=l(sa);yr=r(wf,"load_in_8bit=True"),wf.forEach(o),vr=r(To," argument when calling "),la=s(To,"CODE",{});var Ef=l(la);_r=r(Ef,".from_pretrained"),Ef.forEach(o),gr=r(To," method"),To.forEach(o),Ss=f(e),p(gt.$$.fragment,e),Ys=f(e),Xe=s(e,"P",{});var Ol=l(Xe);wr=r(Ol,"Then, use your model as you would usually use a "),ho=s(Ol,"A",{href:!0});var $f=l(ho);Er=r($f,"PreTrainedModel"),$f.forEach(o),$r=r(Ol,"."),Ol.forEach(o),Os=f(e),Fe=s(e,"P",{});var Hl=l(Fe);Mr=r(Hl,"You can check the memory footprint of your model with "),na=s(Hl,"CODE",{});var Mf=l(na);Tr=r(Mf,"get_memory_footprint"),Mf.forEach(o),kr=r(Hl," method."),Hl.forEach(o),Hs=f(e),p(wt.$$.fragment,e),Ls=f(e),fo=s(e,"P",{});var Tf=l(fo);Jr=r(Tf,"With this integration we were able to load large models on smaller devices and run them without any issue."),Tf.forEach(o),Ks=f(e),p(Pe.$$.fragment,e),el=f(e),he=s(e,"H4",{class:!0});var Ll=l(he);Ve=s(Ll,"A",{id:!0,class:!0,href:!0});var kf=l(Ve);ra=s(kf,"SPAN",{});var Jf=l(ra);p(Et.$$.fragment,Jf),Jf.forEach(o),kf.forEach(o),Cr=f(Ll),ia=s(Ll,"SPAN",{});var Cf=l(ia);Ar=r(Cf,"Advanced usecases"),Cf.forEach(o),Ll.forEach(o),tl=f(e),co=s(e,"P",{});var Af=l(co);Br=r(Af,"Here we will cover some advanced usecases you can perform with FP4 quantization"),Af.forEach(o),ol=f(e),fe=s(e,"H5",{class:!0});var Kl=l(fe);Ie=s(Kl,"A",{id:!0,class:!0,href:!0});var Bf=l(Ie);da=s(Bf,"SPAN",{});var Uf=l(da);p($t.$$.fragment,Uf),Uf.forEach(o),Bf.forEach(o),Ur=f(Kl),ha=s(Kl,"SPAN",{});var zf=l(ha);zr=r(zf,"Change the compute dtype"),zf.forEach(o),Kl.forEach(o),al=f(e),D=s(e,"P",{});var ko=l(D);Nr=r(ko,"The compute dtype is used to change the dtype that will be used during computation. For example, hidden states could be in "),fa=s(ko,"CODE",{});var Nf=l(fa);Zr=r(Nf,"float32"),Nf.forEach(o),Wr=r(ko," but computation can be set to bf16 for speedups. By default, the compute dtype is set to "),ca=s(ko,"CODE",{});var Zf=l(ca);qr=r(Zf,"float32"),Zf.forEach(o),jr=r(ko,"."),ko.forEach(o),sl=f(e),p(Mt.$$.fragment,e),ll=f(e),ce=s(e,"H5",{class:!0});var en=l(ce);Re=s(en,"A",{id:!0,class:!0,href:!0});var Wf=l(Re);ua=s(Wf,"SPAN",{});var qf=l(ua);p(Tt.$$.fragment,qf),qf.forEach(o),Wf.forEach(o),Xr=f(en),pa=s(en,"SPAN",{});var jf=l(pa);Fr=r(jf,"Using NF4 (Normal Float 4) data type"),jf.forEach(o),en.forEach(o),nl=f(e),uo=s(e,"P",{});var Xf=l(uo);Pr=r(Xf,"You can also use the NF4 data type, which is a new 4bit datatype adapted for weights that have been initialized using a normal distribution. For that run:"),Xf.forEach(o),rl=f(e),p(kt.$$.fragment,e),il=f(e),ue=s(e,"H5",{class:!0});var tn=l(ue);Qe=s(tn,"A",{id:!0,class:!0,href:!0});var Ff=l(Qe);ma=s(Ff,"SPAN",{});var Pf=l(ma);p(Jt.$$.fragment,Pf),Pf.forEach(o),Ff.forEach(o),Vr=f(tn),ba=s(tn,"SPAN",{});var Vf=l(ba);Ir=r(Vf,"Use nested quantization for more memory efficient inference"),Vf.forEach(o),tn.forEach(o),dl=f(e),po=s(e,"P",{});var If=l(po);Rr=r(If,"We also advise users to use the nested quantization technique. This saves more memory at no additional performance - from our empirical observations, this enables fine-tuning llama-13b model on an NVIDIA-T4 16GB with a sequence length of 1024, batch size of 1 and gradient accumulation steps of 4."),If.forEach(o),hl=f(e),p(Ct.$$.fragment,e),fl=f(e),pe=s(e,"H3",{class:!0});var on=l(pe);xe=s(on,"A",{id:!0,class:!0,href:!0});var Rf=l(xe);ya=s(Rf,"SPAN",{});var Qf=l(ya);p(At.$$.fragment,Qf),Qf.forEach(o),Rf.forEach(o),Qr=f(on),va=s(on,"SPAN",{});var xf=l(va);xr=r(xf,"Push quantized models on the \u{1F917} Hub"),xf.forEach(o),on.forEach(o),cl=f(e),j=s(e,"P",{});var dt=l(j);Gr=r(dt,"You can push a quantized model on the Hub by naively using "),_a=s(dt,"CODE",{});var Gf=l(_a);Dr=r(Gf,"push_to_hub"),Gf.forEach(o),Sr=r(dt,` method. This will first push the quantization configuration file, then push the quantized model weights.
Make sure to use `),ga=s(dt,"CODE",{});var Df=l(ga);Yr=r(Df,"bitsandbytes>0.37.2"),Df.forEach(o),Or=r(dt," (at this time of writing, we tested it on "),wa=s(dt,"CODE",{});var Sf=l(wa);Hr=r(Sf,"bitsandbytes==0.38.0.post1"),Sf.forEach(o),Lr=r(dt,") to be able to use this feature."),dt.forEach(o),ul=f(e),p(Bt.$$.fragment,e),pl=f(e),p(Ge.$$.fragment,e),ml=f(e),me=s(e,"H3",{class:!0});var an=l(me);De=s(an,"A",{id:!0,class:!0,href:!0});var Yf=l(De);Ea=s(Yf,"SPAN",{});var Of=l(Ea);p(Ut.$$.fragment,Of),Of.forEach(o),Yf.forEach(o),Kr=f(an),$a=s(an,"SPAN",{});var Hf=l($a);ei=r(Hf,"Load a quantized model from the \u{1F917} Hub"),Hf.forEach(o),an.forEach(o),bl=f(e),S=s(e,"P",{});var Jo=l(S);ti=r(Jo,"You can load a quantized model from the Hub by using "),Ma=s(Jo,"CODE",{});var Lf=l(Ma);oi=r(Lf,"from_pretrained"),Lf.forEach(o),ai=r(Jo," method. Make sure that the pushed weights are quantized, by checking that the attribute "),Ta=s(Jo,"CODE",{});var Kf=l(Ta);si=r(Kf,"quantization_config"),Kf.forEach(o),li=r(Jo," is present in the model configuration object."),Jo.forEach(o),yl=f(e),p(zt.$$.fragment,e),vl=f(e),J=s(e,"P",{});var F=l(J);ni=r(F,"Note that in this case, you don\u2019t need to specify the arguments "),ka=s(F,"CODE",{});var ec=l(ka);ri=r(ec,"load_in_8bit=True"),ec.forEach(o),ii=r(F,", but you need to make sure that "),Ja=s(F,"CODE",{});var tc=l(Ja);di=r(tc,"bitsandbytes"),tc.forEach(o),hi=r(F," and "),Ca=s(F,"CODE",{});var oc=l(Ca);fi=r(oc,"accelerate"),oc.forEach(o),ci=r(F,` are installed.
Note also that `),Aa=s(F,"CODE",{});var ac=l(Aa);ui=r(ac,"device_map"),ac.forEach(o),pi=r(F," is optional but setting "),Ba=s(F,"CODE",{});var sc=l(Ba);mi=r(sc,"device_map = 'auto'"),sc.forEach(o),bi=r(F," is prefered for inference as it will dispatch efficiently the model on the available ressources."),F.forEach(o),_l=f(e),be=s(e,"H3",{class:!0});var sn=l(be);Se=s(sn,"A",{id:!0,class:!0,href:!0});var lc=l(Se);Ua=s(lc,"SPAN",{});var nc=l(Ua);p(Nt.$$.fragment,nc),nc.forEach(o),lc.forEach(o),yi=f(sn),za=s(sn,"SPAN",{});var rc=l(za);vi=r(rc,"Advanced usecases"),rc.forEach(o),sn.forEach(o),gl=f(e),mo=s(e,"P",{});var ic=l(mo);_i=r(ic,"This section is intended to advanced users, that want to explore what it is possible to do beyond loading and running 8-bit models."),ic.forEach(o),wl=f(e),ye=s(e,"H4",{class:!0});var ln=l(ye);Ye=s(ln,"A",{id:!0,class:!0,href:!0});var dc=l(Ye);Na=s(dc,"SPAN",{});var hc=l(Na);p(Zt.$$.fragment,hc),hc.forEach(o),dc.forEach(o),gi=f(ln),Oe=s(ln,"SPAN",{});var Ns=l(Oe);wi=r(Ns,"Offload between "),Za=s(Ns,"CODE",{});var fc=l(Za);Ei=r(fc,"cpu"),fc.forEach(o),$i=r(Ns," and "),Wa=s(Ns,"CODE",{});var cc=l(Wa);Mi=r(cc,"gpu"),cc.forEach(o),Ns.forEach(o),ln.forEach(o),El=f(e),B=s(e,"P",{});var L=l(B);Ti=r(L,"One of the advanced usecase of this is being able to load a model and dispatch the weights between "),qa=s(L,"CODE",{});var uc=l(qa);ki=r(uc,"CPU"),uc.forEach(o),Ji=r(L," and "),ja=s(L,"CODE",{});var pc=l(ja);Ci=r(pc,"GPU"),pc.forEach(o),Ai=r(L,". Note that the weights that will be dispatched on CPU "),Xa=s(L,"STRONG",{});var mc=l(Xa);Bi=r(mc,"will not"),mc.forEach(o),Ui=r(L," be converted in 8-bit, thus kept in "),Fa=s(L,"CODE",{});var bc=l(Fa);zi=r(bc,"float32"),bc.forEach(o),Ni=r(L,". This feature is intended for users that want to fit a very large model and dispatch the model between GPU and CPU."),L.forEach(o),$l=f(e),U=s(e,"P",{});var K=l(U);Zi=r(K,"First, load a "),Pa=s(K,"CODE",{});var yc=l(Pa);Wi=r(yc,"BitsAndBytesConfig"),yc.forEach(o),qi=r(K," from "),Va=s(K,"CODE",{});var vc=l(Va);ji=r(vc,"transformers"),vc.forEach(o),Xi=r(K," and set the attribute "),Ia=s(K,"CODE",{});var _c=l(Ia);Fi=r(_c,"llm_int8_enable_fp32_cpu_offload"),_c.forEach(o),Pi=r(K," to "),Ra=s(K,"CODE",{});var gc=l(Ra);Vi=r(gc,"True"),gc.forEach(o),Ii=r(K,":"),K.forEach(o),Ml=f(e),p(Wt.$$.fragment,e),Tl=f(e),Y=s(e,"P",{});var Co=l(Y);Ri=r(Co,"Let\u2019s say you want to load "),Qa=s(Co,"CODE",{});var wc=l(Qa);Qi=r(wc,"bigscience/bloom-1b7"),wc.forEach(o),xi=r(Co," model, and you have just enough GPU RAM to fit the entire model except the "),xa=s(Co,"CODE",{});var Ec=l(xa);Gi=r(Ec,"lm_head"),Ec.forEach(o),Di=r(Co,". Therefore write a custom device_map as follows:"),Co.forEach(o),kl=f(e),p(qt.$$.fragment,e),Jl=f(e),bo=s(e,"P",{});var $c=l(bo);Si=r($c,"And load your model as follows:"),$c.forEach(o),Cl=f(e),p(jt.$$.fragment,e),Al=f(e),yo=s(e,"P",{});var Mc=l(yo);Yi=r(Mc,"And that\u2019s it! Enjoy your model!"),Mc.forEach(o),Bl=f(e),ve=s(e,"H4",{class:!0});var nn=l(ve);He=s(nn,"A",{id:!0,class:!0,href:!0});var Tc=l(He);Ga=s(Tc,"SPAN",{});var kc=l(Ga);p(Xt.$$.fragment,kc),kc.forEach(o),Tc.forEach(o),Oi=f(nn),vo=s(nn,"SPAN",{});var Wh=l(vo);Hi=r(Wh,"Play with "),Da=s(Wh,"CODE",{});var Jc=l(Da);Li=r(Jc,"llm_int8_threshold"),Jc.forEach(o),Wh.forEach(o),nn.forEach(o),Ul=f(e),O=s(e,"P",{});var Ao=l(O);Ki=r(Ao,"You can play with the "),Sa=s(Ao,"CODE",{});var Cc=l(Sa);ed=r(Cc,"llm_int8_threshold"),Cc.forEach(o),td=r(Ao,` argument to change the threshold of the outliers. An \u201Coutlier\u201D is a hidden state value that is greater than a certain threshold.
This corresponds to the outlier threshold for outlier detection as described in `),Ya=s(Ao,"CODE",{});var Ac=l(Ya);od=r(Ac,"LLM.int8()"),Ac.forEach(o),ad=r(Ao,` paper. Any hidden states value that is above this threshold will be considered an outlier and the operation on those values will be done in fp16. Values are usually normally distributed, that is, most values are in the range [-3.5, 3.5], but there are some exceptional systematic outliers that are very differently distributed for large models. These outliers are often in the interval [-60, -6] or [6, 60]. Int8 quantization works well for values of magnitude ~5, but beyond that, there is a significant performance penalty. A good default threshold is 6, but a lower threshold might be needed for more unstable models (small models, fine-tuning).
This argument can impact the inference speed of the model. We suggest to play with this parameter to find which one is the best for your usecase.`),Ao.forEach(o),zl=f(e),p(Ft.$$.fragment,e),Nl=f(e),_e=s(e,"H4",{class:!0});var rn=l(_e);Le=s(rn,"A",{id:!0,class:!0,href:!0});var Bc=l(Le);Oa=s(Bc,"SPAN",{});var Uc=l(Oa);p(Pt.$$.fragment,Uc),Uc.forEach(o),Bc.forEach(o),sd=f(rn),Ha=s(rn,"SPAN",{});var zc=l(Ha);ld=r(zc,"Skip the conversion of some modules"),zc.forEach(o),rn.forEach(o),Zl=f(e),ge=s(e,"P",{});var Zs=l(ge);nd=r(Zs,"Some models has several modules that needs to be not converted in 8-bit to ensure stability. For example Jukebox model has several "),La=s(Zs,"CODE",{});var Nc=l(La);rd=r(Nc,"lm_head"),Nc.forEach(o),id=r(Zs," modules that should be skipped. Play with "),Ka=s(Zs,"CODE",{});var Zc=l(Ka);dd=r(Zc,"llm_int8_skip_modules"),Zc.forEach(o),Zs.forEach(o),Wl=f(e),p(Vt.$$.fragment,e),ql=f(e),we=s(e,"H4",{class:!0});var dn=l(we);Ke=s(dn,"A",{id:!0,class:!0,href:!0});var Wc=l(Ke);es=s(Wc,"SPAN",{});var qc=l(es);p(It.$$.fragment,qc),qc.forEach(o),Wc.forEach(o),hd=f(dn),ts=s(dn,"SPAN",{});var jc=l(ts);fd=r(jc,"Fine-tune a model that has been loaded in 8-bit"),jc.forEach(o),dn.forEach(o),jl=f(e),X=s(e,"P",{});var ht=l(X);cd=r(ht,`With the official support of adapters in the Hugging Face ecosystem, you can fine-tune models that have been loaded in 8-bit.
This enables fine-tuning large models such as `),os=s(ht,"CODE",{});var Xc=l(os);ud=r(Xc,"flan-t5-large"),Xc.forEach(o),pd=r(ht," or "),as=s(ht,"CODE",{});var Fc=l(as);md=r(Fc,"facebook/opt-6.7b"),Fc.forEach(o),bd=r(ht," in a single google Colab. Please have a look at "),Rt=s(ht,"A",{href:!0,rel:!0});var Pc=l(Rt);ss=s(Pc,"CODE",{});var Vc=l(ss);yd=r(Vc,"peft"),Vc.forEach(o),Pc.forEach(o),vd=r(ht," library for more details."),ht.forEach(o),Xl=f(e),C=s(e,"P",{});var P=l(C);_d=r(P,"Note that you don\u2019t need to pass "),ls=s(P,"CODE",{});var Ic=l(ls);gd=r(Ic,"device_map"),Ic.forEach(o),wd=r(P," when loading the model for training. It will automatically load your model on your GPU. You can also set the device map to a specific device if needed (e.g. "),ns=s(P,"CODE",{});var Rc=l(ns);Ed=r(Rc,"cuda:0"),Rc.forEach(o),$d=r(P,", "),rs=s(P,"CODE",{});var Qc=l(rs);Md=r(Qc,"0"),Qc.forEach(o),Td=r(P,", "),is=s(P,"CODE",{});var xc=l(is);kd=r(xc,"torch.device('cuda:0')"),xc.forEach(o),Jd=r(P,"). Please note that "),ds=s(P,"CODE",{});var Gc=l(ds);Cd=r(Gc,"device_map=auto"),Gc.forEach(o),Ad=r(P," should be used for inference only."),P.forEach(o),Fl=f(e),Ee=s(e,"H3",{class:!0});var hn=l(Ee);et=s(hn,"A",{id:!0,class:!0,href:!0});var Dc=l(et);hs=s(Dc,"SPAN",{});var Sc=l(hs);p(Qt.$$.fragment,Sc),Sc.forEach(o),Dc.forEach(o),Bd=f(hn),fs=s(hn,"SPAN",{});var Yc=l(fs);Ud=r(Yc,"BitsAndBytesConfig"),Yc.forEach(o),hn.forEach(o),Pl=f(e),w=s(e,"DIV",{class:!0});var $=l(w);p(xt.$$.fragment,$),zd=f($),Gt=s($,"P",{});var fn=l(Gt);Nd=r(fn,`This is a wrapper class about all possible attributes and features that you can play with a model that has been
loaded using `),cs=s(fn,"CODE",{});var Oc=l(cs);Zd=r(Oc,"bitsandbytes"),Oc.forEach(o),Wd=r(fn,"."),fn.forEach(o),qd=f($),$e=s($,"P",{});var Bo=l($e);jd=r(Bo,"This replaces "),us=s(Bo,"CODE",{});var Hc=l(us);Xd=r(Hc,"load_in_8bit"),Hc.forEach(o),Fd=r(Bo," or "),ps=s(Bo,"CODE",{});var Lc=l(ps);Pd=r(Lc,"load_in_4bit"),Lc.forEach(o),Vd=r(Bo,"therefore both options are mutually exclusive."),Bo.forEach(o),Id=f($),Z=s($,"P",{});var ee=l(Z);Rd=r(ee,"Currently only supports "),ms=s(ee,"CODE",{});var Kc=l(ms);Qd=r(Kc,"LLM.int8()"),Kc.forEach(o),xd=r(ee,", "),bs=s(ee,"CODE",{});var eu=l(bs);Gd=r(eu,"FP4"),eu.forEach(o),Dd=r(ee,", and "),ys=s(ee,"CODE",{});var tu=l(ys);Sd=r(tu,"NF4"),tu.forEach(o),Yd=r(ee," quantization. If more methods are added to "),vs=s(ee,"CODE",{});var ou=l(vs);Od=r(ou,"bitsandbytes"),ou.forEach(o),Hd=r(ee,`,
then more arguments will be added to this class.`),ee.forEach(o),Ld=f($),tt=s($,"DIV",{class:!0});var cn=l(tt);p(Dt.$$.fragment,cn),Kd=f(cn),St=s(cn,"P",{});var un=l(St);eh=r(un,"Instantiates a "),_o=s(un,"A",{href:!0});var au=l(_o);th=r(au,"BitsAndBytesConfig"),au.forEach(o),oh=r(un," from a Python dictionary of parameters."),un.forEach(o),cn.forEach(o),ah=f($),ot=s($,"DIV",{class:!0});var pn=l(ot);p(Yt.$$.fragment,pn),sh=f(pn),Me=s(pn,"P",{});var Uo=l(Me);lh=r(Uo,"Returns "),_s=s(Uo,"CODE",{});var su=l(_s);nh=r(su,"True"),su.forEach(o),rh=r(Uo," if the model is quantizable, "),gs=s(Uo,"CODE",{});var lu=l(gs);ih=r(lu,"False"),lu.forEach(o),dh=r(Uo," otherwise."),Uo.forEach(o),pn.forEach(o),hh=f($),at=s($,"DIV",{class:!0});var mn=l(at);p(Ot.$$.fragment,mn),fh=f(mn),ws=s(mn,"P",{});var nu=l(ws);ch=r(nu,"Safety checker that arguments are correct - also replaces some NoneType arguments with their default values."),nu.forEach(o),mn.forEach(o),uh=f($),st=s($,"DIV",{class:!0});var bn=l(st);p(Ht.$$.fragment,bn),ph=f(bn),Lt=s(bn,"P",{});var yn=l(Lt);mh=r(yn,`This method returns the quantization method used for the model. If the model is not quantizable, it returns
`),Es=s(yn,"CODE",{});var ru=l(Es);bh=r(ru,"None"),ru.forEach(o),yh=r(yn,"."),yn.forEach(o),bn.forEach(o),vh=f($),lt=s($,"DIV",{class:!0});var vn=l(lt);p(Kt.$$.fragment,vn),_h=f(vn),eo=s(vn,"P",{});var _n=l(eo);gh=r(_n,`Serializes this instance to a Python dictionary. Returns:
`),$s=s(_n,"CODE",{});var iu=l($s);wh=r(iu,"Dict[str, Any]"),iu.forEach(o),Eh=r(_n,": Dictionary of all the attributes that make up this configuration instance."),_n.forEach(o),vn.forEach(o),$h=f($),nt=s($,"DIV",{class:!0});var gn=l(nt);p(to.$$.fragment,gn),Mh=f(gn),Ms=s(gn,"P",{});var du=l(Ms);Th=r(du,"Save this instance to a JSON file."),du.forEach(o),gn.forEach(o),$.forEach(o),Vl=f(e),Te=s(e,"H2",{class:!0});var wn=l(Te);rt=s(wn,"A",{id:!0,class:!0,href:!0});var hu=l(rt);Ts=s(hu,"SPAN",{});var fu=l(Ts);p(oo.$$.fragment,fu),fu.forEach(o),hu.forEach(o),kh=f(wn),go=s(wn,"SPAN",{});var qh=l(go);Jh=r(qh,"Quantization with \u{1F917} "),ks=s(qh,"CODE",{});var cu=l(ks);Ch=r(cu,"optimum"),cu.forEach(o),qh.forEach(o),wn.forEach(o),Il=f(e),H=s(e,"P",{});var zo=l(H);Ah=r(zo,"Please have a look at "),ao=s(zo,"A",{href:!0,rel:!0});var uu=l(ao);Bh=r(uu,"Optimum documentation"),uu.forEach(o),Uh=r(zo," to learn more about quantization methods that are supported by "),Js=s(zo,"CODE",{});var pu=l(Js);zh=r(pu,"optimum"),pu.forEach(o),Nh=r(zo," and see if these are applicable for your usecase."),zo.forEach(o),this.h()},h(){c(_,"name","hf:doc:metadata"),c(_,"content",JSON.stringify(Mu)),c(E,"id","quantize-transformers-models"),c(E,"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"),c(E,"href","#quantize-transformers-models"),c(g,"class","relative group"),c(A,"id","bitsandbytes-integration"),c(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"),c(A,"href","#bitsandbytes-integration"),c(N,"class","relative group"),c(ut,"href","https://arxiv.org/abs/2208.07339"),c(ut,"rel","nofollow"),c(pt,"href","https://huggingface.co/blog/hf-bitsandbytes-integration"),c(pt,"rel","nofollow"),c(Be,"id","fp4-quantization"),c(Be,"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"),c(Be,"href","#fp4-quantization"),c(ne,"class","relative group"),c(Ue,"id","requirements"),c(Ue,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(Ue,"href","#requirements"),c(re,"class","relative group"),c(We,"id","load-a-large-model-in-4bit"),c(We,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(We,"href","#load-a-large-model-in-4bit"),c(ie,"class","relative group"),c(je,"id","load-a-large-model-in-8bit"),c(je,"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"),c(je,"href","#load-a-large-model-in-8bit"),c(de,"class","relative group"),c(ho,"href","/docs/transformers/v4.30.0/en/main_classes/model#transformers.PreTrainedModel"),c(Ve,"id","advanced-usecases"),c(Ve,"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"),c(Ve,"href","#advanced-usecases"),c(he,"class","relative group"),c(Ie,"id","change-the-compute-dtype"),c(Ie,"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"),c(Ie,"href","#change-the-compute-dtype"),c(fe,"class","relative group"),c(Re,"id","using-nf4-normal-float-4-data-type"),c(Re,"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"),c(Re,"href","#using-nf4-normal-float-4-data-type"),c(ce,"class","relative group"),c(Qe,"id","use-nested-quantization-for-more-memory-efficient-inference"),c(Qe,"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"),c(Qe,"href","#use-nested-quantization-for-more-memory-efficient-inference"),c(ue,"class","relative group"),c(xe,"id","push-quantized-models-on-the-hub"),c(xe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(xe,"href","#push-quantized-models-on-the-hub"),c(pe,"class","relative group"),c(De,"id","load-a-quantized-model-from-the-hub"),c(De,"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"),c(De,"href","#load-a-quantized-model-from-the-hub"),c(me,"class","relative group"),c(Se,"id","advanced-usecases"),c(Se,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(Se,"href","#advanced-usecases"),c(be,"class","relative group"),c(Ye,"id","offload-between-cpu-and-gpu"),c(Ye,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(Ye,"href","#offload-between-cpu-and-gpu"),c(ye,"class","relative group"),c(He,"id","play-with-llmint8threshold"),c(He,"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"),c(He,"href","#play-with-llmint8threshold"),c(ve,"class","relative group"),c(Le,"id","skip-the-conversion-of-some-modules"),c(Le,"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"),c(Le,"href","#skip-the-conversion-of-some-modules"),c(_e,"class","relative group"),c(Ke,"id","finetune-a-model-that-has-been-loaded-in-8bit"),c(Ke,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(Ke,"href","#finetune-a-model-that-has-been-loaded-in-8bit"),c(we,"class","relative group"),c(Rt,"href","https://github.com/huggingface/peft"),c(Rt,"rel","nofollow"),c(et,"id","transformers.BitsAndBytesConfig"),c(et,"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"),c(et,"href","#transformers.BitsAndBytesConfig"),c(Ee,"class","relative group"),c(_o,"href","/docs/transformers/v4.30.0/en/main_classes/quantization#transformers.BitsAndBytesConfig"),c(tt,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),c(ot,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),c(at,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),c(st,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),c(lt,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),c(nt,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),c(w,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),c(rt,"id","quantization-with-optimum"),c(rt,"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"),c(rt,"href","#quantization-with-optimum"),c(Te,"class","relative group"),c(ao,"href","https://huggingface.co/docs/optimum/index"),c(ao,"rel","nofollow")},m(e,i){t(document.head,_),d(e,k,i),d(e,g,i),t(g,E),t(E,te),m(z,te,null),t(g,ft),t(g,oe),t(oe,ae),d(e,Je,i),d(e,N,i),t(N,A),t(A,se),m(V,se,null),t(N,le),t(N,M),t(M,Ce),t(Ce,no),t(M,ro),d(e,ct,i),d(e,q,i),t(q,En),t(q,No),t(No,$n),t(q,Mn),t(q,Zo),t(Zo,Tn),t(q,kn),t(q,Wo),t(Wo,Jn),t(q,Cn),d(e,Ws,i),d(e,I,i),t(I,An),t(I,ut),t(ut,Bn),t(I,Un),t(I,pt),t(pt,zn),t(I,Nn),d(e,qs,i),d(e,R,i),t(R,Zn),t(R,qo),t(qo,Wn),t(R,qn),t(R,jo),t(jo,jn),t(R,Xn),d(e,js,i),d(e,Ae,i),t(Ae,Fn),t(Ae,Xo),t(Xo,Pn),t(Ae,Vn),d(e,Xs,i),d(e,ne,i),t(ne,Be),t(Be,Fo),m(mt,Fo,null),t(ne,In),t(ne,Po),t(Po,Rn),d(e,Fs,i),d(e,re,i),t(re,Ue),t(Ue,Vo),m(bt,Vo,null),t(re,Qn),t(re,Io),t(Io,xn),d(e,Ps,i),d(e,io,i),t(io,Gn),d(e,Vs,i),d(e,Q,i),t(Q,Ro),t(Ro,ze),t(ze,Dn),t(ze,Qo),t(Qo,Sn),t(ze,Yn),t(ze,xo),t(xo,On),t(Q,Hn),t(Q,Go),t(Go,Ne),t(Ne,Ln),t(Ne,Do),t(Do,Kn),t(Ne,er),t(Ne,So),t(So,tr),t(Q,or),t(Q,Yo),t(Yo,Ze),t(Ze,ar),t(Ze,Oo),t(Oo,sr),t(Ze,lr),t(Ze,Ho),t(Ho,nr),d(e,Is,i),d(e,ie,i),t(ie,We),t(We,Lo),m(yt,Lo,null),t(ie,rr),t(ie,Ko),t(Ko,ir),d(e,Rs,i),d(e,x,i),t(x,dr),t(x,ea),t(ea,hr),t(x,fr),t(x,ta),t(ta,cr),t(x,ur),d(e,Qs,i),m(vt,e,i),d(e,xs,i),m(qe,e,i),d(e,Gs,i),d(e,de,i),t(de,je),t(je,oa),m(_t,oa,null),t(de,pr),t(de,aa),t(aa,mr),d(e,Ds,i),d(e,G,i),t(G,br),t(G,sa),t(sa,yr),t(G,vr),t(G,la),t(la,_r),t(G,gr),d(e,Ss,i),m(gt,e,i),d(e,Ys,i),d(e,Xe,i),t(Xe,wr),t(Xe,ho),t(ho,Er),t(Xe,$r),d(e,Os,i),d(e,Fe,i),t(Fe,Mr),t(Fe,na),t(na,Tr),t(Fe,kr),d(e,Hs,i),m(wt,e,i),d(e,Ls,i),d(e,fo,i),t(fo,Jr),d(e,Ks,i),m(Pe,e,i),d(e,el,i),d(e,he,i),t(he,Ve),t(Ve,ra),m(Et,ra,null),t(he,Cr),t(he,ia),t(ia,Ar),d(e,tl,i),d(e,co,i),t(co,Br),d(e,ol,i),d(e,fe,i),t(fe,Ie),t(Ie,da),m($t,da,null),t(fe,Ur),t(fe,ha),t(ha,zr),d(e,al,i),d(e,D,i),t(D,Nr),t(D,fa),t(fa,Zr),t(D,Wr),t(D,ca),t(ca,qr),t(D,jr),d(e,sl,i),m(Mt,e,i),d(e,ll,i),d(e,ce,i),t(ce,Re),t(Re,ua),m(Tt,ua,null),t(ce,Xr),t(ce,pa),t(pa,Fr),d(e,nl,i),d(e,uo,i),t(uo,Pr),d(e,rl,i),m(kt,e,i),d(e,il,i),d(e,ue,i),t(ue,Qe),t(Qe,ma),m(Jt,ma,null),t(ue,Vr),t(ue,ba),t(ba,Ir),d(e,dl,i),d(e,po,i),t(po,Rr),d(e,hl,i),m(Ct,e,i),d(e,fl,i),d(e,pe,i),t(pe,xe),t(xe,ya),m(At,ya,null),t(pe,Qr),t(pe,va),t(va,xr),d(e,cl,i),d(e,j,i),t(j,Gr),t(j,_a),t(_a,Dr),t(j,Sr),t(j,ga),t(ga,Yr),t(j,Or),t(j,wa),t(wa,Hr),t(j,Lr),d(e,ul,i),m(Bt,e,i),d(e,pl,i),m(Ge,e,i),d(e,ml,i),d(e,me,i),t(me,De),t(De,Ea),m(Ut,Ea,null),t(me,Kr),t(me,$a),t($a,ei),d(e,bl,i),d(e,S,i),t(S,ti),t(S,Ma),t(Ma,oi),t(S,ai),t(S,Ta),t(Ta,si),t(S,li),d(e,yl,i),m(zt,e,i),d(e,vl,i),d(e,J,i),t(J,ni),t(J,ka),t(ka,ri),t(J,ii),t(J,Ja),t(Ja,di),t(J,hi),t(J,Ca),t(Ca,fi),t(J,ci),t(J,Aa),t(Aa,ui),t(J,pi),t(J,Ba),t(Ba,mi),t(J,bi),d(e,_l,i),d(e,be,i),t(be,Se),t(Se,Ua),m(Nt,Ua,null),t(be,yi),t(be,za),t(za,vi),d(e,gl,i),d(e,mo,i),t(mo,_i),d(e,wl,i),d(e,ye,i),t(ye,Ye),t(Ye,Na),m(Zt,Na,null),t(ye,gi),t(ye,Oe),t(Oe,wi),t(Oe,Za),t(Za,Ei),t(Oe,$i),t(Oe,Wa),t(Wa,Mi),d(e,El,i),d(e,B,i),t(B,Ti),t(B,qa),t(qa,ki),t(B,Ji),t(B,ja),t(ja,Ci),t(B,Ai),t(B,Xa),t(Xa,Bi),t(B,Ui),t(B,Fa),t(Fa,zi),t(B,Ni),d(e,$l,i),d(e,U,i),t(U,Zi),t(U,Pa),t(Pa,Wi),t(U,qi),t(U,Va),t(Va,ji),t(U,Xi),t(U,Ia),t(Ia,Fi),t(U,Pi),t(U,Ra),t(Ra,Vi),t(U,Ii),d(e,Ml,i),m(Wt,e,i),d(e,Tl,i),d(e,Y,i),t(Y,Ri),t(Y,Qa),t(Qa,Qi),t(Y,xi),t(Y,xa),t(xa,Gi),t(Y,Di),d(e,kl,i),m(qt,e,i),d(e,Jl,i),d(e,bo,i),t(bo,Si),d(e,Cl,i),m(jt,e,i),d(e,Al,i),d(e,yo,i),t(yo,Yi),d(e,Bl,i),d(e,ve,i),t(ve,He),t(He,Ga),m(Xt,Ga,null),t(ve,Oi),t(ve,vo),t(vo,Hi),t(vo,Da),t(Da,Li),d(e,Ul,i),d(e,O,i),t(O,Ki),t(O,Sa),t(Sa,ed),t(O,td),t(O,Ya),t(Ya,od),t(O,ad),d(e,zl,i),m(Ft,e,i),d(e,Nl,i),d(e,_e,i),t(_e,Le),t(Le,Oa),m(Pt,Oa,null),t(_e,sd),t(_e,Ha),t(Ha,ld),d(e,Zl,i),d(e,ge,i),t(ge,nd),t(ge,La),t(La,rd),t(ge,id),t(ge,Ka),t(Ka,dd),d(e,Wl,i),m(Vt,e,i),d(e,ql,i),d(e,we,i),t(we,Ke),t(Ke,es),m(It,es,null),t(we,hd),t(we,ts),t(ts,fd),d(e,jl,i),d(e,X,i),t(X,cd),t(X,os),t(os,ud),t(X,pd),t(X,as),t(as,md),t(X,bd),t(X,Rt),t(Rt,ss),t(ss,yd),t(X,vd),d(e,Xl,i),d(e,C,i),t(C,_d),t(C,ls),t(ls,gd),t(C,wd),t(C,ns),t(ns,Ed),t(C,$d),t(C,rs),t(rs,Md),t(C,Td),t(C,is),t(is,kd),t(C,Jd),t(C,ds),t(ds,Cd),t(C,Ad),d(e,Fl,i),d(e,Ee,i),t(Ee,et),t(et,hs),m(Qt,hs,null),t(Ee,Bd),t(Ee,fs),t(fs,Ud),d(e,Pl,i),d(e,w,i),m(xt,w,null),t(w,zd),t(w,Gt),t(Gt,Nd),t(Gt,cs),t(cs,Zd),t(Gt,Wd),t(w,qd),t(w,$e),t($e,jd),t($e,us),t(us,Xd),t($e,Fd),t($e,ps),t(ps,Pd),t($e,Vd),t(w,Id),t(w,Z),t(Z,Rd),t(Z,ms),t(ms,Qd),t(Z,xd),t(Z,bs),t(bs,Gd),t(Z,Dd),t(Z,ys),t(ys,Sd),t(Z,Yd),t(Z,vs),t(vs,Od),t(Z,Hd),t(w,Ld),t(w,tt),m(Dt,tt,null),t(tt,Kd),t(tt,St),t(St,eh),t(St,_o),t(_o,th),t(St,oh),t(w,ah),t(w,ot),m(Yt,ot,null),t(ot,sh),t(ot,Me),t(Me,lh),t(Me,_s),t(_s,nh),t(Me,rh),t(Me,gs),t(gs,ih),t(Me,dh),t(w,hh),t(w,at),m(Ot,at,null),t(at,fh),t(at,ws),t(ws,ch),t(w,uh),t(w,st),m(Ht,st,null),t(st,ph),t(st,Lt),t(Lt,mh),t(Lt,Es),t(Es,bh),t(Lt,yh),t(w,vh),t(w,lt),m(Kt,lt,null),t(lt,_h),t(lt,eo),t(eo,gh),t(eo,$s),t($s,wh),t(eo,Eh),t(w,$h),t(w,nt),m(to,nt,null),t(nt,Mh),t(nt,Ms),t(Ms,Th),d(e,Vl,i),d(e,Te,i),t(Te,rt),t(rt,Ts),m(oo,Ts,null),t(Te,kh),t(Te,go),t(go,Jh),t(go,ks),t(ks,Ch),d(e,Il,i),d(e,H,i),t(H,Ah),t(H,ao),t(ao,Bh),t(H,Uh),t(H,Js),t(Js,zh),t(H,Nh),Rl=!0},p(e,[i]){const so={};i&2&&(so.$$scope={dirty:i,ctx:e}),qe.$set(so);const Cs={};i&2&&(Cs.$$scope={dirty:i,ctx:e}),Pe.$set(Cs);const As={};i&2&&(As.$$scope={dirty:i,ctx:e}),Ge.$set(As)},i(e){Rl||(b(z.$$.fragment,e),b(V.$$.fragment,e),b(mt.$$.fragment,e),b(bt.$$.fragment,e),b(yt.$$.fragment,e),b(vt.$$.fragment,e),b(qe.$$.fragment,e),b(_t.$$.fragment,e),b(gt.$$.fragment,e),b(wt.$$.fragment,e),b(Pe.$$.fragment,e),b(Et.$$.fragment,e),b($t.$$.fragment,e),b(Mt.$$.fragment,e),b(Tt.$$.fragment,e),b(kt.$$.fragment,e),b(Jt.$$.fragment,e),b(Ct.$$.fragment,e),b(At.$$.fragment,e),b(Bt.$$.fragment,e),b(Ge.$$.fragment,e),b(Ut.$$.fragment,e),b(zt.$$.fragment,e),b(Nt.$$.fragment,e),b(Zt.$$.fragment,e),b(Wt.$$.fragment,e),b(qt.$$.fragment,e),b(jt.$$.fragment,e),b(Xt.$$.fragment,e),b(Ft.$$.fragment,e),b(Pt.$$.fragment,e),b(Vt.$$.fragment,e),b(It.$$.fragment,e),b(Qt.$$.fragment,e),b(xt.$$.fragment,e),b(Dt.$$.fragment,e),b(Yt.$$.fragment,e),b(Ot.$$.fragment,e),b(Ht.$$.fragment,e),b(Kt.$$.fragment,e),b(to.$$.fragment,e),b(oo.$$.fragment,e),Rl=!0)},o(e){y(z.$$.fragment,e),y(V.$$.fragment,e),y(mt.$$.fragment,e),y(bt.$$.fragment,e),y(yt.$$.fragment,e),y(vt.$$.fragment,e),y(qe.$$.fragment,e),y(_t.$$.fragment,e),y(gt.$$.fragment,e),y(wt.$$.fragment,e),y(Pe.$$.fragment,e),y(Et.$$.fragment,e),y($t.$$.fragment,e),y(Mt.$$.fragment,e),y(Tt.$$.fragment,e),y(kt.$$.fragment,e),y(Jt.$$.fragment,e),y(Ct.$$.fragment,e),y(At.$$.fragment,e),y(Bt.$$.fragment,e),y(Ge.$$.fragment,e),y(Ut.$$.fragment,e),y(zt.$$.fragment,e),y(Nt.$$.fragment,e),y(Zt.$$.fragment,e),y(Wt.$$.fragment,e),y(qt.$$.fragment,e),y(jt.$$.fragment,e),y(Xt.$$.fragment,e),y(Ft.$$.fragment,e),y(Pt.$$.fragment,e),y(Vt.$$.fragment,e),y(It.$$.fragment,e),y(Qt.$$.fragment,e),y(xt.$$.fragment,e),y(Dt.$$.fragment,e),y(Yt.$$.fragment,e),y(Ot.$$.fragment,e),y(Ht.$$.fragment,e),y(Kt.$$.fragment,e),y(to.$$.fragment,e),y(oo.$$.fragment,e),Rl=!1},d(e){o(_),e&&o(k),e&&o(g),v(z),e&&o(Je),e&&o(N),v(V),e&&o(ct),e&&o(q),e&&o(Ws),e&&o(I),e&&o(qs),e&&o(R),e&&o(js),e&&o(Ae),e&&o(Xs),e&&o(ne),v(mt),e&&o(Fs),e&&o(re),v(bt),e&&o(Ps),e&&o(io),e&&o(Vs),e&&o(Q),e&&o(Is),e&&o(ie),v(yt),e&&o(Rs),e&&o(x),e&&o(Qs),v(vt,e),e&&o(xs),v(qe,e),e&&o(Gs),e&&o(de),v(_t),e&&o(Ds),e&&o(G),e&&o(Ss),v(gt,e),e&&o(Ys),e&&o(Xe),e&&o(Os),e&&o(Fe),e&&o(Hs),v(wt,e),e&&o(Ls),e&&o(fo),e&&o(Ks),v(Pe,e),e&&o(el),e&&o(he),v(Et),e&&o(tl),e&&o(co),e&&o(ol),e&&o(fe),v($t),e&&o(al),e&&o(D),e&&o(sl),v(Mt,e),e&&o(ll),e&&o(ce),v(Tt),e&&o(nl),e&&o(uo),e&&o(rl),v(kt,e),e&&o(il),e&&o(ue),v(Jt),e&&o(dl),e&&o(po),e&&o(hl),v(Ct,e),e&&o(fl),e&&o(pe),v(At),e&&o(cl),e&&o(j),e&&o(ul),v(Bt,e),e&&o(pl),v(Ge,e),e&&o(ml),e&&o(me),v(Ut),e&&o(bl),e&&o(S),e&&o(yl),v(zt,e),e&&o(vl),e&&o(J),e&&o(_l),e&&o(be),v(Nt),e&&o(gl),e&&o(mo),e&&o(wl),e&&o(ye),v(Zt),e&&o(El),e&&o(B),e&&o($l),e&&o(U),e&&o(Ml),v(Wt,e),e&&o(Tl),e&&o(Y),e&&o(kl),v(qt,e),e&&o(Jl),e&&o(bo),e&&o(Cl),v(jt,e),e&&o(Al),e&&o(yo),e&&o(Bl),e&&o(ve),v(Xt),e&&o(Ul),e&&o(O),e&&o(zl),v(Ft,e),e&&o(Nl),e&&o(_e),v(Pt),e&&o(Zl),e&&o(ge),e&&o(Wl),v(Vt,e),e&&o(ql),e&&o(we),v(It),e&&o(jl),e&&o(X),e&&o(Xl),e&&o(C),e&&o(Fl),e&&o(Ee),v(Qt),e&&o(Pl),e&&o(w),v(xt),v(Dt),v(Yt),v(Ot),v(Ht),v(Kt),v(to),e&&o(Vl),e&&o(Te),v(oo),e&&o(Il),e&&o(H)}}}const Mu={local:"quantize-transformers-models",sections:[{local:"bitsandbytes-integration",sections:[{local:"fp4-quantization",sections:[{local:"requirements",title:"Requirements"},{local:"load-a-large-model-in-4bit",title:"Load a large model in 4bit"}],title:"FP4 quantization "},{local:"load-a-large-model-in-8bit",sections:[{local:"advanced-usecases",sections:[{local:"change-the-compute-dtype",title:"Change the compute dtype"},{local:"using-nf4-normal-float-4-data-type",title:"Using NF4 (Normal Float 4) data type "},{local:"use-nested-quantization-for-more-memory-efficient-inference",title:"Use nested quantization for more memory efficient inference"}],title:"Advanced usecases"}],title:"Load a large model in 8bit"},{local:"push-quantized-models-on-the-hub",title:"Push quantized models on the \u{1F917} Hub"},{local:"load-a-quantized-model-from-the-hub",title:"Load a quantized model from the \u{1F917} Hub"},{local:"advanced-usecases",sections:[{local:"offload-between-cpu-and-gpu",title:"Offload between `cpu` and `gpu`"},{local:"play-with-llmint8threshold",title:"Play with `llm_int8_threshold`"},{local:"skip-the-conversion-of-some-modules",title:"Skip the conversion of some modules"},{local:"finetune-a-model-that-has-been-loaded-in-8bit",title:"Fine-tune a model that has been loaded in 8-bit"}],title:"Advanced usecases"},{local:"transformers.BitsAndBytesConfig",title:"BitsAndBytesConfig"}],title:"`bitsandbytes` Integration"},{local:"quantization-with-optimum",title:"Quantization with \u{1F917} `optimum` "}],title:"Quantize \u{1F917} Transformers models"};function Tu(ke){return _u(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Uu extends mu{constructor(_){super();bu(this,_,Tu,$u,yu,{})}}export{Uu as default,Mu as metadata};
