import{s as Ie,o as Ne,n as J}from"../chunks/scheduler.5c93273d.js";import{S as Qe,i as He,g as u,s as o,r as _,A as Ae,h as M,f as a,c as f,j as Le,u as c,x as $,k as Ee,y as Se,a as n,v as y,d as U,t as d,w as h}from"../chunks/index.e43dd92b.js";import{T as _t}from"../chunks/Tip.3538f9e3.js";import{C as w}from"../chunks/CodeBlock.6896320e.js";import{H as ct,E as ke}from"../chunks/getInferenceSnippets.7a494bf3.js";import{H as Be,a as ie}from"../chunks/HfOption.d50154c3.js";function Ye(b){let l,r="当前功能处于实验阶段，API可能在未来版本中变更。";return{c(){l=u("p"),l.textContent=r},l(s){l=M(s,"P",{"data-svelte-h":!0}),$(l)!=="svelte-df0fl5"&&(l.textContent=r)},m(s,m){n(s,l,m)},p:J,d(s){s&&a(l)}}}function ze(b){let l,r='LoRA具有高度通用性，目前已支持以下应用场景：<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">文生图</a>以及<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=r},l(s){l=M(s,"P",{"data-svelte-h":!0}),$(l)!=="svelte-1gs7fzn"&&(l.innerHTML=r)},m(s,m){n(s,l,m)},p:J,d(s){s&&a(l)}}}function qe(b){let l,r;return l=new w({props:{code:"Y2QlMjBleGFtcGxlcyUyRnRleHRfdG9faW1hZ2UlMEFwaXAlMjBpbnN0YWxsJTIwLXIlMjByZXF1aXJlbWVudHMudHh0",highlighted:`<span class="hljs-built_in">cd</span> examples/text_to_image
pip install -r requirements.txt`,wrap:!1}}),{c(){_(l.$$.fragment)},l(s){c(l.$$.fragment,s)},m(s,m){y(l,s,m),r=!0},p:J,i(s){r||(U(l.$$.fragment,s),r=!0)},o(s){d(l.$$.fragment,s),r=!1},d(s){h(l,s)}}}function Pe(b){let l,r;return l=new w({props:{code:"Y2QlMjBleGFtcGxlcyUyRnRleHRfdG9faW1hZ2UlMEFwaXAlMjBpbnN0YWxsJTIwLXIlMjByZXF1aXJlbWVudHNfZmxheC50eHQ=",highlighted:`<span class="hljs-built_in">cd</span> examples/text_to_image
pip install -r requirements_flax.txt`,wrap:!1}}),{c(){_(l.$$.fragment)},l(s){c(l.$$.fragment,s)},m(s,m){y(l,s,m),r=!0},p:J,i(s){r||(U(l.$$.fragment,s),r=!0)},o(s){d(l.$$.fragment,s),r=!1},d(s){h(l,s)}}}function De(b){let l,r,s,m;return l=new ie({props:{id:"installation",option:"PyTorch",$$slots:{default:[qe]},$$scope:{ctx:b}}}),s=new ie({props:{id:"installation",option:"Flax",$$slots:{default:[Pe]},$$scope:{ctx:b}}}),{c(){_(l.$$.fragment),r=o(),_(s.$$.fragment)},l(i){c(l.$$.fragment,i),r=f(i),c(s.$$.fragment,i)},m(i,p){y(l,i,p),n(i,r,p),y(s,i,p),m=!0},p(i,p){const g={};p&2&&(g.$$scope={dirty:p,ctx:i}),l.$set(g);const T={};p&2&&(T.$$scope={dirty:p,ctx:i}),s.$set(T)},i(i){m||(U(l.$$.fragment,i),U(s.$$.fragment,i),m=!0)},o(i){d(l.$$.fragment,i),d(s.$$.fragment,i),m=!1},d(i){i&&a(r),h(l,i),h(s,i)}}}function Oe(b){let l,r='🤗 Accelerate是一个支持多GPU/TPU训练和混合精度计算的库，它能根据硬件环境自动配置训练方案。参阅🤗 Accelerate<a href="https://huggingface.co/docs/accelerate/quicktour" rel="nofollow">快速入门</a>了解更多。';return{c(){l=u("p"),l.innerHTML=r},l(s){l=M(s,"P",{"data-svelte-h":!0}),$(l)!=="svelte-1nngx2f"&&(l.innerHTML=r)},m(s,m){n(s,l,m)},p:J,d(s){s&&a(l)}}}function Ke(b){let l,r='以下章节重点解析训练脚本中与LoRA相关的核心部分，但不会涵盖所有实现细节。如需完整理解，建议直接阅读<a href="https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_lora.py" rel="nofollow">脚本源码</a>，如有疑问欢迎反馈。';return{c(){l=u("p"),l.innerHTML=r},l(s){l=M(s,"P",{"data-svelte-h":!0}),$(l)!=="svelte-1vxz2rj"&&(l.innerHTML=r)},m(s,m){n(s,l,m)},p:J,d(s){s&&a(l)}}}function tl(b){let l,r='Diffusers使用<a href="https://hf.co/docs/peft" rel="nofollow">PEFT</a>库的<code>~peft.LoraConfig</code>配置LoRA适配器参数，包括秩(rank)、alpha值以及目标模块。适配器被注入UNet后，通过<code>lora_layers</code>筛选出需要优化的LoRA层。',s,m,i;return m=new w({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=r,s=o(),_(m.$$.fragment)},l(p){l=M(p,"P",{"data-svelte-h":!0}),$(l)!=="svelte-v6q2xr"&&(l.innerHTML=r),s=f(p),c(m.$$.fragment,p)},m(p,g){n(p,l,g),n(p,s,g),y(m,p,g),i=!0},p:J,i(p){i||(U(m.$$.fragment,p),i=!0)},o(p){d(m.$$.fragment,p),i=!1},d(p){p&&(a(l),a(s)),h(m,p)}}}function el(b){let l,r='当需要微调文本编码器时（如SDXL模型），Diffusers同样支持通过<a href="https://hf.co/docs/peft" rel="nofollow">PEFT</a>库实现。<code>~peft.LoraConfig</code>配置适配器参数后注入文本编码器，并筛选LoRA层进行训练。',s,m,i;return m=new w({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=r,s=o(),_(m.$$.fragment)},l(p){l=M(p,"P",{"data-svelte-h":!0}),$(l)!=="svelte-19icm4i"&&(l.innerHTML=r),s=f(p),c(m.$$.fragment,p)},m(p,g){n(p,l,g),n(p,s,g),y(m,p,g),i=!0},p:J,i(p){i||(U(m.$$.fragment,p),i=!0)},o(p){d(m.$$.fragment,p),i=!1},d(p){p&&(a(l),a(s)),h(m,p)}}}function ll(b){let l,r,s,m;return l=new ie({props:{id:"lora",option:"UNet",$$slots:{default:[tl]},$$scope:{ctx:b}}}),s=new ie({props:{id:"lora",option:"text encoder",$$slots:{default:[el]},$$scope:{ctx:b}}}),{c(){_(l.$$.fragment),r=o(),_(s.$$.fragment)},l(i){c(l.$$.fragment,i),r=f(i),c(s.$$.fragment,i)},m(i,p){y(l,i,p),n(i,r,p),y(s,i,p),m=!0},p(i,p){const g={};p&2&&(g.$$scope={dirty:p,ctx:i}),l.$set(g);const T={};p&2&&(T.$$scope={dirty:p,ctx:i}),s.$set(T)},i(i){m||(U(l.$$.fragment,i),U(s.$$.fragment,i),m=!0)},o(i){d(l.$$.fragment,i),d(s.$$.fragment,i),m=!1},d(i){i&&a(r),h(l,i),h(s,i)}}}function al(b){let l,r="在11GB显存的2080 Ti显卡上完整训练约需5小时。";return{c(){l=u("p"),l.textContent=r},l(s){l=M(s,"P",{"data-svelte-h":!0}),$(l)!=="svelte-uzw905"&&(l.textContent=r)},m(s,m){n(s,l,m)},p:J,d(s){s&&a(l)}}}function sl(b){let l,r,s,m,i,p,g,T,v,pe='<a href="https://hf.co/papers/2106.09685" rel="nofollow">LoRA（大语言模型的低秩适配）</a> 是一种轻量级训练技术，能显著减少可训练参数量。其原理是通过向模型注入少量新权重参数，仅训练这些新增参数。这使得LoRA训练速度更快、内存效率更高，并生成更小的模型权重文件（通常仅数百MB），便于存储和分享。LoRA还可与DreamBooth等其他训练技术结合以加速训练过程。',yt,x,Ut,V,oe='本指南将通过解析<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>脚本，帮助您深入理解其工作原理，并掌握如何针对具体需求进行定制化修改。',dt,W,fe="运行脚本前，请确保从源码安装库：",ht,F,bt,G,re="进入包含训练脚本的示例目录，并安装所需依赖：",gt,C,wt,j,Tt,L,me="初始化🤗 Accelerate环境：",Jt,E,xt,B,ue="若要创建默认配置环境（不进行交互式设置）：",Ct,I,jt,N,Me="若在非交互环境（如Jupyter notebook）中使用：",Zt,Q,Rt,H,$e='如需训练自定义数据集，请参考<a href="create_dataset">创建训练数据集指南</a>了解数据准备流程。',Xt,Z,vt,A,Vt,S,_e='训练脚本提供众多参数用于定制训练过程。所有参数及其说明均定义在<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>函数中。多数参数设有默认值，您也可以通过命令行参数覆盖：',Wt,k,ce="例如增加训练轮次：",Ft,Y,Gt,z,ye='基础参数说明可参考<a href="text2image#script-parameters">文生图训练指南</a>，此处重点介绍LoRA相关参数：',Lt,q,Ue="<li><code>--rank</code>：低秩矩阵的内部维度，数值越高可训练参数越多</li> <li><code>--learning_rate</code>：默认学习率为1e-4，但使用LoRA时可适当提高</li>",Et,P,Bt,D,de='数据集预处理和训练循环逻辑位于<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>函数，如需定制训练流程，可在此处进行修改。',It,O,he='与参数说明类似，训练流程的完整解析请参考<a href="text2image#training-script">文生图指南</a>，下文重点介绍LoRA相关实现。',Nt,R,Qt,K,be='<a href="https://github.com/huggingface/diffusers/blob/e4b8f173b97731686e290b2eb98e7f5df2b1b322/examples/text_to_image/train_text_to_image_lora.py#L529" rel="nofollow">优化器</a>仅对<code>lora_layers</code>参数进行优化：',Ht,tt,At,et,ge="除LoRA层设置外，该训练脚本与标准train_text_to_image.py基本相同！",St,lt,kt,at,we="完成所有配置后，即可启动训练脚本！🚀",Yt,st,Te='以下示例使用<a href="https://huggingface.co/datasets/lambdalabs/naruto-blip-captions" rel="nofollow">Naruto BLIP captions</a>训练生成火影角色。请设置环境变量<code>MODEL_NAME</code>和<code>DATASET_NAME</code>指定基础模型和数据集，<code>OUTPUT_DIR</code>设置输出目录，<code>HUB_MODEL_ID</code>指定Hub存储库名称。脚本运行后将生成以下文件：',zt,nt,Je="<li>模型检查点</li> <li><code>pytorch_lora_weights.safetensors</code>（训练好的LoRA权重）</li>",qt,it,xe="多GPU训练请添加<code>--multi_gpu</code>参数。",Pt,X,Dt,pt,Ot,ot,Ce="训练完成后，您可以通过以下方式进行推理：",Kt,ft,te,rt,ee,mt,je="恭喜完成LoRA模型训练！如需进一步了解模型使用方法，可参考以下指南：",le,ut,Ze='<li>学习如何加载<a href="../using-diffusers/loading_adapters#LoRA">不同格式的LoRA权重</a>（如Kohya或TheLastBen训练的模型）</li> <li>掌握使用PEFT进行<a href="../tutorials/using_peft_for_inference">多LoRA组合推理</a>的技巧</li>',ae,Mt,se,$t,ne;return i=new ct({props:{title:"LoRA 低秩适配",local:"lora-低秩适配",headingTag:"h1"}}),g=new _t({props:{warning:!0,$$slots:{default:[Ye]},$$scope:{ctx:b}}}),x=new _t({props:{$$slots:{default:[ze]},$$scope:{ctx:b}}}),F=new w({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}}),C=new Be({props:{id:"installation",options:["PyTorch","Flax"],$$slots:{default:[De]},$$scope:{ctx:b}}}),j=new _t({props:{$$slots:{default:[Oe]},$$scope:{ctx:b}}}),E=new w({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),I=new w({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZyUyMGRlZmF1bHQ=",highlighted:"accelerate config default",wrap:!1}}),Q=new w({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}}),Z=new _t({props:{$$slots:{default:[Ke]},$$scope:{ctx:b}}}),A=new ct({props:{title:"脚本参数",local:"脚本参数",headingTag:"h2"}}),Y=new w({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX3RleHRfdG9faW1hZ2VfbG9yYS5weSUyMCU1QyUwQSUyMCUyMC0tbnVtX3RyYWluX2Vwb2NocyUzRDE1MCUyMCU1Qw==",highlighted:`accelerate launch train_text_to_image_lora.py \\
  --num_train_epochs=150 \\`,wrap:!1}}),P=new ct({props:{title:"训练脚本实现",local:"训练脚本实现",headingTag:"h2"}}),R=new Be({props:{id:"lora",options:["UNet","text encoder"],$$slots:{default:[ll]},$$scope:{ctx:b}}}),tt=new w({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}}),lt=new ct({props:{title:"启动训练",local:"启动训练",headingTag:"h2"}}),X=new _t({props:{warning:!0,$$slots:{default:[al]},$$scope:{ctx:b}}}),pt=new w({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUwQWV4cG9ydCUyME9VVFBVVF9ESVIlM0QlMjIlMkZzZGRhdGElMkZmaW5ldHVuZSUyRmxvcmElMkZuYXJ1dG8lMjIlMEFleHBvcnQlMjBIVUJfTU9ERUxfSUQlM0QlMjJuYXJ1dG8tbG9yYSUyMiUwQWV4cG9ydCUyMERBVEFTRVRfTkFNRSUzRCUyMmxhbWJkYWxhYnMlMkZuYXJ1dG8tYmxpcC1jYXB0aW9ucyUyMiUwQSUwQWFjY2VsZXJhdGUlMjBsYXVuY2glMjAtLW1peGVkX3ByZWNpc2lvbiUzRCUyMmZwMTYlMjIlMjAlMjB0cmFpbl90ZXh0X3RvX2ltYWdlX2xvcmEucHklMjAlNUMlMEElMjAlMjAtLXByZXRyYWluZWRfbW9kZWxfbmFtZV9vcl9wYXRoJTNEJTI0TU9ERUxfTkFNRSUyMCU1QyUwQSUyMCUyMC0tZGF0YXNldF9uYW1lJTNEJTI0REFUQVNFVF9OQU1FJTIwJTVDJTBBJTIwJTIwLS1kYXRhbG9hZGVyX251bV93b3JrZXJzJTNEOCUyMCU1QyUwQSUyMCUyMC0tcmVzb2x1dGlvbiUzRDUxMiUyMCU1QyUwQSUyMCUyMC0tY2VudGVyX2Nyb3AlMjAlNUMlMEElMjAlMjAtLXJhbmRvbV9mbGlwJTIwJTVDJTBBJTIwJTIwLS10cmFpbl9iYXRjaF9zaXplJTNEMSUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNENCUyMCU1QyUwQSUyMCUyMC0tbWF4X3RyYWluX3N0ZXBzJTNEMTUwMDAlMjAlNUMlMEElMjAlMjAtLWxlYXJuaW5nX3JhdGUlM0QxZS0wNCUyMCU1QyUwQSUyMCUyMC0tbWF4X2dyYWRfbm9ybSUzRDElMjAlNUMlMEElMjAlMjAtLWxyX3NjaGVkdWxlciUzRCUyMmNvc2luZSUyMiUyMCU1QyUwQSUyMCUyMC0tbHJfd2FybXVwX3N0ZXBzJTNEMCUyMCU1QyUwQSUyMCUyMC0tb3V0cHV0X2RpciUzRCUyNCU3Qk9VVFBVVF9ESVIlN0QlMjAlNUMlMEElMjAlMjAtLXB1c2hfdG9faHViJTIwJTVDJTBBJTIwJTIwLS1odWJfbW9kZWxfaWQlM0QlMjQlN0JIVUJfTU9ERUxfSUQlN0QlMjAlNUMlMEElMjAlMjAtLXJlcG9ydF90byUzRHdhbmRiJTIwJTVDJTBBJTIwJTIwLS1jaGVja3BvaW50aW5nX3N0ZXBzJTNENTAwJTIwJTVDJTBBJTIwJTIwLS12YWxpZGF0aW9uX3Byb21wdCUzRCUyMiVFOCU5MyU5RCVFOCU4OSVCMiVFNyU5QyVCQyVFNyU5RCU5QiVFNyU5QSU4NCVFNyU4MSVBQiVFNSVCRCVCMSVFNSVCRiU4RCVFOCU4MCU4NSVFOCVBNyU5MiVFOCU4OSVCMiUyMiUyMCU1QyUwQSUyMCUyMC0tc2VlZCUzRDEzMzc=",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;蓝色眼睛的火影忍者角色&quot;</span> \\
  --seed=1337`,wrap:!1}}),ft=new w({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}}),rt=new ct({props:{title:"后续步骤",local:"后续步骤",headingTag:"h2"}}),Mt=new ke({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/zh/training/lora.md"}}),{c(){l=u("meta"),r=o(),s=u("p"),m=o(),_(i.$$.fragment),p=o(),_(g.$$.fragment),T=o(),v=u("p"),v.innerHTML=pe,yt=o(),_(x.$$.fragment),Ut=o(),V=u("p"),V.innerHTML=oe,dt=o(),W=u("p"),W.textContent=fe,ht=o(),_(F.$$.fragment),bt=o(),G=u("p"),G.textContent=re,gt=o(),_(C.$$.fragment),wt=o(),_(j.$$.fragment),Tt=o(),L=u("p"),L.textContent=me,Jt=o(),_(E.$$.fragment),xt=o(),B=u("p"),B.textContent=ue,Ct=o(),_(I.$$.fragment),jt=o(),N=u("p"),N.textContent=Me,Zt=o(),_(Q.$$.fragment),Rt=o(),H=u("p"),H.innerHTML=$e,Xt=o(),_(Z.$$.fragment),vt=o(),_(A.$$.fragment),Vt=o(),S=u("p"),S.innerHTML=_e,Wt=o(),k=u("p"),k.textContent=ce,Ft=o(),_(Y.$$.fragment),Gt=o(),z=u("p"),z.innerHTML=ye,Lt=o(),q=u("ul"),q.innerHTML=Ue,Et=o(),_(P.$$.fragment),Bt=o(),D=u("p"),D.innerHTML=de,It=o(),O=u("p"),O.innerHTML=he,Nt=o(),_(R.$$.fragment),Qt=o(),K=u("p"),K.innerHTML=be,Ht=o(),_(tt.$$.fragment),At=o(),et=u("p"),et.textContent=ge,St=o(),_(lt.$$.fragment),kt=o(),at=u("p"),at.textContent=we,Yt=o(),st=u("p"),st.innerHTML=Te,zt=o(),nt=u("ul"),nt.innerHTML=Je,qt=o(),it=u("p"),it.innerHTML=xe,Pt=o(),_(X.$$.fragment),Dt=o(),_(pt.$$.fragment),Ot=o(),ot=u("p"),ot.textContent=Ce,Kt=o(),_(ft.$$.fragment),te=o(),_(rt.$$.fragment),ee=o(),mt=u("p"),mt.textContent=je,le=o(),ut=u("ul"),ut.innerHTML=Ze,ae=o(),_(Mt.$$.fragment),se=o(),$t=u("p"),this.h()},l(t){const e=Ae("svelte-u9bgzb",document.head);l=M(e,"META",{name:!0,content:!0}),e.forEach(a),r=f(t),s=M(t,"P",{}),Le(s).forEach(a),m=f(t),c(i.$$.fragment,t),p=f(t),c(g.$$.fragment,t),T=f(t),v=M(t,"P",{"data-svelte-h":!0}),$(v)!=="svelte-13ej9e2"&&(v.innerHTML=pe),yt=f(t),c(x.$$.fragment,t),Ut=f(t),V=M(t,"P",{"data-svelte-h":!0}),$(V)!=="svelte-dgwi9"&&(V.innerHTML=oe),dt=f(t),W=M(t,"P",{"data-svelte-h":!0}),$(W)!=="svelte-1l0wcm7"&&(W.textContent=fe),ht=f(t),c(F.$$.fragment,t),bt=f(t),G=M(t,"P",{"data-svelte-h":!0}),$(G)!=="svelte-1por4m9"&&(G.textContent=re),gt=f(t),c(C.$$.fragment,t),wt=f(t),c(j.$$.fragment,t),Tt=f(t),L=M(t,"P",{"data-svelte-h":!0}),$(L)!=="svelte-cfitki"&&(L.textContent=me),Jt=f(t),c(E.$$.fragment,t),xt=f(t),B=M(t,"P",{"data-svelte-h":!0}),$(B)!=="svelte-hx4kz2"&&(B.textContent=ue),Ct=f(t),c(I.$$.fragment,t),jt=f(t),N=M(t,"P",{"data-svelte-h":!0}),$(N)!=="svelte-9bzu46"&&(N.textContent=Me),Zt=f(t),c(Q.$$.fragment,t),Rt=f(t),H=M(t,"P",{"data-svelte-h":!0}),$(H)!=="svelte-i8b5ke"&&(H.innerHTML=$e),Xt=f(t),c(Z.$$.fragment,t),vt=f(t),c(A.$$.fragment,t),Vt=f(t),S=M(t,"P",{"data-svelte-h":!0}),$(S)!=="svelte-sf7iv3"&&(S.innerHTML=_e),Wt=f(t),k=M(t,"P",{"data-svelte-h":!0}),$(k)!=="svelte-ty40j0"&&(k.textContent=ce),Ft=f(t),c(Y.$$.fragment,t),Gt=f(t),z=M(t,"P",{"data-svelte-h":!0}),$(z)!=="svelte-beuy7"&&(z.innerHTML=ye),Lt=f(t),q=M(t,"UL",{"data-svelte-h":!0}),$(q)!=="svelte-11dhbz1"&&(q.innerHTML=Ue),Et=f(t),c(P.$$.fragment,t),Bt=f(t),D=M(t,"P",{"data-svelte-h":!0}),$(D)!=="svelte-17b7hli"&&(D.innerHTML=de),It=f(t),O=M(t,"P",{"data-svelte-h":!0}),$(O)!=="svelte-yu3j2z"&&(O.innerHTML=he),Nt=f(t),c(R.$$.fragment,t),Qt=f(t),K=M(t,"P",{"data-svelte-h":!0}),$(K)!=="svelte-monf0n"&&(K.innerHTML=be),Ht=f(t),c(tt.$$.fragment,t),At=f(t),et=M(t,"P",{"data-svelte-h":!0}),$(et)!=="svelte-3rp6cs"&&(et.textContent=ge),St=f(t),c(lt.$$.fragment,t),kt=f(t),at=M(t,"P",{"data-svelte-h":!0}),$(at)!=="svelte-mxmxgt"&&(at.textContent=we),Yt=f(t),st=M(t,"P",{"data-svelte-h":!0}),$(st)!=="svelte-x76otw"&&(st.innerHTML=Te),zt=f(t),nt=M(t,"UL",{"data-svelte-h":!0}),$(nt)!=="svelte-6bh016"&&(nt.innerHTML=Je),qt=f(t),it=M(t,"P",{"data-svelte-h":!0}),$(it)!=="svelte-1itmr9b"&&(it.innerHTML=xe),Pt=f(t),c(X.$$.fragment,t),Dt=f(t),c(pt.$$.fragment,t),Ot=f(t),ot=M(t,"P",{"data-svelte-h":!0}),$(ot)!=="svelte-xz2z6a"&&(ot.textContent=Ce),Kt=f(t),c(ft.$$.fragment,t),te=f(t),c(rt.$$.fragment,t),ee=f(t),mt=M(t,"P",{"data-svelte-h":!0}),$(mt)!=="svelte-3ai94s"&&(mt.textContent=je),le=f(t),ut=M(t,"UL",{"data-svelte-h":!0}),$(ut)!=="svelte-1v6cen1"&&(ut.innerHTML=Ze),ae=f(t),c(Mt.$$.fragment,t),se=f(t),$t=M(t,"P",{}),Le($t).forEach(a),this.h()},h(){Ee(l,"name","hf:doc:metadata"),Ee(l,"content",nl)},m(t,e){Se(document.head,l),n(t,r,e),n(t,s,e),n(t,m,e),y(i,t,e),n(t,p,e),y(g,t,e),n(t,T,e),n(t,v,e),n(t,yt,e),y(x,t,e),n(t,Ut,e),n(t,V,e),n(t,dt,e),n(t,W,e),n(t,ht,e),y(F,t,e),n(t,bt,e),n(t,G,e),n(t,gt,e),y(C,t,e),n(t,wt,e),y(j,t,e),n(t,Tt,e),n(t,L,e),n(t,Jt,e),y(E,t,e),n(t,xt,e),n(t,B,e),n(t,Ct,e),y(I,t,e),n(t,jt,e),n(t,N,e),n(t,Zt,e),y(Q,t,e),n(t,Rt,e),n(t,H,e),n(t,Xt,e),y(Z,t,e),n(t,vt,e),y(A,t,e),n(t,Vt,e),n(t,S,e),n(t,Wt,e),n(t,k,e),n(t,Ft,e),y(Y,t,e),n(t,Gt,e),n(t,z,e),n(t,Lt,e),n(t,q,e),n(t,Et,e),y(P,t,e),n(t,Bt,e),n(t,D,e),n(t,It,e),n(t,O,e),n(t,Nt,e),y(R,t,e),n(t,Qt,e),n(t,K,e),n(t,Ht,e),y(tt,t,e),n(t,At,e),n(t,et,e),n(t,St,e),y(lt,t,e),n(t,kt,e),n(t,at,e),n(t,Yt,e),n(t,st,e),n(t,zt,e),n(t,nt,e),n(t,qt,e),n(t,it,e),n(t,Pt,e),y(X,t,e),n(t,Dt,e),y(pt,t,e),n(t,Ot,e),n(t,ot,e),n(t,Kt,e),y(ft,t,e),n(t,te,e),y(rt,t,e),n(t,ee,e),n(t,mt,e),n(t,le,e),n(t,ut,e),n(t,ae,e),y(Mt,t,e),n(t,se,e),n(t,$t,e),ne=!0},p(t,[e]){const Re={};e&2&&(Re.$$scope={dirty:e,ctx:t}),g.$set(Re);const Xe={};e&2&&(Xe.$$scope={dirty:e,ctx:t}),x.$set(Xe);const ve={};e&2&&(ve.$$scope={dirty:e,ctx:t}),C.$set(ve);const Ve={};e&2&&(Ve.$$scope={dirty:e,ctx:t}),j.$set(Ve);const We={};e&2&&(We.$$scope={dirty:e,ctx:t}),Z.$set(We);const Fe={};e&2&&(Fe.$$scope={dirty:e,ctx:t}),R.$set(Fe);const Ge={};e&2&&(Ge.$$scope={dirty:e,ctx:t}),X.$set(Ge)},i(t){ne||(U(i.$$.fragment,t),U(g.$$.fragment,t),U(x.$$.fragment,t),U(F.$$.fragment,t),U(C.$$.fragment,t),U(j.$$.fragment,t),U(E.$$.fragment,t),U(I.$$.fragment,t),U(Q.$$.fragment,t),U(Z.$$.fragment,t),U(A.$$.fragment,t),U(Y.$$.fragment,t),U(P.$$.fragment,t),U(R.$$.fragment,t),U(tt.$$.fragment,t),U(lt.$$.fragment,t),U(X.$$.fragment,t),U(pt.$$.fragment,t),U(ft.$$.fragment,t),U(rt.$$.fragment,t),U(Mt.$$.fragment,t),ne=!0)},o(t){d(i.$$.fragment,t),d(g.$$.fragment,t),d(x.$$.fragment,t),d(F.$$.fragment,t),d(C.$$.fragment,t),d(j.$$.fragment,t),d(E.$$.fragment,t),d(I.$$.fragment,t),d(Q.$$.fragment,t),d(Z.$$.fragment,t),d(A.$$.fragment,t),d(Y.$$.fragment,t),d(P.$$.fragment,t),d(R.$$.fragment,t),d(tt.$$.fragment,t),d(lt.$$.fragment,t),d(X.$$.fragment,t),d(pt.$$.fragment,t),d(ft.$$.fragment,t),d(rt.$$.fragment,t),d(Mt.$$.fragment,t),ne=!1},d(t){t&&(a(r),a(s),a(m),a(p),a(T),a(v),a(yt),a(Ut),a(V),a(dt),a(W),a(ht),a(bt),a(G),a(gt),a(wt),a(Tt),a(L),a(Jt),a(xt),a(B),a(Ct),a(jt),a(N),a(Zt),a(Rt),a(H),a(Xt),a(vt),a(Vt),a(S),a(Wt),a(k),a(Ft),a(Gt),a(z),a(Lt),a(q),a(Et),a(Bt),a(D),a(It),a(O),a(Nt),a(Qt),a(K),a(Ht),a(At),a(et),a(St),a(kt),a(at),a(Yt),a(st),a(zt),a(nt),a(qt),a(it),a(Pt),a(Dt),a(Ot),a(ot),a(Kt),a(te),a(ee),a(mt),a(le),a(ut),a(ae),a(se),a($t)),a(l),h(i,t),h(g,t),h(x,t),h(F,t),h(C,t),h(j,t),h(E,t),h(I,t),h(Q,t),h(Z,t),h(A,t),h(Y,t),h(P,t),h(R,t),h(tt,t),h(lt,t),h(X,t),h(pt,t),h(ft,t),h(rt,t),h(Mt,t)}}}const nl='{"title":"LoRA 低秩适配","local":"lora-低秩适配","sections":[{"title":"脚本参数","local":"脚本参数","sections":[],"depth":2},{"title":"训练脚本实现","local":"训练脚本实现","sections":[],"depth":2},{"title":"启动训练","local":"启动训练","sections":[],"depth":2},{"title":"后续步骤","local":"后续步骤","sections":[],"depth":2}],"depth":1}';function il(b){return Ne(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ml extends Qe{constructor(l){super(),He(this,l,il,sl,Ie,{})}}export{Ml as component};
