Diffusers documentation

AutoPipeline

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

AutoPipeline

AutoPipeline는 태스크와 모델을 기반으로 올바른 파이프라인 하위 클래스를 자동으로 선택하는 태스크-모델 파이프라인입니다. 특정 파이프라인 하위 클래스 이름을 알지 못해도 다양한 파이프라인 하위 클래스를 로드하는 복잡성을 처리합니다.

이는 모델에 따라 파이프라인 하위 클래스를 자동으로 선택하는 모델 전용 파이프라인인 DiffusionPipeline과는 다릅니다.

AutoPipelineForImage2Image.from_pretrained(model_id)
        |
        +-- read model_index.json  (e.g. StableDiffusionXLPipeline)
        +-- task mapping           (image-to-image)
        |
        v
StableDiffusionXLImg2ImgPipeline   // returned instance

AutoPipelineForImage2Image는 이미지-이미지 작업에만 사용할 수 있는 작업별 하위 클래스(예: StableDiffusionXLImg2ImgPipeline)를 반환합니다.

import torch
from diffusers import AutoPipelineForImage2Image

pipeline = AutoPipelineForImage2Image.from_pretrained(
  "RunDiffusion/Juggernaut-XL-v9", dtype=torch.bfloat16, device_map="cuda",  # or "mps", "xpu", "cpu"
)
print(pipeline)
# StableDiffusionXLImg2ImgPipeline {
#   "_class_name": "StableDiffusionXLImg2ImgPipeline",
#   ...
# }

DiffusionPipeline로 동일한 모델을 로드하면 기본 텍스트-이미지 서브클래스인 StableDiffusionXLPipeline이 반환됩니다. 해당 파이프라인은 텍스트-이미지 작업에 사용됩니다. 이미지-이미지 또는 인페인팅 작업의 경우 AutoPipelineForImage2Image 또는 AutoPipelineForInpainting과 같은 작업 AutoPipeline을 로드하거나, 해당 작업에 맞는 특정 서브클래스를 로드하세요.

import torch
from diffusers import DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained(
  "RunDiffusion/Juggernaut-XL-v9", dtype=torch.bfloat16, device_map="cuda",  # or "mps", "xpu", "cpu"
)
print(pipeline)
# StableDiffusionXLPipeline {
#   "_class_name": "StableDiffusionXLPipeline",
#   ...
# }

from_pipe로 작업 전환

작업용 AutoPipeline을 한 번 로드한 후, from_pipe()를 사용하여 가중치를 다시 다운로드하지 않고 작업을 전환할 수 있습니다. 구성 요소는 소스 파이프라인에서 재사용됩니다.

import torch
from diffusers import AutoPipelineForText2Image, AutoPipelineForImage2Image

pipeline_t2i = AutoPipelineForText2Image.from_pretrained(
  "RunDiffusion/Juggernaut-XL-v9", dtype=torch.bfloat16, device_map="cuda",  # or "mps", "xpu", "cpu"
)
pipeline_i2i = AutoPipelineForImage2Image.from_pipe(pipeline_t2i)

자세한 내용은 여러 파이프라인에서 모델 재사용을 참조하세요.

모델이 지원되는지 확인하려면 mappings를 확인하세요. 지원되지 않는 모델을 로드하려고 하면 오류가 반환됩니다.

import torch
from diffusers import AutoPipelineForImage2Image

pipeline = AutoPipelineForImage2Image.from_pretrained(
    "openai/shap-e-img2img", dtype=torch.float16,
)
"ValueError: AutoPipeline can't find a pipeline linked to ShapEImg2ImgPipeline for None"

AutoPipeline 클래스에는 네 가지 유형이 있습니다:

각 클래스에는 사전 정의된 매핑이 포함되어 있으며, 이를 통해 파이프라인을 해당 작업에 특화된 하위 클래스와 연결합니다.

from_pretrained()이 호출되면 model_index.json 파일에서 클래스 이름을 추출하고, 매핑을 기반으로 해당 작업에 적합한 pipeline 하위 클래스를 선택합니다.

Update on GitHub