import{s as bl,o as yl,n as Y}from"../chunks/scheduler.182ea377.js";import{S as wl,i as Tl,g as h,s,r as y,A as Jl,h as M,f as t,c as o,j as $l,u as w,x as g,k as gl,y as Ul,a as n,v as T,d as J,t as U,w as _}from"../chunks/index.abf12888.js";import{T as kt}from"../chunks/Tip.230e2334.js";import{C as G}from"../chunks/CodeBlock.57fe6e13.js";import{H as ke,E as _l}from"../chunks/EditOnGithub.9b8e78e4.js";import{H as Bt,a as Be}from"../chunks/HfOption.fc88c804.js";function vl(W){let a,u;return a=new G({props:{code:"Y2QlMjBleGFtcGxlcyUyRmNvbnRyb2xuZXQlMEFwaXAlMjBpbnN0YWxsJTIwLXIlMjByZXF1aXJlbWVudHMudHh0",highlighted:`<span class="hljs-built_in">cd</span> examples/controlnet
pip install -r requirements.txt`,wrap:!1}}),{c(){y(a.$$.fragment)},l(i){w(a.$$.fragment,i)},m(i,p){T(a,i,p),u=!0},p:Y,i(i){u||(J(a.$$.fragment,i),u=!0)},o(i){U(a.$$.fragment,i),u=!1},d(i){_(a,i)}}}function Zl(W){let a,u='If you have access to a TPU, the Flax training script runs even faster! Let’s run the training script on the <a href="https://cloud.google.com/tpu/docs/run-calculation-jax" rel="nofollow">Google Cloud TPU VM</a>. Create a single TPU v4-8 VM and connect to it:',i,p,r,f,m="Install JAX 0.4.5:",v,Z,C,c,x="Then install the required dependencies for the Flax script:",d,j,X;return p=new G({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}}),Z=new G({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}}),j=new G({props:{code:"Y2QlMjBleGFtcGxlcyUyRmNvbnRyb2xuZXQlMEFwaXAlMjBpbnN0YWxsJTIwLXIlMjByZXF1aXJlbWVudHNfZmxheC50eHQ=",highlighted:`<span class="hljs-built_in">cd</span> examples/controlnet
pip install -r requirements_flax.txt`,wrap:!1}}),{c(){a=h("p"),a.innerHTML=u,i=s(),y(p.$$.fragment),r=s(),f=h("p"),f.textContent=m,v=s(),y(Z.$$.fragment),C=s(),c=h("p"),c.textContent=x,d=s(),y(j.$$.fragment)},l($){a=M($,"P",{"data-svelte-h":!0}),g(a)!=="svelte-pcu1fk"&&(a.innerHTML=u),i=o($),w(p.$$.fragment,$),r=o($),f=M($,"P",{"data-svelte-h":!0}),g(f)!=="svelte-1a9obhp"&&(f.textContent=m),v=o($),w(Z.$$.fragment,$),C=o($),c=M($,"P",{"data-svelte-h":!0}),g(c)!=="svelte-2qk98r"&&(c.textContent=x),d=o($),w(j.$$.fragment,$)},m($,I){n($,a,I),n($,i,I),T(p,$,I),n($,r,I),n($,f,I),n($,v,I),T(Z,$,I),n($,C,I),n($,c,I),n($,d,I),T(j,$,I),X=!0},p:Y,i($){X||(J(p.$$.fragment,$),J(Z.$$.fragment,$),J(j.$$.fragment,$),X=!0)},o($){U(p.$$.fragment,$),U(Z.$$.fragment,$),U(j.$$.fragment,$),X=!1},d($){$&&(t(a),t(i),t(r),t(f),t(v),t(C),t(c),t(d)),_(p,$),_(Z,$),_(j,$)}}}function jl(W){let a,u,i,p;return a=new Be({props:{id:"installation",option:"PyTorch",$$slots:{default:[vl]},$$scope:{ctx:W}}}),i=new Be({props:{id:"installation",option:"Flax",$$slots:{default:[Zl]},$$scope:{ctx:W}}}),{c(){y(a.$$.fragment),u=s(),y(i.$$.fragment)},l(r){w(a.$$.fragment,r),u=o(r),w(i.$$.fragment,r)},m(r,f){T(a,r,f),n(r,u,f),T(i,r,f),p=!0},p(r,f){const m={};f&2&&(m.$$scope={dirty:f,ctx:r}),a.$set(m);const v={};f&2&&(v.$$scope={dirty:f,ctx:r}),i.$set(v)},i(r){p||(J(a.$$.fragment,r),J(i.$$.fragment,r),p=!0)},o(r){U(a.$$.fragment,r),U(i.$$.fragment,r),p=!1},d(r){r&&t(u),_(a,r),_(i,r)}}}function Wl(W){let a,u='🤗 Accelerate is a library for helping you train on multiple GPUs/TPUs or with mixed-precision. It’ll automatically configure your training setup based on your hardware and environment. Take a look at the 🤗 Accelerate <a href="https://huggingface.co/docs/accelerate/quicktour" rel="nofollow">Quick tour</a> to learn more.';return{c(){a=h("p"),a.innerHTML=u},l(i){a=M(i,"P",{"data-svelte-h":!0}),g(a)!=="svelte-1qbiqsn"&&(a.innerHTML=u)},m(i,p){n(i,a,p)},p:Y,d(i){i&&t(a)}}}function Cl(W){let a,u='The following sections highlight parts of the training script that are important for understanding how to modify it, but it doesn’t cover every aspect of the script in detail. If you’re interested in learning more, feel free to read through the <a href="https://github.com/huggingface/diffusers/blob/main/examples/controlnet/train_controlnet.py" rel="nofollow">script</a> and let us know if you have any questions or concerns.';return{c(){a=h("p"),a.innerHTML=u},l(i){a=M(i,"P",{"data-svelte-h":!0}),g(a)!=="svelte-c8crv2"&&(a.innerHTML=u)},m(i,p){n(i,a,p)},p:Y,d(i){i&&t(a)}}}function xl(W){let a,u='If you’re streaming a dataset on a TPU, performance may be bottlenecked by the 🤗 Datasets library which is not optimized for images. To ensure maximum throughput, you’re encouraged to explore other dataset formats like <a href="https://webdataset.github.io/webdataset/" rel="nofollow">WebDataset</a>, <a href="https://github.com/pytorch/data" rel="nofollow">TorchData</a>, and <a href="https://www.tensorflow.org/datasets/tfless_tfds" rel="nofollow">TensorFlow Datasets</a>.';return{c(){a=h("p"),a.innerHTML=u},l(i){a=M(i,"P",{"data-svelte-h":!0}),g(a)!=="svelte-onyuom"&&(a.innerHTML=u)},m(i,p){n(i,a,p)},p:Y,d(i){i&&t(a)}}}function Rl(W){let a,u="On a 16GB GPU, you can use bitsandbytes 8-bit optimizer and gradient checkpointing to optimize your training run. Install bitsandbytes:",i,p,r,f,m="Then, add the following parameter to your training command:",v,Z,C;return p=new G({props:{code:"cGlwJTIwaW5zdGFsbCUyMGJpdHNhbmRieXRlcw==",highlighted:"pip install bitsandbytes",wrap:!1}}),Z=new G({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2NvbnRyb2xuZXQucHklMjAlNUMlMEElMjAlMjAtLWdyYWRpZW50X2NoZWNrcG9pbnRpbmclMjAlNUMlMEElMjAlMjAtLXVzZV84Yml0X2FkYW0lMjAlNUM=",highlighted:`accelerate launch train_controlnet.py \\
  --gradient_checkpointing \\
  --use_8bit_adam \\`,wrap:!1}}),{c(){a=h("p"),a.textContent=u,i=s(),y(p.$$.fragment),r=s(),f=h("p"),f.textContent=m,v=s(),y(Z.$$.fragment)},l(c){a=M(c,"P",{"data-svelte-h":!0}),g(a)!=="svelte-izoj73"&&(a.textContent=u),i=o(c),w(p.$$.fragment,c),r=o(c),f=M(c,"P",{"data-svelte-h":!0}),g(f)!=="svelte-1rkm1uq"&&(f.textContent=m),v=o(c),w(Z.$$.fragment,c)},m(c,x){n(c,a,x),n(c,i,x),T(p,c,x),n(c,r,x),n(c,f,x),n(c,v,x),T(Z,c,x),C=!0},p:Y,i(c){C||(J(p.$$.fragment,c),J(Z.$$.fragment,c),C=!0)},o(c){U(p.$$.fragment,c),U(Z.$$.fragment,c),C=!1},d(c){c&&(t(a),t(i),t(r),t(f),t(v)),_(p,c),_(Z,c)}}}function Gl(W){let a,u="On a 12GB GPU, you’ll need bitsandbytes 8-bit optimizer, gradient checkpointing, xFormers, and set the gradients to <code>None</code> instead of zero to reduce your memory-usage.",i,p,r;return p=new G({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(){a=h("p"),a.innerHTML=u,i=s(),y(p.$$.fragment)},l(f){a=M(f,"P",{"data-svelte-h":!0}),g(a)!=="svelte-13zq302"&&(a.innerHTML=u),i=o(f),w(p.$$.fragment,f)},m(f,m){n(f,a,m),n(f,i,m),T(p,f,m),r=!0},p:Y,i(f){r||(J(p.$$.fragment,f),r=!0)},o(f){U(p.$$.fragment,f),r=!1},d(f){f&&(t(a),t(i)),_(p,f)}}}function Il(W){let a,u='On a 8GB GPU, you’ll need to use <a href="https://www.deepspeed.ai/" rel="nofollow">DeepSpeed</a> to offload some of the tensors from the vRAM to either the CPU or NVME to allow training with less GPU memory.',i,p,r="Run the following command to configure your 🤗 Accelerate environment:",f,m,v,Z,C='During configuration, confirm that you want to use DeepSpeed stage 2. Now it should be possible to train on under 8GB vRAM by combining DeepSpeed stage 2, fp16 mixed precision, and offloading the model parameters and the optimizer state to the CPU. The drawback is that this requires more system RAM (~25 GB). See the <a href="https://huggingface.co/docs/accelerate/usage_guides/deepspeed" rel="nofollow">DeepSpeed documentation</a> for more configuration options. Your configuration file should look something like:',c,x,d,j,X='You should also change the default Adam optimizer to DeepSpeed’s optimized version of Adam <a href="https://deepspeed.readthedocs.io/en/latest/optimizers.html#adam-cpu" rel="nofollow"><code>deepspeed.ops.adam.DeepSpeedCPUAdam</code></a> for a substantial speedup. Enabling <code>DeepSpeedCPUAdam</code> requires your system’s CUDA toolchain version to be the same as the one installed with PyTorch.',$,I,S="bitsandbytes 8-bit optimizers don’t seem to be compatible with DeepSpeed at the moment.",N,k,B="That’s it! You don’t need to add any additional parameters to your training command.",z;return m=new G({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),x=new G({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(){a=h("p"),a.innerHTML=u,i=s(),p=h("p"),p.textContent=r,f=s(),y(m.$$.fragment),v=s(),Z=h("p"),Z.innerHTML=C,c=s(),y(x.$$.fragment),d=s(),j=h("p"),j.innerHTML=X,$=s(),I=h("p"),I.textContent=S,N=s(),k=h("p"),k.textContent=B},l(b){a=M(b,"P",{"data-svelte-h":!0}),g(a)!=="svelte-1tq9cba"&&(a.innerHTML=u),i=o(b),p=M(b,"P",{"data-svelte-h":!0}),g(p)!=="svelte-1fx999v"&&(p.textContent=r),f=o(b),w(m.$$.fragment,b),v=o(b),Z=M(b,"P",{"data-svelte-h":!0}),g(Z)!=="svelte-184kffk"&&(Z.innerHTML=C),c=o(b),w(x.$$.fragment,b),d=o(b),j=M(b,"P",{"data-svelte-h":!0}),g(j)!=="svelte-14m6rf5"&&(j.innerHTML=X),$=o(b),I=M(b,"P",{"data-svelte-h":!0}),g(I)!=="svelte-z8cdsf"&&(I.textContent=S),N=o(b),k=M(b,"P",{"data-svelte-h":!0}),g(k)!=="svelte-lwtx0u"&&(k.textContent=B)},m(b,R){n(b,a,R),n(b,i,R),n(b,p,R),n(b,f,R),T(m,b,R),n(b,v,R),n(b,Z,R),n(b,c,R),T(x,b,R),n(b,d,R),n(b,j,R),n(b,$,R),n(b,I,R),n(b,N,R),n(b,k,R),z=!0},p:Y,i(b){z||(J(m.$$.fragment,b),J(x.$$.fragment,b),z=!0)},o(b){U(m.$$.fragment,b),U(x.$$.fragment,b),z=!1},d(b){b&&(t(a),t(i),t(p),t(f),t(v),t(Z),t(c),t(d),t(j),t($),t(I),t(N),t(k)),_(m,b),_(x,b)}}}function Xl(W){let a,u,i,p,r,f;return a=new Be({props:{id:"gpu-select",option:"16GB",$$slots:{default:[Rl]},$$scope:{ctx:W}}}),i=new Be({props:{id:"gpu-select",option:"12GB",$$slots:{default:[Gl]},$$scope:{ctx:W}}}),r=new Be({props:{id:"gpu-select",option:"8GB",$$slots:{default:[Il]},$$scope:{ctx:W}}}),{c(){y(a.$$.fragment),u=s(),y(i.$$.fragment),p=s(),y(r.$$.fragment)},l(m){w(a.$$.fragment,m),u=o(m),w(i.$$.fragment,m),p=o(m),w(r.$$.fragment,m)},m(m,v){T(a,m,v),n(m,u,v),T(i,m,v),n(m,p,v),T(r,m,v),f=!0},p(m,v){const Z={};v&2&&(Z.$$scope={dirty:v,ctx:m}),a.$set(Z);const C={};v&2&&(C.$$scope={dirty:v,ctx:m}),i.$set(C);const c={};v&2&&(c.$$scope={dirty:v,ctx:m}),r.$set(c)},i(m){f||(J(a.$$.fragment,m),J(i.$$.fragment,m),J(r.$$.fragment,m),f=!0)},o(m){U(a.$$.fragment,m),U(i.$$.fragment,m),U(r.$$.fragment,m),f=!1},d(m){m&&(t(u),t(p)),_(a,m),_(i,m),_(r,m)}}}function Nl(W){let a,u;return a=new G({props:{code:"ZXhwb3J0JTIwTU9ERUxfRElSJTNEJTIycnVud2F5bWwlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMEFleHBvcnQlMjBPVVRQVVRfRElSJTNEJTIycGF0aCUyRnRvJTJGc2F2ZSUyRm1vZGVsJTIyJTBBJTBBYWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2NvbnRyb2xuZXQucHklMjAlNUMlMEElMjAtLXByZXRyYWluZWRfbW9kZWxfbmFtZV9vcl9wYXRoJTNEJTI0TU9ERUxfRElSJTIwJTVDJTBBJTIwLS1vdXRwdXRfZGlyJTNEJTI0T1VUUFVUX0RJUiUyMCU1QyUwQSUyMC0tZGF0YXNldF9uYW1lJTNEZnVzaW5nJTJGZmlsbDUwayUyMCU1QyUwQSUyMC0tcmVzb2x1dGlvbiUzRDUxMiUyMCU1QyUwQSUyMC0tbGVhcm5pbmdfcmF0ZSUzRDFlLTUlMjAlNUMlMEElMjAtLXZhbGlkYXRpb25faW1hZ2UlMjAlMjIuJTJGY29uZGl0aW9uaW5nX2ltYWdlXzEucG5nJTIyJTIwJTIyLiUyRmNvbmRpdGlvbmluZ19pbWFnZV8yLnBuZyUyMiUyMCU1QyUwQSUyMC0tdmFsaWRhdGlvbl9wcm9tcHQlMjAlMjJyZWQlMjBjaXJjbGUlMjB3aXRoJTIwYmx1ZSUyMGJhY2tncm91bmQlMjIlMjAlMjJjeWFuJTIwY2lyY2xlJTIwd2l0aCUyMGJyb3duJTIwZmxvcmFsJTIwYmFja2dyb3VuZCUyMiUyMCU1QyUwQSUyMC0tdHJhaW5fYmF0Y2hfc2l6ZSUzRDElMjAlNUMlMEElMjAtLWdyYWRpZW50X2FjY3VtdWxhdGlvbl9zdGVwcyUzRDQlMjAlNUMlMEElMjAtLXB1c2hfdG9faHVi",highlighted:`<span class="hljs-built_in">export</span> MODEL_DIR=<span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;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(){y(a.$$.fragment)},l(i){w(a.$$.fragment,i)},m(i,p){T(a,i,p),u=!0},p:Y,i(i){u||(J(a.$$.fragment,i),u=!0)},o(i){U(a.$$.fragment,i),u=!1},d(i){_(a,i)}}}function kl(W){let a,u="If you run into version conflicts with the plugin, try uninstalling and reinstalling all versions of TensorFlow and Tensorboard. The debugging functionality of the profile plugin is still experimental, and not all views are fully functional. The <code>trace_viewer</code> cuts off events after 1M, which can result in all your device traces getting lost if for example, you profile the compilation step by accident.";return{c(){a=h("p"),a.innerHTML=u},l(i){a=M(i,"P",{"data-svelte-h":!0}),g(a)!=="svelte-1yoxzv4"&&(a.innerHTML=u)},m(i,p){n(i,a,p)},p:Y,d(i){i&&t(a)}}}function Bl(W){let a,u='With Flax, you can <a href="https://jax.readthedocs.io/en/latest/profiling.html" rel="nofollow">profile your code</a> by adding the <code>--profile_steps==5</code> parameter to your training command. Install the Tensorboard profile plugin:',i,p,r,f,m='Then you can inspect the profile at <a href="http://localhost:6006/#profile" rel="nofollow">http://localhost:6006/#profile</a>.',v,Z,C,c,x;return p=new G({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRlbnNvcmZsb3clMjB0ZW5zb3Jib2FyZC1wbHVnaW4tcHJvZmlsZSUwQXRlbnNvcmJvYXJkJTIwLS1sb2dkaXIlMjBydW5zJTJGZmlsbC1jaXJjbGUtMTAwc3RlcHMtMjAyMzA0MTFfMTY1NjEyJTJG",highlighted:`pip install tensorflow tensorboard-plugin-profile
tensorboard --logdir runs/fill-circle-100steps-20230411_165612/`,wrap:!1}}),Z=new kt({props:{warning:!0,$$slots:{default:[kl]},$$scope:{ctx:W}}}),c=new G({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(){a=h("p"),a.innerHTML=u,i=s(),y(p.$$.fragment),r=s(),f=h("p"),f.innerHTML=m,v=s(),y(Z.$$.fragment),C=s(),y(c.$$.fragment)},l(d){a=M(d,"P",{"data-svelte-h":!0}),g(a)!=="svelte-10g27jr"&&(a.innerHTML=u),i=o(d),w(p.$$.fragment,d),r=o(d),f=M(d,"P",{"data-svelte-h":!0}),g(f)!=="svelte-q8hcb8"&&(f.innerHTML=m),v=o(d),w(Z.$$.fragment,d),C=o(d),w(c.$$.fragment,d)},m(d,j){n(d,a,j),n(d,i,j),T(p,d,j),n(d,r,j),n(d,f,j),n(d,v,j),T(Z,d,j),n(d,C,j),T(c,d,j),x=!0},p(d,j){const X={};j&2&&(X.$$scope={dirty:j,ctx:d}),Z.$set(X)},i(d){x||(J(p.$$.fragment,d),J(Z.$$.fragment,d),J(c.$$.fragment,d),x=!0)},o(d){U(p.$$.fragment,d),U(Z.$$.fragment,d),U(c.$$.fragment,d),x=!1},d(d){d&&(t(a),t(i),t(r),t(f),t(v),t(C)),_(p,d),_(Z,d),_(c,d)}}}function Yl(W){let a,u,i,p;return a=new Be({props:{id:"training-inference",option:"PyTorch",$$slots:{default:[Nl]},$$scope:{ctx:W}}}),i=new Be({props:{id:"training-inference",option:"Flax",$$slots:{default:[Bl]},$$scope:{ctx:W}}}),{c(){y(a.$$.fragment),u=s(),y(i.$$.fragment)},l(r){w(a.$$.fragment,r),u=o(r),w(i.$$.fragment,r)},m(r,f){T(a,r,f),n(r,u,f),T(i,r,f),p=!0},p(r,f){const m={};f&2&&(m.$$scope={dirty:f,ctx:r}),a.$set(m);const v={};f&2&&(v.$$scope={dirty:f,ctx:r}),i.$set(v)},i(r){p||(J(a.$$.fragment,r),J(i.$$.fragment,r),p=!0)},o(r){U(a.$$.fragment,r),U(i.$$.fragment,r),p=!1},d(r){r&&t(u),_(a,r),_(i,r)}}}function Hl(W){let a,u,i,p,r,f,m,v='<a href="https://hf.co/papers/2302.05543" rel="nofollow">ControlNet</a> models are adapters trained on top of another pretrained model. It allows for a greater degree of control over image generation by conditioning the model with an additional input image. The input image can be a canny edge, depth map, human pose, and many more.',Z,C,c='If you’re training on a GPU with limited vRAM, you should try enabling the <code>gradient_checkpointing</code>, <code>gradient_accumulation_steps</code>, and <code>mixed_precision</code> parameters in the training command. You can also reduce your memory footprint by using memory-efficient attention with <a href="../optimization/xformers">xFormers</a>. JAX/Flax training is also supported for efficient training on TPUs and GPUs, but it doesn’t support gradient checkpointing or xFormers. You should have a GPU with &gt;30GB of memory if you want to train faster with Flax.',x,d,j='This guide will explore the <a href="https://github.com/huggingface/diffusers/blob/main/examples/controlnet/train_controlnet.py" rel="nofollow">train_controlnet.py</a> training script to help you become familiar with it, and how you can adapt it for your own use-case.',X,$,I="Before running the script, make sure you install the library from source:",S,N,k,B,z="Then navigate to the example folder containing the training script and install the required dependencies for the script you’re using:",b,R,He,H,Ee,Q,Yt="Initialize an 🤗 Accelerate environment:",Le,A,Ve,P,Ht="To setup a default 🤗 Accelerate environment without choosing any configurations:",Fe,q,Se,D,Et="Or if your environment doesn’t support an interactive shell, like a notebook, you can use:",ze,O,Qe,K,Lt='Lastly, if you want to train a model on your own dataset, take a look at the <a href="create_dataset">Create a dataset for training</a> guide to learn how to create a dataset that works with the training script.',Ae,E,Pe,ee,qe,te,Vt='The training script provides many parameters to help you customize your training run. All of the parameters and their descriptions are found in the <a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L231" rel="nofollow"><code>parse_args()</code></a> function. This function provides default values for each parameter, such as the training batch size and learning rate, but you can also set your own values in the training command if you’d like.',De,le,Ft="For example, to speedup training with mixed precision using the fp16 format, add the <code>--mixed_precision</code> parameter to the training command:",Oe,ne,Ke,ae,St='Many of the basic and important parameters are described in the <a href="text2image#script-parameters">Text-to-image</a> training guide, so this guide just focuses on the relevant parameters for ControlNet:',et,ie,zt="<li><code>--max_train_samples</code>: the number of training samples; this can be lowered for faster training, but if you want to stream really large datasets, you’ll need to include this parameter and the <code>--streaming</code> parameter in your training command</li> <li><code>--gradient_accumulation_steps</code>: number of update steps to accumulate before the backward pass; this allows you to train with a bigger batch size than your GPU memory can typically handle</li>",tt,se,lt,oe,Qt='The <a href="https://huggingface.co/papers/2303.09556" rel="nofollow">Min-SNR</a> weighting strategy can help with training by rebalancing the loss to achieve faster convergence. The training script supports predicting <code>epsilon</code> (noise) or <code>v_prediction</code>, but Min-SNR is compatible with both prediction types. This weighting strategy is only supported by PyTorch and is unavailable in the Flax training script.',nt,re,At="Add the <code>--snr_gamma</code> parameter and set it to the recommended value of 5.0:",at,pe,it,fe,st,me,Pt='As with the script parameters, a general walkthrough of the training script is provided in the <a href="text2image#training-script">Text-to-image</a> training guide. Instead, this guide takes a look at the relevant parts of the ControlNet script.',ot,ue,qt='The training script has a <a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L582" rel="nofollow"><code>make_train_dataset</code></a> function for preprocessing the dataset with image transforms and caption tokenization. You’ll see that in addition to the usual caption tokenization and image transforms, the script also includes transforms for the conditioning image.',rt,L,pt,ce,ft,de,Dt='Within the <a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L713" rel="nofollow"><code>main()</code></a> function, you’ll find the code for loading the tokenizer, text encoder, scheduler and models. This is also where the ControlNet model is loaded either from existing weights or randomly initialized from a UNet:',mt,he,ut,Me,Ot='The <a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L871" rel="nofollow">optimizer</a> is set up to update the ControlNet parameters:',ct,$e,dt,ge,Kt='Finally, in the <a href="https://github.com/huggingface/diffusers/blob/64603389da01082055a901f2883c4810d1144edb/examples/controlnet/train_controlnet.py#L943" rel="nofollow">training loop</a>, the conditioning text embeddings and image are passed to the down and mid-blocks of the ControlNet model:',ht,be,Mt,ye,el='If you want to learn more about how the training loop works, check out the <a href="../using-diffusers/write_own_pipeline">Understanding pipelines, models and schedulers</a> tutorial which breaks down the basic pattern of the denoising process.',$t,we,gt,Te,tl="Now you’re ready to launch the training script! 🚀",bt,Je,ll='This guide uses the <a href="https://huggingface.co/datasets/fusing/fill50k" rel="nofollow">fusing/fill50k</a> dataset, but remember, you can create and use your own dataset if you want (see the <a href="create_dataset">Create a dataset for training</a> guide).',yt,Ue,nl="Set the environment variable <code>MODEL_NAME</code> to a model id on the Hub or a path to a local model and <code>OUTPUT_DIR</code> to where you want to save the model.",wt,_e,al="Download the following images to condition your training with:",Tt,ve,Jt,Ze,il="One more thing before you launch the script! Depending on the GPU you have, you may need to enable certain optimizations to train a ControlNet. The default configuration in this script requires ~38GB of vRAM. If you’re training on more than one GPU, add the <code>--multi_gpu</code> parameter to the <code>accelerate launch</code> command.",Ut,V,_t,F,vt,je,sl="Once training is complete, you can use your newly trained model for inference!",Zt,We,jt,Ce,Wt,xe,ol='Stable Diffusion XL (SDXL) is a powerful text-to-image model that generates high-resolution images, and it adds a second text-encoder to its architecture. Use the <a href="https://github.com/huggingface/diffusers/blob/main/examples/controlnet/train_controlnet_sdxl.py" rel="nofollow"><code>train_controlnet_sdxl.py</code></a> script to train a ControlNet adapter for the SDXL model.',Ct,Re,rl='The SDXL training script is discussed in more detail in the <a href="sdxl">SDXL training</a> guide.',xt,Ge,Rt,Ie,pl="Congratulations on training your own ControlNet! To learn more about how to use your new model, the following guides may be helpful:",Gt,Xe,fl='<li>Learn how to <a href="../using-diffusers/controlnet">use a ControlNet</a> for inference on a variety of tasks.</li>',It,Ne,Xt,Ye,Nt;return r=new ke({props:{title:"ControlNet",local:"controlnet",headingTag:"h1"}}),N=new G({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}}),R=new Bt({props:{id:"installation",options:["PyTorch","Flax"],$$slots:{default:[jl]},$$scope:{ctx:W}}}),H=new kt({props:{$$slots:{default:[Wl]},$$scope:{ctx:W}}}),A=new G({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),q=new G({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZyUyMGRlZmF1bHQ=",highlighted:"accelerate config default",wrap:!1}}),O=new G({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 kt({props:{$$slots:{default:[Cl]},$$scope:{ctx:W}}}),ee=new ke({props:{title:"Script parameters",local:"script-parameters",headingTag:"h2"}}),ne=new G({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2NvbnRyb2xuZXQucHklMjAlNUMlMEElMjAlMjAtLW1peGVkX3ByZWNpc2lvbiUzRCUyMmZwMTYlMjI=",highlighted:`accelerate launch train_controlnet.py \\
  --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span>`,wrap:!1}}),se=new ke({props:{title:"Min-SNR weighting",local:"min-snr-weighting",headingTag:"h3"}}),pe=new G({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2NvbnRyb2xuZXQucHklMjAlNUMlMEElMjAlMjAtLXNucl9nYW1tYSUzRDUuMA==",highlighted:`accelerate launch train_controlnet.py \\
  --snr_gamma=5.0`,wrap:!1}}),fe=new ke({props:{title:"Training script",local:"training-script",headingTag:"h2"}}),L=new kt({props:{$$slots:{default:[xl]},$$scope:{ctx:W}}}),ce=new G({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}}),he=new G({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}}),$e=new G({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}}),be=new G({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}}),we=new ke({props:{title:"Launch the script",local:"launch-the-script",headingTag:"h2"}}),ve=new G({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}}),V=new Bt({props:{id:"gpu-select",options:["16GB","12GB","8GB"],$$slots:{default:[Xl]},$$scope:{ctx:W}}}),F=new Bt({props:{id:"training-inference",options:["PyTorch","Flax"],$$slots:{default:[Yl]},$$scope:{ctx:W}}}),We=new G({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvbkNvbnRyb2xOZXRQaXBlbGluZSUyQyUyMENvbnRyb2xOZXRNb2RlbCUwQWZyb20lMjBkaWZmdXNlcnMudXRpbHMlMjBpbXBvcnQlMjBsb2FkX2ltYWdlJTBBaW1wb3J0JTIwdG9yY2glMEElMEFjb250cm9sbmV0JTIwJTNEJTIwQ29udHJvbE5ldE1vZGVsLmZyb21fcHJldHJhaW5lZCglMjJwYXRoJTJGdG8lMkZjb250cm9sbmV0JTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2KSUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uQ29udHJvbE5ldFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJwYXRoJTJGdG8lMkZiYXNlJTJGbW9kZWwlMjIlMkMlMjBjb250cm9sbmV0JTNEY29udHJvbG5ldCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUwQSkudG8oJTIyY3VkYSUyMiklMEElMEFjb250cm9sX2ltYWdlJTIwJTNEJTIwbG9hZF9pbWFnZSglMjIuJTJGY29uZGl0aW9uaW5nX2ltYWdlXzEucG5nJTIyKSUwQXByb21wdCUyMCUzRCUyMCUyMnBhbGUlMjBnb2xkZW4lMjByb2QlMjBjaXJjbGUlMjB3aXRoJTIwb2xkJTIwbGFjZSUyMGJhY2tncm91bmQlMjIlMEElMEFnZW5lcmF0b3IlMjAlM0QlMjB0b3JjaC5tYW51YWxfc2VlZCgwKSUwQWltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEMjAlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IlMkMlMjBpbWFnZSUzRGNvbnRyb2xfaW1hZ2UpLmltYWdlcyU1QjAlNUQlMEFpbWFnZS5zYXZlKCUyMi4lMkZvdXRwdXQucG5nJTIyKQ==",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 = pipe(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}}),Ce=new ke({props:{title:"Stable Diffusion XL",local:"stable-diffusion-xl",headingTag:"h2"}}),Ge=new ke({props:{title:"Next steps",local:"next-steps",headingTag:"h2"}}),Ne=new _l({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/training/controlnet.md"}}),{c(){a=h("meta"),u=s(),i=h("p"),p=s(),y(r.$$.fragment),f=s(),m=h("p"),m.innerHTML=v,Z=s(),C=h("p"),C.innerHTML=c,x=s(),d=h("p"),d.innerHTML=j,X=s(),$=h("p"),$.textContent=I,S=s(),y(N.$$.fragment),k=s(),B=h("p"),B.textContent=z,b=s(),y(R.$$.fragment),He=s(),y(H.$$.fragment),Ee=s(),Q=h("p"),Q.textContent=Yt,Le=s(),y(A.$$.fragment),Ve=s(),P=h("p"),P.textContent=Ht,Fe=s(),y(q.$$.fragment),Se=s(),D=h("p"),D.textContent=Et,ze=s(),y(O.$$.fragment),Qe=s(),K=h("p"),K.innerHTML=Lt,Ae=s(),y(E.$$.fragment),Pe=s(),y(ee.$$.fragment),qe=s(),te=h("p"),te.innerHTML=Vt,De=s(),le=h("p"),le.innerHTML=Ft,Oe=s(),y(ne.$$.fragment),Ke=s(),ae=h("p"),ae.innerHTML=St,et=s(),ie=h("ul"),ie.innerHTML=zt,tt=s(),y(se.$$.fragment),lt=s(),oe=h("p"),oe.innerHTML=Qt,nt=s(),re=h("p"),re.innerHTML=At,at=s(),y(pe.$$.fragment),it=s(),y(fe.$$.fragment),st=s(),me=h("p"),me.innerHTML=Pt,ot=s(),ue=h("p"),ue.innerHTML=qt,rt=s(),y(L.$$.fragment),pt=s(),y(ce.$$.fragment),ft=s(),de=h("p"),de.innerHTML=Dt,mt=s(),y(he.$$.fragment),ut=s(),Me=h("p"),Me.innerHTML=Ot,ct=s(),y($e.$$.fragment),dt=s(),ge=h("p"),ge.innerHTML=Kt,ht=s(),y(be.$$.fragment),Mt=s(),ye=h("p"),ye.innerHTML=el,$t=s(),y(we.$$.fragment),gt=s(),Te=h("p"),Te.textContent=tl,bt=s(),Je=h("p"),Je.innerHTML=ll,yt=s(),Ue=h("p"),Ue.innerHTML=nl,wt=s(),_e=h("p"),_e.textContent=al,Tt=s(),y(ve.$$.fragment),Jt=s(),Ze=h("p"),Ze.innerHTML=il,Ut=s(),y(V.$$.fragment),_t=s(),y(F.$$.fragment),vt=s(),je=h("p"),je.textContent=sl,Zt=s(),y(We.$$.fragment),jt=s(),y(Ce.$$.fragment),Wt=s(),xe=h("p"),xe.innerHTML=ol,Ct=s(),Re=h("p"),Re.innerHTML=rl,xt=s(),y(Ge.$$.fragment),Rt=s(),Ie=h("p"),Ie.textContent=pl,Gt=s(),Xe=h("ul"),Xe.innerHTML=fl,It=s(),y(Ne.$$.fragment),Xt=s(),Ye=h("p"),this.h()},l(e){const l=Jl("svelte-u9bgzb",document.head);a=M(l,"META",{name:!0,content:!0}),l.forEach(t),u=o(e),i=M(e,"P",{}),$l(i).forEach(t),p=o(e),w(r.$$.fragment,e),f=o(e),m=M(e,"P",{"data-svelte-h":!0}),g(m)!=="svelte-q2o66i"&&(m.innerHTML=v),Z=o(e),C=M(e,"P",{"data-svelte-h":!0}),g(C)!=="svelte-l104r8"&&(C.innerHTML=c),x=o(e),d=M(e,"P",{"data-svelte-h":!0}),g(d)!=="svelte-sp8ken"&&(d.innerHTML=j),X=o(e),$=M(e,"P",{"data-svelte-h":!0}),g($)!=="svelte-l7dm2q"&&($.textContent=I),S=o(e),w(N.$$.fragment,e),k=o(e),B=M(e,"P",{"data-svelte-h":!0}),g(B)!=="svelte-z4z0b9"&&(B.textContent=z),b=o(e),w(R.$$.fragment,e),He=o(e),w(H.$$.fragment,e),Ee=o(e),Q=M(e,"P",{"data-svelte-h":!0}),g(Q)!=="svelte-60q53m"&&(Q.textContent=Yt),Le=o(e),w(A.$$.fragment,e),Ve=o(e),P=M(e,"P",{"data-svelte-h":!0}),g(P)!=="svelte-di6juu"&&(P.textContent=Ht),Fe=o(e),w(q.$$.fragment,e),Se=o(e),D=M(e,"P",{"data-svelte-h":!0}),g(D)!=="svelte-tsz4qp"&&(D.textContent=Et),ze=o(e),w(O.$$.fragment,e),Qe=o(e),K=M(e,"P",{"data-svelte-h":!0}),g(K)!=="svelte-1fkfdql"&&(K.innerHTML=Lt),Ae=o(e),w(E.$$.fragment,e),Pe=o(e),w(ee.$$.fragment,e),qe=o(e),te=M(e,"P",{"data-svelte-h":!0}),g(te)!=="svelte-bw2u91"&&(te.innerHTML=Vt),De=o(e),le=M(e,"P",{"data-svelte-h":!0}),g(le)!=="svelte-1r0bv1x"&&(le.innerHTML=Ft),Oe=o(e),w(ne.$$.fragment,e),Ke=o(e),ae=M(e,"P",{"data-svelte-h":!0}),g(ae)!=="svelte-1s0tjh8"&&(ae.innerHTML=St),et=o(e),ie=M(e,"UL",{"data-svelte-h":!0}),g(ie)!=="svelte-9wifrj"&&(ie.innerHTML=zt),tt=o(e),w(se.$$.fragment,e),lt=o(e),oe=M(e,"P",{"data-svelte-h":!0}),g(oe)!=="svelte-isitbv"&&(oe.innerHTML=Qt),nt=o(e),re=M(e,"P",{"data-svelte-h":!0}),g(re)!=="svelte-tp3kp"&&(re.innerHTML=At),at=o(e),w(pe.$$.fragment,e),it=o(e),w(fe.$$.fragment,e),st=o(e),me=M(e,"P",{"data-svelte-h":!0}),g(me)!=="svelte-1ca6n8s"&&(me.innerHTML=Pt),ot=o(e),ue=M(e,"P",{"data-svelte-h":!0}),g(ue)!=="svelte-yhtkem"&&(ue.innerHTML=qt),rt=o(e),w(L.$$.fragment,e),pt=o(e),w(ce.$$.fragment,e),ft=o(e),de=M(e,"P",{"data-svelte-h":!0}),g(de)!=="svelte-1t15wny"&&(de.innerHTML=Dt),mt=o(e),w(he.$$.fragment,e),ut=o(e),Me=M(e,"P",{"data-svelte-h":!0}),g(Me)!=="svelte-1rtudr1"&&(Me.innerHTML=Ot),ct=o(e),w($e.$$.fragment,e),dt=o(e),ge=M(e,"P",{"data-svelte-h":!0}),g(ge)!=="svelte-ane16q"&&(ge.innerHTML=Kt),ht=o(e),w(be.$$.fragment,e),Mt=o(e),ye=M(e,"P",{"data-svelte-h":!0}),g(ye)!=="svelte-6gmbd2"&&(ye.innerHTML=el),$t=o(e),w(we.$$.fragment,e),gt=o(e),Te=M(e,"P",{"data-svelte-h":!0}),g(Te)!=="svelte-rsq2yy"&&(Te.textContent=tl),bt=o(e),Je=M(e,"P",{"data-svelte-h":!0}),g(Je)!=="svelte-87boqf"&&(Je.innerHTML=ll),yt=o(e),Ue=M(e,"P",{"data-svelte-h":!0}),g(Ue)!=="svelte-11t01x0"&&(Ue.innerHTML=nl),wt=o(e),_e=M(e,"P",{"data-svelte-h":!0}),g(_e)!=="svelte-1uo0m2d"&&(_e.textContent=al),Tt=o(e),w(ve.$$.fragment,e),Jt=o(e),Ze=M(e,"P",{"data-svelte-h":!0}),g(Ze)!=="svelte-1wlzzvk"&&(Ze.innerHTML=il),Ut=o(e),w(V.$$.fragment,e),_t=o(e),w(F.$$.fragment,e),vt=o(e),je=M(e,"P",{"data-svelte-h":!0}),g(je)!=="svelte-1x6in5t"&&(je.textContent=sl),Zt=o(e),w(We.$$.fragment,e),jt=o(e),w(Ce.$$.fragment,e),Wt=o(e),xe=M(e,"P",{"data-svelte-h":!0}),g(xe)!=="svelte-t1l7wa"&&(xe.innerHTML=ol),Ct=o(e),Re=M(e,"P",{"data-svelte-h":!0}),g(Re)!=="svelte-6dxtva"&&(Re.innerHTML=rl),xt=o(e),w(Ge.$$.fragment,e),Rt=o(e),Ie=M(e,"P",{"data-svelte-h":!0}),g(Ie)!=="svelte-s6fbj8"&&(Ie.textContent=pl),Gt=o(e),Xe=M(e,"UL",{"data-svelte-h":!0}),g(Xe)!=="svelte-jinr48"&&(Xe.innerHTML=fl),It=o(e),w(Ne.$$.fragment,e),Xt=o(e),Ye=M(e,"P",{}),$l(Ye).forEach(t),this.h()},h(){gl(a,"name","hf:doc:metadata"),gl(a,"content",El)},m(e,l){Ul(document.head,a),n(e,u,l),n(e,i,l),n(e,p,l),T(r,e,l),n(e,f,l),n(e,m,l),n(e,Z,l),n(e,C,l),n(e,x,l),n(e,d,l),n(e,X,l),n(e,$,l),n(e,S,l),T(N,e,l),n(e,k,l),n(e,B,l),n(e,b,l),T(R,e,l),n(e,He,l),T(H,e,l),n(e,Ee,l),n(e,Q,l),n(e,Le,l),T(A,e,l),n(e,Ve,l),n(e,P,l),n(e,Fe,l),T(q,e,l),n(e,Se,l),n(e,D,l),n(e,ze,l),T(O,e,l),n(e,Qe,l),n(e,K,l),n(e,Ae,l),T(E,e,l),n(e,Pe,l),T(ee,e,l),n(e,qe,l),n(e,te,l),n(e,De,l),n(e,le,l),n(e,Oe,l),T(ne,e,l),n(e,Ke,l),n(e,ae,l),n(e,et,l),n(e,ie,l),n(e,tt,l),T(se,e,l),n(e,lt,l),n(e,oe,l),n(e,nt,l),n(e,re,l),n(e,at,l),T(pe,e,l),n(e,it,l),T(fe,e,l),n(e,st,l),n(e,me,l),n(e,ot,l),n(e,ue,l),n(e,rt,l),T(L,e,l),n(e,pt,l),T(ce,e,l),n(e,ft,l),n(e,de,l),n(e,mt,l),T(he,e,l),n(e,ut,l),n(e,Me,l),n(e,ct,l),T($e,e,l),n(e,dt,l),n(e,ge,l),n(e,ht,l),T(be,e,l),n(e,Mt,l),n(e,ye,l),n(e,$t,l),T(we,e,l),n(e,gt,l),n(e,Te,l),n(e,bt,l),n(e,Je,l),n(e,yt,l),n(e,Ue,l),n(e,wt,l),n(e,_e,l),n(e,Tt,l),T(ve,e,l),n(e,Jt,l),n(e,Ze,l),n(e,Ut,l),T(V,e,l),n(e,_t,l),T(F,e,l),n(e,vt,l),n(e,je,l),n(e,Zt,l),T(We,e,l),n(e,jt,l),T(Ce,e,l),n(e,Wt,l),n(e,xe,l),n(e,Ct,l),n(e,Re,l),n(e,xt,l),T(Ge,e,l),n(e,Rt,l),n(e,Ie,l),n(e,Gt,l),n(e,Xe,l),n(e,It,l),T(Ne,e,l),n(e,Xt,l),n(e,Ye,l),Nt=!0},p(e,[l]){const ml={};l&2&&(ml.$$scope={dirty:l,ctx:e}),R.$set(ml);const ul={};l&2&&(ul.$$scope={dirty:l,ctx:e}),H.$set(ul);const cl={};l&2&&(cl.$$scope={dirty:l,ctx:e}),E.$set(cl);const dl={};l&2&&(dl.$$scope={dirty:l,ctx:e}),L.$set(dl);const hl={};l&2&&(hl.$$scope={dirty:l,ctx:e}),V.$set(hl);const Ml={};l&2&&(Ml.$$scope={dirty:l,ctx:e}),F.$set(Ml)},i(e){Nt||(J(r.$$.fragment,e),J(N.$$.fragment,e),J(R.$$.fragment,e),J(H.$$.fragment,e),J(A.$$.fragment,e),J(q.$$.fragment,e),J(O.$$.fragment,e),J(E.$$.fragment,e),J(ee.$$.fragment,e),J(ne.$$.fragment,e),J(se.$$.fragment,e),J(pe.$$.fragment,e),J(fe.$$.fragment,e),J(L.$$.fragment,e),J(ce.$$.fragment,e),J(he.$$.fragment,e),J($e.$$.fragment,e),J(be.$$.fragment,e),J(we.$$.fragment,e),J(ve.$$.fragment,e),J(V.$$.fragment,e),J(F.$$.fragment,e),J(We.$$.fragment,e),J(Ce.$$.fragment,e),J(Ge.$$.fragment,e),J(Ne.$$.fragment,e),Nt=!0)},o(e){U(r.$$.fragment,e),U(N.$$.fragment,e),U(R.$$.fragment,e),U(H.$$.fragment,e),U(A.$$.fragment,e),U(q.$$.fragment,e),U(O.$$.fragment,e),U(E.$$.fragment,e),U(ee.$$.fragment,e),U(ne.$$.fragment,e),U(se.$$.fragment,e),U(pe.$$.fragment,e),U(fe.$$.fragment,e),U(L.$$.fragment,e),U(ce.$$.fragment,e),U(he.$$.fragment,e),U($e.$$.fragment,e),U(be.$$.fragment,e),U(we.$$.fragment,e),U(ve.$$.fragment,e),U(V.$$.fragment,e),U(F.$$.fragment,e),U(We.$$.fragment,e),U(Ce.$$.fragment,e),U(Ge.$$.fragment,e),U(Ne.$$.fragment,e),Nt=!1},d(e){e&&(t(u),t(i),t(p),t(f),t(m),t(Z),t(C),t(x),t(d),t(X),t($),t(S),t(k),t(B),t(b),t(He),t(Ee),t(Q),t(Le),t(Ve),t(P),t(Fe),t(Se),t(D),t(ze),t(Qe),t(K),t(Ae),t(Pe),t(qe),t(te),t(De),t(le),t(Oe),t(Ke),t(ae),t(et),t(ie),t(tt),t(lt),t(oe),t(nt),t(re),t(at),t(it),t(st),t(me),t(ot),t(ue),t(rt),t(pt),t(ft),t(de),t(mt),t(ut),t(Me),t(ct),t(dt),t(ge),t(ht),t(Mt),t(ye),t($t),t(gt),t(Te),t(bt),t(Je),t(yt),t(Ue),t(wt),t(_e),t(Tt),t(Jt),t(Ze),t(Ut),t(_t),t(vt),t(je),t(Zt),t(jt),t(Wt),t(xe),t(Ct),t(Re),t(xt),t(Rt),t(Ie),t(Gt),t(Xe),t(It),t(Xt),t(Ye)),t(a),_(r,e),_(N,e),_(R,e),_(H,e),_(A,e),_(q,e),_(O,e),_(E,e),_(ee,e),_(ne,e),_(se,e),_(pe,e),_(fe,e),_(L,e),_(ce,e),_(he,e),_($e,e),_(be,e),_(we,e),_(ve,e),_(V,e),_(F,e),_(We,e),_(Ce,e),_(Ge,e),_(Ne,e)}}}const El='{"title":"ControlNet","local":"controlnet","sections":[{"title":"Script parameters","local":"script-parameters","sections":[{"title":"Min-SNR weighting","local":"min-snr-weighting","sections":[],"depth":3}],"depth":2},{"title":"Training script","local":"training-script","sections":[],"depth":2},{"title":"Launch the script","local":"launch-the-script","sections":[],"depth":2},{"title":"Stable Diffusion XL","local":"stable-diffusion-xl","sections":[],"depth":2},{"title":"Next steps","local":"next-steps","sections":[],"depth":2}],"depth":1}';function Ll(W){return yl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Pl extends wl{constructor(a){super(),Tl(this,a,Ll,Hl,bl,{})}}export{Pl as component};
