Diffusers documentation

HunyuanImage2.1

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

HunyuanImage2.1

HunyuanImage-2.1은 2K(2048 x 2048) 해상도의 이미지를 생성할 수 있는 17B 텍스트-이미지 모델입니다

HunyuanImage-2.1은 다음 변형으로 제공됩니다:

모델 유형모델 ID
HunyuanImage-2.1hunyuanvideo-community/HunyuanImage-2.1-Diffusers
HunyuanImage-2.1-Distilledhunyuanvideo-community/HunyuanImage-2.1-Distilled-Diffusers
HunyuanImage-2.1-Refinerhunyuanvideo-community/HunyuanImage-2.1-Refiner-Diffusers

Caching은 중간 결과를 저장하고 재사용하여 추론 속도를 높이는 데에도 도움이 될 수 있습니다.

HunyuanImage-2.1

HunyuanImage-2.1은 노이즈 제거 루프에서 Adaptive Projected Guidance (APG)와 Classifier-Free Guidance (CFG)를 결합하여 적용합니다. HunyuanImagePipeline에는 guider 구성 요소(Guider에 대해 자세히 알아보기)가 있으며, 런타임에 guidance_scale 파라미터를 받지 않습니다. guidance_scale과 같은 guider 관련 파라미터를 변경하려면 대신 guider 구성을 업데이트할 수 있습니다.

import torch
from diffusers import HunyuanImagePipeline

pipe = HunyuanImagePipeline.from_pretrained(
    "hunyuanvideo-community/HunyuanImage-2.1-Diffusers", 
    dtype=torch.bfloat16
)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

guider 객체를 검사할 수 있습니다:

>>> pipe.guider
AdaptiveProjectedMixGuidance {
  "_class_name": "AdaptiveProjectedMixGuidance",
  "_diffusers_version": "0.36.0.dev0",
  "adaptive_projected_guidance_momentum": -0.5,
  "adaptive_projected_guidance_rescale": 10.0,
  "adaptive_projected_guidance_scale": 10.0,
  "adaptive_projected_guidance_start_step": 5,
  "enabled": true,
  "eta": 0.0,
  "guidance_rescale": 0.0,
  "guidance_scale": 3.5,
  "start": 0.0,
  "stop": 1.0,
  "use_original_formulation": false
}

State:
  step: None
  num_inference_steps: None
  timestep: None
  count_prepared: 0
  enabled: True
  num_conditions: 2
  momentum_buffer: None
  is_apg_enabled: False
  is_cfg_enabled: True

다른 구성으로 guider를 업데이트하려면 new() 메서드를 사용합니다. 예를 들어, 모든 다른 기본 guidance 매개변수를 유지하면서 guidance_scale=5.0으로 이미지를 생성하려면:

import torch
from diffusers import HunyuanImagePipeline

pipe = HunyuanImagePipeline.from_pretrained(
    "hunyuanvideo-community/HunyuanImage-2.1-Diffusers", 
    dtype=torch.bfloat16
)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

# Update the guider configuration
pipe.guider = pipe.guider.new(guidance_scale=5.0)

prompt = (
    "A cute, cartoon-style anthropomorphic penguin plush toy with fluffy fur, standing in a painting studio, "
    "wearing a red knitted scarf and a red beret with the word 'Tencent' on it, holding a paintbrush with a "
    "focused expression as it paints an oil painting of the Mona Lisa, rendered in a photorealistic photographic style."
)

image = pipe(
    prompt=prompt, 
    num_inference_steps=50, 
    height=2048, 
    width=2048,
).images[0]
image.save("image.png")

HunyuanImage-2.1-Distilled

distilled_guidance_scale를 guidance-distilled 체크포인트와 함께 사용하세요.

import torch
from diffusers import HunyuanImagePipeline
pipe = HunyuanImagePipeline.from_pretrained("hunyuanvideo-community/HunyuanImage-2.1-Distilled-Diffusers", dtype=torch.bfloat16)
pipe = pipe.to("cuda")  # or "mps", "xpu", "cpu"

