import{s as wl,o as yl,n as Yt}from"../chunks/scheduler.e4ff9b64.js";import{S as Ul,i as hl,e as u,s as a,c as U,h as _l,a as c,d as e,b as i,f as Tl,g as h,j as d,k as Ht,l as gl,m as l,n as _,t as g,o as Z,p as j}from"../chunks/index.09f1bca0.js";import{C as Zl,H as Bt,E as jl}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.a5156008.js";import{C as x}from"../chunks/CodeBlock.b05639b3.js";import{H as He,a as Vt}from"../chunks/HfOption.44827c7f.js";function vl(X){let s,J;return s=new x({props:{code:"Y2QlMjBleGFtcGxlcyUyRmNvbnRyb2xuZXQlMEFwaXAlMjBpbnN0YWxsJTIwLXIlMjByZXF1aXJlbWVudHMudHh0",highlighted:`<span class="hljs-built_in">cd</span> examples/controlnet
pip install -r requirements.txt`,wrap:!1}}),{c(){U(s.$$.fragment)},l(o){h(s.$$.fragment,o)},m(o,r){_(s,o,r),J=!0},p:Yt,i(o){J||(g(s.$$.fragment,o),J=!0)},o(o){Z(s.$$.fragment,o),J=!1},d(o){j(s,o)}}}function Wl(X){let s,J='若可访问TPU设备，Flax训练脚本将运行得更快！以下是在 <a href="https://cloud.google.com/tpu/docs/run-calculation-jax" rel="nofollow">Google Cloud TPU VM</a> 上的配置流程。创建单个TPU v4-8虚拟机并连接：',o,r,p,f,m="安装JAX 0.4.5：",w,y,R,M,v="然后安装Flax脚本的依赖：",G,$,W;return r=new x({props:{code:"Wk9ORSUzRHVzLWNlbnRyYWwyLWIlMEFUUFVfVFlQRSUzRHY0LTglMEFWTV9OQU1FJTNEaGdfZmxheCUwQSUwQWdjbG91ZCUyMGFscGhhJTIwY29tcHV0ZSUyMHRwdXMlMjB0cHUtdm0lMjBjcmVhdGUlMjAlMjRWTV9OQU1FJTIwJTVDJTBBJTIwLS16b25lJTIwJTI0Wk9ORSUyMCU1QyUwQSUyMC0tYWNjZWxlcmF0b3ItdHlwZSUyMCUyNFRQVV9UWVBFJTIwJTVDJTBBJTIwLS12ZXJzaW9uJTIwJTIwdHB1LXZtLXY0LWJhc2UlMEElMEFnY2xvdWQlMjBhbHBoYSUyMGNvbXB1dGUlMjB0cHVzJTIwdHB1LXZtJTIwc3NoJTIwJTI0Vk1fTkFNRSUyMC0tem9uZSUyMCUyNFpPTkUlMjAtLSUyMCU1Qw==",highlighted:`ZONE=us-central2-b
TPU_TYPE=v4-8
VM_NAME=hg_flax

gcloud alpha compute tpus tpu-vm create <span class="hljs-variable">$VM_NAME</span> \\
 --zone <span class="hljs-variable">$ZONE</span> \\
 --accelerator-type <span class="hljs-variable">$TPU_TYPE</span> \\
 --version  tpu-vm-v4-base

gcloud alpha compute tpus tpu-vm ssh <span class="hljs-variable">$VM_NAME</span> --zone <span class="hljs-variable">$ZONE</span> -- \\`,wrap:!1}}),y=new x({props:{code:"cGlwJTIwaW5zdGFsbCUyMCUyMmpheCU1QnRwdSU1RCUzRCUzRDAuNC41JTIyJTIwLWYlMjBodHRwcyUzQSUyRiUyRnN0b3JhZ2UuZ29vZ2xlYXBpcy5jb20lMkZqYXgtcmVsZWFzZXMlMkZsaWJ0cHVfcmVsZWFzZXMuaHRtbA==",highlighted:'pip install <span class="hljs-string">&quot;jax[tpu]==0.4.5&quot;</span> -f https://storage.googleapis.com/jax-releases/libtpu_releases.html',wrap:!1}}),$=new x({props:{code:"Y2QlMjBleGFtcGxlcyUyRmNvbnRyb2xuZXQlMEFwaXAlMjBpbnN0YWxsJTIwLXIlMjByZXF1aXJlbWVudHNfZmxheC50eHQ=",highlighted:`<span class="hljs-built_in">cd</span> examples/controlnet
pip install -r requirements_flax.txt`,wrap:!1}}),{c(){s=u("p"),s.innerHTML=J,o=a(),U(r.$$.fragment),p=a(),f=u("p"),f.textContent=m,w=a(),U(y.$$.fragment),R=a(),M=u("p"),M.textContent=v,G=a(),U($.$$.fragment)},l(T){s=c(T,"P",{"data-svelte-h":!0}),d(s)!=="svelte-1s4bkv2"&&(s.innerHTML=J),o=i(T),h(r.$$.fragment,T),p=i(T),f=c(T,"P",{"data-svelte-h":!0}),d(f)!=="svelte-5i8wio"&&(f.textContent=m),w=i(T),h(y.$$.fragment,T),R=i(T),M=c(T,"P",{"data-svelte-h":!0}),d(M)!=="svelte-mvdck"&&(M.textContent=v),G=i(T),h($.$$.fragment,T)},m(T,C){l(T,s,C),l(T,o,C),_(r,T,C),l(T,p,C),l(T,f,C),l(T,w,C),_(y,T,C),l(T,R,C),l(T,M,C),l(T,G,C),_($,T,C),W=!0},p:Yt,i(T){W||(g(r.$$.fragment,T),g(y.$$.fragment,T),g($.$$.fragment,T),W=!0)},o(T){Z(r.$$.fragment,T),Z(y.$$.fragment,T),Z($.$$.fragment,T),W=!1},d(T){T&&(e(s),e(o),e(p),e(f),e(w),e(R),e(M),e(G)),j(r,T),j(y,T),j($,T)}}}function Cl(X){let s,J,o,r;return s=new Vt({props:{id:"installation",option:"PyTorch",$$slots:{default:[vl]},$$scope:{ctx:X}}}),o=new Vt({props:{id:"installation",option:"Flax",$$slots:{default:[Wl]},$$scope:{ctx:X}}}),{c(){U(s.$$.fragment),J=a(),U(o.$$.fragment)},l(p){h(s.$$.fragment,p),J=i(p),h(o.$$.fragment,p)},m(p,f){_(s,p,f),l(p,J,f),_(o,p,f),r=!0},p(p,f){const m={};f&2&&(m.$$scope={dirty:f,ctx:p}),s.$set(m);const w={};f&2&&(w.$$scope={dirty:f,ctx:p}),o.$set(w)},i(p){r||(g(s.$$.fragment,p),g(o.$$.fragment,p),r=!0)},o(p){Z(s.$$.fragment,p),Z(o.$$.fragment,p),r=!1},d(p){p&&e(J),j(s,p),j(o,p)}}}function xl(X){let s,J="16GB显卡可使用bitsandbytes 8-bit优化器和梯度检查点：",o,r,p,f,m="训练命令添加以下参数：",w,y,R;return r=new x({props:{code:"cGlwJTIwaW5zdGFsbCUyMGJpdHNhbmRieXRlcw==",highlighted:"pip install bitsandbytes",wrap:!1}}),y=new x({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2NvbnRyb2xuZXQucHklMjAlNUMlMEElMjAlMjAtLWdyYWRpZW50X2NoZWNrcG9pbnRpbmclMjAlNUMlMEElMjAlMjAtLXVzZV84Yml0X2FkYW0lMjAlNUM=",highlighted:`accelerate launch train_controlnet.py \\
  --gradient_checkpointing \\
  --use_8bit_adam \\`,wrap:!1}}),{c(){s=u("p"),s.textContent=J,o=a(),U(r.$$.fragment),p=a(),f=u("p"),f.textContent=m,w=a(),U(y.$$.fragment)},l(M){s=c(M,"P",{"data-svelte-h":!0}),d(s)!=="svelte-1absvxe"&&(s.textContent=J),o=i(M),h(r.$$.fragment,M),p=i(M),f=c(M,"P",{"data-svelte-h":!0}),d(f)!=="svelte-2snyv6"&&(f.textContent=m),w=i(M),h(y.$$.fragment,M)},m(M,v){l(M,s,v),l(M,o,v),_(r,M,v),l(M,p,v),l(M,f,v),l(M,w,v),_(y,M,v),R=!0},p:Yt,i(M){R||(g(r.$$.fragment,M),g(y.$$.fragment,M),R=!0)},o(M){Z(r.$$.fragment,M),Z(y.$$.fragment,M),R=!1},d(M){M&&(e(s),e(o),e(p),e(f),e(w)),j(r,M),j(y,M)}}}function Xl(X){let s,J="12GB显卡需组合使用bitsandbytes 8-bit优化器、梯度检查点、xFormers，并将梯度置为None而非0：",o,r,p;return r=new x({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2NvbnRyb2xuZXQucHklMjAlNUMlMEElMjAlMjAtLXVzZV84Yml0X2FkYW0lMjAlNUMlMEElMjAlMjAtLWdyYWRpZW50X2NoZWNrcG9pbnRpbmclMjAlNUMlMEElMjAlMjAtLWVuYWJsZV94Zm9ybWVyc19tZW1vcnlfZWZmaWNpZW50X2F0dGVudGlvbiUyMCU1QyUwQSUyMCUyMC0tc2V0X2dyYWRzX3RvX25vbmUlMjAlNUM=",highlighted:`accelerate launch train_controlnet.py \\
  --use_8bit_adam \\
  --gradient_checkpointing \\
  --enable_xformers_memory_efficient_attention \\
  --set_grads_to_none \\`,wrap:!1}}),{c(){s=u("p"),s.textContent=J,o=a(),U(r.$$.fragment)},l(f){s=c(f,"P",{"data-svelte-h":!0}),d(s)!=="svelte-8soba"&&(s.textContent=J),o=i(f),h(r.$$.fragment,f)},m(f,m){l(f,s,m),l(f,o,m),_(r,f,m),p=!0},p:Yt,i(f){p||(g(r.$$.fragment,f),p=!0)},o(f){Z(r.$$.fragment,f),p=!1},d(f){f&&(e(s),e(o)),j(r,f)}}}function Rl(X){let s,J='8GB显卡需使用 <a href="https://www.deepspeed.ai/" rel="nofollow">DeepSpeed</a> 将张量卸载到CPU或NVME：',o,r,p="运行以下命令配置环境：",f,m,w,y,R="选择DeepSpeed stage 2，结合fp16混合精度和参数卸载到CPU的方案。注意这会增加约25GB内存占用。配置示例如下：",M,v,G,$,W='建议将优化器替换为DeepSpeed特化版 <a href="https://deepspeed.readthedocs.io/en/latest/optimizers.html#adam-cpu" rel="nofollow"><code>deepspeed.ops.adam.DeepSpeedCPUAdam</code></a>，注意CUDA工具链版本需与PyTorch匹配。',T,C,B="当前bitsandbytes与DeepSpeed存在兼容性问题。",Q,N,V="无需额外添加训练参数。",Y;return m=new x({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),v=new x({props:{code:"Y29tcHV0ZV9lbnZpcm9ubWVudCUzQSUyMExPQ0FMX01BQ0hJTkUlMEFkZWVwc3BlZWRfY29uZmlnJTNBJTBBJTIwJTIwZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNBJTIwNCUwQSUyMCUyMG9mZmxvYWRfb3B0aW1pemVyX2RldmljZSUzQSUyMGNwdSUwQSUyMCUyMG9mZmxvYWRfcGFyYW1fZGV2aWNlJTNBJTIwY3B1JTBBJTIwJTIwemVybzNfaW5pdF9mbGFnJTNBJTIwZmFsc2UlMEElMjAlMjB6ZXJvX3N0YWdlJTNBJTIwMiUwQWRpc3RyaWJ1dGVkX3R5cGUlM0ElMjBERUVQU1BFRUQ=",highlighted:`compute_environment: LOCAL_MACHINE
