import{s as ot,o as Tt,n as Fl}from"../chunks/scheduler.6e0d5ff7.js";import{S as rt,i as Mt,g as J,s as n,r,E as mt,h as i,f as e,c as a,j as it,u as M,x as U,k as Ut,y as ct,a as s,v as m,d as c,t as u,w as d}from"../chunks/index.d7c1b260.js";import{H as sl,g as ut}from"../chunks/Heading.2be73954.js";import{T as Dl}from"../chunks/Tip.c000e27b.js";import{C as tl}from"../chunks/CodeBlock.09a08494.js";import{D as dt}from"../chunks/DocNotebookDropdown.0647ce65.js";function ft(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&&(e(p),e(o),e(T))}}}function yt(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&&e(p)}}}function Qt(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&&e(p)}}}function jt(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,lt=`마지막으로 <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,tt=`결정론적 알고리즘을 사용하여 재현 가능한 파이프라인을 생성하도록 PyTorch를 구성할 수도 있습니다.
그러나 결정론적 알고리즘은 비결정론적 알고리즘보다 느리고 성능이 저하될 수 있습니다.
하지만 재현성이 중요하다면, 이것이 최선의 방법입니다!`,kl,L,et=`둘 이상의 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,st=`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,nt="이제 동일한 파이프라인을 두번 실행하면 동일한 결과를 얻을 수 있습니다.",Wl,ll,_l,el,Gl;return j=new sl({props:{title:"재현 가능한 파이프라인 생성하기",local:"재현-가능한-파이프라인-생성하기",headingTag:"h1"}}),Q=new dt({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:[ft]},$$scope:{ctx:w}}}),I=new sl({props:{title:"무작위성 제어하기",local:"무작위성-제어하기",headingTag:"h2"}}),k=new tl({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 tl({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:[yt]},$$scope:{ctx:w}}}),O=new sl({props:{title:"GPU",local:"gpu",headingTag:"h3"}}),N=new tl({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 tl({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:[Qt]},$$scope:{ctx:w}}}),H=new sl({props:{title:"결정론적 알고리즘",local:"결정론적-알고리즘",headingTag:"h2"}}),Y=new tl({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 tl({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=lt,El=n(),r(H.$$.fragment),Rl=n(),z=J("p"),z.textContent=tt,kl=n(),L=J("p"),L.innerHTML=et,Zl=n(),q=J("p"),q.innerHTML=st,Bl=n(),r(Y.$$.fragment),$l=n(),K=J("p"),K.textContent=nt,Wl=n(),r(ll.$$.fragment),_l=n(),el=J("p"),this.h()},l(l){const t=mt("svelte-u9bgzb",document.head);p=i(t,"META",{name:!0,content:!0}),t.forEach(e),y=a(l),o=i(l,"P",{}),it(o).forEach(e),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=lt),El=a(l),M(H.$$.fragment,l),Rl=a(l),z=i(l,"P",{"data-svelte-h":!0}),U(z)!=="svelte-124dlbu"&&(z.textContent=tt),kl=a(l),L=i(l,"P",{"data-svelte-h":!0}),U(L)!=="svelte-1pjtl3n"&&(L.innerHTML=et),Zl=a(l),q=i(l,"P",{"data-svelte-h":!0}),U(q)!=="svelte-wj31jr"&&(q.innerHTML=st),Bl=a(l),M(Y.$$.fragment,l),$l=a(l),K=i(l,"P",{"data-svelte-h":!0}),U(K)!=="svelte-uyrq4d"&&(K.textContent=nt),Wl=a(l),M(ll.$$.fragment,l),_l=a(l),el=i(l,"P",{}),it(el).forEach(e),this.h()},h(){Ut(p,"name","hf:doc:metadata"),Ut(p,"content",wt)},m(l,t){ct(document.head,p),s(l,y,t),s(l,o,t),s(l,T,t),m(j,l,t),s(l,f,t),m(Q,l,t),s(l,nl,t),s(l,C,t),s(l,al,t),s(l,g,t),s(l,pl,t),m(h,l,t),s(l,Jl,t),m(I,l,t),s(l,il,t),s(l,E,t),s(l,Ul,t),s(l,R,t),s(l,ol,t),m(k,l,t),s(l,Tl,t),s(l,Z,t),s(l,rl,t),s(l,B,t),s(l,Ml,t),s(l,$,t),s(l,ml,t),m(W,l,t),s(l,cl,t),s(l,_,t),s(l,ul,t),m(G,l,t),s(l,dl,t),s(l,D,t),s(l,fl,t),s(l,F,t),s(l,yl,t),m(b,l,t),s(l,Ql,t),m(O,l,t),s(l,jl,t),s(l,v,t),s(l,wl,t),m(N,l,t),s(l,hl,t),s(l,x,t),s(l,bl,t),s(l,P,t),s(l,Vl,t),s(l,S,t),s(l,Cl,t),m(A,l,t),s(l,gl,t),m(V,l,t),s(l,Il,t),s(l,X,t),s(l,El,t),m(H,l,t),s(l,Rl,t),s(l,z,t),s(l,kl,t),s(l,L,t),s(l,Zl,t),s(l,q,t),s(l,Bl,t),m(Y,l,t),s(l,$l,t),s(l,K,t),s(l,Wl,t),m(ll,l,t),s(l,_l,t),s(l,el,t),Gl=!0},p(l,[t]){const at={};t&2&&(at.$$scope={dirty:t,ctx:l}),h.$set(at);const pt={};t&2&&(pt.$$scope={dirty:t,ctx:l}),b.$set(pt);const Jt={};t&2&&(Jt.$$scope={dirty:t,ctx:l}),V.$set(Jt)},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&&(e(y),e(o),e(T),e(f),e(nl),e(C),e(al),e(g),e(pl),e(Jl),e(il),e(E),e(Ul),e(R),e(ol),e(Tl),e(Z),e(rl),e(B),e(Ml),e($),e(ml),e(cl),e(_),e(ul),e(dl),e(D),e(fl),e(F),e(yl),e(Ql),e(jl),e(v),e(wl),e(hl),e(x),e(bl),e(P),e(Vl),e(S),e(Cl),e(gl),e(Il),e(X),e(El),e(Rl),e(z),e(kl),e(L),e(Zl),e(q),e(Bl),e($l),e(K),e(Wl),e(_l),e(el)),e(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 wt='{"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 ht(w){return Tt(()=>{new URLSearchParams(window.location.search).get("fw"),window.hfDocGoto=ut}),[]}class Rt extends rt{constructor(p){super(),Mt(this,p,ht,jt,ot,{})}}export{Rt as component};
