import{s as it,o as rt,n as pe}from"../chunks/scheduler.8c3d61f6.js";import{S as pt,i as ot,g as m,s as u,r as w,A as ut,h as d,f as s,c,j as lt,u as M,x as h,k as Xe,y as ct,a as n,v as g,d as J,t as T,w as $}from"../chunks/index.589a98e8.js";import{T as He}from"../chunks/Tip.42aa8582.js";import{C as v}from"../chunks/CodeBlock.36627b28.js";import{H as xe,E as mt}from"../chunks/EditOnGithub.e5a8d9cb.js";import{H as dt,a as at}from"../chunks/HfOption.9804ab8b.js";function ft(Z){let l,f='We strongly recommend reading PyTorch’s <a href="https://pytorch.org/docs/stable/notes/randomness.html" rel="nofollow">statement about reproducibility</a>:',i,p,r="“Completely reproducible results are not guaranteed across PyTorch releases, individual commits, or different platforms. Furthermore, results may not be reproducible between CPU and GPU executions, even when using identical seeds.”";return{c(){l=m("p"),l.innerHTML=f,i=u(),p=m("p"),p.textContent=r},l(a){l=d(a,"P",{"data-svelte-h":!0}),h(l)!=="svelte-ccpr3c"&&(l.innerHTML=f),i=c(a),p=d(a,"P",{"data-svelte-h":!0}),h(p)!=="svelte-1ci17z2"&&(p.textContent=r)},m(a,y){n(a,l,y),n(a,i,y),n(a,p,y)},p:pe,d(a){a&&(s(l),s(i),s(p))}}}function ht(Z){let l,f="It might seem unintuitive to pass <code>Generator</code> objects to a pipeline instead of the integer value representing the seed. However, this is the recommended design when working with probabilistic models in PyTorch because a <code>Generator</code> is a <em>random state</em> that can be passed to multiple pipelines in a sequence. As soon as the <code>Generator</code> is consumed, the <em>state</em> is changed in place which means even if you passed the same <code>Generator</code> to a different pipeline, it won’t produce the same result because the state is already changed.";return{c(){l=m("p"),l.innerHTML=f},l(i){l=d(i,"P",{"data-svelte-h":!0}),h(l)!=="svelte-1jpg0yb"&&(l.innerHTML=f)},m(i,p){n(i,l,p)},p:pe,d(i){i&&s(l)}}}function yt(Z){let l,f='To generate reproducible results on a CPU, you’ll need to use a PyTorch <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">Generator</a> and set a seed. Now when you run the code, it always prints a value of <code>1491.1711</code> because the <code>Generator</code> object with the seed is passed to all the random functions in the pipeline. You should get a similar, if not the same, result on whatever hardware and PyTorch version you’re using.',i,p,r;return p=new v({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjBudW1weSUyMGFzJTIwbnAlMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVBpcGVsaW5lJTBBJTBBZGRpbSUyMCUzRCUyMERESU1QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyZ29vZ2xlJTJGZGRwbS1jaWZhcjEwLTMyJTIyJTJDJTIwdXNlX3NhZmV0ZW5zb3JzJTNEVHJ1ZSklMEFnZW5lcmF0b3IlMjAlM0QlMjB0b3JjaC5HZW5lcmF0b3IoZGV2aWNlJTNEJTIyY3B1JTIyKS5tYW51YWxfc2VlZCgwKSUwQWltYWdlJTIwJTNEJTIwZGRpbShudW1faW5mZXJlbmNlX3N0ZXBzJTNEMiUyQyUyMG91dHB1dF90eXBlJTNEJTIybnAlMjIlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IpLmltYWdlcyUwQXByaW50KG5wLmFicyhpbWFnZSkuc3VtKCkp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMPipeline

ddim = DDIMPipeline.from_pretrained(<span class="hljs-string">&quot;google/ddpm-cifar10-32&quot;</span>, use_safetensors=<span class="hljs-literal">True</span>)
generator = torch.Generator(device=<span class="hljs-string">&quot;cpu&quot;</span>).manual_seed(<span class="hljs-number">0</span>)
image = ddim(num_inference_steps=<span class="hljs-number">2</span>, output_type=<span class="hljs-string">&quot;np&quot;</span>, generator=generator).images
<span class="hljs-built_in">print</span>(np.<span class="hljs-built_in">abs</span>(image).<span class="hljs-built_in">sum</span>())`,wrap:!1}}),{c(){l=m("p"),l.innerHTML=f,i=u(),w(p.$$.fragment)},l(a){l=d(a,"P",{"data-svelte-h":!0}),h(l)!=="svelte-mi9bj0"&&(l.innerHTML=f),i=c(a),M(p.$$.fragment,a)},m(a,y){n(a,l,y),n(a,i,y),g(p,a,y),r=!0},p:pe,i(a){r||(J(p.$$.fragment,a),r=!0)},o(a){T(p.$$.fragment,a),r=!1},d(a){a&&(s(l),s(i)),$(p,a)}}}function bt(Z){let l,f="If reproducibility is important to your use case, we recommend always passing a CPU <code>Generator</code>. The performance loss is often negligible and you’ll generate more similar values than if the pipeline had been run on a GPU.";return{c(){l=m("p"),l.innerHTML=f},l(i){l=d(i,"P",{"data-svelte-h":!0}),h(l)!=="svelte-jred1k"&&(l.innerHTML=f)},m(i,p){n(i,l,p)},p:pe,d(i){i&&s(l)}}}function wt(Z){let l,f="Writing a reproducible pipeline on a GPU is a bit trickier, and full reproducibility across different hardware is not guaranteed because matrix multiplication - which diffusion pipelines require a lot of - is less deterministic on a GPU than a CPU. For example, if you run the same code example from the CPU example, you’ll get a different result even though the seed is identical. This is because the GPU uses a different random number generator than the CPU.",i,p,r,a,y='To avoid this issue, Diffusers has a <a href="/docs/diffusers/pr_7830/en/api/utilities#diffusers.utils.torch_utils.randn_tensor">randn_tensor()</a> function for creating random noise on the CPU, and then moving the tensor to a GPU if necessary. The <a href="/docs/diffusers/pr_7830/en/api/utilities#diffusers.utils.torch_utils.randn_tensor">randn_tensor()</a> function is used everywhere inside the pipeline. Now you can call <a href="https://pytorch.org/docs/stable/generated/torch.manual_seed.html" rel="nofollow">torch.manual_seed</a> which automatically creates a CPU <code>Generator</code> that can be passed to the pipeline even if it is being run on a GPU.',I,U,G,W,C,j,x=`Finally, more complex pipelines such as <a href="/docs/diffusers/pr_7830/en/api/pipelines/unclip#diffusers.UnCLIPPipeline">UnCLIPPipeline</a>, are often extremely
susceptible to precision error propagation. You’ll need to use
exactly the same hardware and PyTorch version for full reproducibility.`,_;return p=new v({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjBudW1weSUyMGFzJTIwbnAlMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVBpcGVsaW5lJTBBJTBBZGRpbSUyMCUzRCUyMERESU1QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyZ29vZ2xlJTJGZGRwbS1jaWZhcjEwLTMyJTIyJTJDJTIwdXNlX3NhZmV0ZW5zb3JzJTNEVHJ1ZSklMEFkZGltLnRvKCUyMmN1ZGElMjIpJTBBZ2VuZXJhdG9yJTIwJTNEJTIwdG9yY2guR2VuZXJhdG9yKGRldmljZSUzRCUyMmN1ZGElMjIpLm1hbnVhbF9zZWVkKDApJTBBaW1hZ2UlMjAlM0QlMjBkZGltKG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyJTJDJTIwb3V0cHV0X3R5cGUlM0QlMjJucCUyMiUyQyUyMGdlbmVyYXRvciUzRGdlbmVyYXRvcikuaW1hZ2VzJTBBcHJpbnQobnAuYWJzKGltYWdlKS5zdW0oKSk=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMPipeline

ddim = DDIMPipeline.from_pretrained(<span class="hljs-string">&quot;google/ddpm-cifar10-32&quot;</span>, use_safetensors=<span class="hljs-literal">True</span>)
ddim.to(<span class="hljs-string">&quot;cuda&quot;</span>)
generator = torch.Generator(device=<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(<span class="hljs-number">0</span>)
image = ddim(num_inference_steps=<span class="hljs-number">2</span>, output_type=<span class="hljs-string">&quot;np&quot;</span>, generator=generator).images
<span class="hljs-built_in">print</span>(np.<span class="hljs-built_in">abs</span>(image).<span class="hljs-built_in">sum</span>())`,wrap:!1}}),U=new v({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjBudW1weSUyMGFzJTIwbnAlMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVBpcGVsaW5lJTBBJTBBZGRpbSUyMCUzRCUyMERESU1QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyZ29vZ2xlJTJGZGRwbS1jaWZhcjEwLTMyJTIyJTJDJTIwdXNlX3NhZmV0ZW5zb3JzJTNEVHJ1ZSklMEFkZGltLnRvKCUyMmN1ZGElMjIpJTBBZ2VuZXJhdG9yJTIwJTNEJTIwdG9yY2gubWFudWFsX3NlZWQoMCklMEFpbWFnZSUyMCUzRCUyMGRkaW0obnVtX2luZmVyZW5jZV9zdGVwcyUzRDIlMkMlMjBvdXRwdXRfdHlwZSUzRCUyMm5wJTIyJTJDJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yKS5pbWFnZXMlMEFwcmludChucC5hYnMoaW1hZ2UpLnN1bSgpKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMPipeline

ddim = DDIMPipeline.from_pretrained(<span class="hljs-string">&quot;google/ddpm-cifar10-32&quot;</span>, use_safetensors=<span class="hljs-literal">True</span>)
ddim.to(<span class="hljs-string">&quot;cuda&quot;</span>)
generator = torch.manual_seed(<span class="hljs-number">0</span>)
image = ddim(num_inference_steps=<span class="hljs-number">2</span>, output_type=<span class="hljs-string">&quot;np&quot;</span>, generator=generator).images
<span class="hljs-built_in">print</span>(np.<span class="hljs-built_in">abs</span>(image).<span class="hljs-built_in">sum</span>())`,wrap:!1}}),W=new He({props:{warning:!1,$$slots:{default:[bt]},$$scope:{ctx:Z}}}),{c(){l=m("p"),l.textContent=f,i=u(),w(p.$$.fragment),r=u(),a=m("p"),a.innerHTML=y,I=u(),w(U.$$.fragment),G=u(),w(W.$$.fragment),C=u(),j=m("p"),j.innerHTML=x},l(o){l=d(o,"P",{"data-svelte-h":!0}),h(l)!=="svelte-1v52ack"&&(l.textContent=f),i=c(o),M(p.$$.fragment,o),r=c(o),a=d(o,"P",{"data-svelte-h":!0}),h(a)!=="svelte-w9gr6p"&&(a.innerHTML=y),I=c(o),M(U.$$.fragment,o),G=c(o),M(W.$$.fragment,o),C=c(o),j=d(o,"P",{"data-svelte-h":!0}),h(j)!=="svelte-2cgipi"&&(j.innerHTML=x)},m(o,b){n(o,l,b),n(o,i,b),g(p,o,b),n(o,r,b),n(o,a,b),n(o,I,b),g(U,o,b),n(o,G,b),g(W,o,b),n(o,C,b),n(o,j,b),_=!0},p(o,b){const ie={};b&2&&(ie.$$scope={dirty:b,ctx:o}),W.$set(ie)},i(o){_||(J(p.$$.fragment,o),J(U.$$.fragment,o),J(W.$$.fragment,o),_=!0)},o(o){T(p.$$.fragment,o),T(U.$$.fragment,o),T(W.$$.fragment,o),_=!1},d(o){o&&(s(l),s(i),s(r),s(a),s(I),s(G),s(C),s(j)),$(p,o),$(U,o),$(W,o)}}}function Mt(Z){let l,f,i,p;return l=new at({props:{id:"hardware",option:"CPU",$$slots:{default:[yt]},$$scope:{ctx:Z}}}),i=new at({props:{id:"hardware",option:"GPU",$$slots:{default:[wt]},$$scope:{ctx:Z}}}),{c(){w(l.$$.fragment),f=u(),w(i.$$.fragment)},l(r){M(l.$$.fragment,r),f=c(r),M(i.$$.fragment,r)},m(r,a){g(l,r,a),n(r,f,a),g(i,r,a),p=!0},p(r,a){const y={};a&2&&(y.$$scope={dirty:a,ctx:r}),l.$set(y);const I={};a&2&&(I.$$scope={dirty:a,ctx:r}),i.$set(I)},i(r){p||(J(l.$$.fragment,r),J(i.$$.fragment,r),p=!0)},o(r){T(l.$$.fragment,r),T(i.$$.fragment,r),p=!1},d(r){r&&s(f),$(l,r),$(i,r)}}}function gt(Z){let l,f="Use a list comprehension that iterates over the batch size specified in <code>range()</code> to create a unique <code>Generator</code> object for each image in the batch. If you multiply the <code>Generator</code> by the batch size integer, it only creates <em>one</em> <code>Generator</code> object that is used sequentially for each image in the batch.",i,p,r;return p=new v({props:{code:"JTVCdG9yY2guR2VuZXJhdG9yKCkubWFudWFsX3NlZWQoc2VlZCklNUQlMjAqJTIwNA==",highlighted:'[torch.Generator().manual_seed(seed)] * <span class="hljs-number">4</span>',wrap:!1}}),{c(){l=m("p"),l.innerHTML=f,i=u(),w(p.$$.fragment)},l(a){l=d(a,"P",{"data-svelte-h":!0}),h(l)!=="svelte-9rxsgm"&&(l.innerHTML=f),i=c(a),M(p.$$.fragment,a)},m(a,y){n(a,l,y),n(a,i,y),g(p,a,y),r=!0},p:pe,i(a){r||(J(p.$$.fragment,a),r=!0)},o(a){T(p.$$.fragment,a),r=!1},d(a){a&&(s(l),s(i)),$(p,a)}}}function Jt(Z){let l,f,i,p,r,a,y,I='Diffusion models are inherently random which is what allows it to generate different outputs every time it is run. But there are certain times when you want to generate the same output every time, like when you’re testing, replicating results, and even <a href="#deterministic-batch-generation">improving image quality</a>. While you can’t expect to get identical results across platforms, you can expect reproducible results across releases and platforms within a certain tolerance range (though even this may vary).',U,G,W="This guide will show you how to control randomness for deterministic generation on a CPU and GPU.",C,j,x,_,o,b,ie=`During inference, pipelines rely heavily on random sampling operations which include creating the
Gaussian noise tensors to denoise and adding noise to the scheduling step.`,oe,H,Qe='Take a look at the tensor values in the <a href="/docs/diffusers/pr_7830/en/api/pipelines/ddim#diffusers.DDIMPipeline">DDIMPipeline</a> after two inference steps.',ue,Q,ce,N,Ne="Running the code above prints one value, but if you run it again you get a different value.",me,P,Pe='Each time the pipeline is run, <a href="https://pytorch.org/docs/stable/generated/torch.randn.html" rel="nofollow">torch.randn</a> uses a different random seed to create the Gaussian noise tensors. This leads to a different result each time it is run and enables the diffusion pipeline to generate a different random image each time.',de,E,Ee="But if you need to reliably generate the same image, that depends on whether you’re running the pipeline on a CPU or GPU.",fe,k,he,B,ye,z,be,S,ze="You can also configure PyTorch to use deterministic algorithms to create a reproducible pipeline. The downside is that deterministic algorithms may be slower than non-deterministic ones and you may observe a decrease in performance.",we,F,Se='Non-deterministic behavior occurs when operations are launched in more than one CUDA stream. To avoid this, set the environment variable <a href="https://docs.nvidia.com/cuda/cublas/index.html#results-reproducibility" rel="nofollow">CUBLAS_WORKSPACE_CONFIG</a> to <code>:16:8</code> to only use one buffer size during runtime.',Me,L,Fe='PyTorch typically benchmarks multiple algorithms to select the fastest one, but if you want reproducibility, you should disable this feature because the benchmark may select different algorithms each time. Set Diffusers <a href="https://github.com/huggingface/diffusers/blob/142f353e1c638ff1d20bd798402b68f72c1ebbdd/src/diffusers/utils/testing_utils.py#L861" rel="nofollow">enable_full_determinism</a> to enable deterministic algorithms.',ge,q,Je,Y,Le="Now when you run the same pipeline twice, you’ll get identical results.",Te,D,$e,K,Ze,A,qe='A practical application of creating reproducible pipelines is <em>deterministic batch generation</em>. You generate a batch of images and select one image to improve with a more detailed prompt. The main idea is to pass a list of <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">Generator’s</a> to the pipeline and tie each <code>Generator</code> to a seed so you can reuse it.',je,O,Ye='Let’s use the <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5" rel="nofollow">runwayml/stable-diffusion-v1-5</a> checkpoint and generate a batch of images.',Ue,ee,Ge,te,De="Define four different <code>Generator</code>s and assign each <code>Generator</code> a seed (<code>0</code> to <code>3</code>). Then generate a batch of images and pick one to iterate on.",_e,R,We,se,Ie,V,Ke='<img src="https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/reusabe_seeds.jpg"/>',ve,ne,Ae="Let’s improve the first image (you can choose any image you want) which corresponds to the <code>Generator</code> with seed <code>0</code>. Add some additional text to your prompt and then make sure you reuse the same <code>Generator</code> with seed <code>0</code>. All the generated images should resemble the first image.",Ce,le,ke,X,Oe='<img src="https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/reusabe_seeds_2.jpg"/>',Be,ae,Re,re,Ve;return r=new xe({props:{title:"Reproducible pipelines",local:"reproducible-pipelines",headingTag:"h1"}}),j=new He({props:{warning:!1,$$slots:{default:[ft]},$$scope:{ctx:Z}}}),_=new xe({props:{title:"Control randomness",local:"control-randomness",headingTag:"h2"}}),Q=new v({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERESU1QaXBlbGluZSUwQWltcG9ydCUyMG51bXB5JTIwYXMlMjBucCUwQSUwQWRkaW0lMjAlM0QlMjBERElNUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMCUyMmdvb2dsZSUyRmRkcG0tY2lmYXIxMC0zMiUyMiUyQyUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUpJTBBaW1hZ2UlMjAlM0QlMjBkZGltKG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyJTJDJTIwb3V0cHV0X3R5cGUlM0QlMjJucCUyMikuaW1hZ2VzJTBBcHJpbnQobnAuYWJzKGltYWdlKS5zdW0oKSk=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMPipeline
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

ddim = DDIMPipeline.from_pretrained( <span class="hljs-string">&quot;google/ddpm-cifar10-32&quot;</span>, use_safetensors=<span class="hljs-literal">True</span>)
image = ddim(num_inference_steps=<span class="hljs-number">2</span>, output_type=<span class="hljs-string">&quot;np&quot;</span>).images
<span class="hljs-built_in">print</span>(np.<span class="hljs-built_in">abs</span>(image).<span class="hljs-built_in">sum</span>())`,wrap:!1}}),k=new He({props:{warning:!1,$$slots:{default:[ht]},$$scope:{ctx:Z}}}),B=new dt({props:{id:"hardware",options:["CPU","GPU"],$$slots:{default:[Mt]},$$scope:{ctx:Z}}}),z=new xe({props:{title:"Deterministic algorithms",local:"deterministic-algorithms",headingTag:"h2"}}),q=new v({props:{code:"ZW5hYmxlX2Z1bGxfZGV0ZXJtaW5pc20oKQ==",highlighted:"enable_full_determinism()",wrap:!1}}),D=new v({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVNjaGVkdWxlciUyQyUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZSUyMCUzRCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUyQyUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUpLnRvKCUyMmN1ZGElMjIpJTBBcGlwZS5zY2hlZHVsZXIlMjAlM0QlMjBERElNU2NoZWR1bGVyLmZyb21fY29uZmlnKHBpcGUuc2NoZWR1bGVyLmNvbmZpZyklMEFnJTIwJTNEJTIwdG9yY2guR2VuZXJhdG9yKGRldmljZSUzRCUyMmN1ZGElMjIpJTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyQSUyMGJlYXIlMjBpcyUyMHBsYXlpbmclMjBhJTIwZ3VpdGFyJTIwb24lMjBUaW1lcyUyMFNxdWFyZSUyMiUwQSUwQWcubWFudWFsX3NlZWQoMCklMEFyZXN1bHQxJTIwJTNEJTIwcGlwZShwcm9tcHQlM0Rwcm9tcHQlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNENTAlMkMlMjBnZW5lcmF0b3IlM0RnJTJDJTIwb3V0cHV0X3R5cGUlM0QlMjJsYXRlbnQlMjIpLmltYWdlcyUwQSUwQWcubWFudWFsX3NlZWQoMCklMEFyZXN1bHQyJTIwJTNEJTIwcGlwZShwcm9tcHQlM0Rwcm9tcHQlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNENTAlMkMlMjBnZW5lcmF0b3IlM0RnJTJDJTIwb3V0cHV0X3R5cGUlM0QlMjJsYXRlbnQlMjIpLmltYWdlcyUwQSUwQXByaW50KCUyMkxfaW5mJTIwZGlzdCUyMCUzRCUyMiUyQyUyMGFicyhyZXN1bHQxJTIwLSUyMHJlc3VsdDIpLm1heCgpKSUwQSUyMkxfaW5mJTIwZGlzdCUyMCUzRCUyMHRlbnNvcigwLiUyQyUyMGRldmljZSUzRCdjdWRhJTNBMCcpJTIy",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>, use_safetensors=<span class="hljs-literal">True</span>).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
g = torch.Generator(device=<span class="hljs-string">&quot;cuda&quot;</span>)

prompt = <span class="hljs-string">&quot;A bear is playing a guitar on Times Square&quot;</span>

g.manual_seed(<span class="hljs-number">0</span>)
result1 = pipe(prompt=prompt, num_inference_steps=<span class="hljs-number">50</span>, generator=g, output_type=<span class="hljs-string">&quot;latent&quot;</span>).images

g.manual_seed(<span class="hljs-number">0</span>)
result2 = pipe(prompt=prompt, num_inference_steps=<span class="hljs-number">50</span>, generator=g, output_type=<span class="hljs-string">&quot;latent&quot;</span>).images

<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;L_inf dist =&quot;</span>, <span class="hljs-built_in">abs</span>(result1 - result2).<span class="hljs-built_in">max</span>())
<span class="hljs-string">&quot;L_inf dist = tensor(0., device=&#x27;cuda:0&#x27;)&quot;</span>`,wrap:!1}}),K=new xe({props:{title:"Deterministic batch generation",local:"deterministic-batch-generation",headingTag:"h2"}}),ee=new v({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRGlmZnVzaW9uUGlwZWxpbmUlMEFmcm9tJTIwZGlmZnVzZXJzLnV0aWxzJTIwaW1wb3J0JTIwbWFrZV9pbWFnZV9ncmlkJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIycnVud2F5bWwlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMkMlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlJTBBKSUwQXBpcGVsaW5lJTIwJTNEJTIwcGlwZWxpbmUudG8oJTIyY3VkYSUyMik=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> make_image_grid

pipeline = DiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>, torch_dtype=torch.float16, use_safetensors=<span class="hljs-literal">True</span>
)
pipeline = pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)`,wrap:!1}}),R=new He({props:{warning:!0,$$slots:{default:[gt]},$$scope:{ctx:Z}}}),se=new v({props:{code:"Z2VuZXJhdG9yJTIwJTNEJTIwJTVCdG9yY2guR2VuZXJhdG9yKGRldmljZSUzRCUyMmN1ZGElMjIpLm1hbnVhbF9zZWVkKGkpJTIwZm9yJTIwaSUyMGluJTIwcmFuZ2UoNCklNUQlMEFwcm9tcHQlMjAlM0QlMjAlMjJMYWJyYWRvciUyMGluJTIwdGhlJTIwc3R5bGUlMjBvZiUyMFZlcm1lZXIlMjIlMEFpbWFnZXMlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IlMkMlMjBudW1faW1hZ2VzX3Blcl9wcm9tcHQlM0Q0KS5pbWFnZXMlNUIwJTVEJTBBbWFrZV9pbWFnZV9ncmlkKGltYWdlcyUyQyUyMHJvd3MlM0QyJTJDJTIwY29scyUzRDIp",highlighted:`generator = [torch.Generator(device=<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(i) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">4</span>)]
prompt = <span class="hljs-string">&quot;Labrador in the style of Vermeer&quot;</span>
images = pipeline(prompt, generator=generator, num_images_per_prompt=<span class="hljs-number">4</span>).images[<span class="hljs-number">0</span>]
make_image_grid(images, rows=<span class="hljs-number">2</span>, cols=<span class="hljs-number">2</span>)`,wrap:!1}}),le=new v({props:{code:"cHJvbXB0JTIwJTNEJTIwJTVCcHJvbXB0JTIwJTJCJTIwdCUyMGZvciUyMHQlMjBpbiUyMCU1QiUyMiUyQyUyMGhpZ2hseSUyMHJlYWxpc3RpYyUyMiUyQyUyMCUyMiUyQyUyMGFydHN5JTIyJTJDJTIwJTIyJTJDJTIwdHJlbmRpbmclMjIlMkMlMjAlMjIlMkMlMjBjb2xvcmZ1bCUyMiU1RCU1RCUwQWdlbmVyYXRvciUyMCUzRCUyMCU1QnRvcmNoLkdlbmVyYXRvcihkZXZpY2UlM0QlMjJjdWRhJTIyKS5tYW51YWxfc2VlZCgwKSUyMGZvciUyMGklMjBpbiUyMHJhbmdlKDQpJTVEJTBBaW1hZ2VzJTIwJTNEJTIwcGlwZWxpbmUocHJvbXB0JTJDJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yKS5pbWFnZXMlMEFtYWtlX2ltYWdlX2dyaWQoaW1hZ2VzJTJDJTIwcm93cyUzRDIlMkMlMjBjb2xzJTNEMik=",highlighted:`prompt = [prompt + t <span class="hljs-keyword">for</span> t <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;, highly realistic&quot;</span>, <span class="hljs-string">&quot;, artsy&quot;</span>, <span class="hljs-string">&quot;, trending&quot;</span>, <span class="hljs-string">&quot;, colorful&quot;</span>]]
generator = [torch.Generator(device=<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(<span class="hljs-number">0</span>) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">4</span>)]
images = pipeline(prompt, generator=generator).images
make_image_grid(images, rows=<span class="hljs-number">2</span>, cols=<span class="hljs-number">2</span>)`,wrap:!1}}),ae=new mt({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/using-diffusers/reusing_seeds.md"}}),{c(){l=m("meta"),f=u(),i=m("p"),p=u(),w(r.$$.fragment),a=u(),y=m("p"),y.innerHTML=I,U=u(),G=m("p"),G.textContent=W,C=u(),w(j.$$.fragment),x=u(),w(_.$$.fragment),o=u(),b=m("p"),b.textContent=ie,oe=u(),H=m("p"),H.innerHTML=Qe,ue=u(),w(Q.$$.fragment),ce=u(),N=m("p"),N.textContent=Ne,me=u(),P=m("p"),P.innerHTML=Pe,de=u(),E=m("p"),E.textContent=Ee,fe=u(),w(k.$$.fragment),he=u(),w(B.$$.fragment),ye=u(),w(z.$$.fragment),be=u(),S=m("p"),S.textContent=ze,we=u(),F=m("p"),F.innerHTML=Se,Me=u(),L=m("p"),L.innerHTML=Fe,ge=u(),w(q.$$.fragment),Je=u(),Y=m("p"),Y.textContent=Le,Te=u(),w(D.$$.fragment),$e=u(),w(K.$$.fragment),Ze=u(),A=m("p"),A.innerHTML=qe,je=u(),O=m("p"),O.innerHTML=Ye,Ue=u(),w(ee.$$.fragment),Ge=u(),te=m("p"),te.innerHTML=De,_e=u(),w(R.$$.fragment),We=u(),w(se.$$.fragment),Ie=u(),V=m("div"),V.innerHTML=Ke,ve=u(),ne=m("p"),ne.innerHTML=Ae,Ce=u(),w(le.$$.fragment),ke=u(),X=m("div"),X.innerHTML=Oe,Be=u(),w(ae.$$.fragment),Re=u(),re=m("p"),this.h()},l(e){const t=ut("svelte-u9bgzb",document.head);l=d(t,"META",{name:!0,content:!0}),t.forEach(s),f=c(e),i=d(e,"P",{}),lt(i).forEach(s),p=c(e),M(r.$$.fragment,e),a=c(e),y=d(e,"P",{"data-svelte-h":!0}),h(y)!=="svelte-13kjkmn"&&(y.innerHTML=I),U=c(e),G=d(e,"P",{"data-svelte-h":!0}),h(G)!=="svelte-117kc42"&&(G.textContent=W),C=c(e),M(j.$$.fragment,e),x=c(e),M(_.$$.fragment,e),o=c(e),b=d(e,"P",{"data-svelte-h":!0}),h(b)!=="svelte-1tn5oba"&&(b.textContent=ie),oe=c(e),H=d(e,"P",{"data-svelte-h":!0}),h(H)!=="svelte-hu38yp"&&(H.innerHTML=Qe),ue=c(e),M(Q.$$.fragment,e),ce=c(e),N=d(e,"P",{"data-svelte-h":!0}),h(N)!=="svelte-1oqpaak"&&(N.textContent=Ne),me=c(e),P=d(e,"P",{"data-svelte-h":!0}),h(P)!=="svelte-ppvtm"&&(P.innerHTML=Pe),de=c(e),E=d(e,"P",{"data-svelte-h":!0}),h(E)!=="svelte-uamouh"&&(E.textContent=Ee),fe=c(e),M(k.$$.fragment,e),he=c(e),M(B.$$.fragment,e),ye=c(e),M(z.$$.fragment,e),be=c(e),S=d(e,"P",{"data-svelte-h":!0}),h(S)!=="svelte-gypex5"&&(S.textContent=ze),we=c(e),F=d(e,"P",{"data-svelte-h":!0}),h(F)!=="svelte-dxdx5v"&&(F.innerHTML=Se),Me=c(e),L=d(e,"P",{"data-svelte-h":!0}),h(L)!=="svelte-180x72j"&&(L.innerHTML=Fe),ge=c(e),M(q.$$.fragment,e),Je=c(e),Y=d(e,"P",{"data-svelte-h":!0}),h(Y)!=="svelte-b9yuf0"&&(Y.textContent=Le),Te=c(e),M(D.$$.fragment,e),$e=c(e),M(K.$$.fragment,e),Ze=c(e),A=d(e,"P",{"data-svelte-h":!0}),h(A)!=="svelte-1i3uu02"&&(A.innerHTML=qe),je=c(e),O=d(e,"P",{"data-svelte-h":!0}),h(O)!=="svelte-1sqzo4u"&&(O.innerHTML=Ye),Ue=c(e),M(ee.$$.fragment,e),Ge=c(e),te=d(e,"P",{"data-svelte-h":!0}),h(te)!=="svelte-n4jqbl"&&(te.innerHTML=De),_e=c(e),M(R.$$.fragment,e),We=c(e),M(se.$$.fragment,e),Ie=c(e),V=d(e,"DIV",{class:!0,"data-svelte-h":!0}),h(V)!=="svelte-1709zt"&&(V.innerHTML=Ke),ve=c(e),ne=d(e,"P",{"data-svelte-h":!0}),h(ne)!=="svelte-c26xxu"&&(ne.innerHTML=Ae),Ce=c(e),M(le.$$.fragment,e),ke=c(e),X=d(e,"DIV",{class:!0,"data-svelte-h":!0}),h(X)!=="svelte-cjmjeo"&&(X.innerHTML=Oe),Be=c(e),M(ae.$$.fragment,e),Re=c(e),re=d(e,"P",{}),lt(re).forEach(s),this.h()},h(){Xe(l,"name","hf:doc:metadata"),Xe(l,"content",Tt),Xe(V,"class","flex justify-center"),Xe(X,"class","flex justify-center")},m(e,t){ct(document.head,l),n(e,f,t),n(e,i,t),n(e,p,t),g(r,e,t),n(e,a,t),n(e,y,t),n(e,U,t),n(e,G,t),n(e,C,t),g(j,e,t),n(e,x,t),g(_,e,t),n(e,o,t),n(e,b,t),n(e,oe,t),n(e,H,t),n(e,ue,t),g(Q,e,t),n(e,ce,t),n(e,N,t),n(e,me,t),n(e,P,t),n(e,de,t),n(e,E,t),n(e,fe,t),g(k,e,t),n(e,he,t),g(B,e,t),n(e,ye,t),g(z,e,t),n(e,be,t),n(e,S,t),n(e,we,t),n(e,F,t),n(e,Me,t),n(e,L,t),n(e,ge,t),g(q,e,t),n(e,Je,t),n(e,Y,t),n(e,Te,t),g(D,e,t),n(e,$e,t),g(K,e,t),n(e,Ze,t),n(e,A,t),n(e,je,t),n(e,O,t),n(e,Ue,t),g(ee,e,t),n(e,Ge,t),n(e,te,t),n(e,_e,t),g(R,e,t),n(e,We,t),g(se,e,t),n(e,Ie,t),n(e,V,t),n(e,ve,t),n(e,ne,t),n(e,Ce,t),g(le,e,t),n(e,ke,t),n(e,X,t),n(e,Be,t),g(ae,e,t),n(e,Re,t),n(e,re,t),Ve=!0},p(e,[t]){const et={};t&2&&(et.$$scope={dirty:t,ctx:e}),j.$set(et);const tt={};t&2&&(tt.$$scope={dirty:t,ctx:e}),k.$set(tt);const st={};t&2&&(st.$$scope={dirty:t,ctx:e}),B.$set(st);const nt={};t&2&&(nt.$$scope={dirty:t,ctx:e}),R.$set(nt)},i(e){Ve||(J(r.$$.fragment,e),J(j.$$.fragment,e),J(_.$$.fragment,e),J(Q.$$.fragment,e),J(k.$$.fragment,e),J(B.$$.fragment,e),J(z.$$.fragment,e),J(q.$$.fragment,e),J(D.$$.fragment,e),J(K.$$.fragment,e),J(ee.$$.fragment,e),J(R.$$.fragment,e),J(se.$$.fragment,e),J(le.$$.fragment,e),J(ae.$$.fragment,e),Ve=!0)},o(e){T(r.$$.fragment,e),T(j.$$.fragment,e),T(_.$$.fragment,e),T(Q.$$.fragment,e),T(k.$$.fragment,e),T(B.$$.fragment,e),T(z.$$.fragment,e),T(q.$$.fragment,e),T(D.$$.fragment,e),T(K.$$.fragment,e),T(ee.$$.fragment,e),T(R.$$.fragment,e),T(se.$$.fragment,e),T(le.$$.fragment,e),T(ae.$$.fragment,e),Ve=!1},d(e){e&&(s(f),s(i),s(p),s(a),s(y),s(U),s(G),s(C),s(x),s(o),s(b),s(oe),s(H),s(ue),s(ce),s(N),s(me),s(P),s(de),s(E),s(fe),s(he),s(ye),s(be),s(S),s(we),s(F),s(Me),s(L),s(ge),s(Je),s(Y),s(Te),s($e),s(Ze),s(A),s(je),s(O),s(Ue),s(Ge),s(te),s(_e),s(We),s(Ie),s(V),s(ve),s(ne),s(Ce),s(ke),s(X),s(Be),s(Re),s(re)),s(l),$(r,e),$(j,e),$(_,e),$(Q,e),$(k,e),$(B,e),$(z,e),$(q,e),$(D,e),$(K,e),$(ee,e),$(R,e),$(se,e),$(le,e),$(ae,e)}}}const Tt='{"title":"Reproducible pipelines","local":"reproducible-pipelines","sections":[{"title":"Control randomness","local":"control-randomness","sections":[],"depth":2},{"title":"Deterministic algorithms","local":"deterministic-algorithms","sections":[],"depth":2},{"title":"Deterministic batch generation","local":"deterministic-batch-generation","sections":[],"depth":2}],"depth":1}';function $t(Z){return rt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class It extends pt{constructor(l){super(),ot(this,l,$t,Jt,it,{})}}export{It as component};
