import{s as bl,o as wl,n as V}from"../chunks/scheduler.8c3d61f6.js";import{S as yl,i as Tl,g as h,s,r as w,A as Jl,h as M,f as t,c as o,j as $l,u as y,x as g,k as gl,y as _l,a as n,v as T,d as J,t as _,w as U}from"../chunks/index.da70eac4.js";import{T as kt}from"../chunks/Tip.1d9b8c37.js";import{C as R}from"../chunks/CodeBlock.a9c4becf.js";import{H as ke,E as Ul}from"../chunks/getInferenceSnippets.a8672208.js";import{H as Bt,a as Be}from"../chunks/HfOption.6ab18950.js";function vl(W){let a,u;return a=new R({props:{code:"Y2QlMjBleGFtcGxlcyUyRmNvbnRyb2xuZXQlMEFwaXAlMjBpbnN0YWxsJTIwLXIlMjByZXF1aXJlbWVudHMudHh0",highlighted:`<span class="hljs-built_in">cd</span> examples/controlnet
pip install -r requirements.txt`,wrap:!1}}),{c(){w(a.$$.fragment)},l(i){y(a.$$.fragment,i)},m(i,p){T(a,i,p),u=!0},p:V,i(i){u||(J(a.$$.fragment,i),u=!0)},o(i){_(a.$$.fragment,i),u=!1},d(i){U(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,x,c,C="Then install the required dependencies for the Flax script:",d,j,G;return p=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}}),Z=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}}),j=new R({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(),w(p.$$.fragment),r=s(),f=h("p"),f.textContent=m,v=s(),w(Z.$$.fragment),x=s(),c=h("p"),c.textContent=C,d=s(),w(j.$$.fragment)},l($){a=M($,"P",{"data-svelte-h":!0}),g(a)!=="svelte-pcu1fk"&&(a.innerHTML=u),i=o($),y(p.$$.fragment,$),r=o($),f=M($,"P",{"data-svelte-h":!0}),g(f)!=="svelte-1a9obhp"&&(f.textContent=m),v=o($),y(Z.$$.fragment,$),x=o($),c=M($,"P",{"data-svelte-h":!0}),g(c)!=="svelte-2qk98r"&&(c.textContent=C),d=o($),y(j.$$.fragment,$)},m($,X){n($,a,X),n($,i,X),T(p,$,X),n($,r,X),n($,f,X),n($,v,X),T(Z,$,X),n($,x,X),n($,c,X),n($,d,X),T(j,$,X),G=!0},p:V,i($){G||(J(p.$$.fragment,$),J(Z.$$.fragment,$),J(j.$$.fragment,$),G=!0)},o($){_(p.$$.fragment,$),_(Z.$$.fragment,$),_(j.$$.fragment,$),G=!1},d($){$&&(t(a),t(i),t(r),t(f),t(v),t(x),t(c),t(d)),U(p,$),U(Z,$),U(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(){w(a.$$.fragment),u=s(),w(i.$$.fragment)},l(r){y(a.$$.fragment,r),u=o(r),y(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){_(a.$$.fragment,r),_(i.$$.fragment,r),p=!1},d(r){r&&t(u),U(a,r),U(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:V,d(i){i&&t(a)}}}function xl(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:V,d(i){i&&t(a)}}}function Cl(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:V,d(i){i&&t(a)}}}function Il(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,x;return p=new R({props:{code:"cGlwJTIwaW5zdGFsbCUyMGJpdHNhbmRieXRlcw==",highlighted:"pip install bitsandbytes",wrap:!1}}),Z=new R({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(),w(p.$$.fragment),r=s(),f=h("p"),f.textContent=m,v=s(),w(Z.$$.fragment)},l(c){a=M(c,"P",{"data-svelte-h":!0}),g(a)!=="svelte-izoj73"&&(a.textContent=u),i=o(c),y(p.$$.fragment,c),r=o(c),f=M(c,"P",{"data-svelte-h":!0}),g(f)!=="svelte-1rkm1uq"&&(f.textContent=m),v=o(c),y(Z.$$.fragment,c)},m(c,C){n(c,a,C),n(c,i,C),T(p,c,C),n(c,r,C),n(c,f,C),n(c,v,C),T(Z,c,C),x=!0},p:V,i(c){x||(J(p.$$.fragment,c),J(Z.$$.fragment,c),x=!0)},o(c){_(p.$$.fragment,c),_(Z.$$.fragment,c),x=!1},d(c){c&&(t(a),t(i),t(r),t(f),t(v)),U(p,c),U(Z,c)}}}function Rl(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 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(){a=h("p"),a.innerHTML=u,i=s(),w(p.$$.fragment)},l(f){a=M(f,"P",{"data-svelte-h":!0}),g(a)!=="svelte-13zq302"&&(a.innerHTML=u),i=o(f),y(p.$$.fragment,f)},m(f,m){n(f,a,m),n(f,i,m),T(p,f,m),r=!0},p:V,i(f){r||(J(p.$$.fragment,f),r=!0)},o(f){_(p.$$.fragment,f),r=!1},d(f){f&&(t(a),t(i)),U(p,f)}}}function Xl(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,x='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,C,d,j,G='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.',$,X,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 R({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),C=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(){a=h("p"),a.innerHTML=u,i=s(),p=h("p"),p.textContent=r,f=s(),w(m.$$.fragment),v=s(),Z=h("p"),Z.innerHTML=x,c=s(),w(C.$$.fragment),d=s(),j=h("p"),j.innerHTML=G,$=s(),X=h("p"),X.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),y(m.$$.fragment,b),v=o(b),Z=M(b,"P",{"data-svelte-h":!0}),g(Z)!=="svelte-184kffk"&&(Z.innerHTML=x),c=o(b),y(C.$$.fragment,b),d=o(b),j=M(b,"P",{"data-svelte-h":!0}),g(j)!=="svelte-14m6rf5"&&(j.innerHTML=G),$=o(b),X=M(b,"P",{"data-svelte-h":!0}),g(X)!=="svelte-z8cdsf"&&(X.textContent=S),N=o(b),k=M(b,"P",{"data-svelte-h":!0}),g(k)!=="svelte-lwtx0u"&&(k.textContent=B)},m(b,I){n(b,a,I),n(b,i,I),n(b,p,I),n(b,f,I),T(m,b,I),n(b,v,I),n(b,Z,I),n(b,c,I),T(C,b,I),n(b,d,I),n(b,j,I),n(b,$,I),n(b,X,I),n(b,N,I),n(b,k,I),z=!0},p:V,i(b){z||(J(m.$$.fragment,b),J(C.$$.fragment,b),z=!0)},o(b){_(m.$$.fragment,b),_(C.$$.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(X),t(N),t(k)),U(m,b),U(C,b)}}}function Gl(W){let a,u,i,p,r,f;return a=new Be({props:{id:"gpu-select",option:"16GB",$$slots:{default:[Il]},$$scope:{ctx:W}}}),i=new Be({props:{id:"gpu-select",option:"12GB",$$slots:{default:[Rl]},$$scope:{ctx:W}}}),r=new Be({props:{id:"gpu-select",option:"8GB",$$slots:{default:[Xl]},$$scope:{ctx:W}}}),{c(){w(a.$$.fragment),u=s(),w(i.$$.fragment),p=s(),w(r.$$.fragment)},l(m){y(a.$$.fragment,m),u=o(m),y(i.$$.fragment,m),p=o(m),y(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 x={};v&2&&(x.$$scope={dirty:v,ctx:m}),i.$set(x);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){_(a.$$.fragment,m),_(i.$$.fragment,m),_(r.$$.fragment,m),f=!1},d(m){m&&(t(u),t(p)),U(a,m),U(i,m),U(r,m)}}}function Nl(W){let a,u;return a=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(a.$$.fragment)},l(i){y(a.$$.fragment,i)},m(i,p){T(a,i,p),u=!0},p:V,i(i){u||(J(a.$$.fragment,i),u=!0)},o(i){_(a.$$.fragment,i),u=!1},d(i){U(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:V,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,x,c,C;return p=new R({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 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(){a=h("p"),a.innerHTML=u,i=s(),w(p.$$.fragment),r=s(),f=h("p"),f.innerHTML=m,v=s(),w(Z.$$.fragment),x=s(),w(c.$$.fragment)},l(d){a=M(d,"P",{"data-svelte-h":!0}),g(a)!=="svelte-10g27jr"&&(a.innerHTML=u),i=o(d),y(p.$$.fragment,d),r=o(d),f=M(d,"P",{"data-svelte-h":!0}),g(f)!=="svelte-q8hcb8"&&(f.innerHTML=m),v=o(d),y(Z.$$.fragment,d),x=o(d),y(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,x,j),T(c,d,j),C=!0},p(d,j){const G={};j&2&&(G.$$scope={dirty:j,ctx:d}),Z.$set(G)},i(d){C||(J(p.$$.fragment,d),J(Z.$$.fragment,d),J(c.$$.fragment,d),C=!0)},o(d){_(p.$$.fragment,d),_(Z.$$.fragment,d),_(c.$$.fragment,d),C=!1},d(d){d&&(t(a),t(i),t(r),t(f),t(v),t(x)),U(p,d),U(Z,d),U(c,d)}}}function Vl(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(){w(a.$$.fragment),u=s(),w(i.$$.fragment)},l(r){y(a.$$.fragment,r),u=o(r),y(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){_(a.$$.fragment,r),_(i.$$.fragment,r),p=!1},d(r){r&&t(u),U(a,r),U(i,r)}}}function Yl(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,x,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.',C,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.',G,$,X="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,I,Ye,Y,He,A,Vt="Initialize an 🤗 Accelerate environment:",Le,Q,Ee,P,Yt="To setup a default 🤗 Accelerate environment without choosing any configurations:",Fe,q,Se,D,Ht="Or if your environment doesn’t support an interactive shell, like a notebook, you can use:",ze,O,Ae,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.',Qe,H,Pe,ee,qe,te,Et='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,At='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,Qt="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,we,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,ye,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).',wt,_e,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.",yt,Ue,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.",_t,E,Ut,F,vt,je,sl="Once training is complete, you can use your newly trained model for inference!",Zt,We,jt,xe,Wt,Ce,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.',xt,Ie,rl='The SDXL training script is discussed in more detail in the <a href="sdxl">SDXL training</a> guide.',Ct,Re,It,Xe,pl="Congratulations on training your own ControlNet! To learn more about how to use your new model, the following guides may be helpful:",Rt,Ge,fl='<li>Learn how to <a href="../using-diffusers/controlnet">use a ControlNet</a> for inference on a variety of tasks.</li>',Xt,Ne,Gt,Ve,Nt;return r=new ke({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}}),I=new Bt({props:{id:"installation",options:["PyTorch","Flax"],$$slots:{default:[jl]},$$scope:{ctx:W}}}),Y=new kt({props:{$$slots:{default:[Wl]},$$scope:{ctx:W}}}),Q=new R({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),q=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}}),H=new kt({props:{$$slots:{default:[xl]},$$scope:{ctx:W}}}),ee=new ke({props:{title:"Script parameters",local:"script-parameters",headingTag:"h2"}}),ne=new R({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 R({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:[Cl]},$$scope:{ctx:W}}}),ce=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}}),he=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}}),$e=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}}),be=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}}),ye=new ke({props:{title:"Launch the script",local:"launch-the-script",headingTag:"h2"}}),ve=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}}),E=new Bt({props:{id:"gpu-select",options:["16GB","12GB","8GB"],$$slots:{default:[Gl]},$$scope:{ctx:W}}}),F=new Bt({props:{id:"training-inference",options:["PyTorch","Flax"],$$slots:{default:[Vl]},$$scope:{ctx:W}}}),We=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}}),xe=new ke({props:{title:"Stable Diffusion XL",local:"stable-diffusion-xl",headingTag:"h2"}}),Re=new ke({props:{title:"Next steps",local:"next-steps",headingTag:"h2"}}),Ne=new Ul({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(),w(r.$$.fragment),f=s(),m=h("p"),m.innerHTML=v,Z=s(),x=h("p"),x.innerHTML=c,C=s(),d=h("p"),d.innerHTML=j,G=s(),$=h("p"),$.textContent=X,S=s(),w(N.$$.fragment),k=s(),B=h("p"),B.textContent=z,b=s(),w(I.$$.fragment),Ye=s(),w(Y.$$.fragment),He=s(),A=h("p"),A.textContent=Vt,Le=s(),w(Q.$$.fragment),Ee=s(),P=h("p"),P.textContent=Yt,Fe=s(),w(q.$$.fragment),Se=s(),D=h("p"),D.textContent=Ht,ze=s(),w(O.$$.fragment),Ae=s(),K=h("p"),K.innerHTML=Lt,Qe=s(),w(H.$$.fragment),Pe=s(),w(ee.$$.fragment),qe=s(),te=h("p"),te.innerHTML=Et,De=s(),le=h("p"),le.innerHTML=Ft,Oe=s(),w(ne.$$.fragment),Ke=s(),ae=h("p"),ae.innerHTML=St,et=s(),ie=h("ul"),ie.innerHTML=zt,tt=s(),w(se.$$.fragment),lt=s(),oe=h("p"),oe.innerHTML=At,nt=s(),re=h("p"),re.innerHTML=Qt,at=s(),w(pe.$$.fragment),it=s(),w(fe.$$.fragment),st=s(),me=h("p"),me.innerHTML=Pt,ot=s(),ue=h("p"),ue.innerHTML=qt,rt=s(),w(L.$$.fragment),pt=s(),w(ce.$$.fragment),ft=s(),de=h("p"),de.innerHTML=Dt,mt=s(),w(he.$$.fragment),ut=s(),Me=h("p"),Me.innerHTML=Ot,ct=s(),w($e.$$.fragment),dt=s(),ge=h("p"),ge.innerHTML=Kt,ht=s(),w(be.$$.fragment),Mt=s(),we=h("p"),we.innerHTML=el,$t=s(),w(ye.$$.fragment),gt=s(),Te=h("p"),Te.textContent=tl,bt=s(),Je=h("p"),Je.innerHTML=ll,wt=s(),_e=h("p"),_e.innerHTML=nl,yt=s(),Ue=h("p"),Ue.textContent=al,Tt=s(),w(ve.$$.fragment),Jt=s(),Ze=h("p"),Ze.innerHTML=il,_t=s(),w(E.$$.fragment),Ut=s(),w(F.$$.fragment),vt=s(),je=h("p"),je.textContent=sl,Zt=s(),w(We.$$.fragment),jt=s(),w(xe.$$.fragment),Wt=s(),Ce=h("p"),Ce.innerHTML=ol,xt=s(),Ie=h("p"),Ie.innerHTML=rl,Ct=s(),w(Re.$$.fragment),It=s(),Xe=h("p"),Xe.textContent=pl,Rt=s(),Ge=h("ul"),Ge.innerHTML=fl,Xt=s(),w(Ne.$$.fragment),Gt=s(),Ve=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),y(r.$$.fragment,e),f=o(e),m=M(e,"P",{"data-svelte-h":!0}),g(m)!=="svelte-q2o66i"&&(m.innerHTML=v),Z=o(e),x=M(e,"P",{"data-svelte-h":!0}),g(x)!=="svelte-l104r8"&&(x.innerHTML=c),C=o(e),d=M(e,"P",{"data-svelte-h":!0}),g(d)!=="svelte-sp8ken"&&(d.innerHTML=j),G=o(e),$=M(e,"P",{"data-svelte-h":!0}),g($)!=="svelte-l7dm2q"&&($.textContent=X),S=o(e),y(N.$$.fragment,e),k=o(e),B=M(e,"P",{"data-svelte-h":!0}),g(B)!=="svelte-z4z0b9"&&(B.textContent=z),b=o(e),y(I.$$.fragment,e),Ye=o(e),y(Y.$$.fragment,e),He=o(e),A=M(e,"P",{"data-svelte-h":!0}),g(A)!=="svelte-60q53m"&&(A.textContent=Vt),Le=o(e),y(Q.$$.fragment,e),Ee=o(e),P=M(e,"P",{"data-svelte-h":!0}),g(P)!=="svelte-di6juu"&&(P.textContent=Yt),Fe=o(e),y(q.$$.fragment,e),Se=o(e),D=M(e,"P",{"data-svelte-h":!0}),g(D)!=="svelte-tsz4qp"&&(D.textContent=Ht),ze=o(e),y(O.$$.fragment,e),Ae=o(e),K=M(e,"P",{"data-svelte-h":!0}),g(K)!=="svelte-1fkfdql"&&(K.innerHTML=Lt),Qe=o(e),y(H.$$.fragment,e),Pe=o(e),y(ee.$$.fragment,e),qe=o(e),te=M(e,"P",{"data-svelte-h":!0}),g(te)!=="svelte-bw2u91"&&(te.innerHTML=Et),De=o(e),le=M(e,"P",{"data-svelte-h":!0}),g(le)!=="svelte-1r0bv1x"&&(le.innerHTML=Ft),Oe=o(e),y(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),y(se.$$.fragment,e),lt=o(e),oe=M(e,"P",{"data-svelte-h":!0}),g(oe)!=="svelte-isitbv"&&(oe.innerHTML=At),nt=o(e),re=M(e,"P",{"data-svelte-h":!0}),g(re)!=="svelte-tp3kp"&&(re.innerHTML=Qt),at=o(e),y(pe.$$.fragment,e),it=o(e),y(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),y(L.$$.fragment,e),pt=o(e),y(ce.$$.fragment,e),ft=o(e),de=M(e,"P",{"data-svelte-h":!0}),g(de)!=="svelte-1t15wny"&&(de.innerHTML=Dt),mt=o(e),y(he.$$.fragment,e),ut=o(e),Me=M(e,"P",{"data-svelte-h":!0}),g(Me)!=="svelte-1rtudr1"&&(Me.innerHTML=Ot),ct=o(e),y($e.$$.fragment,e),dt=o(e),ge=M(e,"P",{"data-svelte-h":!0}),g(ge)!=="svelte-ane16q"&&(ge.innerHTML=Kt),ht=o(e),y(be.$$.fragment,e),Mt=o(e),we=M(e,"P",{"data-svelte-h":!0}),g(we)!=="svelte-6gmbd2"&&(we.innerHTML=el),$t=o(e),y(ye.$$.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),wt=o(e),_e=M(e,"P",{"data-svelte-h":!0}),g(_e)!=="svelte-11t01x0"&&(_e.innerHTML=nl),yt=o(e),Ue=M(e,"P",{"data-svelte-h":!0}),g(Ue)!=="svelte-1uo0m2d"&&(Ue.textContent=al),Tt=o(e),y(ve.$$.fragment,e),Jt=o(e),Ze=M(e,"P",{"data-svelte-h":!0}),g(Ze)!=="svelte-1wlzzvk"&&(Ze.innerHTML=il),_t=o(e),y(E.$$.fragment,e),Ut=o(e),y(F.$$.fragment,e),vt=o(e),je=M(e,"P",{"data-svelte-h":!0}),g(je)!=="svelte-1x6in5t"&&(je.textContent=sl),Zt=o(e),y(We.$$.fragment,e),jt=o(e),y(xe.$$.fragment,e),Wt=o(e),Ce=M(e,"P",{"data-svelte-h":!0}),g(Ce)!=="svelte-t1l7wa"&&(Ce.innerHTML=ol),xt=o(e),Ie=M(e,"P",{"data-svelte-h":!0}),g(Ie)!=="svelte-6dxtva"&&(Ie.innerHTML=rl),Ct=o(e),y(Re.$$.fragment,e),It=o(e),Xe=M(e,"P",{"data-svelte-h":!0}),g(Xe)!=="svelte-s6fbj8"&&(Xe.textContent=pl),Rt=o(e),Ge=M(e,"UL",{"data-svelte-h":!0}),g(Ge)!=="svelte-jinr48"&&(Ge.innerHTML=fl),Xt=o(e),y(Ne.$$.fragment,e),Gt=o(e),Ve=M(e,"P",{}),$l(Ve).forEach(t),this.h()},h(){gl(a,"name","hf:doc:metadata"),gl(a,"content",Hl)},m(e,l){_l(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,x,l),n(e,C,l),n(e,d,l),n(e,G,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(I,e,l),n(e,Ye,l),T(Y,e,l),n(e,He,l),n(e,A,l),n(e,Le,l),T(Q,e,l),n(e,Ee,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,Ae,l),n(e,K,l),n(e,Qe,l),T(H,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,we,l),n(e,$t,l),T(ye,e,l),n(e,gt,l),n(e,Te,l),n(e,bt,l),n(e,Je,l),n(e,wt,l),n(e,_e,l),n(e,yt,l),n(e,Ue,l),n(e,Tt,l),T(ve,e,l),n(e,Jt,l),n(e,Ze,l),n(e,_t,l),T(E,e,l),n(e,Ut,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(xe,e,l),n(e,Wt,l),n(e,Ce,l),n(e,xt,l),n(e,Ie,l),n(e,Ct,l),T(Re,e,l),n(e,It,l),n(e,Xe,l),n(e,Rt,l),n(e,Ge,l),n(e,Xt,l),T(Ne,e,l),n(e,Gt,l),n(e,Ve,l),Nt=!0},p(e,[l]){const ml={};l&2&&(ml.$$scope={dirty:l,ctx:e}),I.$set(ml);const ul={};l&2&&(ul.$$scope={dirty:l,ctx:e}),Y.$set(ul);const cl={};l&2&&(cl.$$scope={dirty:l,ctx:e}),H.$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}),E.$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(I.$$.fragment,e),J(Y.$$.fragment,e),J(Q.$$.fragment,e),J(q.$$.fragment,e),J(O.$$.fragment,e),J(H.$$.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(ye.$$.fragment,e),J(ve.$$.fragment,e),J(E.$$.fragment,e),J(F.$$.fragment,e),J(We.$$.fragment,e),J(xe.$$.fragment,e),J(Re.$$.fragment,e),J(Ne.$$.fragment,e),Nt=!0)},o(e){_(r.$$.fragment,e),_(N.$$.fragment,e),_(I.$$.fragment,e),_(Y.$$.fragment,e),_(Q.$$.fragment,e),_(q.$$.fragment,e),_(O.$$.fragment,e),_(H.$$.fragment,e),_(ee.$$.fragment,e),_(ne.$$.fragment,e),_(se.$$.fragment,e),_(pe.$$.fragment,e),_(fe.$$.fragment,e),_(L.$$.fragment,e),_(ce.$$.fragment,e),_(he.$$.fragment,e),_($e.$$.fragment,e),_(be.$$.fragment,e),_(ye.$$.fragment,e),_(ve.$$.fragment,e),_(E.$$.fragment,e),_(F.$$.fragment,e),_(We.$$.fragment,e),_(xe.$$.fragment,e),_(Re.$$.fragment,e),_(Ne.$$.fragment,e),Nt=!1},d(e){e&&(t(u),t(i),t(p),t(f),t(m),t(Z),t(x),t(C),t(d),t(G),t($),t(S),t(k),t(B),t(b),t(Ye),t(He),t(A),t(Le),t(Ee),t(P),t(Fe),t(Se),t(D),t(ze),t(Ae),t(K),t(Qe),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(we),t($t),t(gt),t(Te),t(bt),t(Je),t(wt),t(_e),t(yt),t(Ue),t(Tt),t(Jt),t(Ze),t(_t),t(Ut),t(vt),t(je),t(Zt),t(jt),t(Wt),t(Ce),t(xt),t(Ie),t(Ct),t(It),t(Xe),t(Rt),t(Ge),t(Xt),t(Gt),t(Ve)),t(a),U(r,e),U(N,e),U(I,e),U(Y,e),U(Q,e),U(q,e),U(O,e),U(H,e),U(ee,e),U(ne,e),U(se,e),U(pe,e),U(fe,e),U(L,e),U(ce,e),U(he,e),U($e,e),U(be,e),U(ye,e),U(ve,e),U(E,e),U(F,e),U(We,e),U(xe,e),U(Re,e),U(Ne,e)}}}const Hl='{"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 wl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Pl extends yl{constructor(a){super(),Tl(this,a,Ll,Yl,bl,{})}}export{Pl as component};
