import{s as $l,o as gl,n as Y}from"../chunks/scheduler.182ea377.js";import{S as bl,i as yl,g as h,s,r as y,A as wl,h as M,f as t,c as o,j as hl,u as w,x as g,k as Ml,y as Tl,a as l,v as T,d as J,t as U,w as _}from"../chunks/index.abf12888.js";import{T as Xt}from"../chunks/Tip.230e2334.js";import{C as I}from"../chunks/CodeBlock.57fe6e13.js";import{H as Ne}from"../chunks/Heading.16916d63.js";import{H as Nt,a as ke}from"../chunks/HfOption.fc88c804.js";function Jl(W){let a,u;return a=new I({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 Ul(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 I({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 I({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 I({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($,G){l($,a,G),l($,i,G),T(p,$,G),l($,r,G),l($,f,G),l($,v,G),T(Z,$,G),l($,C,G),l($,c,G),l($,d,G),T(j,$,G),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 _l(W){let a,u,i,p;return a=new ke({props:{id:"installation",option:"PyTorch",$$slots:{default:[Jl]},$$scope:{ctx:W}}}),i=new ke({props:{id:"installation",option:"Flax",$$slots:{default:[Ul]},$$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),l(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 vl(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){l(i,a,p)},p:Y,d(i){i&&t(a)}}}function Zl(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){l(i,a,p)},p:Y,d(i){i&&t(a)}}}function jl(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){l(i,a,p)},p:Y,d(i){i&&t(a)}}}function Wl(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 I({props:{code:"cGlwJTIwaW5zdGFsbCUyMGJpdHNhbmRieXRlcw==",highlighted:"pip install bitsandbytes",wrap:!1}}),Z=new I({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){l(c,a,x),l(c,i,x),T(p,c,x),l(c,r,x),l(c,f,x),l(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 Cl(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 I({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){l(f,a,m),l(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 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,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.',$,G,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 I({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),x=new I({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(),G=h("p"),G.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),G=M(b,"P",{"data-svelte-h":!0}),g(G)!=="svelte-z8cdsf"&&(G.textContent=S),N=o(b),k=M(b,"P",{"data-svelte-h":!0}),g(k)!=="svelte-lwtx0u"&&(k.textContent=B)},m(b,R){l(b,a,R),l(b,i,R),l(b,p,R),l(b,f,R),T(m,b,R),l(b,v,R),l(b,Z,R),l(b,c,R),T(x,b,R),l(b,d,R),l(b,j,R),l(b,$,R),l(b,G,R),l(b,N,R),l(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(G),t(N),t(k)),_(m,b),_(x,b)}}}function Rl(W){let a,u,i,p,r,f;return a=new ke({props:{id:"gpu-select",option:"16GB",$$slots:{default:[Wl]},$$scope:{ctx:W}}}),i=new ke({props:{id:"gpu-select",option:"12GB",$$slots:{default:[Cl]},$$scope:{ctx:W}}}),r=new ke({props:{id:"gpu-select",option:"8GB",$$slots:{default:[xl]},$$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),l(m,u,v),T(i,m,v),l(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 Il(W){let a,u;return a=new I({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 Gl(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){l(i,a,p)},p:Y,d(i){i&&t(a)}}}function Xl(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 I({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRlbnNvcmZsb3clMjB0ZW5zb3Jib2FyZC1wbHVnaW4tcHJvZmlsZSUwQXRlbnNvcmJvYXJkJTIwLS1sb2dkaXIlMjBydW5zJTJGZmlsbC1jaXJjbGUtMTAwc3RlcHMtMjAyMzA0MTFfMTY1NjEyJTJG",highlighted:`pip install tensorflow tensorboard-plugin-profile
tensorboard --logdir runs/fill-circle-100steps-20230411_165612/`,wrap:!1}}),Z=new Xt({props:{warning:!0,$$slots:{default:[Gl]},$$scope:{ctx:W}}}),c=new I({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){l(d,a,j),l(d,i,j),T(p,d,j),l(d,r,j),l(d,f,j),l(d,v,j),T(Z,d,j),l(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 Nl(W){let a,u,i,p;return a=new ke({props:{id:"training-inference",option:"PyTorch",$$slots:{default:[Il]},$$scope:{ctx:W}}}),i=new ke({props:{id:"training-inference",option:"Flax",$$slots:{default:[Xl]},$$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),l(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 kl(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,$,G="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,Ye,H,He,Q,kt="Initialize an 🤗 Accelerate environment:",Ee,A,Le,P,Bt="To setup a default 🤗 Accelerate environment without choosing any configurations:",Ve,q,Fe,D,Yt="Or if your environment doesn’t support an interactive shell, like a notebook, you can use:",Se,O,ze,K,Ht='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,E,Ae,ee,Pe,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.',qe,le,Lt="For example, to speedup training with mixed precision using the fp16 format, add the <code>--mixed_precision</code> parameter to the training command:",De,ne,Oe,ae,Vt='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:',Ke,ie,Ft="<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>",et,se,tt,oe,St='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.',lt,re,zt="Add the <code>--snr_gamma</code> parameter and set it to the recommended value of 5.0:",nt,pe,at,fe,it,me,Qt='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.',st,ue,At='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.',ot,L,rt,ce,pt,de,Pt='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:',ft,he,mt,Me,qt='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:',ut,$e,ct,ge,Dt='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:',dt,be,ht,ye,Ot='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.',Mt,we,$t,Te,Kt="Now you’re ready to launch the training script! 🚀",gt,Je,el='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).',bt,Ue,tl="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,_e,ll="Download the following images to condition your training with:",wt,ve,Tt,Ze,nl="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.",Jt,V,Ut,F,_t,je,al="Once training is complete, you can use your newly trained model for inference!",vt,We,Zt,Ce,jt,xe,il='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.',Wt,Re,sl='The SDXL training script is discussed in more detail in the <a href="sdxl">SDXL training</a> guide.',Ct,Ie,xt,Ge,ol="Congratulations on training your own ControlNet! To learn more about how to use your new model, the following guides may be helpful:",Rt,Xe,rl='<li>Learn how to <a href="../using-diffusers/controlnet">use a ControlNet</a> for inference on a variety of tasks.</li>',It,Be,Gt;return r=new Ne({props:{title:"ControlNet",local:"controlnet",headingTag:"h1"}}),N=new I({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 Nt({props:{id:"installation",options:["PyTorch","Flax"],$$slots:{default:[_l]},$$scope:{ctx:W}}}),H=new Xt({props:{$$slots:{default:[vl]},$$scope:{ctx:W}}}),A=new I({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),q=new I({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZyUyMGRlZmF1bHQ=",highlighted:"accelerate config default",wrap:!1}}),O=new I({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUudXRpbHMlMjBpbXBvcnQlMjB3cml0ZV9iYXNpY19jb25maWclMEElMEF3cml0ZV9iYXNpY19jb25maWcoKQ==",highlighted:`from accelerate.utils import write_basic_config

write_basic_config()`,wrap:!1}}),E=new Xt({props:{$$slots:{default:[Zl]},$$scope:{ctx:W}}}),ee=new Ne({props:{title:"Script parameters",local:"script-parameters",headingTag:"h2"}}),ne=new I({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2NvbnRyb2xuZXQucHklMjAlNUMlMEElMjAlMjAtLW1peGVkX3ByZWNpc2lvbiUzRCUyMmZwMTYlMjI=",highlighted:`accelerate launch train_controlnet.py \\
  --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span>`,wrap:!1}}),se=new Ne({props:{title:"Min-SNR weighting",local:"min-snr-weighting",headingTag:"h3"}}),pe=new I({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2NvbnRyb2xuZXQucHklMjAlNUMlMEElMjAlMjAtLXNucl9nYW1tYSUzRDUuMA==",highlighted:`accelerate launch train_controlnet.py \\
  --snr_gamma=5.0`,wrap:!1}}),fe=new Ne({props:{title:"Training script",local:"training-script",headingTag:"h2"}}),L=new Xt({props:{$$slots:{default:[jl]},$$scope:{ctx:W}}}),ce=new I({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 I({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 I({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 I({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 Ne({props:{title:"Launch the script",local:"launch-the-script",headingTag:"h2"}}),ve=new I({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 Nt({props:{id:"gpu-select",options:["16GB","12GB","8GB"],$$slots:{default:[Rl]},$$scope:{ctx:W}}}),F=new Nt({props:{id:"training-inference",options:["PyTorch","Flax"],$$slots:{default:[Nl]},$$scope:{ctx:W}}}),We=new I({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 Ne({props:{title:"Stable Diffusion XL",local:"stable-diffusion-xl",headingTag:"h2"}}),Ie=new Ne({props:{title:"Next steps",local:"next-steps",headingTag:"h2"}}),{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=G,S=s(),y(N.$$.fragment),k=s(),B=h("p"),B.textContent=z,b=s(),y(R.$$.fragment),Ye=s(),y(H.$$.fragment),He=s(),Q=h("p"),Q.textContent=kt,Ee=s(),y(A.$$.fragment),Le=s(),P=h("p"),P.textContent=Bt,Ve=s(),y(q.$$.fragment),Fe=s(),D=h("p"),D.textContent=Yt,Se=s(),y(O.$$.fragment),ze=s(),K=h("p"),K.innerHTML=Ht,Qe=s(),y(E.$$.fragment),Ae=s(),y(ee.$$.fragment),Pe=s(),te=h("p"),te.innerHTML=Et,qe=s(),le=h("p"),le.innerHTML=Lt,De=s(),y(ne.$$.fragment),Oe=s(),ae=h("p"),ae.innerHTML=Vt,Ke=s(),ie=h("ul"),ie.innerHTML=Ft,et=s(),y(se.$$.fragment),tt=s(),oe=h("p"),oe.innerHTML=St,lt=s(),re=h("p"),re.innerHTML=zt,nt=s(),y(pe.$$.fragment),at=s(),y(fe.$$.fragment),it=s(),me=h("p"),me.innerHTML=Qt,st=s(),ue=h("p"),ue.innerHTML=At,ot=s(),y(L.$$.fragment),rt=s(),y(ce.$$.fragment),pt=s(),de=h("p"),de.innerHTML=Pt,ft=s(),y(he.$$.fragment),mt=s(),Me=h("p"),Me.innerHTML=qt,ut=s(),y($e.$$.fragment),ct=s(),ge=h("p"),ge.innerHTML=Dt,dt=s(),y(be.$$.fragment),ht=s(),ye=h("p"),ye.innerHTML=Ot,Mt=s(),y(we.$$.fragment),$t=s(),Te=h("p"),Te.textContent=Kt,gt=s(),Je=h("p"),Je.innerHTML=el,bt=s(),Ue=h("p"),Ue.innerHTML=tl,yt=s(),_e=h("p"),_e.textContent=ll,wt=s(),y(ve.$$.fragment),Tt=s(),Ze=h("p"),Ze.innerHTML=nl,Jt=s(),y(V.$$.fragment),Ut=s(),y(F.$$.fragment),_t=s(),je=h("p"),je.textContent=al,vt=s(),y(We.$$.fragment),Zt=s(),y(Ce.$$.fragment),jt=s(),xe=h("p"),xe.innerHTML=il,Wt=s(),Re=h("p"),Re.innerHTML=sl,Ct=s(),y(Ie.$$.fragment),xt=s(),Ge=h("p"),Ge.textContent=ol,Rt=s(),Xe=h("ul"),Xe.innerHTML=rl,It=s(),Be=h("p"),this.h()},l(e){const n=wl("svelte-u9bgzb",document.head);a=M(n,"META",{name:!0,content:!0}),n.forEach(t),u=o(e),i=M(e,"P",{}),hl(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=G),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),Ye=o(e),w(H.$$.fragment,e),He=o(e),Q=M(e,"P",{"data-svelte-h":!0}),g(Q)!=="svelte-60q53m"&&(Q.textContent=kt),Ee=o(e),w(A.$$.fragment,e),Le=o(e),P=M(e,"P",{"data-svelte-h":!0}),g(P)!=="svelte-di6juu"&&(P.textContent=Bt),Ve=o(e),w(q.$$.fragment,e),Fe=o(e),D=M(e,"P",{"data-svelte-h":!0}),g(D)!=="svelte-tsz4qp"&&(D.textContent=Yt),Se=o(e),w(O.$$.fragment,e),ze=o(e),K=M(e,"P",{"data-svelte-h":!0}),g(K)!=="svelte-1fkfdql"&&(K.innerHTML=Ht),Qe=o(e),w(E.$$.fragment,e),Ae=o(e),w(ee.$$.fragment,e),Pe=o(e),te=M(e,"P",{"data-svelte-h":!0}),g(te)!=="svelte-bw2u91"&&(te.innerHTML=Et),qe=o(e),le=M(e,"P",{"data-svelte-h":!0}),g(le)!=="svelte-1r0bv1x"&&(le.innerHTML=Lt),De=o(e),w(ne.$$.fragment,e),Oe=o(e),ae=M(e,"P",{"data-svelte-h":!0}),g(ae)!=="svelte-1s0tjh8"&&(ae.innerHTML=Vt),Ke=o(e),ie=M(e,"UL",{"data-svelte-h":!0}),g(ie)!=="svelte-9wifrj"&&(ie.innerHTML=Ft),et=o(e),w(se.$$.fragment,e),tt=o(e),oe=M(e,"P",{"data-svelte-h":!0}),g(oe)!=="svelte-isitbv"&&(oe.innerHTML=St),lt=o(e),re=M(e,"P",{"data-svelte-h":!0}),g(re)!=="svelte-tp3kp"&&(re.innerHTML=zt),nt=o(e),w(pe.$$.fragment,e),at=o(e),w(fe.$$.fragment,e),it=o(e),me=M(e,"P",{"data-svelte-h":!0}),g(me)!=="svelte-1ca6n8s"&&(me.innerHTML=Qt),st=o(e),ue=M(e,"P",{"data-svelte-h":!0}),g(ue)!=="svelte-yhtkem"&&(ue.innerHTML=At),ot=o(e),w(L.$$.fragment,e),rt=o(e),w(ce.$$.fragment,e),pt=o(e),de=M(e,"P",{"data-svelte-h":!0}),g(de)!=="svelte-1t15wny"&&(de.innerHTML=Pt),ft=o(e),w(he.$$.fragment,e),mt=o(e),Me=M(e,"P",{"data-svelte-h":!0}),g(Me)!=="svelte-1rtudr1"&&(Me.innerHTML=qt),ut=o(e),w($e.$$.fragment,e),ct=o(e),ge=M(e,"P",{"data-svelte-h":!0}),g(ge)!=="svelte-ane16q"&&(ge.innerHTML=Dt),dt=o(e),w(be.$$.fragment,e),ht=o(e),ye=M(e,"P",{"data-svelte-h":!0}),g(ye)!=="svelte-6gmbd2"&&(ye.innerHTML=Ot),Mt=o(e),w(we.$$.fragment,e),$t=o(e),Te=M(e,"P",{"data-svelte-h":!0}),g(Te)!=="svelte-rsq2yy"&&(Te.textContent=Kt),gt=o(e),Je=M(e,"P",{"data-svelte-h":!0}),g(Je)!=="svelte-87boqf"&&(Je.innerHTML=el),bt=o(e),Ue=M(e,"P",{"data-svelte-h":!0}),g(Ue)!=="svelte-11t01x0"&&(Ue.innerHTML=tl),yt=o(e),_e=M(e,"P",{"data-svelte-h":!0}),g(_e)!=="svelte-1uo0m2d"&&(_e.textContent=ll),wt=o(e),w(ve.$$.fragment,e),Tt=o(e),Ze=M(e,"P",{"data-svelte-h":!0}),g(Ze)!=="svelte-1wlzzvk"&&(Ze.innerHTML=nl),Jt=o(e),w(V.$$.fragment,e),Ut=o(e),w(F.$$.fragment,e),_t=o(e),je=M(e,"P",{"data-svelte-h":!0}),g(je)!=="svelte-1x6in5t"&&(je.textContent=al),vt=o(e),w(We.$$.fragment,e),Zt=o(e),w(Ce.$$.fragment,e),jt=o(e),xe=M(e,"P",{"data-svelte-h":!0}),g(xe)!=="svelte-t1l7wa"&&(xe.innerHTML=il),Wt=o(e),Re=M(e,"P",{"data-svelte-h":!0}),g(Re)!=="svelte-6dxtva"&&(Re.innerHTML=sl),Ct=o(e),w(Ie.$$.fragment,e),xt=o(e),Ge=M(e,"P",{"data-svelte-h":!0}),g(Ge)!=="svelte-s6fbj8"&&(Ge.textContent=ol),Rt=o(e),Xe=M(e,"UL",{"data-svelte-h":!0}),g(Xe)!=="svelte-jinr48"&&(Xe.innerHTML=rl),It=o(e),Be=M(e,"P",{}),hl(Be).forEach(t),this.h()},h(){Ml(a,"name","hf:doc:metadata"),Ml(a,"content",Bl)},m(e,n){Tl(document.head,a),l(e,u,n),l(e,i,n),l(e,p,n),T(r,e,n),l(e,f,n),l(e,m,n),l(e,Z,n),l(e,C,n),l(e,x,n),l(e,d,n),l(e,X,n),l(e,$,n),l(e,S,n),T(N,e,n),l(e,k,n),l(e,B,n),l(e,b,n),T(R,e,n),l(e,Ye,n),T(H,e,n),l(e,He,n),l(e,Q,n),l(e,Ee,n),T(A,e,n),l(e,Le,n),l(e,P,n),l(e,Ve,n),T(q,e,n),l(e,Fe,n),l(e,D,n),l(e,Se,n),T(O,e,n),l(e,ze,n),l(e,K,n),l(e,Qe,n),T(E,e,n),l(e,Ae,n),T(ee,e,n),l(e,Pe,n),l(e,te,n),l(e,qe,n),l(e,le,n),l(e,De,n),T(ne,e,n),l(e,Oe,n),l(e,ae,n),l(e,Ke,n),l(e,ie,n),l(e,et,n),T(se,e,n),l(e,tt,n),l(e,oe,n),l(e,lt,n),l(e,re,n),l(e,nt,n),T(pe,e,n),l(e,at,n),T(fe,e,n),l(e,it,n),l(e,me,n),l(e,st,n),l(e,ue,n),l(e,ot,n),T(L,e,n),l(e,rt,n),T(ce,e,n),l(e,pt,n),l(e,de,n),l(e,ft,n),T(he,e,n),l(e,mt,n),l(e,Me,n),l(e,ut,n),T($e,e,n),l(e,ct,n),l(e,ge,n),l(e,dt,n),T(be,e,n),l(e,ht,n),l(e,ye,n),l(e,Mt,n),T(we,e,n),l(e,$t,n),l(e,Te,n),l(e,gt,n),l(e,Je,n),l(e,bt,n),l(e,Ue,n),l(e,yt,n),l(e,_e,n),l(e,wt,n),T(ve,e,n),l(e,Tt,n),l(e,Ze,n),l(e,Jt,n),T(V,e,n),l(e,Ut,n),T(F,e,n),l(e,_t,n),l(e,je,n),l(e,vt,n),T(We,e,n),l(e,Zt,n),T(Ce,e,n),l(e,jt,n),l(e,xe,n),l(e,Wt,n),l(e,Re,n),l(e,Ct,n),T(Ie,e,n),l(e,xt,n),l(e,Ge,n),l(e,Rt,n),l(e,Xe,n),l(e,It,n),l(e,Be,n),Gt=!0},p(e,[n]){const pl={};n&2&&(pl.$$scope={dirty:n,ctx:e}),R.$set(pl);const fl={};n&2&&(fl.$$scope={dirty:n,ctx:e}),H.$set(fl);const ml={};n&2&&(ml.$$scope={dirty:n,ctx:e}),E.$set(ml);const ul={};n&2&&(ul.$$scope={dirty:n,ctx:e}),L.$set(ul);const cl={};n&2&&(cl.$$scope={dirty:n,ctx:e}),V.$set(cl);const dl={};n&2&&(dl.$$scope={dirty:n,ctx:e}),F.$set(dl)},i(e){Gt||(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(Ie.$$.fragment,e),Gt=!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(Ie.$$.fragment,e),Gt=!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(Ye),t(He),t(Q),t(Ee),t(Le),t(P),t(Ve),t(Fe),t(D),t(Se),t(ze),t(K),t(Qe),t(Ae),t(Pe),t(te),t(qe),t(le),t(De),t(Oe),t(ae),t(Ke),t(ie),t(et),t(tt),t(oe),t(lt),t(re),t(nt),t(at),t(it),t(me),t(st),t(ue),t(ot),t(rt),t(pt),t(de),t(ft),t(mt),t(Me),t(ut),t(ct),t(ge),t(dt),t(ht),t(ye),t(Mt),t($t),t(Te),t(gt),t(Je),t(bt),t(Ue),t(yt),t(_e),t(wt),t(Tt),t(Ze),t(Jt),t(Ut),t(_t),t(je),t(vt),t(Zt),t(jt),t(xe),t(Wt),t(Re),t(Ct),t(xt),t(Ge),t(Rt),t(Xe),t(It),t(Be)),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),_(Ie,e)}}}const Bl='{"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 Yl(W){return gl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class zl extends bl{constructor(a){super(),yl(this,a,Yl,kl,$l,{})}}export{zl as component};
