import{s as Ht,o as Vt,n as J}from"../chunks/scheduler.182ea377.js";import{S as At,i as Et,g as u,s as r,r as d,A as Qt,h as c,f as l,c as p,j as Bt,u as $,x as h,k as Wt,y as Nt,a as s,v as y,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 $e,E as St}from"../chunks/EditOnGithub.9b8e78e4.js";import{H as Ft,a as it}from"../chunks/HfOption.fc88c804.js";function Yt(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){$(a.$$.fragment,n)},m(n,m){y(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){$(a.$$.fragment,n)},m(n,m){y(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=r(),d(n.$$.fragment)},l(i){$(a.$$.fragment,i),f=p(i),$(n.$$.fragment,i)},m(i,o){y(a,i,o),s(i,f,o),y(n,i,o),m=!0},p(i,o){const b={};o&2&&(b.$$scope={dirty:o,ctx:i}),a.$set(b);const U={};o&2&&(U.$$scope={dirty:o,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=r(),d(m.$$.fragment)},l(o){a=c(o,"P",{"data-svelte-h":!0}),h(a)!=="svelte-inmuy9"&&(a.innerHTML=f),n=p(o),$(m.$$.fragment,o)},m(o,b){s(o,a,b),s(o,n,b),y(m,o,b),i=!0},p:J,i(o){i||(M(m.$$.fragment,o),i=!0)},o(o){_(m.$$.fragment,o),i=!1},d(o){o&&(l(a),l(n)),g(m,o)}}}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=r(),d(m.$$.fragment)},l(o){a=c(o,"P",{"data-svelte-h":!0}),h(a)!=="svelte-11pdijb"&&(a.innerHTML=f),n=p(o),$(m.$$.fragment,o)},m(o,b){s(o,a,b),s(o,n,b),y(m,o,b),i=!0},p:J,i(o){i||(M(m.$$.fragment,o),i=!0)},o(o){_(m.$$.fragment,o),i=!1},d(o){o&&(l(a),l(n)),g(m,o)}}}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=r(),d(n.$$.fragment)},l(i){$(a.$$.fragment,i),f=p(i),$(n.$$.fragment,i)},m(i,o){y(a,i,o),s(i,f,o),y(n,i,o),m=!0},p(i,o){const b={};o&2&&(b.$$scope={dirty:o,ctx:i}),a.$set(b);const U={};o&2&&(U.$$scope={dirty:o,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,o,b,U,L,ot='<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.',ye,x,Me,X,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.',_e,I,pt="Before running the script, make sure you install the library from source:",ge,k,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,Te,v,Ue,B,mt="Initialize an 🤗 Accelerate environment:",Je,W,xe,F,ut="To setup a default 🤗 Accelerate environment without choosing any configurations:",je,H,ve,V,ct="Or if your environment doesn’t support an interactive shell, like a notebook, you can use:",Ce,A,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,C,Le,Q,Xe,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,S,$t="For example, to increase the number of epochs to train:",ke,Y,Ge,q,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:',Be,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,Fe,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.',He,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.',Ve,R,Ae,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,Se,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! 🚀",Ye,ne,Ut='Let’s train on the <a href="https://huggingface.co/datasets/lambdalabs/pokemon-blip-captions" rel="nofollow">Pokémon BLIP captions</a> dataset to generate our own Pokémon. 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,oe,Oe,re,jt="Once training has been completed, you can use your model for inference:",Ke,pe,et,fe,tt,me,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,ue,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 $e({props:{title:"LoRA",local:"lora",headingTag:"h1"}}),b=new de({props:{warning:!0,$$slots:{default:[Yt]},$$scope:{ctx:w}}}),x=new de({props:{$$slots:{default:[qt]},$$scope:{ctx:w}}}),k=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 Ft({props:{id:"installation",options:["PyTorch","Flax"],$$slots:{default:[Dt]},$$scope:{ctx:w}}}),v=new de({props:{$$slots:{default:[Ot]},$$scope:{ctx:w}}}),W=new T({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),H=new T({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZyUyMGRlZmF1bHQ=",highlighted:"accelerate config default",wrap:!1}}),A=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}}),C=new de({props:{$$slots:{default:[Kt]},$$scope:{ctx:w}}}),Q=new $e({props:{title:"Script parameters",local:"script-parameters",headingTag:"h2"}}),Y=new T({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX3RleHRfdG9faW1hZ2VfbG9yYS5weSUyMCU1QyUwQSUyMCUyMC0tbnVtX3RyYWluX2Vwb2NocyUzRDE1MCUyMCU1Qw==",highlighted:`accelerate launch train_text_to_image_lora.py \\
  --num_train_epochs=150 \\`,wrap:!1}}),P=new $e({props:{title:"Training script",local:"training-script",headingTag:"h2"}}),R=new Ft({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 $e({props:{title:"Launch the script",local:"launch-the-script",headingTag:"h2"}}),Z=new de({props:{warning:!0,$$slots:{default:[la]},$$scope:{ctx:w}}}),oe=new T({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTBBZXhwb3J0JTIwT1VUUFVUX0RJUiUzRCUyMiUyRnNkZGF0YSUyRmZpbmV0dW5lJTJGbG9yYSUyRnBva2Vtb24lMjIlMEFleHBvcnQlMjBIVUJfTU9ERUxfSUQlM0QlMjJwb2tlbW9uLWxvcmElMjIlMEFleHBvcnQlMjBEQVRBU0VUX05BTUUlM0QlMjJsYW1iZGFsYWJzJTJGcG9rZW1vbi1ibGlwLWNhcHRpb25zJTIyJTBBJTBBYWNjZWxlcmF0ZSUyMGxhdW5jaCUyMC0tbWl4ZWRfcHJlY2lzaW9uJTNEJTIyZnAxNiUyMiUyMCUyMHRyYWluX3RleHRfdG9faW1hZ2VfbG9yYS5weSUyMCU1QyUwQSUyMCUyMC0tcHJldHJhaW5lZF9tb2RlbF9uYW1lX29yX3BhdGglM0QlMjRNT0RFTF9OQU1FJTIwJTVDJTBBJTIwJTIwLS1kYXRhc2V0X25hbWUlM0QlMjREQVRBU0VUX05BTUUlMjAlNUMlMEElMjAlMjAtLWRhdGFsb2FkZXJfbnVtX3dvcmtlcnMlM0Q4JTIwJTVDJTBBJTIwJTIwLS1yZXNvbHV0aW9uJTNENTEyJTIwJTVDJTBBJTIwJTIwLS1jZW50ZXJfY3JvcCUyMCU1QyUwQSUyMCUyMC0tcmFuZG9tX2ZsaXAlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxJTIwJTVDJTBBJTIwJTIwLS1ncmFkaWVudF9hY2N1bXVsYXRpb25fc3RlcHMlM0Q0JTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0QxNTAwMCUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDFlLTA0JTIwJTVDJTBBJTIwJTIwLS1tYXhfZ3JhZF9ub3JtJTNEMSUyMCU1QyUwQSUyMCUyMC0tbHJfc2NoZWR1bGVyJTNEJTIyY29zaW5lJTIyJTIwJTVDJTBBJTIwJTIwLS1scl93YXJtdXBfc3RlcHMlM0QwJTIwJTVDJTBBJTIwJTIwLS1vdXRwdXRfZGlyJTNEJTI0JTdCT1VUUFVUX0RJUiU3RCUyMCU1QyUwQSUyMCUyMC0tcHVzaF90b19odWIlMjAlNUMlMEElMjAlMjAtLWh1Yl9tb2RlbF9pZCUzRCUyNCU3QkhVQl9NT0RFTF9JRCU3RCUyMCU1QyUwQSUyMCUyMC0tcmVwb3J0X3RvJTNEd2FuZGIlMjAlNUMlMEElMjAlMjAtLWNoZWNrcG9pbnRpbmdfc3RlcHMlM0Q1MDAlMjAlNUMlMEElMjAlMjAtLXZhbGlkYXRpb25fcHJvbXB0JTNEJTIyQSUyMHBva2Vtb24lMjB3aXRoJTIwYmx1ZSUyMGV5ZXMuJTIyJTIwJTVDJTBBJTIwJTIwLS1zZWVkJTNEMTMzNw==",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>

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`,wrap:!1}}),pe=new T({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9QaXBlbGluZUZvclRleHQySW1hZ2UlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwQXV0b1BpcGVsaW5lRm9yVGV4dDJJbWFnZS5mcm9tX3ByZXRyYWluZWQoJTIycnVud2F5bWwlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYpLnRvKCUyMmN1ZGElMjIpJTBBcGlwZWxpbmUubG9hZF9sb3JhX3dlaWdodHMoJTIycGF0aCUyRnRvJTJGbG9yYSUyRm1vZGVsJTIyJTJDJTIwd2VpZ2h0X25hbWUlM0QlMjJweXRvcmNoX2xvcmFfd2VpZ2h0cy5zYWZldGVuc29ycyUyMiklMEFpbWFnZSUyMCUzRCUyMHBpcGVsaW5lKCUyMkElMjBwb2tlbW9uJTIwd2l0aCUyMGJsdWUlMjBleWVzJTIyKS5pbWFnZXMlNUIwJTVE",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 pokemon with blue eyes&quot;</span>).images[<span class="hljs-number">0</span>]`,wrap:!1}}),fe=new $e({props:{title:"Next steps",local:"next-steps",headingTag:"h2"}}),ce=new St({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/training/lora.md"}}),{c(){a=u("meta"),f=r(),n=u("p"),m=r(),d(i.$$.fragment),o=r(),d(b.$$.fragment),U=r(),L=u("p"),L.innerHTML=ot,ye=r(),d(x.$$.fragment),Me=r(),X=u("p"),X.innerHTML=rt,_e=r(),I=u("p"),I.textContent=pt,ge=r(),d(k.$$.fragment),we=r(),G=u("p"),G.textContent=ft,be=r(),d(j.$$.fragment),Te=r(),d(v.$$.fragment),Ue=r(),B=u("p"),B.textContent=mt,Je=r(),d(W.$$.fragment),xe=r(),F=u("p"),F.textContent=ut,je=r(),d(H.$$.fragment),ve=r(),V=u("p"),V.textContent=ct,Ce=r(),d(A.$$.fragment),Re=r(),E=u("p"),E.innerHTML=ht,Ze=r(),d(C.$$.fragment),Le=r(),d(Q.$$.fragment),Xe=r(),N=u("p"),N.innerHTML=dt,Ie=r(),S=u("p"),S.textContent=$t,ke=r(),d(Y.$$.fragment),Ge=r(),q=u("p"),q.innerHTML=yt,Be=r(),z=u("ul"),z.innerHTML=Mt,We=r(),d(P.$$.fragment),Fe=r(),D=u("p"),D.innerHTML=_t,He=r(),O=u("p"),O.innerHTML=gt,Ve=r(),d(R.$$.fragment),Ae=r(),K=u("p"),K.innerHTML=wt,Ee=r(),d(ee.$$.fragment),Qe=r(),te=u("p"),te.textContent=bt,Ne=r(),d(ae.$$.fragment),Se=r(),le=u("p"),le.textContent=Tt,Ye=r(),ne=u("p"),ne.innerHTML=Ut,qe=r(),se=u("ul"),se.innerHTML=Jt,ze=r(),ie=u("p"),ie.innerHTML=xt,Pe=r(),d(Z.$$.fragment),De=r(),d(oe.$$.fragment),Oe=r(),re=u("p"),re.textContent=jt,Ke=r(),d(pe.$$.fragment),et=r(),d(fe.$$.fragment),tt=r(),me=u("p"),me.textContent=vt,at=r(),ue=u("ul"),ue.innerHTML=Ct,lt=r(),d(ce.$$.fragment),nt=r(),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",{}),Bt(n).forEach(l),m=p(e),$(i.$$.fragment,e),o=p(e),$(b.$$.fragment,e),U=p(e),L=c(e,"P",{"data-svelte-h":!0}),h(L)!=="svelte-175koj4"&&(L.innerHTML=ot),ye=p(e),$(x.$$.fragment,e),Me=p(e),X=c(e,"P",{"data-svelte-h":!0}),h(X)!=="svelte-96n353"&&(X.innerHTML=rt),_e=p(e),I=c(e,"P",{"data-svelte-h":!0}),h(I)!=="svelte-l7dm2q"&&(I.textContent=pt),ge=p(e),$(k.$$.fragment,e),we=p(e),G=c(e,"P",{"data-svelte-h":!0}),h(G)!=="svelte-1nancx8"&&(G.textContent=ft),be=p(e),$(j.$$.fragment,e),Te=p(e),$(v.$$.fragment,e),Ue=p(e),B=c(e,"P",{"data-svelte-h":!0}),h(B)!=="svelte-60q53m"&&(B.textContent=mt),Je=p(e),$(W.$$.fragment,e),xe=p(e),F=c(e,"P",{"data-svelte-h":!0}),h(F)!=="svelte-di6juu"&&(F.textContent=ut),je=p(e),$(H.$$.fragment,e),ve=p(e),V=c(e,"P",{"data-svelte-h":!0}),h(V)!=="svelte-tsz4qp"&&(V.textContent=ct),Ce=p(e),$(A.$$.fragment,e),Re=p(e),E=c(e,"P",{"data-svelte-h":!0}),h(E)!=="svelte-1fkfdql"&&(E.innerHTML=ht),Ze=p(e),$(C.$$.fragment,e),Le=p(e),$(Q.$$.fragment,e),Xe=p(e),N=c(e,"P",{"data-svelte-h":!0}),h(N)!=="svelte-iombk1"&&(N.innerHTML=dt),Ie=p(e),S=c(e,"P",{"data-svelte-h":!0}),h(S)!=="svelte-1tuocui"&&(S.textContent=$t),ke=p(e),$(Y.$$.fragment,e),Ge=p(e),q=c(e,"P",{"data-svelte-h":!0}),h(q)!=="svelte-91isnp"&&(q.innerHTML=yt),Be=p(e),z=c(e,"UL",{"data-svelte-h":!0}),h(z)!=="svelte-1vnjzvi"&&(z.innerHTML=Mt),We=p(e),$(P.$$.fragment,e),Fe=p(e),D=c(e,"P",{"data-svelte-h":!0}),h(D)!=="svelte-3k8m7y"&&(D.innerHTML=_t),He=p(e),O=c(e,"P",{"data-svelte-h":!0}),h(O)!=="svelte-18vf99y"&&(O.innerHTML=gt),Ve=p(e),$(R.$$.fragment,e),Ae=p(e),K=c(e,"P",{"data-svelte-h":!0}),h(K)!=="svelte-tizalo"&&(K.innerHTML=wt),Ee=p(e),$(ee.$$.fragment,e),Qe=p(e),te=c(e,"P",{"data-svelte-h":!0}),h(te)!=="svelte-gtrt4e"&&(te.textContent=bt),Ne=p(e),$(ae.$$.fragment,e),Se=p(e),le=c(e,"P",{"data-svelte-h":!0}),h(le)!=="svelte-9dei1q"&&(le.textContent=Tt),Ye=p(e),ne=c(e,"P",{"data-svelte-h":!0}),h(ne)!=="svelte-rb8mku"&&(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),$(Z.$$.fragment,e),De=p(e),$(oe.$$.fragment,e),Oe=p(e),re=c(e,"P",{"data-svelte-h":!0}),h(re)!=="svelte-17edgey"&&(re.textContent=jt),Ke=p(e),$(pe.$$.fragment,e),et=p(e),$(fe.$$.fragment,e),tt=p(e),me=c(e,"P",{"data-svelte-h":!0}),h(me)!=="svelte-7dh2u5"&&(me.textContent=vt),at=p(e),ue=c(e,"UL",{"data-svelte-h":!0}),h(ue)!=="svelte-1jpik92"&&(ue.innerHTML=Ct),lt=p(e),$(ce.$$.fragment,e),nt=p(e),he=c(e,"P",{}),Bt(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),y(i,e,t),s(e,o,t),y(b,e,t),s(e,U,t),s(e,L,t),s(e,ye,t),y(x,e,t),s(e,Me,t),s(e,X,t),s(e,_e,t),s(e,I,t),s(e,ge,t),y(k,e,t),s(e,we,t),s(e,G,t),s(e,be,t),y(j,e,t),s(e,Te,t),y(v,e,t),s(e,Ue,t),s(e,B,t),s(e,Je,t),y(W,e,t),s(e,xe,t),s(e,F,t),s(e,je,t),y(H,e,t),s(e,ve,t),s(e,V,t),s(e,Ce,t),y(A,e,t),s(e,Re,t),s(e,E,t),s(e,Ze,t),y(C,e,t),s(e,Le,t),y(Q,e,t),s(e,Xe,t),s(e,N,t),s(e,Ie,t),s(e,S,t),s(e,ke,t),y(Y,e,t),s(e,Ge,t),s(e,q,t),s(e,Be,t),s(e,z,t),s(e,We,t),y(P,e,t),s(e,Fe,t),s(e,D,t),s(e,He,t),s(e,O,t),s(e,Ve,t),y(R,e,t),s(e,Ae,t),s(e,K,t),s(e,Ee,t),y(ee,e,t),s(e,Qe,t),s(e,te,t),s(e,Ne,t),y(ae,e,t),s(e,Se,t),s(e,le,t),s(e,Ye,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),y(Z,e,t),s(e,De,t),y(oe,e,t),s(e,Oe,t),s(e,re,t),s(e,Ke,t),y(pe,e,t),s(e,et,t),y(fe,e,t),s(e,tt,t),s(e,me,t),s(e,at,t),s(e,ue,t),s(e,lt,t),y(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 Lt={};t&2&&(Lt.$$scope={dirty:t,ctx:e}),j.$set(Lt);const Xt={};t&2&&(Xt.$$scope={dirty:t,ctx:e}),v.$set(Xt);const It={};t&2&&(It.$$scope={dirty:t,ctx:e}),C.$set(It);const kt={};t&2&&(kt.$$scope={dirty:t,ctx:e}),R.$set(kt);const Gt={};t&2&&(Gt.$$scope={dirty:t,ctx:e}),Z.$set(Gt)},i(e){st||(M(i.$$.fragment,e),M(b.$$.fragment,e),M(x.$$.fragment,e),M(k.$$.fragment,e),M(j.$$.fragment,e),M(v.$$.fragment,e),M(W.$$.fragment,e),M(H.$$.fragment,e),M(A.$$.fragment,e),M(C.$$.fragment,e),M(Q.$$.fragment,e),M(Y.$$.fragment,e),M(P.$$.fragment,e),M(R.$$.fragment,e),M(ee.$$.fragment,e),M(ae.$$.fragment,e),M(Z.$$.fragment,e),M(oe.$$.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),_(k.$$.fragment,e),_(j.$$.fragment,e),_(v.$$.fragment,e),_(W.$$.fragment,e),_(H.$$.fragment,e),_(A.$$.fragment,e),_(C.$$.fragment,e),_(Q.$$.fragment,e),_(Y.$$.fragment,e),_(P.$$.fragment,e),_(R.$$.fragment,e),_(ee.$$.fragment,e),_(ae.$$.fragment,e),_(Z.$$.fragment,e),_(oe.$$.fragment,e),_(pe.$$.fragment,e),_(fe.$$.fragment,e),_(ce.$$.fragment,e),st=!1},d(e){e&&(l(f),l(n),l(m),l(o),l(U),l(L),l(ye),l(Me),l(X),l(_e),l(I),l(ge),l(we),l(G),l(be),l(Te),l(Ue),l(B),l(Je),l(xe),l(F),l(je),l(ve),l(V),l(Ce),l(Re),l(E),l(Ze),l(Le),l(Xe),l(N),l(Ie),l(S),l(ke),l(Ge),l(q),l(Be),l(z),l(We),l(Fe),l(D),l(He),l(O),l(Ve),l(Ae),l(K),l(Ee),l(Qe),l(te),l(Ne),l(Se),l(le),l(Ye),l(ne),l(qe),l(se),l(ze),l(ie),l(Pe),l(De),l(Oe),l(re),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(k,e),g(j,e),g(v,e),g(W,e),g(H,e),g(A,e),g(C,e),g(Q,e),g(Y,e),g(P,e),g(R,e),g(ee,e),g(ae,e),g(Z,e),g(oe,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 Vt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ca extends At{constructor(a){super(),Et(this,a,ia,na,Ht,{})}}export{ca as component};
