Diffusers 文件

HiDreamImage

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

HiDreamImage

HiDream-I1 by HiDream.ai

請務必檢視排程器 指南,瞭解如何權衡排程器速度和質量,並參閱在管道之間重用元件部分,瞭解如何高效地將相同元件載入到多個管道中。

可用模型

以下模型適用於 HiDreamImagePipeline 管道

模型名稱 描述
HiDream-ai/HiDream-I1-Full -
HiDream-ai/HiDream-I1-Dev -
HiDream-ai/HiDream-I1-Fast -

HiDreamImagePipeline

class diffusers.HiDreamImagePipeline

< >

( scheduler: FlowMatchEulerDiscreteScheduler vae: AutoencoderKL text_encoder: CLIPTextModelWithProjection tokenizer: CLIPTokenizer text_encoder_2: CLIPTextModelWithProjection tokenizer_2: CLIPTokenizer text_encoder_3: T5EncoderModel tokenizer_3: T5Tokenizer text_encoder_4: LlamaForCausalLM tokenizer_4: PreTrainedTokenizerFast transformer: HiDreamImageTransformer2DModel )

__call__

< >

( prompt: typing.Union[str, typing.List[str]] = None prompt_2: typing.Union[str, typing.List[str], NoneType] = None prompt_3: typing.Union[str, typing.List[str], NoneType] = None prompt_4: typing.Union[str, typing.List[str], NoneType] = None height: typing.Optional[int] = None width: typing.Optional[int] = None num_inference_steps: int = 50 sigmas: typing.Optional[typing.List[float]] = None guidance_scale: float = 5.0 negative_prompt: typing.Union[str, typing.List[str], NoneType] = None negative_prompt_2: typing.Union[str, typing.List[str], NoneType] = None negative_prompt_3: typing.Union[str, typing.List[str], NoneType] = None negative_prompt_4: typing.Union[str, typing.List[str], NoneType] = None num_images_per_prompt: typing.Optional[int] = 1 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None latents: typing.Optional[torch.FloatTensor] = None prompt_embeds_t5: typing.Optional[torch.FloatTensor] = None prompt_embeds_llama3: typing.Optional[torch.FloatTensor] = None negative_prompt_embeds_t5: typing.Optional[torch.FloatTensor] = None negative_prompt_embeds_llama3: typing.Optional[torch.FloatTensor] = None pooled_prompt_embeds: typing.Optional[torch.FloatTensor] = None negative_pooled_prompt_embeds: typing.Optional[torch.FloatTensor] = None output_type: typing.Optional[str] = 'pil' return_dict: bool = True attention_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None callback_on_step_end: typing.Optional[typing.Callable[[int, int, typing.Dict], NoneType]] = None callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'] max_sequence_length: int = 128 **kwargs ) ~pipelines.hidream_image.HiDreamImagePipelineOutput or tuple

引數

  • prompt (strList[str], 可選) — 用於引導影像生成的提示詞。如果未定義,則必須傳入 prompt_embeds
  • prompt_2 (strList[str], 可選) — 要傳送到 tokenizer_2text_encoder_2 的提示詞。如果未定義,將使用 prompt 代替。
  • prompt_3 (strList[str], 可選) — 要傳送到 tokenizer_3text_encoder_3 的提示詞。如果未定義,將使用 prompt 代替。
  • prompt_4 (strList[str], 可選) — 要傳送到 tokenizer_4text_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], 可選) — 用於去噪過程的自定義 sigmas,適用於支援 set_timesteps 方法中 sigmas 引數的排程器。如果未定義,將使用傳入 num_inference_steps 時的預設行為。
  • guidance_scale (float, 可選, 預設為 3.5) — 如 Classifier-Free Diffusion Guidance 中定義的引導比例。guidance_scale 定義為 Imagen Paper 中公式 2 的 w。透過設定 guidance_scale > 1 啟用引導比例。較高的引導比例鼓勵生成與文字 prompt 密切相關的影像,通常以犧牲較低影像質量為代價。
  • negative_prompt (strList[str], 可選) — 用於不引導影像生成的提示詞。如果未定義,則必須傳入 negative_prompt_embeds 代替。在使用非引導模式時(即如果 true_cfg_scale 不大於 1),此引數將被忽略。
  • negative_prompt_2 (strList[str], 可選) — 要傳送到 tokenizer_2text_encoder_2 的不引導影像生成的提示詞。如果未定義,所有文字編碼器都將使用 negative_prompt
  • negative_prompt_3 (strList[str], 可選) — 要傳送到 tokenizer_3text_encoder_3 的不引導影像生成的提示詞。如果未定義,所有文字編碼器都將使用 negative_prompt
  • negative_prompt_4 (strList[str], 可選) — 要傳送到 tokenizer_4text_encoder_4 的不引導影像生成的提示詞。如果未定義,所有文字編碼器都將使用 negative_prompt
  • num_images_per_prompt (int, 可選, 預設為 1) — 每個提示詞生成的影像數量。
  • generator (torch.GeneratorList[torch.Generator], 可選) — 一個或多個 torch 生成器,用於使生成具有確定性。
  • latents (torch.FloatTensor, 可選) — 預生成的含噪潛在向量,從高斯分佈中取樣,用作影像生成的輸入。可用於透過不同提示詞調整同一生成。如果未提供,將使用提供的隨機 generator 取樣生成一個潛在向量張量。
  • prompt_embeds (torch.FloatTensor, 可選) — 預生成的文字嵌入。可用於輕鬆調整文字輸入,例如提示詞權重。如果未提供,將從prompt輸入引數生成文字嵌入。
  • negative_prompt_embeds (torch.FloatTensor, 可選) — 預生成的負面文字嵌入。可用於輕鬆調整文字輸入,例如提示詞權重。如果未提供,將從negative_prompt輸入引數生成負面文字嵌入。
  • pooled_prompt_embeds (torch.FloatTensor, 可選) — 預生成的池化文字嵌入。可用於輕鬆調整文字輸入,例如提示詞權重。如果未提供,將從prompt輸入引數生成池化文字嵌入。
  • negative_pooled_prompt_embeds (torch.FloatTensor, 可選) — 預生成的負面池化文字嵌入。可用於輕鬆調整文字輸入,例如提示詞權重。如果未提供,將從negative_prompt輸入引數生成負面池化文字嵌入。
  • output_type (str, 可選, 預設為"pil") — 生成影像的輸出格式。選擇PIL: PIL.Image.Imagenp.array
  • return_dict (bool, 可選, 預設為True) — 是否返回~pipelines.flux.FluxPipelineOutput而不是普通元組。
  • attention_kwargs (dict, 可選) — 一個 kwargs 字典,如果指定,將作為self.processor下定義的AttentionProcessor的引數傳遞給diffusers.models.attention_processor
  • 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.HiDreamImagePipelineOutputtuple

