Diffusers documentation
HiDreamImage
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
< source >( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLtext_encoder: CLIPTextModelWithProjectiontokenizer: CLIPTokenizertext_encoder_2: CLIPTextModelWithProjectiontokenizer_2: CLIPTokenizertext_encoder_3: T5EncoderModeltokenizer_3: T5Tokenizertext_encoder_4: LlamaForCausalLMtokenizer_4: TokenizersBackendtransformer: HiDreamImageTransformer2DModel )
__call__
< source >( 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, optional, defaults to 3.5) — Embedded guiddance scale is enabled by settingguidance_scale> 1. Higherguidance_scaleencourages a model to generate images more aligned withpromptat the expense of lower image quality.Guidance-distilled モデルは、
guidance_scale> 1 の場合に、真の 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に送信する、画像生成を導かないためのプロンプトです。定義されていない場合、すべてのテキストエンコーダーで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 ジェネレーター1つまたはリスト。 - latents (
torch.FloatTensor, 任意) — 画像生成の入力として使用する、ガウス分布からサンプリングされた事前生成されたノイジーな潜在変数です。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダムgeneratorを使用してサンプリングを行い、潜在変数テンソルが生成されます。 - prompt_embeds_t5 (
torch.FloatTensor、任意) — 事前生成済みの T5 テキスト埋め込み。テキスト入力の調整、例 プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、prompt入力引数からテキスト埋め込みが生成されます。 - prompt_embeds_llama3 (
torch.FloatTensor、任意) — 事前に生成された LLaMA3 のテキスト埋め込み。テキスト入力の調整、例えばプロンプトの重み付けなどを容易に行うことができます。 指定されない場合、prompt入力引数からテキスト埋め込みが生成されます。 - negative_prompt_embeds_t5 (
torch.FloatTensor, 省略可) — 事前に生成された負の T5 テキスト埋め込み。テキスト入力の調整、例えばプロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、negative_prompt入力引数から埋め込みが生成されます。 - negative_prompt_embeds_llama3 (
torch.FloatTensor, 任意) — 事前生成された負の LLaMA3 テキスト埋め込み。テキスト入力の調整、例えばプロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、negative_prompt入力引数から埋め込みが生成されます。 - pooled_prompt_embeds (
torch.FloatTensor, 任意) — 事前に生成されたプールのテキスト埋め込み。テキスト入力の調整、例えばプロンプトの重み付けなどに簡単に使用できます。 指定されない場合、prompt入力引数からプールのテキスト埋め込みが生成されます。 - negative_pooled_prompt_embeds (
torch.FloatTensor, 任意) — 事前に生成されたネガティブなプーリング済みテキスト埋め込み。テキスト入力の調整、例えばプロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、negative_prompt入力引数からプーリング済み 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 を返します。タプルを返す場合、最初の要素は生成された画像のリストです。
生成用のパイプラインを呼び出したときに実行される関数。
例:
>>> 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
クラス diffusers.pipelines.hidream_image.pipeline_output.HiDreamImagePipelineOutput
< source >( images: list[PIL.Image.Image] | numpy.ndarray )
HiDreamImage パイプライン用の出力クラスです。