prompt = (
    "A cute, cartoon-style anthropomorphic penguin plush toy with fluffy fur, standing in a painting studio, "
    "wearing a red knitted scarf and a red beret with the word 'Tencent' on it, holding a paintbrush with a "
    "focused expression as it paints an oil painting of the Mona Lisa, rendered in a photorealistic photographic style."
)

out = pipe(
    prompt,
    num_inference_steps=8,
    distilled_guidance_scale=3.25,
    height=2048,
    width=2048,
    generator=generator,
).images[0]

HunyuanImagePipeline

클래스 diffusers.HunyuanImagePipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLHunyuanImagetext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2Tokenizertext_encoder_2: T5EncoderModeltokenizer_2: ByT5Tokenizertransformer: HunyuanImageTransformer2DModelguider: AdaptiveProjectedMixGuidance | None = Noneocr_guider: AdaptiveProjectedMixGuidance | None = None )

매개변수

  • transformer (HunyuanImageTransformer2DModel) — 인코딩된 이미지 레이턴트를 디노이즈하기 위한 조건부 Transformer (MMDiT) 아키텍처.
  • scheduler (FlowMatchEulerDiscreteScheduler) — transformer와 함께 사용하여 인코딩된 이미지 latents의 노이즈를 제거하는 데 사용되는 스케줄러.
  • vae (AutoencoderKLHunyuanImage) — 이미지를 잠재 표현으로 인코딩하고 디코딩하는 Variational Auto-Encoder (VAE) 모델.
  • text_encoder (Qwen2.5-VL-7B-Instruct) — 구체적으로 Qwen2.5-VL-7B-Instruct의 Qwen2.5-VL-7B-Instruct 변형입니다.
  • tokenizer (Qwen2Tokenizer) — [Qwen2Tokenizer] 클래스의 토크나이저입니다.
  • text_encoder_2 (T5EncoderModel) — T5EncoderModel 변형입니다.
  • tokenizer_2 (ByT5Tokenizer) — [ByT5Tokenizer] 클래스의 토크나이저
  • guider (AdaptiveProjectedMixGuidance) — 이미지 생성을 안내하는 데 사용할 [AdaptiveProjectedMixGuidance].
  • ocr_guider (AdaptiveProjectedMixGuidance, 선택 사항) — 텍스트 렌더링이 필요한 경우 이미지 생성을 안내하는 데 사용할 [AdaptiveProjectedMixGuidance]입니다.

텍스트에서 이미지 생성을 위한 HunyuanImage 파이프라인.

__call__

< >

