import{S as Qf,i as Hf,s as qf,e as s,k as d,w as v,t as o,M as Of,c as r,d as a,m as u,a as n,x as T,h as l,b as f,N as Kf,G as t,g as h,y as J,q as E,o as U,B as $,v as ep,L as tp}from"../../chunks/vendor-hf-doc-builder.js";import{T as at}from"../../chunks/Tip-hf-doc-builder.js";import{I as Ue}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as B}from"../../chunks/CodeBlock-hf-doc-builder.js";function ap(Z){let p,M;return{c(){p=s("p"),M=o("This is an experimental feature. Its APIs can change in future.")},l(c){p=r(c,"P",{});var w=n(p);M=l(w,"This is an experimental feature. Its APIs can change in future."),w.forEach(a)},m(c,w){h(c,p,w),t(p,M)},d(c){c&&a(p)}}}function op(Z){let p,M,c,w,j;return{c(){p=s("p"),M=o(`\u{1F4A1} LoRA is not only limited to attention layers. The authors found that amending
the attention layers of a language model is sufficient to obtain good downstream performance with great efficiency. This is why it\u2019s common to just add the LoRA weights to the attention layers of a model. Check out the `),c=s("a"),w=o("Using LoRA for efficient Stable Diffusion fine-tuning"),j=o(" blog for more information about how LoRA works!"),this.h()},l(m){p=r(m,"P",{});var y=n(p);M=l(y,`\u{1F4A1} LoRA is not only limited to attention layers. The authors found that amending
the attention layers of a language model is sufficient to obtain good downstream performance with great efficiency. This is why it\u2019s common to just add the LoRA weights to the attention layers of a model. Check out the `),c=r(y,"A",{href:!0,rel:!0});var R=n(c);w=l(R,"Using LoRA for efficient Stable Diffusion fine-tuning"),R.forEach(a),j=l(y," blog for more information about how LoRA works!"),y.forEach(a),this.h()},h(){f(c,"href","https://huggingface.co/blog/lora"),f(c,"rel","nofollow")},m(m,y){h(m,p,y),t(p,M),t(p,c),t(c,w),t(p,j)},d(m){m&&a(p)}}}function lp(Z){let p,M,c,w,j,m,y,R,A,g,I,_,k,N,G,Q,X,S,H,D;return{c(){p=s("p"),M=o("\u{1F4A1} A "),c=s("code"),w=o("scale"),j=o(" value of "),m=s("code"),y=o("0"),R=o(" is the same as not using your LoRA weights and you\u2019re only using the base model weights, and a "),A=s("code"),g=o("scale"),I=o(" value of "),_=s("code"),k=o("1"),N=o(" means you\u2019re only using the fully finetuned LoRA weights. Values between "),G=s("code"),Q=o("0"),X=o(" and "),S=s("code"),H=o("1"),D=o(" interpolates between the two weights.")},l(L){p=r(L,"P",{});var b=n(p);M=l(b,"\u{1F4A1} A "),c=r(b,"CODE",{});var O=n(c);w=l(O,"scale"),O.forEach(a),j=l(b," value of "),m=r(b,"CODE",{});var W=n(m);y=l(W,"0"),W.forEach(a),R=l(b," is the same as not using your LoRA weights and you\u2019re only using the base model weights, and a "),A=r(b,"CODE",{});var V=n(A);g=l(V,"scale"),V.forEach(a),I=l(b," value of "),_=r(b,"CODE",{});var ce=n(_);k=l(ce,"1"),ce.forEach(a),N=l(b," means you\u2019re only using the fully finetuned LoRA weights. Values between "),G=r(b,"CODE",{});var Y=n(G);Q=l(Y,"0"),Y.forEach(a),X=l(b," and "),S=r(b,"CODE",{});var me=n(S);H=l(me,"1"),me.forEach(a),D=l(b," interpolates between the two weights."),b.forEach(a)},m(L,b){h(L,p,b),t(p,M),t(p,c),t(c,w),t(p,j),t(p,m),t(m,y),t(p,R),t(p,A),t(A,g),t(p,I),t(p,_),t(_,k),t(p,N),t(p,G),t(G,Q),t(p,X),t(p,S),t(S,H),t(p,D)},d(L){L&&a(p)}}}function sp(Z){let p,M,c,w,j,m,y,R,A,g,I;return g=new B({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1Yi5yZXBvY2FyZCUyMGltcG9ydCUyMFJlcG9DYXJkJTBBJTBBbG9yYV9tb2RlbF9pZCUyMCUzRCUyMCUyMnNheWFrcGF1bCUyRnNkLW1vZGVsLWZpbmV0dW5lZC1sb3JhLXQ0JTIyJTBBY2FyZCUyMCUzRCUyMFJlcG9DYXJkLmxvYWQobG9yYV9tb2RlbF9pZCklMEFiYXNlX21vZGVsX2lkJTIwJTNEJTIwY2FyZC5kYXRhLnRvX2RpY3QoKSU1QiUyMmJhc2VfbW9kZWwlMjIlNUQlMEElMEFwaXBlJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKGJhc2VfbW9kZWxfaWQlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYpJTBBLi4u",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub.repocard <span class="hljs-keyword">import</span> RepoCard

lora_model_id = <span class="hljs-string">&quot;sayakpaul/sd-model-finetuned-lora-t4&quot;</span>
card = RepoCard.load(lora_model_id)
base_model_id = card.data.to_dict()[<span class="hljs-string">&quot;base_model&quot;</span>]

pipe = StableDiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16)
...`}}),{c(){p=s("p"),M=o(`If you are loading the LoRA parameters from the Hub and if the Hub repository has
a `),c=s("code"),w=o("base_model"),j=o(" tag (such as "),m=s("a"),y=o("this"),R=o(`), then
you can do:`),A=d(),v(g.$$.fragment),this.h()},l(_){p=r(_,"P",{});var k=n(p);M=l(k,`If you are loading the LoRA parameters from the Hub and if the Hub repository has
a `),c=r(k,"CODE",{});var N=n(c);w=l(N,"base_model"),N.forEach(a),j=l(k," tag (such as "),m=r(k,"A",{href:!0,rel:!0});var G=n(m);y=l(G,"this"),G.forEach(a),R=l(k,`), then
you can do:`),k.forEach(a),A=u(_),T(g.$$.fragment,_),this.h()},h(){f(m,"href","https://huggingface.co/sayakpaul/sd-model-finetuned-lora-t4/blob/main/README.md?code=true#L4"),f(m,"rel","nofollow")},m(_,k){h(_,p,k),t(p,M),t(p,c),t(c,w),t(p,j),t(p,m),t(m,y),t(p,R),h(_,A,k),J(g,_,k),I=!0},p:tp,i(_){I||(E(g.$$.fragment,_),I=!0)},o(_){U(g.$$.fragment,_),I=!1},d(_){_&&a(p),_&&a(A),$(g,_)}}}function rp(Z){let p,M,c,w,j;return{c(){p=s("p"),M=o("\u{1F4A1} Take a look at the "),c=s("a"),w=o("Training Stable Diffusion with DreamBooth using \u{1F9E8} Diffusers"),j=o(" blog for an in-depth analysis of DreamBooth experiments and recommended settings."),this.h()},l(m){p=r(m,"P",{});var y=n(p);M=l(y,"\u{1F4A1} Take a look at the "),c=r(y,"A",{href:!0,rel:!0});var R=n(c);w=l(R,"Training Stable Diffusion with DreamBooth using \u{1F9E8} Diffusers"),R.forEach(a),j=l(y," blog for an in-depth analysis of DreamBooth experiments and recommended settings."),y.forEach(a),this.h()},h(){f(c,"href","https://huggingface.co/blog/dreambooth"),f(c,"rel","nofollow")},m(m,y){h(m,p,y),t(p,M),t(p,c),t(c,w),t(p,j)},d(m){m&&a(p)}}}function np(Z){let p,M,c,w,j,m,y,R,A,g,I,_,k,N,G,Q,X,S,H,D;return{c(){p=s("p"),M=o("\u{1F4A1} A "),c=s("code"),w=o("scale"),j=o(" value of "),m=s("code"),y=o("0"),R=o(" is the same as not using your LoRA weights and you\u2019re only using the base model weights, and a "),A=s("code"),g=o("scale"),I=o(" value of "),_=s("code"),k=o("1"),N=o(" means you\u2019re only using the fully finetuned LoRA weights. Values between "),G=s("code"),Q=o("0"),X=o(" and "),S=s("code"),H=o("1"),D=o(" interpolates between the two weights.")},l(L){p=r(L,"P",{});var b=n(p);M=l(b,"\u{1F4A1} A "),c=r(b,"CODE",{});var O=n(c);w=l(O,"scale"),O.forEach(a),j=l(b," value of "),m=r(b,"CODE",{});var W=n(m);y=l(W,"0"),W.forEach(a),R=l(b," is the same as not using your LoRA weights and you\u2019re only using the base model weights, and a "),A=r(b,"CODE",{});var V=n(A);g=l(V,"scale"),V.forEach(a),I=l(b," value of "),_=r(b,"CODE",{});var ce=n(_);k=l(ce,"1"),ce.forEach(a),N=l(b," means you\u2019re only using the fully finetuned LoRA weights. Values between "),G=r(b,"CODE",{});var Y=n(G);Q=l(Y,"0"),Y.forEach(a),X=l(b," and "),S=r(b,"CODE",{});var me=n(S);H=l(me,"1"),me.forEach(a),D=l(b," interpolates between the two weights."),b.forEach(a)},m(L,b){h(L,p,b),t(p,M),t(p,c),t(c,w),t(p,j),t(p,m),t(m,y),t(p,R),t(p,A),t(A,g),t(p,I),t(p,_),t(_,k),t(p,N),t(p,G),t(G,Q),t(p,X),t(p,S),t(S,H),t(p,D)},d(L){L&&a(p)}}}function ip(Z){let p,M,c,w,j,m,y,R;return{c(){p=s("p"),M=o(`If your LoRA parameters involve the UNet as well as the Text Encoder, then passing
`),c=s("code"),w=o('cross_attention_kwargs={"scale": 0.5}'),j=o(" will apply the "),m=s("code"),y=o("scale"),R=o(` value to both the UNet
and the Text Encoder.`)},l(A){p=r(A,"P",{});var g=n(p);M=l(g,`If your LoRA parameters involve the UNet as well as the Text Encoder, then passing
`),c=r(g,"CODE",{});var I=n(c);w=l(I,'cross_attention_kwargs={"scale": 0.5}'),I.forEach(a),j=l(g," will apply the "),m=r(g,"CODE",{});var _=n(m);y=l(_,"scale"),_.forEach(a),R=l(g,` value to both the UNet
and the Text Encoder.`),g.forEach(a)},m(A,g){h(A,p,g),t(p,M),t(p,c),t(c,w),t(p,j),t(p,m),t(m,y),t(p,R)},d(A){A&&a(p)}}}function hp(Z){let p,M,c,w,j,m,y,R;return{c(){p=s("p"),M=o("If you\u2019re loading a checkpoint in the "),c=s("code"),w=o("safetensors"),j=o(" format, please ensure you have "),m=s("code"),y=o("safetensors"),R=o(" installed.")},l(A){p=r(A,"P",{});var g=n(p);M=l(g,"If you\u2019re loading a checkpoint in the "),c=r(g,"CODE",{});var I=n(c);w=l(I,"safetensors"),I.forEach(a),j=l(g," format, please ensure you have "),m=r(g,"CODE",{});var _=n(m);y=l(_,"safetensors"),_.forEach(a),R=l(g," installed."),g.forEach(a)},m(A,g){h(A,p,g),t(p,M),t(p,c),t(c,w),t(p,j),t(p,m),t(m,y),t(p,R)},d(A){A&&a(p)}}}function fp(Z){let p,M,c,w,j,m,y,R,A,g,I,_,k,N,G,Q,X,S,H,D,L,b,O,W,V,ce,Y,me,Es,Us,Da,$s,js,we,As,ea,Rs,ks,Va,Is,Zs,Ns,Ya,Gs,Po,$e,zo,x,ot,Ws,Bs,lt,Ss,Ls,st,Cs,Xs,rt,Ds,Vs,Qo,je,Ys,ta,xs,Fs,Ho,nt,qo,ge,Ae,xa,it,Ps,Fa,zs,Oo,aa,Qs,Ko,_e,Re,Pa,ht,Hs,za,qs,el,K,Os,ft,Qa,Ks,er,pt,tr,ar,tl,C,or,Ha,lr,sr,dt,qa,rr,nr,Oa,ir,hr,oa,fr,pr,al,ee,dr,Ka,ur,cr,eo,mr,wr,ol,ut,ll,la,gr,sl,te,sa,to,_r,yr,br,ke,ao,Mr,vr,ct,Tr,Jr,Er,ra,oo,Ur,$r,rl,ae,jr,mt,Ar,Rr,lo,kr,Ir,nl,wt,il,ye,Ie,so,gt,Zr,ro,Nr,hl,oe,Gr,na,Wr,Br,ia,Sr,Lr,fl,_t,pl,le,Cr,no,Xr,Dr,io,Vr,Yr,dl,Ze,ul,yt,cl,Ne,ml,be,Ge,ho,bt,xr,fo,Fr,wl,Mt,vt,Pr,zr,gl,We,_l,Me,Be,po,Tt,Qr,uo,Hr,yl,F,qr,Jt,co,Or,Kr,Et,en,tn,ha,an,on,bl,P,ln,mo,sn,rn,Ut,wo,nn,hn,go,fn,pn,Ml,Se,dn,_o,un,cn,vl,$t,Tl,fa,mn,Jl,se,pa,yo,wn,gn,_n,Le,bo,yn,bn,jt,Mn,vn,Tn,da,Mo,Jn,En,El,re,Un,At,$n,jn,vo,An,Rn,Ul,ne,kn,To,In,Zn,Jo,Nn,Gn,$l,Rt,jl,ve,Ce,Eo,kt,Wn,Uo,Bn,Al,Xe,Sn,ua,Ln,Cn,Rl,It,kl,ie,Xn,$o,Dn,Vn,jo,Yn,xn,Il,De,Zl,Zt,Nl,he,Fn,Ao,Pn,zn,Ro,Qn,Hn,Gl,Nt,Wl,Ve,Bl,z,qn,ca,On,Kn,ma,ei,ti,wa,ai,oi,Sl,Ye,Gt,Wt,li,Bt,ko,si,ri,ni,St,ii,Io,Lt,hi,Ct,Zo,fi,pi,Ll,q,No,di,ui,ga,ci,mi,_a,wi,gi,Cl,Te,xe,Go,Xt,_i,Wo,yi,Xl,Fe,bi,ya,Mi,vi,Dl,Je,Pe,Bo,Dt,Ti,So,Ji,Vl,fe,Ei,Vt,Ui,$i,Yt,ji,Ai,Yl,pe,Ri,ba,ki,Ii,xt,Zi,Ni,xl,ze,Gi,Ft,Wi,Bi,Fl,Pt,Pl,Qe,Si,Ma,Li,Ci,zl,zt,Ql,va,Xi,Hl,Qt,ql,He,Ol,Ta,Di,Kl,Ht,es,Ja,Vi,ts,Ea,Ua,Oi,as,qe,Yi,$a,xi,Fi,os,qt,ls;return m=new Ue({}),I=new at({props:{warning:!0,$$slots:{default:[ap]},$$scope:{ctx:Z}}}),$e=new at({props:{$$slots:{default:[op]},$$scope:{ctx:Z}}}),nt=new B({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login"}}),it=new Ue({}),ht=new Ue({}),ut=new B({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTBBZXhwb3J0JTIwT1VUUFVUX0RJUiUzRCUyMiUyRnNkZGF0YSUyRmZpbmV0dW5lJTJGbG9yYSUyRnBva2Vtb24lMjIlMEFleHBvcnQlMjBIVUJfTU9ERUxfSUQlM0QlMjJwb2tlbW9uLWxvcmElMjIlMEFleHBvcnQlMjBEQVRBU0VUX05BTUUlM0QlMjJsYW1iZGFsYWJzJTJGcG9rZW1vbi1ibGlwLWNhcHRpb25zJTIy",highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;/sddata/finetune/lora/pokemon&quot;</span>
<span class="hljs-built_in">export</span> HUB_MODEL_ID=<span class="hljs-string">&quot;pokemon-lora&quot;</span>
<span class="hljs-built_in">export</span> DATASET_NAME=<span class="hljs-string">&quot;lambdalabs/pokemon-blip-captions&quot;</span>`}}),wt=new B({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMC0tbWl4ZWRfcHJlY2lzaW9uJTNEJTIyZnAxNiUyMiUyMCUyMHRyYWluX3RleHRfdG9faW1hZ2VfbG9yYS5weSUyMCU1QyUwQSUyMCUyMC0tcHJldHJhaW5lZF9tb2RlbF9uYW1lX29yX3BhdGglM0QlMjRNT0RFTF9OQU1FJTIwJTVDJTBBJTIwJTIwLS1kYXRhc2V0X25hbWUlM0QlMjREQVRBU0VUX05BTUUlMjAlNUMlMEElMjAlMjAtLWRhdGFsb2FkZXJfbnVtX3dvcmtlcnMlM0Q4JTIwJTVDJTBBJTIwJTIwLS1yZXNvbHV0aW9uJTNENTEyJTIwLS1jZW50ZXJfY3JvcCUyMC0tcmFuZG9tX2ZsaXAlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxJTIwJTVDJTBBJTIwJTIwLS1ncmFkaWVudF9hY2N1bXVsYXRpb25fc3RlcHMlM0Q0JTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0QxNTAwMCUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDFlLTA0JTIwJTVDJTBBJTIwJTIwLS1tYXhfZ3JhZF9ub3JtJTNEMSUyMCU1QyUwQSUyMCUyMC0tbHJfc2NoZWR1bGVyJTNEJTIyY29zaW5lJTIyJTIwLS1scl93YXJtdXBfc3RlcHMlM0QwJTIwJTVDJTBBJTIwJTIwLS1vdXRwdXRfZGlyJTNEJTI0JTdCT1VUUFVUX0RJUiU3RCUyMCU1QyUwQSUyMCUyMC0tcHVzaF90b19odWIlMjAlNUMlMEElMjAlMjAtLWh1Yl9tb2RlbF9pZCUzRCUyNCU3QkhVQl9NT0RFTF9JRCU3RCUyMCU1QyUwQSUyMCUyMC0tcmVwb3J0X3RvJTNEd2FuZGIlMjAlNUMlMEElMjAlMjAtLWNoZWNrcG9pbnRpbmdfc3RlcHMlM0Q1MDAlMjAlNUMlMEElMjAlMjAtLXZhbGlkYXRpb25fcHJvbXB0JTNEJTIyQSUyMHBva2Vtb24lMjB3aXRoJTIwYmx1ZSUyMGV5ZXMuJTIyJTIwJTVDJTBBJTIwJTIwLS1zZWVkJTNEMTMzNw==",highlighted:`accelerate launch --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span>  train_text_to_image_lora.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span> \\
  --dataset_name=<span class="hljs-variable">$DATASET_NAME</span> \\
  --dataloader_num_workers=8 \\
  --resolution=512 --center_crop --random_flip \\
  --train_batch_size=1 \\
  --gradient_accumulation_steps=4 \\
  --max_train_steps=15000 \\
  --learning_rate=1e-04 \\
  --max_grad_norm=1 \\
  --lr_scheduler=<span class="hljs-string">&quot;cosine&quot;</span> --lr_warmup_steps=0 \\
  --output_dir=<span class="hljs-variable">\${OUTPUT_DIR}</span> \\
  --push_to_hub \\
  --hub_model_id=<span class="hljs-variable">\${HUB_MODEL_ID}</span> \\
  --report_to=wandb \\
  --checkpointing_steps=500 \\
  --validation_prompt=<span class="hljs-string">&quot;A pokemon with blue eyes.&quot;</span> \\
  --seed=1337`}}),gt=new Ue({}),_t=new B({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUlMkMlMjBEUE1Tb2x2ZXJNdWx0aXN0ZXBTY2hlZHVsZXIlMEElMEFtb2RlbF9iYXNlJTIwJTNEJTIwJTIycnVud2F5bWwlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMEElMEFwaXBlJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2Jhc2UlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYpJTBBcGlwZS5zY2hlZHVsZXIlMjAlM0QlMjBEUE1Tb2x2ZXJNdWx0aXN0ZXBTY2hlZHVsZXIuZnJvbV9jb25maWcocGlwZS5zY2hlZHVsZXIuY29uZmlnKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline, DPMSolverMultistepScheduler

<span class="hljs-meta">&gt;&gt;&gt; </span>model_base = <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = StableDiffusionPipeline.from_pretrained(model_base, torch_dtype=torch.float16)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)`}}),Ze=new at({props:{$$slots:{default:[lp]},$$scope:{ctx:Z}}}),yt=new B({props:{code:"cGlwZS51bmV0LmxvYWRfYXR0bl9wcm9jcyhsb3JhX21vZGVsX3BhdGgpJTBBcGlwZS50byglMjJjdWRhJTIyKSUwQSUwQWltYWdlJTIwJTNEJTIwcGlwZSglMEElMjAlMjAlMjAlMjAlMjJBJTIwcG9rZW1vbiUyMHdpdGglMjBibHVlJTIwZXllcy4lMjIlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEMjUlMkMlMjBndWlkYW5jZV9zY2FsZSUzRDcuNSUyQyUyMGNyb3NzX2F0dGVudGlvbl9rd2FyZ3MlM0QlN0IlMjJzY2FsZSUyMiUzQSUyMDAuNSU3RCUwQSkuaW1hZ2VzJTVCMCU1RCUwQSUwQWltYWdlJTIwJTNEJTIwcGlwZSglMjJBJTIwcG9rZW1vbiUyMHdpdGglMjBibHVlJTIwZXllcy4lMjIlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEMjUlMkMlMjBndWlkYW5jZV9zY2FsZSUzRDcuNSkuaW1hZ2VzJTVCMCU1RCUwQWltYWdlLnNhdmUoJTIyYmx1ZV9wb2tlbW9uLnBuZyUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>pipe.unet.load_attn_procs(lora_model_path)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)
<span class="hljs-comment"># use half the weights from the LoRA finetuned model and half the weights from the base model</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipe(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;A pokemon with blue eyes.&quot;</span>, num_inference_steps=<span class="hljs-number">25</span>, guidance_scale=<span class="hljs-number">7.5</span>, cross_attention_kwargs={<span class="hljs-string">&quot;scale&quot;</span>: <span class="hljs-number">0.5</span>}
<span class="hljs-meta">... </span>).images[<span class="hljs-number">0</span>]
<span class="hljs-comment"># use the weights from the fully finetuned LoRA model</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipe(<span class="hljs-string">&quot;A pokemon with blue eyes.&quot;</span>, num_inference_steps=<span class="hljs-number">25</span>, guidance_scale=<span class="hljs-number">7.5</span>).images[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>image.save(<span class="hljs-string">&quot;blue_pokemon.png&quot;</span>)`}}),Ne=new at({props:{$$slots:{default:[sp]},$$scope:{ctx:Z}}}),bt=new Ue({}),We=new at({props:{$$slots:{default:[rp]},$$scope:{ctx:Z}}}),Tt=new Ue({}),$t=new B({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTBBZXhwb3J0JTIwSU5TVEFOQ0VfRElSJTNEJTIycGF0aC10by1pbnN0YW5jZS1pbWFnZXMlMjIlMEFleHBvcnQlMjBPVVRQVVRfRElSJTNEJTIycGF0aC10by1zYXZlLW1vZGVsJTIy",highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>
<span class="hljs-built_in">export</span> INSTANCE_DIR=<span class="hljs-string">&quot;path-to-instance-images&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;path-to-save-model&quot;</span>`}}),Rt=new B({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2RyZWFtYm9vdGhfbG9yYS5weSUyMCU1QyUwQSUyMCUyMC0tcHJldHJhaW5lZF9tb2RlbF9uYW1lX29yX3BhdGglM0QlMjRNT0RFTF9OQU1FJTIwJTIwJTVDJTBBJTIwJTIwLS1pbnN0YW5jZV9kYXRhX2RpciUzRCUyNElOU1RBTkNFX0RJUiUyMCU1QyUwQSUyMCUyMC0tb3V0cHV0X2RpciUzRCUyNE9VVFBVVF9ESVIlMjAlNUMlMEElMjAlMjAtLWluc3RhbmNlX3Byb21wdCUzRCUyMmElMjBwaG90byUyMG9mJTIwc2tzJTIwZG9nJTIyJTIwJTVDJTBBJTIwJTIwLS1yZXNvbHV0aW9uJTNENTEyJTIwJTVDJTBBJTIwJTIwLS10cmFpbl9iYXRjaF9zaXplJTNEMSUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNEMSUyMCU1QyUwQSUyMCUyMC0tY2hlY2twb2ludGluZ19zdGVwcyUzRDEwMCUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDFlLTQlMjAlNUMlMEElMjAlMjAtLXJlcG9ydF90byUzRCUyMndhbmRiJTIyJTIwJTVDJTBBJTIwJTIwLS1scl9zY2hlZHVsZXIlM0QlMjJjb25zdGFudCUyMiUyMCU1QyUwQSUyMCUyMC0tbHJfd2FybXVwX3N0ZXBzJTNEMCUyMCU1QyUwQSUyMCUyMC0tbWF4X3RyYWluX3N0ZXBzJTNENTAwJTIwJTVDJTBBJTIwJTIwLS12YWxpZGF0aW9uX3Byb21wdCUzRCUyMkElMjBwaG90byUyMG9mJTIwc2tzJTIwZG9nJTIwaW4lMjBhJTIwYnVja2V0JTIyJTIwJTVDJTBBJTIwJTIwLS12YWxpZGF0aW9uX2Vwb2NocyUzRDUwJTIwJTVDJTBBJTIwJTIwLS1zZWVkJTNEJTIyMCUyMiUyMCU1QyUwQSUyMCUyMC0tcHVzaF90b19odWI=",highlighted:`accelerate launch train_dreambooth_lora.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span>  \\
  --instance_data_dir=<span class="hljs-variable">$INSTANCE_DIR</span> \\
  --output_dir=<span class="hljs-variable">$OUTPUT_DIR</span> \\
  --instance_prompt=<span class="hljs-string">&quot;a photo of sks dog&quot;</span> \\
  --resolution=512 \\
  --train_batch_size=1 \\
  --gradient_accumulation_steps=1 \\
  --checkpointing_steps=100 \\
  --learning_rate=1e-4 \\
  --report_to=<span class="hljs-string">&quot;wandb&quot;</span> \\
  --lr_scheduler=<span class="hljs-string">&quot;constant&quot;</span> \\
  --lr_warmup_steps=0 \\
  --max_train_steps=500 \\
  --validation_prompt=<span class="hljs-string">&quot;A photo of sks dog in a bucket&quot;</span> \\
  --validation_epochs=50 \\
  --seed=<span class="hljs-string">&quot;0&quot;</span> \\
  --push_to_hub`}}),kt=new Ue({}),It=new B({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUlMEElMEFtb2RlbF9iYXNlJTIwJTNEJTIwJTIycnVud2F5bWwlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMEElMEFwaXBlJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2Jhc2UlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>model_base = <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = StableDiffusionPipeline.from_pretrained(model_base, torch_dtype=torch.float16)`}}),De=new at({props:{$$slots:{default:[np]},$$scope:{ctx:Z}}}),Zt=new B({props:{code:"cGlwZS51bmV0LmxvYWRfYXR0bl9wcm9jcyhsb3JhX21vZGVsX3BhdGgpJTBBcGlwZS50byglMjJjdWRhJTIyKSUwQSUwQWltYWdlJTIwJTNEJTIwcGlwZSglMEElMjAlMjAlMjAlMjAlMjJBJTIwcGljdHVyZSUyMG9mJTIwYSUyMHNrcyUyMGRvZyUyMGluJTIwYSUyMGJ1Y2tldC4lMjIlMkMlMEElMjAlMjAlMjAlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEMjUlMkMlMEElMjAlMjAlMjAlMjBndWlkYW5jZV9zY2FsZSUzRDcuNSUyQyUwQSUyMCUyMCUyMCUyMGNyb3NzX2F0dGVudGlvbl9rd2FyZ3MlM0QlN0IlMjJzY2FsZSUyMiUzQSUyMDAuNSU3RCUyQyUwQSkuaW1hZ2VzJTVCMCU1RCUwQSUwQWltYWdlJTIwJTNEJTIwcGlwZSglMjJBJTIwcGljdHVyZSUyMG9mJTIwYSUyMHNrcyUyMGRvZyUyMGluJTIwYSUyMGJ1Y2tldC4lMjIlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEMjUlMkMlMjBndWlkYW5jZV9zY2FsZSUzRDcuNSkuaW1hZ2VzJTVCMCU1RCUwQWltYWdlLnNhdmUoJTIyYnVja2V0LWRvZy5wbmclMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>pipe.unet.load_attn_procs(lora_model_path)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)
<span class="hljs-comment"># use half the weights from the LoRA finetuned model and half the weights from the base model</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipe(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;A picture of a sks dog in a bucket.&quot;</span>,
<span class="hljs-meta">... </span>    num_inference_steps=<span class="hljs-number">25</span>,
<span class="hljs-meta">... </span>    guidance_scale=<span class="hljs-number">7.5</span>,
<span class="hljs-meta">... </span>    cross_attention_kwargs={<span class="hljs-string">&quot;scale&quot;</span>: <span class="hljs-number">0.5</span>},
<span class="hljs-meta">... </span>).images[<span class="hljs-number">0</span>]
<span class="hljs-comment"># use the weights from the fully finetuned LoRA model</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipe(<span class="hljs-string">&quot;A picture of a sks dog in a bucket.&quot;</span>, num_inference_steps=<span class="hljs-number">25</span>, guidance_scale=<span class="hljs-number">7.5</span>).images[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>image.save(<span class="hljs-string">&quot;bucket-dog.png&quot;</span>)`}}),Nt=new B({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1Yi5yZXBvY2FyZCUyMGltcG9ydCUyMFJlcG9DYXJkJTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBaW1wb3J0JTIwdG9yY2glMEElMEFsb3JhX21vZGVsX2lkJTIwJTNEJTIwJTIyc2F5YWtwYXVsJTJGZHJlYW1ib290aC10ZXh0LWVuY29kZXItdGVzdCUyMiUwQWNhcmQlMjAlM0QlMjBSZXBvQ2FyZC5sb2FkKGxvcmFfbW9kZWxfaWQpJTBBYmFzZV9tb2RlbF9pZCUyMCUzRCUyMGNhcmQuZGF0YS50b19kaWN0KCklNUIlMjJiYXNlX21vZGVsJTIyJTVEJTBBJTBBcGlwZSUyMCUzRCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChiYXNlX21vZGVsX2lkJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2KSUwQXBpcGUlMjAlM0QlMjBwaXBlLnRvKCUyMmN1ZGElMjIpJTBBcGlwZS5sb2FkX2xvcmFfd2VpZ2h0cyhsb3JhX21vZGVsX2lkKSUwQWltYWdlJTIwJTNEJTIwcGlwZSglMjJBJTIwcGljdHVyZSUyMG9mJTIwYSUyMHNrcyUyMGRvZyUyMGluJTIwYSUyMGJ1Y2tldCUyMiUyQyUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyNSkuaW1hZ2VzJTVCMCU1RA==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub.repocard <span class="hljs-keyword">import</span> RepoCard
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline
<span class="hljs-keyword">import</span> torch

lora_model_id = <span class="hljs-string">&quot;sayakpaul/dreambooth-text-encoder-test&quot;</span>
card = RepoCard.load(lora_model_id)
base_model_id = card.data.to_dict()[<span class="hljs-string">&quot;base_model&quot;</span>]

pipe = StableDiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16)
pipe = pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipe.load_lora_weights(lora_model_id)
image = pipe(<span class="hljs-string">&quot;A picture of a sks dog in a bucket&quot;</span>, num_inference_steps=<span class="hljs-number">25</span>).images[<span class="hljs-number">0</span>]`}}),Ve=new at({props:{$$slots:{default:[ip]},$$scope:{ctx:Z}}}),St=new B({props:{code:"cGlwZS5sb2FkX2xvcmFfd2VpZ2h0cyhsb3JhX21vZGVsX3BhdGgp",highlighted:"pipe.load_lora_weights(lora_model_path)"}}),Xt=new Ue({}),Dt=new Ue({}),Pt=new B({props:{code:"d2dldCUyMGh0dHBzJTNBJTJGJTJGY2l2aXRhaS5jb20lMkZhcGklMkZkb3dubG9hZCUyRm1vZGVscyUyRjE1NjAzJTIwLU8lMjBsaWdodF9hbmRfc2hhZG93LnNhZmV0ZW5zb3Jz",highlighted:"wget https://civitai.com/api/download/models/15603 -O light_and_shadow.safetensors"}}),zt=new B({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUlMkMlMjBEUE1Tb2x2ZXJNdWx0aXN0ZXBTY2hlZHVsZXIlMEElMEFwaXBlbGluZSUyMCUzRCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJnc2RmJTJGQ291bnRlcmZlaXQtVjIuNSUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUyQyUyMHNhZmV0eV9jaGVja2VyJTNETm9uZSUwQSkudG8oJTIyY3VkYSUyMiklMEFwaXBlbGluZS5zY2hlZHVsZXIlMjAlM0QlMjBEUE1Tb2x2ZXJNdWx0aXN0ZXBTY2hlZHVsZXIuZnJvbV9jb25maWcoJTBBJTIwJTIwJTIwJTIwcGlwZWxpbmUuc2NoZWR1bGVyLmNvbmZpZyUyQyUyMHVzZV9rYXJyYXNfc2lnbWFzJTNEVHJ1ZSUwQSk=",highlighted:`<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline, DPMSolverMultistepScheduler

pipeline = StableDiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;gsdf/Counterfeit-V2.5&quot;</span>, torch_dtype=torch.float16, safety_checker=<span class="hljs-literal">None</span>
).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipeline.scheduler = DPMSolverMultistepScheduler.from_config(
    pipeline.scheduler.config, use_karras_sigmas=<span class="hljs-literal">True</span>
)`}}),Qt=new B({props:{code:"cGlwZWxpbmUubG9hZF9sb3JhX3dlaWdodHMoJTIyLiUyMiUyQyUyMHdlaWdodF9uYW1lJTNEJTIybGlnaHRfYW5kX3NoYWRvdy5zYWZldGVuc29ycyUyMik=",highlighted:'pipeline.load_lora_weights(<span class="hljs-string">&quot;.&quot;</span>, weight_name=<span class="hljs-string">&quot;light_and_shadow.safetensors&quot;</span>)'}}),He=new at({props:{warning:!0,$$slots:{default:[hp]},$$scope:{ctx:Z}}}),Ht=new B({props:{code:"cHJvbXB0JTIwJTNEJTIwJTIybWFzdGVycGllY2UlMkMlMjBiZXN0JTIwcXVhbGl0eSUyQyUyMDFnaXJsJTJDJTIwYXQlMjBkdXNrJTIyJTBBbmVnYXRpdmVfcHJvbXB0JTIwJTNEJTIwKCUyMihsb3clMjBxdWFsaXR5JTJDJTIwd29yc3QlMjBxdWFsaXR5JTNBMS40KSUyQyUyMChiYWQlMjBhbmF0b215KSUyQyUyMChpbmFjY3VyYXRlJTIwbGltYiUzQTEuMiklMkMlMjAlMjIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJiYWQlMjBjb21wb3NpdGlvbiUyQyUyMGluYWNjdXJhdGUlMjBleWVzJTJDJTIwZXh0cmElMjBkaWdpdCUyQyUyMGZld2VyJTIwZGlnaXRzJTJDJTIwKGV4dHJhJTIwYXJtcyUzQTEuMiklMkMlMjBsYXJnZSUyMGJyZWFzdHMlMjIpJTBBJTBBaW1hZ2VzJTIwJTNEJTIwcGlwZWxpbmUocHJvbXB0JTNEcHJvbXB0JTJDJTIwJTBBJTIwJTIwJTIwJTIwbmVnYXRpdmVfcHJvbXB0JTNEbmVnYXRpdmVfcHJvbXB0JTJDJTIwJTBBJTIwJTIwJTIwJTIwd2lkdGglM0Q1MTIlMkMlMjAlMEElMjAlMjAlMjAlMjBoZWlnaHQlM0Q3NjglMkMlMjAlMEElMjAlMjAlMjAlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEMTUlMkMlMjAlMEElMjAlMjAlMjAlMjBudW1faW1hZ2VzX3Blcl9wcm9tcHQlM0Q0JTJDJTBBJTIwJTIwJTIwJTIwZ2VuZXJhdG9yJTNEdG9yY2gubWFudWFsX3NlZWQoMCklMEEpLmltYWdlcw==",highlighted:`prompt = <span class="hljs-string">&quot;masterpiece, best quality, 1girl, at dusk&quot;</span>
negative_prompt = (<span class="hljs-string">&quot;(low quality, worst quality:1.4), (bad anatomy), (inaccurate limb:1.2), &quot;</span>
                   <span class="hljs-string">&quot;bad composition, inaccurate eyes, extra digit, fewer digits, (extra arms:1.2), large breasts&quot;</span>)

