Diffusers documentation

HiDreamImage

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

HiDreamImage

HiDream.ai의 HiDream-I1

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

사용 가능한 모델

다음 모델들이 HiDreamImagePipeline 파이프라인에서 사용할 수 있습니다:

모델 이름설명
HiDream-ai/HiDream-I1-Full-
HiDream-ai/HiDream-I1-Dev-
HiDream-ai/HiDream-I1-Fast-

HiDreamImagePipeline

클래스 diffusers.HiDreamImagePipeline

< >

( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLtext_encoder: CLIPTextModelWithProjectiontokenizer: CLIPTokenizertext_encoder_2: CLIPTextModelWithProjectiontokenizer_2: CLIPTokenizertext_encoder_3: T5EncoderModeltokenizer_3: T5Tokenizertext_encoder_4: LlamaForCausalLMtokenizer_4: TokenizersBackendtransformer: HiDreamImageTransformer2DModel )

__call__

< >

( prompt: str | list[str] = Noneprompt_2: str | list[str] | None = Noneprompt_3: str | list[str] | None = Noneprompt_4: str | list[str] | None = Noneheight: int | None = Nonewidth: int | None = Nonenum_inference_steps: int = 50sigmas: list[float] | None = Noneguidance_scale: float = 5.0negative_prompt: str | list[str] | None = Nonenegative_prompt_2: str | list[str] | None = Nonenegative_prompt_3: str | list[str] | None = Nonenegative_prompt_4: str | list[str] | None = Nonenum_images_per_prompt: int | None = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.FloatTensor] = Noneprompt_embeds_t5: typing.Optional[torch.FloatTensor] = Noneprompt_embeds_llama3: typing.Optional[torch.FloatTensor] = Nonenegative_prompt_embeds_t5: typing.Optional[torch.FloatTensor] = Nonenegative_prompt_embeds_llama3: typing.Optional[torch.FloatTensor] = Nonepooled_prompt_embeds: typing.Optional[torch.FloatTensor] = Nonenegative_pooled_prompt_embeds: typing.Optional[torch.FloatTensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Trueattention_kwargs: dict[str, typing.Any] | None = Nonecallback_on_step_end: typing.Optional[typing.Callable[[int, int], NoneType]] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 128**kwargs ) → ~pipelines.hidream_image.HiDreamImagePipelineOutput or tuple