( prompt: str | list[str] = Nonenegative_prompt: str | list[str] = Noneheight: int | None = Nonewidth: int | None = Nonenum_inference_steps: int = 50distilled_guidance_scale: float | None = 3.25sigmas: list[float] | None = Nonenum_images_per_prompt: int = 1generator: torch.Generator | list[torch.Generator] | None = Nonelatents: torch.Tensor | None = Noneprompt_embeds: torch.Tensor | None = Noneprompt_embeds_mask: torch.Tensor | None = Nonenegative_prompt_embeds: torch.Tensor | None = Nonenegative_prompt_embeds_mask: torch.Tensor | None = Noneprompt_embeds_2: torch.Tensor | None = Noneprompt_embeds_mask_2: torch.Tensor | None = Nonenegative_prompt_embeds_2: torch.Tensor | None = Nonenegative_prompt_embeds_mask_2: torch.Tensor | None = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, Any] | None = Nonecallback_on_step_end: Callable[[int, int], None] | None = Nonecallback_on_step_end_tensor_inputs: list[str] = ['latents'] ) → ~pipelines.hunyuan_image.HunyuanImagePipelineOutput or tuple

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 이미지 생성을 안내할 프롬프트입니다. 정의되지 않은 경우 prompt_embeds를 대신 전달해야 합니다.
  • negative_prompt (str 또는 list[str], 선택 사항) — 이미지 생성을 안내하지 않을 프롬프트입니다. 정의되지 않았고 negative_prompt_embeds도 제공되지 않은 경우, 빈 negative prompt를 사용합니다. guidance를 사용하지 않는 경우 무시됩니다. ).
  • height (int, 선택 사항, 기본값은 self.unet.config.sample_size * self.vae_scale_factor) — 생성된 이미지의 픽셀 단위 높이입니다. 최적의 결과를 위해 기본값은 1024로 설정됩니다.
  • width (int, 선택 사항, 기본값은 self.unet.config.sample_size * self.vae_scale_factor) — 생성된 이미지의 픽셀 단위 너비입니다. 최적의 결과를 위해 기본값은 1024로 설정되어 있습니다.
  • num_inference_steps (int, 선택 사항, 기본값 50) — 디노이징 단계의 수입니다. 디노이징 단계가 많을수록 일반적으로 더 높은 품질의 이미지를 생성하지만, 추론 속도가 느려집니다.
  • sigmas (list[float], 선택 사항) — set_timesteps 메서드에 sigmas 인수를 지원하는 스케줄러의 노이즈 제거 과정에 사용할 커스텀 시그마입니다. 정의되지 않은 경우, num_inference_steps가 전달될 때의 기본 동작이 사용됩니다.
  • distilled_guidance_scale (float, 선택 사항, 기본값 None) — 가이던스 디스틸레이션 모델에 사용할 가이던스 스케일 값입니다. 추론 시 노이즈 예측 리스케일링을 통해 가이던스 스케일을 적용하는 전통적인 classifier-free guidance와 달리, 가이던스 디스틸레이션 모델은 forward pass 중에 가이던스 스케일을 직접 입력 파라미터로 받습니다. distilled_guidance_scale > 1로 설정하면 가이던스가 활성화됩니다. 가이던스 스케일이 높을수록 prompt 텍스트와 밀접하게 연결된 이미지를 생성하도록 유도되지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. 가이던스 디스틸레이션 모델의 경우 이 파라미터는 필수입니다. 비디스틸레이션 모델의 경우 이 파라미터는 무시됩니다.
  • num_images_per_prompt (int, 선택 사항, 기본값 1) — 프롬프트당 생성할 이미지의 수입니다.
  • generator (torch.Generator 또는 list[torch.Generator], 선택 사항) — 생성을 결정적으로 만들기 위한 torch generator 하나 또는 목록
  • latents (torch.Tensor, 선택 사항) — 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 랜덤 generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_mask (torch.Tensor, 선택 사항) — 미리 생성된 텍스트 임베딩 마스크입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩 마스크가 생성됩니다.
  • prompt_embeds_2 (torch.Tensor, 선택) — ocr에 사용할 사전 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 ocr의 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_mask_2 (torch.Tensor, 선택 사항) — ocr용 사전 생성된 텍스트 임베딩 마스크입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 ocr용 텍스트 임베딩 마스크가 생성됩니다.
  • negative_prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 negative text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative_prompt_embeds가 생성됩니다.
  • negative_prompt_embeds_mask (torch.Tensor, 선택) — 미리 생성된 negative text embeddings mask입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative text embeddings mask가 생성됩니다.
  • negative_prompt_embeds_2 (torch.Tensor, 선택) — ocr용 사전 생성된 negative text embeddings입니다. 프롬프트 가중치와 같은 예를 들어 텍스트 입력을 쉽게 조정하는 데 사용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 ocr용 negative text embeddings가 생성됩니다.
  • negative_prompt_embeds_mask_2 (torch.Tensor, 선택) — ocr용 사전 생성된 negative text embeddings mask입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 prompt 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 ocr용 negative text embeddings mask가 생성됩니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~pipelines.qwenimage.QwenImagePipelineOutput를 반환할지 여부.
  • attention_kwargs (dict, 선택 사항) — 지정된 경우 diffusers.models.attention_processor의 self.processor에서 정의된 AttentionProcessor로 전달되는 kwargs 사전입니다.
  • callback_on_step_end (Callable, 선택 사항) — 추론 중 각 디노이징 단계의 끝에서 호출되는 함수입니다. 이 함수는 다음 인수를 받아 호출됩니다: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). callback_kwargs에는 callback_on_step_end_tensor_inputs로 지정된 모든 텐서 목록이 포함됩니다.
  • callback_on_step_end_tensor_inputs (List, 선택 사항) — callback_on_step_end 함수의 텐서 입력 목록입니다. 목록에 지정된 텐서는 callback_kwargs 인수로 전달됩니다. 파이프라인 클래스의 ._callback_tensor_inputs 속성에 나열된 변수만 포함할 수 있습니다.

