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