deepspeed_config:
  gradient_accumulation_steps: 4
  offload_optimizer_device: cpu
  offload_param_device: cpu
  zero3_init_flag: <span class="hljs-literal">false</span>
  zero_stage: 2
distributed_type: DEEPSPEED`,wrap:!1}}),{c(){s=u("p"),s.innerHTML=J,o=a(),r=u("p"),r.textContent=p,f=a(),U(m.$$.fragment),w=a(),y=u("p"),y.textContent=R,M=a(),U(v.$$.fragment),G=a(),$=u("p"),$.innerHTML=W,T=a(),C=u("p"),C.textContent=B,Q=a(),N=u("p"),N.textContent=V},l(b){s=c(b,"P",{"data-svelte-h":!0}),d(s)!=="svelte-1ksb623"&&(s.innerHTML=J),o=i(b),r=c(b,"P",{"data-svelte-h":!0}),d(r)!=="svelte-13vvhkm"&&(r.textContent=p),f=i(b),h(m.$$.fragment,b),w=i(b),y=c(b,"P",{"data-svelte-h":!0}),d(y)!=="svelte-tt6e04"&&(y.textContent=R),M=i(b),h(v.$$.fragment,b),G=i(b),$=c(b,"P",{"data-svelte-h":!0}),d($)!=="svelte-bazipz"&&($.innerHTML=W),T=i(b),C=c(b,"P",{"data-svelte-h":!0}),d(C)!=="svelte-1vu9iwx"&&(C.textContent=B),Q=i(b),N=c(b,"P",{"data-svelte-h":!0}),d(N)!=="svelte-1wz42f8"&&(N.textContent=V)},m(b,I){l(b,s,I),l(b,o,I),l(b,r,I),l(b,f,I),_(m,b,I),l(b,w,I),l(b,y,I),l(b,M,I),_(v,b,I),l(b,G,I),l(b,$,I),l(b,T,I),l(b,C,I),l(b,Q,I),l(b,N,I),Y=!0},p:Yt,i(b){Y||(g(m.$$.fragment,b),g(v.$$.fragment,b),Y=!0)},o(b){Z(m.$$.fragment,b),Z(v.$$.fragment,b),Y=!1},d(b){b&&(e(s),e(o),e(r),e(f),e(w),e(y),e(M),e(G),e($),e(T),e(C),e(Q),e(N)),j(m,b),j(v,b)}}}function Il(X){let s,J,o,r,p,f;return s=new Vt({props:{id:"gpu-select",option:"16GB",$$slots:{default:[xl]},$$scope:{ctx:X}}}),o=new Vt({props:{id:"gpu-select",option:"12GB",$$slots:{default:[Xl]},$$scope:{ctx:X}}}),p=new Vt({props:{id:"gpu-select",option:"8GB",$$slots:{default:[Rl]},$$scope:{ctx:X}}}),{c(){U(s.$$.fragment),J=a(),U(o.$$.fragment),r=a(),U(p.$$.fragment)},l(m){h(s.$$.fragment,m),J=i(m),h(o.$$.fragment,m),r=i(m),h(p.$$.fragment,m)},m(m,w){_(s,m,w),l(m,J,w),_(o,m,w),l(m,r,w),_(p,m,w),f=!0},p(m,w){const y={};w&2&&(y.$$scope={dirty:w,ctx:m}),s.$set(y);const R={};w&2&&(R.$$scope={dirty:w,ctx:m}),o.$set(R);const M={};w&2&&(M.$$scope={dirty:w,ctx:m}),p.$set(M)},i(m){f||(g(s.$$.fragment,m),g(o.$$.fragment,m),g(p.$$.fragment,m),f=!0)},o(m){Z(s.$$.fragment,m),Z(o.$$.fragment,m),Z(p.$$.fragment,m),f=!1},d(m){m&&(e(J),e(r)),j(s,m),j(o,m),j(p,m)}}}function Gl(X){let s,J;return s=new x({props:{code:"ZXhwb3J0JTIwTU9ERUxfRElSJTNEJTIyc3RhYmxlLWRpZmZ1c2lvbi12MS01JTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTBBZXhwb3J0JTIwT1VUUFVUX0RJUiUzRCUyMnBhdGglMkZ0byUyRnNhdmUlMkZtb2RlbCUyMiUwQSUwQWFjY2VsZXJhdGUlMjBsYXVuY2glMjB0cmFpbl9jb250cm9sbmV0LnB5JTIwJTVDJTBBJTIwLS1wcmV0cmFpbmVkX21vZGVsX25hbWVfb3JfcGF0aCUzRCUyNE1PREVMX0RJUiUyMCU1QyUwQSUyMC0tb3V0cHV0X2RpciUzRCUyNE9VVFBVVF9ESVIlMjAlNUMlMEElMjAtLWRhdGFzZXRfbmFtZSUzRGZ1c2luZyUyRmZpbGw1MGslMjAlNUMlMEElMjAtLXJlc29sdXRpb24lM0Q1MTIlMjAlNUMlMEElMjAtLWxlYXJuaW5nX3JhdGUlM0QxZS01JTIwJTVDJTBBJTIwLS12YWxpZGF0aW9uX2ltYWdlJTIwJTIyLiUyRmNvbmRpdGlvbmluZ19pbWFnZV8xLnBuZyUyMiUyMCUyMi4lMkZjb25kaXRpb25pbmdfaW1hZ2VfMi5wbmclMjIlMjAlNUMlMEElMjAtLXZhbGlkYXRpb25fcHJvbXB0JTIwJTIycmVkJTIwY2lyY2xlJTIwd2l0aCUyMGJsdWUlMjBiYWNrZ3JvdW5kJTIyJTIwJTIyY3lhbiUyMGNpcmNsZSUyMHdpdGglMjBicm93biUyMGZsb3JhbCUyMGJhY2tncm91bmQlMjIlMjAlNUMlMEElMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxJTIwJTVDJTBBJTIwLS1ncmFkaWVudF9hY2N1bXVsYXRpb25fc3RlcHMlM0Q0JTIwJTVDJTBBJTIwLS1wdXNoX3RvX2h1Yg==",highlighted:`<span class="hljs-built_in">export</span> MODEL_DIR=<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;path/to/save/model&quot;</span>