반환값

~pipelines.hunyuan_image.HunyuanImagePipelineOutput 또는 tuple

return_dict가 True인 경우 ~pipelines.hunyuan_image.HunyuanImagePipelineOutput, 그렇지 않으면 tuple입니다. tuple을 반환할 경우 첫 번째 요소는 생성된 이미지의 목록입니다.

생성을 위해 파이프라인을 호출할 때 호출되는 함수.

예:

>>> import torch
>>> from diffusers import HunyuanImagePipeline

>>> pipe = HunyuanImagePipeline.from_pretrained(
...     "hunyuanvideo-community/HunyuanImage-2.1-Diffusers", torch_dtype=torch.bfloat16
... )
>>> pipe.to("cuda")
>>> prompt = "A cat holding a sign that says hello world"
>>> # Depending on the variant being used, the pipeline call will slightly vary.
>>> # Refer to the pipeline documentation for more details.
>>> image = pipe(prompt, negative_prompt="", num_inference_steps=50).images[0]
>>> image.save("hunyuanimage.png")

encode_prompt

< >

( prompt: str | list[str]device: torch.device | None = Nonebatch_size: int = 1num_images_per_prompt: int = 1prompt_embeds: torch.Tensor | None = Noneprompt_embeds_mask: torch.Tensor | None = Noneprompt_embeds_2: torch.Tensor | None = Noneprompt_embeds_mask_2: torch.Tensor | None = None )

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 인코딩할 프롬프트
  • device — (torch.device): torch device
  • batch_size (int) — 프롬프트의 배치 크기, 기본값은 1
  • num_images_per_prompt (int) — 프롬프트당 생성할 이미지 수
  • prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 텍스트 임베딩입니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_mask (torch.Tensor, 선택 사항) — 미리 생성된 텍스트 마스크입니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 마스크가 생성됩니다.
  • prompt_embeds_2 (torch.Tensor, 선택 사항) — ByT5에서 생성된 글리프 텍스트 임베딩입니다. 제공되지 않으면 prompt 입력 인수를 사용하여 self.tokenizer_2와 self.text_encoder_2로 생성됩니다.
  • prompt_embeds_mask_2 (torch.Tensor, 선택 사항) — ByT5에서 사전 생성된 글리프 텍스트 마스크입니다. 제공되지 않으면 prompt 입력 인수를 사용하여 self.tokenizer_2와 self.text_encoder_2로 생성됩니다.

HunyuanImageRefinerPipeline

클래스 diffusers.HunyuanImageRefinerPipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLHunyuanImageRefinertext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2Tokenizertransformer: HunyuanImageTransformer2DModelguider: AdaptiveProjectedMixGuidance | None = None )

매개변수

  • transformer (HunyuanImageTransformer2DModel) — 인코딩된 이미지 레이턴트를 디노이즈하기 위한 조건부 Transformer (MMDiT) 아키텍처.
  • scheduler (FlowMatchEulerDiscreteScheduler) — transformer와 함께 사용하여 인코딩된 이미지 latents의 노이즈를 제거하는 데 사용되는 스케줄러.
  • vae (AutoencoderKLHunyuanImageRefiner) — 잠재 표현으로 이미지를 인코딩 및 디코딩하는 Variational Auto-Encoder (VAE) 모델.
  • text_encoder (Qwen2.5-VL-7B-Instruct) — 구체적으로 Qwen2.5-VL-7B-Instruct의 Qwen2.5-VL-7B-Instruct 변형입니다.
  • tokenizer (Qwen2Tokenizer) — [Qwen2Tokenizer] 클래스의 토크나이저입니다.

텍스트에서 이미지 생성을 위한 HunyuanImage 파이프라인.

__call__

< >

