import{s as It,o as Vt,n as We}from"../chunks/scheduler.53228c21.js";import{S as Ht,i as Xt,e as M,s as o,c as g,h as Bt,a as h,d as t,b as r,f as Gt,g as _,j as b,k as $e,l as Nt,m as l,n as w,t as U,o as J,p as T}from"../chunks/index.100fac89.js";import{C as Qt}from"../chunks/CopyLLMTxtMenu.9360b11d.js";import{C as v}from"../chunks/CodeBlock.d30a6509.js";import{H as je,E as Ft}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.c9001d7a.js";import{H as ct,a as Ze}from"../chunks/HfOption.fad27e59.js";function Et(k){let i,d='The <a href="https://github.com/huggingface/diffusers/blob/6e68c71503682c8693cb5b06a4da4911dfd655ee/examples/kandinsky2_2/text_to_image/train_text_to_image_prior.py#L441" rel="nofollow"><code>main()</code></a> function contains the code for preparing the dataset and training the model.',s,f,a='One of the main differences you’ll notice right away is that the training script also loads a <a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPImageProcessor" rel="nofollow">CLIPImageProcessor</a> - in addition to a scheduler and tokenizer - for preprocessing images and a <a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPVisionModelWithProjection" rel="nofollow">CLIPVisionModelWithProjection</a> model for encoding the images:',p,y,u,$,E='Kandinsky uses a <a href="/docs/diffusers/main/en/api/models/prior_transformer#diffusers.PriorTransformer">PriorTransformer</a> to generate the image embeddings, so you’ll want to setup the optimizer to learn the prior mode’s parameters.',X,W,N,C,B='Next, the input captions are tokenized, and images are <a href="https://github.com/huggingface/diffusers/blob/6e68c71503682c8693cb5b06a4da4911dfd655ee/examples/kandinsky2_2/text_to_image/train_text_to_image_prior.py#L632" rel="nofollow">preprocessed</a> by the <a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPImageProcessor" rel="nofollow">CLIPImageProcessor</a>:',Q,R,G,I,V='Finally, the <a href="https://github.com/huggingface/diffusers/blob/6e68c71503682c8693cb5b06a4da4911dfd655ee/examples/kandinsky2_2/text_to_image/train_text_to_image_prior.py#L718" rel="nofollow">training loop</a> converts the input images into latents, adds noise to the image embeddings, and makes a prediction:',x,c,j,H,P='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.',F;return y=new v({props:{code:"bm9pc2Vfc2NoZWR1bGVyJTIwJTNEJTIwRERQTVNjaGVkdWxlcihiZXRhX3NjaGVkdWxlJTNEJTIyc3F1YXJlZGNvc19jYXBfdjIlMjIlMkMlMjBwcmVkaWN0aW9uX3R5cGUlM0QlMjJzYW1wbGUlMjIpJTBBaW1hZ2VfcHJvY2Vzc29yJTIwJTNEJTIwQ0xJUEltYWdlUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBhcmdzLnByZXRyYWluZWRfcHJpb3JfbW9kZWxfbmFtZV9vcl9wYXRoJTJDJTIwc3ViZm9sZGVyJTNEJTIyaW1hZ2VfcHJvY2Vzc29yJTIyJTBBKSUwQXRva2VuaXplciUyMCUzRCUyMENMSVBUb2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGFyZ3MucHJldHJhaW5lZF9wcmlvcl9tb2RlbF9uYW1lX29yX3BhdGglMkMlMjBzdWJmb2xkZXIlM0QlMjJ0b2tlbml6ZXIlMjIpJTBBJTBBd2l0aCUyMENvbnRleHRNYW5hZ2VycyhkZWVwc3BlZWRfemVyb19pbml0X2Rpc2FibGVkX2NvbnRleHRfbWFuYWdlcigpKSUzQSUwQSUyMCUyMCUyMCUyMGltYWdlX2VuY29kZXIlMjAlM0QlMjBDTElQVmlzaW9uTW9kZWxXaXRoUHJvamVjdGlvbi5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYXJncy5wcmV0cmFpbmVkX3ByaW9yX21vZGVsX25hbWVfb3JfcGF0aCUyQyUyMHN1YmZvbGRlciUzRCUyMmltYWdlX2VuY29kZXIlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHdlaWdodF9kdHlwZSUwQSUyMCUyMCUyMCUyMCkuZXZhbCgpJTBBJTIwJTIwJTIwJTIwdGV4dF9lbmNvZGVyJTIwJTNEJTIwQ0xJUFRleHRNb2RlbFdpdGhQcm9qZWN0aW9uLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhcmdzLnByZXRyYWluZWRfcHJpb3JfbW9kZWxfbmFtZV9vcl9wYXRoJTJDJTIwc3ViZm9sZGVyJTNEJTIydGV4dF9lbmNvZGVyJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R3ZWlnaHRfZHR5cGUlMEElMjAlMjAlMjAlMjApLmV2YWwoKQ==",highlighted:`noise_scheduler = DDPMScheduler(beta_schedule=<span class="hljs-string">&quot;squaredcos_cap_v2&quot;</span>, prediction_type=<span class="hljs-string">&quot;sample&quot;</span>)
image_processor = CLIPImageProcessor.from_pretrained(
    args.pretrained_prior_model_name_or_path, subfolder=<span class="hljs-string">&quot;image_processor&quot;</span>
)
tokenizer = CLIPTokenizer.from_pretrained(args.pretrained_prior_model_name_or_path, subfolder=<span class="hljs-string">&quot;tokenizer&quot;</span>)

<span class="hljs-keyword">with</span> ContextManagers(deepspeed_zero_init_disabled_context_manager()):
    image_encoder = CLIPVisionModelWithProjection.from_pretrained(
        args.pretrained_prior_model_name_or_path, subfolder=<span class="hljs-string">&quot;image_encoder&quot;</span>, torch_dtype=weight_dtype
    ).<span class="hljs-built_in">eval</span>()
    text_encoder = CLIPTextModelWithProjection.from_pretrained(
        args.pretrained_prior_model_name_or_path, subfolder=<span class="hljs-string">&quot;text_encoder&quot;</span>, torch_dtype=weight_dtype
    ).<span class="hljs-built_in">eval</span>()`,wrap:!1}}),W=new v({props:{code:"cHJpb3IlMjAlM0QlMjBQcmlvclRyYW5zZm9ybWVyLmZyb21fcHJldHJhaW5lZChhcmdzLnByZXRyYWluZWRfcHJpb3JfbW9kZWxfbmFtZV9vcl9wYXRoJTJDJTIwc3ViZm9sZGVyJTNEJTIycHJpb3IlMjIpJTBBcHJpb3IudHJhaW4oKSUwQW9wdGltaXplciUyMCUzRCUyMG9wdGltaXplcl9jbHMoJTBBJTIwJTIwJTIwJTIwcHJpb3IucGFyYW1ldGVycygpJTJDJTBBJTIwJTIwJTIwJTIwbHIlM0RhcmdzLmxlYXJuaW5nX3JhdGUlMkMlMEElMjAlMjAlMjAlMjBiZXRhcyUzRChhcmdzLmFkYW1fYmV0YTElMkMlMjBhcmdzLmFkYW1fYmV0YTIpJTJDJTBBJTIwJTIwJTIwJTIwd2VpZ2h0X2RlY2F5JTNEYXJncy5hZGFtX3dlaWdodF9kZWNheSUyQyUwQSUyMCUyMCUyMCUyMGVwcyUzRGFyZ3MuYWRhbV9lcHNpbG9uJTJDJTBBKQ==",highlighted:`prior = PriorTransformer.from_pretrained(args.pretrained_prior_model_name_or_path, subfolder=<span class="hljs-string">&quot;prior&quot;</span>)