accelerate launch train_controlnet.py \\
 --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_DIR</span> \\
 --output_dir=<span class="hljs-variable">$OUTPUT_DIR</span> \\
 --dataset_name=fusing/fill50k \\
 --resolution=512 \\
 --learning_rate=1e-5 \\
 --validation_image <span class="hljs-string">&quot;./conditioning_image_1.png&quot;</span> <span class="hljs-string">&quot;./conditioning_image_2.png&quot;</span> \\
 --validation_prompt <span class="hljs-string">&quot;red circle with blue background&quot;</span> <span class="hljs-string">&quot;cyan circle with brown floral background&quot;</span> \\
 --train_batch_size=1 \\
 --gradient_accumulation_steps=4 \\
 --push_to_hub`,wrap:!1}}),{c(){U(s.$$.fragment)},l(o){h(s.$$.fragment,o)},m(o,r){_(s,o,r),J=!0},p:Yt,i(o){J||(g(s.$$.fragment,o),J=!0)},o(o){Z(s.$$.fragment,o),J=!1},d(o){j(s,o)}}}function Nl(X){let s,J="Flax版本支持通过 <code>--profile_steps==5</code> 参数进行性能分析：",o,r,p,f,m='在 <a href="http://localhost:6006/#profile" rel="nofollow">http://localhost:6006/#profile</a> 查看分析结果。',w,y,R="<p>若遇到插件版本冲突，建议重新安装TensorFlow和Tensorboard。注意性能分析插件仍处实验阶段，部分视图可能不完整。<code>trace_viewer</code> 会截断超过1M的事件记录，在编译步骤分析时可能导致设备轨迹丢失。</p>",M,v,G;return r=new x({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRlbnNvcmZsb3clMjB0ZW5zb3Jib2FyZC1wbHVnaW4tcHJvZmlsZSUwQXRlbnNvcmJvYXJkJTIwLS1sb2dkaXIlMjBydW5zJTJGZmlsbC1jaXJjbGUtMTAwc3RlcHMtMjAyMzA0MTFfMTY1NjEyJTJG",highlighted:`pip install tensorflow tensorboard-plugin-profile
