Buckets:

rtrm's picture
download
raw
13.4 kB
import{s as Me,o as Te,n as we}from"../chunks/scheduler.8c3d61f6.js";import{S as _e,i as ve,g as d,s as p,r as $,A as Je,h as f,f as s,c as m,j as $e,u as y,x as g,k as re,y as je,a as n,v as w,d as M,t as T,w as _}from"../chunks/index.da70eac4.js";import{C as ie}from"../chunks/CodeBlock.a9c4becf.js";import{H as le,E as Ue}from"../chunks/getInferenceSnippets.ea1775db.js";import{H as Ze,a as ye}from"../chunks/HfOption.6c3b4e77.js";function Ge(J){let l,h='The GPU uses a different random number generator than the CPU. Diffusers solves this issue with the <a href="/docs/diffusers/pr_12403/en/api/utilities#diffusers.utils.torch_utils.randn_tensor">randn_tensor()</a> function to create the random tensor on a CPU and then moving it to the GPU. This function is used everywhere inside the pipeline and you don’t need to explicitly call it.',o,r,a='Use <a href="https://docs.pytorch.org/docs/stable/generated/torch.manual_seed.html" rel="nofollow">manual_seed</a> as shown below to set a seed.',i,u,v;return u=new ie({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjBudW1weSUyMGFzJTIwbnAlMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVBpcGVsaW5lJTBBJTBBZGRpbSUyMCUzRCUyMERESU1QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyZ29vZ2xlJTJGZGRwbS1jaWZhcjEwLTMyJTIyJTJDJTIwZGV2aWNlX21hcCUzRCUyMmN1ZGElMjIpJTBBZ2VuZXJhdG9yJTIwJTNEJTIwdG9yY2gubWFudWFsX3NlZWQoMCklMEFpbWFnZSUyMCUzRCUyMGRkaW0obnVtX2luZmVyZW5jZV9zdGVwcyUzRDIlMkMlMjBvdXRwdXRfdHlwZSUzRCUyMm5wJTIyJTJDJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yKS5pbWFnZXMlMEFwcmludChucC5hYnMoaW1hZ2UpLnN1bSgpKQ==",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>, device_map=<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}}),{c(){l=d("p"),l.innerHTML=h,o=p(),r=d("p"),r.innerHTML=a,i=p(),$(u.$$.fragment)},l(c){l=f(c,"P",{"data-svelte-h":!0}),g(l)!=="svelte-11urb4o"&&(l.innerHTML=h),o=m(c),r=f(c,"P",{"data-svelte-h":!0}),g(r)!=="svelte-195eoue"&&(r.innerHTML=a),i=m(c),y(u.$$.fragment,c)},m(c,b){n(c,l,b),n(c,o,b),n(c,r,b),n(c,i,b),w(u,c,b),v=!0},p:we,i(c){v||(M(u.$$.fragment,c),v=!0)},o(c){T(u.$$.fragment,c),v=!1},d(c){c&&(s(l),s(o),s(r),s(i)),_(u,c)}}}function Ce(J){let l,h='Set <code>device=&quot;cpu&quot;</code> in the <code>Generator</code> and use <a href="https://docs.pytorch.org/docs/stable/generated/torch.manual_seed.html" rel="nofollow">manual_seed</a> to set a seed for generating random numbers.',o,r,a;return r=new ie({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjBudW1weSUyMGFzJTIwbnAlMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVBpcGVsaW5lJTBBJTBBZGRpbSUyMCUzRCUyMERESU1QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyZ29vZ2xlJTJGZGRwbS1jaWZhcjEwLTMyJTIyKSUwQWdlbmVyYXRvciUyMCUzRCUyMHRvcmNoLkdlbmVyYXRvcihkZXZpY2UlM0QlMjJjcHUlMjIpLm1hbnVhbF9zZWVkKDApJTBBaW1hZ2UlMjAlM0QlMjBkZGltKG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyJTJDJTIwb3V0cHV0X3R5cGUlM0QlMjJucCUyMiUyQyUyMGdlbmVyYXRvciUzRGdlbmVyYXRvcikuaW1hZ2VzJTBBcHJpbnQobnAuYWJzKGltYWdlKS5zdW0oKSk=",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>)
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=d("p"),l.innerHTML=h,o=p(),$(r.$$.fragment)},l(i){l=f(i,"P",{"data-svelte-h":!0}),g(l)!=="svelte-i5qv65"&&(l.innerHTML=h),o=m(i),y(r.$$.fragment,i)},m(i,u){n(i,l,u),n(i,o,u),w(r,i,u),a=!0},p:we,i(i){a||(M(r.$$.fragment,i),a=!0)},o(i){T(r.$$.fragment,i),a=!1},d(i){i&&(s(l),s(o)),_(r,i)}}}function ke(J){let l,h,o,r;return l=new ye({props:{id:"generator",option:"GPU",$$slots:{default:[Ge]},$$scope:{ctx:J}}}),o=new ye({props:{id:"generator",option:"CPU",$$slots:{default:[Ce]},$$scope:{ctx:J}}}),{c(){$(l.$$.fragment),h=p(),$(o.$$.fragment)},l(a){y(l.$$.fragment,a),h=m(a),y(o.$$.fragment,a)},m(a,i){w(l,a,i),n(a,h,i),w(o,a,i),r=!0},p(a,i){const u={};i&2&&(u.$$scope={dirty:i,ctx:a}),l.$set(u);const v={};i&2&&(v.$$scope={dirty:i,ctx:a}),o.$set(v)},i(a){r||(M(l.$$.fragment,a),M(o.$$.fragment,a),r=!0)},o(a){T(l.$$.fragment,a),T(o.$$.fragment,a),r=!1},d(a){a&&s(h),_(l,a),_(o,a)}}}function We(J){let l,h,o,r,a,i,u,v="Diffusion is a random process that generates a different output every time. For certain situations like testing and replicating results, you want to generate the same result each time, across releases and platforms within a certain tolerance range.",c,b,oe="This guide will show you how to control sources of randomness and enable deterministic algorithms.",z,Z,S,G,pe='Pipelines rely on <a href="https://pytorch.org/docs/stable/generated/torch.randn.html" rel="nofollow">torch.randn</a>, which uses a different random seed each time, to create the initial noisy tensors. To generate the same output on a CPU or GPU, use a <a href="https://docs.pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">Generator</a> to manage how random values are generated.',F,j,me="<p>If reproducibility is important to your use case, we recommend always using a CPU <code>Generator</code>. The performance loss is often negligible and you’ll generate more similar values.</p>",x,U,D,C,ce="The <code>Generator</code> object should be passed to the pipeline instead of an integer seed. <code>Generator</code> maintains a <em>random state</em> that is consumed and modified when used. Once consumed, the same <code>Generator</code> object produces different results in subsequent calls, even across different pipelines, because it’s <em>state</em> has changed.",Q,k,Y,W,q,R,ue='PyTorch supports <a href="https://docs.pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms" rel="nofollow">deterministic algorithms</a> - where available - for certain operations so they produce the same results. Deterministic algorithms may be slower and decrease performance.',A,V,de='Use Diffusers’ <a href="https://github.com/huggingface/diffusers/blob/142f353e1c638ff1d20bd798402b68f72c1ebbdd/src/diffusers/utils/testing_utils.py#L861" rel="nofollow">enable_full_determinism</a> function to enable deterministic algorithms.',K,H,N,I,fe="Under the hood, <code>enable_full_determinism</code> works by:",O,B,he='<li>Setting 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 rntime. Non-deterministic behavior occurs when operations are used in more than one CUDA stream.</li> <li>Disabling benchmarking to find the fastest convolution operation by setting <code>torch.backends.cudnn.benchmark=False</code>. Non-deterministic behavior occurs because the benchmark may select different algorithms each time depending on hardware or benchmarking noise.</li> <li>Disabling TensorFloat32 (TF32) operations in favor of more precise and consistent full-precision operations.</li>',ee,P,te,E,be='We strongly recommend reading PyTorch’s developer notes about <a href="https://docs.pytorch.org/docs/stable/notes/randomness.html" rel="nofollow">Reproducibility</a>. You can try to limit randomness, but it is not <em>guaranteed</em> even with an identical seed.',se,X,ne,L,ae;return a=new le({props:{title:"Reproducibility",local:"reproducibility",headingTag:"h1"}}),Z=new le({props:{title:"Generator",local:"generator",headingTag:"h2"}}),U=new Ze({props:{id:"generator",options:["GPU","CPU"],$$slots:{default:[ke]},$$scope:{ctx:J}}}),k=new ie({props:{code:"Z2VuZXJhdG9yJTIwJTNEJTIwdG9yY2gubWFudWFsX3NlZWQoMCklMEElMEFmb3IlMjBfJTIwaW4lMjByYW5nZSg1KSUzQSUwQS0lMjAlMjAlMjAlMjBpbWFnZSUyMCUzRCUyMHBpcGVsaW5lKHByb21wdCUyQyUyMGdlbmVyYXRvciUzRGdlbmVyYXRvciklMEElMkIlMjAlMjAlMjAlMjBpbWFnZSUyMCUzRCUyMHBpcGVsaW5lKHByb21wdCUyQyUyMGdlbmVyYXRvciUzRHRvcmNoLm1hbnVhbF9zZWVkKDApKQ==",highlighted:`generator = torch.manual_seed(<span class="hljs-number">0</span>)
<span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>):
- image = pipeline(prompt, generator=generator)
+ image = pipeline(prompt, generator=torch.manual_seed(<span class="hljs-number">0</span>))`,wrap:!1}}),W=new le({props:{title:"Deterministic algorithms",local:"deterministic-algorithms",headingTag:"h2"}}),H=new ie({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzX3V0aWxzJTIwaW1wb3J0JTIwZW5hYmxlX2Z1bGxfZGV0ZXJtaW5pc20lMEElMEFlbmFibGVfZnVsbF9kZXRlcm1pbmlzbSgp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers_utils <span class="hljs-keyword">import</span> enable_full_determinism
enable_full_determinism()`,wrap:!1}}),P=new le({props:{title:"Resources",local:"resources",headingTag:"h2"}}),X=new Ue({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/using-diffusers/reusing_seeds.md"}}),{c(){l=d("meta"),h=p(),o=d("p"),r=p(),$(a.$$.fragment),i=p(),u=d("p"),u.textContent=v,c=p(),b=d("p"),b.textContent=oe,z=p(),$(Z.$$.fragment),S=p(),G=d("p"),G.innerHTML=pe,F=p(),j=d("blockquote"),j.innerHTML=me,x=p(),$(U.$$.fragment),D=p(),C=d("p"),C.innerHTML=ce,Q=p(),$(k.$$.fragment),Y=p(),$(W.$$.fragment),q=p(),R=d("p"),R.innerHTML=ue,A=p(),V=d("p"),V.innerHTML=de,K=p(),$(H.$$.fragment),N=p(),I=d("p"),I.innerHTML=fe,O=p(),B=d("ul"),B.innerHTML=he,ee=p(),$(P.$$.fragment),te=p(),E=d("p"),E.innerHTML=be,se=p(),$(X.$$.fragment),ne=p(),L=d("p"),this.h()},l(e){const t=Je("svelte-u9bgzb",document.head);l=f(t,"META",{name:!0,content:!0}),t.forEach(s),h=m(e),o=f(e,"P",{}),$e(o).forEach(s),r=m(e),y(a.$$.fragment,e),i=m(e),u=f(e,"P",{"data-svelte-h":!0}),g(u)!=="svelte-urbwv"&&(u.textContent=v),c=m(e),b=f(e,"P",{"data-svelte-h":!0}),g(b)!=="svelte-j5curv"&&(b.textContent=oe),z=m(e),y(Z.$$.fragment,e),S=m(e),G=f(e,"P",{"data-svelte-h":!0}),g(G)!=="svelte-p45uo9"&&(G.innerHTML=pe),F=m(e),j=f(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),g(j)!=="svelte-avo6dt"&&(j.innerHTML=me),x=m(e),y(U.$$.fragment,e),D=m(e),C=f(e,"P",{"data-svelte-h":!0}),g(C)!=="svelte-1q1k51l"&&(C.innerHTML=ce),Q=m(e),y(k.$$.fragment,e),Y=m(e),y(W.$$.fragment,e),q=m(e),R=f(e,"P",{"data-svelte-h":!0}),g(R)!=="svelte-174lkkp"&&(R.innerHTML=ue),A=m(e),V=f(e,"P",{"data-svelte-h":!0}),g(V)!=="svelte-1hzqg3c"&&(V.innerHTML=de),K=m(e),y(H.$$.fragment,e),N=m(e),I=f(e,"P",{"data-svelte-h":!0}),g(I)!=="svelte-k420hc"&&(I.innerHTML=fe),O=m(e),B=f(e,"UL",{"data-svelte-h":!0}),g(B)!=="svelte-9fj8sk"&&(B.innerHTML=he),ee=m(e),y(P.$$.fragment,e),te=m(e),E=f(e,"P",{"data-svelte-h":!0}),g(E)!=="svelte-1flhclo"&&(E.innerHTML=be),se=m(e),y(X.$$.fragment,e),ne=m(e),L=f(e,"P",{}),$e(L).forEach(s),this.h()},h(){re(l,"name","hf:doc:metadata"),re(l,"content",Re),re(j,"class","tip")},m(e,t){je(document.head,l),n(e,h,t),n(e,o,t),n(e,r,t),w(a,e,t),n(e,i,t),n(e,u,t),n(e,c,t),n(e,b,t),n(e,z,t),w(Z,e,t),n(e,S,t),n(e,G,t),n(e,F,t),n(e,j,t),n(e,x,t),w(U,e,t),n(e,D,t),n(e,C,t),n(e,Q,t),w(k,e,t),n(e,Y,t),w(W,e,t),n(e,q,t),n(e,R,t),n(e,A,t),n(e,V,t),n(e,K,t),w(H,e,t),n(e,N,t),n(e,I,t),n(e,O,t),n(e,B,t),n(e,ee,t),w(P,e,t),n(e,te,t),n(e,E,t),n(e,se,t),w(X,e,t),n(e,ne,t),n(e,L,t),ae=!0},p(e,[t]){const ge={};t&2&&(ge.$$scope={dirty:t,ctx:e}),U.$set(ge)},i(e){ae||(M(a.$$.fragment,e),M(Z.$$.fragment,e),M(U.$$.fragment,e),M(k.$$.fragment,e),M(W.$$.fragment,e),M(H.$$.fragment,e),M(P.$$.fragment,e),M(X.$$.fragment,e),ae=!0)},o(e){T(a.$$.fragment,e),T(Z.$$.fragment,e),T(U.$$.fragment,e),T(k.$$.fragment,e),T(W.$$.fragment,e),T(H.$$.fragment,e),T(P.$$.fragment,e),T(X.$$.fragment,e),ae=!1},d(e){e&&(s(h),s(o),s(r),s(i),s(u),s(c),s(b),s(z),s(S),s(G),s(F),s(j),s(x),s(D),s(C),s(Q),s(Y),s(q),s(R),s(A),s(V),s(K),s(N),s(I),s(O),s(B),s(ee),s(te),s(E),s(se),s(ne),s(L)),s(l),_(a,e),_(Z,e),_(U,e),_(k,e),_(W,e),_(H,e),_(P,e),_(X,e)}}}const Re='{"title":"Reproducibility","local":"reproducibility","sections":[{"title":"Generator","local":"generator","sections":[],"depth":2},{"title":"Deterministic algorithms","local":"deterministic-algorithms","sections":[],"depth":2},{"title":"Resources","local":"resources","sections":[],"depth":2}],"depth":1}';function Ve(J){return Te(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Xe extends _e{constructor(l){super(),ve(this,l,Ve,We,Me,{})}}export{Xe as component};

Xet Storage Details

Size:
13.4 kB
·
Xet hash:
0b7f1b3bd59cb04439ff4cd9ba05c7c8ff6388cc579a8bfe7010dd4ab4b58755

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