images = pipeline(prompt=prompt, 
    negative_prompt=negative_prompt, 
    width=<span class="hljs-number">512</span>, 
    height=<span class="hljs-number">768</span>, 
    num_inference_steps=<span class="hljs-number">15</span>, 
    num_images_per_prompt=<span class="hljs-number">4</span>,
    generator=torch.manual_seed(<span class="hljs-number">0</span>)
).images`}}),qt=new B({props:{code:"bG9yYV9tb2RlbF9pZCUyMCUzRCUyMCUyMnNheWFrcGF1bCUyRmNpdml0YWktbGlnaHQtc2hhZG93LWxvcmElMjIlMEFsb3JhX2ZpbGVuYW1lJTIwJTNEJTIwJTIybGlnaHRfYW5kX3NoYWRvdy5zYWZldGVuc29ycyUyMiUwQXBpcGVsaW5lLmxvYWRfbG9yYV93ZWlnaHRzKGxvcmFfbW9kZWxfaWQlMkMlMjB3ZWlnaHRfbmFtZSUzRGxvcmFfZmlsZW5hbWUp",highlighted:`lora_model_id = <span class="hljs-string">&quot;sayakpaul/civitai-light-shadow-lora&quot;</span>
lora_filename = <span class="hljs-string">&quot;light_and_shadow.safetensors&quot;</span>
pipeline.load_lora_weights(lora_model_id, weight_name=lora_filename)`}}),{c(){p=s("meta"),M=d(),c=s("h1"),w=s("a"),j=s("span"),v(m.$$.fragment),y=d(),R=s("span"),A=o("Low-Rank Adaptation of Large Language Models (LoRA)"),g=d(),v(I.$$.fragment),_=d(),k=s("p"),N=s("a"),G=o("Low-Rank Adaptation of Large Language Models (LoRA)"),Q=o(" is a training method that accelerates the training of large models while consuming less memory. It adds pairs of rank-decomposition weight matrices (called "),X=s("strong"),S=o("update matrices"),H=o(") to existing weights, and "),D=s("strong"),L=o("only"),b=o(" trains those newly added weights. This has a couple of advantages:"),O=d(),W=s("ul"),V=s("li"),ce=o("Previous pretrained weights are kept frozen so the model is not as prone to "),Y=s("a"),me=o("catastrophic forgetting"),Es=o("."),Us=d(),Da=s("li"),$s=o("Rank-decomposition matrices have significantly fewer parameters than the original model, which means that trained LoRA weights are easily portable."),js=d(),we=s("li"),As=o("LoRA matrices are generally added to the attention layers of the original model. \u{1F9E8} Diffusers provides the "),ea=s("a"),Rs=o("load_attn_procs()"),ks=o(" method to load the LoRA weights into a model\u2019s attention layers. You can control the extent to which the model is adapted toward new training images via a "),Va=s("code"),Is=o("scale"),Zs=o(" parameter."),Ns=d(),Ya=s("li"),Gs=o("The greater memory-efficiency allows you to run fine-tuning on consumer GPUs like the Tesla T4, RTX 3080 or even the RTX 2080 Ti! GPUs like the T4 are free and readily accessible in Kaggle or Google Colab notebooks."),Po=d(),v($e.$$.fragment),zo=d(),x=s("p"),ot=s("a"),Ws=o("cloneofsimo"),Bs=o(" was the first to try out LoRA training for Stable Diffusion in the popular "),lt=s("a"),Ss=o("lora"),Ls=o(" GitHub repository. \u{1F9E8} Diffusers now supports finetuning with LoRA for "),st=s("a"),Cs=o("text-to-image generation"),Xs=o(" and "),rt=s("a"),Ds=o("DreamBooth"),Vs=o(". This guide will show you how to do both."),Qo=d(),je=s("p"),Ys=o("If you\u2019d like to store or share your model with the community, login to your Hugging Face account (create "),ta=s("a"),xs=o("one"),Fs=o(" if you don\u2019t have one already):"),Ho=d(),v(nt.$$.fragment),qo=d(),ge=s("h2"),Ae=s("a"),xa=s("span"),v(it.$$.fragment),Ps=d(),Fa=s("span"),zs=o("Text-to-image"),Oo=d(),aa=s("p"),Qs=o("Finetuning a model like Stable Diffusion, which has billions of parameters, can be slow and difficult. With LoRA, it is much easier and faster to finetune a diffusion model. It can run on hardware with as little as 11GB of GPU RAM without resorting to tricks such as 8-bit optimizers."),Ko=d(),_e=s("h3"),Re=s("a"),Pa=s("span"),v(ht.$$.fragment),Hs=d(),za=s("span"),qs=o("Training"),el=d(),K=s("p"),Os=o("Let\u2019s finetune "),ft=s("a"),Qa=s("code"),Ks=o("stable-diffusion-v1-5"),er=o(" on the "),pt=s("a"),tr=o("Pok\xE9mon BLIP captions"),ar=o(" dataset to generate your own Pok\xE9mon."),tl=d(),C=s("p"),or=o("Specify the "),Ha=s("code"),lr=o("MODEL_NAME"),sr=o(" environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),dt=s("a"),qa=s("code"),rr=o("pretrained_model_name_or_path"),nr=o(" argument. You\u2019ll also need to set the "),Oa=s("code"),ir=o("DATASET_NAME"),hr=o(" environment variable to the name of the dataset you want to train on. To use your own dataset, take a look at the "),oa=s("a"),fr=o("Create a dataset for training"),pr=o(" guide."),al=d(),ee=s("p"),dr=o("The "),Ka=s("code"),ur=o("OUTPUT_DIR"),cr=o(" and "),eo=s("code"),mr=o("HUB_MODEL_ID"),wr=o(" variables are optional and specify where to save the model to on the Hub:"),ol=d(),v(ut.$$.fragment),ll=d(),la=s("p"),gr=o("There are some flags to be aware of before you start training:"),sl=d(),te=s("ul"),sa=s("li"),to=s("code"),_r=o("--push_to_hub"),yr=o(" stores the trained LoRA embeddings on the Hub."),br=d(),ke=s("li"),ao=s("code"),Mr=o("--report_to=wandb"),vr=o(" reports and logs the training results to your Weights & Biases dashboard (as an example, take a look at this "),ct=s("a"),Tr=o("report"),Jr=o(")."),Er=d(),ra=s("li"),oo=s("code"),Ur=o("--learning_rate=1e-04"),$r=o(", you can afford to use a higher learning rate than you normally would with LoRA."),rl=d(),ae=s("p"),jr=o("Now you\u2019re ready to launch the training (you can find the full training script "),mt=s("a"),Ar=o("here"),Rr=o("). Training takes about 5 hours on a 2080 Ti GPU with 11GB of RAM, and it\u2019ll create and save model checkpoints and the "),lo=s("code"),kr=o("pytorch_lora_weights"),Ir=o(" in your repository."),nl=d(),v(wt.$$.fragment),il=d(),ye=s("h3"),Ie=s("a"),so=s("span"),v(gt.$$.fragment),Zr=d(),ro=s("span"),Nr=o("Inference"),hl=d(),oe=s("p"),Gr=o("Now you can use the model for inference by loading the base model in the "),na=s("a"),Wr=o("StableDiffusionPipeline"),Br=o(" and then the "),ia=s("a"),Sr=o("DPMSolverMultistepScheduler"),Lr=o(":"),fl=d(),v(_t.$$.fragment),pl=d(),le=s("p"),Cr=o("Load the LoRA weights from your finetuned model "),no=s("em"),Xr=o("on top of the base model weights"),Dr=o(", and then move the pipeline to a GPU for faster inference. When you merge the LoRA weights with the frozen pretrained model weights, you can optionally adjust how much of the weights to merge with the "),io=s("code"),Vr=o("scale"),Yr=o(" parameter:"),dl=d(),v(Ze.$$.fragment),ul=d(),v(yt.$$.fragment),cl=d(),v(Ne.$$.fragment),ml=d(),be=s("h2"),Ge=s("a"),ho=s("span"),v(bt.$$.fragment),xr=d(),fo=s("span"),Fr=o("DreamBooth"),wl=d(),Mt=s("p"),vt=s("a"),Pr=o("DreamBooth"),zr=o(" is a finetuning technique for personalizing a text-to-image model like Stable Diffusion to generate photorealistic images of a subject in different contexts, given a few images of the subject. However, DreamBooth is very sensitive to hyperparameters and it is easy to overfit. Some important hyperparameters to consider include those that affect the training time (learning rate, number of training steps), and inference time (number of steps, scheduler type)."),gl=d(),v(We.$$.fragment),_l=d(),Me=s("h3"),Be=s("a"),po=s("span"),v(Tt.$$.fragment),Qr=d(),uo=s("span"),Hr=o("Training"),yl=d(),F=s("p"),qr=o("Let\u2019s finetune "),Jt=s("a"),co=s("code"),Or=o("stable-diffusion-v1-5"),Kr=o(" with DreamBooth and LoRA with some \u{1F436} "),Et=s("a"),en=o("dog images"),tn=o(". Download and save these images to a directory. To use your own dataset, take a look at the "),ha=s("a"),an=o("Create a dataset for training"),on=o(" guide."),bl=d(),P=s("p"),ln=o("To start, specify the "),mo=s("code"),sn=o("MODEL_NAME"),rn=o(" environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),Ut=s("a"),wo=s("code"),nn=o("pretrained_model_name_or_path"),hn=o(" argument. You\u2019ll also need to set "),go=s("code"),fn=o("INSTANCE_DIR"),pn=o(" to the path of the directory containing the images."),Ml=d(),Se=s("p"),dn=o("The "),_o=s("code"),un=o("OUTPUT_DIR"),cn=o(" variables is optional and specifies where to save the model to on the Hub:"),vl=d(),v($t.$$.fragment),Tl=d(),fa=s("p"),mn=o("There are some flags to be aware of before you start training:"),Jl=d(),se=s("ul"),pa=s("li"),yo=s("code"),wn=o("--push_to_hub"),gn=o(" stores the trained LoRA embeddings on the Hub."),_n=d(),Le=s("li"),bo=s("code"),yn=o("--report_to=wandb"),bn=o(" reports and logs the training results to your Weights & Biases dashboard (as an example, take a look at this "),jt=s("a"),Mn=o("report"),vn=o(")."),Tn=d(),da=s("li"),Mo=s("code"),Jn=o("--learning_rate=1e-04"),En=o(", you can afford to use a higher learning rate than you normally would with LoRA."),El=d(),re=s("p"),Un=o("Now you\u2019re ready to launch the training (you can find the full training script "),At=s("a"),$n=o("here"),jn=o("). The script creates and saves model checkpoints and the "),vo=s("code"),An=o("pytorch_lora_weights.bin"),Rn=o(" file in your repository."),Ul=d(),ne=s("p"),kn=o(`It\u2019s also possible to additionally fine-tune the text encoder with LoRA. This, in most cases, leads
to better results with a slight increase in the compute. To allow fine-tuning the text encoder with LoRA,
specify the `),To=s("code"),In=o("--train_text_encoder"),Zn=o(" while launching the "),Jo=s("code"),Nn=o("train_dreambooth_lora.py"),Gn=o(" script."),$l=d(),v(Rt.$$.fragment),jl=d(),ve=s("h3"),Ce=s("a"),Eo=s("span"),v(kt.$$.fragment),Wn=d(),Uo=s("span"),Bn=o("Inference"),Al=d(),Xe=s("p"),Sn=o("Now you can use the model for inference by loading the base model in the "),ua=s("a"),Ln=o("StableDiffusionPipeline"),Cn=o(":"),Rl=d(),v(It.$$.fragment),kl=d(),ie=s("p"),Xn=o("Load the LoRA weights from your finetuned DreamBooth model "),$o=s("em"),Dn=o("on top of the base model weights"),Vn=o(", and then move the pipeline to a GPU for faster inference. When you merge the LoRA weights with the frozen pretrained model weights, you can optionally adjust how much of the weights to merge with the "),jo=s("code"),Yn=o("scale"),xn=o(" parameter:"),Il=d(),v(De.$$.fragment),Zl=d(),v(Zt.$$.fragment),Nl=d(),he=s("p"),Fn=o("If you used "),Ao=s("code"),Pn=o("--train_text_encoder"),zn=o(" during training, then use "),Ro=s("code"),Qn=o("pipe.load_lora_weights()"),Hn=o(` to load the LoRA
weights. For example:`),Gl=d(),v(Nt.$$.fragment),Wl=d(),v(Ve.$$.fragment),Bl=d(),z=s("p"),qn=o("Note that the use of "),ca=s("a"),On=o("load_lora_weights()"),Kn=o(" is preferred to "),ma=s("a"),ei=o("load_attn_procs()"),ti=o(` for loading LoRA parameters. This is because
`),wa=s("a"),ai=o("load_lora_weights()"),oi=o(" can handle the following situations:"),Sl=d(),Ye=s("ul"),Gt=s("li"),Wt=s("p"),li=o("LoRA parameters that don\u2019t have separate identifiers for the UNet and the text encoder (such as "),Bt=s("a"),ko=s("code"),si=o('"patrickvonplaten/lora_dreambooth_dog_example"'),ri=o("). So, you can just do:"),ni=d(),v(St.$$.fragment),ii=d(),Io=s("li"),Lt=s("p"),hi=o("LoRA parameters that have separate identifiers for the UNet and the text encoder such as: "),Ct=s("a"),Zo=s("code"),fi=o('"sayakpaul/dreambooth"'),pi=o("."),Ll=d(),q=s("p"),No=s("strong"),di=o("Note"),ui=o(" that it is possible to provide a local directory path to "),ga=s("a"),ci=o("load_lora_weights()"),mi=o(" as well as "),_a=s("a"),wi=o("load_attn_procs()"),gi=o(`. To know about the supported inputs,
refer to the respective docstrings.`),Cl=d(),Te=s("h2"),xe=s("a"),Go=s("span"),v(Xt.$$.fragment),_i=d(),Wo=s("span"),yi=o("Unloading LoRA parameters"),Xl=d(),Fe=s("p"),bi=o("You can call "),ya=s("a"),Mi=o("unload_lora_weights()"),vi=o(" on a pipeline to unload the LoRA parameters."),Dl=d(),Je=s("h2"),Pe=s("a"),Bo=s("span"),v(Dt.$$.fragment),Ti=d(),So=s("span"),Ji=o("Supporting A1111 themed LoRA checkpoints from Diffusers"),Vl=d(),fe=s("p"),Ei=o("This support was made possible because of our amazing contributors: "),Vt=s("a"),Ui=o("@takuma104"),$i=o(" and "),Yt=s("a"),ji=o("@isidentical"),Ai=o("."),Yl=d(),pe=s("p"),Ri=o(`To provide seamless interoperability with A1111 to our users, we support loading A1111 formatted
LoRA checkpoints using `),ba=s("a"),ki=o("load_lora_weights()"),Ii=o(` in a limited capacity.
In this section, we explain how to load an A1111 formatted LoRA checkpoint from `),xt=s("a"),Zi=o("CivitAI"),Ni=o(`
in Diffusers and perform inference with it.`),xl=d(),ze=s("p"),Gi=o(`First, download a checkpoint. We\u2019ll use
`),Ft=s("a"),Wi=o("this one"),Bi=o(" for demonstration purposes."),Fl=d(),v(Pt.$$.fragment),Pl=d(),Qe=s("p"),Si=o("Next, we initialize a "),Ma=s("a"),Li=o("~DiffusionPipeline"),Ci=o(":"),zl=d(),v(zt.$$.fragment),Ql=d(),va=s("p"),Xi=o("We then load the checkpoint downloaded from CivitAI:"),Hl=d(),v(Qt.$$.fragment),ql=d(),v(He.$$.fragment),Ol=d(),Ta=s("p"),Di=o("And then it\u2019s time for running inference:"),Kl=d(),v(Ht.$$.fragment),es=d(),Ja=s("p"),Vi=o("Below is a comparison between the LoRA and the non-LoRA results:"),ts=d(),Ea=s("p"),Ua=s("img"),as=d(),qe=s("p"),Yi=o(`You have a similar checkpoint stored on the Hugging Face Hub, you can load it
directly with `),$a=s("a"),xi=o("load_lora_weights()"),Fi=o(" like so:"),os=d(),v(qt.$$.fragment),this.h()},l(e){const i=Of('[data-svelte="svelte-1phssyn"]',document.head);p=r(i,"META",{name:!0,content:!0}),i.forEach(a),M=u(e),c=r(e,"H1",{class:!0});var Ot=n(c);w=r(Ot,"A",{id:!0,class:!0,href:!0});var Lo=n(w);j=r(Lo,"SPAN",{});var Co=n(j);T(m.$$.fragment,Co),Co.forEach(a),Lo.forEach(a),y=u(Ot),R=r(Ot,"SPAN",{});var Xo=n(R);A=l(Xo,"Low-Rank Adaptation of Large Language Models (LoRA)"),Xo.forEach(a),Ot.forEach(a),g=u(e),T(I.$$.fragment,e),_=u(e),k=r(e,"P",{});var de=n(k);N=r(de,"A",{href:!0,rel:!0});var Do=n(N);G=l(Do,"Low-Rank Adaptation of Large Language Models (LoRA)"),Do.forEach(a),Q=l(de," is a training method that accelerates the training of large models while consuming less memory. It adds pairs of rank-decomposition weight matrices (called "),X=r(de,"STRONG",{});var Vo=n(X);S=l(Vo,"update matrices"),Vo.forEach(a),H=l(de,") to existing weights, and "),D=r(de,"STRONG",{});var Yo=n(D);L=l(Yo,"only"),Yo.forEach(a),b=l(de," trains those newly added weights. This has a couple of advantages:"),de.forEach(a),O=u(e),W=r(e,"UL",{});var Oe=n(W);V=r(Oe,"LI",{});var ss=n(V);ce=l(ss,"Previous pretrained weights are kept frozen so the model is not as prone to "),Y=r(ss,"A",{href:!0,rel:!0});var Ki=n(Y);me=l(Ki,"catastrophic forgetting"),Ki.forEach(a),Es=l(ss,"."),ss.forEach(a),Us=u(Oe),Da=r(Oe,"LI",{});var eh=n(Da);$s=l(eh,"Rank-decomposition matrices have significantly fewer parameters than the original model, which means that trained LoRA weights are easily portable."),eh.forEach(a),js=u(Oe),we=r(Oe,"LI",{});var ja=n(we);As=l(ja,"LoRA matrices are generally added to the attention layers of the original model. \u{1F9E8} Diffusers provides the "),ea=r(ja,"A",{href:!0});var th=n(ea);Rs=l(th,"load_attn_procs()"),th.forEach(a),ks=l(ja," method to load the LoRA weights into a model\u2019s attention layers. You can control the extent to which the model is adapted toward new training images via a "),Va=r(ja,"CODE",{});var ah=n(Va);Is=l(ah,"scale"),ah.forEach(a),Zs=l(ja," parameter."),ja.forEach(a),Ns=u(Oe),Ya=r(Oe,"LI",{});var oh=n(Ya);Gs=l(oh,"The greater memory-efficiency allows you to run fine-tuning on consumer GPUs like the Tesla T4, RTX 3080 or even the RTX 2080 Ti! GPUs like the T4 are free and readily accessible in Kaggle or Google Colab notebooks."),oh.forEach(a),Oe.forEach(a),Po=u(e),T($e.$$.fragment,e),zo=u(e),x=r(e,"P",{});var Ee=n(x);ot=r(Ee,"A",{href:!0,rel:!0});var lh=n(ot);Ws=l(lh,"cloneofsimo"),lh.forEach(a),Bs=l(Ee," was the first to try out LoRA training for Stable Diffusion in the popular "),lt=r(Ee,"A",{href:!0,rel:!0});var sh=n(lt);Ss=l(sh,"lora"),sh.forEach(a),Ls=l(Ee," GitHub repository. \u{1F9E8} Diffusers now supports finetuning with LoRA for "),st=r(Ee,"A",{href:!0,rel:!0});var rh=n(st);Cs=l(rh,"text-to-image generation"),rh.forEach(a),Xs=l(Ee," and "),rt=r(Ee,"A",{href:!0,rel:!0});var nh=n(rt);Ds=l(nh,"DreamBooth"),nh.forEach(a),Vs=l(Ee,". This guide will show you how to do both."),Ee.forEach(a),Qo=u(e),je=r(e,"P",{});var rs=n(je);Ys=l(rs,"If you\u2019d like to store or share your model with the community, login to your Hugging Face account (create "),ta=r(rs,"A",{href:!0});var ih=n(ta);xs=l(ih,"one"),ih.forEach(a),Fs=l(rs," if you don\u2019t have one already):"),rs.forEach(a),Ho=u(e),T(nt.$$.fragment,e),qo=u(e),ge=r(e,"H2",{class:!0});var ns=n(ge);Ae=r(ns,"A",{id:!0,class:!0,href:!0});var hh=n(Ae);xa=r(hh,"SPAN",{});var fh=n(xa);T(it.$$.fragment,fh),fh.forEach(a),hh.forEach(a),Ps=u(ns),Fa=r(ns,"SPAN",{});var ph=n(Fa);zs=l(ph,"Text-to-image"),ph.forEach(a),ns.forEach(a),Oo=u(e),aa=r(e,"P",{});var dh=n(aa);Qs=l(dh,"Finetuning a model like Stable Diffusion, which has billions of parameters, can be slow and difficult. With LoRA, it is much easier and faster to finetune a diffusion model. It can run on hardware with as little as 11GB of GPU RAM without resorting to tricks such as 8-bit optimizers."),dh.forEach(a),Ko=u(e),_e=r(e,"H3",{class:!0});var is=n(_e);Re=r(is,"A",{id:!0,class:!0,href:!0});var uh=n(Re);Pa=r(uh,"SPAN",{});var ch=n(Pa);T(ht.$$.fragment,ch),ch.forEach(a),uh.forEach(a),Hs=u(is),za=r(is,"SPAN",{});var mh=n(za);qs=l(mh,"Training"),mh.forEach(a),is.forEach(a),el=u(e),K=r(e,"P",{});var Aa=n(K);Os=l(Aa,"Let\u2019s finetune "),ft=r(Aa,"A",{href:!0,rel:!0});var wh=n(ft);Qa=r(wh,"CODE",{});var gh=n(Qa);Ks=l(gh,"stable-diffusion-v1-5"),gh.forEach(a),wh.forEach(a),er=l(Aa," on the "),pt=r(Aa,"A",{href:!0,rel:!0});var _h=n(pt);tr=l(_h,"Pok\xE9mon BLIP captions"),_h.forEach(a),ar=l(Aa," dataset to generate your own Pok\xE9mon."),Aa.forEach(a),tl=u(e),C=r(e,"P",{});var ue=n(C);or=l(ue,"Specify the "),Ha=r(ue,"CODE",{});var yh=n(Ha);lr=l(yh,"MODEL_NAME"),yh.forEach(a),sr=l(ue," environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),dt=r(ue,"A",{href:!0,rel:!0});var bh=n(dt);qa=r(bh,"CODE",{});var Mh=n(qa);rr=l(Mh,"pretrained_model_name_or_path"),Mh.forEach(a),bh.forEach(a),nr=l(ue," argument. You\u2019ll also need to set the "),Oa=r(ue,"CODE",{});var vh=n(Oa);ir=l(vh,"DATASET_NAME"),vh.forEach(a),hr=l(ue," environment variable to the name of the dataset you want to train on. To use your own dataset, take a look at the "),oa=r(ue,"A",{href:!0});var Th=n(oa);fr=l(Th,"Create a dataset for training"),Th.forEach(a),pr=l(ue," guide."),ue.forEach(a),al=u(e),ee=r(e,"P",{});var Ra=n(ee);dr=l(Ra,"The "),Ka=r(Ra,"CODE",{});var Jh=n(Ka);ur=l(Jh,"OUTPUT_DIR"),Jh.forEach(a),cr=l(Ra," and "),eo=r(Ra,"CODE",{});var Eh=n(eo);mr=l(Eh,"HUB_MODEL_ID"),Eh.forEach(a),wr=l(Ra," variables are optional and specify where to save the model to on the Hub:"),Ra.forEach(a),ol=u(e),T(ut.$$.fragment,e),ll=u(e),la=r(e,"P",{});var Uh=n(la);gr=l(Uh,"There are some flags to be aware of before you start training:"),Uh.forEach(a),sl=u(e),te=r(e,"UL",{});var ka=n(te);sa=r(ka,"LI",{});var Pi=n(sa);to=r(Pi,"CODE",{});var $h=n(to);_r=l($h,"--push_to_hub"),$h.forEach(a),yr=l(Pi," stores the trained LoRA embeddings on the Hub."),Pi.forEach(a),br=u(ka),ke=r(ka,"LI",{});var xo=n(ke);ao=r(xo,"CODE",{});var jh=n(ao);Mr=l(jh,"--report_to=wandb"),jh.forEach(a),vr=l(xo," reports and logs the training results to your Weights & Biases dashboard (as an example, take a look at this "),ct=r(xo,"A",{href:!0,rel:!0});var Ah=n(ct);Tr=l(Ah,"report"),Ah.forEach(a),Jr=l(xo,")."),xo.forEach(a),Er=u(ka),ra=r(ka,"LI",{});var zi=n(ra);oo=r(zi,"CODE",{});var Rh=n(oo);Ur=l(Rh,"--learning_rate=1e-04"),Rh.forEach(a),$r=l(zi,", you can afford to use a higher learning rate than you normally would with LoRA."),zi.forEach(a),ka.forEach(a),rl=u(e),ae=r(e,"P",{});var Ia=n(ae);jr=l(Ia,"Now you\u2019re ready to launch the training (you can find the full training script "),mt=r(Ia,"A",{href:!0,rel:!0});var kh=n(mt);Ar=l(kh,"here"),kh.forEach(a),Rr=l(Ia,"). Training takes about 5 hours on a 2080 Ti GPU with 11GB of RAM, and it\u2019ll create and save model checkpoints and the "),lo=r(Ia,"CODE",{});var Ih=n(lo);kr=l(Ih,"pytorch_lora_weights"),Ih.forEach(a),Ir=l(Ia," in your repository."),Ia.forEach(a),nl=u(e),T(wt.$$.fragment,e),il=u(e),ye=r(e,"H3",{class:!0});var hs=n(ye);Ie=r(hs,"A",{id:!0,class:!0,href:!0});var Zh=n(Ie);so=r(Zh,"SPAN",{});var Nh=n(so);T(gt.$$.fragment,Nh),Nh.forEach(a),Zh.forEach(a),Zr=u(hs),ro=r(hs,"SPAN",{});var Gh=n(ro);Nr=l(Gh,"Inference"),Gh.forEach(a),hs.forEach(a),hl=u(e),oe=r(e,"P",{});var Za=n(oe);Gr=l(Za,"Now you can use the model for inference by loading the base model in the "),na=r(Za,"A",{href:!0});var Wh=n(na);Wr=l(Wh,"StableDiffusionPipeline"),Wh.forEach(a),Br=l(Za," and then the "),ia=r(Za,"A",{href:!0});var Bh=n(ia);Sr=l(Bh,"DPMSolverMultistepScheduler"),Bh.forEach(a),Lr=l(Za,":"),Za.forEach(a),fl=u(e),T(_t.$$.fragment,e),pl=u(e),le=r(e,"P",{});var Na=n(le);Cr=l(Na,"Load the LoRA weights from your finetuned model "),no=r(Na,"EM",{});var Sh=n(no);Xr=l(Sh,"on top of the base model weights"),Sh.forEach(a),Dr=l(Na,", and then move the pipeline to a GPU for faster inference. When you merge the LoRA weights with the frozen pretrained model weights, you can optionally adjust how much of the weights to merge with the "),io=r(Na,"CODE",{});var Lh=n(io);Vr=l(Lh,"scale"),Lh.forEach(a),Yr=l(Na," parameter:"),Na.forEach(a),dl=u(e),T(Ze.$$.fragment,e),ul=u(e),T(yt.$$.fragment,e),cl=u(e),T(Ne.$$.fragment,e),ml=u(e),be=r(e,"H2",{class:!0});var fs=n(be);Ge=r(fs,"A",{id:!0,class:!0,href:!0});var Ch=n(Ge);ho=r(Ch,"SPAN",{});var Xh=n(ho);T(bt.$$.fragment,Xh),Xh.forEach(a),Ch.forEach(a),xr=u(fs),fo=r(fs,"SPAN",{});var Dh=n(fo);Fr=l(Dh,"DreamBooth"),Dh.forEach(a),fs.forEach(a),wl=u(e),Mt=r(e,"P",{});var Qi=n(Mt);vt=r(Qi,"A",{href:!0,rel:!0});var Vh=n(vt);Pr=l(Vh,"DreamBooth"),Vh.forEach(a),zr=l(Qi," is a finetuning technique for personalizing a text-to-image model like Stable Diffusion to generate photorealistic images of a subject in different contexts, given a few images of the subject. However, DreamBooth is very sensitive to hyperparameters and it is easy to overfit. Some important hyperparameters to consider include those that affect the training time (learning rate, number of training steps), and inference time (number of steps, scheduler type)."),Qi.forEach(a),gl=u(e),T(We.$$.fragment,e),_l=u(e),Me=r(e,"H3",{class:!0});var ps=n(Me);Be=r(ps,"A",{id:!0,class:!0,href:!0});var Yh=n(Be);po=r(Yh,"SPAN",{});var xh=n(po);T(Tt.$$.fragment,xh),xh.forEach(a),Yh.forEach(a),Qr=u(ps),uo=r(ps,"SPAN",{});var Fh=n(uo);Hr=l(Fh,"Training"),Fh.forEach(a),ps.forEach(a),yl=u(e),F=r(e,"P",{});var Ke=n(F);qr=l(Ke,"Let\u2019s finetune "),Jt=r(Ke,"A",{href:!0,rel:!0});var Ph=n(Jt);co=r(Ph,"CODE",{});var zh=n(co);Or=l(zh,"stable-diffusion-v1-5"),zh.forEach(a),Ph.forEach(a),Kr=l(Ke," with DreamBooth and LoRA with some \u{1F436} "),Et=r(Ke,"A",{href:!0,rel:!0});var Qh=n(Et);en=l(Qh,"dog images"),Qh.forEach(a),tn=l(Ke,". Download and save these images to a directory. To use your own dataset, take a look at the "),ha=r(Ke,"A",{href:!0});var Hh=n(ha);an=l(Hh,"Create a dataset for training"),Hh.forEach(a),on=l(Ke," guide."),Ke.forEach(a),bl=u(e),P=r(e,"P",{});var et=n(P);ln=l(et,"To start, specify the "),mo=r(et,"CODE",{});var qh=n(mo);sn=l(qh,"MODEL_NAME"),qh.forEach(a),rn=l(et," environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),Ut=r(et,"A",{href:!0,rel:!0});var Oh=n(Ut);wo=r(Oh,"CODE",{});var Kh=n(wo);nn=l(Kh,"pretrained_model_name_or_path"),Kh.forEach(a),Oh.forEach(a),hn=l(et," argument. You\u2019ll also need to set "),go=r(et,"CODE",{});var ef=n(go);fn=l(ef,"INSTANCE_DIR"),ef.forEach(a),pn=l(et," to the path of the directory containing the images."),et.forEach(a),Ml=u(e),Se=r(e,"P",{});var ds=n(Se);dn=l(ds,"The "),_o=r(ds,"CODE",{});var tf=n(_o);un=l(tf,"OUTPUT_DIR"),tf.forEach(a),cn=l(ds," variables is optional and specifies where to save the model to on the Hub:"),ds.forEach(a),vl=u(e),T($t.$$.fragment,e),Tl=u(e),fa=r(e,"P",{});var af=n(fa);mn=l(af,"There are some flags to be aware of before you start training:"),af.forEach(a),Jl=u(e),se=r(e,"UL",{});var Ga=n(se);pa=r(Ga,"LI",{});var Hi=n(pa);yo=r(Hi,"CODE",{});var of=n(yo);wn=l(of,"--push_to_hub"),of.forEach(a),gn=l(Hi," stores the trained LoRA embeddings on the Hub."),Hi.forEach(a),_n=u(Ga),Le=r(Ga,"LI",{});var Fo=n(Le);bo=r(Fo,"CODE",{});var lf=n(bo);yn=l(lf,"--report_to=wandb"),lf.forEach(a),bn=l(Fo," reports and logs the training results to your Weights & Biases dashboard (as an example, take a look at this "),jt=r(Fo,"A",{href:!0,rel:!0});var sf=n(jt);Mn=l(sf,"report"),sf.forEach(a),vn=l(Fo,")."),Fo.forEach(a),Tn=u(Ga),da=r(Ga,"LI",{});var qi=n(da);Mo=r(qi,"CODE",{});var rf=n(Mo);Jn=l(rf,"--learning_rate=1e-04"),rf.forEach(a),En=l(qi,", you can afford to use a higher learning rate than you normally would with LoRA."),qi.forEach(a),Ga.forEach(a),El=u(e),re=r(e,"P",{});var Wa=n(re);Un=l(Wa,"Now you\u2019re ready to launch the training (you can find the full training script "),At=r(Wa,"A",{href:!0,rel:!0});var nf=n(At);$n=l(nf,"here"),nf.forEach(a),jn=l(Wa,"). The script creates and saves model checkpoints and the "),vo=r(Wa,"CODE",{});var hf=n(vo);An=l(hf,"pytorch_lora_weights.bin"),hf.forEach(a),Rn=l(Wa," file in your repository."),Wa.forEach(a),Ul=u(e),ne=r(e,"P",{});var Ba=n(ne);kn=l(Ba,`It\u2019s also possible to additionally fine-tune the text encoder with LoRA. This, in most cases, leads
to better results with a slight increase in the compute. To allow fine-tuning the text encoder with LoRA,
specify the `),To=r(Ba,"CODE",{});var ff=n(To);In=l(ff,"--train_text_encoder"),ff.forEach(a),Zn=l(Ba," while launching the "),Jo=r(Ba,"CODE",{});var pf=n(Jo);Nn=l(pf,"train_dreambooth_lora.py"),pf.forEach(a),Gn=l(Ba," script."),Ba.forEach(a),$l=u(e),T(Rt.$$.fragment,e),jl=u(e),ve=r(e,"H3",{class:!0});var us=n(ve);Ce=r(us,"A",{id:!0,class:!0,href:!0});var df=n(Ce);Eo=r(df,"SPAN",{});var uf=n(Eo);T(kt.$$.fragment,uf),uf.forEach(a),df.forEach(a),Wn=u(us),Uo=r(us,"SPAN",{});var cf=n(Uo);Bn=l(cf,"Inference"),cf.forEach(a),us.forEach(a),Al=u(e),Xe=r(e,"P",{});var cs=n(Xe);Sn=l(cs,"Now you can use the model for inference by loading the base model in the "),ua=r(cs,"A",{href:!0});var mf=n(ua);Ln=l(mf,"StableDiffusionPipeline"),mf.forEach(a),Cn=l(cs,":"),cs.forEach(a),Rl=u(e),T(It.$$.fragment,e),kl=u(e),ie=r(e,"P",{});var Sa=n(ie);Xn=l(Sa,"Load the LoRA weights from your finetuned DreamBooth model "),$o=r(Sa,"EM",{});var wf=n($o);Dn=l(wf,"on top of the base model weights"),wf.forEach(a),Vn=l(Sa,", and then move the pipeline to a GPU for faster inference. When you merge the LoRA weights with the frozen pretrained model weights, you can optionally adjust how much of the weights to merge with the "),jo=r(Sa,"CODE",{});var gf=n(jo);Yn=l(gf,"scale"),gf.forEach(a),xn=l(Sa," parameter:"),Sa.forEach(a),Il=u(e),T(De.$$.fragment,e),Zl=u(e),T(Zt.$$.fragment,e),Nl=u(e),he=r(e,"P",{});var La=n(he);Fn=l(La,"If you used "),Ao=r(La,"CODE",{});var _f=n(Ao);Pn=l(_f,"--train_text_encoder"),_f.forEach(a),zn=l(La," during training, then use "),Ro=r(La,"CODE",{});var yf=n(Ro);Qn=l(yf,"pipe.load_lora_weights()"),yf.forEach(a),Hn=l(La,` to load the LoRA
weights. For example:`),La.forEach(a),Gl=u(e),T(Nt.$$.fragment,e),Wl=u(e),T(Ve.$$.fragment,e),Bl=u(e),z=r(e,"P",{});var tt=n(z);qn=l(tt,"Note that the use of "),ca=r(tt,"A",{href:!0});var bf=n(ca);On=l(bf,"load_lora_weights()"),bf.forEach(a),Kn=l(tt," is preferred to "),ma=r(tt,"A",{href:!0});var Mf=n(ma);ei=l(Mf,"load_attn_procs()"),Mf.forEach(a),ti=l(tt,` for loading LoRA parameters. This is because
`),wa=r(tt,"A",{href:!0});var vf=n(wa);ai=l(vf,"load_lora_weights()"),vf.forEach(a),oi=l(tt," can handle the following situations:"),tt.forEach(a),Sl=u(e),Ye=r(e,"UL",{});var ms=n(Ye);Gt=r(ms,"LI",{});var ws=n(Gt);Wt=r(ws,"P",{});var gs=n(Wt);li=l(gs,"LoRA parameters that don\u2019t have separate identifiers for the UNet and the text encoder (such as "),Bt=r(gs,"A",{href:!0,rel:!0});var Tf=n(Bt);ko=r(Tf,"CODE",{});var Jf=n(ko);si=l(Jf,'"patrickvonplaten/lora_dreambooth_dog_example"'),Jf.forEach(a),Tf.forEach(a),ri=l(gs,"). So, you can just do:"),gs.forEach(a),ni=u(ws),T(St.$$.fragment,ws),ws.forEach(a),ii=u(ms),Io=r(ms,"LI",{});var Ef=n(Io);Lt=r(Ef,"P",{});var _s=n(Lt);hi=l(_s,"LoRA parameters that have separate identifiers for the UNet and the text encoder such as: "),Ct=r(_s,"A",{href:!0,rel:!0});var Uf=n(Ct);Zo=r(Uf,"CODE",{});var $f=n(Zo);fi=l($f,'"sayakpaul/dreambooth"'),$f.forEach(a),Uf.forEach(a),pi=l(_s,"."),_s.forEach(a),Ef.forEach(a),ms.forEach(a),Ll=u(e),q=r(e,"P",{});var Kt=n(q);No=r(Kt,"STRONG",{});var jf=n(No);di=l(jf,"Note"),jf.forEach(a),ui=l(Kt," that it is possible to provide a local directory path to "),ga=r(Kt,"A",{href:!0});var Af=n(ga);ci=l(Af,"load_lora_weights()"),Af.forEach(a),mi=l(Kt," as well as "),_a=r(Kt,"A",{href:!0});var Rf=n(_a);wi=l(Rf,"load_attn_procs()"),Rf.forEach(a),gi=l(Kt,`. To know about the supported inputs,
refer to the respective docstrings.`),Kt.forEach(a),Cl=u(e),Te=r(e,"H2",{class:!0});var ys=n(Te);xe=r(ys,"A",{id:!0,class:!0,href:!0});var kf=n(xe);Go=r(kf,"SPAN",{});var If=n(Go);T(Xt.$$.fragment,If),If.forEach(a),kf.forEach(a),_i=u(ys),Wo=r(ys,"SPAN",{});var Zf=n(Wo);yi=l(Zf,"Unloading LoRA parameters"),Zf.forEach(a),ys.forEach(a),Xl=u(e),Fe=r(e,"P",{});var bs=n(Fe);bi=l(bs,"You can call "),ya=r(bs,"A",{href:!0});var Nf=n(ya);Mi=l(Nf,"unload_lora_weights()"),Nf.forEach(a),vi=l(bs," on a pipeline to unload the LoRA parameters."),bs.forEach(a),Dl=u(e),Je=r(e,"H2",{class:!0});var Ms=n(Je);Pe=r(Ms,"A",{id:!0,class:!0,href:!0});var Gf=n(Pe);Bo=r(Gf,"SPAN",{});var Wf=n(Bo);T(Dt.$$.fragment,Wf),Wf.forEach(a),Gf.forEach(a),Ti=u(Ms),So=r(Ms,"SPAN",{});var Bf=n(So);Ji=l(Bf,"Supporting A1111 themed LoRA checkpoints from Diffusers"),Bf.forEach(a),Ms.forEach(a),Vl=u(e),fe=r(e,"P",{});var Ca=n(fe);Ei=l(Ca,"This support was made possible because of our amazing contributors: "),Vt=r(Ca,"A",{href:!0,rel:!0});var Sf=n(Vt);Ui=l(Sf,"@takuma104"),Sf.forEach(a),$i=l(Ca," and "),Yt=r(Ca,"A",{href:!0,rel:!0});var Lf=n(Yt);ji=l(Lf,"@isidentical"),Lf.forEach(a),Ai=l(Ca,"."),Ca.forEach(a),Yl=u(e),pe=r(e,"P",{});var Xa=n(pe);Ri=l(Xa,`To provide seamless interoperability with A1111 to our users, we support loading A1111 formatted
LoRA checkpoints using `),ba=r(Xa,"A",{href:!0});var Cf=n(ba);ki=l(Cf,"load_lora_weights()"),Cf.forEach(a),Ii=l(Xa,` in a limited capacity.
In this section, we explain how to load an A1111 formatted LoRA checkpoint from `),xt=r(Xa,"A",{href:!0,rel:!0});var Xf=n(xt);Zi=l(Xf,"CivitAI"),Xf.forEach(a),Ni=l(Xa,`
in Diffusers and perform inference with it.`),Xa.forEach(a),xl=u(e),ze=r(e,"P",{});var vs=n(ze);Gi=l(vs,`First, download a checkpoint. We\u2019ll use
`),Ft=r(vs,"A",{href:!0,rel:!0});var Df=n(Ft);Wi=l(Df,"this one"),Df.forEach(a),Bi=l(vs," for demonstration purposes."),vs.forEach(a),Fl=u(e),T(Pt.$$.fragment,e),Pl=u(e),Qe=r(e,"P",{});var Ts=n(Qe);Si=l(Ts,"Next, we initialize a "),Ma=r(Ts,"A",{href:!0});var Vf=n(Ma);Li=l(Vf,"~DiffusionPipeline"),Vf.forEach(a),Ci=l(Ts,":"),Ts.forEach(a),zl=u(e),T(zt.$$.fragment,e),Ql=u(e),va=r(e,"P",{});var Yf=n(va);Xi=l(Yf,"We then load the checkpoint downloaded from CivitAI:"),Yf.forEach(a),Hl=u(e),T(Qt.$$.fragment,e),ql=u(e),T(He.$$.fragment,e),Ol=u(e),Ta=r(e,"P",{});var xf=n(Ta);Di=l(xf,"And then it\u2019s time for running inference:"),xf.forEach(a),Kl=u(e),T(Ht.$$.fragment,e),es=u(e),Ja=r(e,"P",{});var Ff=n(Ja);Vi=l(Ff,"Below is a comparison between the LoRA and the non-LoRA results:"),Ff.forEach(a),ts=u(e),Ea=r(e,"P",{});var Pf=n(Ea);Ua=r(Pf,"IMG",{src:!0,alt:!0}),Pf.forEach(a),as=u(e),qe=r(e,"P",{});var Js=n(qe);Yi=l(Js,`You have a similar checkpoint stored on the Hugging Face Hub, you can load it
directly with `),$a=r(Js,"A",{href:!0});var zf=n($a);xi=l(zf,"load_lora_weights()"),zf.forEach(a),Fi=l(Js," like so:"),Js.forEach(a),os=u(e),T(qt.$$.fragment,e),this.h()},h(){f(p,"name","hf:doc:metadata"),f(p,"content",JSON.stringify(pp)),f(w,"id","lowrank-adaptation-of-large-language-models-lora"),f(w,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(w,"href","#lowrank-adaptation-of-large-language-models-lora"),f(c,"class","relative group"),f(N,"href","https://arxiv.org/abs/2106.09685"),f(N,"rel","nofollow"),f(Y,"href","https://www.pnas.org/doi/10.1073/pnas.1611835114"),f(Y,"rel","nofollow"),f(ea,"href","/docs/diffusers/v0.19.0/en/api/loaders#diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs"),f(ot,"href","https://github.com/cloneofsimo"),f(ot,"rel","nofollow"),f(lt,"href","https://github.com/cloneofsimo/lora"),f(lt,"rel","nofollow"),f(st,"href","https://github.com/huggingface/diffusers/tree/main/examples/text_to_image#training-with-lora"),f(st,"rel","nofollow"),f(rt,"href","https://github.com/huggingface/diffusers/tree/main/examples/dreambooth#training-with-low-rank-adaptation-of-large-language-models-lora"),f(rt,"rel","nofollow"),f(ta,"href","hf.co/join"),f(Ae,"id","texttoimage"),f(Ae,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Ae,"href","#texttoimage"),f(ge,"class","relative group"),f(Re,"id","text-to-image-training"),f(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"),f(Re,"href","#text-to-image-training"),f(_e,"class","relative group"),f(ft,"href","https://huggingface.co/runwayml/stable-diffusion-v1-5"),f(ft,"rel","nofollow"),f(pt,"href","https://huggingface.co/datasets/lambdalabs/pokemon-blip-captions"),f(pt,"rel","nofollow"),f(dt,"href","https://huggingface.co/docs/diffusers/en/api/diffusion_pipeline#diffusers.DiffusionPipeline.from_pretrained.pretrained_model_name_or_path"),f(dt,"rel","nofollow"),f(oa,"href","create_dataset"),f(ct,"href","https://wandb.ai/pcuenq/text2image-fine-tune/runs/b4k1w0tn?workspace=user-pcuenq"),f(ct,"rel","nofollow"),f(mt,"href","https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_lora.py"),f(mt,"rel","nofollow"),f(Ie,"id","text-to-image-inference"),f(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"),f(Ie,"href","#text-to-image-inference"),f(ye,"class","relative group"),f(na,"href","/docs/diffusers/v0.19.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),f(ia,"href","/docs/diffusers/v0.19.0/en/api/schedulers/multistep_dpm_solver#diffusers.DPMSolverMultistepScheduler"),f(Ge,"id","dreambooth"),f(Ge,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Ge,"href","#dreambooth"),f(be,"class","relative group"),f(vt,"href","https://arxiv.org/abs/2208.12242"),f(vt,"rel","nofollow"),f(Be,"id","dreambooth-training"),f(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"),f(Be,"href","#dreambooth-training"),f(Me,"class","relative group"),f(Jt,"href","https://huggingface.co/runwayml/stable-diffusion-v1-5"),f(Jt,"rel","nofollow"),f(Et,"href","https://drive.google.com/drive/folders/1BO_dyz-p65qhBRRMRA4TbZ8qW4rB99JZ"),f(Et,"rel","nofollow"),f(ha,"href","create_dataset"),f(Ut,"href","https://huggingface.co/docs/diffusers/en/api/diffusion_pipeline#diffusers.DiffusionPipeline.from_pretrained.pretrained_model_name_or_path"),f(Ut,"rel","nofollow"),f(jt,"href","https://wandb.ai/pcuenq/text2image-fine-tune/runs/b4k1w0tn?workspace=user-pcuenq"),f(jt,"rel","nofollow"),f(At,"href","https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/train_dreambooth_lora.py"),f(At,"rel","nofollow"),f(Ce,"id","dreambooth-inference"),f(Ce,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Ce,"href","#dreambooth-inference"),f(ve,"class","relative group"),f(ua,"href","/docs/diffusers/v0.19.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),f(ca,"href","/docs/diffusers/v0.19.0/en/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline.load_lora_weights"),f(ma,"href","/docs/diffusers/v0.19.0/en/api/loaders#diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs"),f(wa,"href","/docs/diffusers/v0.19.0/en/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline.load_lora_weights"),f(Bt,"href","https://huggingface.co/patrickvonplaten/lora_dreambooth_dog_example"),f(Bt,"rel","nofollow"),f(Ct,"href","https://huggingface.co/sayakpaul/dreambooth"),f(Ct,"rel","nofollow"),f(ga,"href","/docs/diffusers/v0.19.0/en/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline.load_lora_weights"),f(_a,"href","/docs/diffusers/v0.19.0/en/api/loaders#diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs"),f(xe,"id","unloading-lora-parameters"),f(xe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(xe,"href","#unloading-lora-parameters"),f(Te,"class","relative group"),f(ya,"href","/docs/diffusers/v0.19.0/en/api/loaders#diffusers.loaders.LoraLoaderMixin.unload_lora_weights"),f(Pe,"id","supporting-a1111-themed-lora-checkpoints-from-diffusers"),f(Pe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Pe,"href","#supporting-a1111-themed-lora-checkpoints-from-diffusers"),f(Je,"class","relative group"),f(Vt,"href","https://github.com/takuma104"),f(Vt,"rel","nofollow"),f(Yt,"href","https://github.com/isidentical"),f(Yt,"rel","nofollow"),f(ba,"href","/docs/diffusers/v0.19.0/en/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline.load_lora_weights"),f(xt,"href","https://civitai.com/"),f(xt,"rel","nofollow"),f(Ft,"href","https://civitai.com/models/13239/light-and-shadow"),f(Ft,"rel","nofollow"),f(Ma,"href","/docs/diffusers/v0.19.0/en/api/pipelines/overview#diffusers.DiffusionPipeline"),Kf(Ua.src,Oi="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/lora_non_lora_comparison.png")||f(Ua,"src",Oi),f(Ua,"alt","lora_non_lora"),f($a,"href","/docs/diffusers/v0.19.0/en/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline.load_lora_weights")},m(e,i){t(document.head,p),h(e,M,i),h(e,c,i),t(c,w),t(w,j),J(m,j,null),t(c,y),t(c,R),t(R,A),h(e,g,i),J(I,e,i),h(e,_,i),h(e,k,i),t(k,N),t(N,G),t(k,Q),t(k,X),t(X,S),t(k,H),t(k,D),t(D,L),t(k,b),h(e,O,i),h(e,W,i),t(W,V),t(V,ce),t(V,Y),t(Y,me),t(V,Es),t(W,Us),t(W,Da),t(Da,$s),t(W,js),t(W,we),t(we,As),t(we,ea),t(ea,Rs),t(we,ks),t(we,Va),t(Va,Is),t(we,Zs),t(W,Ns),t(W,Ya),t(Ya,Gs),h(e,Po,i),J($e,e,i),h(e,zo,i),h(e,x,i),t(x,ot),t(ot,Ws),t(x,Bs),t(x,lt),t(lt,Ss),t(x,Ls),t(x,st),t(st,Cs),t(x,Xs),t(x,rt),t(rt,Ds),t(x,Vs),h(e,Qo,i),h(e,je,i),t(je,Ys),t(je,ta),t(ta,xs),t(je,Fs),h(e,Ho,i),J(nt,e,i),h(e,qo,i),h(e,ge,i),t(ge,Ae),t(Ae,xa),J(it,xa,null),t(ge,Ps),t(ge,Fa),t(Fa,zs),h(e,Oo,i),h(e,aa,i),t(aa,Qs),h(e,Ko,i),h(e,_e,i),t(_e,Re),t(Re,Pa),J(ht,Pa,null),t(_e,Hs),t(_e,za),t(za,qs),h(e,el,i),h(e,K,i),t(K,Os),t(K,ft),t(ft,Qa),t(Qa,Ks),t(K,er),t(K,pt),t(pt,tr),t(K,ar),h(e,tl,i),h(e,C,i),t(C,or),t(C,Ha),t(Ha,lr),t(C,sr),t(C,dt),t(dt,qa),t(qa,rr),t(C,nr),t(C,Oa),t(Oa,ir),t(C,hr),t(C,oa),t(oa,fr),t(C,pr),h(e,al,i),h(e,ee,i),t(ee,dr),t(ee,Ka),t(Ka,ur),t(ee,cr),t(ee,eo),t(eo,mr),t(ee,wr),h(e,ol,i),J(ut,e,i),h(e,ll,i),h(e,la,i),t(la,gr),h(e,sl,i),h(e,te,i),t(te,sa),t(sa,to),t(to,_r),t(sa,yr),t(te,br),t(te,ke),t(ke,ao),t(ao,Mr),t(ke,vr),t(ke,ct),t(ct,Tr),t(ke,Jr),t(te,Er),t(te,ra),t(ra,oo),t(oo,Ur),t(ra,$r),h(e,rl,i),h(e,ae,i),t(ae,jr),t(ae,mt),t(mt,Ar),t(ae,Rr),t(ae,lo),t(lo,kr),t(ae,Ir),h(e,nl,i),J(wt,e,i),h(e,il,i),h(e,ye,i),t(ye,Ie),t(Ie,so),J(gt,so,null),t(ye,Zr),t(ye,ro),t(ro,Nr),h(e,hl,i),h(e,oe,i),t(oe,Gr),t(oe,na),t(na,Wr),t(oe,Br),t(oe,ia),t(ia,Sr),t(oe,Lr),h(e,fl,i),J(_t,e,i),h(e,pl,i),h(e,le,i),t(le,Cr),t(le,no),t(no,Xr),t(le,Dr),t(le,io),t(io,Vr),t(le,Yr),h(e,dl,i),J(Ze,e,i),h(e,ul,i),J(yt,e,i),h(e,cl,i),J(Ne,e,i),h(e,ml,i),h(e,be,i),t(be,Ge),t(Ge,ho),J(bt,ho,null),t(be,xr),t(be,fo),t(fo,Fr),h(e,wl,i),h(e,Mt,i),t(Mt,vt),t(vt,Pr),t(Mt,zr),h(e,gl,i),J(We,e,i),h(e,_l,i),h(e,Me,i),t(Me,Be),t(Be,po),J(Tt,po,null),t(Me,Qr),t(Me,uo),t(uo,Hr),h(e,yl,i),h(e,F,i),t(F,qr),t(F,Jt),t(Jt,co),t(co,Or),t(F,Kr),t(F,Et),t(Et,en),t(F,tn),t(F,ha),t(ha,an),t(F,on),h(e,bl,i),h(e,P,i),t(P,ln),t(P,mo),t(mo,sn),t(P,rn),t(P,Ut),t(Ut,wo),t(wo,nn),t(P,hn),t(P,go),t(go,fn),t(P,pn),h(e,Ml,i),h(e,Se,i),t(Se,dn),t(Se,_o),t(_o,un),t(Se,cn),h(e,vl,i),J($t,e,i),h(e,Tl,i),h(e,fa,i),t(fa,mn),h(e,Jl,i),h(e,se,i),t(se,pa),t(pa,yo),t(yo,wn),t(pa,gn),t(se,_n),t(se,Le),t(Le,bo),t(bo,yn),t(Le,bn),t(Le,jt),t(jt,Mn),t(Le,vn),t(se,Tn),t(se,da),t(da,Mo),t(Mo,Jn),t(da,En),h(e,El,i),h(e,re,i),t(re,Un),t(re,At),t(At,$n),t(re,jn),t(re,vo),t(vo,An),t(re,Rn),h(e,Ul,i),h(e,ne,i),t(ne,kn),t(ne,To),t(To,In),t(ne,Zn),t(ne,Jo),t(Jo,Nn),t(ne,Gn),h(e,$l,i),J(Rt,e,i),h(e,jl,i),h(e,ve,i),t(ve,Ce),t(Ce,Eo),J(kt,Eo,null),t(ve,Wn),t(ve,Uo),t(Uo,Bn),h(e,Al,i),h(e,Xe,i),t(Xe,Sn),t(Xe,ua),t(ua,Ln),t(Xe,Cn),h(e,Rl,i),J(It,e,i),h(e,kl,i),h(e,ie,i),t(ie,Xn),t(ie,$o),t($o,Dn),t(ie,Vn),t(ie,jo),t(jo,Yn),t(ie,xn),h(e,Il,i),J(De,e,i),h(e,Zl,i),J(Zt,e,i),h(e,Nl,i),h(e,he,i),t(he,Fn),t(he,Ao),t(Ao,Pn),t(he,zn),t(he,Ro),t(Ro,Qn),t(he,Hn),h(e,Gl,i),J(Nt,e,i),h(e,Wl,i),J(Ve,e,i),h(e,Bl,i),h(e,z,i),t(z,qn),t(z,ca),t(ca,On),t(z,Kn),t(z,ma),t(ma,ei),t(z,ti),t(z,wa),t(wa,ai),t(z,oi),h(e,Sl,i),h(e,Ye,i),t(Ye,Gt),t(Gt,Wt),t(Wt,li),t(Wt,Bt),t(Bt,ko),t(ko,si),t(Wt,ri),t(Gt,ni),J(St,Gt,null),t(Ye,ii),t(Ye,Io),t(Io,Lt),t(Lt,hi),t(Lt,Ct),t(Ct,Zo),t(Zo,fi),t(Lt,pi),h(e,Ll,i),h(e,q,i),t(q,No),t(No,di),t(q,ui),t(q,ga),t(ga,ci),t(q,mi),t(q,_a),t(_a,wi),t(q,gi),h(e,Cl,i),h(e,Te,i),t(Te,xe),t(xe,Go),J(Xt,Go,null),t(Te,_i),t(Te,Wo),t(Wo,yi),h(e,Xl,i),h(e,Fe,i),t(Fe,bi),t(Fe,ya),t(ya,Mi),t(Fe,vi),h(e,Dl,i),h(e,Je,i),t(Je,Pe),t(Pe,Bo),J(Dt,Bo,null),t(Je,Ti),t(Je,So),t(So,Ji),h(e,Vl,i),h(e,fe,i),t(fe,Ei),t(fe,Vt),t(Vt,Ui),t(fe,$i),t(fe,Yt),t(Yt,ji),t(fe,Ai),h(e,Yl,i),h(e,pe,i),t(pe,Ri),t(pe,ba),t(ba,ki),t(pe,Ii),t(pe,xt),t(xt,Zi),t(pe,Ni),h(e,xl,i),h(e,ze,i),t(ze,Gi),t(ze,Ft),t(Ft,Wi),t(ze,Bi),h(e,Fl,i),J(Pt,e,i),h(e,Pl,i),h(e,Qe,i),t(Qe,Si),t(Qe,Ma),t(Ma,Li),t(Qe,Ci),h(e,zl,i),J(zt,e,i),h(e,Ql,i),h(e,va,i),t(va,Xi),h(e,Hl,i),J(Qt,e,i),h(e,ql,i),J(He,e,i),h(e,Ol,i),h(e,Ta,i),t(Ta,Di),h(e,Kl,i),J(Ht,e,i),h(e,es,i),h(e,Ja,i),t(Ja,Vi),h(e,ts,i),h(e,Ea,i),t(Ea,Ua),h(e,as,i),h(e,qe,i),t(qe,Yi),t(qe,$a),t($a,xi),t(qe,Fi),h(e,os,i),J(qt,e,i),ls=!0},p(e,[i]){const Ot={};i&2&&(Ot.$$scope={dirty:i,ctx:e}),I.$set(Ot);const Lo={};i&2&&(Lo.$$scope={dirty:i,ctx:e}),$e.$set(Lo);const Co={};i&2&&(Co.$$scope={dirty:i,ctx:e}),Ze.$set(Co);const Xo={};i&2&&(Xo.$$scope={dirty:i,ctx:e}),Ne.$set(Xo);const de={};i&2&&(de.$$scope={dirty:i,ctx:e}),We.$set(de);const Do={};i&2&&(Do.$$scope={dirty:i,ctx:e}),De.$set(Do);const Vo={};i&2&&(Vo.$$scope={dirty:i,ctx:e}),Ve.$set(Vo);const Yo={};i&2&&(Yo.$$scope={dirty:i,ctx:e}),He.$set(Yo)},i(e){ls||(E(m.$$.fragment,e),E(I.$$.fragment,e),E($e.$$.fragment,e),E(nt.$$.fragment,e),E(it.$$.fragment,e),E(ht.$$.fragment,e),E(ut.$$.fragment,e),E(wt.$$.fragment,e),E(gt.$$.fragment,e),E(_t.$$.fragment,e),E(Ze.$$.fragment,e),E(yt.$$.fragment,e),E(Ne.$$.fragment,e),E(bt.$$.fragment,e),E(We.$$.fragment,e),E(Tt.$$.fragment,e),E($t.$$.fragment,e),E(Rt.$$.fragment,e),E(kt.$$.fragment,e),E(It.$$.fragment,e),E(De.$$.fragment,e),E(Zt.$$.fragment,e),E(Nt.$$.fragment,e),E(Ve.$$.fragment,e),E(St.$$.fragment,e),E(Xt.$$.fragment,e),E(Dt.$$.fragment,e),E(Pt.$$.fragment,e),E(zt.$$.fragment,e),E(Qt.$$.fragment,e),E(He.$$.fragment,e),E(Ht.$$.fragment,e),E(qt.$$.fragment,e),ls=!0)},o(e){U(m.$$.fragment,e),U(I.$$.fragment,e),U($e.$$.fragment,e),U(nt.$$.fragment,e),U(it.$$.fragment,e),U(ht.$$.fragment,e),U(ut.$$.fragment,e),U(wt.$$.fragment,e),U(gt.$$.fragment,e),U(_t.$$.fragment,e),U(Ze.$$.fragment,e),U(yt.$$.fragment,e),U(Ne.$$.fragment,e),U(bt.$$.fragment,e),U(We.$$.fragment,e),U(Tt.$$.fragment,e),U($t.$$.fragment,e),U(Rt.$$.fragment,e),U(kt.$$.fragment,e),U(It.$$.fragment,e),U(De.$$.fragment,e),U(Zt.$$.fragment,e),U(Nt.$$.fragment,e),U(Ve.$$.fragment,e),U(St.$$.fragment,e),U(Xt.$$.fragment,e),U(Dt.$$.fragment,e),U(Pt.$$.fragment,e),U(zt.$$.fragment,e),U(Qt.$$.fragment,e),U(He.$$.fragment,e),U(Ht.$$.fragment,e),U(qt.$$.fragment,e),ls=!1},d(e){a(p),e&&a(M),e&&a(c),$(m),e&&a(g),$(I,e),e&&a(_),e&&a(k),e&&a(O),e&&a(W),e&&a(Po),$($e,e),e&&a(zo),e&&a(x),e&&a(Qo),e&&a(je),e&&a(Ho),$(nt,e),e&&a(qo),e&&a(ge),$(it),e&&a(Oo),e&&a(aa),e&&a(Ko),e&&a(_e),$(ht),e&&a(el),e&&a(K),e&&a(tl),e&&a(C),e&&a(al),e&&a(ee),e&&a(ol),$(ut,e),e&&a(ll),e&&a(la),e&&a(sl),e&&a(te),e&&a(rl),e&&a(ae),e&&a(nl),$(wt,e),e&&a(il),e&&a(ye),$(gt),e&&a(hl),e&&a(oe),e&&a(fl),$(_t,e),e&&a(pl),e&&a(le),e&&a(dl),$(Ze,e),e&&a(ul),$(yt,e),e&&a(cl),$(Ne,e),e&&a(ml),e&&a(be),$(bt),e&&a(wl),e&&a(Mt),e&&a(gl),$(We,e),e&&a(_l),e&&a(Me),$(Tt),e&&a(yl),e&&a(F),e&&a(bl),e&&a(P),e&&a(Ml),e&&a(Se),e&&a(vl),$($t,e),e&&a(Tl),e&&a(fa),e&&a(Jl),e&&a(se),e&&a(El),e&&a(re),e&&a(Ul),e&&a(ne),e&&a($l),$(Rt,e),e&&a(jl),e&&a(ve),$(kt),e&&a(Al),e&&a(Xe),e&&a(Rl),$(It,e),e&&a(kl),e&&a(ie),e&&a(Il),$(De,e),e&&a(Zl),$(Zt,e),e&&a(Nl),e&&a(he),e&&a(Gl),$(Nt,e),e&&a(Wl),$(Ve,e),e&&a(Bl),e&&a(z),e&&a(Sl),e&&a(Ye),$(St),e&&a(Ll),e&&a(q),e&&a(Cl),e&&a(Te),$(Xt),e&&a(Xl),e&&a(Fe),e&&a(Dl),e&&a(Je),$(Dt),e&&a(Vl),e&&a(fe),e&&a(Yl),e&&a(pe),e&&a(xl),e&&a(ze),e&&a(Fl),$(Pt,e),e&&a(Pl),e&&a(Qe),e&&a(zl),$(zt,e),e&&a(Ql),e&&a(va),e&&a(Hl),$(Qt,e),e&&a(ql),$(He,e),e&&a(Ol),e&&a(Ta),e&&a(Kl),$(Ht,e),e&&a(es),e&&a(Ja),e&&a(ts),e&&a(Ea),e&&a(as),e&&a(qe),e&&a(os),$(qt,e)}}}const pp={local:"lowrank-adaptation-of-large-language-models-lora",sections:[{local:"texttoimage",sections:[{local:"text-to-image-training",title:"Training"},{local:"text-to-image-inference",title:"Inference"}],title:"Text-to-image"},{local:"dreambooth",sections:[{local:"dreambooth-training",title:"Training"},{local:"dreambooth-inference",title:"Inference"}],title:"DreamBooth"},{local:"unloading-lora-parameters",title:"Unloading LoRA parameters"},{local:"supporting-a1111-themed-lora-checkpoints-from-diffusers",title:"Supporting A1111 themed LoRA checkpoints from Diffusers"}],title:"Low-Rank Adaptation of Large Language Models (LoRA)"};function dp(Z){return ep(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class gp extends Qf{constructor(p){super();Hf(this,p,dp,fp,qf,{})}}export{gp as default,pp as metadata};
