Buckets:
| import{s as Lt,o as Dt,n as ft}from"../chunks/scheduler.182ea377.js";import{S as At,i as Kt,g as n,s as i,p as y,A as Ot,h as a,f as t,c as o,j as f,q as b,m as p,k as u,v as d,a as l,r as M,d as w,t as g,u as j}from"../chunks/index.008d68e4.js";import{T as yt}from"../chunks/Tip.4f096367.js";import{I as Ze}from"../chunks/IconCopyLink.96bbb92b.js";import{C as we}from"../chunks/CodeBlock.5ed6eb7b.js";import{D as es}from"../chunks/DocNotebookDropdown.bb388256.js";function ts(W){let r,J='💡 We strongly recommend reading PyTorch’s <a href="https://pytorch.org/docs/stable/notes/randomness.html" rel="nofollow">statement about reproducibility</a>:',c,m,B="<p>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.</p>";return{c(){r=n("p"),r.innerHTML=J,c=i(),m=n("blockquote"),m.innerHTML=B},l(h){r=a(h,"P",{"data-svelte-h":!0}),p(r)!=="svelte-mk56g"&&(r.innerHTML=J),c=o(h),m=a(h,"BLOCKQUOTE",{"data-svelte-h":!0}),p(m)!=="svelte-16ppwuq"&&(m.innerHTML=B)},m(h,x){l(h,r,x),l(h,c,x),l(h,m,x)},p:ft,d(h){h&&(t(r),t(c),t(m))}}}function ss(W){let r,J=`💡 It might be a bit unintuitive at first to pass <code>Generator</code> 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 <code>Generator</code>s are <em>random states</em> that can be | |
| passed to multiple pipelines in a sequence.`;return{c(){r=n("p"),r.innerHTML=J},l(c){r=a(c,"P",{"data-svelte-h":!0}),p(r)!=="svelte-1whzuej"&&(r.innerHTML=J)},m(c,m){l(c,r,m)},p:ft,d(c){c&&t(r)}}}function ls(W){let r,J=`💡 If reproducibility is important, we recommend always passing a CPU generator. | |
| The performance loss is often neglectable, and you’ll generate much more similar | |
| values than if the pipeline had been run on a GPU.`;return{c(){r=n("p"),r.textContent=J},l(c){r=a(c,"P",{"data-svelte-h":!0}),p(r)!=="svelte-6qqsvj"&&(r.textContent=J)},m(c,m){l(c,r,m)},p:ft,d(c){c&&t(r)}}}function ns(W){let r,J,c,m,B,h,x,he,bt="Create reproducible pipelines",We,R,Be,E,Mt='Reproducibility is important for testing, replicating results, and can even be used to <a href="reusing_seeds">improve image quality</a>. 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’t 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.',_e,H,wt="This is why it’s important to understand how to control sources of randomness in diffusion models or use deterministic algorithms.",Ce,_,$e,T,C,ge,X,ut,ye,gt="Control randomness",ke,P,jt=`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.`,Ie,S,Jt='Take a look at the tensor values in the <a href="/docs/diffusers/v0.25.0/zh/api/pipelines/ddim#diffusers.DDIMPipeline">DDIMPipeline</a> after two inference steps:',Ge,z,Ve,N,Tt="Running the code above prints one value, but if you run it again you get a different value. What is going on here?",xe,Q,vt='Every time the pipeline is run, <a href="https://pytorch.org/docs/stable/generated/torch.randn.html" rel="nofollow"><code>torch.randn</code></a> 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.',Re,F,Ut="But if you need to reliably generate the same image, that’ll depend on whether you’re running the pipeline on a CPU or GPU.",Ee,v,$,je,q,dt,fe,Zt="CPU",He,Y,Wt='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"><code>Generator</code></a> and set a seed:',Xe,L,Pe,D,Bt="Now when you run the code above, it always prints a value of <code>1491.1711</code> no matter what because the <code>Generator</code> object with the seed is passed to all the random functions of the pipeline.",Se,A,_t="If you run this code example on your specific hardware and PyTorch version, you should get a similar, if not the same, result.",ze,k,Ne,U,I,Je,K,mt,be,Ct="GPU",Qe,O,$t="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:",Fe,ee,qe,te,kt="The result is not the same even though you’re using an identical seed because the GPU uses a different random number generator than the CPU.",Ye,se,It="To circumvent this problem, 🧨 Diffusers has a <code>randn_tensor()</code> function for creating random noise on the CPU, and then moving the tensor to a GPU if necessary. The <code>randn_tensor</code> function is used everywhere inside the pipeline, allowing the user to <strong>always</strong> pass a CPU <code>Generator</code> even if the pipeline is run on a GPU.",Le,le,Gt="You’ll see the results are much closer now!",De,ne,Ae,G,Ke,ae,Vt=`Finally, for more complex pipelines such as <a href="/docs/diffusers/v0.25.0/zh/api/pipelines/unclip#diffusers.UnCLIPPipeline">UnCLIPPipeline</a>, these are often extremely | |
| susceptible to precision error propagation. Don’t expect similar results across | |
| different GPU hardware or PyTorch versions. In this case, you’ll need to run | |
| exactly the same hardware and PyTorch version for full reproducibility.`,Oe,Z,V,Te,ie,ht,Me,xt="Deterministic algorithms",et,oe,Rt="You can also configure PyTorch to use deterministic algorithms to create a reproducible pipeline. However, you should be aware that deterministic algorithms may be slower than nondeterministic ones and you may observe a decrease in performance. But if reproducibility is important to you, then this is the way to go!",tt,re,Et='Nondeterministic 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"><code>CUBLAS_WORKSPACE_CONFIG</code></a> to <code>:16:8</code> to only use one buffer size during runtime.',st,pe,Ht='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. Lastly, pass <code>True</code> to <a href="https://pytorch.org/docs/stable/generated/torch.use_deterministic_algorithms.html" rel="nofollow"><code>torch.use_deterministic_algorithms</code></a> to enable deterministic algorithms.',lt,ce,nt,ue,Xt="Now when you run the same pipeline twice, you’ll get identical results.",at,de,it;return h=new Ze({}),R=new es({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/zh/reproducibility.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/zh/pytorch/reproducibility.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/zh/tensorflow/reproducibility.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/zh/reproducibility.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/zh/pytorch/reproducibility.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/zh/tensorflow/reproducibility.ipynb"}]}}),_=new yt({props:{$$slots:{default:[ts]},$$scope:{ctx:W}}}),X=new Ze({}),z=new we({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERESU1QaXBlbGluZSUwQWltcG9ydCUyMG51bXB5JTIwYXMlMjBucCUwQSUwQW1vZGVsX2lkJTIwJTNEJTIwJTIyZ29vZ2xlJTJGZGRwbS1jaWZhcjEwLTMyJTIyJTBBJTBBJTIzJTIwbG9hZCUyMG1vZGVsJTIwYW5kJTIwc2NoZWR1bGVyJTBBZGRpbSUyMCUzRCUyMERESU1QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQlMkMlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlKSUwQSUwQSUyMyUyMHJ1biUyMHBpcGVsaW5lJTIwZm9yJTIwanVzdCUyMHR3byUyMHN0ZXBzJTIwYW5kJTIwcmV0dXJuJTIwbnVtcHklMjB0ZW5zb3IlMEFpbWFnZSUyMCUzRCUyMGRkaW0obnVtX2luZmVyZW5jZV9zdGVwcyUzRDIlMkMlMjBvdXRwdXRfdHlwZSUzRCUyMm5wJTIyKS5pbWFnZXMlMEFwcmludChucC5hYnMoaW1hZ2UpLnN1bSgpKQ==",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">"google/ddpm-cifar10-32"</span> | |
| <span class="hljs-comment"># load model and scheduler</span> | |
| ddim = DDIMPipeline.from_pretrained(model_id, use_safetensors=<span class="hljs-literal">True</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">"np"</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>())`}}),q=new Ze({}),L=new we({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVBpcGVsaW5lJTBBaW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJnb29nbGUlMkZkZHBtLWNpZmFyMTAtMzIlMjIlMEElMEElMjMlMjBsb2FkJTIwbW9kZWwlMjBhbmQlMjBzY2hlZHVsZXIlMEFkZGltJTIwJTNEJTIwRERJTVBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUpJTBBJTBBJTIzJTIwY3JlYXRlJTIwYSUyMGdlbmVyYXRvciUyMGZvciUyMHJlcHJvZHVjaWJpbGl0eSUwQWdlbmVyYXRvciUyMCUzRCUyMHRvcmNoLkdlbmVyYXRvcihkZXZpY2UlM0QlMjJjcHUlMjIpLm1hbnVhbF9zZWVkKDApJTBBJTBBJTIzJTIwcnVuJTIwcGlwZWxpbmUlMjBmb3IlMjBqdXN0JTIwdHdvJTIwc3RlcHMlMjBhbmQlMjByZXR1cm4lMjBudW1weSUyMHRlbnNvciUwQWltYWdlJTIwJTNEJTIwZGRpbShudW1faW5mZXJlbmNlX3N0ZXBzJTNEMiUyQyUyMG91dHB1dF90eXBlJTNEJTIybnAlMjIlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IpLmltYWdlcyUwQXByaW50KG5wLmFicyhpbWFnZSkuc3VtKCkp",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">"google/ddpm-cifar10-32"</span> | |
| <span class="hljs-comment"># load model and scheduler</span> | |
| ddim = DDIMPipeline.from_pretrained(model_id, use_safetensors=<span class="hljs-literal">True</span>) | |
| <span class="hljs-comment"># create a generator for reproducibility</span> | |
| generator = torch.Generator(device=<span class="hljs-string">"cpu"</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">"np"</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 yt({props:{$$slots:{default:[ss]},$$scope:{ctx:W}}}),K=new Ze({}),ee=new we({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVBpcGVsaW5lJTBBaW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJnb29nbGUlMkZkZHBtLWNpZmFyMTAtMzIlMjIlMEElMEElMjMlMjBsb2FkJTIwbW9kZWwlMjBhbmQlMjBzY2hlZHVsZXIlMEFkZGltJTIwJTNEJTIwRERJTVBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUpJTBBZGRpbS50byglMjJjdWRhJTIyKSUwQSUwQSUyMyUyMGNyZWF0ZSUyMGElMjBnZW5lcmF0b3IlMjBmb3IlMjByZXByb2R1Y2liaWxpdHklMEFnZW5lcmF0b3IlMjAlM0QlMjB0b3JjaC5HZW5lcmF0b3IoZGV2aWNlJTNEJTIyY3VkYSUyMikubWFudWFsX3NlZWQoMCklMEElMEElMjMlMjBydW4lMjBwaXBlbGluZSUyMGZvciUyMGp1c3QlMjB0d28lMjBzdGVwcyUyMGFuZCUyMHJldHVybiUyMG51bXB5JTIwdGVuc29yJTBBaW1hZ2UlMjAlM0QlMjBkZGltKG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyJTJDJTIwb3V0cHV0X3R5cGUlM0QlMjJucCUyMiUyQyUyMGdlbmVyYXRvciUzRGdlbmVyYXRvcikuaW1hZ2VzJTBBcHJpbnQobnAuYWJzKGltYWdlKS5zdW0oKSk=",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">"google/ddpm-cifar10-32"</span> | |
| <span class="hljs-comment"># load model and scheduler</span> | |
| ddim = DDIMPipeline.from_pretrained(model_id, use_safetensors=<span class="hljs-literal">True</span>) | |
| ddim.to(<span class="hljs-string">"cuda"</span>) | |
| <span class="hljs-comment"># create a generator for reproducibility</span> | |
| generator = torch.Generator(device=<span class="hljs-string">"cuda"</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">"np"</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>())`}}),ne=new we({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVBpcGVsaW5lJTBBaW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJnb29nbGUlMkZkZHBtLWNpZmFyMTAtMzIlMjIlMEElMEElMjMlMjBsb2FkJTIwbW9kZWwlMjBhbmQlMjBzY2hlZHVsZXIlMEFkZGltJTIwJTNEJTIwRERJTVBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUpJTBBZGRpbS50byglMjJjdWRhJTIyKSUwQSUwQSUyMyUyMGNyZWF0ZSUyMGElMjBnZW5lcmF0b3IlMjBmb3IlMjByZXByb2R1Y2liaWxpdHklM0IlMjBub3RpY2UlMjB5b3UlMjBkb24ndCUyMHBsYWNlJTIwaXQlMjBvbiUyMHRoZSUyMEdQVSElMEFnZW5lcmF0b3IlMjAlM0QlMjB0b3JjaC5tYW51YWxfc2VlZCgwKSUwQSUwQSUyMyUyMHJ1biUyMHBpcGVsaW5lJTIwZm9yJTIwanVzdCUyMHR3byUyMHN0ZXBzJTIwYW5kJTIwcmV0dXJuJTIwbnVtcHklMjB0ZW5zb3IlMEFpbWFnZSUyMCUzRCUyMGRkaW0obnVtX2luZmVyZW5jZV9zdGVwcyUzRDIlMkMlMjBvdXRwdXRfdHlwZSUzRCUyMm5wJTIyJTJDJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yKS5pbWFnZXMlMEFwcmludChucC5hYnMoaW1hZ2UpLnN1bSgpKQ==",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">"google/ddpm-cifar10-32"</span> | |
| <span class="hljs-comment"># load model and scheduler</span> | |
| ddim = DDIMPipeline.from_pretrained(model_id, use_safetensors=<span class="hljs-literal">True</span>) | |
| ddim.to(<span class="hljs-string">"cuda"</span>) | |
| <span class="hljs-comment"># create a generator for reproducibility; notice you don'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">"np"</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>())`}}),G=new yt({props:{$$slots:{default:[ls]},$$scope:{ctx:W}}}),ie=new Ze({}),ce=new we({props:{code:"aW1wb3J0JTIwb3MlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQW9zLmVudmlyb24lNUIlMjJDVUJMQVNfV09SS1NQQUNFX0NPTkZJRyUyMiU1RCUyMCUzRCUyMCUyMiUzQTE2JTNBOCUyMiUwQSUwQXRvcmNoLmJhY2tlbmRzLmN1ZG5uLmJlbmNobWFyayUyMCUzRCUyMEZhbHNlJTBBdG9yY2gudXNlX2RldGVybWluaXN0aWNfYWxnb3JpdGhtcyhUcnVlKQ==",highlighted:`<span class="hljs-keyword">import</span> os | |
| <span class="hljs-keyword">import</span> torch | |
| os.environ[<span class="hljs-string">"CUBLAS_WORKSPACE_CONFIG"</span>] = <span class="hljs-string">":16:8"</span> | |
| torch.backends.cudnn.benchmark = <span class="hljs-literal">False</span> | |
| torch.use_deterministic_algorithms(<span class="hljs-literal">True</span>)`}}),de=new we({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVNjaGVkdWxlciUyQyUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUwQXBpcGUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQlMkMlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlKS50byglMjJjdWRhJTIyKSUwQXBpcGUuc2NoZWR1bGVyJTIwJTNEJTIwRERJTVNjaGVkdWxlci5mcm9tX2NvbmZpZyhwaXBlLnNjaGVkdWxlci5jb25maWcpJTBBZyUyMCUzRCUyMHRvcmNoLkdlbmVyYXRvcihkZXZpY2UlM0QlMjJjdWRhJTIyKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkElMjBiZWFyJTIwaXMlMjBwbGF5aW5nJTIwYSUyMGd1aXRhciUyMG9uJTIwVGltZXMlMjBTcXVhcmUlMjIlMEElMEFnLm1hbnVhbF9zZWVkKDApJTBBcmVzdWx0MSUyMCUzRCUyMHBpcGUocHJvbXB0JTNEcHJvbXB0JTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDUwJTJDJTIwZ2VuZXJhdG9yJTNEZyUyQyUyMG91dHB1dF90eXBlJTNEJTIybGF0ZW50JTIyKS5pbWFnZXMlMEElMEFnLm1hbnVhbF9zZWVkKDApJTBBcmVzdWx0MiUyMCUzRCUyMHBpcGUocHJvbXB0JTNEcHJvbXB0JTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDUwJTJDJTIwZ2VuZXJhdG9yJTNEZyUyQyUyMG91dHB1dF90eXBlJTNEJTIybGF0ZW50JTIyKS5pbWFnZXMlMEElMEFwcmludCglMjJMX2luZiUyMGRpc3QlMjAlM0QlMjIlMkMlMjBhYnMocmVzdWx0MSUyMC0lMjByZXN1bHQyKS5tYXgoKSklMEElMjJMX2luZiUyMGRpc3QlMjAlM0QlMjB0ZW5zb3IoMC4lMkMlMjBkZXZpY2UlM0QnY3VkYSUzQTAnKSUyMg==",highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, StableDiffusionPipeline | |
| model_id = <span class="hljs-string">"runwayml/stable-diffusion-v1-5"</span> | |
| pipe = StableDiffusionPipeline.from_pretrained(model_id, use_safetensors=<span class="hljs-literal">True</span>).to(<span class="hljs-string">"cuda"</span>) | |
| pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config) | |
| g = torch.Generator(device=<span class="hljs-string">"cuda"</span>) | |
| prompt = <span class="hljs-string">"A bear is playing a guitar on Times Square"</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">"latent"</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">"latent"</span>).images | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">"L_inf dist ="</span>, <span class="hljs-built_in">abs</span>(result1 - result2).<span class="hljs-built_in">max</span>()) | |
| <span class="hljs-string">"L_inf dist = tensor(0., device='cuda:0')"</span>`}}),{c(){r=n("meta"),J=i(),c=n("h1"),m=n("a"),B=n("span"),y(h.$$.fragment),x=i(),he=n("span"),he.textContent=bt,We=i(),y(R.$$.fragment),Be=i(),E=n("p"),E.innerHTML=Mt,_e=i(),H=n("p"),H.textContent=wt,Ce=i(),y(_.$$.fragment),$e=i(),T=n("h2"),C=n("a"),ge=n("span"),y(X.$$.fragment),ut=i(),ye=n("span"),ye.textContent=gt,ke=i(),P=n("p"),P.textContent=jt,Ie=i(),S=n("p"),S.innerHTML=Jt,Ge=i(),y(z.$$.fragment),Ve=i(),N=n("p"),N.textContent=Tt,xe=i(),Q=n("p"),Q.innerHTML=vt,Re=i(),F=n("p"),F.textContent=Ut,Ee=i(),v=n("h3"),$=n("a"),je=n("span"),y(q.$$.fragment),dt=i(),fe=n("span"),fe.textContent=Zt,He=i(),Y=n("p"),Y.innerHTML=Wt,Xe=i(),y(L.$$.fragment),Pe=i(),D=n("p"),D.innerHTML=Bt,Se=i(),A=n("p"),A.textContent=_t,ze=i(),y(k.$$.fragment),Ne=i(),U=n("h3"),I=n("a"),Je=n("span"),y(K.$$.fragment),mt=i(),be=n("span"),be.textContent=Ct,Qe=i(),O=n("p"),O.textContent=$t,Fe=i(),y(ee.$$.fragment),qe=i(),te=n("p"),te.textContent=kt,Ye=i(),se=n("p"),se.innerHTML=It,Le=i(),le=n("p"),le.textContent=Gt,De=i(),y(ne.$$.fragment),Ae=i(),y(G.$$.fragment),Ke=i(),ae=n("p"),ae.innerHTML=Vt,Oe=i(),Z=n("h2"),V=n("a"),Te=n("span"),y(ie.$$.fragment),ht=i(),Me=n("span"),Me.textContent=xt,et=i(),oe=n("p"),oe.textContent=Rt,tt=i(),re=n("p"),re.innerHTML=Et,st=i(),pe=n("p"),pe.innerHTML=Ht,lt=i(),y(ce.$$.fragment),nt=i(),ue=n("p"),ue.textContent=Xt,at=i(),y(de.$$.fragment),this.h()},l(e){const s=Ot("svelte-1phssyn",document.head);r=a(s,"META",{name:!0,content:!0}),s.forEach(t),J=o(e),c=a(e,"H1",{class:!0});var me=f(c);m=a(me,"A",{id:!0,class:!0,href:!0});var ve=f(m);B=a(ve,"SPAN",{});var Ue=f(B);b(h.$$.fragment,Ue),Ue.forEach(t),ve.forEach(t),x=o(me),he=a(me,"SPAN",{"data-svelte-h":!0}),p(he)!=="svelte-1nua4d8"&&(he.textContent=bt),me.forEach(t),We=o(e),b(R.$$.fragment,e),Be=o(e),E=a(e,"P",{"data-svelte-h":!0}),p(E)!=="svelte-1sdj1n4"&&(E.innerHTML=Mt),_e=o(e),H=a(e,"P",{"data-svelte-h":!0}),p(H)!=="svelte-spyond"&&(H.textContent=wt),Ce=o(e),b(_.$$.fragment,e),$e=o(e),T=a(e,"H2",{class:!0});var ot=f(T);C=a(ot,"A",{id:!0,class:!0,href:!0});var Pt=f(C);ge=a(Pt,"SPAN",{});var St=f(ge);b(X.$$.fragment,St),St.forEach(t),Pt.forEach(t),ut=o(ot),ye=a(ot,"SPAN",{"data-svelte-h":!0}),p(ye)!=="svelte-10ngjj0"&&(ye.textContent=gt),ot.forEach(t),ke=o(e),P=a(e,"P",{"data-svelte-h":!0}),p(P)!=="svelte-1tn5oba"&&(P.textContent=jt),Ie=o(e),S=a(e,"P",{"data-svelte-h":!0}),p(S)!=="svelte-q3djmk"&&(S.innerHTML=Jt),Ge=o(e),b(z.$$.fragment,e),Ve=o(e),N=a(e,"P",{"data-svelte-h":!0}),p(N)!=="svelte-6e7pfa"&&(N.textContent=Tt),xe=o(e),Q=a(e,"P",{"data-svelte-h":!0}),p(Q)!=="svelte-mhfmil"&&(Q.innerHTML=vt),Re=o(e),F=a(e,"P",{"data-svelte-h":!0}),p(F)!=="svelte-opovkl"&&(F.textContent=Ut),Ee=o(e),v=a(e,"H3",{class:!0});var rt=f(v);$=a(rt,"A",{id:!0,class:!0,href:!0});var zt=f($);je=a(zt,"SPAN",{});var Nt=f(je);b(q.$$.fragment,Nt),Nt.forEach(t),zt.forEach(t),dt=o(rt),fe=a(rt,"SPAN",{"data-svelte-h":!0}),p(fe)!=="svelte-1xflp2p"&&(fe.textContent=Zt),rt.forEach(t),He=o(e),Y=a(e,"P",{"data-svelte-h":!0}),p(Y)!=="svelte-1kryd8j"&&(Y.innerHTML=Wt),Xe=o(e),b(L.$$.fragment,e),Pe=o(e),D=a(e,"P",{"data-svelte-h":!0}),p(D)!=="svelte-jf8pj"&&(D.innerHTML=Bt),Se=o(e),A=a(e,"P",{"data-svelte-h":!0}),p(A)!=="svelte-1mz2u42"&&(A.textContent=_t),ze=o(e),b(k.$$.fragment,e),Ne=o(e),U=a(e,"H3",{class:!0});var pt=f(U);I=a(pt,"A",{id:!0,class:!0,href:!0});var Qt=f(I);Je=a(Qt,"SPAN",{});var Ft=f(Je);b(K.$$.fragment,Ft),Ft.forEach(t),Qt.forEach(t),mt=o(pt),be=a(pt,"SPAN",{"data-svelte-h":!0}),p(be)!=="svelte-1giv785"&&(be.textContent=Ct),pt.forEach(t),Qe=o(e),O=a(e,"P",{"data-svelte-h":!0}),p(O)!=="svelte-vhxkpf"&&(O.textContent=$t),Fe=o(e),b(ee.$$.fragment,e),qe=o(e),te=a(e,"P",{"data-svelte-h":!0}),p(te)!=="svelte-1tpavxr"&&(te.textContent=kt),Ye=o(e),se=a(e,"P",{"data-svelte-h":!0}),p(se)!=="svelte-oj1ygm"&&(se.innerHTML=It),Le=o(e),le=a(e,"P",{"data-svelte-h":!0}),p(le)!=="svelte-v5oouu"&&(le.textContent=Gt),De=o(e),b(ne.$$.fragment,e),Ae=o(e),b(G.$$.fragment,e),Ke=o(e),ae=a(e,"P",{"data-svelte-h":!0}),p(ae)!=="svelte-ll9qmb"&&(ae.innerHTML=Vt),Oe=o(e),Z=a(e,"H2",{class:!0});var ct=f(Z);V=a(ct,"A",{id:!0,class:!0,href:!0});var qt=f(V);Te=a(qt,"SPAN",{});var Yt=f(Te);b(ie.$$.fragment,Yt),Yt.forEach(t),qt.forEach(t),ht=o(ct),Me=a(ct,"SPAN",{"data-svelte-h":!0}),p(Me)!=="svelte-1jk9829"&&(Me.textContent=xt),ct.forEach(t),et=o(e),oe=a(e,"P",{"data-svelte-h":!0}),p(oe)!=="svelte-j2780s"&&(oe.textContent=Rt),tt=o(e),re=a(e,"P",{"data-svelte-h":!0}),p(re)!=="svelte-10j1qq1"&&(re.innerHTML=Et),st=o(e),pe=a(e,"P",{"data-svelte-h":!0}),p(pe)!=="svelte-1ncc9dd"&&(pe.innerHTML=Ht),lt=o(e),b(ce.$$.fragment,e),nt=o(e),ue=a(e,"P",{"data-svelte-h":!0}),p(ue)!=="svelte-b9yuf0"&&(ue.textContent=Xt),at=o(e),b(de.$$.fragment,e),this.h()},h(){u(r,"name","hf:doc:metadata"),u(r,"content",JSON.stringify(as)),u(m,"id","create-reproducible-pipelines"),u(m,"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"),u(m,"href","#create-reproducible-pipelines"),u(c,"class","relative group"),u(C,"id","control-randomness"),u(C,"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"),u(C,"href","#control-randomness"),u(T,"class","relative group"),u($,"id","cpu"),u($,"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"),u($,"href","#cpu"),u(v,"class","relative group"),u(I,"id","gpu"),u(I,"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"),u(I,"href","#gpu"),u(U,"class","relative group"),u(V,"id","deterministic-algorithms"),u(V,"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"),u(V,"href","#deterministic-algorithms"),u(Z,"class","relative group")},m(e,s){d(document.head,r),l(e,J,s),l(e,c,s),d(c,m),d(m,B),M(h,B,null),d(c,x),d(c,he),l(e,We,s),M(R,e,s),l(e,Be,s),l(e,E,s),l(e,_e,s),l(e,H,s),l(e,Ce,s),M(_,e,s),l(e,$e,s),l(e,T,s),d(T,C),d(C,ge),M(X,ge,null),d(T,ut),d(T,ye),l(e,ke,s),l(e,P,s),l(e,Ie,s),l(e,S,s),l(e,Ge,s),M(z,e,s),l(e,Ve,s),l(e,N,s),l(e,xe,s),l(e,Q,s),l(e,Re,s),l(e,F,s),l(e,Ee,s),l(e,v,s),d(v,$),d($,je),M(q,je,null),d(v,dt),d(v,fe),l(e,He,s),l(e,Y,s),l(e,Xe,s),M(L,e,s),l(e,Pe,s),l(e,D,s),l(e,Se,s),l(e,A,s),l(e,ze,s),M(k,e,s),l(e,Ne,s),l(e,U,s),d(U,I),d(I,Je),M(K,Je,null),d(U,mt),d(U,be),l(e,Qe,s),l(e,O,s),l(e,Fe,s),M(ee,e,s),l(e,qe,s),l(e,te,s),l(e,Ye,s),l(e,se,s),l(e,Le,s),l(e,le,s),l(e,De,s),M(ne,e,s),l(e,Ae,s),M(G,e,s),l(e,Ke,s),l(e,ae,s),l(e,Oe,s),l(e,Z,s),d(Z,V),d(V,Te),M(ie,Te,null),d(Z,ht),d(Z,Me),l(e,et,s),l(e,oe,s),l(e,tt,s),l(e,re,s),l(e,st,s),l(e,pe,s),l(e,lt,s),M(ce,e,s),l(e,nt,s),l(e,ue,s),l(e,at,s),M(de,e,s),it=!0},p(e,[s]){const me={};s&2&&(me.$$scope={dirty:s,ctx:e}),_.$set(me);const ve={};s&2&&(ve.$$scope={dirty:s,ctx:e}),k.$set(ve);const Ue={};s&2&&(Ue.$$scope={dirty:s,ctx:e}),G.$set(Ue)},i(e){it||(w(h.$$.fragment,e),w(R.$$.fragment,e),w(_.$$.fragment,e),w(X.$$.fragment,e),w(z.$$.fragment,e),w(q.$$.fragment,e),w(L.$$.fragment,e),w(k.$$.fragment,e),w(K.$$.fragment,e),w(ee.$$.fragment,e),w(ne.$$.fragment,e),w(G.$$.fragment,e),w(ie.$$.fragment,e),w(ce.$$.fragment,e),w(de.$$.fragment,e),it=!0)},o(e){g(h.$$.fragment,e),g(R.$$.fragment,e),g(_.$$.fragment,e),g(X.$$.fragment,e),g(z.$$.fragment,e),g(q.$$.fragment,e),g(L.$$.fragment,e),g(k.$$.fragment,e),g(K.$$.fragment,e),g(ee.$$.fragment,e),g(ne.$$.fragment,e),g(G.$$.fragment,e),g(ie.$$.fragment,e),g(ce.$$.fragment,e),g(de.$$.fragment,e),it=!1},d(e){e&&(t(J),t(c),t(We),t(Be),t(E),t(_e),t(H),t(Ce),t($e),t(T),t(ke),t(P),t(Ie),t(S),t(Ge),t(Ve),t(N),t(xe),t(Q),t(Re),t(F),t(Ee),t(v),t(He),t(Y),t(Xe),t(Pe),t(D),t(Se),t(A),t(ze),t(Ne),t(U),t(Qe),t(O),t(Fe),t(qe),t(te),t(Ye),t(se),t(Le),t(le),t(De),t(Ae),t(Ke),t(ae),t(Oe),t(Z),t(et),t(oe),t(tt),t(re),t(st),t(pe),t(lt),t(nt),t(ue),t(at)),t(r),j(h),j(R,e),j(_,e),j(X),j(z,e),j(q),j(L,e),j(k,e),j(K),j(ee,e),j(ne,e),j(G,e),j(ie),j(ce,e),j(de,e)}}}const as={local:"create-reproducible-pipelines",sections:[{local:"control-randomness",sections:[{local:"cpu",title:"CPU"},{local:"gpu",title:"GPU"}],title:"Control randomness"},{local:"deterministic-algorithms",title:"Deterministic algorithms"}],title:"Create reproducible pipelines"};function is(W){return Dt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ms extends At{constructor(r){super(),Kt(this,r,is,ns,Lt,{})}}export{ms as component}; | |
Xet Storage Details
- Size:
- 27.9 kB
- Xet hash:
- c2dd94c445c5d1962446206262955f1193572df507f1763e347b0735dd213d46
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.