import{s as Te,o as me,n as vl}from"../chunks/scheduler.e3739aa0.js";import{S as Me,i as ue,g as i,s as n,r as T,E as ce,h as J,f as t,c as a,j as oe,u as m,x as U,k as re,y as de,a as s,v as M,d as u,t as c,w as d}from"../chunks/index.13f5b837.js";import{T as Ol}from"../chunks/Tip.51dedfeb.js";import{C as tl}from"../chunks/CodeBlock.de02009a.js";import{D as fe}from"../chunks/DocNotebookDropdown.5cbf7847.js";import{H as nl,E as ye}from"../chunks/EditOnGithub.72bac8d8.js";function Qe(w){let p,y='💡 Pytorch의 <a href="https://pytorch.org/docs/stable/notes/randomness.html" rel="nofollow">재현성에 대한 선언</a>를 꼭 읽어보길 추천합니다:',o,r,j=`<p>완전하게 재현가능한 결과는 Pytorch 배포, 개별적인 커밋, 혹은 다른 플랫폼들에서 보장되지 않습니다.
또한, 결과는 CPU와 GPU 실행간에 심지어 같은 seed를 사용할 때도 재현 가능하지 않을 수 있습니다.</p>`;return{c(){p=i("p"),p.innerHTML=y,o=n(),r=i("blockquote"),r.innerHTML=j},l(f){p=J(f,"P",{"data-svelte-h":!0}),U(p)!=="svelte-3yn5i4"&&(p.innerHTML=y),o=a(f),r=J(f,"BLOCKQUOTE",{"data-svelte-h":!0}),U(r)!=="svelte-va9th1"&&(r.innerHTML=j)},m(f,Q){s(f,p,Q),s(f,o,Q),s(f,r,Q)},p:vl,d(f){f&&(t(p),t(o),t(r))}}}function je(w){let p,y=`💡 처음에는 시드를 나타내는 정수값 대신에 <code>Generator</code> 개체를 파이프라인에 전달하는 것이 약간 비직관적일 수 있지만,
<code>Generator</code>는 순차적으로 여러 파이프라인에 전달될 수 있는 \\랜덤상태\\이기 때문에 PyTorch에서 확률론적 모델을 다룰 때 권장되는 설계입니다.`;return{c(){p=i("p"),p.innerHTML=y},l(o){p=J(o,"P",{"data-svelte-h":!0}),U(p)!=="svelte-8pt0v2"&&(p.innerHTML=y)},m(o,r){s(o,p,r)},p:vl,d(o){o&&t(p)}}}function we(w){let p,y=`💡 재현성이 중요한 경우에는 항상 CPU generator를 전달하는 것이 좋습니다.
성능 손실은 무시할 수 없는 경우가 많으며 파이프라인이 GPU에서 실행되었을 때보다 훨씬 더 비슷한 값을 생성할 수 있습니다.`;return{c(){p=i("p"),p.textContent=y},l(o){p=J(o,"P",{"data-svelte-h":!0}),U(p)!=="svelte-784xbp"&&(p.textContent=y)},m(o,r){s(o,p,r)},p:vl,d(o){o&&t(p)}}}function he(w){let p,y,o,r,j,f,Q,al,g,Nl=`재현성은 테스트, 결과 재현, 그리고 <a href="resuing_seeds">이미지 퀄리티 높이기</a>에서 중요합니다.
그러나 diffusion 모델의 무작위성은 매번 모델이 돌아갈 때마다 파이프라인이 다른 이미지를 생성할 수 있도록 하는 이유로 필요합니다.
플랫폼 간에 정확하게 동일한 결과를 얻을 수는 없지만, 특정 허용 범위 내에서 릴리스 및 플랫폼 간에 결과를 재현할 수는 있습니다.
그럼에도 diffusion 파이프라인과 체크포인트에 따라 허용 오차가 달라집니다.`,pl,C,xl="diffusion 모델에서 무작위성의 원천을 제어하거나 결정론적 알고리즘을 사용하는 방법을 이해하는 것이 중요한 이유입니다.",il,h,Jl,I,Ul,E,Pl="추론에서, 파이프라인은 노이즈를 줄이기 위해 가우시안 노이즈를 생성하거나 스케줄링 단계에 노이즈를 더하는 등의 랜덤 샘플링 실행에 크게 의존합니다,",ol,R,Sl='<a href="https://huggingface.co/docs/diffusers/v0.18.0/en/api/pipelines/ddim#diffusers.DDIMPipeline" rel="nofollow">DDIMPipeline</a>에서 두 추론 단계 이후의 텐서 값을 살펴보세요:',rl,k,Tl,Z,Al="위의 코드를 실행하면 하나의 값이 나오지만, 다시 실행하면 다른 값이 나옵니다. 무슨 일이 일어나고 있는 걸까요?",ml,$,Xl=`파이프라인이 실행될 때마다, <a href="https://pytorch.org/docs/stable/generated/torch.randn.html" rel="nofollow">torch.randn</a>은
단계적으로 노이즈 제거되는 가우시안 노이즈가 생성하기 위한 다른 랜덤 seed를 사용합니다.`,Ml,B,Hl="그러나 동일한 이미지를 안정적으로 생성해야 하는 경우에는 CPU에서 파이프라인을 실행하는지 GPU에서 실행하는지에 따라 달라집니다.",ul,W,cl,_,zl='CPU에서 재현 가능한 결과를 생성하려면, PyTorch <a href="https://pytorch.org/docs/stable/generated/torch.randn.html" rel="nofollow">Generator</a>로 seed를 고정합니다:',dl,G,fl,D,Ll="이제 위의 코드를 실행하면 seed를 가진 <code>Generator</code> 객체가 파이프라인의 모든 랜덤 함수에 전달되므로 항상 <code>1491.1711</code> 값이 출력됩니다.",yl,F,ql="특정 하드웨어 및 PyTorch 버전에서 이 코드 예제를 실행하면 동일하지는 않더라도 유사한 결과를 얻을 수 있습니다.",Ql,b,jl,O,wl,v,Yl="예를 들면, GPU 상에서 같은 코드 예시를 실행하면:",hl,N,bl,x,Kl="GPU가 CPU와 다른 난수 생성기를 사용하기 때문에 동일한 시드를 사용하더라도 결과가 같지 않습니다.",Vl,P,le=`이 문제를 피하기 위해 🧨 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>를 통과할 수 있습니다.`,gl,S,ee="이제 결과에 훨씬 더 다가왔습니다!",Cl,A,Il,V,El,X,te=`마지막으로 <a href="https://huggingface.co/docs/diffusers/v0.18.0/en/api/pipelines/unclip#diffusers.UnCLIPPipeline" rel="nofollow">UnCLIPPipeline</a>과 같은
더 복잡한 파이프라인의 경우, 이들은 종종 정밀 오차 전파에 극도로 취약합니다.
다른 GPU 하드웨어 또는 PyTorch 버전에서 유사한 결과를 기대하지 마세요.
이 경우 완전한 재현성을 위해 완전히 동일한 하드웨어 및 PyTorch 버전을 실행해야 합니다.`,Rl,H,kl,z,se=`결정론적 알고리즘을 사용하여 재현 가능한 파이프라인을 생성하도록 PyTorch를 구성할 수도 있습니다.
그러나 결정론적 알고리즘은 비결정론적 알고리즘보다 느리고 성능이 저하될 수 있습니다.
하지만 재현성이 중요하다면, 이것이 최선의 방법입니다!`,Zl,L,ne=`둘 이상의 CUDA 스트림에서 작업이 시작될 때 비결정론적 동작이 발생합니다.
이 문제를 방지하려면 환경 변수 <a href="https://docs.nvidia.com/cuda/cublas/index.html#results-reproducibility" rel="nofollow">CUBLAS_WORKSPACE_CONFIG</a>를 <code>:16:8</code>로 설정해서
런타임 중에 오직 하나의 버퍼 크리만 사용하도록 설정합니다.`,$l,q,ae=`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,Wl,K,pe="이제 동일한 파이프라인을 두번 실행하면 동일한 결과를 얻을 수 있습니다.",_l,ll,Gl,el,Dl,sl,Fl;return j=new nl({props:{title:"재현 가능한 파이프라인 생성하기",local:"재현-가능한-파이프라인-생성하기",headingTag:"h1"}}),Q=new fe({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 Ol({props:{$$slots:{default:[Qe]},$$scope:{ctx:w}}}),I=new nl({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 nl({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 Ol({props:{$$slots:{default:[je]},$$scope:{ctx:w}}}),O=new nl({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 Ol({props:{$$slots:{default:[we]},$$scope:{ctx:w}}}),H=new nl({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}}),el=new ye({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/ko/using-diffusers/reproducibility.md"}}),{c(){p=i("meta"),y=n(),o=i("p"),r=n(),T(j.$$.fragment),f=n(),T(Q.$$.fragment),al=n(),g=i("p"),g.innerHTML=Nl,pl=n(),C=i("p"),C.textContent=xl,il=n(),T(h.$$.fragment),Jl=n(),T(I.$$.fragment),Ul=n(),E=i("p"),E.textContent=Pl,ol=n(),R=i("p"),R.innerHTML=Sl,rl=n(),T(k.$$.fragment),Tl=n(),Z=i("p"),Z.textContent=Al,ml=n(),$=i("p"),$.innerHTML=Xl,Ml=n(),B=i("p"),B.textContent=Hl,ul=n(),T(W.$$.fragment),cl=n(),_=i("p"),_.innerHTML=zl,dl=n(),T(G.$$.fragment),fl=n(),D=i("p"),D.innerHTML=Ll,yl=n(),F=i("p"),F.textContent=ql,Ql=n(),T(b.$$.fragment),jl=n(),T(O.$$.fragment),wl=n(),v=i("p"),v.textContent=Yl,hl=n(),T(N.$$.fragment),bl=n(),x=i("p"),x.textContent=Kl,Vl=n(),P=i("p"),P.innerHTML=le,gl=n(),S=i("p"),S.textContent=ee,Cl=n(),T(A.$$.fragment),Il=n(),T(V.$$.fragment),El=n(),X=i("p"),X.innerHTML=te,Rl=n(),T(H.$$.fragment),kl=n(),z=i("p"),z.textContent=se,Zl=n(),L=i("p"),L.innerHTML=ne,$l=n(),q=i("p"),q.innerHTML=ae,Bl=n(),T(Y.$$.fragment),Wl=n(),K=i("p"),K.textContent=pe,_l=n(),T(ll.$$.fragment),Gl=n(),T(el.$$.fragment),Dl=n(),sl=i("p"),this.h()},l(l){const e=ce("svelte-u9bgzb",document.head);p=J(e,"META",{name:!0,content:!0}),e.forEach(t),y=a(l),o=J(l,"P",{}),oe(o).forEach(t),r=a(l),m(j.$$.fragment,l),f=a(l),m(Q.$$.fragment,l),al=a(l),g=J(l,"P",{"data-svelte-h":!0}),U(g)!=="svelte-1jbr77x"&&(g.innerHTML=Nl),pl=a(l),C=J(l,"P",{"data-svelte-h":!0}),U(C)!=="svelte-hcwx4f"&&(C.textContent=xl),il=a(l),m(h.$$.fragment,l),Jl=a(l),m(I.$$.fragment,l),Ul=a(l),E=J(l,"P",{"data-svelte-h":!0}),U(E)!=="svelte-rovd75"&&(E.textContent=Pl),ol=a(l),R=J(l,"P",{"data-svelte-h":!0}),U(R)!=="svelte-1oq8xcu"&&(R.innerHTML=Sl),rl=a(l),m(k.$$.fragment,l),Tl=a(l),Z=J(l,"P",{"data-svelte-h":!0}),U(Z)!=="svelte-zj7eo2"&&(Z.textContent=Al),ml=a(l),$=J(l,"P",{"data-svelte-h":!0}),U($)!=="svelte-znzen0"&&($.innerHTML=Xl),Ml=a(l),B=J(l,"P",{"data-svelte-h":!0}),U(B)!=="svelte-tun6p5"&&(B.textContent=Hl),ul=a(l),m(W.$$.fragment,l),cl=a(l),_=J(l,"P",{"data-svelte-h":!0}),U(_)!=="svelte-1ozlo3o"&&(_.innerHTML=zl),dl=a(l),m(G.$$.fragment,l),fl=a(l),D=J(l,"P",{"data-svelte-h":!0}),U(D)!=="svelte-1fjfua9"&&(D.innerHTML=Ll),yl=a(l),F=J(l,"P",{"data-svelte-h":!0}),U(F)!=="svelte-j3qgnm"&&(F.textContent=ql),Ql=a(l),m(b.$$.fragment,l),jl=a(l),m(O.$$.fragment,l),wl=a(l),v=J(l,"P",{"data-svelte-h":!0}),U(v)!=="svelte-1cafmef"&&(v.textContent=Yl),hl=a(l),m(N.$$.fragment,l),bl=a(l),x=J(l,"P",{"data-svelte-h":!0}),U(x)!=="svelte-141n7wf"&&(x.textContent=Kl),Vl=a(l),P=J(l,"P",{"data-svelte-h":!0}),U(P)!=="svelte-7f5ryc"&&(P.innerHTML=le),gl=a(l),S=J(l,"P",{"data-svelte-h":!0}),U(S)!=="svelte-1xwk1mu"&&(S.textContent=ee),Cl=a(l),m(A.$$.fragment,l),Il=a(l),m(V.$$.fragment,l),El=a(l),X=J(l,"P",{"data-svelte-h":!0}),U(X)!=="svelte-1evdu50"&&(X.innerHTML=te),Rl=a(l),m(H.$$.fragment,l),kl=a(l),z=J(l,"P",{"data-svelte-h":!0}),U(z)!=="svelte-124dlbu"&&(z.textContent=se),Zl=a(l),L=J(l,"P",{"data-svelte-h":!0}),U(L)!=="svelte-1pjtl3n"&&(L.innerHTML=ne),$l=a(l),q=J(l,"P",{"data-svelte-h":!0}),U(q)!=="svelte-wj31jr"&&(q.innerHTML=ae),Bl=a(l),m(Y.$$.fragment,l),Wl=a(l),K=J(l,"P",{"data-svelte-h":!0}),U(K)!=="svelte-uyrq4d"&&(K.textContent=pe),_l=a(l),m(ll.$$.fragment,l),Gl=a(l),m(el.$$.fragment,l),Dl=a(l),sl=J(l,"P",{}),oe(sl).forEach(t),this.h()},h(){re(p,"name","hf:doc:metadata"),re(p,"content",be)},m(l,e){de(document.head,p),s(l,y,e),s(l,o,e),s(l,r,e),M(j,l,e),s(l,f,e),M(Q,l,e),s(l,al,e),s(l,g,e),s(l,pl,e),s(l,C,e),s(l,il,e),M(h,l,e),s(l,Jl,e),M(I,l,e),s(l,Ul,e),s(l,E,e),s(l,ol,e),s(l,R,e),s(l,rl,e),M(k,l,e),s(l,Tl,e),s(l,Z,e),s(l,ml,e),s(l,$,e),s(l,Ml,e),s(l,B,e),s(l,ul,e),M(W,l,e),s(l,cl,e),s(l,_,e),s(l,dl,e),M(G,l,e),s(l,fl,e),s(l,D,e),s(l,yl,e),s(l,F,e),s(l,Ql,e),M(b,l,e),s(l,jl,e),M(O,l,e),s(l,wl,e),s(l,v,e),s(l,hl,e),M(N,l,e),s(l,bl,e),s(l,x,e),s(l,Vl,e),s(l,P,e),s(l,gl,e),s(l,S,e),s(l,Cl,e),M(A,l,e),s(l,Il,e),M(V,l,e),s(l,El,e),s(l,X,e),s(l,Rl,e),M(H,l,e),s(l,kl,e),s(l,z,e),s(l,Zl,e),s(l,L,e),s(l,$l,e),s(l,q,e),s(l,Bl,e),M(Y,l,e),s(l,Wl,e),s(l,K,e),s(l,_l,e),M(ll,l,e),s(l,Gl,e),M(el,l,e),s(l,Dl,e),s(l,sl,e),Fl=!0},p(l,[e]){const ie={};e&2&&(ie.$$scope={dirty:e,ctx:l}),h.$set(ie);const Je={};e&2&&(Je.$$scope={dirty:e,ctx:l}),b.$set(Je);const Ue={};e&2&&(Ue.$$scope={dirty:e,ctx:l}),V.$set(Ue)},i(l){Fl||(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),u(el.$$.fragment,l),Fl=!0)},o(l){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),c(el.$$.fragment,l),Fl=!1},d(l){l&&(t(y),t(o),t(r),t(f),t(al),t(g),t(pl),t(C),t(il),t(Jl),t(Ul),t(E),t(ol),t(R),t(rl),t(Tl),t(Z),t(ml),t($),t(Ml),t(B),t(ul),t(cl),t(_),t(dl),t(fl),t(D),t(yl),t(F),t(Ql),t(jl),t(wl),t(v),t(hl),t(bl),t(x),t(Vl),t(P),t(gl),t(S),t(Cl),t(Il),t(El),t(X),t(Rl),t(kl),t(z),t(Zl),t(L),t($l),t(q),t(Bl),t(Wl),t(K),t(_l),t(Gl),t(Dl),t(sl)),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),d(el,l)}}}const be='{"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 Ve(w){return me(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ze extends Me{constructor(p){super(),ue(this,p,Ve,he,Te,{})}}export{Ze as component};