tensorboard --logdir runs/fill-circle-100steps-20230411_165612/`,wrap:!1}}),v=new x({props:{code:"cHl0aG9uMyUyMHRyYWluX2NvbnRyb2xuZXRfZmxheC5weSUyMCU1QyUwQSUyMC0tcHJldHJhaW5lZF9tb2RlbF9uYW1lX29yX3BhdGglM0QlMjRNT0RFTF9ESVIlMjAlNUMlMEElMjAtLW91dHB1dF9kaXIlM0QlMjRPVVRQVVRfRElSJTIwJTVDJTBBJTIwLS1kYXRhc2V0X25hbWUlM0RmdXNpbmclMkZmaWxsNTBrJTIwJTVDJTBBJTIwLS1yZXNvbHV0aW9uJTNENTEyJTIwJTVDJTBBJTIwLS1sZWFybmluZ19yYXRlJTNEMWUtNSUyMCU1QyUwQSUyMC0tdmFsaWRhdGlvbl9pbWFnZSUyMCUyMi4lMkZjb25kaXRpb25pbmdfaW1hZ2VfMS5wbmclMjIlMjAlMjIuJTJGY29uZGl0aW9uaW5nX2ltYWdlXzIucG5nJTIyJTIwJTVDJTBBJTIwLS12YWxpZGF0aW9uX3Byb21wdCUyMCUyMnJlZCUyMGNpcmNsZSUyMHdpdGglMjBibHVlJTIwYmFja2dyb3VuZCUyMiUyMCUyMmN5YW4lMjBjaXJjbGUlMjB3aXRoJTIwYnJvd24lMjBmbG9yYWwlMjBiYWNrZ3JvdW5kJTIyJTIwJTVDJTBBJTIwLS12YWxpZGF0aW9uX3N0ZXBzJTNEMTAwMCUyMCU1QyUwQSUyMC0tdHJhaW5fYmF0Y2hfc2l6ZSUzRDIlMjAlNUMlMEElMjAtLXJldmlzaW9uJTNEJTIybm9uLWVtYSUyMiUyMCU1QyUwQSUyMC0tZnJvbV9wdCUyMCU1QyUwQSUyMC0tcmVwb3J0X3RvJTNEJTIyd2FuZGIlMjIlMjAlNUMlMEElMjAtLXRyYWNrZXJfcHJvamVjdF9uYW1lJTNEJTI0SFVCX01PREVMX0lEJTIwJTVDJTBBJTIwLS1udW1fdHJhaW5fZXBvY2hzJTNEMTElMjAlNUMlMEElMjAtLXB1c2hfdG9faHViJTIwJTVDJTBBJTIwLS1odWJfbW9kZWxfaWQlM0QlMjRIVUJfTU9ERUxfSUQ=",highlighted:`python3 train_controlnet_flax.py \\
 --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_DIR</span> \\
 --output_dir=<span class="hljs-variable">$OUTPUT_DIR</span> \\
 --dataset_name=fusing/fill50k \\
 --resolution=512 \\
 --learning_rate=1e-5 \\
 --validation_image <span class="hljs-string">&quot;./conditioning_image_1.png&quot;</span> <span class="hljs-string">&quot;./conditioning_image_2.png&quot;</span> \\
 --validation_prompt <span class="hljs-string">&quot;red circle with blue background&quot;</span> <span class="hljs-string">&quot;cyan circle with brown floral background&quot;</span> \\
 --validation_steps=1000 \\
 --train_batch_size=2 \\
 --revision=<span class="hljs-string">&quot;non-ema&quot;</span> \\
 --from_pt \\
 --report_to=<span class="hljs-string">&quot;wandb&quot;</span> \\
 --tracker_project_name=<span class="hljs-variable">$HUB_MODEL_ID</span> \\
 --num_train_epochs=11 \\
 --push_to_hub \\
 --hub_model_id=<span class="hljs-variable">$HUB_MODEL_ID</span>`,wrap:!1}}),{c(){s=u("p"),s.innerHTML=J,o=a(),U(r.$$.fragment),p=a(),f=u("p"),f.innerHTML=m,w=a(),y=u("blockquote"),y.innerHTML=R,M=a(),U(v.$$.fragment),this.h()},l($){s=c($,"P",{"data-svelte-h":!0}),d(s)!=="svelte-qmdj7q"&&(s.innerHTML=J),o=i($),h(r.$$.fragment,$),p=i($),f=c($,"P",{"data-svelte-h":!0}),d(f)!=="svelte-3kn6xy"&&(f.innerHTML=m),w=i($),y=c($,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),d(y)!=="svelte-74enx5"&&(y.innerHTML=R),M=i($),h(v.$$.fragment,$),this.h()},h(){Ht(y,"class","warning")},m($,W){l($,s,W),l($,o,W),_(r,$,W),l($,p,W),l($,f,W),l($,w,W),l($,y,W),l($,M,W),_(v,$,W),G=!0},p:Yt,i($){G||(g(r.$$.fragment,$),g(v.$$.fragment,$),G=!0)},o($){Z(r.$$.fragment,$),Z(v.$$.fragment,$),G=!1},d($){$&&(e(s),e(o),e(p),e(f),e(w),e(y),e(M)),j(r,$),j(v,$)}}}function Bl(X){let s,J,o,r;return s=new Vt({props:{id:"training-inference",option:"PyTorch",$$slots:{default:[Gl]},$$scope:{ctx:X}}}),o=new Vt({props:{id:"training-inference",option:"Flax",$$slots:{default:[Nl]},$$scope:{ctx:X}}}),{c(){U(s.$$.fragment),J=a(),U(o.$$.fragment)},l(p){h(s.$$.fragment,p),J=i(p),h(o.$$.fragment,p)},m(p,f){_(s,p,f),l(p,J,f),_(o,p,f),r=!0},p(p,f){const m={};f&2&&(m.$$scope={dirty:f,ctx:p}),s.$set(m);const w={};f&2&&(w.$$scope={dirty:f,ctx:p}),o.$set(w)},i(p){r||(g(s.$$.fragment,p),g(o.$$.fragment,p),r=!0)},o(p){Z(s.$$.fragment,p),Z(o.$$.fragment,p),r=!1},d(p){p&&e(J),j(s,p),j(o,p)}}}function Vl(X){let s,J,o,r,p,f,m,w,y,R='<a href="https://hf.co/papers/2302.05543" rel="nofollow">ControlNet</a> 是一种基于预训练模型的适配器架构。它通过额外输入的条件图像（如边缘检测图、深度图、人体姿态图等），实现对生成图像的精细化控制。',M,v,G='在显存有限的GPU上训练时，建议启用训练命令中的 <code>gradient_checkpointing</code>（梯度检查点）、<code>gradient_accumulation_steps</code>（梯度累积步数）和 <code>mixed_precision</code>（混合精度）参数。还可使用 <a href="../optimization/xformers">xFormers</a> 的内存高效注意力机制进一步降低显存占用。虽然JAX/Flax训练支持在TPU和GPU上高效运行，但不支持梯度检查点和xFormers。若需通过Flax加速训练，建议使用显存大于30GB的GPU。',$,W,T='本指南将解析 <a href="https://github.com/huggingface/diffusers/blob/main/examples/controlnet/train_controlnet.py" rel="nofollow">train_controlnet.py</a> 训练脚本，帮助您理解其逻辑并适配自定义需求。',C,B,Q="运行脚本前，请确保从源码安装库：",N,V,Y,b,I="然后进入包含训练脚本的示例目录，安装所需依赖：",kt,H,Lt,E,Ee='<p>🤗 Accelerate 是一个支持多GPU/TPU训练和混合精度的库，它能根据硬件环境自动配置训练方案。参阅 🤗 Accelerate <a href="https://huggingface.co/docs/accelerate/quicktour" rel="nofollow">快速入门</a> 了解更多。</p>',Ft,z,ke="初始化🤗 Accelerate环境：",St,A,Qt,P,Le="若要创建默认配置（不进行交互式选择）：",zt,D,At,q,Fe="若环境不支持交互式shell（如notebook），可使用：",Pt,O,Dt,K,Se='最后，如需训练自定义数据集，请参阅 <a href="create_dataset">创建训练数据集</a> 指南了解数据准备方法。',qt,k,Qe='<p>下文重点解析脚本中的关键模块，但不会覆盖所有实现细节。如需深入了解，建议直接阅读 <a href="https://github.com/huggingface/diffusers/blob/main/examples/controlnet/train_controlnet.py" rel="nofollow">脚本源码</a>，如有疑问欢迎反馈。</p>',Ot,tt,Kt,et,ze='训练脚本提供了丰富的可配置参数，所有参数及其说明详见 <a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L231" rel="nofollow"><code>parse_args()</code></a> 函数。虽然该函数已为每个参数提供默认值（如训练批大小、学习率等），但您可以通过命令行参数覆盖这些默认值。',te,lt,Ae="例如，使用fp16混合精度加速训练, 可使用<code>--mixed_precision</code>参数",ee,nt,le,st,Pe='基础参数说明可参考 <a href="text2image#script-parameters">文生图</a> 训练指南，此处重点介绍ControlNet相关参数：',ne,at,De="<li><code>--max_train_samples</code>: 训练样本数量，减少该值可加快训练，但对超大数据集需配合 <code>--streaming</code> 参数使用</li> <li><code>--gradient_accumulation_steps</code>: 梯度累积步数，通过分步计算实现显存受限情况下的更大批次训练</li>",se,it,ae,pt,qe='<a href="https://huggingface.co/papers/2303.09556" rel="nofollow">Min-SNR</a> 加权策略通过重新平衡损失函数加速模型收敛。虽然训练脚本支持预测 <code>epsilon</code>（噪声）或 <code>v_prediction</code>，但Min-SNR对两种预测类型均兼容。该策略仅适用于PyTorch版本，Flax训练脚本暂不支持。',ie,ot,Oe="推荐值设为5.0：",pe,ft,oe,rt,fe,mt,Ke='与参数说明类似，训练流程的通用解析可参考 <a href="text2image#training-script">文生图</a> 指南。此处重点分析ControlNet特有的实现。',re,ut,tl='脚本中的 <a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L582" rel="nofollow"><code>make_train_dataset</code></a> 函数负责数据预处理，除常规的文本标注分词和图像变换外，还包含条件图像的特效处理：',me,L,el='<p>在TPU上流式加载数据集时，🤗 Datasets库可能成为性能瓶颈（因其未针对图像数据优化）。建议考虑 <a href="https://webdataset.github.io/webdataset/" rel="nofollow">WebDataset</a>、<a href="https://github.com/pytorch/data" rel="nofollow">TorchData</a> 或 <a href="https://www.tensorflow.org/datasets/tfless_tfds" rel="nofollow">TensorFlow Datasets</a> 等高效数据格式。</p>',ue,ct,ce,Mt,ll='在 <a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L713" rel="nofollow"><code>main()</code></a> 函数中，代码会加载分词器、文本编码器、调度器和模型。此处也是ControlNet模型的加载点（支持从现有权重加载或从UNet随机初始化）：',Me,$t,$e,bt,nl='<a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L871" rel="nofollow">优化器</a> 专门针对ControlNet参数进行更新：',be,dt,de,Jt,sl='在 <a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L943" rel="nofollow">训练循环</a> 中，条件文本嵌入和图像被输入到ControlNet的下采样和中层模块：',Je,Tt,Te,wt,al='若想深入理解训练循环机制，可参阅 <a href="../using-diffusers/write_own_pipeline">理解管道、模型与调度器</a> 教程，该教程详细解析了去噪过程的基本原理。',we,yt,ye,Ut,il="现在可以启动训练脚本了！🚀",Ue,ht,pl='本指南使用 <a href="https://huggingface.co/datasets/fusing/fill50k" rel="nofollow">fusing/fill50k</a> 数据集，当然您也可以按照 <a href="create_dataset">创建训练数据集</a> 指南准备自定义数据。',he,_t,ol="设置环境变量 <code>MODEL_NAME</code> 为Hub模型ID或本地路径，<code>OUTPUT_DIR</code> 为模型保存路径。",_e,gt,fl="下载训练用的条件图像：",ge,Zt,Ze,jt,rl="根据GPU型号，可能需要启用特定优化。默认配置需要约38GB显存。若使用多GPU训练，请在 <code>accelerate launch</code> 命令中添加 <code>--multi_gpu</code> 参数。",je,F,ve,S,We,vt,ml="训练完成后即可进行推理：",Ce,Wt,xe,Ct,Xe,xt,ul='Stable Diffusion XL (SDXL) 是新一代文生图模型，通过添加第二文本编码器支持生成更高分辨率图像。使用 <a href="https://github.com/huggingface/diffusers/blob/main/examples/controlnet/train_controlnet_sdxl.py" rel="nofollow"><code>train_controlnet_sdxl.py</code></a> 脚本可为SDXL训练ControlNet适配器。',Re,Xt,cl='SDXL训练脚本的详细解析请参阅 <a href="sdxl">SDXL训练</a> 指南。',Ie,Rt,Ge,It,Ml="恭喜完成ControlNet训练！如需进一步了解模型应用，以下指南可能有所帮助：",Ne,Gt,$l='<li>学习如何 <a href="../using-diffusers/controlnet">使用ControlNet</a> 进行多样化任务的推理</li>',Be,Nt,Ve,Et,Ye;return p=new Zl({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),m=new Bt({props:{title:"ControlNet",local:"controlnet",headingTag:"h1"}}),V=new x({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}}),H=new He({props:{id:"installation",options:["PyTorch","Flax"],$$slots:{default:[Cl]},$$scope:{ctx:X}}}),A=new x({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),D=new x({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZyUyMGRlZmF1bHQ=",highlighted:"accelerate config default",wrap:!1}}),O=new x({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}}),tt=new Bt({props:{title:"脚本参数",local:"脚本参数",headingTag:"h2"}}),nt=new x({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2NvbnRyb2xuZXQucHklMjAlNUMlMEElMjAlMjAtLW1peGVkX3ByZWNpc2lvbiUzRCUyMmZwMTYlMjI=",highlighted:`accelerate launch train_controlnet.py \\
  --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span>`,wrap:!1}}),it=new Bt({props:{title:"Min-SNR加权策略",local:"min-snr加权策略",headingTag:"h3"}}),ft=new x({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2NvbnRyb2xuZXQucHklMjAlNUMlMEElMjAlMjAtLXNucl9nYW1tYSUzRDUuMA==",highlighted:`accelerate launch train_controlnet.py \\
  --snr_gamma=5.0`,wrap:!1}}),rt=new Bt({props:{title:"训练脚本",local:"训练脚本",headingTag:"h2"}}),ct=new x({props:{code:"Y29uZGl0aW9uaW5nX2ltYWdlX3RyYW5zZm9ybXMlMjAlM0QlMjB0cmFuc2Zvcm1zLkNvbXBvc2UoJTBBJTIwJTIwJTIwJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdHJhbnNmb3Jtcy5SZXNpemUoYXJncy5yZXNvbHV0aW9uJTJDJTIwaW50ZXJwb2xhdGlvbiUzRHRyYW5zZm9ybXMuSW50ZXJwb2xhdGlvbk1vZGUuQklMSU5FQVIpJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdHJhbnNmb3Jtcy5DZW50ZXJDcm9wKGFyZ3MucmVzb2x1dGlvbiklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB0cmFuc2Zvcm1zLlRvVGVuc29yKCklMkMlMEElMjAlMjAlMjAlMjAlNUQlMEEp",highlighted:`conditioning_image_transforms = transforms.Compose(
    [
        transforms.Resize(args.resolution, interpolation=transforms.InterpolationMode.BILINEAR),
        transforms.CenterCrop(args.resolution),
        transforms.ToTensor(),
    ]
)`,wrap:!1}}),$t=new x({props:{code:"aWYlMjBhcmdzLmNvbnRyb2xuZXRfbW9kZWxfbmFtZV9vcl9wYXRoJTNBJTBBJTIwJTIwJTIwJTIwbG9nZ2VyLmluZm8oJTIyTG9hZGluZyUyMGV4aXN0aW5nJTIwY29udHJvbG5ldCUyMHdlaWdodHMlMjIpJTBBJTIwJTIwJTIwJTIwY29udHJvbG5ldCUyMCUzRCUyMENvbnRyb2xOZXRNb2RlbC5mcm9tX3ByZXRyYWluZWQoYXJncy5jb250cm9sbmV0X21vZGVsX25hbWVfb3JfcGF0aCklMEFlbHNlJTNBJTBBJTIwJTIwJTIwJTIwbG9nZ2VyLmluZm8oJTIySW5pdGlhbGl6aW5nJTIwY29udHJvbG5ldCUyMHdlaWdodHMlMjBmcm9tJTIwdW5ldCUyMiklMEElMjAlMjAlMjAlMjBjb250cm9sbmV0JTIwJTNEJTIwQ29udHJvbE5ldE1vZGVsLmZyb21fdW5ldCh1bmV0KQ==",highlighted:`<span class="hljs-keyword">if</span> args.controlnet_model_name_or_path:
    logger.info(<span class="hljs-string">&quot;Loading existing controlnet weights&quot;</span>)
    controlnet = ControlNetModel.from_pretrained(args.controlnet_model_name_or_path)
