import{s as Et,o as Vt,n as he}from"../chunks/scheduler.8c3d61f6.js";import{S as Bt,i as At,g as u,s as i,r as d,A as Ft,h as m,f as a,c as r,j as Wt,u as y,x as c,k as It,y as Nt,a as l,v as M,d as _,t as g,w as $}from"../chunks/index.da70eac4.js";import{T as de}from"../chunks/Tip.1d9b8c37.js";import{C as U}from"../chunks/CodeBlock.a9c4becf.js";import{H as ye,E as Ht}from"../chunks/getInferenceSnippets.28ca3596.js";import{H as Qt,a as Gt}from"../chunks/HfOption.6c3b4e77.js";function St(b){let n,h="This is experimental and the API may change in the future.";return{c(){n=u("p"),n.textContent=h},l(s){n=m(s,"P",{"data-svelte-h":!0}),c(n)!=="svelte-us7smu"&&(n.textContent=h)},m(s,f){l(s,n,f)},p:he,d(s){s&&a(n)}}}function Yt(b){let n,h='LoRA is very versatile and supported for <a href="https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/train_dreambooth_lora.py" rel="nofollow">DreamBooth</a>, <a href="https://github.com/huggingface/diffusers/blob/main/examples/kandinsky2_2/text_to_image/train_text_to_image_lora_decoder.py" rel="nofollow">Kandinsky 2.2</a>, <a href="https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_lora_sdxl.py" rel="nofollow">Stable Diffusion XL</a>, <a href="https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_lora.py" rel="nofollow">text-to-image</a>, and <a href="https://github.com/huggingface/diffusers/blob/main/examples/wuerstchen/text_to_image/train_text_to_image_lora_prior.py" rel="nofollow">Wuerstchen</a>.';return{c(){n=u("p"),n.innerHTML=h},l(s){n=m(s,"P",{"data-svelte-h":!0}),c(n)!=="svelte-1xa3xmb"&&(n.innerHTML=h)},m(s,f){l(s,n,f)},p:he,d(s){s&&a(n)}}}function qt(b){let n,h='🤗 Accelerate is a library for helping you train on multiple GPUs/TPUs or with mixed-precision. It’ll automatically configure your training setup based on your hardware and environment. Take a look at the 🤗 Accelerate <a href="https://huggingface.co/docs/accelerate/quicktour" rel="nofollow">Quick tour</a> to learn more.';return{c(){n=u("p"),n.innerHTML=h},l(s){n=m(s,"P",{"data-svelte-h":!0}),c(n)!=="svelte-1qbiqsn"&&(n.innerHTML=h)},m(s,f){l(s,n,f)},p:he,d(s){s&&a(n)}}}function zt(b){let n,h='The following sections highlight parts of the training script that are important for understanding how to modify it, but it doesn’t cover every aspect of the script in detail. If you’re interested in learning more, feel free to read through the <a href="https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_lora.py" rel="nofollow">script</a> and let us know if you have any questions or concerns.';return{c(){n=u("p"),n.innerHTML=h},l(s){n=m(s,"P",{"data-svelte-h":!0}),c(n)!=="svelte-38b4u1"&&(n.innerHTML=h)},m(s,f){l(s,n,f)},p:he,d(s){s&&a(n)}}}function Pt(b){let n,h='Diffusers uses <code>~peft.LoraConfig</code> from the <a href="https://hf.co/docs/peft" rel="nofollow">PEFT</a> library to set up the parameters of the LoRA adapter such as the rank, alpha, and which modules to insert the LoRA weights into. The adapter is added to the UNet, and only the LoRA layers are filtered for optimization in <code>lora_layers</code>.',s,f,p;return f=new U({props:{code:"dW5ldF9sb3JhX2NvbmZpZyUyMCUzRCUyMExvcmFDb25maWcoJTBBJTIwJTIwJTIwJTIwciUzRGFyZ3MucmFuayUyQyUwQSUyMCUyMCUyMCUyMGxvcmFfYWxwaGElM0RhcmdzLnJhbmslMkMlMEElMjAlMjAlMjAlMjBpbml0X2xvcmFfd2VpZ2h0cyUzRCUyMmdhdXNzaWFuJTIyJTJDJTBBJTIwJTIwJTIwJTIwdGFyZ2V0X21vZHVsZXMlM0QlNUIlMjJ0b19rJTIyJTJDJTIwJTIydG9fcSUyMiUyQyUyMCUyMnRvX3YlMjIlMkMlMjAlMjJ0b19vdXQuMCUyMiU1RCUyQyUwQSklMEElMEF1bmV0LmFkZF9hZGFwdGVyKHVuZXRfbG9yYV9jb25maWcpJTBBbG9yYV9sYXllcnMlMjAlM0QlMjBmaWx0ZXIobGFtYmRhJTIwcCUzQSUyMHAucmVxdWlyZXNfZ3JhZCUyQyUyMHVuZXQucGFyYW1ldGVycygpKQ==",highlighted:`unet_lora_config = LoraConfig(
    r=args.rank,
    lora_alpha=args.rank,
    init_lora_weights=<span class="hljs-string">&quot;gaussian&quot;</span>,
    target_modules=[<span class="hljs-string">&quot;to_k&quot;</span>, <span class="hljs-string">&quot;to_q&quot;</span>, <span class="hljs-string">&quot;to_v&quot;</span>, <span class="hljs-string">&quot;to_out.0&quot;</span>],
)

unet.add_adapter(unet_lora_config)
lora_layers = <span class="hljs-built_in">filter</span>(<span class="hljs-keyword">lambda</span> p: p.requires_grad, unet.parameters())`,wrap:!1}}),{c(){n=u("p"),n.innerHTML=h,s=i(),d(f.$$.fragment)},l(o){n=m(o,"P",{"data-svelte-h":!0}),c(n)!=="svelte-inmuy9"&&(n.innerHTML=h),s=r(o),y(f.$$.fragment,o)},m(o,w){l(o,n,w),l(o,s,w),M(f,o,w),p=!0},p:he,i(o){p||(_(f.$$.fragment,o),p=!0)},o(o){g(f.$$.fragment,o),p=!1},d(o){o&&(a(n),a(s)),$(f,o)}}}function Dt(b){let n,h='Diffusers also supports finetuning the text encoder with LoRA from the <a href="https://hf.co/docs/peft" rel="nofollow">PEFT</a> library when necessary such as finetuning Stable Diffusion XL (SDXL). The <code>~peft.LoraConfig</code> is used to configure the parameters of the LoRA adapter which are then added to the text encoder, and only the LoRA layers are filtered for training.',s,f,p;return f=new U({props:{code:"dGV4dF9sb3JhX2NvbmZpZyUyMCUzRCUyMExvcmFDb25maWcoJTBBJTIwJTIwJTIwJTIwciUzRGFyZ3MucmFuayUyQyUwQSUyMCUyMCUyMCUyMGxvcmFfYWxwaGElM0RhcmdzLnJhbmslMkMlMEElMjAlMjAlMjAlMjBpbml0X2xvcmFfd2VpZ2h0cyUzRCUyMmdhdXNzaWFuJTIyJTJDJTBBJTIwJTIwJTIwJTIwdGFyZ2V0X21vZHVsZXMlM0QlNUIlMjJxX3Byb2olMjIlMkMlMjAlMjJrX3Byb2olMjIlMkMlMjAlMjJ2X3Byb2olMjIlMkMlMjAlMjJvdXRfcHJvaiUyMiU1RCUyQyUwQSklMEElMEF0ZXh0X2VuY29kZXJfb25lLmFkZF9hZGFwdGVyKHRleHRfbG9yYV9jb25maWcpJTBBdGV4dF9lbmNvZGVyX3R3by5hZGRfYWRhcHRlcih0ZXh0X2xvcmFfY29uZmlnKSUwQXRleHRfbG9yYV9wYXJhbWV0ZXJzX29uZSUyMCUzRCUyMGxpc3QoZmlsdGVyKGxhbWJkYSUyMHAlM0ElMjBwLnJlcXVpcmVzX2dyYWQlMkMlMjB0ZXh0X2VuY29kZXJfb25lLnBhcmFtZXRlcnMoKSkpJTBBdGV4dF9sb3JhX3BhcmFtZXRlcnNfdHdvJTIwJTNEJTIwbGlzdChmaWx0ZXIobGFtYmRhJTIwcCUzQSUyMHAucmVxdWlyZXNfZ3JhZCUyQyUyMHRleHRfZW5jb2Rlcl90d28ucGFyYW1ldGVycygpKSk=",highlighted:`text_lora_config = LoraConfig(
    r=args.rank,
    lora_alpha=args.rank,
    init_lora_weights=<span class="hljs-string">&quot;gaussian&quot;</span>,
    target_modules=[<span class="hljs-string">&quot;q_proj&quot;</span>, <span class="hljs-string">&quot;k_proj&quot;</span>, <span class="hljs-string">&quot;v_proj&quot;</span>, <span class="hljs-string">&quot;out_proj&quot;</span>],
)

text_encoder_one.add_adapter(text_lora_config)
text_encoder_two.add_adapter(text_lora_config)
text_lora_parameters_one = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">filter</span>(<span class="hljs-keyword">lambda</span> p: p.requires_grad, text_encoder_one.parameters()))
text_lora_parameters_two = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">filter</span>(<span class="hljs-keyword">lambda</span> p: p.requires_grad, text_encoder_two.parameters()))`,wrap:!1}}),{c(){n=u("p"),n.innerHTML=h,s=i(),d(f.$$.fragment)},l(o){n=m(o,"P",{"data-svelte-h":!0}),c(n)!=="svelte-11pdijb"&&(n.innerHTML=h),s=r(o),y(f.$$.fragment,o)},m(o,w){l(o,n,w),l(o,s,w),M(f,o,w),p=!0},p:he,i(o){p||(_(f.$$.fragment,o),p=!0)},o(o){g(f.$$.fragment,o),p=!1},d(o){o&&(a(n),a(s)),$(f,o)}}}function Ot(b){let n,h,s,f;return n=new Gt({props:{id:"lora",option:"UNet",$$slots:{default:[Pt]},$$scope:{ctx:b}}}),s=new Gt({props:{id:"lora",option:"text encoder",$$slots:{default:[Dt]},$$scope:{ctx:b}}}),{c(){d(n.$$.fragment),h=i(),d(s.$$.fragment)},l(p){y(n.$$.fragment,p),h=r(p),y(s.$$.fragment,p)},m(p,o){M(n,p,o),l(p,h,o),M(s,p,o),f=!0},p(p,o){const w={};o&2&&(w.$$scope={dirty:o,ctx:p}),n.$set(w);const C={};o&2&&(C.$$scope={dirty:o,ctx:p}),s.$set(C)},i(p){f||(_(n.$$.fragment,p),_(s.$$.fragment,p),f=!0)},o(p){g(n.$$.fragment,p),g(s.$$.fragment,p),f=!1},d(p){p&&a(h),$(n,p),$(s,p)}}}function Kt(b){let n,h="A full training run takes ~5 hours on a 2080 Ti GPU with 11GB of VRAM.";return{c(){n=u("p"),n.textContent=h},l(s){n=m(s,"P",{"data-svelte-h":!0}),c(n)!=="svelte-phs0cw"&&(n.textContent=h)},m(s,f){l(s,n,f)},p:he,d(s){s&&a(n)}}}function ea(b){let n,h,s,f,p,o,w,C,Z,it='<a href="https://hf.co/papers/2106.09685" rel="nofollow">LoRA (Low-Rank Adaptation of Large Language Models)</a> is a popular and lightweight training technique that significantly reduces the number of trainable parameters. It works by inserting a smaller number of new weights into the model and only these are trained. This makes training with LoRA much faster, memory-efficient, and produces smaller model weights (a few hundred MBs), which are easier to store and share. LoRA can also be combined with other training techniques like DreamBooth to speedup training.',Me,T,_e,R,rt='This guide will explore the <a href="https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_lora.py" rel="nofollow">train_text_to_image_lora.py</a> script to help you become more familiar with it, and how you can adapt it for your own use-case.',ge,X,ot="Before running the script, make sure you install the library from source:",$e,L,we,k,pt="Navigate to the example folder with the training script and install the required dependencies for the script you’re using:",be,W,Ue,J,Te,I,ft="Initialize an 🤗 Accelerate environment:",Je,G,xe,E,ut="To setup a default 🤗 Accelerate environment without choosing any configurations:",je,V,ve,B,mt="Or if your environment doesn’t support an interactive shell, like a notebook, you can use:",Ce,A,Ze,F,ht='Lastly, if you want to train a model on your own dataset, take a look at the <a href="create_dataset">Create a dataset for training</a> guide to learn how to create a dataset that works with the training script.',Re,x,Xe,N,Le,H,ct='The training script has many parameters to help you customize your training run. All of the parameters and their descriptions are found in the <a href="https://github.com/huggingface/diffusers/blob/dd9a5caf61f04d11c0fa9f3947b69ab0010c9a0f/examples/text_to_image/train_text_to_image_lora.py#L85" rel="nofollow"><code>parse_args()</code></a> function. Default values are provided for most parameters that work pretty well, but you can also set your own values in the training command if you’d like.',ke,Q,dt="For example, to increase the number of epochs to train:",We,S,Ie,Y,yt='Many of the basic and important parameters are described in the <a href="text2image#script-parameters">Text-to-image</a> training guide, so this guide just focuses on the LoRA relevant parameters:',Ge,q,Mt="<li><code>--rank</code>: the inner dimension of the low-rank matrices to train; a higher rank means more trainable parameters</li> <li><code>--learning_rate</code>: the default learning rate is 1e-4, but with LoRA, you can use a higher learning rate</li>",Ee,z,Ve,P,_t='The dataset preprocessing code and training loop are found in the <a href="https://github.com/huggingface/diffusers/blob/dd9a5caf61f04d11c0fa9f3947b69ab0010c9a0f/examples/text_to_image/train_text_to_image_lora.py#L371" rel="nofollow"><code>main()</code></a> function, and if you need to adapt the training script, this is where you’ll make your changes.',Be,D,gt='As with the script parameters, a walkthrough of the training script is provided in the <a href="text2image#training-script">Text-to-image</a> training guide. Instead, this guide takes a look at the LoRA relevant parts of the script.',Ae,j,Fe,O,$t='The <a href="https://github.com/huggingface/diffusers/blob/e4b8f173b97731686e290b2eb98e7f5df2b1b322/examples/text_to_image/train_text_to_image_lora.py#L529" rel="nofollow">optimizer</a> is initialized with the <code>lora_layers</code> because these are the only weights that’ll be optimized:',Ne,K,He,ee,wt="Aside from setting up the LoRA layers, the training script is more or less the same as train_text_to_image.py!",Qe,te,Se,ae,bt="Once you’ve made all your changes or you’re okay with the default configuration, you’re ready to launch the training script! 🚀",Ye,le,Ut='Let’s train on the <a href="https://huggingface.co/datasets/lambdalabs/naruto-blip-captions" rel="nofollow">Naruto BLIP captions</a> dataset to generate your own Naruto characters. Set the environment variables <code>MODEL_NAME</code> and <code>DATASET_NAME</code> to the model and dataset respectively. You should also specify where to save the model in <code>OUTPUT_DIR</code>, and the name of the model to save to on the Hub with <code>HUB_MODEL_ID</code>. The script creates and saves the following files to your repository:',qe,ne,Tt="<li>saved model checkpoints</li> <li><code>pytorch_lora_weights.safetensors</code> (the trained LoRA weights)</li>",ze,se,Jt="If you’re training on more than one GPU, add the <code>--multi_gpu</code> parameter to the <code>accelerate launch</code> command.",Pe,v,De,ie,Oe,re,xt="Once training has been completed, you can use your model for inference:",Ke,oe,et,pe,tt,fe,jt="Congratulations on training a new model with LoRA! To learn more about how to use your new model, the following guides may be helpful:",at,ue,vt='<li>Learn how to <a href="../using-diffusers/loading_adapters#LoRA">load different LoRA formats</a> trained using community trainers like Kohya and TheLastBen.</li> <li>Learn how to use and <a href="../tutorials/using_peft_for_inference">combine multiple LoRA’s</a> with PEFT for inference.</li>',lt,me,nt,ce,st;return p=new ye({props:{title:"LoRA",local:"lora",headingTag:"h1"}}),w=new de({props:{warning:!0,$$slots:{default:[St]},$$scope:{ctx:b}}}),T=new de({props:{$$slots:{default:[Yt]},$$scope:{ctx:b}}}),L=new U({props:{code:"Z2l0JTIwY2xvbmUlMjBodHRwcyUzQSUyRiUyRmdpdGh1Yi5jb20lMkZodWdnaW5nZmFjZSUyRmRpZmZ1c2VycyUwQWNkJTIwZGlmZnVzZXJzJTBBcGlwJTIwaW5zdGFsbCUyMC4=",highlighted:`git <span class="hljs-built_in">clone</span> https://github.com/huggingface/diffusers
<span class="hljs-built_in">cd</span> diffusers
pip install .`,wrap:!1}}),W=new U({props:{code:"Y2QlMjBleGFtcGxlcyUyRnRleHRfdG9faW1hZ2UlMEFwaXAlMjBpbnN0YWxsJTIwLXIlMjByZXF1aXJlbWVudHMudHh0",highlighted:`<span class="hljs-built_in">cd</span> examples/text_to_image
pip install -r requirements.txt`,wrap:!1}}),J=new de({props:{$$slots:{default:[qt]},$$scope:{ctx:b}}}),G=new U({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),V=new U({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZyUyMGRlZmF1bHQ=",highlighted:"accelerate config default",wrap:!1}}),A=new U({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUudXRpbHMlMjBpbXBvcnQlMjB3cml0ZV9iYXNpY19jb25maWclMEElMEF3cml0ZV9iYXNpY19jb25maWcoKQ==",highlighted:`<span class="hljs-keyword">from</span> accelerate.utils <span class="hljs-keyword">import</span> write_basic_config

write_basic_config()`,wrap:!1}}),x=new de({props:{$$slots:{default:[zt]},$$scope:{ctx:b}}}),N=new ye({props:{title:"Script parameters",local:"script-parameters",headingTag:"h2"}}),S=new U({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX3RleHRfdG9faW1hZ2VfbG9yYS5weSUyMCU1QyUwQSUyMCUyMC0tbnVtX3RyYWluX2Vwb2NocyUzRDE1MCUyMCU1Qw==",highlighted:`accelerate launch train_text_to_image_lora.py \\
  --num_train_epochs=150 \\`,wrap:!1}}),z=new ye({props:{title:"Training script",local:"training-script",headingTag:"h2"}}),j=new Qt({props:{id:"lora",options:["UNet","text encoder"],$$slots:{default:[Ot]},$$scope:{ctx:b}}}),K=new U({props:{code:"b3B0aW1pemVyJTIwJTNEJTIwb3B0aW1pemVyX2NscyglMEElMjAlMjAlMjAlMjBsb3JhX2xheWVycyUyQyUwQSUyMCUyMCUyMCUyMGxyJTNEYXJncy5sZWFybmluZ19yYXRlJTJDJTBBJTIwJTIwJTIwJTIwYmV0YXMlM0QoYXJncy5hZGFtX2JldGExJTJDJTIwYXJncy5hZGFtX2JldGEyKSUyQyUwQSUyMCUyMCUyMCUyMHdlaWdodF9kZWNheSUzRGFyZ3MuYWRhbV93ZWlnaHRfZGVjYXklMkMlMEElMjAlMjAlMjAlMjBlcHMlM0RhcmdzLmFkYW1fZXBzaWxvbiUyQyUwQSk=",highlighted:`optimizer = optimizer_cls(
    lora_layers,
    lr=args.learning_rate,
    betas=(args.adam_beta1, args.adam_beta2),
    weight_decay=args.adam_weight_decay,
    eps=args.adam_epsilon,
)`,wrap:!1}}),te=new ye({props:{title:"Launch the script",local:"launch-the-script",headingTag:"h2"}}),v=new de({props:{warning:!0,$$slots:{default:[Kt]},$$scope:{ctx:b}}}),ie=new U({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUwQWV4cG9ydCUyME9VVFBVVF9ESVIlM0QlMjIlMkZzZGRhdGElMkZmaW5ldHVuZSUyRmxvcmElMkZuYXJ1dG8lMjIlMEFleHBvcnQlMjBIVUJfTU9ERUxfSUQlM0QlMjJuYXJ1dG8tbG9yYSUyMiUwQWV4cG9ydCUyMERBVEFTRVRfTkFNRSUzRCUyMmxhbWJkYWxhYnMlMkZuYXJ1dG8tYmxpcC1jYXB0aW9ucyUyMiUwQSUwQWFjY2VsZXJhdGUlMjBsYXVuY2glMjAtLW1peGVkX3ByZWNpc2lvbiUzRCUyMmZwMTYlMjIlMjAlMjB0cmFpbl90ZXh0X3RvX2ltYWdlX2xvcmEucHklMjAlNUMlMEElMjAlMjAtLXByZXRyYWluZWRfbW9kZWxfbmFtZV9vcl9wYXRoJTNEJTI0TU9ERUxfTkFNRSUyMCU1QyUwQSUyMCUyMC0tZGF0YXNldF9uYW1lJTNEJTI0REFUQVNFVF9OQU1FJTIwJTVDJTBBJTIwJTIwLS1kYXRhbG9hZGVyX251bV93b3JrZXJzJTNEOCUyMCU1QyUwQSUyMCUyMC0tcmVzb2x1dGlvbiUzRDUxMiUyMCU1QyUwQSUyMCUyMC0tY2VudGVyX2Nyb3AlMjAlNUMlMEElMjAlMjAtLXJhbmRvbV9mbGlwJTIwJTVDJTBBJTIwJTIwLS10cmFpbl9iYXRjaF9zaXplJTNEMSUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNENCUyMCU1QyUwQSUyMCUyMC0tbWF4X3RyYWluX3N0ZXBzJTNEMTUwMDAlMjAlNUMlMEElMjAlMjAtLWxlYXJuaW5nX3JhdGUlM0QxZS0wNCUyMCU1QyUwQSUyMCUyMC0tbWF4X2dyYWRfbm9ybSUzRDElMjAlNUMlMEElMjAlMjAtLWxyX3NjaGVkdWxlciUzRCUyMmNvc2luZSUyMiUyMCU1QyUwQSUyMCUyMC0tbHJfd2FybXVwX3N0ZXBzJTNEMCUyMCU1QyUwQSUyMCUyMC0tb3V0cHV0X2RpciUzRCUyNCU3Qk9VVFBVVF9ESVIlN0QlMjAlNUMlMEElMjAlMjAtLXB1c2hfdG9faHViJTIwJTVDJTBBJTIwJTIwLS1odWJfbW9kZWxfaWQlM0QlMjQlN0JIVUJfTU9ERUxfSUQlN0QlMjAlNUMlMEElMjAlMjAtLXJlcG9ydF90byUzRHdhbmRiJTIwJTVDJTBBJTIwJTIwLS1jaGVja3BvaW50aW5nX3N0ZXBzJTNENTAwJTIwJTVDJTBBJTIwJTIwLS12YWxpZGF0aW9uX3Byb21wdCUzRCUyMkElMjBuYXJ1dG8lMjB3aXRoJTIwYmx1ZSUyMGV5ZXMuJTIyJTIwJTVDJTBBJTIwJTIwLS1zZWVkJTNEMTMzNw==",highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;stable-diffusion-v1-5/stable-diffusion-v1-5&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;/sddata/finetune/lora/naruto&quot;</span>
<span class="hljs-built_in">export</span> HUB_MODEL_ID=<span class="hljs-string">&quot;naruto-lora&quot;</span>
<span class="hljs-built_in">export</span> DATASET_NAME=<span class="hljs-string">&quot;lambdalabs/naruto-blip-captions&quot;</span>

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 naruto with blue eyes.&quot;</span> \\
  --seed=1337`,wrap:!1}}),oe=new U({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9QaXBlbGluZUZvclRleHQySW1hZ2UlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwQXV0b1BpcGVsaW5lRm9yVGV4dDJJbWFnZS5mcm9tX3ByZXRyYWluZWQoJTIyc3RhYmxlLWRpZmZ1c2lvbi12MS01JTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2KS50byglMjJjdWRhJTIyKSUwQXBpcGVsaW5lLmxvYWRfbG9yYV93ZWlnaHRzKCUyMnBhdGglMkZ0byUyRmxvcmElMkZtb2RlbCUyMiUyQyUyMHdlaWdodF9uYW1lJTNEJTIycHl0b3JjaF9sb3JhX3dlaWdodHMuc2FmZXRlbnNvcnMlMjIpJTBBaW1hZ2UlMjAlM0QlMjBwaXBlbGluZSglMjJBJTIwbmFydXRvJTIwd2l0aCUyMGJsdWUlMjBleWVzJTIyKS5pbWFnZXMlNUIwJTVE",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoPipelineForText2Image
<span class="hljs-keyword">import</span> torch

pipeline = AutoPipelineForText2Image.from_pretrained(<span class="hljs-string">&quot;stable-diffusion-v1-5/stable-diffusion-v1-5&quot;</span>, torch_dtype=torch.float16).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipeline.load_lora_weights(<span class="hljs-string">&quot;path/to/lora/model&quot;</span>, weight_name=<span class="hljs-string">&quot;pytorch_lora_weights.safetensors&quot;</span>)
image = pipeline(<span class="hljs-string">&quot;A naruto with blue eyes&quot;</span>).images[<span class="hljs-number">0</span>]`,wrap:!1}}),pe=new ye({props:{title:"Next steps",local:"next-steps",headingTag:"h2"}}),me=new Ht({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/training/lora.md"}}),{c(){n=u("meta"),h=i(),s=u("p"),f=i(),d(p.$$.fragment),o=i(),d(w.$$.fragment),C=i(),Z=u("p"),Z.innerHTML=it,Me=i(),d(T.$$.fragment),_e=i(),R=u("p"),R.innerHTML=rt,ge=i(),X=u("p"),X.textContent=ot,$e=i(),d(L.$$.fragment),we=i(),k=u("p"),k.textContent=pt,be=i(),d(W.$$.fragment),Ue=i(),d(J.$$.fragment),Te=i(),I=u("p"),I.textContent=ft,Je=i(),d(G.$$.fragment),xe=i(),E=u("p"),E.textContent=ut,je=i(),d(V.$$.fragment),ve=i(),B=u("p"),B.textContent=mt,Ce=i(),d(A.$$.fragment),Ze=i(),F=u("p"),F.innerHTML=ht,Re=i(),d(x.$$.fragment),Xe=i(),d(N.$$.fragment),Le=i(),H=u("p"),H.innerHTML=ct,ke=i(),Q=u("p"),Q.textContent=dt,We=i(),d(S.$$.fragment),Ie=i(),Y=u("p"),Y.innerHTML=yt,Ge=i(),q=u("ul"),q.innerHTML=Mt,Ee=i(),d(z.$$.fragment),Ve=i(),P=u("p"),P.innerHTML=_t,Be=i(),D=u("p"),D.innerHTML=gt,Ae=i(),d(j.$$.fragment),Fe=i(),O=u("p"),O.innerHTML=$t,Ne=i(),d(K.$$.fragment),He=i(),ee=u("p"),ee.textContent=wt,Qe=i(),d(te.$$.fragment),Se=i(),ae=u("p"),ae.textContent=bt,Ye=i(),le=u("p"),le.innerHTML=Ut,qe=i(),ne=u("ul"),ne.innerHTML=Tt,ze=i(),se=u("p"),se.innerHTML=Jt,Pe=i(),d(v.$$.fragment),De=i(),d(ie.$$.fragment),Oe=i(),re=u("p"),re.textContent=xt,Ke=i(),d(oe.$$.fragment),et=i(),d(pe.$$.fragment),tt=i(),fe=u("p"),fe.textContent=jt,at=i(),ue=u("ul"),ue.innerHTML=vt,lt=i(),d(me.$$.fragment),nt=i(),ce=u("p"),this.h()},l(e){const t=Ft("svelte-u9bgzb",document.head);n=m(t,"META",{name:!0,content:!0}),t.forEach(a),h=r(e),s=m(e,"P",{}),Wt(s).forEach(a),f=r(e),y(p.$$.fragment,e),o=r(e),y(w.$$.fragment,e),C=r(e),Z=m(e,"P",{"data-svelte-h":!0}),c(Z)!=="svelte-175koj4"&&(Z.innerHTML=it),Me=r(e),y(T.$$.fragment,e),_e=r(e),R=m(e,"P",{"data-svelte-h":!0}),c(R)!=="svelte-96n353"&&(R.innerHTML=rt),ge=r(e),X=m(e,"P",{"data-svelte-h":!0}),c(X)!=="svelte-l7dm2q"&&(X.textContent=ot),$e=r(e),y(L.$$.fragment,e),we=r(e),k=m(e,"P",{"data-svelte-h":!0}),c(k)!=="svelte-1nancx8"&&(k.textContent=pt),be=r(e),y(W.$$.fragment,e),Ue=r(e),y(J.$$.fragment,e),Te=r(e),I=m(e,"P",{"data-svelte-h":!0}),c(I)!=="svelte-60q53m"&&(I.textContent=ft),Je=r(e),y(G.$$.fragment,e),xe=r(e),E=m(e,"P",{"data-svelte-h":!0}),c(E)!=="svelte-di6juu"&&(E.textContent=ut),je=r(e),y(V.$$.fragment,e),ve=r(e),B=m(e,"P",{"data-svelte-h":!0}),c(B)!=="svelte-tsz4qp"&&(B.textContent=mt),Ce=r(e),y(A.$$.fragment,e),Ze=r(e),F=m(e,"P",{"data-svelte-h":!0}),c(F)!=="svelte-1fkfdql"&&(F.innerHTML=ht),Re=r(e),y(x.$$.fragment,e),Xe=r(e),y(N.$$.fragment,e),Le=r(e),H=m(e,"P",{"data-svelte-h":!0}),c(H)!=="svelte-iombk1"&&(H.innerHTML=ct),ke=r(e),Q=m(e,"P",{"data-svelte-h":!0}),c(Q)!=="svelte-1tuocui"&&(Q.textContent=dt),We=r(e),y(S.$$.fragment,e),Ie=r(e),Y=m(e,"P",{"data-svelte-h":!0}),c(Y)!=="svelte-91isnp"&&(Y.innerHTML=yt),Ge=r(e),q=m(e,"UL",{"data-svelte-h":!0}),c(q)!=="svelte-1vnjzvi"&&(q.innerHTML=Mt),Ee=r(e),y(z.$$.fragment,e),Ve=r(e),P=m(e,"P",{"data-svelte-h":!0}),c(P)!=="svelte-3k8m7y"&&(P.innerHTML=_t),Be=r(e),D=m(e,"P",{"data-svelte-h":!0}),c(D)!=="svelte-18vf99y"&&(D.innerHTML=gt),Ae=r(e),y(j.$$.fragment,e),Fe=r(e),O=m(e,"P",{"data-svelte-h":!0}),c(O)!=="svelte-tizalo"&&(O.innerHTML=$t),Ne=r(e),y(K.$$.fragment,e),He=r(e),ee=m(e,"P",{"data-svelte-h":!0}),c(ee)!=="svelte-gtrt4e"&&(ee.textContent=wt),Qe=r(e),y(te.$$.fragment,e),Se=r(e),ae=m(e,"P",{"data-svelte-h":!0}),c(ae)!=="svelte-9dei1q"&&(ae.textContent=bt),Ye=r(e),le=m(e,"P",{"data-svelte-h":!0}),c(le)!=="svelte-vqlj4l"&&(le.innerHTML=Ut),qe=r(e),ne=m(e,"UL",{"data-svelte-h":!0}),c(ne)!=="svelte-1qgx1zz"&&(ne.innerHTML=Tt),ze=r(e),se=m(e,"P",{"data-svelte-h":!0}),c(se)!=="svelte-mj0rx7"&&(se.innerHTML=Jt),Pe=r(e),y(v.$$.fragment,e),De=r(e),y(ie.$$.fragment,e),Oe=r(e),re=m(e,"P",{"data-svelte-h":!0}),c(re)!=="svelte-17edgey"&&(re.textContent=xt),Ke=r(e),y(oe.$$.fragment,e),et=r(e),y(pe.$$.fragment,e),tt=r(e),fe=m(e,"P",{"data-svelte-h":!0}),c(fe)!=="svelte-7dh2u5"&&(fe.textContent=jt),at=r(e),ue=m(e,"UL",{"data-svelte-h":!0}),c(ue)!=="svelte-1jpik92"&&(ue.innerHTML=vt),lt=r(e),y(me.$$.fragment,e),nt=r(e),ce=m(e,"P",{}),Wt(ce).forEach(a),this.h()},h(){It(n,"name","hf:doc:metadata"),It(n,"content",ta)},m(e,t){Nt(document.head,n),l(e,h,t),l(e,s,t),l(e,f,t),M(p,e,t),l(e,o,t),M(w,e,t),l(e,C,t),l(e,Z,t),l(e,Me,t),M(T,e,t),l(e,_e,t),l(e,R,t),l(e,ge,t),l(e,X,t),l(e,$e,t),M(L,e,t),l(e,we,t),l(e,k,t),l(e,be,t),M(W,e,t),l(e,Ue,t),M(J,e,t),l(e,Te,t),l(e,I,t),l(e,Je,t),M(G,e,t),l(e,xe,t),l(e,E,t),l(e,je,t),M(V,e,t),l(e,ve,t),l(e,B,t),l(e,Ce,t),M(A,e,t),l(e,Ze,t),l(e,F,t),l(e,Re,t),M(x,e,t),l(e,Xe,t),M(N,e,t),l(e,Le,t),l(e,H,t),l(e,ke,t),l(e,Q,t),l(e,We,t),M(S,e,t),l(e,Ie,t),l(e,Y,t),l(e,Ge,t),l(e,q,t),l(e,Ee,t),M(z,e,t),l(e,Ve,t),l(e,P,t),l(e,Be,t),l(e,D,t),l(e,Ae,t),M(j,e,t),l(e,Fe,t),l(e,O,t),l(e,Ne,t),M(K,e,t),l(e,He,t),l(e,ee,t),l(e,Qe,t),M(te,e,t),l(e,Se,t),l(e,ae,t),l(e,Ye,t),l(e,le,t),l(e,qe,t),l(e,ne,t),l(e,ze,t),l(e,se,t),l(e,Pe,t),M(v,e,t),l(e,De,t),M(ie,e,t),l(e,Oe,t),l(e,re,t),l(e,Ke,t),M(oe,e,t),l(e,et,t),M(pe,e,t),l(e,tt,t),l(e,fe,t),l(e,at,t),l(e,ue,t),l(e,lt,t),M(me,e,t),l(e,nt,t),l(e,ce,t),st=!0},p(e,[t]){const Ct={};t&2&&(Ct.$$scope={dirty:t,ctx:e}),w.$set(Ct);const Zt={};t&2&&(Zt.$$scope={dirty:t,ctx:e}),T.$set(Zt);const Rt={};t&2&&(Rt.$$scope={dirty:t,ctx:e}),J.$set(Rt);const Xt={};t&2&&(Xt.$$scope={dirty:t,ctx:e}),x.$set(Xt);const Lt={};t&2&&(Lt.$$scope={dirty:t,ctx:e}),j.$set(Lt);const kt={};t&2&&(kt.$$scope={dirty:t,ctx:e}),v.$set(kt)},i(e){st||(_(p.$$.fragment,e),_(w.$$.fragment,e),_(T.$$.fragment,e),_(L.$$.fragment,e),_(W.$$.fragment,e),_(J.$$.fragment,e),_(G.$$.fragment,e),_(V.$$.fragment,e),_(A.$$.fragment,e),_(x.$$.fragment,e),_(N.$$.fragment,e),_(S.$$.fragment,e),_(z.$$.fragment,e),_(j.$$.fragment,e),_(K.$$.fragment,e),_(te.$$.fragment,e),_(v.$$.fragment,e),_(ie.$$.fragment,e),_(oe.$$.fragment,e),_(pe.$$.fragment,e),_(me.$$.fragment,e),st=!0)},o(e){g(p.$$.fragment,e),g(w.$$.fragment,e),g(T.$$.fragment,e),g(L.$$.fragment,e),g(W.$$.fragment,e),g(J.$$.fragment,e),g(G.$$.fragment,e),g(V.$$.fragment,e),g(A.$$.fragment,e),g(x.$$.fragment,e),g(N.$$.fragment,e),g(S.$$.fragment,e),g(z.$$.fragment,e),g(j.$$.fragment,e),g(K.$$.fragment,e),g(te.$$.fragment,e),g(v.$$.fragment,e),g(ie.$$.fragment,e),g(oe.$$.fragment,e),g(pe.$$.fragment,e),g(me.$$.fragment,e),st=!1},d(e){e&&(a(h),a(s),a(f),a(o),a(C),a(Z),a(Me),a(_e),a(R),a(ge),a(X),a($e),a(we),a(k),a(be),a(Ue),a(Te),a(I),a(Je),a(xe),a(E),a(je),a(ve),a(B),a(Ce),a(Ze),a(F),a(Re),a(Xe),a(Le),a(H),a(ke),a(Q),a(We),a(Ie),a(Y),a(Ge),a(q),a(Ee),a(Ve),a(P),a(Be),a(D),a(Ae),a(Fe),a(O),a(Ne),a(He),a(ee),a(Qe),a(Se),a(ae),a(Ye),a(le),a(qe),a(ne),a(ze),a(se),a(Pe),a(De),a(Oe),a(re),a(Ke),a(et),a(tt),a(fe),a(at),a(ue),a(lt),a(nt),a(ce)),a(n),$(p,e),$(w,e),$(T,e),$(L,e),$(W,e),$(J,e),$(G,e),$(V,e),$(A,e),$(x,e),$(N,e),$(S,e),$(z,e),$(j,e),$(K,e),$(te,e),$(v,e),$(ie,e),$(oe,e),$(pe,e),$(me,e)}}}const ta='{"title":"LoRA","local":"lora","sections":[{"title":"Script parameters","local":"script-parameters","sections":[],"depth":2},{"title":"Training script","local":"training-script","sections":[],"depth":2},{"title":"Launch the script","local":"launch-the-script","sections":[],"depth":2},{"title":"Next steps","local":"next-steps","sections":[],"depth":2}],"depth":1}';function aa(b){return Vt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class pa extends Bt{constructor(n){super(),At(this,n,aa,ea,Et,{})}}export{pa as component};