prior.train()
optimizer = optimizer_cls(
    prior.parameters(),
    lr=args.learning_rate,
    betas=(args.adam_beta1, args.adam_beta2),
    weight_decay=args.adam_weight_decay,
    eps=args.adam_epsilon,
)`,wrap:!1}}),R=new v({props:{code:"ZGVmJTIwcHJlcHJvY2Vzc190cmFpbihleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjBpbWFnZXMlMjAlM0QlMjAlNUJpbWFnZS5jb252ZXJ0KCUyMlJHQiUyMiklMjBmb3IlMjBpbWFnZSUyMGluJTIwZXhhbXBsZXMlNUJpbWFnZV9jb2x1bW4lNUQlNUQlMEElMjAlMjAlMjAlMjBleGFtcGxlcyU1QiUyMmNsaXBfcGl4ZWxfdmFsdWVzJTIyJTVEJTIwJTNEJTIwaW1hZ2VfcHJvY2Vzc29yKGltYWdlcyUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpLnBpeGVsX3ZhbHVlcyUwQSUyMCUyMCUyMCUyMGV4YW1wbGVzJTVCJTIydGV4dF9pbnB1dF9pZHMlMjIlNUQlMkMlMjBleGFtcGxlcyU1QiUyMnRleHRfbWFzayUyMiU1RCUyMCUzRCUyMHRva2VuaXplX2NhcHRpb25zKGV4YW1wbGVzKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMGV4YW1wbGVz",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_train</span>(<span class="hljs-params">examples</span>):
    images = [image.convert(<span class="hljs-string">&quot;RGB&quot;</span>) <span class="hljs-keyword">for</span> image <span class="hljs-keyword">in</span> examples[image_column]]
    examples[<span class="hljs-string">&quot;clip_pixel_values&quot;</span>] = image_processor(images, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).pixel_values
    examples[<span class="hljs-string">&quot;text_input_ids&quot;</span>], examples[<span class="hljs-string">&quot;text_mask&quot;</span>] = tokenize_captions(examples)
    <span class="hljs-keyword">return</span> examples`,wrap:!1}}),c=new v({props:{code:"bW9kZWxfcHJlZCUyMCUzRCUyMHByaW9yKCUwQSUyMCUyMCUyMCUyMG5vaXN5X2xhdGVudHMlMkMlMEElMjAlMjAlMjAlMjB0aW1lc3RlcCUzRHRpbWVzdGVwcyUyQyUwQSUyMCUyMCUyMCUyMHByb2pfZW1iZWRkaW5nJTNEcHJvbXB0X2VtYmVkcyUyQyUwQSUyMCUyMCUyMCUyMGVuY29kZXJfaGlkZGVuX3N0YXRlcyUzRHRleHRfZW5jb2Rlcl9oaWRkZW5fc3RhdGVzJTJDJTBBJTIwJTIwJTIwJTIwYXR0ZW50aW9uX21hc2slM0R0ZXh0X21hc2slMkMlMEEpLnByZWRpY3RlZF9pbWFnZV9lbWJlZGRpbmc=",highlighted:`model_pred = prior(
    noisy_latents,
    timestep=timesteps,
    proj_embedding=prompt_embeds,
    encoder_hidden_states=text_encoder_hidden_states,
    attention_mask=text_mask,
).predicted_image_embedding`,wrap:!1}}),{c(){i=M("p"),i.innerHTML=d,s=o(),f=M("p"),f.innerHTML=a,p=o(),g(y.$$.fragment),u=o(),$=M("p"),$.innerHTML=E,X=o(),g(W.$$.fragment),N=o(),C=M("p"),C.innerHTML=B,Q=o(),g(R.$$.fragment),G=o(),I=M("p"),I.innerHTML=V,x=o(),g(c.$$.fragment),j=o(),H=M("p"),H.innerHTML=P},l(m){i=h(m,"P",{"data-svelte-h":!0}),b(i)!=="svelte-1vaqpft"&&(i.innerHTML=d),s=r(m),f=h(m,"P",{"data-svelte-h":!0}),b(f)!=="svelte-1q9rvn2"&&(f.innerHTML=a),p=r(m),_(y.$$.fragment,m),u=r(m),$=h(m,"P",{"data-svelte-h":!0}),b($)!=="svelte-f8cqiu"&&($.innerHTML=E),X=r(m),_(W.$$.fragment,m),N=r(m),C=h(m,"P",{"data-svelte-h":!0}),b(C)!=="svelte-1vfjyn1"&&(C.innerHTML=B),Q=r(m),_(R.$$.fragment,m),G=r(m),I=h(m,"P",{"data-svelte-h":!0}),b(I)!=="svelte-1t2oswx"&&(I.innerHTML=V),x=r(m),_(c.$$.fragment,m),j=r(m),H=h(m,"P",{"data-svelte-h":!0}),b(H)!=="svelte-6gmbd2"&&(H.innerHTML=P)},m(m,Z){l(m,i,Z),l(m,s,Z),l(m,f,Z),l(m,p,Z),w(y,m,Z),l(m,u,Z),l(m,$,Z),l(m,X,Z),w(W,m,Z),l(m,N,Z),l(m,C,Z),l(m,Q,Z),w(R,m,Z),l(m,G,Z),l(m,I,Z),l(m,x,Z),w(c,m,Z),l(m,j,Z),l(m,H,Z),F=!0},p:We,i(m){F||(U(y.$$.fragment,m),U(W.$$.fragment,m),U(R.$$.fragment,m),U(c.$$.fragment,m),F=!0)},o(m){J(y.$$.fragment,m),J(W.$$.fragment,m),J(R.$$.fragment,m),J(c.$$.fragment,m),F=!1},d(m){m&&(t(i),t(s),t(f),t(p),t(u),t($),t(X),t(N),t(C),t(Q),t(G),t(I),t(x),t(j),t(H)),T(y,m),T(W,m),T(R,m),T(c,m)}}}function Yt(k){let i,d='The <a href="https://github.com/huggingface/diffusers/blob/6e68c71503682c8693cb5b06a4da4911dfd655ee/examples/kandinsky2_2/text_to_image/train_text_to_image_decoder.py#L440" rel="nofollow"><code>main()</code></a> function contains the code for preparing the dataset and training the model.',s,f,a='Unlike the prior model, the decoder initializes a <a href="/docs/diffusers/main/en/api/models/vq#diffusers.VQModel">VQModel</a> to decode the latents into images and it uses a <a href="/docs/diffusers/main/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>:',p,y,u,$,E='Next, the script includes several image transforms and a <a href="https://github.com/huggingface/diffusers/blob/6e68c71503682c8693cb5b06a4da4911dfd655ee/examples/kandinsky2_2/text_to_image/train_text_to_image_decoder.py#L622" rel="nofollow">preprocessing</a> function for applying the transforms to the images and returning the pixel values:',X,W,N,C,B='Lastly, the <a href="https://github.com/huggingface/diffusers/blob/6e68c71503682c8693cb5b06a4da4911dfd655ee/examples/kandinsky2_2/text_to_image/train_text_to_image_decoder.py#L706" rel="nofollow">training loop</a> handles converting the images to latents, adding noise, and predicting the noise residual.',Q,R,G='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.',I,V,x;return y=new v({props:{code:"d2l0aCUyMENvbnRleHRNYW5hZ2VycyhkZWVwc3BlZWRfemVyb19pbml0X2Rpc2FibGVkX2NvbnRleHRfbWFuYWdlcigpKSUzQSUwQSUyMCUyMCUyMCUyMHZhZSUyMCUzRCUyMFZRTW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGFyZ3MucHJldHJhaW5lZF9kZWNvZGVyX21vZGVsX25hbWVfb3JfcGF0aCUyQyUyMHN1YmZvbGRlciUzRCUyMm1vdnElMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHdlaWdodF9kdHlwZSUwQSUyMCUyMCUyMCUyMCkuZXZhbCgpJTBBJTIwJTIwJTIwJTIwaW1hZ2VfZW5jb2RlciUyMCUzRCUyMENMSVBWaXNpb25Nb2RlbFdpdGhQcm9qZWN0aW9uLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhcmdzLnByZXRyYWluZWRfcHJpb3JfbW9kZWxfbmFtZV9vcl9wYXRoJTJDJTIwc3ViZm9sZGVyJTNEJTIyaW1hZ2VfZW5jb2RlciUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEd2VpZ2h0X2R0eXBlJTBBJTIwJTIwJTIwJTIwKS5ldmFsKCklMEF1bmV0JTIwJTNEJTIwVU5ldDJEQ29uZGl0aW9uTW9kZWwuZnJvbV9wcmV0cmFpbmVkKGFyZ3MucHJldHJhaW5lZF9kZWNvZGVyX21vZGVsX25hbWVfb3JfcGF0aCUyQyUyMHN1YmZvbGRlciUzRCUyMnVuZXQlMjIp",highlighted:`<span class="hljs-keyword">with</span> ContextManagers(deepspeed_zero_init_disabled_context_manager()):
    vae = VQModel.from_pretrained(
        args.pretrained_decoder_model_name_or_path, subfolder=<span class="hljs-string">&quot;movq&quot;</span>, torch_dtype=weight_dtype
    ).<span class="hljs-built_in">eval</span>()
    image_encoder = CLIPVisionModelWithProjection.from_pretrained(
        args.pretrained_prior_model_name_or_path, subfolder=<span class="hljs-string">&quot;image_encoder&quot;</span>, torch_dtype=weight_dtype
    ).<span class="hljs-built_in">eval</span>()
unet = UNet2DConditionModel.from_pretrained(args.pretrained_decoder_model_name_or_path, subfolder=<span class="hljs-string">&quot;unet&quot;</span>)`,wrap:!1}}),W=new v({props:{code:"ZGVmJTIwcHJlcHJvY2Vzc190cmFpbihleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjBpbWFnZXMlMjAlM0QlMjAlNUJpbWFnZS5jb252ZXJ0KCUyMlJHQiUyMiklMjBmb3IlMjBpbWFnZSUyMGluJTIwZXhhbXBsZXMlNUJpbWFnZV9jb2x1bW4lNUQlNUQlMEElMjAlMjAlMjAlMjBleGFtcGxlcyU1QiUyMnBpeGVsX3ZhbHVlcyUyMiU1RCUyMCUzRCUyMCU1QnRyYWluX3RyYW5zZm9ybXMoaW1hZ2UpJTIwZm9yJTIwaW1hZ2UlMjBpbiUyMGltYWdlcyU1RCUwQSUyMCUyMCUyMCUyMGV4YW1wbGVzJTVCJTIyY2xpcF9waXhlbF92YWx1ZXMlMjIlNUQlMjAlM0QlMjBpbWFnZV9wcm9jZXNzb3IoaW1hZ2VzJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMikucGl4ZWxfdmFsdWVzJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwZXhhbXBsZXM=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_train</span>(<span class="hljs-params">examples</span>):
    images = [image.convert(<span class="hljs-string">&quot;RGB&quot;</span>) <span class="hljs-keyword">for</span> image <span class="hljs-keyword">in</span> examples[image_column]]
    examples[<span class="hljs-string">&quot;pixel_values&quot;</span>] = [train_transforms(image) <span class="hljs-keyword">for</span> image <span class="hljs-keyword">in</span> images]
    examples[<span class="hljs-string">&quot;clip_pixel_values&quot;</span>] = image_processor(images, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).pixel_values
    <span class="hljs-keyword">return</span> examples`,wrap:!1}}),V=new v({props:{code:"bW9kZWxfcHJlZCUyMCUzRCUyMHVuZXQobm9pc3lfbGF0ZW50cyUyQyUyMHRpbWVzdGVwcyUyQyUyME5vbmUlMkMlMjBhZGRlZF9jb25kX2t3YXJncyUzRGFkZGVkX2NvbmRfa3dhcmdzKS5zYW1wbGUlNUIlM0ElMkMlMjAlM0E0JTVE",highlighted:'model_pred = unet(noisy_latents, timesteps, <span class="hljs-literal">None</span>, added_cond_kwargs=added_cond_kwargs).sample[:, :<span class="hljs-number">4</span>]',wrap:!1}}),{c(){i=M("p"),i.innerHTML=d,s=o(),f=M("p"),f.innerHTML=a,p=o(),g(y.$$.fragment),u=o(),$=M("p"),$.innerHTML=E,X=o(),g(W.$$.fragment),N=o(),C=M("p"),C.innerHTML=B,Q=o(),R=M("p"),R.innerHTML=G,I=o(),g(V.$$.fragment)},l(c){i=h(c,"P",{"data-svelte-h":!0}),b(i)!=="svelte-1d8rtu6"&&(i.innerHTML=d),s=r(c),f=h(c,"P",{"data-svelte-h":!0}),b(f)!=="svelte-81ryn1"&&(f.innerHTML=a),p=r(c),_(y.$$.fragment,c),u=r(c),$=h(c,"P",{"data-svelte-h":!0}),b($)!=="svelte-tuk4pl"&&($.innerHTML=E),X=r(c),_(W.$$.fragment,c),N=r(c),C=h(c,"P",{"data-svelte-h":!0}),b(C)!=="svelte-rweqyj"&&(C.innerHTML=B),Q=r(c),R=h(c,"P",{"data-svelte-h":!0}),b(R)!=="svelte-6gmbd2"&&(R.innerHTML=G),I=r(c),_(V.$$.fragment,c)},m(c,j){l(c,i,j),l(c,s,j),l(c,f,j),l(c,p,j),w(y,c,j),l(c,u,j),l(c,$,j),l(c,X,j),w(W,c,j),l(c,N,j),l(c,C,j),l(c,Q,j),l(c,R,j),l(c,I,j),w(V,c,j),x=!0},p:We,i(c){x||(U(y.$$.fragment,c),U(W.$$.fragment,c),U(V.$$.fragment,c),x=!0)},o(c){J(y.$$.fragment,c),J(W.$$.fragment,c),J(V.$$.fragment,c),x=!1},d(c){c&&(t(i),t(s),t(f),t(p),t(u),t($),t(X),t(N),t(C),t(Q),t(R),t(I)),T(y,c),T(W,c),T(V,c)}}}function At(k){let i,d,s,f;return i=new Ze({props:{id:"script",option:"prior model",$$slots:{default:[Et]},$$scope:{ctx:k}}}),s=new Ze({props:{id:"script",option:"decoder model",$$slots:{default:[Yt]},$$scope:{ctx:k}}}),{c(){g(i.$$.fragment),d=o(),g(s.$$.fragment)},l(a){_(i.$$.fragment,a),d=r(a),_(s.$$.fragment,a)},m(a,p){w(i,a,p),l(a,d,p),w(s,a,p),f=!0},p(a,p){const y={};p&2&&(y.$$scope={dirty:p,ctx:a}),i.$set(y);const u={};p&2&&(u.$$scope={dirty:p,ctx:a}),s.$set(u)},i(a){f||(U(i.$$.fragment,a),U(s.$$.fragment,a),f=!0)},o(a){J(i.$$.fragment,a),J(s.$$.fragment,a),f=!1},d(a){a&&t(d),T(i,a),T(s,a)}}}function Lt(k){let i,d;return i=new v({props:{code:"ZXhwb3J0JTIwREFUQVNFVF9OQU1FJTNEJTIybGFtYmRhbGFicyUyRm5hcnV0by1ibGlwLWNhcHRpb25zJTIyJTBBJTBBYWNjZWxlcmF0ZSUyMGxhdW5jaCUyMC0tbWl4ZWRfcHJlY2lzaW9uJTNEJTIyZnAxNiUyMiUyMCUyMHRyYWluX3RleHRfdG9faW1hZ2VfcHJpb3IucHklMjAlNUMlMEElMjAlMjAtLWRhdGFzZXRfbmFtZSUzRCUyNERBVEFTRVRfTkFNRSUyMCU1QyUwQSUyMCUyMC0tcmVzb2x1dGlvbiUzRDc2OCUyMCU1QyUwQSUyMCUyMC0tdHJhaW5fYmF0Y2hfc2l6ZSUzRDElMjAlNUMlMEElMjAlMjAtLWdyYWRpZW50X2FjY3VtdWxhdGlvbl9zdGVwcyUzRDQlMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDE1MDAwJTIwJTVDJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNEMWUtMDUlMjAlNUMlMEElMjAlMjAtLW1heF9ncmFkX25vcm0lM0QxJTIwJTVDJTBBJTIwJTIwLS1jaGVja3BvaW50c190b3RhbF9saW1pdCUzRDMlMjAlNUMlMEElMjAlMjAtLWxyX3NjaGVkdWxlciUzRCUyMmNvbnN0YW50JTIyJTIwJTVDJTBBJTIwJTIwLS1scl93YXJtdXBfc3RlcHMlM0QwJTIwJTVDJTBBJTIwJTIwLS12YWxpZGF0aW9uX3Byb21wdHMlM0QlMjJBJTIwcm9ib3QlMjBuYXJ1dG8lMkMlMjA0ayUyMHBob3RvJTIyJTIwJTVDJTBBJTIwJTIwLS1yZXBvcnRfdG8lM0QlMjJ3YW5kYiUyMiUyMCU1QyUwQSUyMCUyMC0tcHVzaF90b19odWIlMjAlNUMlMEElMjAlMjAtLW91dHB1dF9kaXIlM0QlMjJrYW5kaTItcHJpb3ItbmFydXRvLW1vZGVsJTIy",highlighted:`<span class="hljs-built_in">export</span> DATASET_NAME=<span class="hljs-string">&quot;lambdalabs/naruto-blip-captions&quot;</span>

accelerate launch --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span>  train_text_to_image_prior.py \\
  --dataset_name=<span class="hljs-variable">$DATASET_NAME</span> \\
  --resolution=768 \\
  --train_batch_size=1 \\
  --gradient_accumulation_steps=4 \\
  --max_train_steps=15000 \\
  --learning_rate=1e-05 \\
  --max_grad_norm=1 \\
  --checkpoints_total_limit=3 \\
  --lr_scheduler=<span class="hljs-string">&quot;constant&quot;</span> \\
  --lr_warmup_steps=0 \\
  --validation_prompts=<span class="hljs-string">&quot;A robot naruto, 4k photo&quot;</span> \\
  --report_to=<span class="hljs-string">&quot;wandb&quot;</span> \\
  --push_to_hub \\
  --output_dir=<span class="hljs-string">&quot;kandi2-prior-naruto-model&quot;</span>`,wrap:!1}}),{c(){g(i.$$.fragment)},l(s){_(i.$$.fragment,s)},m(s,f){w(i,s,f),d=!0},p:We,i(s){d||(U(i.$$.fragment,s),d=!0)},o(s){J(i.$$.fragment,s),d=!1},d(s){T(i,s)}}}function zt(k){let i,d;return i=new v({props:{code:"ZXhwb3J0JTIwREFUQVNFVF9OQU1FJTNEJTIybGFtYmRhbGFicyUyRm5hcnV0by1ibGlwLWNhcHRpb25zJTIyJTBBJTBBYWNjZWxlcmF0ZSUyMGxhdW5jaCUyMC0tbWl4ZWRfcHJlY2lzaW9uJTNEJTIyZnAxNiUyMiUyMCUyMHRyYWluX3RleHRfdG9faW1hZ2VfZGVjb2Rlci5weSUyMCU1QyUwQSUyMCUyMC0tZGF0YXNldF9uYW1lJTNEJTI0REFUQVNFVF9OQU1FJTIwJTVDJTBBJTIwJTIwLS1yZXNvbHV0aW9uJTNENzY4JTIwJTVDJTBBJTIwJTIwLS10cmFpbl9iYXRjaF9zaXplJTNEMSUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNENCUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfY2hlY2twb2ludGluZyUyMCU1QyUwQSUyMCUyMC0tbWF4X3RyYWluX3N0ZXBzJTNEMTUwMDAlMjAlNUMlMEElMjAlMjAtLWxlYXJuaW5nX3JhdGUlM0QxZS0wNSUyMCU1QyUwQSUyMCUyMC0tbWF4X2dyYWRfbm9ybSUzRDElMjAlNUMlMEElMjAlMjAtLWNoZWNrcG9pbnRzX3RvdGFsX2xpbWl0JTNEMyUyMCU1QyUwQSUyMCUyMC0tbHJfc2NoZWR1bGVyJTNEJTIyY29uc3RhbnQlMjIlMjAlNUMlMEElMjAlMjAtLWxyX3dhcm11cF9zdGVwcyUzRDAlMjAlNUMlMEElMjAlMjAtLXZhbGlkYXRpb25fcHJvbXB0cyUzRCUyMkElMjByb2JvdCUyMG5hcnV0byUyQyUyMDRrJTIwcGhvdG8lMjIlMjAlNUMlMEElMjAlMjAtLXJlcG9ydF90byUzRCUyMndhbmRiJTIyJTIwJTVDJTBBJTIwJTIwLS1wdXNoX3RvX2h1YiUyMCU1QyUwQSUyMCUyMC0tb3V0cHV0X2RpciUzRCUyMmthbmRpMi1kZWNvZGVyLW5hcnV0by1tb2RlbCUyMg==",highlighted:`<span class="hljs-built_in">export</span> DATASET_NAME=<span class="hljs-string">&quot;lambdalabs/naruto-blip-captions&quot;</span>

accelerate launch --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span>  train_text_to_image_decoder.py \\
  --dataset_name=<span class="hljs-variable">$DATASET_NAME</span> \\
  --resolution=768 \\
  --train_batch_size=1 \\
  --gradient_accumulation_steps=4 \\
  --gradient_checkpointing \\
  --max_train_steps=15000 \\
  --learning_rate=1e-05 \\
  --max_grad_norm=1 \\
  --checkpoints_total_limit=3 \\
  --lr_scheduler=<span class="hljs-string">&quot;constant&quot;</span> \\
  --lr_warmup_steps=0 \\
  --validation_prompts=<span class="hljs-string">&quot;A robot naruto, 4k photo&quot;</span> \\
  --report_to=<span class="hljs-string">&quot;wandb&quot;</span> \\
  --push_to_hub \\
  --output_dir=<span class="hljs-string">&quot;kandi2-decoder-naruto-model&quot;</span>`,wrap:!1}}),{c(){g(i.$$.fragment)},l(s){_(i.$$.fragment,s)},m(s,f){w(i,s,f),d=!0},p:We,i(s){d||(U(i.$$.fragment,s),d=!0)},o(s){J(i.$$.fragment,s),d=!1},d(s){T(i,s)}}}function qt(k){let i,d,s,f;return i=new Ze({props:{id:"training-inference",option:"prior model",$$slots:{default:[Lt]},$$scope:{ctx:k}}}),s=new Ze({props:{id:"training-inference",option:"decoder model",$$slots:{default:[zt]},$$scope:{ctx:k}}}),{c(){g(i.$$.fragment),d=o(),g(s.$$.fragment)},l(a){_(i.$$.fragment,a),d=r(a),_(s.$$.fragment,a)},m(a,p){w(i,a,p),l(a,d,p),w(s,a,p),f=!0},p(a,p){const y={};p&2&&(y.$$scope={dirty:p,ctx:a}),i.$set(y);const u={};p&2&&(u.$$scope={dirty:p,ctx:a}),s.$set(u)},i(a){f||(U(i.$$.fragment,a),U(s.$$.fragment,a),f=!0)},o(a){J(i.$$.fragment,a),J(s.$$.fragment,a),f=!1},d(a){a&&t(d),T(i,a),T(s,a)}}}function St(k){let i,d,s,f="<p>Feel free to replace <code>kandinsky-community/kandinsky-2-2-decoder</code> with your own trained decoder checkpoint!</p>",a;return i=new v({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9QaXBlbGluZUZvclRleHQySW1hZ2UlMkMlMjBEaWZmdXNpb25QaXBlbGluZSUwQWltcG9ydCUyMHRvcmNoJTBBJTBBcHJpb3JfcGlwZWxpbmUlMjAlM0QlMjBEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQob3V0cHV0X2RpciUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFwcmlvcl9jb21wb25lbnRzJTIwJTNEJTIwJTdCJTIycHJpb3JfJTIyJTIwJTJCJTIwayUzQSUyMHYlMjBmb3IlMjBrJTJDdiUyMGluJTIwcHJpb3JfcGlwZWxpbmUuY29tcG9uZW50cy5pdGVtcygpJTdEJTBBcGlwZWxpbmUlMjAlM0QlMjBBdXRvUGlwZWxpbmVGb3JUZXh0MkltYWdlLmZyb21fcHJldHJhaW5lZCglMjJrYW5kaW5za3ktY29tbXVuaXR5JTJGa2FuZGluc2t5LTItMi1kZWNvZGVyJTIyJTJDJTIwKipwcmlvcl9jb21wb25lbnRzJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2KSUwQSUwQXBpcGUuZW5hYmxlX21vZGVsX2NwdV9vZmZsb2FkKCklMEFwcm9tcHQlM0QlMjJBJTIwcm9ib3QlMjBuYXJ1dG8lMkMlMjA0ayUyMHBob3RvJTIyJTBBaW1hZ2UlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQlM0Rwcm9tcHQlMkMlMjBuZWdhdGl2ZV9wcm9tcHQlM0RuZWdhdGl2ZV9wcm9tcHQpLmltYWdlcyU1QjAlNUQ=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoPipelineForText2Image, DiffusionPipeline
<span class="hljs-keyword">import</span> torch

prior_pipeline = DiffusionPipeline.from_pretrained(output_dir, torch_dtype=torch.float16)
prior_components = {<span class="hljs-string">&quot;prior_&quot;</span> + k: v <span class="hljs-keyword">for</span> k,v <span class="hljs-keyword">in</span> prior_pipeline.components.items()}
pipeline = AutoPipelineForText2Image.from_pretrained(<span class="hljs-string">&quot;kandinsky-community/kandinsky-2-2-decoder&quot;</span>, **prior_components, torch_dtype=torch.float16)

pipe.enable_model_cpu_offload()
prompt=<span class="hljs-string">&quot;A robot naruto, 4k photo&quot;</span>
image = pipeline(prompt=prompt, negative_prompt=negative_prompt).images[<span class="hljs-number">0</span>]`,wrap:!1}}),{c(){g(i.$$.fragment),d=o(),s=M("blockquote"),s.innerHTML=f,this.h()},l(p){_(i.$$.fragment,p),d=r(p),s=h(p,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),b(s)!=="svelte-a2nyya"&&(s.innerHTML=f),this.h()},h(){$e(s,"class","tip")},m(p,y){w(i,p,y),l(p,d,y),l(p,s,y),a=!0},p:We,i(p){a||(U(i.$$.fragment,p),a=!0)},o(p){J(i.$$.fragment,p),a=!1},d(p){p&&(t(d),t(s)),T(i,p)}}}function Pt(k){let i,d,s,f="For the decoder model, you can also perform inference from a saved checkpoint which can be useful for viewing intermediate results. In this case, load the checkpoint into the UNet:",a,p,y;return i=new v({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9QaXBlbGluZUZvclRleHQySW1hZ2UlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwQXV0b1BpcGVsaW5lRm9yVGV4dDJJbWFnZS5mcm9tX3ByZXRyYWluZWQoJTIycGF0aCUyRnRvJTJGc2F2ZWQlMkZtb2RlbCUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFwaXBlbGluZS5lbmFibGVfbW9kZWxfY3B1X29mZmxvYWQoKSUwQSUwQXByb21wdCUzRCUyMkElMjByb2JvdCUyMG5hcnV0byUyQyUyMDRrJTIwcGhvdG8lMjIlMEFpbWFnZSUyMCUzRCUyMHBpcGVsaW5lKHByb21wdCUzRHByb21wdCkuaW1hZ2VzJTVCMCU1RA==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoPipelineForText2Image
<span class="hljs-keyword">import</span> torch

pipeline = AutoPipelineForText2Image.from_pretrained(<span class="hljs-string">&quot;path/to/saved/model&quot;</span>, torch_dtype=torch.float16)
pipeline.enable_model_cpu_offload()

prompt=<span class="hljs-string">&quot;A robot naruto, 4k photo&quot;</span>
image = pipeline(prompt=prompt).images[<span class="hljs-number">0</span>]`,wrap:!1}}),p=new v({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9QaXBlbGluZUZvclRleHQySW1hZ2UlMkMlMjBVTmV0MkRDb25kaXRpb25Nb2RlbCUwQSUwQXVuZXQlMjAlM0QlMjBVTmV0MkRDb25kaXRpb25Nb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIycGF0aCUyRnRvJTJGc2F2ZWQlMkZtb2RlbCUyMiUyMCUyQiUyMCUyMiUyRmNoZWNrcG9pbnQtJTNDTiUzRSUyRnVuZXQlMjIpJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBBdXRvUGlwZWxpbmVGb3JUZXh0MkltYWdlLmZyb21fcHJldHJhaW5lZCglMjJrYW5kaW5za3ktY29tbXVuaXR5JTJGa2FuZGluc2t5LTItMi1kZWNvZGVyJTIyJTJDJTIwdW5ldCUzRHVuZXQlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYpJTBBcGlwZWxpbmUuZW5hYmxlX21vZGVsX2NwdV9vZmZsb2FkKCklMEElMEFpbWFnZSUyMCUzRCUyMHBpcGVsaW5lKHByb21wdCUzRCUyMkElMjByb2JvdCUyMG5hcnV0byUyQyUyMDRrJTIwcGhvdG8lMjIpLmltYWdlcyU1QjAlNUQ=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoPipelineForText2Image, UNet2DConditionModel

unet = UNet2DConditionModel.from_pretrained(<span class="hljs-string">&quot;path/to/saved/model&quot;</span> + <span class="hljs-string">&quot;/checkpoint-&lt;N&gt;/unet&quot;</span>)

pipeline = AutoPipelineForText2Image.from_pretrained(<span class="hljs-string">&quot;kandinsky-community/kandinsky-2-2-decoder&quot;</span>, unet=unet, torch_dtype=torch.float16)
pipeline.enable_model_cpu_offload()

image = pipeline(prompt=<span class="hljs-string">&quot;A robot naruto, 4k photo&quot;</span>).images[<span class="hljs-number">0</span>]`,wrap:!1}}),{c(){g(i.$$.fragment),d=o(),s=M("p"),s.textContent=f,a=o(),g(p.$$.fragment)},l(u){_(i.$$.fragment,u),d=r(u),s=h(u,"P",{"data-svelte-h":!0}),b(s)!=="svelte-1xieqd5"&&(s.textContent=f),a=r(u),_(p.$$.fragment,u)},m(u,$){w(i,u,$),l(u,d,$),l(u,s,$),l(u,a,$),w(p,u,$),y=!0},p:We,i(u){y||(U(i.$$.fragment,u),U(p.$$.fragment,u),y=!0)},o(u){J(i.$$.fragment,u),J(p.$$.fragment,u),y=!1},d(u){u&&(t(d),t(s),t(a)),T(i,u),T(p,u)}}}function Dt(k){let i,d,s,f;return i=new Ze({props:{id:"training-inference",option:"prior model",$$slots:{default:[St]},$$scope:{ctx:k}}}),s=new Ze({props:{id:"training-inference",option:"decoder model",$$slots:{default:[Pt]},$$scope:{ctx:k}}}),{c(){g(i.$$.fragment),d=o(),g(s.$$.fragment)},l(a){_(i.$$.fragment,a),d=r(a),_(s.$$.fragment,a)},m(a,p){w(i,a,p),l(a,d,p),w(s,a,p),f=!0},p(a,p){const y={};p&2&&(y.$$scope={dirty:p,ctx:a}),i.$set(y);const u={};p&2&&(u.$$scope={dirty:p,ctx:a}),s.$set(u)},i(a){f||(U(i.$$.fragment,a),U(s.$$.fragment,a),f=!0)},o(a){J(i.$$.fragment,a),J(s.$$.fragment,a),f=!1},d(a){a&&t(d),T(i,a),T(s,a)}}}function Kt(k){let i,d,s,f,a,p,y,u,$,E="<p>This script is experimental, and it’s easy to overfit and run into issues like catastrophic forgetting. Try exploring different hyperparameters to get the best results on your dataset.</p>",X,W,N="Kandinsky 2.2 is a multilingual text-to-image model capable of producing more photorealistic images. The model includes an image prior model for creating image embeddings from text prompts, and a decoder model that generates images based on the prior model’s embeddings. That’s why you’ll find two separate scripts in Diffusers for Kandinsky 2.2, one for training the prior model and one for training the decoder model. You can train both models separately, but to get the best results, you should train both the prior and decoder models.",C,B,Q='Depending on your GPU, you may need to enable <code>gradient_checkpointing</code> (⚠️ not supported for the prior model!), <code>mixed_precision</code>, and <code>gradient_accumulation_steps</code> to help fit the model into memory and to speedup training. You can reduce your memory-usage even more by enabling memory-efficient attention with <a href="../optimization/xformers">xFormers</a> (version <a href="https://github.com/huggingface/diffusers/issues/2234#issuecomment-1416931212" rel="nofollow">v0.0.16</a> fails for training on some GPUs so you may need to install a development version instead).',R,G,I='This guide explores the <a href="https://github.com/huggingface/diffusers/blob/main/examples/kandinsky2_2/text_to_image/train_text_to_image_prior.py" rel="nofollow">train_text_to_image_prior.py</a> and the <a href="https://github.com/huggingface/diffusers/blob/main/examples/kandinsky2_2/text_to_image/train_text_to_image_decoder.py" rel="nofollow">train_text_to_image_decoder.py</a> scripts to help you become more familiar with it, and how you can adapt it for your own use-case.',V,x,c="Before running the scripts, make sure you install the library from source:",j,H,P,F,m="Then navigate to the example folder containing the training script and install the required dependencies for the script you’re using:",Z,D,Ce,Y,dt='<p>🤗 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.</p>',Re,K,ft="Initialize an 🤗 Accelerate environment:",ve,O,xe,ee,ut="To setup a default 🤗 Accelerate environment without choosing any configurations:",Ge,te,Ie,le,yt="Or if your environment doesn’t support an interactive shell, like a notebook, you can use:",Ve,ne,He,ae,Mt='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.',Xe,A,ht="<p>The following sections highlight parts of the training scripts that are important for understanding how to modify it, but it doesn’t cover every aspect of the scripts in detail. If you’re interested in learning more, feel free to read through the scripts and let us know if you have any questions or concerns.</p>",Be,ie,Ne,se,bt='The training scripts 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/6e68c71503682c8693cb5b06a4da4911dfd655ee/examples/kandinsky2_2/text_to_image/train_text_to_image_prior.py#L190" rel="nofollow"><code>parse_args()</code></a> function. The training scripts 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,oe,gt="For example, to speedup training with mixed precision using the fp16 format, add the <code>--mixed_precision</code> parameter to the training command:",Fe,re,Ee,pe,_t='Most of the parameters are identical to the parameters in the <a href="text2image#script-parameters">Text-to-image</a> training guide, so let’s get straight to a walkthrough of the Kandinsky training scripts!',Ye,me,Ae,ce,wt='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.',Le,de,Ut="Add the <code>--snr_gamma</code> parameter and set it to the recommended value of 5.0:",ze,fe,qe,ue,Se,ye,Jt='The training script is also similar to the <a href="text2image#training-script">Text-to-image</a> training guide, but it’s been modified to support training the prior and decoder models. This guide focuses on the code that is unique to the Kandinsky 2.2 training scripts.',Pe,L,De,Me,Ke,he,Tt="Once you’ve made all your changes or you’re okay with the default configuration, you’re ready to launch the training script! 🚀",Oe,be,$t='You’ll train on the <a href="https://huggingface.co/datasets/lambdalabs/naruto-blip-captions" rel="nofollow">Naruto BLIP captions</a> dataset to generate your own Naruto characters, but you can also create and train on your own dataset by following the <a href="create_dataset">Create a dataset for training</a> guide. Set the environment variable <code>DATASET_NAME</code> to the name of the dataset on the Hub or if you’re training on your own files, set the environment variable <code>TRAIN_DIR</code> to a path to your dataset.',et,ge,jt="If you’re training on more than one GPU, add the <code>--multi_gpu</code> parameter to the <code>accelerate launch</code> command.",tt,z,Zt="<p>To monitor training progress with Weights &amp; Biases, add the <code>--report_to=wandb</code> parameter to the training command. You’ll also need to add the <code>--validation_prompt</code> to the training command to keep track of results. This can be really useful for debugging the model and viewing intermediate results.</p>",lt,q,nt,_e,Wt="Once training is finished, you can use your newly trained model for inference!",at,S,it,we,st,Ue,kt="Congratulations on training a Kandinsky 2.2 model! To learn more about how to use your new model, the following guides may be helpful:",ot,Je,Ct='<li>Read the <a href="../using-diffusers/kandinsky">Kandinsky</a> guide to learn how to use it for a variety of different tasks (text-to-image, image-to-image, inpainting, interpolation), and how it can be combined with a ControlNet.</li> <li>Check out the <a href="dreambooth">DreamBooth</a> and <a href="lora">LoRA</a> training guides to learn how to train a personalized Kandinsky model with just a few example images. These two training techniques can even be combined!</li>',rt,Te,pt,ke,mt;return a=new Qt({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),y=new je({props:{title:"Kandinsky 2.2",local:"kandinsky-22",headingTag:"h1"}}),H=new v({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}}),D=new v({props:{code:"Y2QlMjBleGFtcGxlcyUyRmthbmRpbnNreTJfMiUyRnRleHRfdG9faW1hZ2UlMEFwaXAlMjBpbnN0YWxsJTIwLXIlMjByZXF1aXJlbWVudHMudHh0",highlighted:`<span class="hljs-built_in">cd</span> examples/kandinsky2_2/text_to_image
pip install -r requirements.txt`,wrap:!1}}),O=new v({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),te=new v({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZyUyMGRlZmF1bHQ=",highlighted:"accelerate config default",wrap:!1}}),ne=new v({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}}),ie=new je({props:{title:"Script parameters",local:"script-parameters",headingTag:"h2"}}),re=new v({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX3RleHRfdG9faW1hZ2VfcHJpb3IucHklMjAlNUMlMEElMjAlMjAtLW1peGVkX3ByZWNpc2lvbiUzRCUyMmZwMTYlMjI=",highlighted:`accelerate launch train_text_to_image_prior.py \\
  --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span>`,wrap:!1}}),me=new je({props:{title:"Min-SNR weighting",local:"min-snr-weighting",headingTag:"h3"}}),fe=new v({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX3RleHRfdG9faW1hZ2VfcHJpb3IucHklMjAlNUMlMEElMjAlMjAtLXNucl9nYW1tYSUzRDUuMA==",highlighted:`accelerate launch train_text_to_image_prior.py \\
  --snr_gamma=5.0`,wrap:!1}}),ue=new je({props:{title:"Training script",local:"training-script",headingTag:"h2"}}),L=new ct({props:{id:"script",options:["prior model","decoder model"],$$slots:{default:[At]},$$scope:{ctx:k}}}),Me=new je({props:{title:"Launch the script",local:"launch-the-script",headingTag:"h2"}}),q=new ct({props:{id:"training-inference",options:["prior model","decoder model"],$$slots:{default:[qt]},$$scope:{ctx:k}}}),S=new ct({props:{id:"training-inference",options:["prior model","decoder model"],$$slots:{default:[Dt]},$$scope:{ctx:k}}}),we=new je({props:{title:"Next steps",local:"next-steps",headingTag:"h2"}}),Te=new Ft({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/training/kandinsky.md"}}),{c(){i=M("meta"),d=o(),s=M("p"),f=o(),g(a.$$.fragment),p=o(),g(y.$$.fragment),u=o(),$=M("blockquote"),$.innerHTML=E,X=o(),W=M("p"),W.textContent=N,C=o(),B=M("p"),B.innerHTML=Q,R=o(),G=M("p"),G.innerHTML=I,V=o(),x=M("p"),x.textContent=c,j=o(),g(H.$$.fragment),P=o(),F=M("p"),F.textContent=m,Z=o(),g(D.$$.fragment),Ce=o(),Y=M("blockquote"),Y.innerHTML=dt,Re=o(),K=M("p"),K.textContent=ft,ve=o(),g(O.$$.fragment),xe=o(),ee=M("p"),ee.textContent=ut,Ge=o(),g(te.$$.fragment),Ie=o(),le=M("p"),le.textContent=yt,Ve=o(),g(ne.$$.fragment),He=o(),ae=M("p"),ae.innerHTML=Mt,Xe=o(),A=M("blockquote"),A.innerHTML=ht,Be=o(),g(ie.$$.fragment),Ne=o(),se=M("p"),se.innerHTML=bt,Qe=o(),oe=M("p"),oe.innerHTML=gt,Fe=o(),g(re.$$.fragment),Ee=o(),pe=M("p"),pe.innerHTML=_t,Ye=o(),g(me.$$.fragment),Ae=o(),ce=M("p"),ce.innerHTML=wt,Le=o(),de=M("p"),de.innerHTML=Ut,ze=o(),g(fe.$$.fragment),qe=o(),g(ue.$$.fragment),Se=o(),ye=M("p"),ye.innerHTML=Jt,Pe=o(),g(L.$$.fragment),De=o(),g(Me.$$.fragment),Ke=o(),he=M("p"),he.textContent=Tt,Oe=o(),be=M("p"),be.innerHTML=$t,et=o(),ge=M("p"),ge.innerHTML=jt,tt=o(),z=M("blockquote"),z.innerHTML=Zt,lt=o(),g(q.$$.fragment),nt=o(),_e=M("p"),_e.textContent=Wt,at=o(),g(S.$$.fragment),it=o(),g(we.$$.fragment),st=o(),Ue=M("p"),Ue.textContent=kt,ot=o(),Je=M("ul"),Je.innerHTML=Ct,rt=o(),g(Te.$$.fragment),pt=o(),ke=M("p"),this.h()},l(e){const n=Bt("svelte-u9bgzb",document.head);i=h(n,"META",{name:!0,content:!0}),n.forEach(t),d=r(e),s=h(e,"P",{}),Gt(s).forEach(t),f=r(e),_(a.$$.fragment,e),p=r(e),_(y.$$.fragment,e),u=r(e),$=h(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),b($)!=="svelte-b2kvo6"&&($.innerHTML=E),X=r(e),W=h(e,"P",{"data-svelte-h":!0}),b(W)!=="svelte-6gxptx"&&(W.textContent=N),C=r(e),B=h(e,"P",{"data-svelte-h":!0}),b(B)!=="svelte-1qig94u"&&(B.innerHTML=Q),R=r(e),G=h(e,"P",{"data-svelte-h":!0}),b(G)!=="svelte-1l8tmhd"&&(G.innerHTML=I),V=r(e),x=h(e,"P",{"data-svelte-h":!0}),b(x)!=="svelte-if4ul"&&(x.textContent=c),j=r(e),_(H.$$.fragment,e),P=r(e),F=h(e,"P",{"data-svelte-h":!0}),b(F)!=="svelte-z4z0b9"&&(F.textContent=m),Z=r(e),_(D.$$.fragment,e),Ce=r(e),Y=h(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),b(Y)!=="svelte-1in84qc"&&(Y.innerHTML=dt),Re=r(e),K=h(e,"P",{"data-svelte-h":!0}),b(K)!=="svelte-60q53m"&&(K.textContent=ft),ve=r(e),_(O.$$.fragment,e),xe=r(e),ee=h(e,"P",{"data-svelte-h":!0}),b(ee)!=="svelte-di6juu"&&(ee.textContent=ut),Ge=r(e),_(te.$$.fragment,e),Ie=r(e),le=h(e,"P",{"data-svelte-h":!0}),b(le)!=="svelte-tsz4qp"&&(le.textContent=yt),Ve=r(e),_(ne.$$.fragment,e),He=r(e),ae=h(e,"P",{"data-svelte-h":!0}),b(ae)!=="svelte-1fkfdql"&&(ae.innerHTML=Mt),Xe=r(e),A=h(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),b(A)!=="svelte-egugij"&&(A.innerHTML=ht),Be=r(e),_(ie.$$.fragment,e),Ne=r(e),se=h(e,"P",{"data-svelte-h":!0}),b(se)!=="svelte-r2qipu"&&(se.innerHTML=bt),Qe=r(e),oe=h(e,"P",{"data-svelte-h":!0}),b(oe)!=="svelte-1r0bv1x"&&(oe.innerHTML=gt),Fe=r(e),_(re.$$.fragment,e),Ee=r(e),pe=h(e,"P",{"data-svelte-h":!0}),b(pe)!=="svelte-fx0sux"&&(pe.innerHTML=_t),Ye=r(e),_(me.$$.fragment,e),Ae=r(e),ce=h(e,"P",{"data-svelte-h":!0}),b(ce)!=="svelte-1x34p4w"&&(ce.innerHTML=wt),Le=r(e),de=h(e,"P",{"data-svelte-h":!0}),b(de)!=="svelte-tp3kp"&&(de.innerHTML=Ut),ze=r(e),_(fe.$$.fragment,e),qe=r(e),_(ue.$$.fragment,e),Se=r(e),ye=h(e,"P",{"data-svelte-h":!0}),b(ye)!=="svelte-1c9upjb"&&(ye.innerHTML=Jt),Pe=r(e),_(L.$$.fragment,e),De=r(e),_(Me.$$.fragment,e),Ke=r(e),he=h(e,"P",{"data-svelte-h":!0}),b(he)!=="svelte-9dei1q"&&(he.textContent=Tt),Oe=r(e),be=h(e,"P",{"data-svelte-h":!0}),b(be)!=="svelte-1iz4o7j"&&(be.innerHTML=$t),et=r(e),ge=h(e,"P",{"data-svelte-h":!0}),b(ge)!=="svelte-mj0rx7"&&(ge.innerHTML=jt),tt=r(e),z=h(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),b(z)!=="svelte-rxdmtb"&&(z.innerHTML=Zt),lt=r(e),_(q.$$.fragment,e),nt=r(e),_e=h(e,"P",{"data-svelte-h":!0}),b(_e)!=="svelte-5prdlk"&&(_e.textContent=Wt),at=r(e),_(S.$$.fragment,e),it=r(e),_(we.$$.fragment,e),st=r(e),Ue=h(e,"P",{"data-svelte-h":!0}),b(Ue)!=="svelte-135a8e3"&&(Ue.textContent=kt),ot=r(e),Je=h(e,"UL",{"data-svelte-h":!0}),b(Je)!=="svelte-1mj75la"&&(Je.innerHTML=Ct),rt=r(e),_(Te.$$.fragment,e),pt=r(e),ke=h(e,"P",{}),Gt(ke).forEach(t),this.h()},h(){$e(i,"name","hf:doc:metadata"),$e(i,"content",Ot),$e($,"class","warning"),$e(Y,"class","tip"),$e(A,"class","tip"),$e(z,"class","tip")},m(e,n){Nt(document.head,i),l(e,d,n),l(e,s,n),l(e,f,n),w(a,e,n),l(e,p,n),w(y,e,n),l(e,u,n),l(e,$,n),l(e,X,n),l(e,W,n),l(e,C,n),l(e,B,n),l(e,R,n),l(e,G,n),l(e,V,n),l(e,x,n),l(e,j,n),w(H,e,n),l(e,P,n),l(e,F,n),l(e,Z,n),w(D,e,n),l(e,Ce,n),l(e,Y,n),l(e,Re,n),l(e,K,n),l(e,ve,n),w(O,e,n),l(e,xe,n),l(e,ee,n),l(e,Ge,n),w(te,e,n),l(e,Ie,n),l(e,le,n),l(e,Ve,n),w(ne,e,n),l(e,He,n),l(e,ae,n),l(e,Xe,n),l(e,A,n),l(e,Be,n),w(ie,e,n),l(e,Ne,n),l(e,se,n),l(e,Qe,n),l(e,oe,n),l(e,Fe,n),w(re,e,n),l(e,Ee,n),l(e,pe,n),l(e,Ye,n),w(me,e,n),l(e,Ae,n),l(e,ce,n),l(e,Le,n),l(e,de,n),l(e,ze,n),w(fe,e,n),l(e,qe,n),w(ue,e,n),l(e,Se,n),l(e,ye,n),l(e,Pe,n),w(L,e,n),l(e,De,n),w(Me,e,n),l(e,Ke,n),l(e,he,n),l(e,Oe,n),l(e,be,n),l(e,et,n),l(e,ge,n),l(e,tt,n),l(e,z,n),l(e,lt,n),w(q,e,n),l(e,nt,n),l(e,_e,n),l(e,at,n),w(S,e,n),l(e,it,n),w(we,e,n),l(e,st,n),l(e,Ue,n),l(e,ot,n),l(e,Je,n),l(e,rt,n),w(Te,e,n),l(e,pt,n),l(e,ke,n),mt=!0},p(e,[n]){const Rt={};n&2&&(Rt.$$scope={dirty:n,ctx:e}),L.$set(Rt);const vt={};n&2&&(vt.$$scope={dirty:n,ctx:e}),q.$set(vt);const xt={};n&2&&(xt.$$scope={dirty:n,ctx:e}),S.$set(xt)},i(e){mt||(U(a.$$.fragment,e),U(y.$$.fragment,e),U(H.$$.fragment,e),U(D.$$.fragment,e),U(O.$$.fragment,e),U(te.$$.fragment,e),U(ne.$$.fragment,e),U(ie.$$.fragment,e),U(re.$$.fragment,e),U(me.$$.fragment,e),U(fe.$$.fragment,e),U(ue.$$.fragment,e),U(L.$$.fragment,e),U(Me.$$.fragment,e),U(q.$$.fragment,e),U(S.$$.fragment,e),U(we.$$.fragment,e),U(Te.$$.fragment,e),mt=!0)},o(e){J(a.$$.fragment,e),J(y.$$.fragment,e),J(H.$$.fragment,e),J(D.$$.fragment,e),J(O.$$.fragment,e),J(te.$$.fragment,e),J(ne.$$.fragment,e),J(ie.$$.fragment,e),J(re.$$.fragment,e),J(me.$$.fragment,e),J(fe.$$.fragment,e),J(ue.$$.fragment,e),J(L.$$.fragment,e),J(Me.$$.fragment,e),J(q.$$.fragment,e),J(S.$$.fragment,e),J(we.$$.fragment,e),J(Te.$$.fragment,e),mt=!1},d(e){e&&(t(d),t(s),t(f),t(p),t(u),t($),t(X),t(W),t(C),t(B),t(R),t(G),t(V),t(x),t(j),t(P),t(F),t(Z),t(Ce),t(Y),t(Re),t(K),t(ve),t(xe),t(ee),t(Ge),t(Ie),t(le),t(Ve),t(He),t(ae),t(Xe),t(A),t(Be),t(Ne),t(se),t(Qe),t(oe),t(Fe),t(Ee),t(pe),t(Ye),t(Ae),t(ce),t(Le),t(de),t(ze),t(qe),t(Se),t(ye),t(Pe),t(De),t(Ke),t(he),t(Oe),t(be),t(et),t(ge),t(tt),t(z),t(lt),t(nt),t(_e),t(at),t(it),t(st),t(Ue),t(ot),t(Je),t(rt),t(pt),t(ke)),t(i),T(a,e),T(y,e),T(H,e),T(D,e),T(O,e),T(te,e),T(ne,e),T(ie,e),T(re,e),T(me,e),T(fe,e),T(ue,e),T(L,e),T(Me,e),T(q,e),T(S,e),T(we,e),T(Te,e)}}}const Ot='{"title":"Kandinsky 2.2","local":"kandinsky-22","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":"Next steps","local":"next-steps","sections":[],"depth":2}],"depth":1}';function el(k){return Vt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ol extends Ht{constructor(i){super(),Xt(this,i,el,Kt,It,{})}}export{ol as component};