<span class="hljs-keyword">else</span>:
    logger.info(<span class="hljs-string">&quot;Initializing controlnet weights from unet&quot;</span>)
    controlnet = ControlNetModel.from_unet(unet)`,wrap:!1}}),dt=new x({props:{code:"cGFyYW1zX3RvX29wdGltaXplJTIwJTNEJTIwY29udHJvbG5ldC5wYXJhbWV0ZXJzKCklMEFvcHRpbWl6ZXIlMjAlM0QlMjBvcHRpbWl6ZXJfY2xhc3MoJTBBJTIwJTIwJTIwJTIwcGFyYW1zX3RvX29wdGltaXplJTJDJTBBJTIwJTIwJTIwJTIwbHIlM0RhcmdzLmxlYXJuaW5nX3JhdGUlMkMlMEElMjAlMjAlMjAlMjBiZXRhcyUzRChhcmdzLmFkYW1fYmV0YTElMkMlMjBhcmdzLmFkYW1fYmV0YTIpJTJDJTBBJTIwJTIwJTIwJTIwd2VpZ2h0X2RlY2F5JTNEYXJncy5hZGFtX3dlaWdodF9kZWNheSUyQyUwQSUyMCUyMCUyMCUyMGVwcyUzRGFyZ3MuYWRhbV9lcHNpbG9uJTJDJTBBKQ==",highlighted:`params_to_optimize = controlnet.parameters()