( prompt: str | list[str] = Nonenegative_prompt: str | list[str] = Nonedistilled_guidance_scale: float | None = 3.25image: PipelineImageInput | None = Noneheight: int | None = Nonewidth: int | None = Nonenum_inference_steps: int = 4sigmas: list[float] | None = Nonenum_images_per_prompt: int = 1generator: torch.Generator | list[torch.Generator] | None = Nonelatents: torch.Tensor | None = Noneprompt_embeds: torch.Tensor | None = Noneprompt_embeds_mask: torch.Tensor | None = Nonenegative_prompt_embeds: torch.Tensor | None = Nonenegative_prompt_embeds_mask: torch.Tensor | None = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, Any] | None = Nonecallback_on_step_end: Callable[[int, int], None] | None = Nonecallback_on_step_end_tensor_inputs: list[str] = ['latents'] ) → ~pipelines.hunyuan_image.HunyuanImagePipelineOutput or tuple

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 이미지 생성을 안내할 프롬프트입니다. 정의되지 않은 경우 prompt_embeds를 대신 전달해야 합니다.
  • negative_prompt (str 또는 list[str], 선택) — 이미지 생성을 안내하지 않을 프롬프트입니다. 정의되지 않으면 빈 negative prompt를 사용합니다. guidance를 사용하지 않는 경우 무시됩니다.
  • distilled_guidance_scale (float, 선택 사항, 기본값 None) — 가이던스 디스틸레이션 모델에 사용할 가이던스 스케일 값입니다. 추론 시 노이즈 예측 리스케일링을 통해 가이던스 스케일을 적용하는 전통적인 classifier-free guidance와 달리, 가이던스 디스틸레이션 모델은 forward pass 중에 가이던스 스케일을 직접 입력 파라미터로 받습니다. distilled_guidance_scale > 1로 설정하면 가이던스가 활성화됩니다. 가이던스 스케일이 높을수록 prompt 텍스트와 밀접하게 연결된 이미지를 생성하도록 유도되지만, 일반적으로 이미지 품질이 낮아지는 대가를 치릅니다. 가이던스 디스틸레이션 모델의 경우 이 파라미터는 필수입니다. 비디스틸레이션 모델의 경우 이 파라미터는 무시됩니다.
  • image (PipelineImageInput, 선택 사항) — 정제할 입력 이미지입니다.
  • num_images_per_prompt (int, 선택 사항, 기본값 1) —
  • height (int, 선택 사항, 기본값은 self.unet.config.sample_size * self.vae_scale_factor) — 생성된 이미지의 픽셀 단위 높이입니다. 최적의 결과를 위해 기본값은 1024로 설정됩니다.
  • width (int, 선택 사항, 기본값은 self.unet.config.sample_size * self.vae_scale_factor) — 생성된 이미지의 픽셀 단위 너비입니다. 최적의 결과를 위해 기본값은 1024로 설정되어 있습니다.
  • num_inference_steps (int, 선택 사항, 기본값 50) — 디노이징 단계의 수입니다. 디노이징 단계가 많을수록 일반적으로 더 높은 품질의 이미지를 생성하지만, 추론 속도가 느려집니다.
  • sigmas (list[float], 선택 사항) — set_timesteps 메서드에 sigmas 인수를 지원하는 스케줄러의 노이즈 제거 과정에 사용할 커스텀 시그마입니다. 정의되지 않은 경우, num_inference_steps가 전달될 때의 기본 동작이 사용됩니다.
  • num_images_per_prompt (int, 선택 사항, 기본값 1) — 프롬프트당 생성할 이미지의 수입니다.
  • generator (torch.Generator 또는 list[torch.Generator], 선택 사항) — 생성을 결정적으로 만들기 위한 torch generator 하나 또는 목록
  • latents (torch.Tensor, 선택 사항) — 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 랜덤 generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
  • prompt_embeds (torch.Tensor, 선택) — 미리 생성된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_mask (torch.Tensor, 선택 사항) — prompt_embeds에 대한 어텐션 마스크입니다.
  • negative_prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 negative text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 negative_prompt_embeds가 생성됩니다.
  • negative_prompt_embeds_mask (torch.Tensor, 선택 사항) — negative_prompt_embeds에 대한 어텐션 마스크입니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~pipelines.qwenimage.QwenImagePipelineOutput를 반환할지 여부.
  • attention_kwargs (dict, 선택 사항) — 지정된 경우 diffusers.models.attention_processor의 self.processor에서 정의된 AttentionProcessor로 전달되는 kwargs 사전입니다.
  • callback_on_step_end (Callable, 선택 사항) — 추론 중 각 디노이징 단계의 끝에서 호출되는 함수입니다. 이 함수는 다음 인수를 받아 호출됩니다: callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict). callback_kwargs에는 callback_on_step_end_tensor_inputs로 지정된 모든 텐서 목록이 포함됩니다.
  • callback_on_step_end_tensor_inputs (List, 선택 사항) — callback_on_step_end 함수의 텐서 입력 목록입니다. 목록에 지정된 텐서는 callback_kwargs 인수로 전달됩니다. 파이프라인 클래스의 ._callback_tensor_inputs 속성에 나열된 변수만 포함할 수 있습니다.

