Buckets:
| # AutoPipelineBlocks | |
| [AutoPipelineBlocks](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.AutoPipelineBlocks)는 서로 다른 워크플로를 지원하는 블록을 포함하는 멀티 블록 유형입니다. 런타임에 제공된 입력을 기반으로 실행할 서브 블록을 자동으로 선택합니다. 이는 일반적으로 텍스트-이미지 생성, 이미지-이미지 변환, 인페인팅과 같은 여러 워크플로를 편의를 위해 단일 파이프라인으로 패키징하는 데 사용됩니다. | |
| 이 가이드는 [AutoPipelineBlocks](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.AutoPipelineBlocks)를 만드는 방법을 보여줍니다. | |
| 텍스트-이미지, 이미지-이미지, 인페인팅을 위한 세 개의 [ModularPipelineBlocks](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks)를 생성합니다. 이들은 파이프라인에서 사용할 수 있는 다양한 워크플로를 나타냅니다. | |
| ```py | |
| import torch | |
| from diffusers.modular_pipelines import ModularPipelineBlocks, InputParam, OutputParam | |
| class TextToImageBlock(ModularPipelineBlocks): | |
| model_name = "text2img" | |
| @property | |
| def inputs(self): | |
| return [InputParam(name="prompt")] | |
| @property | |
| def intermediate_outputs(self): | |
| return [] | |
| @property | |
| def description(self): | |
| return "I'm a text-to-image workflow!" | |
| def __call__(self, components, state): | |
| block_state = self.get_block_state(state) | |
| print("running the text-to-image workflow") | |
| # Add your text-to-image logic here | |
| # For example: generate image from prompt | |
| self.set_block_state(state, block_state) | |
| return components, state | |
| ``` | |
| ```py | |
| class ImageToImageBlock(ModularPipelineBlocks): | |
| model_name = "img2img" | |
| @property | |
| def inputs(self): | |
| return [InputParam(name="prompt"), InputParam(name="image")] | |
| @property | |
| def intermediate_outputs(self): | |
| return [] | |
| @property | |
| def description(self): | |
| return "I'm an image-to-image workflow!" | |
| def __call__(self, components, state): | |
| block_state = self.get_block_state(state) | |
| print("running the image-to-image workflow") | |
| # Add your image-to-image logic here | |
| # For example: transform input image based on prompt | |
| self.set_block_state(state, block_state) | |
| return components, state | |
| ``` | |
| ```py | |
| class InpaintBlock(ModularPipelineBlocks): | |
| model_name = "inpaint" | |
| @property | |
| def inputs(self): | |
| return [InputParam(name="prompt"), InputParam(name="image"), InputParam(name="mask")] | |
| @property | |
| def intermediate_outputs(self): | |
| return [] | |
| @property | |
| def description(self): | |
| return "I'm an inpaint workflow!" | |
| def __call__(self, components, state): | |
| block_state = self.get_block_state(state) | |
| print("running the inpaint workflow") | |
| # Add your inpainting logic here | |
| # For example: fill masked areas based on prompt | |
| self.set_block_state(state, block_state) | |
| return components, state | |
| ``` | |
| [AutoPipelineBlocks](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.AutoPipelineBlocks) 클래스를 생성하여 서브 블록 클래스 목록과 해당 블록 이름을 포함합니다. | |
| `block_trigger_inputs`도 포함해야 합니다. 이는 해당 블록을 트리거하는 입력 이름의 목록입니다. 런타임에 트리거 입력이 제공되면 해당 블록이 실행될 블록으로 선택됩니다. 트리거 입력이 감지되지 않는 경우 실행할 기본 블록을 지정하려면 `None`을 사용하세요. | |
| 마지막으로, 어떤 입력이 어떤 워크플로를 트리거하는지 명확히 설명하는 `description`을 포함하는 것이 중요합니다. 이를 통해 사용자가 특정 워크플로를 실행하는 방법을 이해할 수 있습니다. | |
| ```py | |
| from diffusers.modular_pipelines import AutoPipelineBlocks | |
| class AutoImageBlocks(AutoPipelineBlocks): | |
| # List of sub-block classes to choose from | |
| block_classes = [InpaintBlock, ImageToImageBlock, TextToImageBlock] | |
| # Names for each block in the same order | |
| block_names = ["inpaint", "img2img", "text2img"] | |
| # Trigger inputs that determine which block to run | |
| # - "mask" triggers inpaint workflow | |
| # - "image" triggers img2img workflow (but only if mask is not provided) | |
| # - if none of above, runs the text2img workflow (default) | |
| block_trigger_inputs = ["mask", "image", None] | |
| @property | |
| def description(self): | |
| return ( | |
| "Pipeline generates images given different types of conditions!\n" | |
| + "This is an auto pipeline block that works for text2img, img2img and inpainting tasks.\n" | |
| + " - inpaint workflow is run when `mask` is provided.\n" | |
| + " - img2img workflow is run when `image` is provided (but only when `mask` is not provided).\n" | |
| + " - text2img workflow is run when neither `image` nor `mask` is provided.\n" | |
| ) | |
| ``` | |
| 블록을 실행하는 방법과 필요한 입력이 무엇인지에 대한 혼란을 피하려면 `description`을 포함하는 것이 **매우** 중요합니다. [AutoPipelineBlocks](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.AutoPipelineBlocks)는 편리하지만, 적절히 설명되지 않으면 조건부 로직을 파악하기 어려울 수 있습니다. | |
| `AutoImageBlocks`의 인스턴스를 생성합니다. | |
| ```py | |
| auto_blocks = AutoImageBlocks() | |
| ``` | |
| 중첩된 [AutoPipelineBlocks](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.AutoPipelineBlocks) 블록이 더 큰 파이프라인의 하위 블록으로 사용되는 경우와 같이 더 복잡한 구성에서는, 입력에 따라 실제로 실행되는 블록을 추출하기 위해 [get_execution_blocks()](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.SequentialPipelineBlocks.get_execution_blocks) 메서드를 사용하세요. | |
| ```py | |
| auto_blocks.get_execution_blocks(mask=True) | |
| ``` | |
| ## ConditionalPipelineBlocks | |
| [AutoPipelineBlocks](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.AutoPipelineBlocks)는 [ConditionalPipelineBlocks](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ConditionalPipelineBlocks)의 특수한 경우입니다. [AutoPipelineBlocks](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.AutoPipelineBlocks)는 트리거 입력이 제공되었는지에 따라 블록을 선택하는 반면, [ConditionalPipelineBlocks](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ConditionalPipelineBlocks)는 `select_block` 메서드에 제공된 사용자 정의 선택 로직에 따라 블록을 선택할 수 있습니다. | |
| 다음은 [ConditionalPipelineBlocks](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ConditionalPipelineBlocks)를 직접 사용하여 작성한 동일한 예시입니다: | |
| ```py | |
| from diffusers.modular_pipelines import ConditionalPipelineBlocks | |
| class AutoImageBlocks(ConditionalPipelineBlocks): | |
| block_classes = [InpaintBlock, ImageToImageBlock, TextToImageBlock] | |
| block_names = ["inpaint", "img2img", "text2img"] | |
| block_trigger_inputs = ["mask", "image"] | |
| default_block_name = "text2img" | |
| @property | |
| def description(self): | |
| return ( | |
| "Pipeline generates images given different types of conditions!\n" | |
| + "This is an auto pipeline block that works for text2img, img2img and inpainting tasks.\n" | |
| + " - inpaint workflow is run when `mask` is provided.\n" | |
| + " - img2img workflow is run when `image` is provided (but only when `mask` is not provided).\n" | |
| + " - text2img workflow is run when neither `image` nor `mask` is provided.\n" | |
| ) | |
| def select_block(self, mask=None, image=None) -> str | None: | |
| if mask is not None: | |
| return "inpaint" | |
| if image is not None: | |
| return "img2img" | |
| return None # falls back to default_block_name ("text2img") | |
| ``` | |
| `block_trigger_inputs`에 나열된 입력은 `select_block()`의 키워드 인수로 전달됩니다. `select_block`이 `None`을 반환하면 `default_block_name`으로 폴백됩니다. `default_block_name`도 `None`인 경우, 해당 조건 블록 전체가 건너뜁니다. 이는 특정 입력이 제공될 때만 실행되어야 하는 선택적 처리 단계에 유용합니다. | |
| ## 워크플로 | |
| 조건 블록([AutoPipelineBlocks](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.AutoPipelineBlocks) 또는 [ConditionalPipelineBlocks](/docs/diffusers/main/ko/api/modular_diffusers/pipeline_blocks#diffusers.ConditionalPipelineBlocks))을 포함하는 파이프라인은 여러 워크플로를 지원할 수 있습니다. 예를 들어, 저희 SDXL 모듈형 파이프라인은 하나의 파이프라인에서 12개의 워크플로를 지원합니다. 하지만 이는 사용자가 어떤 워크플로가 지원되는지, 그리고 어떻게 실행하는지 파악하기 어렵게 만들 수도 있습니다. 파이프라인 빌더의 관점에서는 특정 워크플로에 관련되는 블록만 추출할 수 있는 기능이 유용합니다. | |
| 각 워크플로에 이름을 부여하고 필요한 입력을 명시적으로 나열하도록 `_workflow_map`을 정의하는 것을 권장합니다. | |
| ```py | |
| from diffusers.modular_pipelines import SequentialPipelineBlocks | |
| class MyPipelineBlocks(SequentialPipelineBlocks): | |
| block_classes = [TextEncoderBlock, AutoImageBlocks, DecodeBlock] | |
| block_names = ["text_encoder", "auto_image", "decode"] | |
| _workflow_map = { | |
| "text2image": {"prompt": True}, | |
| "image2image": {"image": True, "prompt": True}, | |
| "inpaint": {"mask": True, "image": True, "prompt": True}, | |
| } | |
| ``` | |
| 모든 내장 모듈형 파이프라인에는 사전 정의된 워크플로가 포함되어 있습니다. `available_workflows` 속성은 지원되는 모든 워크플로를 나열합니다: | |
| ```py | |
| pipeline_blocks = MyPipelineBlocks() | |
| pipeline_blocks.available_workflows | |
| # ['text2image', 'image2image', 'inpaint'] | |
| ``` | |
| `get_workflow`를 사용하여 특정 워크플로를 가져와 워크플로를 실행하는 특정 블록을 검사하고 디버깅합니다. | |
| ```py | |
| pipeline_blocks.get_workflow("inpaint") | |
| ``` | |
Xet Storage Details
- Size:
- 10.5 kB
- Xet hash:
- 5fef8f0e85171d59a77d6c11ec3bab7bc9f46e5e8b9076fd2b78a8343520ecb9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.