Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"ModularPipeline","local":"modularpipeline","sections":[{"title":"파이프라인 만들기","local":"creating-a-pipeline","sections":[{"title":"init_pipeline","local":"initpipeline","sections":[],"depth":3},{"title":"from_pretrained","local":"frompretrained","sections":[],"depth":3}],"depth":2},{"title":"컴포넌트 로드","local":"loading-components","sections":[],"depth":2},{"title":"컴포넌트 업데이트","local":"updating-components","sections":[{"title":"AutoModel에서","local":"from-automodel","sections":[],"depth":3},{"title":"ComponentSpec에서","local":"from-componentspec","sections":[],"depth":3}],"depth":2},{"title":"파이프라인을 단계로 분할하기","local":"splitting-a-pipeline-into-stages","sections":[],"depth":2},{"title":"모듈형 저장소","local":"modular-repository","sections":[{"title":"자체 포함 복사본 저장","local":"save-a-self-contained-copy","sections":[{"title":"기존 모듈형 인덱스 업데이트","local":"update-an-existing-modular-index","sections":[],"depth":4}],"depth":3},{"title":"기존 컴포넌트에 대한 참조 유지","local":"keep-references-to-existing-components","sections":[],"depth":3}],"depth":2}],"depth":1}"/> | |
| <link href="/docs/diffusers/main/en/_app/immutable/entry/start.vZc-dOUR.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/Bafuik5c.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/Bupkjr9f.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/entry/app.B6c3Ml05.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/CyvZ3FS5.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/l0QnnOED.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DnVIJfC5.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/nodes/0.BQlx092V.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/CoSrdQax.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/nodes/321.DHeMFHSv.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/B4AMoTAu.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/B_Tpb3TG.js" rel="modulepreload"> | |
| <!--10zod39--><meta name="hf:doc:metadata" content="{"title":"ModularPipeline","local":"modularpipeline","sections":[{"title":"Creating a pipeline","local":"creating-a-pipeline","sections":[{"title":"init_pipeline","local":"initpipeline","sections":[],"depth":3},{"title":"from_pretrained","local":"frompretrained","sections":[],"depth":3}],"depth":2},{"title":"Loading components","local":"loading-components","sections":[],"depth":2},{"title":"Updating components","local":"updating-components","sections":[{"title":"From AutoModel","local":"from-automodel","sections":[],"depth":3},{"title":"From ComponentSpec","local":"from-componentspec","sections":[],"depth":3}],"depth":2},{"title":"Splitting a pipeline into stages","local":"splitting-a-pipeline-into-stages","sections":[],"depth":2},{"title":"Modular repository","local":"modular-repository","sections":[{"title":"Save a self-contained copy","local":"save-a-self-contained-copy","sections":[{"title":"Update an existing modular index","local":"update-an-existing-modular-index","sections":[],"depth":4}],"depth":3},{"title":"Keep references to existing components","local":"keep-references-to-existing-components","sections":[],"depth":3}],"depth":2}],"depth":1}"/><!----> | |
| <link href="/docs/diffusers/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"><div dir="ltr" class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----></span> <span dir="auto">Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="modularpipeline" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#modularpipeline"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->ModularPipeline<!----></span></h1><!--]--><!----> <p><a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>는 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks">ModularPipelineBlocks</a>를 모델 로딩 및 블록에서 정의된 계산 단계를 수행하는 실행 가능한 파이프라인으로 변환합니다. 이는 파이프라인 실행을 위한 주요 인터페이스이며, API는 <a href="/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a>과 매우 유사하지만 몇 가지 주요 차이점이 있습니다.</p> <ul><li><p><strong>Loading is lazy.</strong> With <a href="/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a>, <a href="/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained">from_pretrained()</a> creates the pipeline and loads all models at the same time. With <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>, creating and loading are two separate steps: <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a> reads the configuration and knows where to load each component from, but doesn’t actually load the model weights. You load the models later with <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a>, which is where you pass loading arguments like <code>dtype</code> and <code>quantization_config</code>.</p></li> <li><p><strong>파이프라인을 생성하는 두 가지 방법</strong> 기존 diffusers 모델 저장소와 함께 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a>를 사용할 수 있습니다. 이 방법은 기본 파이프라인 블록에 자동으로 매핑한 후 추가 설정 없이 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>으로 변환합니다. 현재 지원되는 모델을 확인하려면 <a href="https://github.com/huggingface/diffusers/tree/main/src/diffusers/modular_pipelines" rel="nofollow">modular_pipelines_directory</a>를 살펴보세요. 또한 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks">ModularPipelineBlocks</a>로 직접 파이프라인을 조립한 후 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.init_pipeline">init_pipeline()</a> 메서드로 변환할 수도 있습니다(자세한 내용은 <a href="#creating-a-pipeline">파이프라인 생성</a>을 참고하세요).</p></li> <li><p><strong>파이프라인 실행 방법은 동일합니다.</strong> 로드된 후, 익숙한 인수를 그대로 사용하여 파이프라인을 호출합니다. 파이프라인 블록이 <a href="./auto_pipeline_blocks"><code>AutoPipelineBlocks</code></a>를 사용하여 입력에 따라 워크플로를 자동으로 선택하는 경우, 단일 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>이 여러 워크플로(텍스트-이미지, 이미지-이미지, 인페인팅 등)를 지원할 수 있습니다.</p></li></ul> <p>다음은 SDXL을 사용한 텍스트-이미지 생성, 이미지-이미지 변환, 인페인팅의 완전한 예시입니다.</p> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><!--[--><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">텍스트-이미지</div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">이미지-이미지</div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">인페인팅</div><!--]--></div> <div class="language-select"><div><div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ModularPipeline | |
| pipeline = ModularPipeline.from_pretrained(<span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>) | |
| pipeline.load_components(dtype=torch.float16) | |
| pipeline.to(<span class="hljs-string">"cuda"</span>) <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| image = pipeline(prompt=<span class="hljs-string">"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"</span>).images[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"modular_t2i_out.png"</span>)<!----></pre></div><!----></div><!----> <div hidden=""><div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ModularPipeline | |
| <span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image | |
| pipeline = ModularPipeline.from_pretrained(<span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>) | |
| pipeline.load_components(dtype=torch.float16) | |
| pipeline.to(<span class="hljs-string">"cuda"</span>) <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| url = <span class="hljs-string">"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-text2img.png"</span> | |
| init_image = load_image(url) | |
| prompt = <span class="hljs-string">"a dog catching a frisbee in the jungle"</span> | |
| image = pipeline(prompt=prompt, image=init_image, strength=<span class="hljs-number">0.8</span>).images[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"modular_i2i_out.png"</span>)<!----></pre></div><!----></div><!----> <div hidden=""><div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ModularPipeline | |
| <span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image | |
| pipeline = ModularPipeline.from_pretrained(<span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>) | |
| pipeline.load_components(dtype=torch.float16) | |
| pipeline.to(<span class="hljs-string">"cuda"</span>) <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| img_url = <span class="hljs-string">"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-text2img.png"</span> | |
| mask_url = <span class="hljs-string">"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-inpaint-mask.png"</span> | |
| init_image = load_image(img_url) | |
| mask_image = load_image(mask_url) | |
| prompt = <span class="hljs-string">"A deep sea diver floating"</span> | |
| image = pipeline(prompt=prompt, image=init_image, mask_image=mask_image, strength=<span class="hljs-number">0.85</span>).images[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"modular_inpaint_out.png"</span>)<!----></pre></div><!----></div><!----><!----></div><!----> <p>이 가이드에서는 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>를 생성하고, 그 구성 요소를 관리하며, 파이프라인을 실행하는 방법을 보여줍니다.</p> <!--[1--><h2 class="relative group"><a id="creating-a-pipeline" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#creating-a-pipeline"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->파이프라인 만들기<!----></span></h2><!--]--><!----> <p>There are two ways to create a <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>. Assemble and create a pipeline from <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks">ModularPipelineBlocks</a> with <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.init_pipeline">init_pipeline()</a>, or load an existing pipeline with <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a>.</p> <p><a href="./components_manager"><code>ComponentsManager</code></a>를 초기화하여 디바이스 배치와 메모리 관리를 처리할 수도 있습니다. 자동 오프로딩이 필요하지 않다면 이 단계를 건너뛰고 <code>pipeline.to("cuda")</code>를 사용하여 파이프라인을 수동으로 원하는 디바이스로 이동할 수 있습니다.</p> <blockquote class="tip"><p><a href="./components_manager">ComponentsManager</a> 문서의 자세한 내용을 참조하여 다른 워크플로우 간에 구성 요소를 관리하는 데 어떻게 도움이 되는지 확인하세요.</p></blockquote> <!--[2--><h3 class="relative group"><a id="initpipeline" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#initpipeline"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->init_pipeline<!----></span></h3><!--]--><!----> <p><a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.init_pipeline">init_pipeline()</a>은 모든 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks">ModularPipelineBlocks</a>를 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>로 변환합니다.</p> <p>동작 방식을 확인하기 위해 최소한의 블록을 정의해 보겠습니다:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> CLIPTextModel | |
| <span class="hljs-keyword">from</span> diffusers.modular_pipelines <span class="hljs-keyword">import</span> ( | |
| ComponentSpec, | |
| ModularPipelineBlocks, | |
| PipelineState, | |
| ) | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">MyBlock</span>(<span class="hljs-title class_ inherited__">ModularPipelineBlocks</span>): | |
| <span class="hljs-meta"> @property</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">expected_components</span>(<span class="hljs-params">self</span>): | |
| <span class="hljs-keyword">return</span> [ | |
| ComponentSpec( | |
| name=<span class="hljs-string">"text_encoder"</span>, | |
| type_hint=CLIPTextModel, | |
| pretrained_model_name_or_path=<span class="hljs-string">"openai/clip-vit-large-patch14"</span>, | |
| ), | |
| ] | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">__call__</span>(<span class="hljs-params">self, components, state: PipelineState</span>) -> PipelineState: | |
| <span class="hljs-keyword">return</span> components, state<!----></pre></div><!----> <p><a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.init_pipeline">init_pipeline()</a>를 호출하여 파이프라인으로 변환합니다. 파이프라인의 <code>blocks</code> 속성은 해당 파이프라인이 생성된 블록을 나타내며, 예상 입력, 출력 및 계산 로직을 결정합니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!---->block = MyBlock() | |
| pipe = block.init_pipeline() | |
| pipe.blocks<!----></pre></div><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class=" "><!----><span class="hljs-title class_">MyBlock</span> <span class="hljs-punctuation">{</span> | |
| <span class="hljs-string">"_class_name"</span>: <span class="hljs-string">"MyBlock"</span>, | |
| <span class="hljs-string">"_diffusers_version"</span>: <span class="hljs-string">"0.37.0.dev0"</span> | |
| <span class="hljs-punctuation">}</span><!----></pre></div><!----> <blockquote class="warning"><p>Blocks는 변경 가능합니다. 파이프라인을 생성하기 전에 자유롭게 블록을 추가, 제거 또는 교체할 수 있습니다. 그러나 파이프라인이 생성된 후에는 <code>pipeline.blocks</code>를 수정해도 복사본을 반환하기 때문에 파이프라인에 영향을 주지 않습니다. 다른 블록 구조가 필요하면 블록을 수정한 후 새로운 파이프라인을 생성하세요.</p></blockquote> <p>리포지토리를 지정하지 않고 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.init_pipeline">init_pipeline()</a>을 호출하면, 블록의 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_components#diffusers.ComponentSpec">ComponentSpec</a>에 정의된 <code>pretrained_model_name_or_path</code>를 사용하여 각 구성 요소를从哪里 로드할지 결정합니다. 파이프라인을 출력하면 구성 요소 로드 설정을 확인할 수 있습니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!---->pipe | |
| ModularPipeline { | |
| <span class="hljs-string">"_blocks_class_name"</span>: <span class="hljs-string">"MyBlock"</span>, | |
| <span class="hljs-string">"_class_name"</span>: <span class="hljs-string">"ModularPipeline"</span>, | |
| <span class="hljs-string">"_diffusers_version"</span>: <span class="hljs-string">"0.37.0.dev0"</span>, | |
| <span class="hljs-string">"text_encoder"</span>: [ | |
| null, | |
| null, | |
| { | |
| <span class="hljs-string">"pretrained_model_name_or_path"</span>: <span class="hljs-string">"openai/clip-vit-large-patch14"</span>, | |
| <span class="hljs-string">"revision"</span>: null, | |
| <span class="hljs-string">"subfolder"</span>: <span class="hljs-string">""</span>, | |
| <span class="hljs-string">"type_hint"</span>: [ | |
| <span class="hljs-string">"transformers"</span>, | |
| <span class="hljs-string">"CLIPTextModel"</span> | |
| ], | |
| <span class="hljs-string">"variant"</span>: null | |
| } | |
| ] | |
| }<!----></pre></div><!----> <p><a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.init_pipeline">init_pipeline()</a>에 저장소를 전달하면, 해당 저장소의 파이프라인 구성(<code>model_index.json</code> 또는 <code>modular_model_index.json</code>)과 블록의 구성 요소를 매칭하여 로딩 경로를 재정의합니다. 로딩 사양이 기록되고 저장되는 방법은 <a href="#modular-repository">Modular repository</a>를 참고하세요.</p> <p>아래 예시에서 <code>pretrained_model_name_or_path</code>는 <code>"stabilityai/stable-diffusion-xl-base-1.0"</code>으로 업데이트됩니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!---->pipe = block.init_pipeline(<span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>) | |
| pipe | |
| ModularPipeline { | |
| <span class="hljs-string">"_blocks_class_name"</span>: <span class="hljs-string">"MyBlock"</span>, | |
| <span class="hljs-string">"_class_name"</span>: <span class="hljs-string">"ModularPipeline"</span>, | |
| <span class="hljs-string">"_diffusers_version"</span>: <span class="hljs-string">"0.37.0.dev0"</span>, | |
| <span class="hljs-string">"text_encoder"</span>: [ | |
| null, | |
| null, | |
| { | |
| <span class="hljs-string">"pretrained_model_name_or_path"</span>: <span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>, | |
| <span class="hljs-string">"revision"</span>: null, | |
| <span class="hljs-string">"subfolder"</span>: <span class="hljs-string">"text_encoder"</span>, | |
| <span class="hljs-string">"type_hint"</span>: [ | |
| <span class="hljs-string">"transformers"</span>, | |
| <span class="hljs-string">"CLIPTextModel"</span> | |
| ], | |
| <span class="hljs-string">"variant"</span>: null | |
| } | |
| ] | |
| }<!----></pre></div><!----> <p>블록의 구성 요소가 저장소에 없으면 <code>null</code>로 남아 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a> 실행 시 건너뜁니다.</p> <!--[2--><h3 class="relative group"><a id="frompretrained" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#frompretrained"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->from_pretrained<!----></span></h3><!--]--><!----> <p><a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a>은 블록을 직접 정의하지 않고 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>을 생성하는 편리한 방법입니다.</p> <p>세 가지 유형의 저장소와 함께 작동합니다.</p> <p><strong>일반적인 diffusers 저장소.</strong> 지원되는 모델 저장소를 전달하면 기본 파이프라인 블록으로 자동으로 매핑됩니다. 현재 지원되는 모델에는 SDXL, Wan, Qwen, Z-Image, Flux, Flux2가 포함됩니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ModularPipeline, ComponentsManager | |
| components = ComponentsManager() | |
| pipeline = ModularPipeline.from_pretrained( | |
| <span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>, components_manager=components | |
| )<!----></pre></div><!----> <p><strong>모듈형 저장소.</strong> 이러한 저장소에는 각 구성 요소를从哪里 로드할지 지정하는 <code>modular_model_index.json</code> 파일이 포함되어 있습니다. 구성 요소는 서로 다른 저장소에서 가져올 수 있으며, 모듈형 저장소 자체에는 모델 가중치가 전혀 없을 수도 있습니다. 예를 들어, <a href="https://huggingface.co/diffusers/flux2-bnb-4bit-modular" rel="nofollow">diffusers/flux2-bnb-4bit-modular</a>는 한 저장소에서 양자화된 transformer를 로드하고 나머지 구성 요소를 다른 저장소에서 로드합니다. 포맷에 대한 자세한 내용은 <a href="#modular-repository">Modular repository</a>를 참고하세요.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ModularPipeline, ComponentsManager | |
| components = ComponentsManager() | |
| pipeline = ModularPipeline.from_pretrained( | |
| <span class="hljs-string">"diffusers/flux2-bnb-4bit-modular"</span>, components_manager=components | |
| )<!----></pre></div><!----> <p><strong>커스텀 코드가 포함된 모듈형 저장소.</strong> 일부 저장소에는 로딩 구성과 함께 커스텀 파이프라인 블록이 포함됩니다. 이를 로드하려면 <code>trust_remote_code=True</code>를 추가하세요. 직접 만들려면 <a href="./custom_blocks">커스텀 블록</a>을 참고하세요.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ModularPipeline, ComponentsManager | |
| components = ComponentsManager() | |
| pipeline = ModularPipeline.from_pretrained( | |
| <span class="hljs-string">"diffusers/Florence2-image-Annotator"</span>, trust_remote_code=<span class="hljs-literal">True</span>, components_manager=components | |
| )<!----></pre></div><!----> <p>pipeline 블록이 워크플로를 정의하는 경우(<code>pipeline.blocks.available_workflows</code> 확인), <code>workflow=</code>를 전달하여 해당 워크플로의 블록만 유지합니다. 이는 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.get_workflow">get_workflow()</a>와 동일한 가지치기입니다. 그러면 pipeline은 해당 워크플로가 사용하는 컴포넌트만 선언하고, docstring은 정확히 해당 워크플로의 입력을 설명합니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!---->pipeline = ModularPipeline.from_pretrained(<span class="hljs-string">"Qwen/Qwen-Image"</span>, workflow=<span class="hljs-string">"inpainting"</span>)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="loading-components" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#loading-components"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->컴포넌트 로드<!----></span></h2><!--]--><!----> <p><a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>는 구성 요소가 자동으로 인스턴스화되지 않습니다. 구성 및 구성 요소 사양만 로드합니다. 구성 요소는 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a>를 사용하여 로드할 수 있습니다.</p> <p>…</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">import</span> torch | |
| pipeline.load_components(dtype=torch.float16)<!----></pre></div><!----> <p>이름으로 특정 구성 요소를 로드할 수도 있습니다. 아래 예시에서는 <code>text_encoder</code>만 로드합니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!---->pipeline.load_components(names=[<span class="hljs-string">"text_encoder"</span>], dtype=torch.float16)<!----></pre></div><!----> <p>블록이 워크플로를 정의하는 파이프라인에서 <code>workflow=</code>는 해당 워크플로가 사용하는 컴포넌트만 로드합니다. 파이프라인은 모든 블록을 유지하므로, 이는 하나의 파이프라인을 여러 워크플로에 걸쳐 실행하는 편리한 방법입니다. 각 호출은 새로운 워크플로가 아직 누락한 것만 추가합니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!---->pipeline.load_components(workflow=<span class="hljs-string">"inpainting"</span>, dtype=torch.float16)<!----></pre></div><!----> <p>로드 후 파이프라인을 출력하면 어떤 구성 요소가 로드되었는지 확인할 수 있습니다. 처음 두 필드가 <code>null</code>에서 해당 구성 요소의 라이브러리와 클래스로 변경됩니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!---->pipeline<!----></pre></div><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class=" "><!----><span class="hljs-comment"># text_encoder is loaded - shows library and class</span> | |
| <span class="hljs-string">"text_encoder"</span>: [ | |
| <span class="hljs-string">"transformers"</span>, | |
| <span class="hljs-string">"CLIPTextModel"</span>, | |
| { ... } | |
| ] | |
| <span class="hljs-comment"># unet is not loaded yet - still null</span> | |
| <span class="hljs-string">"unet"</span>: [ | |
| <span class="hljs-literal">null</span>, | |
| <span class="hljs-literal">null</span>, | |
| { ... } | |
| ]<!----></pre></div><!----> <p><code>dtype</code>, <code>variant</code>, <code>revision</code>, <code>quantization_config</code>와 같은 키워드 인수는 각 구성 요소에 대해 <code>from_pretrained()</code>로 전달됩니다. 모든 구성 요소에 적용할 단일 값을 전달하거나, 구성 요소별 값을 설정하기 위해 dict를 전달할 수 있습니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-comment"># apply bfloat16 to all components</span> | |
| pipeline.load_components(dtype=torch.bfloat16) | |
| <span class="hljs-comment"># different dtypes per component</span> | |
| pipeline.load_components(dtype={<span class="hljs-string">"transformer"</span>: torch.bfloat16, <span class="hljs-string">"default"</span>: torch.float32})<!----></pre></div><!----> <p><a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a>는 아직 로드되지 않았고 유효한 로딩 스펙을 가진 컴포넌트만 로드합니다. 이는 파이프라인에 이미 컴포넌트를 설정한 경우 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a>를 다시 호출해도 해당 컴포넌트가 다시 로드되지 않음을 의미합니다.</p> <!--[1--><h2 class="relative group"><a id="updating-components" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#updating-components"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->컴포넌트 업데이트<!----></span></h2><!--]--><!----> <p><a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.update_components">update_components()</a>는 파이프라인의 구성 요소를 새로운 구성 요소로 교체합니다. 구성 요소가 업데이트되면 파이프라인 설정의 로딩 사양도 함께 업데이트되며, 이후 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a> 호출 시 해당 구성 요소는 건너뜁니다.</p> <!--[2--><h3 class="relative group"><a id="from-automodel" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#from-automodel"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->AutoModel에서<!----></span></h3><!--]--><!----> <p><code>AutoModel.from_pretrained()</code>로 로드된 모델 객체를 전달할 수 있습니다. 이 방식으로 로드된 모델에는 로드 정보가 자동으로 태그됩니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoModel | |
| unet = AutoModel.from_pretrained( | |
| <span class="hljs-string">"RunDiffusion/Juggernaut-XL-v9"</span>, subfolder=<span class="hljs-string">"unet"</span>, variant=<span class="hljs-string">"fp16"</span>, dtype=torch.float16 | |
| ) | |
| pipeline.update_components(unet=unet)<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="from-componentspec" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#from-componentspec"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->ComponentSpec에서<!----></span></h3><!--]--><!----> <p><a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.get_component_spec">get_component_spec()</a>을 사용하여 현재 구성 요소 사양의 사본을 가져오고, 수정한 후 새로운 구성 요소를 로드합니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!---->unet_spec = pipeline.get_component_spec(<span class="hljs-string">"unet"</span>) | |
| <span class="hljs-comment"># modify to load from a different repository</span> | |
| unet_spec.pretrained_model_name_or_path = <span class="hljs-string">"RunDiffusion/Juggernaut-XL-v9"</span> | |
| <span class="hljs-comment"># load and update</span> | |
| unet = unet_spec.load(dtype=torch.float16) | |
| pipeline.update_components(unet=unet)<!----></pre></div><!----> <p><a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_components#diffusers.ComponentSpec">ComponentSpec</a>를 처음부터 직접 생성할 수도 있습니다.</p> <p>모든 구성 요소가 사전 학습된 가중치에서 로드되는 것은 아닙니다. 일부 구성 요소는 <code>pipeline.config_component_names</code>에 나열된 대로 config에서 생성됩니다. 이러한 구성 요소에는 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_components#diffusers.ComponentSpec.load">load()</a> 대신 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_components#diffusers.ComponentSpec.create">create()</a>를 사용하세요.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!---->guider_spec = pipeline.get_component_spec(<span class="hljs-string">"guider"</span>) | |
| guider_spec.config = {<span class="hljs-string">"guidance_scale"</span>: <span class="hljs-number">5.0</span>} | |
| guider = guider_spec.create() | |
| pipeline.update_components(guider=guider)<!----></pre></div><!----> <p>또는 객체를 직접 전달합니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers.guiders <span class="hljs-keyword">import</span> ClassifierFreeGuidance | |
| guider = ClassifierFreeGuidance(guidance_scale=<span class="hljs-number">5.0</span>) | |
| pipeline.update_components(guider=guider)<!----></pre></div><!----> <p>사용 가능한 guider와 설정 방법에 대한 자세한 내용은 <a href="../using-diffusers/guiders">Guiders</a> 가이드를 참고하세요.</p> <!--[1--><h2 class="relative group"><a id="splitting-a-pipeline-into-stages" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#splitting-a-pipeline-into-stages"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->파이프라인을 단계로 분할하기<!----></span></h2><!--]--><!----> <p>블록은 구성 가능(composable)하므로, 파이프라인을 분해하여 각 단계별로 별도의 파이프라인으로 재구성할 수 있습니다. 아래 예제는 텍스트 인코더 블록을 파이프라인의 나머지 부분에서 분리하는 방법을 보여줍니다. 이를 통해 프롬프트를 독립적으로 인코딩한 후 임베딩을 메인 파이프라인에 전달할 수 있습니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ModularPipeline, ComponentsManager | |
| <span class="hljs-keyword">import</span> torch | |
| device = <span class="hljs-string">"cuda"</span> <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| dtype = torch.bfloat16 | |
| repo_id = <span class="hljs-string">"black-forest-labs/FLUX.2-klein-4B"</span> | |
| <span class="hljs-comment"># get the blocks and separate out the text encoder</span> | |
| blocks = ModularPipeline.from_pretrained(repo_id).blocks | |
| text_block = blocks.sub_blocks.pop(<span class="hljs-string">"text_encoder"</span>) | |
| <span class="hljs-comment"># use ComponentsManager to handle offloading across multiple pipelines</span> | |
| manager = ComponentsManager() | |
| manager.enable_auto_cpu_offload(device=device) | |
| <span class="hljs-comment"># create separate pipelines for each stage</span> | |
| text_encoder_pipeline = text_block.init_pipeline(repo_id, components_manager=manager) | |
| pipeline = blocks.init_pipeline(repo_id, components_manager=manager) | |
| <span class="hljs-comment"># encode text</span> | |
| text_encoder_pipeline.load_components(dtype=dtype) | |
| text_embeddings = text_encoder_pipeline(prompt=<span class="hljs-string">"a cat"</span>).get_by_kwargs(<span class="hljs-string">"denoiser_input_fields"</span>) | |
| <span class="hljs-comment"># denoise and decode</span> | |
| pipeline.load_components(dtype=dtype) | |
| output = pipeline( | |
| **text_embeddings, | |
| num_inference_steps=<span class="hljs-number">4</span>, | |
| ).images[<span class="hljs-number">0</span>]<!----></pre></div><!----> <p><a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager">ComponentsManager</a>은 여러 파이프라인에 걸친 메모리를 관리합니다. <a href="/docs/diffusers/main/ko/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a>의 오프로딩 전략이 고정된 순서를 따르는 것과 달리, <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager">ComponentsManager</a>는 모델의 포워드 패스가 실행될 때마다 현재 메모리 상황에 따라 오프로딩을 동적으로 결정합니다. 따라서 파이프라인을 몇 개 생성하든, 어떤 순서로 실행하든 작동합니다. 자세한 내용은 <a href="./components_manager">ComponentsManager</a> 가이드를 참고하세요.</p> <p>pipeline 단계가 구성 요소를 공유하는 경우(예: 인코딩과 디코딩에 동일한 VAE 사용), 다시 로드하는 대신 이미 로드된 구성 요소를 다른 pipeline에 전달하기 위해 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.update_components">update_components()</a>를 사용할 수 있습니다.</p> <!--[1--><h2 class="relative group"><a id="modular-repository" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#modular-repository"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->모듈형 저장소<!----></span></h2><!--]--><!----> <p><em>pretrained components</em>를 사용하는 파이프라인 블록의 경우 저장소가 필요합니다. 저장소는 로딩 사양과 메타데이터를 제공합니다.</p> <p><a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>는 일반적인 diffusers 저장소와 바로 함께 작동합니다. 그러나 더 많은 유연성을 위해 <em>모듈형 저장소</em>를 만들 수도 있습니다. 모듈형 저장소에는 다음 3가지 요소를 포함하는 <code>modular_model_index.json</code> 파일이 있습니다.</p> <ul><li><code>library</code>와 <code>class</code>는 해당 구성 요소가 어떤 라이브러리에서 로드되었는지와 그 클래스를 나타냅니다. <code>null</code>인 경우, 해당 구성 요소는 아직 로드되지 않은 것입니다.</li> <li><code>loading_specs_dict</code>에는 저장소와 하위 폴더와 같이 구성 요소를 로드하는 데 필요한 정보가 포함되어 있습니다.</li></ul> <p>모듈형 저장소의 핵심 이점은 컴포넌트를 서로 다른 저장소에서 로드할 수 있다는 것입니다. 예를 들어, <a href="https://huggingface.co/diffusers/flux2-bnb-4bit-modular" rel="nofollow">diffusers/flux2-bnb-4bit-modular</a>는 <code>diffusers/FLUX.2-dev-bnb-4bit</code>에서 양자화된 transformer를 로드하는 동시에 나머지 컴포넌트는 <code>black-forest-labs/FLUX.2-dev</code>에서 로드합니다.</p> <p>일반적인 diffusers 저장소를 모듈형 저장소로 변환하려면, 먼저 일반적인 저장소를 사용하여 파이프라인을 생성한 후 Hub에 push합니다. 저장된 저장소에는 모든 로딩 사양이 포함된 <code>modular_model_index.json</code>가 포함됩니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ModularPipeline | |
| <span class="hljs-comment"># load from a regular repo</span> | |
| pipeline = ModularPipeline.from_pretrained(<span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>) | |
| <span class="hljs-comment"># push as a modular repository</span> | |
| pipeline.save_pretrained(<span class="hljs-string">"local/path"</span>, repo_id=<span class="hljs-string">"my-username/sdxl-modular"</span>, push_to_hub=<span class="hljs-literal">True</span>)<!----></pre></div><!----> <p>기본적으로 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.save_pretrained">save_pretrained()</a>는 Diffusers가 직렬화할 수 있는 현재 로드된 각 구성 요소를 기록합니다. 로드되지 않았거나 직렬화할 수 없는 구성 요소는 기록되지 않으며 기존 로드 사양을 유지합니다. 이를 통해 원하는 목적에 따라 두 가지 방식으로 저장할 수 있습니다.</p> <!--[2--><h3 class="relative group"><a id="save-a-self-contained-copy" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#save-a-self-contained-copy"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->자체 포함 복사본 저장<!----></span></h3><!--]--><!----> <p>모든 구성 요소를 로드한 후 저장합니다. 모든 사양이 결과물을 가리키므로 오프라인을 포함하여 한 곳에서 완전히 다시 로드됩니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!---->pipe = ModularPipeline.from_pretrained(<span class="hljs-string">"MiniMaxAI/MiniMax-H3"</span>) | |
| pipe.load_components() | |
| pipe.save_pretrained(<span class="hljs-string">"path/to/local-copy"</span>)<!----></pre></div><!----> <p><code>modular_model_index.json</code>에 기록된 대상은 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline.save_pretrained">save_pretrained()</a>가 데이터를 쓰는 위치입니다. 로컬 저장 시에는 <code>save_directory</code>, <code>push_to_hub=True</code>를 전달한 경우에는 <code>repo_id</code>입니다.</p> <p><code>huggingface_hub>=1.32.0</code>부터 동일한 Xet 기반 파일은 Hub 저장소 간에 하나의 캐시된 페이로드를 공유할 수 있습니다. 이는 샤드화된 체크포인트의 개별 파일에도 적용됩니다. 다른 샤드와 내용이 달라도 동일한 Xet 해시를 가진 샤드는 재사용될 수 있습니다. 두 다운로드 모두 심볼릭 링크를 지원하는 동일한 Hub 캐시 디렉터리를 사용해야 합니다. dtype, 직렬화 방식 또는 샤드 경계를 변경하면 파일 해시가 달라져 재사용이 불가능해질 수 있습니다. 이를 통해 다운로드 트래픽과 디스크 공간을 절약할 수 있지만, 로드된 구성 요소가 사용하는 메모리는 절약되지 않습니다.</p> <p>공유 캐싱은 최선 노력(best-effort) 방식입니다. <code>HF_HUB_DISABLE_SHARED_BLOBS=1</code>을 설정해도 로딩은 지원되지만, 개별 사본을 캐시합니다. <code>modular_model_index.json</code>에 있는 기존 구성 요소 참조는 변경되지 않으며, 모듈형 저장소에 저장되지 않은 구성 요소의 외부 참조는 유지해야 합니다.</p> <!--[3--><h4 class="relative group"><a id="update-an-existing-modular-index" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#update-an-existing-modular-index"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->기존 모듈형 인덱스 업데이트<!----></span></h4><!--]--><!----> <p>마이그레이션은 선택 사항입니다: 원본 저장소에 대한 참조는 이미 캐시된 파일을 재사용합니다. 중복 다운로드를 피하기 위해만 사용되었고 해당 구성 요소를 모듈형 저장소에서 로드하도록 변경하려면 참조를 업데이트하세요.</p> <p>먼저, 모듈형 저장소에 동일한 구성 요소 구성과 모든 필수 가중치 파일이 포함되어 있는지 확인하십시오. 여기에는 가중치 인덱스와 샤드화된 체크포인트의 모든 샤드가 포함됩니다. 일치하는 Xet 해시가 어떤 가중치 파일을 공유 캐시로 재사용할 수 있는지를 결정합니다. 존재하지 않거나 의도적으로 다른 체크포인트에서 로드되는 구성 요소에 대한 참조를 유지하십시오.</p> <p><code>modular_model_index.json</code>의 로컬 사본에서 관련 로딩 사양만 수정합니다. 예를 들어, 모듈형 저장소에서 <code>vae/</code> 아래에 저장된 VAE를 동일한 가중치 변형으로 사용하려면:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">import</span> json | |
| <span class="hljs-keyword">from</span> pathlib <span class="hljs-keyword">import</span> Path | |
| index_path = Path(<span class="hljs-string">"path/to/local-copy/modular_model_index.json"</span>) | |
| index = json.loads(index_path.read_text()) | |
| spec = index[<span class="hljs-string">"vae"</span>][<span class="hljs-number">2</span>] | |
| spec[<span class="hljs-string">"pretrained_model_name_or_path"</span>] = <span class="hljs-string">"my-username/my-modular-repo"</span> | |
| spec.pop(<span class="hljs-string">"repo"</span>, <span class="hljs-literal">None</span>) | |
| spec[<span class="hljs-string">"subfolder"</span>] = <span class="hljs-string">"vae"</span> | |
| spec[<span class="hljs-string">"revision"</span>] = <span class="hljs-literal">None</span> | |
| index_path.write_text(json.dumps(index, indent=<span class="hljs-number">2</span>) + <span class="hljs-string">"\n"</span>)<!----></pre></div><!----> <p>이것은 레거시 <code>repo</code> 필드도 제거합니다. 원본 저장소의 리비전은 대상 저장소의 리비전을 식별하지 않습니다: 대상의 기본 브랜치를 사용하려면 <code>None</code>을 사용하거나, 해당 구성 요소를 포함하는 대상 리비전을 고정하세요. 파일명이 다르면 <code>subfolder</code>와 <code>variant</code>를 조정하세요.</p> <p>업데이트된 인덱스를 게시하기 전에 <code>ModularPipeline.from_pretrained("path/to/local-copy")</code>로 로드하고, <code>load_components(names="vae")</code>를 호출한 후, 해당 구성 요소가 예상된 매개변수로 로드되는지 확인하세요. 편집된 인덱스만 업로드하세요. 가중치를 다시 저장하면 해시가 변경되어 캐시 재사용이 방지될 수 있습니다.</p> <!--[2--><h3 class="relative group"><a id="keep-references-to-existing-components" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#keep-references-to-existing-components"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->기존 컴포넌트에 대한 참조 유지<!----></span></h3><!--]--><!----> <p>새로운 것만(아니면 아무것도 아닌) 로드합니다. 로드된 컴포넌트만 저장되며, 나머지는 원래 저장소를 가리키는 포인터로 유지됩니다. 한 컴포넌트를 교체하면서 다른 컴포넌트는 원래 저장소에서 계속 로드하기를 원할 때 이 모드를 사용하세요. 예를 들어, 커스텀 transformer를 저장하면서 나머지 컴포넌트는 기본 저장소에서 계속 로드되도록 할 수 있습니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-py "><!---->pipe = ModularPipeline.from_pretrained(<span class="hljs-string">"black-forest-labs/FLUX.2-dev"</span>) | |
| pipe.update_components(transformer=my_custom_transformer) <span class="hljs-comment"># the only component in memory</span> | |
| pipe.save_pretrained(<span class="hljs-string">"local/path"</span>, repo_id=<span class="hljs-string">"my-username/flux2-custom-transformer"</span>, push_to_hub=<span class="hljs-literal">True</span>)<!----></pre></div><!----> <p><code>overwrite_modular_index=False</code>를 전달하면 <code>modular_model_index.json</code>의 로딩 사양을 그대로 유지합니다. 로딩 사양이 비어 있는 저장된 컴포넌트는 보존할 내용이 없으므로 대상 경로로 채워집니다.</p> <p>파일을 다른 방식으로 이동하면 인덱스가 다시 작성되지 않습니다. <code>hf download --local-dir</code>로 다운로드한 복사본은 여전히 작동합니다. 파이프라인이 로컬 디렉터리에서 로드되면, 해당 디렉터리에 파일이 존재하는 모든 구성 요소는 기록된 저장소가 아닌 해당 디렉터리에서 로드됩니다. <code>hf upload</code>로 업로드한 복사본은 여전히 이전 위치를 가리키므로, 이 경우 인덱스를 수동으로 업데이트해야 합니다.</p> <p>모듈형 저장소에는 Python 코드로 작성된 사용자 정의 파이프라인 블록도 포함할 수 있습니다. 이를 통해 Diffusers에 기본적으로 제공되지 않는 특수한 블록을 공유할 수 있습니다. 예를 들어, <a href="https://huggingface.co/diffusers/Florence2-image-Annotator" rel="nofollow">diffusers/Florence2-image-Annotator</a>에는 로드 구성과 함께 사용자 정의 블록이 포함되어 있습니다:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class=" "><!----><span class="hljs-type">Florence2</span>-image-<span class="hljs-type">Annotator</span>/ | |
| ├── <span class="hljs-keyword">block</span>.py <span class="hljs-comment"># Custom pipeline blocks implementation</span> | |
| ├── config.json <span class="hljs-comment"># Pipeline configuration and auto_map</span> | |
| ├── mellon_config.json <span class="hljs-comment"># UI configuration for Mellon</span> | |
| └── modular_model_index.json <span class="hljs-comment"># Component loading specifications</span><!----></pre></div><!----> <p><code>config.json</code> 파일에는 <a href="/docs/diffusers/main/ko/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>가 커스텀 블록을 어디에서 찾을 수 있는지 알려 주는 <code>auto_map</code> 키가 포함되어 있습니다:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> 복사됨</div><!----></button><!----></div> <pre class="language-json "><!----><span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"_class_name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Florence2AnnotatorBlocks"</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"auto_map"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"ModularPipelineBlocks"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"block.Florence2AnnotatorBlocks"</span> | |
| <span class="hljs-punctuation">}</span> | |
| <span class="hljs-punctuation">}</span><!----></pre></div><!----> <p><code>trust_remote_code=True</code>를 사용하여 <a href="#frompretrained">from_pretrained</a>에 표시된 대로 사용자 정의 코드 저장소를 로드합니다. 직접 생성하고 공유하는 방법은 <a href="./custom_blocks">Custom blocks</a>를 참조하세요.</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/diffusers/blob/main/docs/source/en/modular_diffusers/modular_pipeline.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg><!----> <span><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]--> | |
| <script> | |
| { | |
| __sveltekit_1rjuniz = { | |
| base: "/docs/diffusers/main/en", | |
| assets: "/docs/diffusers/main/en" | |
| }; | |
| const element = document.currentScript.parentElement; | |
| Promise.all([ | |
| import("/docs/diffusers/main/en/_app/immutable/entry/start.vZc-dOUR.js"), | |
| import("/docs/diffusers/main/en/_app/immutable/entry/app.B6c3Ml05.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 321], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 100 kB
- Xet hash:
- 0bac92a56b84cfe7c4e4d03698647886b2763cc39ad24edbe0db36ecd22c5f68
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.