Buckets:

rtrm's picture
download
raw
13.6 kB
import{s as Me,o as Te,n as ie}from"../chunks/scheduler.8c3d61f6.js";import{S as _e,i as ve,g as f,s as p,r as b,A as Je,h,f as s,c as m,j as ge,u as g,x as w,k as we,y as je,a,v as y,d as M,t as T,w as _}from"../chunks/index.da70eac4.js";import{T as Ue}from"../chunks/Tip.1d9b8c37.js";import{C as re}from"../chunks/CodeBlock.a9c4becf.js";import{H as le,E as Ze}from"../chunks/getInferenceSnippets.676f6ee5.js";import{H as Ge,a as ye}from"../chunks/HfOption.6c3b4e77.js";function Ce(v){let n,d="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.";return{c(){n=f("p"),n.innerHTML=d},l(i){n=h(i,"P",{"data-svelte-h":!0}),w(n)!=="svelte-14ecxc2"&&(n.innerHTML=d)},m(i,o){a(i,n,o)},p:ie,d(i){i&&s(n)}}}function ke(v){let n,d='The GPU uses a different random number generator than the CPU. Diffusers solves this issue with the <a href="/docs/diffusers/pr_12262/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.',i,o,l='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.',r,u,J;return u=new re({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(){n=f("p"),n.innerHTML=d,i=p(),o=f("p"),o.innerHTML=l,r=p(),b(u.$$.fragment)},l(c){n=h(c,"P",{"data-svelte-h":!0}),w(n)!=="svelte-1gwdu5n"&&(n.innerHTML=d),i=m(c),o=h(c,"P",{"data-svelte-h":!0}),w(o)!=="svelte-195eoue"&&(o.innerHTML=l),r=m(c),g(u.$$.fragment,c)},m(c,$){a(c,n,$),a(c,i,$),a(c,o,$),a(c,r,$),y(u,c,$),J=!0},p:ie,i(c){J||(M(u.$$.fragment,c),J=!0)},o(c){T(u.$$.fragment,c),J=!1},d(c){c&&(s(n),s(i),s(o),s(r)),_(u,c)}}}function We(v){let n,d='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.',i,o,l;return o=new re({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(){n=f("p"),n.innerHTML=d,i=p(),b(o.$$.fragment)},l(r){n=h(r,"P",{"data-svelte-h":!0}),w(n)!=="svelte-i5qv65"&&(n.innerHTML=d),i=m(r),g(o.$$.fragment,r)},m(r,u){a(r,n,u),a(r,i,u),y(o,r,u),l=!0},p:ie,i(r){l||(M(o.$$.fragment,r),l=!0)},o(r){T(o.$$.fragment,r),l=!1},d(r){r&&(s(n),s(i)),_(o,r)}}}function Re(v){let n,d,i,o;return n=new ye({props:{id:"generator",option:"GPU",$$slots:{default:[ke]},$$scope:{ctx:v}}}),i=new ye({props:{id:"generator",option:"CPU",$$slots:{default:[We]},$$scope:{ctx:v}}}),{c(){b(n.$$.fragment),d=p(),b(i.$$.fragment)},l(l){g(n.$$.fragment,l),d=m(l),g(i.$$.fragment,l)},m(l,r){y(n,l,r),a(l,d,r),y(i,l,r),o=!0},p(l,r){const u={};r&2&&(u.$$scope={dirty:r,ctx:l}),n.$set(u);const J={};r&2&&(J.$$scope={dirty:r,ctx:l}),i.$set(J)},i(l){o||(M(n.$$.fragment,l),M(i.$$.fragment,l),o=!0)},o(l){T(n.$$.fragment,l),T(i.$$.fragment,l),o=!1},d(l){l&&s(d),_(n,l),_(i,l)}}}function Ve(v){let n,d,i,o,l,r,u,J="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,$,oe="This guide will show you how to control sources of randomness and enable deterministic algorithms.",L,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,x,U,D,C,me="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.",Y,k,Q,W,q,R,ce='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,ue='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,de="Under the hood, <code>enable_full_determinism</code> works by:",O,P,fe='<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,B,te,X,he='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,E,ne,z,ae;return l=new le({props:{title:"Reproducibility",local:"reproducibility",headingTag:"h1"}}),Z=new le({props:{title:"Generator",local:"generator",headingTag:"h2"}}),j=new Ue({props:{warning:!1,$$slots:{default:[Ce]},$$scope:{ctx:v}}}),U=new Ge({props:{id:"generator",options:["GPU","CPU"],$$slots:{default:[Re]},$$scope:{ctx:v}}}),k=new re({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 re({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}}),B=new le({props:{title:"Resources",local:"resources",headingTag:"h2"}}),E=new Ze({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/using-diffusers/reusing_seeds.md"}}),{c(){n=f("meta"),d=p(),i=f("p"),o=p(),b(l.$$.fragment),r=p(),u=f("p"),u.textContent=J,c=p(),$=f("p"),$.textContent=oe,L=p(),b(Z.$$.fragment),S=p(),G=f("p"),G.innerHTML=pe,F=p(),b(j.$$.fragment),x=p(),b(U.$$.fragment),D=p(),C=f("p"),C.innerHTML=me,Y=p(),b(k.$$.fragment),Q=p(),b(W.$$.fragment),q=p(),R=f("p"),R.innerHTML=ce,A=p(),V=f("p"),V.innerHTML=ue,K=p(),b(H.$$.fragment),N=p(),I=f("p"),I.innerHTML=de,O=p(),P=f("ul"),P.innerHTML=fe,ee=p(),b(B.$$.fragment),te=p(),X=f("p"),X.innerHTML=he,se=p(),b(E.$$.fragment),ne=p(),z=f("p"),this.h()},l(e){const t=Je("svelte-u9bgzb",document.head);n=h(t,"META",{name:!0,content:!0}),t.forEach(s),d=m(e),i=h(e,"P",{}),ge(i).forEach(s),o=m(e),g(l.$$.fragment,e),r=m(e),u=h(e,"P",{"data-svelte-h":!0}),w(u)!=="svelte-urbwv"&&(u.textContent=J),c=m(e),$=h(e,"P",{"data-svelte-h":!0}),w($)!=="svelte-j5curv"&&($.textContent=oe),L=m(e),g(Z.$$.fragment,e),S=m(e),G=h(e,"P",{"data-svelte-h":!0}),w(G)!=="svelte-p45uo9"&&(G.innerHTML=pe),F=m(e),g(j.$$.fragment,e),x=m(e),g(U.$$.fragment,e),D=m(e),C=h(e,"P",{"data-svelte-h":!0}),w(C)!=="svelte-1q1k51l"&&(C.innerHTML=me),Y=m(e),g(k.$$.fragment,e),Q=m(e),g(W.$$.fragment,e),q=m(e),R=h(e,"P",{"data-svelte-h":!0}),w(R)!=="svelte-174lkkp"&&(R.innerHTML=ce),A=m(e),V=h(e,"P",{"data-svelte-h":!0}),w(V)!=="svelte-1hzqg3c"&&(V.innerHTML=ue),K=m(e),g(H.$$.fragment,e),N=m(e),I=h(e,"P",{"data-svelte-h":!0}),w(I)!=="svelte-k420hc"&&(I.innerHTML=de),O=m(e),P=h(e,"UL",{"data-svelte-h":!0}),w(P)!=="svelte-9fj8sk"&&(P.innerHTML=fe),ee=m(e),g(B.$$.fragment,e),te=m(e),X=h(e,"P",{"data-svelte-h":!0}),w(X)!=="svelte-1flhclo"&&(X.innerHTML=he),se=m(e),g(E.$$.fragment,e),ne=m(e),z=h(e,"P",{}),ge(z).forEach(s),this.h()},h(){we(n,"name","hf:doc:metadata"),we(n,"content",He)},m(e,t){je(document.head,n),a(e,d,t),a(e,i,t),a(e,o,t),y(l,e,t),a(e,r,t),a(e,u,t),a(e,c,t),a(e,$,t),a(e,L,t),y(Z,e,t),a(e,S,t),a(e,G,t),a(e,F,t),y(j,e,t),a(e,x,t),y(U,e,t),a(e,D,t),a(e,C,t),a(e,Y,t),y(k,e,t),a(e,Q,t),y(W,e,t),a(e,q,t),a(e,R,t),a(e,A,t),a(e,V,t),a(e,K,t),y(H,e,t),a(e,N,t),a(e,I,t),a(e,O,t),a(e,P,t),a(e,ee,t),y(B,e,t),a(e,te,t),a(e,X,t),a(e,se,t),y(E,e,t),a(e,ne,t),a(e,z,t),ae=!0},p(e,[t]){const $e={};t&2&&($e.$$scope={dirty:t,ctx:e}),j.$set($e);const be={};t&2&&(be.$$scope={dirty:t,ctx:e}),U.$set(be)},i(e){ae||(M(l.$$.fragment,e),M(Z.$$.fragment,e),M(j.$$.fragment,e),M(U.$$.fragment,e),M(k.$$.fragment,e),M(W.$$.fragment,e),M(H.$$.fragment,e),M(B.$$.fragment,e),M(E.$$.fragment,e),ae=!0)},o(e){T(l.$$.fragment,e),T(Z.$$.fragment,e),T(j.$$.fragment,e),T(U.$$.fragment,e),T(k.$$.fragment,e),T(W.$$.fragment,e),T(H.$$.fragment,e),T(B.$$.fragment,e),T(E.$$.fragment,e),ae=!1},d(e){e&&(s(d),s(i),s(o),s(r),s(u),s(c),s($),s(L),s(S),s(G),s(F),s(x),s(D),s(C),s(Y),s(Q),s(q),s(R),s(A),s(V),s(K),s(N),s(I),s(O),s(P),s(ee),s(te),s(X),s(se),s(ne),s(z)),s(n),_(l,e),_(Z,e),_(j,e),_(U,e),_(k,e),_(W,e),_(H,e),_(B,e),_(E,e)}}}const He='{"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 Ie(v){return Te(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Se extends _e{constructor(n){super(),ve(this,n,Ie,Ve,Me,{})}}export{Se as component};

Xet Storage Details

Size:
13.6 kB
·
Xet hash:
be78a55dc5d2d3010434d288f80354dc78390b0d1ee006e9e4b9bdea80c9196a

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