optimizer = optimizer_class(
    params_to_optimize,
    lr=args.learning_rate,
    betas=(args.adam_beta1, args.adam_beta2),
    weight_decay=args.adam_weight_decay,
    eps=args.adam_epsilon,
)`,wrap:!1}}),Tt=new x({props:{code:"ZW5jb2Rlcl9oaWRkZW5fc3RhdGVzJTIwJTNEJTIwdGV4dF9lbmNvZGVyKGJhdGNoJTVCJTIyaW5wdXRfaWRzJTIyJTVEKSU1QjAlNUQlMEFjb250cm9sbmV0X2ltYWdlJTIwJTNEJTIwYmF0Y2glNUIlMjJjb25kaXRpb25pbmdfcGl4ZWxfdmFsdWVzJTIyJTVELnRvKGR0eXBlJTNEd2VpZ2h0X2R0eXBlKSUwQSUwQWRvd25fYmxvY2tfcmVzX3NhbXBsZXMlMkMlMjBtaWRfYmxvY2tfcmVzX3NhbXBsZSUyMCUzRCUyMGNvbnRyb2xuZXQoJTBBJTIwJTIwJTIwJTIwbm9pc3lfbGF0ZW50cyUyQyUwQSUyMCUyMCUyMCUyMHRpbWVzdGVwcyUyQyUwQSUyMCUyMCUyMCUyMGVuY29kZXJfaGlkZGVuX3N0YXRlcyUzRGVuY29kZXJfaGlkZGVuX3N0YXRlcyUyQyUwQSUyMCUyMCUyMCUyMGNvbnRyb2xuZXRfY29uZCUzRGNvbnRyb2xuZXRfaW1hZ2UlMkMlMEElMjAlMjAlMjAlMjByZXR1cm5fZGljdCUzREZhbHNlJTJDJTBBKQ==",highlighted:`encoder_hidden_states = text_encoder(batch[<span class="hljs-string">&quot;input_ids&quot;</span>])[<span class="hljs-number">0</span>]
controlnet_image = batch[<span class="hljs-string">&quot;conditioning_pixel_values&quot;</span>].to(dtype=weight_dtype)

