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