import{s as oe,o as Te,n as Fl}from"../chunks/scheduler.6e0d5ff7.js";import{S as re,i as Me,g as J,s as n,r,E as me,h as i,f as t,c as a,j as ie,u as M,x as U,k as Ue,y as ce,a as s,v as m,d as c,t as u,w as d}from"../chunks/index.d7c1b260.js";import{T as Dl}from"../chunks/Tip.c000e27b.js";import{C as el}from"../chunks/CodeBlock.09a08494.js";import{D as ue}from"../chunks/DocNotebookDropdown.b1b23d60.js";import{H as sl}from"../chunks/Heading.30a009b0.js";function de(w){let p,y='💡 Pytorch의 <a href="https://pytorch.org/docs/stable/notes/randomness.html" rel="nofollow">재현성에 대한 선언</a>를 꼭 읽어보길 추천합니다:',o,T,j=`<p>완전하게 재현가능한 결과는 Pytorch 배포, 개별적인 커밋, 혹은 다른 플랫폼들에서 보장되지 않습니다.
또한, 결과는 CPU와 GPU 실행간에 심지어 같은 seed를 사용할 때도 재현 가능하지 않을 수 있습니다.</p>`;return{c(){p=J("p"),p.innerHTML=y,o=n(),T=J("blockquote"),T.innerHTML=j},l(f){p=i(f,"P",{"data-svelte-h":!0}),U(p)!=="svelte-3yn5i4"&&(p.innerHTML=y),o=a(f),T=i(f,"BLOCKQUOTE",{"data-svelte-h":!0}),U(T)!=="svelte-va9th1"&&(T.innerHTML=j)},m(f,Q){s(f,p,Q),s(f,o,Q),s(f,T,Q)},p:Fl,d(f){f&&(t(p),t(o),t(T))}}}function fe(w){let p,y=`💡 처음에는 시드를 나타내는 정수값 대신에 <code>Generator</code> 개체를 파이프라인에 전달하는 것이 약간 비직관적일 수 있지만,
<code>Generator</code>는 순차적으로 여러 파이프라인에 전달될 수 있는 \\랜덤상태\\이기 때문에 PyTorch에서 확률론적 모델을 다룰 때 권장되는 설계입니다.`;return{c(){p=J("p"),p.innerHTML=y},l(o){p=i(o,"P",{"data-svelte-h":!0}),U(p)!=="svelte-8pt0v2"&&(p.innerHTML=y)},m(o,T){s(o,p,T)},p:Fl,d(o){o&&t(p)}}}function ye(w){let p,y=`💡 재현성이 중요한 경우에는 항상 CPU generator를 전달하는 것이 좋습니다.
성능 손실은 무시할 수 없는 경우가 많으며 파이프라인이 GPU에서 실행되었을 때보다 훨씬 더 비슷한 값을 생성할 수 있습니다.`;return{c(){p=J("p"),p.textContent=y},l(o){p=i(o,"P",{"data-svelte-h":!0}),U(p)!=="svelte-784xbp"&&(p.textContent=y)},m(o,T){s(o,p,T)},p:Fl,d(o){o&&t(p)}}}function Qe(w){let p,y,o,T,j,f,Q,nl,C,Ol=`재현성은 테스트, 결과 재현, 그리고 <a href="resuing_seeds">이미지 퀄리티 높이기</a>에서 중요합니다.
그러나 diffusion 모델의 무작위성은 매번 모델이 돌아갈 때마다 파이프라인이 다른 이미지를 생성할 수 있도록 하는 이유로 필요합니다.
플랫폼 간에 정확하게 동일한 결과를 얻을 수는 없지만, 특정 허용 범위 내에서 릴리스 및 플랫폼 간에 결과를 재현할 수는 있습니다.
그럼에도 diffusion 파이프라인과 체크포인트에 따라 허용 오차가 달라집니다.`,al,g,vl="diffusion 모델에서 무작위성의 원천을 제어하거나 결정론적 알고리즘을 사용하는 방법을 이해하는 것이 중요한 이유입니다.",pl,h,Jl,I,il,E,Nl="추론에서, 파이프라인은 노이즈를 줄이기 위해 가우시안 노이즈를 생성하거나 스케줄링 단계에 노이즈를 더하는 등의 랜덤 샘플링 실행에 크게 의존합니다,",Ul,R,xl='<a href="https://huggingface.co/docs/diffusers/v0.18.0/en/api/pipelines/ddim#diffusers.DDIMPipeline" rel="nofollow">DDIMPipeline</a>에서 두 추론 단계 이후의 텐서 값을 살펴보세요:',ol,k,Tl,Z,Pl="위의 코드를 실행하면 하나의 값이 나오지만, 다시 실행하면 다른 값이 나옵니다. 무슨 일이 일어나고 있는 걸까요?",rl,B,Sl=`파이프라인이 실행될 때마다, <a href="https://pytorch.org/docs/stable/generated/torch.randn.html" rel="nofollow">torch.randn</a>은
단계적으로 노이즈 제거되는 가우시안 노이즈가 생성하기 위한 다른 랜덤 seed를 사용합니다.`,Ml,$,Al="그러나 동일한 이미지를 안정적으로 생성해야 하는 경우에는 CPU에서 파이프라인을 실행하는지 GPU에서 실행하는지에 따라 달라집니다.",ml,W,cl,_,Xl='CPU에서 재현 가능한 결과를 생성하려면, PyTorch <a href="https://pytorch.org/docs/stable/generated/torch.randn.html" rel="nofollow">Generator</a>로 seed를 고정합니다:',ul,G,dl,D,Hl="이제 위의 코드를 실행하면 seed를 가진 <code>Generator</code> 객체가 파이프라인의 모든 랜덤 함수에 전달되므로 항상 <code>1491.1711</code> 값이 출력됩니다.",fl,F,zl="특정 하드웨어 및 PyTorch 버전에서 이 코드 예제를 실행하면 동일하지는 않더라도 유사한 결과를 얻을 수 있습니다.",yl,b,Ql,O,jl,v,Ll="예를 들면, GPU 상에서 같은 코드 예시를 실행하면:",wl,N,hl,x,ql="GPU가 CPU와 다른 난수 생성기를 사용하기 때문에 동일한 시드를 사용하더라도 결과가 같지 않습니다.",bl,P,Yl=`이 문제를 피하기 위해 🧨 Diffusers는 CPU에 임의의 노이즈를 생성한 다음 필요에 따라 텐서를 GPU로 이동시키는
<a href="https://huggingface.co/docs/diffusers/v0.18.0/en/api/utilities#diffusers.utils.randn_tensor" rel="nofollow">randn_tensor()</a>기능을 가지고 있습니다.
<code>randn_tensor</code> 기능은 파이프라인 내부 어디에서나 사용되므로 파이프라인이 GPU에서 실행되더라도 <strong>항상</strong> CPU <code>Generator</code>를 통과할 수 있습니다.`,Vl,S,Kl="이제 결과에 훨씬 더 다가왔습니다!",Cl,A,gl,V,Il,X,le=`마지막으로 <a href="https://huggingface.co/docs/diffusers/v0.18.0/en/api/pipelines/unclip#diffusers.UnCLIPPipeline" rel="nofollow">UnCLIPPipeline</a>과 같은
더 복잡한 파이프라인의 경우, 이들은 종종 정밀 오차 전파에 극도로 취약합니다.
다른 GPU 하드웨어 또는 PyTorch 버전에서 유사한 결과를 기대하지 마세요.
이 경우 완전한 재현성을 위해 완전히 동일한 하드웨어 및 PyTorch 버전을 실행해야 합니다.`,El,H,Rl,z,ee=`결정론적 알고리즘을 사용하여 재현 가능한 파이프라인을 생성하도록 PyTorch를 구성할 수도 있습니다.
그러나 결정론적 알고리즘은 비결정론적 알고리즘보다 느리고 성능이 저하될 수 있습니다.
하지만 재현성이 중요하다면, 이것이 최선의 방법입니다!`,kl,L,te=`둘 이상의 CUDA 스트림에서 작업이 시작될 때 비결정론적 동작이 발생합니다.
이 문제를 방지하려면 환경 변수 <a href="https://docs.nvidia.com/cuda/cublas/index.html#results-reproducibility" rel="nofollow">CUBLAS_WORKSPACE_CONFIG</a>를 <code>:16:8</code>로 설정해서
런타임 중에 오직 하나의 버퍼 크리만 사용하도록 설정합니다.`,Zl,q,se=`PyTorch는 일반적으로 가장 빠른 알고리즘을 선택하기 위해 여러 알고리즘을 벤치마킹합니다.
하지만 재현성을 원하는 경우, 벤치마크가 매 순간 다른 알고리즘을 선택할 수 있기 때문에 이 기능을 사용하지 않도록 설정해야 합니다.
마지막으로, <a href="https://pytorch.org/docs/stable/generated/torch.use_deterministic_algorithms.html" rel="nofollow">torch.use_deterministic_algorithms</a>에
<code>True</code>를 통과시켜 결정론적 알고리즘이 활성화 되도록 합니다.`,Bl,Y,$l,K,ne="이제 동일한 파이프라인을 두번 실행하면 동일한 결과를 얻을 수 있습니다.",Wl,ll,_l,tl,Gl;return j=new sl({props:{title:"재현 가능한 파이프라인 생성하기",local:"재현-가능한-파이프라인-생성하기",headingTag:"h1"}}),Q=new ue({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/ko/reproducibility.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/ko/pytorch/reproducibility.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/ko/tensorflow/reproducibility.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/ko/reproducibility.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/ko/pytorch/reproducibility.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/ko/tensorflow/reproducibility.ipynb"}]}}),h=new Dl({props:{$$slots:{default:[de]},$$scope:{ctx:w}}}),I=new sl({props:{title:"무작위성 제어하기",local:"무작위성-제어하기",headingTag:"h2"}}),k=new el({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERESU1QaXBlbGluZSUwQWltcG9ydCUyMG51bXB5JTIwYXMlMjBucCUwQSUwQW1vZGVsX2lkJTIwJTNEJTIwJTIyZ29vZ2xlJTJGZGRwbS1jaWZhcjEwLTMyJTIyJTBBJTBBJTIzJTIwJUVCJUFBJUE4JUVCJThEJUI4JUVBJUIzJUJDJTIwJUVDJThBJUE0JUVDJUJDJTgwJUVDJUE0JTg0JUVCJTlGJUFDJUVCJUE1JUJDJTIwJUVCJUI2JTg4JUVCJTlGJUFDJUVDJTk4JUE0JUVBJUI4JUIwJTBBZGRpbSUyMCUzRCUyMERESU1QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQpJTBBJTBBJTIzJTIwJUVCJTkxJTkwJTIwJUVBJUIwJTlDJUVDJTlEJTk4JTIwJUVCJThCJUE4JUVBJUIzJTg0JUVDJTk3JTkwJTIwJUVCJThDJTgwJUVEJTk1JUI0JUVDJTg0JTlDJTIwJUVEJThDJThDJUVDJTlEJUI0JUVEJTk0JTg0JUVCJTlEJUJDJUVDJTlEJUI4JUVDJTlEJTg0JTIwJUVDJThCJUE0JUVEJTk2JTg5JUVEJTk1JTk4JUVBJUIzJUEwJTIwbnVtcHklMjB0ZW5zb3IlRUIlQTElOUMlMjAlRUElQjAlOTIlRUMlOUQlODQlMjAlRUIlQjAlOTglRUQlOTklOTglRUQlOTUlOTglRUElQjglQjAlMEFpbWFnZSUyMCUzRCUyMGRkaW0obnVtX2luZmVyZW5jZV9zdGVwcyUzRDIlMkMlMjBvdXRwdXRfdHlwZSUzRCUyMm5wJTIyKS5pbWFnZXMlMEFwcmludChucC5hYnMoaW1hZ2UpLnN1bSgpKQ==",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"># 모델과 스케줄러를 불러오기</span>
ddim = DDIMPipeline.from_pretrained(model_id)

<span class="hljs-comment"># 두 개의 단계에 대해서 파이프라인을 실행하고 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>())`,wrap:!1}}),W=new sl({props:{title:"CPU",local:"cpu",headingTag:"h3"}}),G=new el({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVBpcGVsaW5lJTBBaW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJnb29nbGUlMkZkZHBtLWNpZmFyMTAtMzIlMjIlMEElMEElMjMlMjAlRUIlQUElQTglRUIlOEQlQjglRUElQjMlQkMlMjAlRUMlOEElQTQlRUMlQkMlODAlRUMlQTQlODQlRUIlOUYlQUMlMjAlRUIlQjYlODglRUIlOUYlQUMlRUMlOTglQTQlRUElQjglQjAlMEFkZGltJTIwJTNEJTIwRERJTVBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCklMEElMEElMjMlMjAlRUMlOUUlQUMlRUQlOTglODQlRUMlODQlQjElRUMlOUQlODQlMjAlRUMlOUMlODQlRUQlOTUlQjQlMjBnZW5lcmF0b3IlMjAlRUIlQTclOEMlRUIlOTMlQTQlRUElQjglQjAlMEFnZW5lcmF0b3IlMjAlM0QlMjB0b3JjaC5HZW5lcmF0b3IoZGV2aWNlJTNEJTIyY3B1JTIyKS5tYW51YWxfc2VlZCgwKSUwQSUwQSUyMyUyMCVFQiU5MSU5MCUyMCVFQSVCMCU5QyVFQyU5RCU5OCUyMCVFQiU4QiVBOCVFQSVCMyU4NCVFQyU5NyU5MCUyMCVFQiU4QyU4MCVFRCU5NSVCNCVFQyU4NCU5QyUyMCVFRCU4QyU4QyVFQyU5RCVCNCVFRCU5NCU4NCVFQiU5RCVCQyVFQyU5RCVCOCVFQyU5RCU4NCUyMCVFQyU4QiVBNCVFRCU5NiU4OSVFRCU5NSU5OCVFQSVCMyVBMCUyMG51bXB5JTIwdGVuc29yJUVCJUExJTlDJTIwJUVBJUIwJTkyJUVDJTlEJTg0JTIwJUVCJUIwJTk4JUVEJTk5JTk4JUVEJTk1JTk4JUVBJUI4JUIwJTBBaW1hZ2UlMjAlM0QlMjBkZGltKG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyJTJDJTIwb3V0cHV0X3R5cGUlM0QlMjJucCUyMiUyQyUyMGdlbmVyYXRvciUzRGdlbmVyYXRvcikuaW1hZ2VzJTBBcHJpbnQobnAuYWJzKGltYWdlKS5zdW0oKSk=",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"># 모델과 스케줄러 불러오기</span>
ddim = DDIMPipeline.from_pretrained(model_id)

<span class="hljs-comment"># 재현성을 위해 generator 만들기</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"># 두 개의 단계에 대해서 파이프라인을 실행하고 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>())`,wrap:!1}}),b=new Dl({props:{$$slots:{default:[fe]},$$scope:{ctx:w}}}),O=new sl({props:{title:"GPU",local:"gpu",headingTag:"h3"}}),N=new el({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVBpcGVsaW5lJTBBaW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJnb29nbGUlMkZkZHBtLWNpZmFyMTAtMzIlMjIlMEElMEElMjMlMjAlRUIlQUElQTglRUIlOEQlQjglRUElQjMlQkMlMjAlRUMlOEElQTQlRUMlQkMlODAlRUMlQTQlODQlRUIlOUYlQUMlMjAlRUIlQjYlODglRUIlOUYlQUMlRUMlOTglQTQlRUElQjglQjAlMEFkZGltJTIwJTNEJTIwRERJTVBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCklMEFkZGltLnRvKCUyMmN1ZGElMjIpJTBBJTBBJTIzJTIwJUVDJTlFJUFDJUVEJTk4JTg0JUVDJTg0JUIxJUVDJTlEJTg0JTIwJUVDJTlDJTg0JUVEJTk1JTlDJTIwZ2VuZXJhdG9yJTIwJUVCJUE3JThDJUVCJTkzJUE0JUVBJUI4JUIwJTBBZ2VuZXJhdG9yJTIwJTNEJTIwdG9yY2guR2VuZXJhdG9yKGRldmljZSUzRCUyMmN1ZGElMjIpLm1hbnVhbF9zZWVkKDApJTBBJTBBJTIzJTIwJUVCJTkxJTkwJTIwJUVBJUIwJTlDJUVDJTlEJTk4JTIwJUVCJThCJUE4JUVBJUIzJTg0JUVDJTk3JTkwJTIwJUVCJThDJTgwJUVEJTk1JUI0JUVDJTg0JTlDJTIwJUVEJThDJThDJUVDJTlEJUI0JUVEJTk0JTg0JUVCJTlEJUJDJUVDJTlEJUI4JUVDJTlEJTg0JTIwJUVDJThCJUE0JUVEJTk2JTg5JUVEJTk1JTk4JUVBJUIzJUEwJTIwbnVtcHklMjB0ZW5zb3IlRUIlQTElOUMlMjAlRUElQjAlOTIlRUMlOUQlODQlMjAlRUIlQjAlOTglRUQlOTklOTglRUQlOTUlOTglRUElQjglQjAlMEFpbWFnZSUyMCUzRCUyMGRkaW0obnVtX2luZmVyZW5jZV9zdGVwcyUzRDIlMkMlMjBvdXRwdXRfdHlwZSUzRCUyMm5wJTIyJTJDJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yKS5pbWFnZXMlMEFwcmludChucC5hYnMoaW1hZ2UpLnN1bSgpKQ==",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"># 모델과 스케줄러 불러오기</span>
ddim = DDIMPipeline.from_pretrained(model_id)
ddim.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-comment"># 재현성을 위한 generator 만들기</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"># 두 개의 단계에 대해서 파이프라인을 실행하고 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>())`,wrap:!1}}),A=new el({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVBpcGVsaW5lJTBBaW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJnb29nbGUlMkZkZHBtLWNpZmFyMTAtMzIlMjIlMEElMEElMjMlMjAlRUIlQUElQTglRUIlOEQlQjglRUElQjMlQkMlMjAlRUMlOEElQTQlRUMlQkMlODAlRUMlQTQlODQlRUIlOUYlQUMlMjAlRUIlQjYlODglRUIlOUYlQUMlRUMlOTglQTQlRUElQjglQjAlMEFkZGltJTIwJTNEJTIwRERJTVBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCklMEFkZGltLnRvKCUyMmN1ZGElMjIpJTBBJTBBJTIzJUVDJTlFJUFDJUVEJTk4JTg0JUVDJTg0JUIxJUVDJTlEJTg0JTIwJUVDJTlDJTg0JUVEJTk1JTlDJTIwZ2VuZXJhdG9yJTIwJUVCJUE3JThDJUVCJTkzJUE0JUVBJUI4JUIwJTIwKEdQVSVFQyU5NyU5MCUyMCVFQyU5OCVBQyVFQiVBNiVBQyVFQyVBNyU4MCUyMCVFQyU5NSU4QSVFQiU4RiU4NCVFQiVBMSU5RCUyMCVFQyVBMSVCMCVFQyU4QiVBQyVFRCU5NSU5QyVFQiU4QiVBNCEpJTBBZ2VuZXJhdG9yJTIwJTNEJTIwdG9yY2gubWFudWFsX3NlZWQoMCklMEElMEElMjMlMjAlRUIlOTElOTAlMjAlRUElQjAlOUMlRUMlOUQlOTglMjAlRUIlOEIlQTglRUElQjMlODQlRUMlOTclOTAlMjAlRUIlOEMlODAlRUQlOTUlQjQlRUMlODQlOUMlMjAlRUQlOEMlOEMlRUMlOUQlQjQlRUQlOTQlODQlRUIlOUQlQkMlRUMlOUQlQjglRUMlOUQlODQlMjAlRUMlOEIlQTQlRUQlOTYlODklRUQlOTUlOTglRUElQjMlQTAlMjBudW1weSUyMHRlbnNvciVFQiVBMSU5QyUyMCVFQSVCMCU5MiVFQyU5RCU4NCUyMCVFQiVCMCU5OCVFRCU5OSU5OCVFRCU5NSU5OCVFQSVCOCVCMCUwQWltYWdlJTIwJTNEJTIwZGRpbShudW1faW5mZXJlbmNlX3N0ZXBzJTNEMiUyQyUyMG91dHB1dF90eXBlJTNEJTIybnAlMjIlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IpLmltYWdlcyUwQXByaW50KG5wLmFicyhpbWFnZSkuc3VtKCkp",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"># 모델과 스케줄러 불러오기</span>
ddim = DDIMPipeline.from_pretrained(model_id)
ddim.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-comment">#재현성을 위한 generator 만들기 (GPU에 올리지 않도록 조심한다!)</span>
generator = torch.manual_seed(<span class="hljs-number">0</span>)

<span class="hljs-comment"># 두 개의 단계에 대해서 파이프라인을 실행하고 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>())`,wrap:!1}}),V=new Dl({props:{$$slots:{default:[ye]},$$scope:{ctx:w}}}),H=new sl({props:{title:"결정론적 알고리즘",local:"결정론적-알고리즘",headingTag:"h2"}}),Y=new el({props:{code:"aW1wb3J0JTIwb3MlMEElMEFvcy5lbnZpcm9uJTVCJTIyQ1VCTEFTX1dPUktTUEFDRV9DT05GSUclMjIlNUQlMjAlM0QlMjAlMjIlM0ExNiUzQTglMjIlMEElMEF0b3JjaC5iYWNrZW5kcy5jdWRubi5iZW5jaG1hcmslMjAlM0QlMjBGYWxzZSUwQXRvcmNoLnVzZV9kZXRlcm1pbmlzdGljX2FsZ29yaXRobXMoVHJ1ZSk=",highlighted:`<span class="hljs-keyword">import</span> os

os.environ[<span class="hljs-string">&quot;CUBLAS_WORKSPACE_CONFIG&quot;</span>] = <span class="hljs-string">&quot;:16:8&quot;</span>

torch.backends.cudnn.benchmark = <span class="hljs-literal">False</span>
torch.use_deterministic_algorithms(<span class="hljs-literal">True</span>)`,wrap:!1}}),ll=new el({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVNjaGVkdWxlciUyQyUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBaW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUwQXBpcGUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQpLnRvKCUyMmN1ZGElMjIpJTBBcGlwZS5zY2hlZHVsZXIlMjAlM0QlMjBERElNU2NoZWR1bGVyLmZyb21fY29uZmlnKHBpcGUuc2NoZWR1bGVyLmNvbmZpZyklMEFnJTIwJTNEJTIwdG9yY2guR2VuZXJhdG9yKGRldmljZSUzRCUyMmN1ZGElMjIpJTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyQSUyMGJlYXIlMjBpcyUyMHBsYXlpbmclMjBhJTIwZ3VpdGFyJTIwb24lMjBUaW1lcyUyMFNxdWFyZSUyMiUwQSUwQWcubWFudWFsX3NlZWQoMCklMEFyZXN1bHQxJTIwJTNEJTIwcGlwZShwcm9tcHQlM0Rwcm9tcHQlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNENTAlMkMlMjBnZW5lcmF0b3IlM0RnJTJDJTIwb3V0cHV0X3R5cGUlM0QlMjJsYXRlbnQlMjIpLmltYWdlcyUwQSUwQWcubWFudWFsX3NlZWQoMCklMEFyZXN1bHQyJTIwJTNEJTIwcGlwZShwcm9tcHQlM0Rwcm9tcHQlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNENTAlMkMlMjBnZW5lcmF0b3IlM0RnJTJDJTIwb3V0cHV0X3R5cGUlM0QlMjJsYXRlbnQlMjIpLmltYWdlcyUwQSUwQXByaW50KCUyMkxfaW5mJTIwZGlzdCUyMCUzRCUyMCUyMiUyQyUyMGFicyhyZXN1bHQxJTIwLSUyMHJlc3VsdDIpLm1heCgpKSUwQSUyMkxfaW5mJTIwZGlzdCUyMCUzRCUyMCUyMHRlbnNvcigwLiUyQyUyMGRldmljZSUzRCdjdWRhJTNBMCcpJTIy",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, StableDiffusionPipeline
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

model_id = <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>
pipe = StableDiffusionPipeline.from_pretrained(model_id).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}}),{c(){p=J("meta"),y=n(),o=J("p"),T=n(),r(j.$$.fragment),f=n(),r(Q.$$.fragment),nl=n(),C=J("p"),C.innerHTML=Ol,al=n(),g=J("p"),g.textContent=vl,pl=n(),r(h.$$.fragment),Jl=n(),r(I.$$.fragment),il=n(),E=J("p"),E.textContent=Nl,Ul=n(),R=J("p"),R.innerHTML=xl,ol=n(),r(k.$$.fragment),Tl=n(),Z=J("p"),Z.textContent=Pl,rl=n(),B=J("p"),B.innerHTML=Sl,Ml=n(),$=J("p"),$.textContent=Al,ml=n(),r(W.$$.fragment),cl=n(),_=J("p"),_.innerHTML=Xl,ul=n(),r(G.$$.fragment),dl=n(),D=J("p"),D.innerHTML=Hl,fl=n(),F=J("p"),F.textContent=zl,yl=n(),r(b.$$.fragment),Ql=n(),r(O.$$.fragment),jl=n(),v=J("p"),v.textContent=Ll,wl=n(),r(N.$$.fragment),hl=n(),x=J("p"),x.textContent=ql,bl=n(),P=J("p"),P.innerHTML=Yl,Vl=n(),S=J("p"),S.textContent=Kl,Cl=n(),r(A.$$.fragment),gl=n(),r(V.$$.fragment),Il=n(),X=J("p"),X.innerHTML=le,El=n(),r(H.$$.fragment),Rl=n(),z=J("p"),z.textContent=ee,kl=n(),L=J("p"),L.innerHTML=te,Zl=n(),q=J("p"),q.innerHTML=se,Bl=n(),r(Y.$$.fragment),$l=n(),K=J("p"),K.textContent=ne,Wl=n(),r(ll.$$.fragment),_l=n(),tl=J("p"),this.h()},l(l){const e=me("svelte-u9bgzb",document.head);p=i(e,"META",{name:!0,content:!0}),e.forEach(t),y=a(l),o=i(l,"P",{}),ie(o).forEach(t),T=a(l),M(j.$$.fragment,l),f=a(l),M(Q.$$.fragment,l),nl=a(l),C=i(l,"P",{"data-svelte-h":!0}),U(C)!=="svelte-1jbr77x"&&(C.innerHTML=Ol),al=a(l),g=i(l,"P",{"data-svelte-h":!0}),U(g)!=="svelte-hcwx4f"&&(g.textContent=vl),pl=a(l),M(h.$$.fragment,l),Jl=a(l),M(I.$$.fragment,l),il=a(l),E=i(l,"P",{"data-svelte-h":!0}),U(E)!=="svelte-rovd75"&&(E.textContent=Nl),Ul=a(l),R=i(l,"P",{"data-svelte-h":!0}),U(R)!=="svelte-1oq8xcu"&&(R.innerHTML=xl),ol=a(l),M(k.$$.fragment,l),Tl=a(l),Z=i(l,"P",{"data-svelte-h":!0}),U(Z)!=="svelte-zj7eo2"&&(Z.textContent=Pl),rl=a(l),B=i(l,"P",{"data-svelte-h":!0}),U(B)!=="svelte-znzen0"&&(B.innerHTML=Sl),Ml=a(l),$=i(l,"P",{"data-svelte-h":!0}),U($)!=="svelte-tun6p5"&&($.textContent=Al),ml=a(l),M(W.$$.fragment,l),cl=a(l),_=i(l,"P",{"data-svelte-h":!0}),U(_)!=="svelte-1ozlo3o"&&(_.innerHTML=Xl),ul=a(l),M(G.$$.fragment,l),dl=a(l),D=i(l,"P",{"data-svelte-h":!0}),U(D)!=="svelte-1fjfua9"&&(D.innerHTML=Hl),fl=a(l),F=i(l,"P",{"data-svelte-h":!0}),U(F)!=="svelte-j3qgnm"&&(F.textContent=zl),yl=a(l),M(b.$$.fragment,l),Ql=a(l),M(O.$$.fragment,l),jl=a(l),v=i(l,"P",{"data-svelte-h":!0}),U(v)!=="svelte-1cafmef"&&(v.textContent=Ll),wl=a(l),M(N.$$.fragment,l),hl=a(l),x=i(l,"P",{"data-svelte-h":!0}),U(x)!=="svelte-141n7wf"&&(x.textContent=ql),bl=a(l),P=i(l,"P",{"data-svelte-h":!0}),U(P)!=="svelte-7f5ryc"&&(P.innerHTML=Yl),Vl=a(l),S=i(l,"P",{"data-svelte-h":!0}),U(S)!=="svelte-1xwk1mu"&&(S.textContent=Kl),Cl=a(l),M(A.$$.fragment,l),gl=a(l),M(V.$$.fragment,l),Il=a(l),X=i(l,"P",{"data-svelte-h":!0}),U(X)!=="svelte-1evdu50"&&(X.innerHTML=le),El=a(l),M(H.$$.fragment,l),Rl=a(l),z=i(l,"P",{"data-svelte-h":!0}),U(z)!=="svelte-124dlbu"&&(z.textContent=ee),kl=a(l),L=i(l,"P",{"data-svelte-h":!0}),U(L)!=="svelte-1pjtl3n"&&(L.innerHTML=te),Zl=a(l),q=i(l,"P",{"data-svelte-h":!0}),U(q)!=="svelte-wj31jr"&&(q.innerHTML=se),Bl=a(l),M(Y.$$.fragment,l),$l=a(l),K=i(l,"P",{"data-svelte-h":!0}),U(K)!=="svelte-uyrq4d"&&(K.textContent=ne),Wl=a(l),M(ll.$$.fragment,l),_l=a(l),tl=i(l,"P",{}),ie(tl).forEach(t),this.h()},h(){Ue(p,"name","hf:doc:metadata"),Ue(p,"content",je)},m(l,e){ce(document.head,p),s(l,y,e),s(l,o,e),s(l,T,e),m(j,l,e),s(l,f,e),m(Q,l,e),s(l,nl,e),s(l,C,e),s(l,al,e),s(l,g,e),s(l,pl,e),m(h,l,e),s(l,Jl,e),m(I,l,e),s(l,il,e),s(l,E,e),s(l,Ul,e),s(l,R,e),s(l,ol,e),m(k,l,e),s(l,Tl,e),s(l,Z,e),s(l,rl,e),s(l,B,e),s(l,Ml,e),s(l,$,e),s(l,ml,e),m(W,l,e),s(l,cl,e),s(l,_,e),s(l,ul,e),m(G,l,e),s(l,dl,e),s(l,D,e),s(l,fl,e),s(l,F,e),s(l,yl,e),m(b,l,e),s(l,Ql,e),m(O,l,e),s(l,jl,e),s(l,v,e),s(l,wl,e),m(N,l,e),s(l,hl,e),s(l,x,e),s(l,bl,e),s(l,P,e),s(l,Vl,e),s(l,S,e),s(l,Cl,e),m(A,l,e),s(l,gl,e),m(V,l,e),s(l,Il,e),s(l,X,e),s(l,El,e),m(H,l,e),s(l,Rl,e),s(l,z,e),s(l,kl,e),s(l,L,e),s(l,Zl,e),s(l,q,e),s(l,Bl,e),m(Y,l,e),s(l,$l,e),s(l,K,e),s(l,Wl,e),m(ll,l,e),s(l,_l,e),s(l,tl,e),Gl=!0},p(l,[e]){const ae={};e&2&&(ae.$$scope={dirty:e,ctx:l}),h.$set(ae);const pe={};e&2&&(pe.$$scope={dirty:e,ctx:l}),b.$set(pe);const Je={};e&2&&(Je.$$scope={dirty:e,ctx:l}),V.$set(Je)},i(l){Gl||(c(j.$$.fragment,l),c(Q.$$.fragment,l),c(h.$$.fragment,l),c(I.$$.fragment,l),c(k.$$.fragment,l),c(W.$$.fragment,l),c(G.$$.fragment,l),c(b.$$.fragment,l),c(O.$$.fragment,l),c(N.$$.fragment,l),c(A.$$.fragment,l),c(V.$$.fragment,l),c(H.$$.fragment,l),c(Y.$$.fragment,l),c(ll.$$.fragment,l),Gl=!0)},o(l){u(j.$$.fragment,l),u(Q.$$.fragment,l),u(h.$$.fragment,l),u(I.$$.fragment,l),u(k.$$.fragment,l),u(W.$$.fragment,l),u(G.$$.fragment,l),u(b.$$.fragment,l),u(O.$$.fragment,l),u(N.$$.fragment,l),u(A.$$.fragment,l),u(V.$$.fragment,l),u(H.$$.fragment,l),u(Y.$$.fragment,l),u(ll.$$.fragment,l),Gl=!1},d(l){l&&(t(y),t(o),t(T),t(f),t(nl),t(C),t(al),t(g),t(pl),t(Jl),t(il),t(E),t(Ul),t(R),t(ol),t(Tl),t(Z),t(rl),t(B),t(Ml),t($),t(ml),t(cl),t(_),t(ul),t(dl),t(D),t(fl),t(F),t(yl),t(Ql),t(jl),t(v),t(wl),t(hl),t(x),t(bl),t(P),t(Vl),t(S),t(Cl),t(gl),t(Il),t(X),t(El),t(Rl),t(z),t(kl),t(L),t(Zl),t(q),t(Bl),t($l),t(K),t(Wl),t(_l),t(tl)),t(p),d(j,l),d(Q,l),d(h,l),d(I,l),d(k,l),d(W,l),d(G,l),d(b,l),d(O,l),d(N,l),d(A,l),d(V,l),d(H,l),d(Y,l),d(ll,l)}}}const je='{"title":"재현 가능한 파이프라인 생성하기","local":"재현-가능한-파이프라인-생성하기","sections":[{"title":"무작위성 제어하기","local":"무작위성-제어하기","sections":[{"title":"CPU","local":"cpu","sections":[],"depth":3},{"title":"GPU","local":"gpu","sections":[],"depth":3}],"depth":2},{"title":"결정론적 알고리즘","local":"결정론적-알고리즘","sections":[],"depth":2}],"depth":1}';function we(w){return Te(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ee extends re{constructor(p){super(),Me(this,p,we,Qe,oe,{})}}export{Ee as component};