down_block_res_samples, mid_block_res_sample = controlnet(
    noisy_latents,
    timesteps,
    encoder_hidden_states=encoder_hidden_states,
    controlnet_cond=controlnet_image,
    return_dict=<span class="hljs-literal">False</span>,
)`,wrap:!1}}),yt=new Bt({props:{title:"启动训练",local:"启动训练",headingTag:"h2"}}),Zt=new x({props:{code:"d2dldCUyMGh0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZkYXRhc2V0cyUyRmh1Z2dpbmdmYWNlJTJGZG9jdW1lbnRhdGlvbi1pbWFnZXMlMkZyZXNvbHZlJTJGbWFpbiUyRmRpZmZ1c2VycyUyRmNvbnRyb2xuZXRfdHJhaW5pbmclMkZjb25kaXRpb25pbmdfaW1hZ2VfMS5wbmclMEF3Z2V0JTIwaHR0cHMlM0ElMkYlMkZodWdnaW5nZmFjZS5jbyUyRmRhdGFzZXRzJTJGaHVnZ2luZ2ZhY2UlMkZkb2N1bWVudGF0aW9uLWltYWdlcyUyRnJlc29sdmUlMkZtYWluJTJGZGlmZnVzZXJzJTJGY29udHJvbG5ldF90cmFpbmluZyUyRmNvbmRpdGlvbmluZ19pbWFnZV8yLnBuZw==",highlighted:`wget https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_1.png
wget https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_training/conditioning_image_2.png`,wrap:!1}}),F=new He({props:{id:"gpu-select",options:["16GB","12GB","8GB"],$$slots:{default:[Il]},$$scope:{ctx:X}}}),S=new He({props:{id:"training-inference",options:["PyTorch","Flax"],$$slots:{default:[Bl]},$$scope:{ctx:X}}}),Wt=new x({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvbkNvbnRyb2xOZXRQaXBlbGluZSUyQyUyMENvbnRyb2xOZXRNb2RlbCUwQWZyb20lMjBkaWZmdXNlcnMudXRpbHMlMjBpbXBvcnQlMjBsb2FkX2ltYWdlJTBBaW1wb3J0JTIwdG9yY2glMEElMEFjb250cm9sbmV0JTIwJTNEJTIwQ29udHJvbE5ldE1vZGVsLmZyb21fcHJldHJhaW5lZCglMjJwYXRoJTJGdG8lMkZjb250cm9sbmV0JTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2KSUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uQ29udHJvbE5ldFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJwYXRoJTJGdG8lMkZiYXNlJTJGbW9kZWwlMjIlMkMlMjBjb250cm9sbmV0JTNEY29udHJvbG5ldCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUwQSkudG8oJTIyY3VkYSUyMiklMEElMEFjb250cm9sX2ltYWdlJTIwJTNEJTIwbG9hZF9pbWFnZSglMjIuJTJGY29uZGl0aW9uaW5nX2ltYWdlXzEucG5nJTIyKSUwQXByb21wdCUyMCUzRCUyMCUyMnBhbGUlMjBnb2xkZW4lMjByb2QlMjBjaXJjbGUlMjB3aXRoJTIwb2xkJTIwbGFjZSUyMGJhY2tncm91bmQlMjIlMEElMEFnZW5lcmF0b3IlMjAlM0QlMjB0b3JjaC5tYW51YWxfc2VlZCgwKSUwQWltYWdlJTIwJTNEJTIwcGlwZWxpbmUocHJvbXB0JTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDIwJTJDJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yJTJDJTIwaW1hZ2UlM0Rjb250cm9sX2ltYWdlKS5pbWFnZXMlNUIwJTVEJTBBaW1hZ2Uuc2F2ZSglMjIuJTJGb3V0cHV0LnBuZyUyMik=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionControlNetPipeline, ControlNetModel
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image
<span class="hljs-keyword">import</span> torch

controlnet = ControlNetModel.from_pretrained(<span class="hljs-string">&quot;path/to/controlnet&quot;</span>, torch_dtype=torch.float16)
pipeline = StableDiffusionControlNetPipeline.from_pretrained(
    <span class="hljs-string">&quot;path/to/base/model&quot;</span>, controlnet=controlnet, torch_dtype=torch.float16
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

control_image = load_image(<span class="hljs-string">&quot;./conditioning_image_1.png&quot;</span>)
prompt = <span class="hljs-string">&quot;pale golden rod circle with old lace background&quot;</span>

generator = torch.manual_seed(<span class="hljs-number">0</span>)
image = pipeline(prompt, num_inference_steps=<span class="hljs-number">20</span>, generator=generator, image=control_image).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;./output.png&quot;</span>)`,wrap:!1}}),Ct=new Bt({props:{title:"Stable Diffusion XL",local:"stable-diffusion-xl",headingTag:"h2"}}),Rt=new Bt({props:{title:"后续步骤",local:"后续步骤",headingTag:"h2"}}),Nt=new jl({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/zh/training/controlnet.md"}}),{c(){s=u("meta"),J=a(),o=u("p"),r=a(),U(p.$$.fragment),f=a(),U(m.$$.fragment),w=a(),y=u("p"),y.innerHTML=R,M=a(),v=u("p"),v.innerHTML=G,$=a(),W=u("p"),W.innerHTML=T,C=a(),B=u("p"),B.textContent=Q,N=a(),U(V.$$.fragment),Y=a(),b=u("p"),b.textContent=I,kt=a(),U(H.$$.fragment),Lt=a(),E=u("blockquote"),E.innerHTML=Ee,Ft=a(),z=u("p"),z.textContent=ke,St=a(),U(A.$$.fragment),Qt=a(),P=u("p"),P.textContent=Le,zt=a(),U(D.$$.fragment),At=a(),q=u("p"),q.textContent=Fe,Pt=a(),U(O.$$.fragment),Dt=a(),K=u("p"),K.innerHTML=Se,qt=a(),k=u("blockquote"),k.innerHTML=Qe,Ot=a(),U(tt.$$.fragment),Kt=a(),et=u("p"),et.innerHTML=ze,te=a(),lt=u("p"),lt.innerHTML=Ae,ee=a(),U(nt.$$.fragment),le=a(),st=u("p"),st.innerHTML=Pe,ne=a(),at=u("ul"),at.innerHTML=De,se=a(),U(it.$$.fragment),ae=a(),pt=u("p"),pt.innerHTML=qe,ie=a(),ot=u("p"),ot.textContent=Oe,pe=a(),U(ft.$$.fragment),oe=a(),U(rt.$$.fragment),fe=a(),mt=u("p"),mt.innerHTML=Ke,re=a(),ut=u("p"),ut.innerHTML=tl,me=a(),L=u("blockquote"),L.innerHTML=el,ue=a(),U(ct.$$.fragment),ce=a(),Mt=u("p"),Mt.innerHTML=ll,Me=a(),U($t.$$.fragment),$e=a(),bt=u("p"),bt.innerHTML=nl,be=a(),U(dt.$$.fragment),de=a(),Jt=u("p"),Jt.innerHTML=sl,Je=a(),U(Tt.$$.fragment),Te=a(),wt=u("p"),wt.innerHTML=al,we=a(),U(yt.$$.fragment),ye=a(),Ut=u("p"),Ut.textContent=il,Ue=a(),ht=u("p"),ht.innerHTML=pl,he=a(),_t=u("p"),_t.innerHTML=ol,_e=a(),gt=u("p"),gt.textContent=fl,ge=a(),U(Zt.$$.fragment),Ze=a(),jt=u("p"),jt.innerHTML=rl,je=a(),U(F.$$.fragment),ve=a(),U(S.$$.fragment),We=a(),vt=u("p"),vt.textContent=ml,Ce=a(),U(Wt.$$.fragment),xe=a(),U(Ct.$$.fragment),Xe=a(),xt=u("p"),xt.innerHTML=ul,Re=a(),Xt=u("p"),Xt.innerHTML=cl,Ie=a(),U(Rt.$$.fragment),Ge=a(),It=u("p"),It.textContent=Ml,Ne=a(),Gt=u("ul"),Gt.innerHTML=$l,Be=a(),U(Nt.$$.fragment),Ve=a(),Et=u("p"),this.h()},l(t){const n=_l("svelte-u9bgzb",document.head);s=c(n,"META",{name:!0,content:!0}),n.forEach(e),J=i(t),o=c(t,"P",{}),Tl(o).forEach(e),r=i(t),h(p.$$.fragment,t),f=i(t),h(m.$$.fragment,t),w=i(t),y=c(t,"P",{"data-svelte-h":!0}),d(y)!=="svelte-sjsnd7"&&(y.innerHTML=R),M=i(t),v=c(t,"P",{"data-svelte-h":!0}),d(v)!=="svelte-1m7lkjp"&&(v.innerHTML=G),$=i(t),W=c(t,"P",{"data-svelte-h":!0}),d(W)!=="svelte-1vg4fo"&&(W.innerHTML=T),C=i(t),B=c(t,"P",{"data-svelte-h":!0}),d(B)!=="svelte-1l0wcm7"&&(B.textContent=Q),N=i(t),h(V.$$.fragment,t),Y=i(t),b=c(t,"P",{"data-svelte-h":!0}),d(b)!=="svelte-1xawbup"&&(b.textContent=I),kt=i(t),h(H.$$.fragment,t),Lt=i(t),E=c(t,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),d(E)!=="svelte-eahdbc"&&(E.innerHTML=Ee),Ft=i(t),z=c(t,"P",{"data-svelte-h":!0}),d(z)!=="svelte-cfitki"&&(z.textContent=ke),St=i(t),h(A.$$.fragment,t),Qt=i(t),P=c(t,"P",{"data-svelte-h":!0}),d(P)!=="svelte-xibv3y"&&(P.textContent=Le),zt=i(t),h(D.$$.fragment,t),At=i(t),q=c(t,"P",{"data-svelte-h":!0}),d(q)!=="svelte-1hg4sov"&&(q.textContent=Fe),Pt=i(t),h(O.$$.fragment,t),Dt=i(t),K=c(t,"P",{"data-svelte-h":!0}),d(K)!=="svelte-1rrm6a6"&&(K.innerHTML=Se),qt=i(t),k=c(t,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),d(k)!=="svelte-1va67of"&&(k.innerHTML=Qe),Ot=i(t),h(tt.$$.fragment,t),Kt=i(t),et=c(t,"P",{"data-svelte-h":!0}),d(et)!=="svelte-1xocvee"&&(et.innerHTML=ze),te=i(t),lt=c(t,"P",{"data-svelte-h":!0}),d(lt)!=="svelte-1y2ini0"&&(lt.innerHTML=Ae),ee=i(t),h(nt.$$.fragment,t),le=i(t),st=c(t,"P",{"data-svelte-h":!0}),d(st)!=="svelte-9h2hrj"&&(st.innerHTML=Pe),ne=i(t),at=c(t,"UL",{"data-svelte-h":!0}),d(at)!=="svelte-131ombr"&&(at.innerHTML=De),se=i(t),h(it.$$.fragment,t),ae=i(t),pt=c(t,"P",{"data-svelte-h":!0}),d(pt)!=="svelte-fpn1fz"&&(pt.innerHTML=qe),ie=i(t),ot=c(t,"P",{"data-svelte-h":!0}),d(ot)!=="svelte-w3lby1"&&(ot.textContent=Oe),pe=i(t),h(ft.$$.fragment,t),oe=i(t),h(rt.$$.fragment,t),fe=i(t),mt=c(t,"P",{"data-svelte-h":!0}),d(mt)!=="svelte-19vruao"&&(mt.innerHTML=Ke),re=i(t),ut=c(t,"P",{"data-svelte-h":!0}),d(ut)!=="svelte-og5v3i"&&(ut.innerHTML=tl),me=i(t),L=c(t,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),d(L)!=="svelte-1tmrdma"&&(L.innerHTML=el),ue=i(t),h(ct.$$.fragment,t),ce=i(t),Mt=c(t,"P",{"data-svelte-h":!0}),d(Mt)!=="svelte-labw4g"&&(Mt.innerHTML=ll),Me=i(t),h($t.$$.fragment,t),$e=i(t),bt=c(t,"P",{"data-svelte-h":!0}),d(bt)!=="svelte-1k39kzg"&&(bt.innerHTML=nl),be=i(t),h(dt.$$.fragment,t),de=i(t),Jt=c(t,"P",{"data-svelte-h":!0}),d(Jt)!=="svelte-1lsxjeq"&&(Jt.innerHTML=sl),Je=i(t),h(Tt.$$.fragment,t),Te=i(t),wt=c(t,"P",{"data-svelte-h":!0}),d(wt)!=="svelte-17e7gr9"&&(wt.innerHTML=al),we=i(t),h(yt.$$.fragment,t),ye=i(t),Ut=c(t,"P",{"data-svelte-h":!0}),d(Ut)!=="svelte-jxb8qf"&&(Ut.textContent=il),Ue=i(t),ht=c(t,"P",{"data-svelte-h":!0}),d(ht)!=="svelte-dw0fwn"&&(ht.innerHTML=pl),he=i(t),_t=c(t,"P",{"data-svelte-h":!0}),d(_t)!=="svelte-5ud1ys"&&(_t.innerHTML=ol),_e=i(t),gt=c(t,"P",{"data-svelte-h":!0}),d(gt)!=="svelte-sixk1u"&&(gt.textContent=fl),ge=i(t),h(Zt.$$.fragment,t),Ze=i(t),jt=c(t,"P",{"data-svelte-h":!0}),d(jt)!=="svelte-1gs6ntu"&&(jt.innerHTML=rl),je=i(t),h(F.$$.fragment,t),ve=i(t),h(S.$$.fragment,t),We=i(t),vt=c(t,"P",{"data-svelte-h":!0}),d(vt)!=="svelte-257z1r"&&(vt.textContent=ml),Ce=i(t),h(Wt.$$.fragment,t),xe=i(t),h(Ct.$$.fragment,t),Xe=i(t),xt=c(t,"P",{"data-svelte-h":!0}),d(xt)!=="svelte-9jjphj"&&(xt.innerHTML=ul),Re=i(t),Xt=c(t,"P",{"data-svelte-h":!0}),d(Xt)!=="svelte-wz3tw3"&&(Xt.innerHTML=cl),Ie=i(t),h(Rt.$$.fragment,t),Ge=i(t),It=c(t,"P",{"data-svelte-h":!0}),d(It)!=="svelte-r8lz9h"&&(It.textContent=Ml),Ne=i(t),Gt=c(t,"UL",{"data-svelte-h":!0}),d(Gt)!=="svelte-9xdgu2"&&(Gt.innerHTML=$l),Be=i(t),h(Nt.$$.fragment,t),Ve=i(t),Et=c(t,"P",{}),Tl(Et).forEach(e),this.h()},h(){Ht(s,"name","hf:doc:metadata"),Ht(s,"content",Yl),Ht(E,"class","tip"),Ht(k,"class","tip"),Ht(L,"class","tip")},m(t,n){gl(document.head,s),l(t,J,n),l(t,o,n),l(t,r,n),_(p,t,n),l(t,f,n),_(m,t,n),l(t,w,n),l(t,y,n),l(t,M,n),l(t,v,n),l(t,$,n),l(t,W,n),l(t,C,n),l(t,B,n),l(t,N,n),_(V,t,n),l(t,Y,n),l(t,b,n),l(t,kt,n),_(H,t,n),l(t,Lt,n),l(t,E,n),l(t,Ft,n),l(t,z,n),l(t,St,n),_(A,t,n),l(t,Qt,n),l(t,P,n),l(t,zt,n),_(D,t,n),l(t,At,n),l(t,q,n),l(t,Pt,n),_(O,t,n),l(t,Dt,n),l(t,K,n),l(t,qt,n),l(t,k,n),l(t,Ot,n),_(tt,t,n),l(t,Kt,n),l(t,et,n),l(t,te,n),l(t,lt,n),l(t,ee,n),_(nt,t,n),l(t,le,n),l(t,st,n),l(t,ne,n),l(t,at,n),l(t,se,n),_(it,t,n),l(t,ae,n),l(t,pt,n),l(t,ie,n),l(t,ot,n),l(t,pe,n),_(ft,t,n),l(t,oe,n),_(rt,t,n),l(t,fe,n),l(t,mt,n),l(t,re,n),l(t,ut,n),l(t,me,n),l(t,L,n),l(t,ue,n),_(ct,t,n),l(t,ce,n),l(t,Mt,n),l(t,Me,n),_($t,t,n),l(t,$e,n),l(t,bt,n),l(t,be,n),_(dt,t,n),l(t,de,n),l(t,Jt,n),l(t,Je,n),_(Tt,t,n),l(t,Te,n),l(t,wt,n),l(t,we,n),_(yt,t,n),l(t,ye,n),l(t,Ut,n),l(t,Ue,n),l(t,ht,n),l(t,he,n),l(t,_t,n),l(t,_e,n),l(t,gt,n),l(t,ge,n),_(Zt,t,n),l(t,Ze,n),l(t,jt,n),l(t,je,n),_(F,t,n),l(t,ve,n),_(S,t,n),l(t,We,n),l(t,vt,n),l(t,Ce,n),_(Wt,t,n),l(t,xe,n),_(Ct,t,n),l(t,Xe,n),l(t,xt,n),l(t,Re,n),l(t,Xt,n),l(t,Ie,n),_(Rt,t,n),l(t,Ge,n),l(t,It,n),l(t,Ne,n),l(t,Gt,n),l(t,Be,n),_(Nt,t,n),l(t,Ve,n),l(t,Et,n),Ye=!0},p(t,[n]){const bl={};n&2&&(bl.$$scope={dirty:n,ctx:t}),H.$set(bl);const dl={};n&2&&(dl.$$scope={dirty:n,ctx:t}),F.$set(dl);const Jl={};n&2&&(Jl.$$scope={dirty:n,ctx:t}),S.$set(Jl)},i(t){Ye||(g(p.$$.fragment,t),g(m.$$.fragment,t),g(V.$$.fragment,t),g(H.$$.fragment,t),g(A.$$.fragment,t),g(D.$$.fragment,t),g(O.$$.fragment,t),g(tt.$$.fragment,t),g(nt.$$.fragment,t),g(it.$$.fragment,t),g(ft.$$.fragment,t),g(rt.$$.fragment,t),g(ct.$$.fragment,t),g($t.$$.fragment,t),g(dt.$$.fragment,t),g(Tt.$$.fragment,t),g(yt.$$.fragment,t),g(Zt.$$.fragment,t),g(F.$$.fragment,t),g(S.$$.fragment,t),g(Wt.$$.fragment,t),g(Ct.$$.fragment,t),g(Rt.$$.fragment,t),g(Nt.$$.fragment,t),Ye=!0)},o(t){Z(p.$$.fragment,t),Z(m.$$.fragment,t),Z(V.$$.fragment,t),Z(H.$$.fragment,t),Z(A.$$.fragment,t),Z(D.$$.fragment,t),Z(O.$$.fragment,t),Z(tt.$$.fragment,t),Z(nt.$$.fragment,t),Z(it.$$.fragment,t),Z(ft.$$.fragment,t),Z(rt.$$.fragment,t),Z(ct.$$.fragment,t),Z($t.$$.fragment,t),Z(dt.$$.fragment,t),Z(Tt.$$.fragment,t),Z(yt.$$.fragment,t),Z(Zt.$$.fragment,t),Z(F.$$.fragment,t),Z(S.$$.fragment,t),Z(Wt.$$.fragment,t),Z(Ct.$$.fragment,t),Z(Rt.$$.fragment,t),Z(Nt.$$.fragment,t),Ye=!1},d(t){t&&(e(J),e(o),e(r),e(f),e(w),e(y),e(M),e(v),e($),e(W),e(C),e(B),e(N),e(Y),e(b),e(kt),e(Lt),e(E),e(Ft),e(z),e(St),e(Qt),e(P),e(zt),e(At),e(q),e(Pt),e(Dt),e(K),e(qt),e(k),e(Ot),e(Kt),e(et),e(te),e(lt),e(ee),e(le),e(st),e(ne),e(at),e(se),e(ae),e(pt),e(ie),e(ot),e(pe),e(oe),e(fe),e(mt),e(re),e(ut),e(me),e(L),e(ue),e(ce),e(Mt),e(Me),e($e),e(bt),e(be),e(de),e(Jt),e(Je),e(Te),e(wt),e(we),e(ye),e(Ut),e(Ue),e(ht),e(he),e(_t),e(_e),e(gt),e(ge),e(Ze),e(jt),e(je),e(ve),e(We),e(vt),e(Ce),e(xe),e(Xe),e(xt),e(Re),e(Xt),e(Ie),e(Ge),e(It),e(Ne),e(Gt),e(Be),e(Ve),e(Et)),e(s),j(p,t),j(m,t),j(V,t),j(H,t),j(A,t),j(D,t),j(O,t),j(tt,t),j(nt,t),j(it,t),j(ft,t),j(rt,t),j(ct,t),j($t,t),j(dt,t),j(Tt,t),j(yt,t),j(Zt,t),j(F,t),j(S,t),j(Wt,t),j(Ct,t),j(Rt,t),j(Nt,t)}}}const Yl='{"title":"ControlNet","local":"controlnet","sections":[{"title":"脚本参数","local":"脚本参数","sections":[{"title":"Min-SNR加权策略","local":"min-snr加权策略","sections":[],"depth":3}],"depth":2},{"title":"训练脚本","local":"训练脚本","sections":[],"depth":2},{"title":"启动训练","local":"启动训练","sections":[],"depth":2},{"title":"Stable Diffusion XL","local":"stable-diffusion-xl","sections":[],"depth":2},{"title":"后续步骤","local":"后续步骤","sections":[],"depth":2}],"depth":1}';function Hl(X){return yl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ql extends Ul{constructor(s){super(),hl(this,s,Hl,Vl,wl,{})}}export{Ql as component};
