Buckets:

hf-doc-build/doc / diffusers /v0.15.0 /en /_app /pages /using-diffusers /reproducibility.mdx-hf-doc-builder.js
rtrm's picture
download
raw
27.2 kB
import{S as pr,i as dr,s as ur,e as n,k as u,w as D,t as o,M as cr,c as a,d as t,m as c,a as i,x as U,h as l,b as f,G as s,g as p,y as k,q as C,o as G,B as T,v as fr}from"../../chunks/vendor-hf-doc-builder.js";import{T as js}from"../../chunks/Tip-hf-doc-builder.js";import{D as mr}from"../../chunks/Docstring-hf-doc-builder.js";import{C as Gt}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as Ye}from"../../chunks/IconCopyLink-hf-doc-builder.js";function hr(W){let d,b,m,h,E,_,$,w,j;return{c(){d=n("p"),b=o("\u{1F4A1} We strongly recommend reading PyTorch\u2019s "),m=n("a"),h=o("statement about reproducibility"),E=o(":"),_=u(),$=n("blockquote"),w=n("p"),j=o("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."),this.h()},l(v){d=a(v,"P",{});var y=i(d);b=l(y,"\u{1F4A1} We strongly recommend reading PyTorch\u2019s "),m=a(y,"A",{href:!0,rel:!0});var I=i(m);h=l(I,"statement about reproducibility"),I.forEach(t),E=l(y,":"),y.forEach(t),_=c(v),$=a(v,"BLOCKQUOTE",{});var g=i($);w=a(g,"P",{});var A=i(w);j=l(A,"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."),A.forEach(t),g.forEach(t),this.h()},h(){f(m,"href","https://pytorch.org/docs/stable/notes/randomness.html"),f(m,"rel","nofollow")},m(v,y){p(v,d,y),s(d,b),s(d,m),s(m,h),s(d,E),p(v,_,y),p(v,$,y),s($,w),s(w,j)},d(v){v&&t(d),v&&t(_),v&&t($)}}}function yr(W){let d,b,m,h,E,_,$,w,j,v,y;return{c(){d=n("p"),b=o("\u{1F4A1} It might be a bit unintuitive at first to pass "),m=n("code"),h=o("Generator"),E=o(` objects to the pipeline instead of
just integer values representing the seed, but this is the recommended design when dealing with
probabilistic models in PyTorch as `),_=n("code"),$=o("Generator"),w=o("\u2019s are "),j=n("em"),v=o("random states"),y=o(` that can be
passed to multiple pipelines in a sequence.`)},l(I){d=a(I,"P",{});var g=i(d);b=l(g,"\u{1F4A1} It might be a bit unintuitive at first to pass "),m=a(g,"CODE",{});var A=i(m);h=l(A,"Generator"),A.forEach(t),E=l(g,` objects to the pipeline instead of
just integer values representing the seed, but this is the recommended design when dealing with
probabilistic models in PyTorch as `),_=a(g,"CODE",{});var fe=i(_);$=l(fe,"Generator"),fe.forEach(t),w=l(g,"\u2019s are "),j=a(g,"EM",{});var ee=i(j);v=l(ee,"random states"),ee.forEach(t),y=l(g,` that can be
passed to multiple pipelines in a sequence.`),g.forEach(t)},m(I,g){p(I,d,g),s(d,b),s(d,m),s(m,h),s(d,E),s(d,_),s(_,$),s(d,w),s(d,j),s(j,v),s(d,y)},d(I){I&&t(d)}}}function vr(W){let d,b;return{c(){d=n("p"),b=o(`\u{1F4A1} If reproducibility is important, we recommend always passing a CPU generator.
The performance loss is often neglectable, and you\u2019ll generate much more similar
values than if the pipeline had been run on a GPU.`)},l(m){d=a(m,"P",{});var h=i(d);b=l(h,`\u{1F4A1} If reproducibility is important, we recommend always passing a CPU generator.
The performance loss is often neglectable, and you\u2019ll generate much more similar
values than if the pipeline had been run on a GPU.`),h.forEach(t)},m(m,h){p(m,d,h),s(d,b)},d(m){m&&t(d)}}}function gr(W){let d,b,m,h,E,_,$,w,j,v,y,I,g,A,fe,ee,me,Tt,Je,L,Ke,M,H,Ue,te,It,ke,qt,Qe,he,xt,Ve,B,At,ye,Mt,Nt,Xe,se,Ze,ve,Ot,et,z,St,re,Ce,Rt,Ft,tt,ge,Wt,st,N,Y,Ge,ne,Lt,Te,Ht,rt,J,Bt,ae,Ie,zt,Yt,nt,ie,at,q,Jt,qe,Kt,Qt,xe,Vt,Xt,it,_e,Zt,ot,K,lt,O,Q,Ae,oe,es,Me,ts,pt,be,ss,dt,le,ut,we,rs,ct,P,ns,$e,Ne,as,is,Oe,os,ls,Se,ps,ds,Re,us,cs,ft,Pe,fs,mt,pe,ht,V,yt,X,ms,Ee,hs,ys,vt,S,Z,Fe,de,vs,We,gs,gt,R,ue,_s,F,bs,Le,ws,$s,He,Ps,Es,_t;return _=new Ye({}),L=new js({props:{$$slots:{default:[hr]},$$scope:{ctx:W}}}),te=new Ye({}),se=new Gt({props:{code:`from diffusers import DDIMPipeline
import numpy as np
model_id = "google/ddpm-cifar10-32"
# load model and scheduler
ddim = DDIMPipeline.from_pretrained(model_id)
# run pipeline for just two steps and return numpy tensor
image = ddim(num_inference_steps=2, output_type="np").images
print(np.abs(image).sum())`,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
model_id = <span class="hljs-string">&quot;google/ddpm-cifar10-32&quot;</span>
<span class="hljs-comment"># load model and scheduler</span>
ddim = DDIMPipeline.from_pretrained(model_id)
<span class="hljs-comment"># run pipeline for just two steps and return numpy tensor</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>())`}}),ne=new Ye({}),ie=new Gt({props:{code:`import torch
from diffusers import DDIMPipeline
import numpy as np
model_id = "google/ddpm-cifar10-32"
# load model and scheduler
ddim = DDIMPipeline.from_pretrained(model_id)
# create a generator for reproducibility
generator = torch.Generator(device="cpu").manual_seed(0)
# run pipeline for just two steps and return numpy tensor
image = ddim(num_inference_steps=2, output_type="np", generator=generator).images
print(np.abs(image).sum())`,highlighted:`<span class="hljs-keyword">import</span> torch
<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
model_id = <span class="hljs-string">&quot;google/ddpm-cifar10-32&quot;</span>
<span class="hljs-comment"># load model and scheduler</span>
ddim = DDIMPipeline.from_pretrained(model_id)
<span class="hljs-comment"># create a generator for reproducibility</span>
generator = torch.Generator(device=<span class="hljs-string">&quot;cpu&quot;</span>).manual_seed(<span class="hljs-number">0</span>)
<span class="hljs-comment"># run pipeline for just two steps and return numpy tensor</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>())`}}),K=new js({props:{$$slots:{default:[yr]},$$scope:{ctx:W}}}),oe=new Ye({}),le=new Gt({props:{code:`import torch
from diffusers import DDIMPipeline
import numpy as np
model_id = "google/ddpm-cifar10-32"
# load model and scheduler
ddim = DDIMPipeline.from_pretrained(model_id)
ddim.to("cuda")
# create a generator for reproducibility
generator = torch.Generator(device="cuda").manual_seed(0)
# run pipeline for just two steps and return numpy tensor
image = ddim(num_inference_steps=2, output_type="np", generator=generator).images
print(np.abs(image).sum())`,highlighted:`<span class="hljs-keyword">import</span> torch
<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
model_id = <span class="hljs-string">&quot;google/ddpm-cifar10-32&quot;</span>
<span class="hljs-comment"># load model and scheduler</span>
ddim = DDIMPipeline.from_pretrained(model_id)
ddim.to(<span class="hljs-string">&quot;cuda&quot;</span>)
<span class="hljs-comment"># create a generator for reproducibility</span>
generator = torch.Generator(device=<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(<span class="hljs-number">0</span>)
<span class="hljs-comment"># run pipeline for just two steps and return numpy tensor</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>())`}}),pe=new Gt({props:{code:`import torch
from diffusers import DDIMPipeline
import numpy as np
model_id = "google/ddpm-cifar10-32"
# load model and scheduler
ddim = DDIMPipeline.from_pretrained(model_id)
ddim.to("cuda")
# create a generator for reproducibility; notice you don't place it on the GPU!
generator = torch.manual_seed(0)
# run pipeline for just two steps and return numpy tensor
image = ddim(num_inference_steps=2, output_type="np", generator=generator).images
print(np.abs(image).sum())`,highlighted:`<span class="hljs-keyword">import</span> torch
<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
model_id = <span class="hljs-string">&quot;google/ddpm-cifar10-32&quot;</span>
<span class="hljs-comment"># load model and scheduler</span>
ddim = DDIMPipeline.from_pretrained(model_id)
ddim.to(<span class="hljs-string">&quot;cuda&quot;</span>)
<span class="hljs-comment"># create a generator for reproducibility; notice you don&#x27;t place it on the GPU!</span>
generator = torch.manual_seed(<span class="hljs-number">0</span>)
<span class="hljs-comment"># run pipeline for just two steps and return numpy tensor</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>())`}}),V=new js({props:{$$slots:{default:[vr]},$$scope:{ctx:W}}}),de=new Ye({}),ue=new mr({props:{name:"diffusers.utils.randn_tensor",anchor:"diffusers.utils.randn_tensor",parameters:[{name:"shape",val:": typing.Union[typing.Tuple, typing.List]"},{name:"generator",val:": typing.Union[typing.List[ForwardRef('torch.Generator')], ForwardRef('torch.Generator'), NoneType] = None"},{name:"device",val:": typing.Optional[ForwardRef('torch.device')] = None"},{name:"dtype",val:": typing.Optional[ForwardRef('torch.dtype')] = None"},{name:"layout",val:": typing.Optional[ForwardRef('torch.layout')] = None"}],source:"https://github.com/huggingface/diffusers/blob/v0.15.0/src/diffusers/utils/torch_utils.py#L29"}}),{c(){d=n("meta"),b=u(),m=n("h1"),h=n("a"),E=n("span"),D(_.$$.fragment),$=u(),w=n("span"),j=o("Create reproducible pipelines"),v=u(),y=n("p"),I=o("Reproducibility is important for testing, replicating results, and can even be used to "),g=n("a"),A=o("improve image quality"),fe=o(". However, the randomness in diffusion models is a desired property because it allows the pipeline to generate different images every time it is run. While you can\u2019t expect to get the exact same results across platforms, you can expect results to be reproducible across releases and platforms within a certain tolerance range. Even then, tolerance varies depending on the diffusion pipeline and checkpoint."),ee=u(),me=n("p"),Tt=o("This is why it\u2019s important to understand how to control sources of randomness in diffusion models."),Je=u(),D(L.$$.fragment),Ke=u(),M=n("h2"),H=n("a"),Ue=n("span"),D(te.$$.fragment),It=u(),ke=n("span"),qt=o("Inference"),Qe=u(),he=n("p"),xt=o(`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.`),Ve=u(),B=n("p"),At=o("Take a look at the tensor values in the "),ye=n("a"),Mt=o("DDIMPipeline"),Nt=o(" after two inference steps:"),Xe=u(),D(se.$$.fragment),Ze=u(),ve=n("p"),Ot=o("Running the code above prints one value, but if you run it again you get a different value. What is going on here?"),et=u(),z=n("p"),St=o("Every time the pipeline is run, "),re=n("a"),Ce=n("code"),Rt=o("torch.randn"),Ft=o(" uses a different random seed to create Gaussian noise which is denoised stepwise. This leads to a different result each time it is run, which is great for diffusion pipelines since it generates a different random image each time."),tt=u(),ge=n("p"),Wt=o("But if you need to reliably generate the same image, that\u2019ll depend on whether you\u2019re running the pipeline on a CPU or GPU."),st=u(),N=n("h3"),Y=n("a"),Ge=n("span"),D(ne.$$.fragment),Lt=u(),Te=n("span"),Ht=o("CPU"),rt=u(),J=n("p"),Bt=o("To generate reproducible results on a CPU, you\u2019ll need to use a PyTorch "),ae=n("a"),Ie=n("code"),zt=o("Generator"),Yt=o(" and set a seed:"),nt=u(),D(ie.$$.fragment),at=u(),q=n("p"),Jt=o("Now when you run the code above, it always prints a value of "),qe=n("code"),Kt=o("1491.1711"),Qt=o(" no matter what because the "),xe=n("code"),Vt=o("Generator"),Xt=o(" object with the seed is passed to all the random functions of the pipeline."),it=u(),_e=n("p"),Zt=o("If you run this code example on your specific hardware and PyTorch version, you should get a similar, if not the same, result."),ot=u(),D(K.$$.fragment),lt=u(),O=n("h3"),Q=n("a"),Ae=n("span"),D(oe.$$.fragment),es=u(),Me=n("span"),ts=o("GPU"),pt=u(),be=n("p"),ss=o("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 above on a GPU:"),dt=u(),D(le.$$.fragment),ut=u(),we=n("p"),rs=o("The result is not the same even though you\u2019re using an identical seed because the GPU uses a different random number generator than the CPU."),ct=u(),P=n("p"),ns=o("To circumvent this problem, \u{1F9E8} Diffusers has a "),$e=n("a"),Ne=n("code"),as=o("randn_tensor"),is=o(" function for creating random noise on the CPU, and then moving the tensor to a GPU if necessary. The "),Oe=n("code"),os=o("randn_tensor"),ls=o(" function is used everywhere inside the pipeline, allowing the user to "),Se=n("strong"),ps=o("always"),ds=o(" pass a CPU "),Re=n("code"),us=o("Generator"),cs=o(" even if the pipeline is run on a GPU."),ft=u(),Pe=n("p"),fs=o("You\u2019ll see the results are much closer now!"),mt=u(),D(pe.$$.fragment),ht=u(),D(V.$$.fragment),yt=u(),X=n("p"),ms=o("Finally, for more complex pipelines such as "),Ee=n("a"),hs=o("UnCLIPPipeline"),ys=o(`, these are often extremely
susceptible to precision error propagation. Don\u2019t expect similar results across
different GPU hardware or PyTorch versions. In this case, you\u2019ll need to run
exactly the same hardware and PyTorch version for full reproducibility.`),vt=u(),S=n("h2"),Z=n("a"),Fe=n("span"),D(de.$$.fragment),vs=u(),We=n("span"),gs=o("randn_tensor"),gt=u(),R=n("div"),D(ue.$$.fragment),_s=u(),F=n("p"),bs=o("This is a helper function that allows to create random tensors on the desired "),Le=n("code"),ws=o("device"),$s=o(" with the desired "),He=n("code"),Ps=o("dtype"),Es=o(`. When
passing a list of generators one can seed each batched size individually. If CPU generators are passed the tensor
will always be created on CPU.`),this.h()},l(e){const r=cr('[data-svelte="svelte-1phssyn"]',document.head);d=a(r,"META",{name:!0,content:!0}),r.forEach(t),b=c(e),m=a(e,"H1",{class:!0});var ce=i(m);h=a(ce,"A",{id:!0,class:!0,href:!0});var Be=i(h);E=a(Be,"SPAN",{});var ze=i(E);U(_.$$.fragment,ze),ze.forEach(t),Be.forEach(t),$=c(ce),w=a(ce,"SPAN",{});var Ds=i(w);j=l(Ds,"Create reproducible pipelines"),Ds.forEach(t),ce.forEach(t),v=c(e),y=a(e,"P",{});var bt=i(y);I=l(bt,"Reproducibility is important for testing, replicating results, and can even be used to "),g=a(bt,"A",{href:!0});var Us=i(g);A=l(Us,"improve image quality"),Us.forEach(t),fe=l(bt,". However, the randomness in diffusion models is a desired property because it allows the pipeline to generate different images every time it is run. While you can\u2019t expect to get the exact same results across platforms, you can expect results to be reproducible across releases and platforms within a certain tolerance range. Even then, tolerance varies depending on the diffusion pipeline and checkpoint."),bt.forEach(t),ee=c(e),me=a(e,"P",{});var ks=i(me);Tt=l(ks,"This is why it\u2019s important to understand how to control sources of randomness in diffusion models."),ks.forEach(t),Je=c(e),U(L.$$.fragment,e),Ke=c(e),M=a(e,"H2",{class:!0});var wt=i(M);H=a(wt,"A",{id:!0,class:!0,href:!0});var Cs=i(H);Ue=a(Cs,"SPAN",{});var Gs=i(Ue);U(te.$$.fragment,Gs),Gs.forEach(t),Cs.forEach(t),It=c(wt),ke=a(wt,"SPAN",{});var Ts=i(ke);qt=l(Ts,"Inference"),Ts.forEach(t),wt.forEach(t),Qe=c(e),he=a(e,"P",{});var Is=i(he);xt=l(Is,`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.`),Is.forEach(t),Ve=c(e),B=a(e,"P",{});var $t=i(B);At=l($t,"Take a look at the tensor values in the "),ye=a($t,"A",{href:!0});var qs=i(ye);Mt=l(qs,"DDIMPipeline"),qs.forEach(t),Nt=l($t," after two inference steps:"),$t.forEach(t),Xe=c(e),U(se.$$.fragment,e),Ze=c(e),ve=a(e,"P",{});var xs=i(ve);Ot=l(xs,"Running the code above prints one value, but if you run it again you get a different value. What is going on here?"),xs.forEach(t),et=c(e),z=a(e,"P",{});var Pt=i(z);St=l(Pt,"Every time the pipeline is run, "),re=a(Pt,"A",{href:!0,rel:!0});var As=i(re);Ce=a(As,"CODE",{});var Ms=i(Ce);Rt=l(Ms,"torch.randn"),Ms.forEach(t),As.forEach(t),Ft=l(Pt," uses a different random seed to create Gaussian noise which is denoised stepwise. This leads to a different result each time it is run, which is great for diffusion pipelines since it generates a different random image each time."),Pt.forEach(t),tt=c(e),ge=a(e,"P",{});var Ns=i(ge);Wt=l(Ns,"But if you need to reliably generate the same image, that\u2019ll depend on whether you\u2019re running the pipeline on a CPU or GPU."),Ns.forEach(t),st=c(e),N=a(e,"H3",{class:!0});var Et=i(N);Y=a(Et,"A",{id:!0,class:!0,href:!0});var Os=i(Y);Ge=a(Os,"SPAN",{});var Ss=i(Ge);U(ne.$$.fragment,Ss),Ss.forEach(t),Os.forEach(t),Lt=c(Et),Te=a(Et,"SPAN",{});var Rs=i(Te);Ht=l(Rs,"CPU"),Rs.forEach(t),Et.forEach(t),rt=c(e),J=a(e,"P",{});var jt=i(J);Bt=l(jt,"To generate reproducible results on a CPU, you\u2019ll need to use a PyTorch "),ae=a(jt,"A",{href:!0,rel:!0});var Fs=i(ae);Ie=a(Fs,"CODE",{});var Ws=i(Ie);zt=l(Ws,"Generator"),Ws.forEach(t),Fs.forEach(t),Yt=l(jt," and set a seed:"),jt.forEach(t),nt=c(e),U(ie.$$.fragment,e),at=c(e),q=a(e,"P",{});var je=i(q);Jt=l(je,"Now when you run the code above, it always prints a value of "),qe=a(je,"CODE",{});var Ls=i(qe);Kt=l(Ls,"1491.1711"),Ls.forEach(t),Qt=l(je," no matter what because the "),xe=a(je,"CODE",{});var Hs=i(xe);Vt=l(Hs,"Generator"),Hs.forEach(t),Xt=l(je," object with the seed is passed to all the random functions of the pipeline."),je.forEach(t),it=c(e),_e=a(e,"P",{});var Bs=i(_e);Zt=l(Bs,"If you run this code example on your specific hardware and PyTorch version, you should get a similar, if not the same, result."),Bs.forEach(t),ot=c(e),U(K.$$.fragment,e),lt=c(e),O=a(e,"H3",{class:!0});var Dt=i(O);Q=a(Dt,"A",{id:!0,class:!0,href:!0});var zs=i(Q);Ae=a(zs,"SPAN",{});var Ys=i(Ae);U(oe.$$.fragment,Ys),Ys.forEach(t),zs.forEach(t),es=c(Dt),Me=a(Dt,"SPAN",{});var Js=i(Me);ts=l(Js,"GPU"),Js.forEach(t),Dt.forEach(t),pt=c(e),be=a(e,"P",{});var Ks=i(be);ss=l(Ks,"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 above on a GPU:"),Ks.forEach(t),dt=c(e),U(le.$$.fragment,e),ut=c(e),we=a(e,"P",{});var Qs=i(we);rs=l(Qs,"The result is not the same even though you\u2019re using an identical seed because the GPU uses a different random number generator than the CPU."),Qs.forEach(t),ct=c(e),P=a(e,"P",{});var x=i(P);ns=l(x,"To circumvent this problem, \u{1F9E8} Diffusers has a "),$e=a(x,"A",{href:!0});var Vs=i($e);Ne=a(Vs,"CODE",{});var Xs=i(Ne);as=l(Xs,"randn_tensor"),Xs.forEach(t),Vs.forEach(t),is=l(x," function for creating random noise on the CPU, and then moving the tensor to a GPU if necessary. The "),Oe=a(x,"CODE",{});var Zs=i(Oe);os=l(Zs,"randn_tensor"),Zs.forEach(t),ls=l(x," function is used everywhere inside the pipeline, allowing the user to "),Se=a(x,"STRONG",{});var er=i(Se);ps=l(er,"always"),er.forEach(t),ds=l(x," pass a CPU "),Re=a(x,"CODE",{});var tr=i(Re);us=l(tr,"Generator"),tr.forEach(t),cs=l(x," even if the pipeline is run on a GPU."),x.forEach(t),ft=c(e),Pe=a(e,"P",{});var sr=i(Pe);fs=l(sr,"You\u2019ll see the results are much closer now!"),sr.forEach(t),mt=c(e),U(pe.$$.fragment,e),ht=c(e),U(V.$$.fragment,e),yt=c(e),X=a(e,"P",{});var Ut=i(X);ms=l(Ut,"Finally, for more complex pipelines such as "),Ee=a(Ut,"A",{href:!0});var rr=i(Ee);hs=l(rr,"UnCLIPPipeline"),rr.forEach(t),ys=l(Ut,`, these are often extremely
susceptible to precision error propagation. Don\u2019t expect similar results across
different GPU hardware or PyTorch versions. In this case, you\u2019ll need to run
exactly the same hardware and PyTorch version for full reproducibility.`),Ut.forEach(t),vt=c(e),S=a(e,"H2",{class:!0});var kt=i(S);Z=a(kt,"A",{id:!0,class:!0,href:!0});var nr=i(Z);Fe=a(nr,"SPAN",{});var ar=i(Fe);U(de.$$.fragment,ar),ar.forEach(t),nr.forEach(t),vs=c(kt),We=a(kt,"SPAN",{});var ir=i(We);gs=l(ir,"randn_tensor"),ir.forEach(t),kt.forEach(t),gt=c(e),R=a(e,"DIV",{class:!0});var Ct=i(R);U(ue.$$.fragment,Ct),_s=c(Ct),F=a(Ct,"P",{});var De=i(F);bs=l(De,"This is a helper function that allows to create random tensors on the desired "),Le=a(De,"CODE",{});var or=i(Le);ws=l(or,"device"),or.forEach(t),$s=l(De," with the desired "),He=a(De,"CODE",{});var lr=i(He);Ps=l(lr,"dtype"),lr.forEach(t),Es=l(De,`. When
passing a list of generators one can seed each batched size individually. If CPU generators are passed the tensor
will always be created on CPU.`),De.forEach(t),Ct.forEach(t),this.h()},h(){f(d,"name","hf:doc:metadata"),f(d,"content",JSON.stringify(_r)),f(h,"id","create-reproducible-pipelines"),f(h,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(h,"href","#create-reproducible-pipelines"),f(m,"class","relative group"),f(g,"href","reusing_seeds"),f(H,"id","inference"),f(H,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(H,"href","#inference"),f(M,"class","relative group"),f(ye,"href","/docs/diffusers/v0.15.0/en/api/pipelines/ddim#diffusers.DDIMPipeline"),f(re,"href","https://pytorch.org/docs/stable/generated/torch.randn.html"),f(re,"rel","nofollow"),f(Y,"id","cpu"),f(Y,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Y,"href","#cpu"),f(N,"class","relative group"),f(ae,"href","https://pytorch.org/docs/stable/generated/torch.randn.html"),f(ae,"rel","nofollow"),f(Q,"id","gpu"),f(Q,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Q,"href","#gpu"),f(O,"class","relative group"),f($e,"href","#diffusers.utils.randn_tensor"),f(Ee,"href","/docs/diffusers/v0.15.0/en/api/pipelines/unclip#diffusers.UnCLIPPipeline"),f(Z,"id","diffusers.utils.randn_tensor"),f(Z,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Z,"href","#diffusers.utils.randn_tensor"),f(S,"class","relative group"),f(R,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,r){s(document.head,d),p(e,b,r),p(e,m,r),s(m,h),s(h,E),k(_,E,null),s(m,$),s(m,w),s(w,j),p(e,v,r),p(e,y,r),s(y,I),s(y,g),s(g,A),s(y,fe),p(e,ee,r),p(e,me,r),s(me,Tt),p(e,Je,r),k(L,e,r),p(e,Ke,r),p(e,M,r),s(M,H),s(H,Ue),k(te,Ue,null),s(M,It),s(M,ke),s(ke,qt),p(e,Qe,r),p(e,he,r),s(he,xt),p(e,Ve,r),p(e,B,r),s(B,At),s(B,ye),s(ye,Mt),s(B,Nt),p(e,Xe,r),k(se,e,r),p(e,Ze,r),p(e,ve,r),s(ve,Ot),p(e,et,r),p(e,z,r),s(z,St),s(z,re),s(re,Ce),s(Ce,Rt),s(z,Ft),p(e,tt,r),p(e,ge,r),s(ge,Wt),p(e,st,r),p(e,N,r),s(N,Y),s(Y,Ge),k(ne,Ge,null),s(N,Lt),s(N,Te),s(Te,Ht),p(e,rt,r),p(e,J,r),s(J,Bt),s(J,ae),s(ae,Ie),s(Ie,zt),s(J,Yt),p(e,nt,r),k(ie,e,r),p(e,at,r),p(e,q,r),s(q,Jt),s(q,qe),s(qe,Kt),s(q,Qt),s(q,xe),s(xe,Vt),s(q,Xt),p(e,it,r),p(e,_e,r),s(_e,Zt),p(e,ot,r),k(K,e,r),p(e,lt,r),p(e,O,r),s(O,Q),s(Q,Ae),k(oe,Ae,null),s(O,es),s(O,Me),s(Me,ts),p(e,pt,r),p(e,be,r),s(be,ss),p(e,dt,r),k(le,e,r),p(e,ut,r),p(e,we,r),s(we,rs),p(e,ct,r),p(e,P,r),s(P,ns),s(P,$e),s($e,Ne),s(Ne,as),s(P,is),s(P,Oe),s(Oe,os),s(P,ls),s(P,Se),s(Se,ps),s(P,ds),s(P,Re),s(Re,us),s(P,cs),p(e,ft,r),p(e,Pe,r),s(Pe,fs),p(e,mt,r),k(pe,e,r),p(e,ht,r),k(V,e,r),p(e,yt,r),p(e,X,r),s(X,ms),s(X,Ee),s(Ee,hs),s(X,ys),p(e,vt,r),p(e,S,r),s(S,Z),s(Z,Fe),k(de,Fe,null),s(S,vs),s(S,We),s(We,gs),p(e,gt,r),p(e,R,r),k(ue,R,null),s(R,_s),s(R,F),s(F,bs),s(F,Le),s(Le,ws),s(F,$s),s(F,He),s(He,Ps),s(F,Es),_t=!0},p(e,[r]){const ce={};r&2&&(ce.$$scope={dirty:r,ctx:e}),L.$set(ce);const Be={};r&2&&(Be.$$scope={dirty:r,ctx:e}),K.$set(Be);const ze={};r&2&&(ze.$$scope={dirty:r,ctx:e}),V.$set(ze)},i(e){_t||(C(_.$$.fragment,e),C(L.$$.fragment,e),C(te.$$.fragment,e),C(se.$$.fragment,e),C(ne.$$.fragment,e),C(ie.$$.fragment,e),C(K.$$.fragment,e),C(oe.$$.fragment,e),C(le.$$.fragment,e),C(pe.$$.fragment,e),C(V.$$.fragment,e),C(de.$$.fragment,e),C(ue.$$.fragment,e),_t=!0)},o(e){G(_.$$.fragment,e),G(L.$$.fragment,e),G(te.$$.fragment,e),G(se.$$.fragment,e),G(ne.$$.fragment,e),G(ie.$$.fragment,e),G(K.$$.fragment,e),G(oe.$$.fragment,e),G(le.$$.fragment,e),G(pe.$$.fragment,e),G(V.$$.fragment,e),G(de.$$.fragment,e),G(ue.$$.fragment,e),_t=!1},d(e){t(d),e&&t(b),e&&t(m),T(_),e&&t(v),e&&t(y),e&&t(ee),e&&t(me),e&&t(Je),T(L,e),e&&t(Ke),e&&t(M),T(te),e&&t(Qe),e&&t(he),e&&t(Ve),e&&t(B),e&&t(Xe),T(se,e),e&&t(Ze),e&&t(ve),e&&t(et),e&&t(z),e&&t(tt),e&&t(ge),e&&t(st),e&&t(N),T(ne),e&&t(rt),e&&t(J),e&&t(nt),T(ie,e),e&&t(at),e&&t(q),e&&t(it),e&&t(_e),e&&t(ot),T(K,e),e&&t(lt),e&&t(O),T(oe),e&&t(pt),e&&t(be),e&&t(dt),T(le,e),e&&t(ut),e&&t(we),e&&t(ct),e&&t(P),e&&t(ft),e&&t(Pe),e&&t(mt),T(pe,e),e&&t(ht),T(V,e),e&&t(yt),e&&t(X),e&&t(vt),e&&t(S),T(de),e&&t(gt),e&&t(R),T(ue)}}}const _r={local:"create-reproducible-pipelines",sections:[{local:"inference",sections:[{local:"cpu",title:"CPU"},{local:"gpu",title:"GPU"}],title:"Inference"},{local:"diffusers.utils.randn_tensor",title:"randn_tensor"}],title:"Create reproducible pipelines"};function br(W){return fr(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Dr extends pr{constructor(d){super();dr(this,d,br,gr,ur,{})}}export{Dr as default,_r as metadata};

Xet Storage Details

Size:
27.2 kB
·
Xet hash:
3161fb78954f2f1fc068ca04836a3d35b85890c05dd944bfa4eddc8cce6ba9f1

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.