반환값

~pipelines.hunyuan_image.HunyuanImagePipelineOutput 또는 tuple

return_dict가 True인 경우 ~pipelines.hunyuan_image.HunyuanImagePipelineOutput, 그렇지 않으면 tuple입니다. tuple을 반환할 경우 첫 번째 요소는 생성된 이미지의 목록입니다.

생성을 위해 파이프라인을 호출할 때 호출되는 함수.

예:

>>> import torch
>>> from diffusers import HunyuanImageRefinerPipeline

>>> pipe = HunyuanImageRefinerPipeline.from_pretrained(
...     "hunyuanvideo-community/HunyuanImage-2.1-Refiner-Diffusers", torch_dtype=torch.bfloat16
... )
>>> pipe.to("cuda")
>>> prompt = "A cat holding a sign that says hello world"
>>> image = load_image("path/to/image.png")
>>> # Depending on the variant being used, the pipeline call will slightly vary.
>>> # Refer to the pipeline documentation for more details.
>>> image = pipe(prompt, image=image, num_inference_steps=4).images[0]
>>> image.save("hunyuanimage.png")

encode_prompt

< >

( prompt: str | list[str] | None = Nonedevice: torch.device | None = Nonebatch_size: int = 1num_images_per_prompt: int = 1prompt_embeds: torch.Tensor | None = Noneprompt_embeds_mask: torch.Tensor | None = None )

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 인코딩할 프롬프트
  • device — (torch.device): torch device
  • batch_size (int) — 프롬프트의 배치 크기, 기본값은 1
  • num_images_per_prompt (int) — 프롬프트당 생성할 이미지 수
  • prompt_embeds (torch.Tensor, 선택 사항) — 미리 생성된 텍스트 임베딩입니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_mask (torch.Tensor, 선택 사항) — 미리 생성된 텍스트 마스크입니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 마스크가 생성됩니다.
  • prompt_embeds_2 (torch.Tensor, 선택 사항) — ByT5에서 생성된 글리프 텍스트 임베딩입니다. 제공되지 않으면 prompt 입력 인수를 사용하여 self.tokenizer_2와 self.text_encoder_2로 생성됩니다.
  • prompt_embeds_mask_2 (torch.Tensor, 선택 사항) — ByT5에서 사전 생성된 글리프 텍스트 마스크입니다. 제공되지 않으면 prompt 입력 인수를 사용하여 self.tokenizer_2와 self.text_encoder_2로 생성됩니다.

HunyuanImagePipelineOutput

클래스 diffusers.pipelines.hunyuan_image.pipeline_output.HunyuanImagePipelineOutput

< >

( images: list )

매개변수

  • images (list[PIL.Image.Image] 또는 np.ndarray) — batch_size 길이의 denoised PIL 이미지 목록 또는 (batch_size, height, width, num_channels) 형태의 numpy 배열. PIL 이미지 또는 numpy 배열은 diffusion 파이프라인의 denoised 이미지를 나타냅니다.

HunyuanImage 파이프라인의 출력 클래스입니다.

Update on GitHub