import{s as Vt,o as At,n as x}from"../chunks/scheduler.8c3d61f6.js";import{S as Ft,i as Nt,g as m,s as o,r as d,A as Ht,h as c,f as l,c as p,j as It,u as y,x as h,k as Et,y as Qt,a as s,v as $,d as M,t as _,w as g}from"../chunks/index.da70eac4.js";import{T as de}from"../chunks/Tip.1d9b8c37.js";import{C as U}from"../chunks/CodeBlock.00a903b3.js";import{H as ye,E as Yt}from"../chunks/EditOnGithub.1e64e623.js";import{H as Bt,a as it}from"../chunks/HfOption.6ab18950.js";function St(w){let a,f="This is experimental and the API may change in the future.";return{c(){a=m("p"),a.textContent=f},l(n){a=c(n,"P",{"data-svelte-h":!0}),h(a)!=="svelte-us7smu"&&(a.textContent=f)},m(n,u){s(n,a,u)},p:x,d(n){n&&l(a)}}}function qt(w){let a,f='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(){a=m("p"),a.innerHTML=f},l(n){a=c(n,"P",{"data-svelte-h":!0}),h(a)!=="svelte-1xa3xmb"&&(a.innerHTML=f)},m(n,u){s(n,a,u)},p:x,d(n){n&&l(a)}}}function zt(w){let a,f;return a=new U({props:{code:"Y2QlMjBleGFtcGxlcyUyRnRleHRfdG9faW1hZ2UlMEFwaXAlMjBpbnN0YWxsJTIwLXIlMjByZXF1aXJlbWVudHMudHh0",highlighted:`<span class="hljs-built_in">cd</span> examples/text_to_image
pip install -r requirements.txt`,wrap:!1}}),{c(){d(a.$$.fragment)},l(n){y(a.$$.fragment,n)},m(n,u){$(a,n,u),f=!0},p:x,i(n){f||(M(a.$$.fragment,n),f=!0)},o(n){_(a.$$.fragment,n),f=!1},d(n){g(a,n)}}}function Pt(w){let a,f;return a=new U({props:{code:"Y2QlMjBleGFtcGxlcyUyRnRleHRfdG9faW1hZ2UlMEFwaXAlMjBpbnN0YWxsJTIwLXIlMjByZXF1aXJlbWVudHNfZmxheC50eHQ=",highlighted:`<span class="hljs-built_in">cd</span> examples/text_to_image
pip install -r requirements_flax.txt`,wrap:!1}}),{c(){d(a.$$.fragment)},l(n){y(a.$$.fragment,n)},m(n,u){$(a,n,u),f=!0},p:x,i(n){f||(M(a.$$.fragment,n),f=!0)},o(n){_(a.$$.fragment,n),f=!1},d(n){g(a,n)}}}function Dt(w){let a,f,n,u;return a=new it({props:{id:"installation",option:"PyTorch",$$slots:{default:[zt]},$$scope:{ctx:w}}}),n=new it({props:{id:"installation",option:"Flax",$$slots:{default:[Pt]},$$scope:{ctx:w}}}),{c(){d(a.$$.fragment),f=o(),d(n.$$.fragment)},l(i){y(a.$$.fragment,i),f=p(i),y(n.$$.fragment,i)},m(i,r){$(a,i,r),s(i,f,r),$(n,i,r),u=!0},p(i,r){const b={};r&2&&(b.$$scope={dirty:r,ctx:i}),a.$set(b);const T={};r&2&&(T.$$scope={dirty:r,ctx:i}),n.$set(T)},i(i){u||(M(a.$$.fragment,i),M(n.$$.fragment,i),u=!0)},o(i){_(a.$$.fragment,i),_(n.$$.fragment,i),u=!1},d(i){i&&l(f),g(a,i),g(n,i)}}}function Ot(w){let a,f='🤗 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(){a=m("p"),a.innerHTML=f},l(n){a=c(n,"P",{"data-svelte-h":!0}),h(a)!=="svelte-1qbiqsn"&&(a.innerHTML=f)},m(n,u){s(n,a,u)},p:x,d(n){n&&l(a)}}}function Kt(w){let a,f='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/text_to_image_lora.py" rel="nofollow">script</a> and let us know if you have any questions or concerns.';return{c(){a=m("p"),a.innerHTML=f},l(n){a=c(n,"P",{"data-svelte-h":!0}),h(a)!=="svelte-ckqpc4"&&(a.innerHTML=f)},m(n,u){s(n,a,u)},p:x,d(n){n&&l(a)}}}function ea(w){let a,f='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>.',n,u,i;return u=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(){a=m("p"),a.innerHTML=f,n=o(),d(u.$$.fragment)},l(r){a=c(r,"P",{"data-svelte-h":!0}),h(a)!=="svelte-inmuy9"&&(a.innerHTML=f),n=p(r),y(u.$$.fragment,r)},m(r,b){s(r,a,b),s(r,n,b),$(u,r,b),i=!0},p:x,i(r){i||(M(u.$$.fragment,r),i=!0)},o(r){_(u.$$.fragment,r),i=!1},d(r){r&&(l(a),l(n)),g(u,r)}}}function ta(w){let a,f='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.',n,u,i;return u=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(){a=m("p"),a.innerHTML=f,n=o(),d(u.$$.fragment)},l(r){a=c(r,"P",{"data-svelte-h":!0}),h(a)!=="svelte-11pdijb"&&(a.innerHTML=f),n=p(r),y(u.$$.fragment,r)},m(r,b){s(r,a,b),s(r,n,b),$(u,r,b),i=!0},p:x,i(r){i||(M(u.$$.fragment,r),i=!0)},o(r){_(u.$$.fragment,r),i=!1},d(r){r&&(l(a),l(n)),g(u,r)}}}function aa(w){let a,f,n,u;return a=new it({props:{id:"lora",option:"UNet",$$slots:{default:[ea]},$$scope:{ctx:w}}}),n=new it({props:{id:"lora",option:"text encoder",$$slots:{default:[ta]},$$scope:{ctx:w}}}),{c(){d(a.$$.fragment),f=o(),d(n.$$.fragment)},l(i){y(a.$$.fragment,i),f=p(i),y(n.$$.fragment,i)},m(i,r){$(a,i,r),s(i,f,r),$(n,i,r),u=!0},p(i,r){const b={};r&2&&(b.$$scope={dirty:r,ctx:i}),a.$set(b);const T={};r&2&&(T.$$scope={dirty:r,ctx:i}),n.$set(T)},i(i){u||(M(a.$$.fragment,i),M(n.$$.fragment,i),u=!0)},o(i){_(a.$$.fragment,i),_(n.$$.fragment,i),u=!1},d(i){i&&l(f),g(a,i),g(n,i)}}}function la(w){let a,f="A full training run takes ~5 hours on a 2080 Ti GPU with 11GB of VRAM.";return{c(){a=m("p"),a.textContent=f},l(n){a=c(n,"P",{"data-svelte-h":!0}),h(a)!=="svelte-phs0cw"&&(a.textContent=f)},m(n,u){s(n,a,u)},p:x,d(n){n&&l(a)}}}function na(w){let a,f,n,u,i,r,b,T,X,rt='<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.',$e,J,Me,L,ot='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.',_e,k,pt="Before running the script, make sure you install the library from source:",ge,W,we,G,ft="Navigate to the example folder with the training script and install the required dependencies for the script you’re using:",be,j,Ue,v,Te,I,ut="Initialize an 🤗 Accelerate environment:",xe,E,Je,B,mt="To setup a default 🤗 Accelerate environment without choosing any configurations:",je,V,ve,A,ct="Or if your environment doesn’t support an interactive shell, like a notebook, you can use:",Ce,F,Ze,N,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,C,Xe,H,Le,Q,dt='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,Y,yt="For example, to increase the number of epochs to train:",We,S,Ge,q,$t='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:',Ie,z,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,P,Be,D,_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.',Ve,O,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,Z,Fe,K,wt='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,ee,He,te,bt="Aside from setting up the LoRA layers, the training script is more or less the same as train_text_to_image.py!",Qe,ae,Ye,le,Ut="Once you’ve made all your changes or you’re okay with the default configuration, you’re ready to launch the training script! 🚀",Se,ne,Tt='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,se,xt="<li>saved model checkpoints</li> <li><code>pytorch_lora_weights.safetensors</code> (the trained LoRA weights)</li>",ze,ie,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,R,De,re,Oe,oe,jt="Once training has been completed, you can use your model for inference:",Ke,pe,et,fe,tt,ue,vt="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,me,Ct='<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,ce,nt,he,st;return i=new ye({props:{title:"LoRA",local:"lora",headingTag:"h1"}}),b=new de({props:{warning:!0,$$slots:{default:[St]},$$scope:{ctx:w}}}),J=new de({props:{$$slots:{default:[qt]},$$scope:{ctx:w}}}),W=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}}),j=new Bt({props:{id:"installation",options:["PyTorch","Flax"],$$slots:{default:[Dt]},$$scope:{ctx:w}}}),v=new de({props:{$$slots:{default:[Ot]},$$scope:{ctx:w}}}),E=new U({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),V=new U({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZyUyMGRlZmF1bHQ=",highlighted:"accelerate config default",wrap:!1}}),F=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}}),C=new de({props:{$$slots:{default:[Kt]},$$scope:{ctx:w}}}),H=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}}),P=new ye({props:{title:"Training script",local:"training-script",headingTag:"h2"}}),Z=new Bt({props:{id:"lora",options:["UNet","text encoder"],$$slots:{default:[aa]},$$scope:{ctx:w}}}),ee=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}}),ae=new ye({props:{title:"Launch the script",local:"launch-the-script",headingTag:"h2"}}),R=new de({props:{warning:!0,$$slots:{default:[la]},$$scope:{ctx:w}}}),re=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}}),pe=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}}),fe=new ye({props:{title:"Next steps",local:"next-steps",headingTag:"h2"}}),ce=new Yt({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/training/lora.md"}}),{c(){a=m("meta"),f=o(),n=m("p"),u=o(),d(i.$$.fragment),r=o(),d(b.$$.fragment),T=o(),X=m("p"),X.innerHTML=rt,$e=o(),d(J.$$.fragment),Me=o(),L=m("p"),L.innerHTML=ot,_e=o(),k=m("p"),k.textContent=pt,ge=o(),d(W.$$.fragment),we=o(),G=m("p"),G.textContent=ft,be=o(),d(j.$$.fragment),Ue=o(),d(v.$$.fragment),Te=o(),I=m("p"),I.textContent=ut,xe=o(),d(E.$$.fragment),Je=o(),B=m("p"),B.textContent=mt,je=o(),d(V.$$.fragment),ve=o(),A=m("p"),A.textContent=ct,Ce=o(),d(F.$$.fragment),Ze=o(),N=m("p"),N.innerHTML=ht,Re=o(),d(C.$$.fragment),Xe=o(),d(H.$$.fragment),Le=o(),Q=m("p"),Q.innerHTML=dt,ke=o(),Y=m("p"),Y.textContent=yt,We=o(),d(S.$$.fragment),Ge=o(),q=m("p"),q.innerHTML=$t,Ie=o(),z=m("ul"),z.innerHTML=Mt,Ee=o(),d(P.$$.fragment),Be=o(),D=m("p"),D.innerHTML=_t,Ve=o(),O=m("p"),O.innerHTML=gt,Ae=o(),d(Z.$$.fragment),Fe=o(),K=m("p"),K.innerHTML=wt,Ne=o(),d(ee.$$.fragment),He=o(),te=m("p"),te.textContent=bt,Qe=o(),d(ae.$$.fragment),Ye=o(),le=m("p"),le.textContent=Ut,Se=o(),ne=m("p"),ne.innerHTML=Tt,qe=o(),se=m("ul"),se.innerHTML=xt,ze=o(),ie=m("p"),ie.innerHTML=Jt,Pe=o(),d(R.$$.fragment),De=o(),d(re.$$.fragment),Oe=o(),oe=m("p"),oe.textContent=jt,Ke=o(),d(pe.$$.fragment),et=o(),d(fe.$$.fragment),tt=o(),ue=m("p"),ue.textContent=vt,at=o(),me=m("ul"),me.innerHTML=Ct,lt=o(),d(ce.$$.fragment),nt=o(),he=m("p"),this.h()},l(e){const t=Ht("svelte-u9bgzb",document.head);a=c(t,"META",{name:!0,content:!0}),t.forEach(l),f=p(e),n=c(e,"P",{}),It(n).forEach(l),u=p(e),y(i.$$.fragment,e),r=p(e),y(b.$$.fragment,e),T=p(e),X=c(e,"P",{"data-svelte-h":!0}),h(X)!=="svelte-175koj4"&&(X.innerHTML=rt),$e=p(e),y(J.$$.fragment,e),Me=p(e),L=c(e,"P",{"data-svelte-h":!0}),h(L)!=="svelte-96n353"&&(L.innerHTML=ot),_e=p(e),k=c(e,"P",{"data-svelte-h":!0}),h(k)!=="svelte-l7dm2q"&&(k.textContent=pt),ge=p(e),y(W.$$.fragment,e),we=p(e),G=c(e,"P",{"data-svelte-h":!0}),h(G)!=="svelte-1nancx8"&&(G.textContent=ft),be=p(e),y(j.$$.fragment,e),Ue=p(e),y(v.$$.fragment,e),Te=p(e),I=c(e,"P",{"data-svelte-h":!0}),h(I)!=="svelte-60q53m"&&(I.textContent=ut),xe=p(e),y(E.$$.fragment,e),Je=p(e),B=c(e,"P",{"data-svelte-h":!0}),h(B)!=="svelte-di6juu"&&(B.textContent=mt),je=p(e),y(V.$$.fragment,e),ve=p(e),A=c(e,"P",{"data-svelte-h":!0}),h(A)!=="svelte-tsz4qp"&&(A.textContent=ct),Ce=p(e),y(F.$$.fragment,e),Ze=p(e),N=c(e,"P",{"data-svelte-h":!0}),h(N)!=="svelte-1fkfdql"&&(N.innerHTML=ht),Re=p(e),y(C.$$.fragment,e),Xe=p(e),y(H.$$.fragment,e),Le=p(e),Q=c(e,"P",{"data-svelte-h":!0}),h(Q)!=="svelte-iombk1"&&(Q.innerHTML=dt),ke=p(e),Y=c(e,"P",{"data-svelte-h":!0}),h(Y)!=="svelte-1tuocui"&&(Y.textContent=yt),We=p(e),y(S.$$.fragment,e),Ge=p(e),q=c(e,"P",{"data-svelte-h":!0}),h(q)!=="svelte-91isnp"&&(q.innerHTML=$t),Ie=p(e),z=c(e,"UL",{"data-svelte-h":!0}),h(z)!=="svelte-1vnjzvi"&&(z.innerHTML=Mt),Ee=p(e),y(P.$$.fragment,e),Be=p(e),D=c(e,"P",{"data-svelte-h":!0}),h(D)!=="svelte-3k8m7y"&&(D.innerHTML=_t),Ve=p(e),O=c(e,"P",{"data-svelte-h":!0}),h(O)!=="svelte-18vf99y"&&(O.innerHTML=gt),Ae=p(e),y(Z.$$.fragment,e),Fe=p(e),K=c(e,"P",{"data-svelte-h":!0}),h(K)!=="svelte-tizalo"&&(K.innerHTML=wt),Ne=p(e),y(ee.$$.fragment,e),He=p(e),te=c(e,"P",{"data-svelte-h":!0}),h(te)!=="svelte-gtrt4e"&&(te.textContent=bt),Qe=p(e),y(ae.$$.fragment,e),Ye=p(e),le=c(e,"P",{"data-svelte-h":!0}),h(le)!=="svelte-9dei1q"&&(le.textContent=Ut),Se=p(e),ne=c(e,"P",{"data-svelte-h":!0}),h(ne)!=="svelte-vqlj4l"&&(ne.innerHTML=Tt),qe=p(e),se=c(e,"UL",{"data-svelte-h":!0}),h(se)!=="svelte-1qgx1zz"&&(se.innerHTML=xt),ze=p(e),ie=c(e,"P",{"data-svelte-h":!0}),h(ie)!=="svelte-mj0rx7"&&(ie.innerHTML=Jt),Pe=p(e),y(R.$$.fragment,e),De=p(e),y(re.$$.fragment,e),Oe=p(e),oe=c(e,"P",{"data-svelte-h":!0}),h(oe)!=="svelte-17edgey"&&(oe.textContent=jt),Ke=p(e),y(pe.$$.fragment,e),et=p(e),y(fe.$$.fragment,e),tt=p(e),ue=c(e,"P",{"data-svelte-h":!0}),h(ue)!=="svelte-7dh2u5"&&(ue.textContent=vt),at=p(e),me=c(e,"UL",{"data-svelte-h":!0}),h(me)!=="svelte-1jpik92"&&(me.innerHTML=Ct),lt=p(e),y(ce.$$.fragment,e),nt=p(e),he=c(e,"P",{}),It(he).forEach(l),this.h()},h(){Et(a,"name","hf:doc:metadata"),Et(a,"content",sa)},m(e,t){Qt(document.head,a),s(e,f,t),s(e,n,t),s(e,u,t),$(i,e,t),s(e,r,t),$(b,e,t),s(e,T,t),s(e,X,t),s(e,$e,t),$(J,e,t),s(e,Me,t),s(e,L,t),s(e,_e,t),s(e,k,t),s(e,ge,t),$(W,e,t),s(e,we,t),s(e,G,t),s(e,be,t),$(j,e,t),s(e,Ue,t),$(v,e,t),s(e,Te,t),s(e,I,t),s(e,xe,t),$(E,e,t),s(e,Je,t),s(e,B,t),s(e,je,t),$(V,e,t),s(e,ve,t),s(e,A,t),s(e,Ce,t),$(F,e,t),s(e,Ze,t),s(e,N,t),s(e,Re,t),$(C,e,t),s(e,Xe,t),$(H,e,t),s(e,Le,t),s(e,Q,t),s(e,ke,t),s(e,Y,t),s(e,We,t),$(S,e,t),s(e,Ge,t),s(e,q,t),s(e,Ie,t),s(e,z,t),s(e,Ee,t),$(P,e,t),s(e,Be,t),s(e,D,t),s(e,Ve,t),s(e,O,t),s(e,Ae,t),$(Z,e,t),s(e,Fe,t),s(e,K,t),s(e,Ne,t),$(ee,e,t),s(e,He,t),s(e,te,t),s(e,Qe,t),$(ae,e,t),s(e,Ye,t),s(e,le,t),s(e,Se,t),s(e,ne,t),s(e,qe,t),s(e,se,t),s(e,ze,t),s(e,ie,t),s(e,Pe,t),$(R,e,t),s(e,De,t),$(re,e,t),s(e,Oe,t),s(e,oe,t),s(e,Ke,t),$(pe,e,t),s(e,et,t),$(fe,e,t),s(e,tt,t),s(e,ue,t),s(e,at,t),s(e,me,t),s(e,lt,t),$(ce,e,t),s(e,nt,t),s(e,he,t),st=!0},p(e,[t]){const Zt={};t&2&&(Zt.$$scope={dirty:t,ctx:e}),b.$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}),j.$set(Xt);const Lt={};t&2&&(Lt.$$scope={dirty:t,ctx:e}),v.$set(Lt);const kt={};t&2&&(kt.$$scope={dirty:t,ctx:e}),C.$set(kt);const Wt={};t&2&&(Wt.$$scope={dirty:t,ctx:e}),Z.$set(Wt);const Gt={};t&2&&(Gt.$$scope={dirty:t,ctx:e}),R.$set(Gt)},i(e){st||(M(i.$$.fragment,e),M(b.$$.fragment,e),M(J.$$.fragment,e),M(W.$$.fragment,e),M(j.$$.fragment,e),M(v.$$.fragment,e),M(E.$$.fragment,e),M(V.$$.fragment,e),M(F.$$.fragment,e),M(C.$$.fragment,e),M(H.$$.fragment,e),M(S.$$.fragment,e),M(P.$$.fragment,e),M(Z.$$.fragment,e),M(ee.$$.fragment,e),M(ae.$$.fragment,e),M(R.$$.fragment,e),M(re.$$.fragment,e),M(pe.$$.fragment,e),M(fe.$$.fragment,e),M(ce.$$.fragment,e),st=!0)},o(e){_(i.$$.fragment,e),_(b.$$.fragment,e),_(J.$$.fragment,e),_(W.$$.fragment,e),_(j.$$.fragment,e),_(v.$$.fragment,e),_(E.$$.fragment,e),_(V.$$.fragment,e),_(F.$$.fragment,e),_(C.$$.fragment,e),_(H.$$.fragment,e),_(S.$$.fragment,e),_(P.$$.fragment,e),_(Z.$$.fragment,e),_(ee.$$.fragment,e),_(ae.$$.fragment,e),_(R.$$.fragment,e),_(re.$$.fragment,e),_(pe.$$.fragment,e),_(fe.$$.fragment,e),_(ce.$$.fragment,e),st=!1},d(e){e&&(l(f),l(n),l(u),l(r),l(T),l(X),l($e),l(Me),l(L),l(_e),l(k),l(ge),l(we),l(G),l(be),l(Ue),l(Te),l(I),l(xe),l(Je),l(B),l(je),l(ve),l(A),l(Ce),l(Ze),l(N),l(Re),l(Xe),l(Le),l(Q),l(ke),l(Y),l(We),l(Ge),l(q),l(Ie),l(z),l(Ee),l(Be),l(D),l(Ve),l(O),l(Ae),l(Fe),l(K),l(Ne),l(He),l(te),l(Qe),l(Ye),l(le),l(Se),l(ne),l(qe),l(se),l(ze),l(ie),l(Pe),l(De),l(Oe),l(oe),l(Ke),l(et),l(tt),l(ue),l(at),l(me),l(lt),l(nt),l(he)),l(a),g(i,e),g(b,e),g(J,e),g(W,e),g(j,e),g(v,e),g(E,e),g(V,e),g(F,e),g(C,e),g(H,e),g(S,e),g(P,e),g(Z,e),g(ee,e),g(ae,e),g(R,e),g(re,e),g(pe,e),g(fe,e),g(ce,e)}}}const sa='{"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 ia(w){return At(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ca extends Ft{constructor(a){super(),Nt(this,a,ia,na,Vt,{})}}export{ca as component};