매개변수

  • prompt (str 또는 list[str], 선택 사항) — 이미지 생성을 안내할 프롬프트입니다. 정의되지 않은 경우 prompt_embeds를 대신 전달해야 합니다.
  • prompt_2 (str 또는 list[str], 선택) — tokenizer_2 및 text_encoder_2에 전송할 프롬프트입니다. 정의되지 않은 경우 prompt가 대신 사용됩니다.
  • prompt_3 (str 또는 list[str], 선택 사항) — tokenizer_3 및 text_encoder_3에 전송할 프롬프트입니다. 정의되지 않은 경우 prompt가 대신 사용됩니다.
  • prompt_4 (str 또는 list[str], 선택 사항) — tokenizer_4 및 text_encoder_4에 전송할 프롬프트입니다. 정의되지 않은 경우 prompt가 대신 사용됩니다.
  • 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가 전달될 때의 기본 동작이 사용됩니다.
  • guidance_scale (float, 선택 사항, 기본값 3.5) — 임베디드 가이던스 스케일은 guidance_scale > 1. 을 더 높이면 guidance_scale 모델이 prompt 에 더 부합하는 이미지를 생성하도록 장려하지만, 이미지 품질이 낮아지는 대가를 치릅니다.

    Guidance-distilled 모델은 guidance_scale > 1인 경우 true classifer-free guidance를 근사합니다. 자세한 내용은 논문을 참고하세요.

  • negative_prompt (str 또는 list[str], 선택 사항) — 이미지 생성을 안내하지 않을 프롬프트입니다. 정의되지 않은 경우 negative_prompt_embeds를 대신 전달해야 합니다. 가이던스를 사용하지 않을 때 무시됩니다(즉, true_cfg_scale가 1보다 크지 않으면 무시됩니다).
  • negative_prompt_2 (str 또는 list[str], 선택) — tokenizer_2 및 text_encoder_2에 전송할 이미지 생성을 유도하지 않을 프롬프트입니다. 정의되지 않은 경우, 모든 text-encoder에 negative_prompt가 사용됩니다.
  • negative_prompt_3 (str 또는 list[str], 선택 사항) — tokenizer_3 및 text_encoder_3에 전송할 이미지 생성을 유도하지 않을 프롬프트입니다. 정의되지 않은 경우, 모든 text-encoder에서 negative_prompt가 사용됩니다.
  • negative_prompt_4 (str 또는 list[str], 선택 사항) — tokenizer_4 및 text_encoder_4에 전송할 이미지 생성을 유도하지 않을 프롬프트입니다. 정의되지 않은 경우, 모든 text-encoder에서 negative_prompt가 사용됩니다.
  • num_images_per_prompt (int, 선택 사항, 기본값 1) — 프롬프트당 생성할 이미지의 수입니다.
  • generator (torch.Generator 또는 list[torch.Generator], 선택 사항) — 생성을 결정적으로 만들기 위한 torch generator 하나 또는 목록
  • latents (torch.FloatTensor, 선택 사항) — 이미지 생성의 입력으로 사용할 가우시안 분포에서 샘플링된 사전 생성된 노이즈 latents입니다. 동일한 생성을 다른 프롬프트로 조정하는 데 사용할 수 있습니다. 제공되지 않으면, 제공된 무작위 generator를 사용하여 샘플링하여 latents 텐서가 생성됩니다.
  • prompt_embeds_t5 (torch.FloatTensor, 선택) — 미리 생성된 T5 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • prompt_embeds_llama3 (torch.FloatTensor, 선택) — 미리 생성된 LLaMA3 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 텍스트 임베딩이 생성됩니다.
  • negative_prompt_embeds_t5 (torch.FloatTensor, 선택) — 미리 생성된 negative T5 텍스트 임베딩입니다. 예를 들어 프롬프트 가중치와 같은 텍스트 입력을 쉽게 조정하는 데 사용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 임베딩이 생성됩니다.
  • negative_prompt_embeds_llama3 (torch.FloatTensor, 선택) — 미리 생성된 negative LLaMA3 텍스트 임베딩입니다. 예를 들어 프롬프트 가중치와 같은 텍스트 입력을 쉽게 조정하는 데 사용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 임베딩이 생성됩니다.
  • pooled_prompt_embeds (torch.FloatTensor, 선택) — 미리 생성된 풀링된 텍스트 임베딩입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 prompt 입력 인자로부터 풀링된 텍스트 임베딩이 생성됩니다.
  • negative_pooled_prompt_embeds (torch.FloatTensor, 선택) — 미리 생성된 negative pooled text embeddings입니다. 텍스트 입력을 쉽게 조정하는 데 사용할 수 있으며, 예를 들어 프롬프트 가중치 설정에 활용할 수 있습니다. 제공되지 않으면 negative_prompt 입력 인자로부터 pooled negative_prompt_embeds가 생성됩니다.
  • output_type (str, 선택 사항, 기본값 "pil") — 이미지 생성의 출력 형식입니다. PIL: PIL.Image.Image 또는 np.array 중 하나를 선택합니다.
  • return_dict (bool, 선택 사항, 기본값 True) — 일반 튜플 대신 ~pipelines.flux.FluxPipelineOutput를 반환할지 여부.
  • 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 속성에 나열된 변수만 포함할 수 있습니다.
  • max_sequence_length (int, 기본값 128) — prompt에 사용할 최대 시퀀스 길이입니다.

반환값

~pipelines.hidream_image.HiDreamImagePipelineOutput 또는 tuple

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

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

예:

>>> import torch
>>> from transformers import AutoTokenizer, LlamaForCausalLM
>>> from diffusers import HiDreamImagePipeline

>>> tokenizer_4 = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3.1-8B-Instruct")
>>> text_encoder_4 = LlamaForCausalLM.from_pretrained(
...     "meta-llama/Meta-Llama-3.1-8B-Instruct",
...     output_hidden_states=True,
...     output_attentions=True,
...     torch_dtype=torch.bfloat16,
... )

>>> pipe = HiDreamImagePipeline.from_pretrained(
...     "HiDream-ai/HiDream-I1-Full",
...     tokenizer_4=tokenizer_4,
...     text_encoder_4=text_encoder_4,
...     torch_dtype=torch.bfloat16,
... )
>>> pipe.enable_model_cpu_offload()

>>> image = pipe(
...     'A cat holding a sign that says "Hi-Dreams.ai".',
...     height=1024,
...     width=1024,
...     guidance_scale=5.0,
...     num_inference_steps=50,
...     generator=torch.Generator("cuda").manual_seed(0),
... ).images[0]
>>> image.save("output.png")

HiDreamImagePipelineOutput

class diffusers.pipelines.hidream_image.pipeline_output.HiDreamImagePipelineOutput

< >

( images: list[PIL.Image.Image] | numpy.ndarray )

매개변수

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

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

Update on GitHub