如果return_dict為 True,則為~pipelines.hidream_image.HiDreamImagePipelineOutput,否則為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")

disable_vae_slicing

< >

( )

停用切片 VAE 解碼。如果之前啟用了 enable_vae_slicing,此方法將返回一步計算解碼。

disable_vae_tiling

< >

( )

停用平鋪 VAE 解碼。如果之前啟用了 enable_vae_tiling,此方法將恢復一步計算解碼。

enable_vae_slicing

< >

( )

啟用切片 VAE 解碼。啟用此選項後,VAE 會將輸入張量分片,分步計算解碼。這有助於節省一些記憶體並允許更大的批次大小。

enable_vae_tiling

< >

( )

啟用平鋪 VAE 解碼。啟用此選項後,VAE 將把輸入張量分割成瓦片,分多步計算編碼和解碼。這對於節省大量記憶體和處理更大的影像非常有用。

HiDreamImagePipelineOutput

class diffusers.pipelines.hidream_image.pipeline_output.HiDreamImagePipelineOutput

< >

( images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray] )

引數

  • images (List[PIL.Image.Image]np.ndarray) — 長度為batch_size的去噪PIL影像列表或形狀為(batch_size, height, width, num_channels)的numpy陣列。PIL影像或numpy陣列表示擴散管道的去噪影像。

HiDreamImage 管道的輸出類。

< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.