import{s as Tl,o as wl,n as Y}from"../chunks/scheduler.5c93273d.js";import{S as _l,i as yl,g as $,s as i,r as w,A as Ul,h as d,f as e,c as p,j as bl,u as _,x as J,k as Jl,y as gl,a as n,v as y,d as U,t as g,w as h}from"../chunks/index.e43dd92b.js";import{T as Be}from"../chunks/Tip.1cbfe904.js";import{C as R}from"../chunks/CodeBlock.6896320e.js";import{H as Bt,E as hl}from"../chunks/getInferenceSnippets.d410b42d.js";import{H as Ve,a as Vt}from"../chunks/HfOption.d50154c3.js";function Zl(W){let s,u;return s=new R({props:{code:"Y2QlMjBleGFtcGxlcyUyRmNvbnRyb2xuZXQlMEFwaXAlMjBpbnN0YWxsJTIwLXIlMjByZXF1aXJlbWVudHMudHh0",highlighted:`<span class="hljs-built_in">cd</span> examples/controlnet
pip install -r requirements.txt`,wrap:!1}}),{c(){w(s.$$.fragment)},l(a){_(s.$$.fragment,a)},m(a,f){y(s,a,f),u=!0},p:Y,i(a){u||(U(s.$$.fragment,a),u=!0)},o(a){g(s.$$.fragment,a),u=!1},d(a){h(s,a)}}}function jl(W){let s,u='若可访问TPU设备，Flax训练脚本将运行得更快！以下是在 <a href="https://cloud.google.com/tpu/docs/run-calculation-jax" rel="nofollow">Google Cloud TPU VM</a> 上的配置流程。创建单个TPU v4-8虚拟机并连接：',a,f,o,r,m="安装JAX 0.4.5：",Z,j,C,c,x="然后安装Flax脚本的依赖：",M,v,G;return f=new R({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}}),j=new R({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}}),v=new R({props:{code:"Y2QlMjBleGFtcGxlcyUyRmNvbnRyb2xuZXQlMEFwaXAlMjBpbnN0YWxsJTIwLXIlMjByZXF1aXJlbWVudHNfZmxheC50eHQ=",highlighted:`<span class="hljs-built_in">cd</span> examples/controlnet
pip install -r requirements_flax.txt`,wrap:!1}}),{c(){s=$("p"),s.innerHTML=u,a=i(),w(f.$$.fragment),o=i(),r=$("p"),r.textContent=m,Z=i(),w(j.$$.fragment),C=i(),c=$("p"),c.textContent=x,M=i(),w(v.$$.fragment)},l(b){s=d(b,"P",{"data-svelte-h":!0}),J(s)!=="svelte-1s4bkv2"&&(s.innerHTML=u),a=p(b),_(f.$$.fragment,b),o=p(b),r=d(b,"P",{"data-svelte-h":!0}),J(r)!=="svelte-5i8wio"&&(r.textContent=m),Z=p(b),_(j.$$.fragment,b),C=p(b),c=d(b,"P",{"data-svelte-h":!0}),J(c)!=="svelte-mvdck"&&(c.textContent=x),M=p(b),_(v.$$.fragment,b)},m(b,I){n(b,s,I),n(b,a,I),y(f,b,I),n(b,o,I),n(b,r,I),n(b,Z,I),y(j,b,I),n(b,C,I),n(b,c,I),n(b,M,I),y(v,b,I),G=!0},p:Y,i(b){G||(U(f.$$.fragment,b),U(j.$$.fragment,b),U(v.$$.fragment,b),G=!0)},o(b){g(f.$$.fragment,b),g(j.$$.fragment,b),g(v.$$.fragment,b),G=!1},d(b){b&&(e(s),e(a),e(o),e(r),e(Z),e(C),e(c),e(M)),h(f,b),h(j,b),h(v,b)}}}function vl(W){let s,u,a,f;return s=new Vt({props:{id:"installation",option:"PyTorch",$$slots:{default:[Zl]},$$scope:{ctx:W}}}),a=new Vt({props:{id:"installation",option:"Flax",$$slots:{default:[jl]},$$scope:{ctx:W}}}),{c(){w(s.$$.fragment),u=i(),w(a.$$.fragment)},l(o){_(s.$$.fragment,o),u=p(o),_(a.$$.fragment,o)},m(o,r){y(s,o,r),n(o,u,r),y(a,o,r),f=!0},p(o,r){const m={};r&2&&(m.$$scope={dirty:r,ctx:o}),s.$set(m);const Z={};r&2&&(Z.$$scope={dirty:r,ctx:o}),a.$set(Z)},i(o){f||(U(s.$$.fragment,o),U(a.$$.fragment,o),f=!0)},o(o){g(s.$$.fragment,o),g(a.$$.fragment,o),f=!1},d(o){o&&e(u),h(s,o),h(a,o)}}}function Wl(W){let s,u='🤗 Accelerate 是一个支持多GPU/TPU训练和混合精度的库，它能根据硬件环境自动配置训练方案。参阅 🤗 Accelerate <a href="https://huggingface.co/docs/accelerate/quicktour" rel="nofollow">快速入门</a> 了解更多。';return{c(){s=$("p"),s.innerHTML=u},l(a){s=d(a,"P",{"data-svelte-h":!0}),J(s)!=="svelte-1s0j5en"&&(s.innerHTML=u)},m(a,f){n(a,s,f)},p:Y,d(a){a&&e(s)}}}function Cl(W){let s,u='下文重点解析脚本中的关键模块，但不会覆盖所有实现细节。如需深入了解，建议直接阅读 <a href="https://github.com/huggingface/diffusers/blob/main/examples/controlnet/train_controlnet.py" rel="nofollow">脚本源码</a>，如有疑问欢迎反馈。';return{c(){s=$("p"),s.innerHTML=u},l(a){s=d(a,"P",{"data-svelte-h":!0}),J(s)!=="svelte-jdk84q"&&(s.innerHTML=u)},m(a,f){n(a,s,f)},p:Y,d(a){a&&e(s)}}}function xl(W){let s,u='在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> 等高效数据格式。';return{c(){s=$("p"),s.innerHTML=u},l(a){s=d(a,"P",{"data-svelte-h":!0}),J(s)!=="svelte-ccb1b5"&&(s.innerHTML=u)},m(a,f){n(a,s,f)},p:Y,d(a){a&&e(s)}}}function Xl(W){let s,u="16GB显卡可使用bitsandbytes 8-bit优化器和梯度检查点：",a,f,o,r,m="训练命令添加以下参数：",Z,j,C;return f=new R({props:{code:"cGlwJTIwaW5zdGFsbCUyMGJpdHNhbmRieXRlcw==",highlighted:"pip install bitsandbytes",wrap:!1}}),j=new R({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2NvbnRyb2xuZXQucHklMjAlNUMlMEElMjAlMjAtLWdyYWRpZW50X2NoZWNrcG9pbnRpbmclMjAlNUMlMEElMjAlMjAtLXVzZV84Yml0X2FkYW0lMjAlNUM=",highlighted:`accelerate launch train_controlnet.py \\
  --gradient_checkpointing \\
  --use_8bit_adam \\`,wrap:!1}}),{c(){s=$("p"),s.textContent=u,a=i(),w(f.$$.fragment),o=i(),r=$("p"),r.textContent=m,Z=i(),w(j.$$.fragment)},l(c){s=d(c,"P",{"data-svelte-h":!0}),J(s)!=="svelte-1absvxe"&&(s.textContent=u),a=p(c),_(f.$$.fragment,c),o=p(c),r=d(c,"P",{"data-svelte-h":!0}),J(r)!=="svelte-2snyv6"&&(r.textContent=m),Z=p(c),_(j.$$.fragment,c)},m(c,x){n(c,s,x),n(c,a,x),y(f,c,x),n(c,o,x),n(c,r,x),n(c,Z,x),y(j,c,x),C=!0},p:Y,i(c){C||(U(f.$$.fragment,c),U(j.$$.fragment,c),C=!0)},o(c){g(f.$$.fragment,c),g(j.$$.fragment,c),C=!1},d(c){c&&(e(s),e(a),e(o),e(r),e(Z)),h(f,c),h(j,c)}}}function Rl(W){let s,u="12GB显卡需组合使用bitsandbytes 8-bit优化器、梯度检查点、xFormers，并将梯度置为None而非0：",a,f,o;return f=new R({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=$("p"),s.textContent=u,a=i(),w(f.$$.fragment)},l(r){s=d(r,"P",{"data-svelte-h":!0}),J(s)!=="svelte-8soba"&&(s.textContent=u),a=p(r),_(f.$$.fragment,r)},m(r,m){n(r,s,m),n(r,a,m),y(f,r,m),o=!0},p:Y,i(r){o||(U(f.$$.fragment,r),o=!0)},o(r){g(f.$$.fragment,r),o=!1},d(r){r&&(e(s),e(a)),h(f,r)}}}function Il(W){let s,u='8GB显卡需使用 <a href="https://www.deepspeed.ai/" rel="nofollow">DeepSpeed</a> 将张量卸载到CPU或NVME：',a,f,o="运行以下命令配置环境：",r,m,Z,j,C="选择DeepSpeed stage 2，结合fp16混合精度和参数卸载到CPU的方案。注意这会增加约25GB内存占用。配置示例如下：",c,x,M,v,G='建议将优化器替换为DeepSpeed特化版 <a href="https://deepspeed.readthedocs.io/en/latest/optimizers.html#adam-cpu" rel="nofollow"><code>deepspeed.ops.adam.DeepSpeedCPUAdam</code></a>，注意CUDA工具链版本需与PyTorch匹配。',b,I,S="当前bitsandbytes与DeepSpeed存在兼容性问题。",N,B,V="无需额外添加训练参数。",Q;return m=new R({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),x=new R({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=$("p"),s.innerHTML=u,a=i(),f=$("p"),f.textContent=o,r=i(),w(m.$$.fragment),Z=i(),j=$("p"),j.textContent=C,c=i(),w(x.$$.fragment),M=i(),v=$("p"),v.innerHTML=G,b=i(),I=$("p"),I.textContent=S,N=i(),B=$("p"),B.textContent=V},l(T){s=d(T,"P",{"data-svelte-h":!0}),J(s)!=="svelte-1ksb623"&&(s.innerHTML=u),a=p(T),f=d(T,"P",{"data-svelte-h":!0}),J(f)!=="svelte-13vvhkm"&&(f.textContent=o),r=p(T),_(m.$$.fragment,T),Z=p(T),j=d(T,"P",{"data-svelte-h":!0}),J(j)!=="svelte-tt6e04"&&(j.textContent=C),c=p(T),_(x.$$.fragment,T),M=p(T),v=d(T,"P",{"data-svelte-h":!0}),J(v)!=="svelte-bazipz"&&(v.innerHTML=G),b=p(T),I=d(T,"P",{"data-svelte-h":!0}),J(I)!=="svelte-1vu9iwx"&&(I.textContent=S),N=p(T),B=d(T,"P",{"data-svelte-h":!0}),J(B)!=="svelte-1wz42f8"&&(B.textContent=V)},m(T,X){n(T,s,X),n(T,a,X),n(T,f,X),n(T,r,X),y(m,T,X),n(T,Z,X),n(T,j,X),n(T,c,X),y(x,T,X),n(T,M,X),n(T,v,X),n(T,b,X),n(T,I,X),n(T,N,X),n(T,B,X),Q=!0},p:Y,i(T){Q||(U(m.$$.fragment,T),U(x.$$.fragment,T),Q=!0)},o(T){g(m.$$.fragment,T),g(x.$$.fragment,T),Q=!1},d(T){T&&(e(s),e(a),e(f),e(r),e(Z),e(j),e(c),e(M),e(v),e(b),e(I),e(N),e(B)),h(m,T),h(x,T)}}}function Gl(W){let s,u,a,f,o,r;return s=new Vt({props:{id:"gpu-select",option:"16GB",$$slots:{default:[Xl]},$$scope:{ctx:W}}}),a=new Vt({props:{id:"gpu-select",option:"12GB",$$slots:{default:[Rl]},$$scope:{ctx:W}}}),o=new Vt({props:{id:"gpu-select",option:"8GB",$$slots:{default:[Il]},$$scope:{ctx:W}}}),{c(){w(s.$$.fragment),u=i(),w(a.$$.fragment),f=i(),w(o.$$.fragment)},l(m){_(s.$$.fragment,m),u=p(m),_(a.$$.fragment,m),f=p(m),_(o.$$.fragment,m)},m(m,Z){y(s,m,Z),n(m,u,Z),y(a,m,Z),n(m,f,Z),y(o,m,Z),r=!0},p(m,Z){const j={};Z&2&&(j.$$scope={dirty:Z,ctx:m}),s.$set(j);const C={};Z&2&&(C.$$scope={dirty:Z,ctx:m}),a.$set(C);const c={};Z&2&&(c.$$scope={dirty:Z,ctx:m}),o.$set(c)},i(m){r||(U(s.$$.fragment,m),U(a.$$.fragment,m),U(o.$$.fragment,m),r=!0)},o(m){g(s.$$.fragment,m),g(a.$$.fragment,m),g(o.$$.fragment,m),r=!1},d(m){m&&(e(u),e(f)),h(s,m),h(a,m),h(o,m)}}}function Nl(W){let s,u;return s=new R({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(){w(s.$$.fragment)},l(a){_(s.$$.fragment,a)},m(a,f){y(s,a,f),u=!0},p:Y,i(a){u||(U(s.$$.fragment,a),u=!0)},o(a){g(s.$$.fragment,a),u=!1},d(a){h(s,a)}}}function Bl(W){let s,u="若遇到插件版本冲突，建议重新安装TensorFlow和Tensorboard。注意性能分析插件仍处实验阶段，部分视图可能不完整。<code>trace_viewer</code> 会截断超过1M的事件记录，在编译步骤分析时可能导致设备轨迹丢失。";return{c(){s=$("p"),s.innerHTML=u},l(a){s=d(a,"P",{"data-svelte-h":!0}),J(s)!=="svelte-1csqw6r"&&(s.innerHTML=u)},m(a,f){n(a,s,f)},p:Y,d(a){a&&e(s)}}}function Vl(W){let s,u="Flax版本支持通过 <code>--profile_steps==5</code> 参数进行性能分析：",a,f,o,r,m='在 <a href="http://localhost:6006/#profile" rel="nofollow">http://localhost:6006/#profile</a> 查看分析结果。',Z,j,C,c,x;return f=new R({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRlbnNvcmZsb3clMjB0ZW5zb3Jib2FyZC1wbHVnaW4tcHJvZmlsZSUwQXRlbnNvcmJvYXJkJTIwLS1sb2dkaXIlMjBydW5zJTJGZmlsbC1jaXJjbGUtMTAwc3RlcHMtMjAyMzA0MTFfMTY1NjEyJTJG",highlighted:`pip install tensorflow tensorboard-plugin-profile
tensorboard --logdir runs/fill-circle-100steps-20230411_165612/`,wrap:!1}}),j=new Be({props:{warning:!0,$$slots:{default:[Bl]},$$scope:{ctx:W}}}),c=new R({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=$("p"),s.innerHTML=u,a=i(),w(f.$$.fragment),o=i(),r=$("p"),r.innerHTML=m,Z=i(),w(j.$$.fragment),C=i(),w(c.$$.fragment)},l(M){s=d(M,"P",{"data-svelte-h":!0}),J(s)!=="svelte-qmdj7q"&&(s.innerHTML=u),a=p(M),_(f.$$.fragment,M),o=p(M),r=d(M,"P",{"data-svelte-h":!0}),J(r)!=="svelte-3kn6xy"&&(r.innerHTML=m),Z=p(M),_(j.$$.fragment,M),C=p(M),_(c.$$.fragment,M)},m(M,v){n(M,s,v),n(M,a,v),y(f,M,v),n(M,o,v),n(M,r,v),n(M,Z,v),y(j,M,v),n(M,C,v),y(c,M,v),x=!0},p(M,v){const G={};v&2&&(G.$$scope={dirty:v,ctx:M}),j.$set(G)},i(M){x||(U(f.$$.fragment,M),U(j.$$.fragment,M),U(c.$$.fragment,M),x=!0)},o(M){g(f.$$.fragment,M),g(j.$$.fragment,M),g(c.$$.fragment,M),x=!1},d(M){M&&(e(s),e(a),e(o),e(r),e(Z),e(C)),h(f,M),h(j,M),h(c,M)}}}function Yl(W){let s,u,a,f;return s=new Vt({props:{id:"training-inference",option:"PyTorch",$$slots:{default:[Nl]},$$scope:{ctx:W}}}),a=new Vt({props:{id:"training-inference",option:"Flax",$$slots:{default:[Vl]},$$scope:{ctx:W}}}),{c(){w(s.$$.fragment),u=i(),w(a.$$.fragment)},l(o){_(s.$$.fragment,o),u=p(o),_(a.$$.fragment,o)},m(o,r){y(s,o,r),n(o,u,r),y(a,o,r),f=!0},p(o,r){const m={};r&2&&(m.$$scope={dirty:r,ctx:o}),s.$set(m);const Z={};r&2&&(Z.$$scope={dirty:r,ctx:o}),a.$set(Z)},i(o){f||(U(s.$$.fragment,o),U(a.$$.fragment,o),f=!0)},o(o){g(s.$$.fragment,o),g(a.$$.fragment,o),f=!1},d(o){o&&e(u),h(s,o),h(a,o)}}}function Hl(W){let s,u,a,f,o,r,m,Z='<a href="https://hf.co/papers/2302.05543" rel="nofollow">ControlNet</a> 是一种基于预训练模型的适配器架构。它通过额外输入的条件图像（如边缘检测图、深度图、人体姿态图等），实现对生成图像的精细化控制。',j,C,c='在显存有限的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。',x,M,v='本指南将解析 <a href="https://github.com/huggingface/diffusers/blob/main/examples/controlnet/train_controlnet.py" rel="nofollow">train_controlnet.py</a> 训练脚本，帮助您理解其逻辑并适配自定义需求。',G,b,I="运行脚本前，请确保从源码安装库：",S,N,B,V,Q="然后进入包含训练脚本的示例目录，安装所需依赖：",T,X,Ht,H,Et,z,Ye="初始化🤗 Accelerate环境：",kt,A,Lt,P,He="若要创建默认配置（不进行交互式选择）：",Ft,D,St,q,Ee="若环境不支持交互式shell（如notebook），可使用：",Qt,O,zt,K,ke='最后，如需训练自定义数据集，请参阅 <a href="create_dataset">创建训练数据集</a> 指南了解数据准备方法。',At,E,Pt,tt,Dt,et,Le='训练脚本提供了丰富的可配置参数，所有参数及其说明详见 <a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L231" rel="nofollow"><code>parse_args()</code></a> 函数。虽然该函数已为每个参数提供默认值（如训练批大小、学习率等），但您可以通过命令行参数覆盖这些默认值。',qt,lt,Fe="例如，使用fp16混合精度加速训练, 可使用<code>--mixed_precision</code>参数",Ot,nt,Kt,st,Se='基础参数说明可参考 <a href="text2image#script-parameters">文生图</a> 训练指南，此处重点介绍ControlNet相关参数：',te,at,Qe="<li><code>--max_train_samples</code>: 训练样本数量，减少该值可加快训练，但对超大数据集需配合 <code>--streaming</code> 参数使用</li> <li><code>--gradient_accumulation_steps</code>: 梯度累积步数，通过分步计算实现显存受限情况下的更大批次训练</li>",ee,it,le,pt,ze='<a href="https://huggingface.co/papers/2303.09556" rel="nofollow">Min-SNR</a> 加权策略通过重新平衡损失函数加速模型收敛。虽然训练脚本支持预测 <code>epsilon</code>（噪声）或 <code>v_prediction</code>，但Min-SNR对两种预测类型均兼容。该策略仅适用于PyTorch版本，Flax训练脚本暂不支持。',ne,ot,Ae="推荐值设为5.0：",se,ft,ae,rt,ie,mt,Pe='与参数说明类似，训练流程的通用解析可参考 <a href="text2image#training-script">文生图</a> 指南。此处重点分析ControlNet特有的实现。',pe,ut,De='脚本中的 <a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L582" rel="nofollow"><code>make_train_dataset</code></a> 函数负责数据预处理，除常规的文本标注分词和图像变换外，还包含条件图像的特效处理：',oe,k,fe,ct,re,Mt,qe='在 <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,ue,dt,Oe='<a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L871" rel="nofollow">优化器</a> 专门针对ControlNet参数进行更新：',ce,bt,Me,Jt,Ke='在 <a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L943" rel="nofollow">训练循环</a> 中，条件文本嵌入和图像被输入到ControlNet的下采样和中层模块：',$e,Tt,de,wt,tl='若想深入理解训练循环机制，可参阅 <a href="../using-diffusers/write_own_pipeline">理解管道、模型与调度器</a> 教程，该教程详细解析了去噪过程的基本原理。',be,_t,Je,yt,el="现在可以启动训练脚本了！🚀",Te,Ut,ll='本指南使用 <a href="https://huggingface.co/datasets/fusing/fill50k" rel="nofollow">fusing/fill50k</a> 数据集，当然您也可以按照 <a href="create_dataset">创建训练数据集</a> 指南准备自定义数据。',we,gt,nl="设置环境变量 <code>MODEL_NAME</code> 为Hub模型ID或本地路径，<code>OUTPUT_DIR</code> 为模型保存路径。",_e,ht,sl="下载训练用的条件图像：",ye,Zt,Ue,jt,al="根据GPU型号，可能需要启用特定优化。默认配置需要约38GB显存。若使用多GPU训练，请在 <code>accelerate launch</code> 命令中添加 <code>--multi_gpu</code> 参数。",ge,L,he,F,Ze,vt,il="训练完成后即可进行推理：",je,Wt,ve,Ct,We,xt,pl='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适配器。',Ce,Xt,ol='SDXL训练脚本的详细解析请参阅 <a href="sdxl">SDXL训练</a> 指南。',xe,Rt,Xe,It,fl="恭喜完成ControlNet训练！如需进一步了解模型应用，以下指南可能有所帮助：",Re,Gt,rl='<li>学习如何 <a href="../using-diffusers/controlnet">使用ControlNet</a> 进行多样化任务的推理</li>',Ie,Nt,Ge,Yt,Ne;return o=new Bt({props:{title:"ControlNet",local:"controlnet",headingTag:"h1"}}),N=new R({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}}),X=new Ve({props:{id:"installation",options:["PyTorch","Flax"],$$slots:{default:[vl]},$$scope:{ctx:W}}}),H=new Be({props:{$$slots:{default:[Wl]},$$scope:{ctx:W}}}),A=new R({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),D=new R({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZyUyMGRlZmF1bHQ=",highlighted:"accelerate config default",wrap:!1}}),O=new R({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}}),E=new Be({props:{$$slots:{default:[Cl]},$$scope:{ctx:W}}}),tt=new Bt({props:{title:"脚本参数",local:"脚本参数",headingTag:"h2"}}),nt=new R({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 R({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2NvbnRyb2xuZXQucHklMjAlNUMlMEElMjAlMjAtLXNucl9nYW1tYSUzRDUuMA==",highlighted:`accelerate launch train_controlnet.py \\
  --snr_gamma=5.0`,wrap:!1}}),rt=new Bt({props:{title:"训练脚本",local:"训练脚本",headingTag:"h2"}}),k=new Be({props:{$$slots:{default:[xl]},$$scope:{ctx:W}}}),ct=new R({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 R({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}}),bt=new R({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 R({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}}),_t=new Bt({props:{title:"启动训练",local:"启动训练",headingTag:"h2"}}),Zt=new R({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}}),L=new Ve({props:{id:"gpu-select",options:["16GB","12GB","8GB"],$$slots:{default:[Gl]},$$scope:{ctx:W}}}),F=new Ve({props:{id:"training-inference",options:["PyTorch","Flax"],$$slots:{default:[Yl]},$$scope:{ctx:W}}}),Wt=new R({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 hl({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/zh/training/controlnet.md"}}),{c(){s=$("meta"),u=i(),a=$("p"),f=i(),w(o.$$.fragment),r=i(),m=$("p"),m.innerHTML=Z,j=i(),C=$("p"),C.innerHTML=c,x=i(),M=$("p"),M.innerHTML=v,G=i(),b=$("p"),b.textContent=I,S=i(),w(N.$$.fragment),B=i(),V=$("p"),V.textContent=Q,T=i(),w(X.$$.fragment),Ht=i(),w(H.$$.fragment),Et=i(),z=$("p"),z.textContent=Ye,kt=i(),w(A.$$.fragment),Lt=i(),P=$("p"),P.textContent=He,Ft=i(),w(D.$$.fragment),St=i(),q=$("p"),q.textContent=Ee,Qt=i(),w(O.$$.fragment),zt=i(),K=$("p"),K.innerHTML=ke,At=i(),w(E.$$.fragment),Pt=i(),w(tt.$$.fragment),Dt=i(),et=$("p"),et.innerHTML=Le,qt=i(),lt=$("p"),lt.innerHTML=Fe,Ot=i(),w(nt.$$.fragment),Kt=i(),st=$("p"),st.innerHTML=Se,te=i(),at=$("ul"),at.innerHTML=Qe,ee=i(),w(it.$$.fragment),le=i(),pt=$("p"),pt.innerHTML=ze,ne=i(),ot=$("p"),ot.textContent=Ae,se=i(),w(ft.$$.fragment),ae=i(),w(rt.$$.fragment),ie=i(),mt=$("p"),mt.innerHTML=Pe,pe=i(),ut=$("p"),ut.innerHTML=De,oe=i(),w(k.$$.fragment),fe=i(),w(ct.$$.fragment),re=i(),Mt=$("p"),Mt.innerHTML=qe,me=i(),w($t.$$.fragment),ue=i(),dt=$("p"),dt.innerHTML=Oe,ce=i(),w(bt.$$.fragment),Me=i(),Jt=$("p"),Jt.innerHTML=Ke,$e=i(),w(Tt.$$.fragment),de=i(),wt=$("p"),wt.innerHTML=tl,be=i(),w(_t.$$.fragment),Je=i(),yt=$("p"),yt.textContent=el,Te=i(),Ut=$("p"),Ut.innerHTML=ll,we=i(),gt=$("p"),gt.innerHTML=nl,_e=i(),ht=$("p"),ht.textContent=sl,ye=i(),w(Zt.$$.fragment),Ue=i(),jt=$("p"),jt.innerHTML=al,ge=i(),w(L.$$.fragment),he=i(),w(F.$$.fragment),Ze=i(),vt=$("p"),vt.textContent=il,je=i(),w(Wt.$$.fragment),ve=i(),w(Ct.$$.fragment),We=i(),xt=$("p"),xt.innerHTML=pl,Ce=i(),Xt=$("p"),Xt.innerHTML=ol,xe=i(),w(Rt.$$.fragment),Xe=i(),It=$("p"),It.textContent=fl,Re=i(),Gt=$("ul"),Gt.innerHTML=rl,Ie=i(),w(Nt.$$.fragment),Ge=i(),Yt=$("p"),this.h()},l(t){const l=Ul("svelte-u9bgzb",document.head);s=d(l,"META",{name:!0,content:!0}),l.forEach(e),u=p(t),a=d(t,"P",{}),bl(a).forEach(e),f=p(t),_(o.$$.fragment,t),r=p(t),m=d(t,"P",{"data-svelte-h":!0}),J(m)!=="svelte-sjsnd7"&&(m.innerHTML=Z),j=p(t),C=d(t,"P",{"data-svelte-h":!0}),J(C)!=="svelte-1m7lkjp"&&(C.innerHTML=c),x=p(t),M=d(t,"P",{"data-svelte-h":!0}),J(M)!=="svelte-1vg4fo"&&(M.innerHTML=v),G=p(t),b=d(t,"P",{"data-svelte-h":!0}),J(b)!=="svelte-1l0wcm7"&&(b.textContent=I),S=p(t),_(N.$$.fragment,t),B=p(t),V=d(t,"P",{"data-svelte-h":!0}),J(V)!=="svelte-1xawbup"&&(V.textContent=Q),T=p(t),_(X.$$.fragment,t),Ht=p(t),_(H.$$.fragment,t),Et=p(t),z=d(t,"P",{"data-svelte-h":!0}),J(z)!=="svelte-cfitki"&&(z.textContent=Ye),kt=p(t),_(A.$$.fragment,t),Lt=p(t),P=d(t,"P",{"data-svelte-h":!0}),J(P)!=="svelte-xibv3y"&&(P.textContent=He),Ft=p(t),_(D.$$.fragment,t),St=p(t),q=d(t,"P",{"data-svelte-h":!0}),J(q)!=="svelte-1hg4sov"&&(q.textContent=Ee),Qt=p(t),_(O.$$.fragment,t),zt=p(t),K=d(t,"P",{"data-svelte-h":!0}),J(K)!=="svelte-1rrm6a6"&&(K.innerHTML=ke),At=p(t),_(E.$$.fragment,t),Pt=p(t),_(tt.$$.fragment,t),Dt=p(t),et=d(t,"P",{"data-svelte-h":!0}),J(et)!=="svelte-1xocvee"&&(et.innerHTML=Le),qt=p(t),lt=d(t,"P",{"data-svelte-h":!0}),J(lt)!=="svelte-1y2ini0"&&(lt.innerHTML=Fe),Ot=p(t),_(nt.$$.fragment,t),Kt=p(t),st=d(t,"P",{"data-svelte-h":!0}),J(st)!=="svelte-9h2hrj"&&(st.innerHTML=Se),te=p(t),at=d(t,"UL",{"data-svelte-h":!0}),J(at)!=="svelte-131ombr"&&(at.innerHTML=Qe),ee=p(t),_(it.$$.fragment,t),le=p(t),pt=d(t,"P",{"data-svelte-h":!0}),J(pt)!=="svelte-fpn1fz"&&(pt.innerHTML=ze),ne=p(t),ot=d(t,"P",{"data-svelte-h":!0}),J(ot)!=="svelte-w3lby1"&&(ot.textContent=Ae),se=p(t),_(ft.$$.fragment,t),ae=p(t),_(rt.$$.fragment,t),ie=p(t),mt=d(t,"P",{"data-svelte-h":!0}),J(mt)!=="svelte-19vruao"&&(mt.innerHTML=Pe),pe=p(t),ut=d(t,"P",{"data-svelte-h":!0}),J(ut)!=="svelte-og5v3i"&&(ut.innerHTML=De),oe=p(t),_(k.$$.fragment,t),fe=p(t),_(ct.$$.fragment,t),re=p(t),Mt=d(t,"P",{"data-svelte-h":!0}),J(Mt)!=="svelte-labw4g"&&(Mt.innerHTML=qe),me=p(t),_($t.$$.fragment,t),ue=p(t),dt=d(t,"P",{"data-svelte-h":!0}),J(dt)!=="svelte-1k39kzg"&&(dt.innerHTML=Oe),ce=p(t),_(bt.$$.fragment,t),Me=p(t),Jt=d(t,"P",{"data-svelte-h":!0}),J(Jt)!=="svelte-1lsxjeq"&&(Jt.innerHTML=Ke),$e=p(t),_(Tt.$$.fragment,t),de=p(t),wt=d(t,"P",{"data-svelte-h":!0}),J(wt)!=="svelte-17e7gr9"&&(wt.innerHTML=tl),be=p(t),_(_t.$$.fragment,t),Je=p(t),yt=d(t,"P",{"data-svelte-h":!0}),J(yt)!=="svelte-jxb8qf"&&(yt.textContent=el),Te=p(t),Ut=d(t,"P",{"data-svelte-h":!0}),J(Ut)!=="svelte-dw0fwn"&&(Ut.innerHTML=ll),we=p(t),gt=d(t,"P",{"data-svelte-h":!0}),J(gt)!=="svelte-5ud1ys"&&(gt.innerHTML=nl),_e=p(t),ht=d(t,"P",{"data-svelte-h":!0}),J(ht)!=="svelte-sixk1u"&&(ht.textContent=sl),ye=p(t),_(Zt.$$.fragment,t),Ue=p(t),jt=d(t,"P",{"data-svelte-h":!0}),J(jt)!=="svelte-1gs6ntu"&&(jt.innerHTML=al),ge=p(t),_(L.$$.fragment,t),he=p(t),_(F.$$.fragment,t),Ze=p(t),vt=d(t,"P",{"data-svelte-h":!0}),J(vt)!=="svelte-257z1r"&&(vt.textContent=il),je=p(t),_(Wt.$$.fragment,t),ve=p(t),_(Ct.$$.fragment,t),We=p(t),xt=d(t,"P",{"data-svelte-h":!0}),J(xt)!=="svelte-9jjphj"&&(xt.innerHTML=pl),Ce=p(t),Xt=d(t,"P",{"data-svelte-h":!0}),J(Xt)!=="svelte-wz3tw3"&&(Xt.innerHTML=ol),xe=p(t),_(Rt.$$.fragment,t),Xe=p(t),It=d(t,"P",{"data-svelte-h":!0}),J(It)!=="svelte-r8lz9h"&&(It.textContent=fl),Re=p(t),Gt=d(t,"UL",{"data-svelte-h":!0}),J(Gt)!=="svelte-9xdgu2"&&(Gt.innerHTML=rl),Ie=p(t),_(Nt.$$.fragment,t),Ge=p(t),Yt=d(t,"P",{}),bl(Yt).forEach(e),this.h()},h(){Jl(s,"name","hf:doc:metadata"),Jl(s,"content",El)},m(t,l){gl(document.head,s),n(t,u,l),n(t,a,l),n(t,f,l),y(o,t,l),n(t,r,l),n(t,m,l),n(t,j,l),n(t,C,l),n(t,x,l),n(t,M,l),n(t,G,l),n(t,b,l),n(t,S,l),y(N,t,l),n(t,B,l),n(t,V,l),n(t,T,l),y(X,t,l),n(t,Ht,l),y(H,t,l),n(t,Et,l),n(t,z,l),n(t,kt,l),y(A,t,l),n(t,Lt,l),n(t,P,l),n(t,Ft,l),y(D,t,l),n(t,St,l),n(t,q,l),n(t,Qt,l),y(O,t,l),n(t,zt,l),n(t,K,l),n(t,At,l),y(E,t,l),n(t,Pt,l),y(tt,t,l),n(t,Dt,l),n(t,et,l),n(t,qt,l),n(t,lt,l),n(t,Ot,l),y(nt,t,l),n(t,Kt,l),n(t,st,l),n(t,te,l),n(t,at,l),n(t,ee,l),y(it,t,l),n(t,le,l),n(t,pt,l),n(t,ne,l),n(t,ot,l),n(t,se,l),y(ft,t,l),n(t,ae,l),y(rt,t,l),n(t,ie,l),n(t,mt,l),n(t,pe,l),n(t,ut,l),n(t,oe,l),y(k,t,l),n(t,fe,l),y(ct,t,l),n(t,re,l),n(t,Mt,l),n(t,me,l),y($t,t,l),n(t,ue,l),n(t,dt,l),n(t,ce,l),y(bt,t,l),n(t,Me,l),n(t,Jt,l),n(t,$e,l),y(Tt,t,l),n(t,de,l),n(t,wt,l),n(t,be,l),y(_t,t,l),n(t,Je,l),n(t,yt,l),n(t,Te,l),n(t,Ut,l),n(t,we,l),n(t,gt,l),n(t,_e,l),n(t,ht,l),n(t,ye,l),y(Zt,t,l),n(t,Ue,l),n(t,jt,l),n(t,ge,l),y(L,t,l),n(t,he,l),y(F,t,l),n(t,Ze,l),n(t,vt,l),n(t,je,l),y(Wt,t,l),n(t,ve,l),y(Ct,t,l),n(t,We,l),n(t,xt,l),n(t,Ce,l),n(t,Xt,l),n(t,xe,l),y(Rt,t,l),n(t,Xe,l),n(t,It,l),n(t,Re,l),n(t,Gt,l),n(t,Ie,l),y(Nt,t,l),n(t,Ge,l),n(t,Yt,l),Ne=!0},p(t,[l]){const ml={};l&2&&(ml.$$scope={dirty:l,ctx:t}),X.$set(ml);const ul={};l&2&&(ul.$$scope={dirty:l,ctx:t}),H.$set(ul);const cl={};l&2&&(cl.$$scope={dirty:l,ctx:t}),E.$set(cl);const Ml={};l&2&&(Ml.$$scope={dirty:l,ctx:t}),k.$set(Ml);const $l={};l&2&&($l.$$scope={dirty:l,ctx:t}),L.$set($l);const dl={};l&2&&(dl.$$scope={dirty:l,ctx:t}),F.$set(dl)},i(t){Ne||(U(o.$$.fragment,t),U(N.$$.fragment,t),U(X.$$.fragment,t),U(H.$$.fragment,t),U(A.$$.fragment,t),U(D.$$.fragment,t),U(O.$$.fragment,t),U(E.$$.fragment,t),U(tt.$$.fragment,t),U(nt.$$.fragment,t),U(it.$$.fragment,t),U(ft.$$.fragment,t),U(rt.$$.fragment,t),U(k.$$.fragment,t),U(ct.$$.fragment,t),U($t.$$.fragment,t),U(bt.$$.fragment,t),U(Tt.$$.fragment,t),U(_t.$$.fragment,t),U(Zt.$$.fragment,t),U(L.$$.fragment,t),U(F.$$.fragment,t),U(Wt.$$.fragment,t),U(Ct.$$.fragment,t),U(Rt.$$.fragment,t),U(Nt.$$.fragment,t),Ne=!0)},o(t){g(o.$$.fragment,t),g(N.$$.fragment,t),g(X.$$.fragment,t),g(H.$$.fragment,t),g(A.$$.fragment,t),g(D.$$.fragment,t),g(O.$$.fragment,t),g(E.$$.fragment,t),g(tt.$$.fragment,t),g(nt.$$.fragment,t),g(it.$$.fragment,t),g(ft.$$.fragment,t),g(rt.$$.fragment,t),g(k.$$.fragment,t),g(ct.$$.fragment,t),g($t.$$.fragment,t),g(bt.$$.fragment,t),g(Tt.$$.fragment,t),g(_t.$$.fragment,t),g(Zt.$$.fragment,t),g(L.$$.fragment,t),g(F.$$.fragment,t),g(Wt.$$.fragment,t),g(Ct.$$.fragment,t),g(Rt.$$.fragment,t),g(Nt.$$.fragment,t),Ne=!1},d(t){t&&(e(u),e(a),e(f),e(r),e(m),e(j),e(C),e(x),e(M),e(G),e(b),e(S),e(B),e(V),e(T),e(Ht),e(Et),e(z),e(kt),e(Lt),e(P),e(Ft),e(St),e(q),e(Qt),e(zt),e(K),e(At),e(Pt),e(Dt),e(et),e(qt),e(lt),e(Ot),e(Kt),e(st),e(te),e(at),e(ee),e(le),e(pt),e(ne),e(ot),e(se),e(ae),e(ie),e(mt),e(pe),e(ut),e(oe),e(fe),e(re),e(Mt),e(me),e(ue),e(dt),e(ce),e(Me),e(Jt),e($e),e(de),e(wt),e(be),e(Je),e(yt),e(Te),e(Ut),e(we),e(gt),e(_e),e(ht),e(ye),e(Ue),e(jt),e(ge),e(he),e(Ze),e(vt),e(je),e(ve),e(We),e(xt),e(Ce),e(Xt),e(xe),e(Xe),e(It),e(Re),e(Gt),e(Ie),e(Ge),e(Yt)),e(s),h(o,t),h(N,t),h(X,t),h(H,t),h(A,t),h(D,t),h(O,t),h(E,t),h(tt,t),h(nt,t),h(it,t),h(ft,t),h(rt,t),h(k,t),h(ct,t),h($t,t),h(bt,t),h(Tt,t),h(_t,t),h(Zt,t),h(L,t),h(F,t),h(Wt,t),h(Ct,t),h(Rt,t),h(Nt,t)}}}const El='{"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 kl(W){return wl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Pl extends _l{constructor(s){super(),yl(this,s,kl,Hl,Tl,{})}}export{Pl as component};
