Diffusers documentation

EasyAnimate

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

EasyAnimate

Alibaba PAI による EasyAnimate。

GitHubページの説明: EasyAnimateは、Diffusion TransformerのベースラインモデルおよびLoraモデルの学習、ならびにAI画像や動画の生成を目的として設計された、transformerアーキテクチャに基づくパイプラインです。事前学習済みのEasyAnimateモデルからの直接予測に対応しており、さまざまな解像度で、長さ約6秒、8fpsの動画を生成できます(EasyAnimateV5.1、1〜49フレーム)。さらに、ユーザーは特定のスタイル変換用に独自のベースラインモデルやLoraモデルを学習させることもできます。

このパイプラインは bubbliiiing によって提供されました。元のコードベースは こちら で確認できます。元の重みは hf.co/alibaba-pai 配下で確認できます。

テキストから動画への変換と、動画から動画への変換用の公式EasyAnimateチェックポイントが2つあります。

チェックポイント推奨される推論用データ型
alibaba-pai/EasyAnimateV5.1-12b-zhtorch.float16
alibaba-pai/EasyAnimateV5.1-12b-zh-InPtorch.float16

画像から動画への変換および動画から動画への変換に対応する公式のEasyAnimateチェックポイントが1つ利用可能です。

チェックポイント推奨される推論用データ型
alibaba-pai/EasyAnimateV5.1-12b-zh-InPtorch.float16

control-to-video用の公式EasyAnimateチェックポイントは2つ利用可能です。

チェックポイント推奨される推論用データ型
alibaba-pai/EasyAnimateV5.1-12b-zh-Controltorch.float16
alibaba-pai/EasyAnimateV5.1-12b-zh-Control-Cameratorch.float16

EasyAnimateV5.1 シリーズについて:

  • テキストトゥビデオ(T2V)とイメージトゥビデオ(I2V)は、複数の解像度に対応しています。幅と高さは 256 から 1024 まで変更できます。
  • T2VモデルとI2Vモデルの両方は、1〜49フレームでの生成に対応しており、この範囲のフレーム数で最も良好な結果が得られます。動画の書き出しには8 FPSでの出力を推奨します。

量子化

Quantizationは、モデルの重みを低精度のデータ型で保存することで、非常に大規模なモデルのメモリ要件を軽減するのに役立ちます。ただし、動画モデルによって、Quantizationが動画の品質に与える影響は異なります。

サポートされている量子化バックエンドと、ユースケースに対応する量子化バックエンドの選択について詳しくは、Quantizationの概要を参照してください。以下の例では、bitsandbytesを使用して量子化されたEasyAnimatePipelineを読み込んで推論を実行する方法を示しています。

import torch
from diffusers import BitsAndBytesConfig as DiffusersBitsAndBytesConfig, EasyAnimateTransformer3DModel, EasyAnimatePipeline
from diffusers.utils import export_to_video

quant_config = DiffusersBitsAndBytesConfig(load_in_8bit=True)
transformer_8bit = EasyAnimateTransformer3DModel.from_pretrained(
    "alibaba-pai/EasyAnimateV5.1-12b-zh",
    subfolder="transformer",
    quantization_config=quant_config,
    dtype=torch.float16,
)

pipeline = EasyAnimatePipeline.from_pretrained(
    "alibaba-pai/EasyAnimateV5.1-12b-zh",
    transformer=transformer_8bit,
    dtype=torch.float16,
    device_map="balanced",
)

prompt = "A cat walks on the grass, realistic style."
negative_prompt = "bad detailed"
video = pipeline(prompt=prompt, negative_prompt=negative_prompt, num_frames=49, num_inference_steps=30).frames[0]
export_to_video(video, "cat.mp4", fps=8)

EasyAnimatePipeline

クラス diffusers.EasyAnimatePipeline

< >

( vae: AutoencoderKLMagvittext_encoder: transformers.models.qwen2_vl.modeling_qwen2_vl.Qwen2VLForConditionalGeneration | transformers.models.bert.modeling_bert.BertModeltokenizer: transformers.models.qwen2.tokenization_qwen2.Qwen2Tokenizer | transformers.models.bert.tokenization_bert.BertTokenizertransformer: EasyAnimateTransformer3DModelscheduler: FlowMatchEulerDiscreteScheduler )

パラメータ

  • vae (AutoencoderKLMagvit) — 潜在表現へのエンコードとデコードを行う、動画用の変分オートエンコーダ(VAE)モデル。
  • text_encoder (~transformers.Qwen2VLForConditionalGeneration, ~transformers.BertModel | None) — EasyAnimate は V5.1 で qwen2 vl を使用しています。
  • tokenizer (~transformers.Qwen2Tokenizer, ~transformers.BertTokenizer | None) — テキストをトークン化するためのQwen2TokenizerまたはBertTokenizer。
  • transformer (EasyAnimateTransformer3DModel) — EasyAnimate Team によって設計された EasyAnimate モデルです。
  • scheduler (FlowMatchEulerDiscreteScheduler) — EasyAnimate と組み合わせて使用し、エンコードされた画像の潜在変数からノイズを除去するためのスケジューラです。

EasyAnimate を使用したテキストから動画への生成を行う Pipeline です。

このモデルは DiffusionPipeline を継承しています。すべてのパイプラインに対してライブラリが実装している汎用的なメソッド(ダウンロードや保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。

EasyAnimateはV5.1で1つのテキストエンコーダーqwen2 vlを使用しています。

__call__

< >

( prompt: str | list[str] = Nonenum_frames: int | None = 49height: int | None = 512width: int | None = 512num_inference_steps: int | None = 50guidance_scale: float | None = 5.0negative_prompt: str | list[str] | None = Nonenum_images_per_prompt: int | None = 1eta: float | None = 0.0generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonetimesteps: list[int] | None = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_attention_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_attention_mask: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Truecallback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = Nonecallback_on_step_end_tensor_inputs: list[str] = ['latents']guidance_rescale: float = 0.0 ) → StableDiffusionPipelineOutput or tuple

パラメータ

  • prompt (str または list[str]、省略可) — 画像や動画の生成を導くためのテキストプロンプトです。指定しない場合は、代わりに prompt_embeds を使用します。
  • num_frames (int, 任意) — 生成される動画の長さ(フレーム数)。
  • height (int, 任意) — 生成される画像の高さ(ピクセル単位)。
  • width (int, 任意) — 生成される画像の幅(ピクセル単位)。
  • num_inference_steps (int、任意、デフォルト値は 50)— 生成時のデノイジングステップ数です。ステップ数が多いほど、一般的には高品質な画像が得られますが、推論速度は低下します。
  • guidance_scale (float、任意、デフォルト値は 5.0) — モデルがプロンプトに沿った出力を生成するよう促します。値を高くすると、画像の品質が低下する可能性があります。
  • negative_prompt (str または list[str]、省略可) — 生成時に除外する内容を指定するプロンプトです。指定しない場合、negative_prompt_embeds が使用されます。
  • num_images_per_prompt (int、任意、デフォルトは 1)— 各プロンプトに対して生成する画像の数。
  • eta (float, 省略可、デフォルト値は 0.0) — DDIM スケジューリングに適用されます。関連する文献の eta パラメータによって制御されます。
  • generator (torch.Generator または list[torch.Generator]、任意) — 画像生成の再現性を確保するためのジェネレーター。
  • latents (torch.Tensor, 任意) — 生成を条件付けするための事前定義済みの潜在テンソル。
  • prompt_embeds (torch.Tensor, 任意) — プロンプトのテキスト埋め込みです。プロンプト文字列の入力を上書きし、より柔軟な指定を可能にします。
  • negative_prompt_embeds (torch.Tensor, 任意) — ネガティブプロンプト用の埋め込み。定義されている場合、文字列入力を上書きします。
  • prompt_attention_mask (torch.Tensor, 任意) — プライマリープロンプト埋め込み用のアテンションマスクです。
  • negative_prompt_attention_mask (torch.Tensor, 任意) — ネガティブプロンプトの埋め込みに対するアテンションマスクです。
  • output_type (str、任意、デフォルト値は “latent”) — 生成される出力の形式。PIL イメージまたは NumPy 配列のいずれかです。
  • return_dict (bool、任意、デフォルトは True) — True の場合、構造化された出力を返します。それ以外の場合は、単純なタプルを返します。
  • callback_on_step_end (Callable, 任意) — 各デノイジングステップの終了時に呼び出される関数。
  • callback_on_step_end_tensor_inputs (list[str]、省略可) — コールバック関数の呼び出しに含めるテンソル名。
  • guidance_rescale (float、任意、デフォルト値は 0.0)— guidance scale に基づいてノイズレベルを調整します。
  • timesteps (list[int]、任意) — ノイズ除去プロセスに使用するカスタムなタイムステップ。定義されていない場合、num_inference_steps に対するスケジューラーのデフォルトスケジュールが使用されます。

戻り値

StableDiffusionPipelineOutput または tuple

If return_dict is True, StableDiffusionPipelineOutput is returned, otherwise a tuple is returned where the first element is a list with the generated images and the second element is a list of bools indicating whether the corresponding generated image contains “not-safe-for-work” (nsfw) content.

提供されたプロンプトに基づいて、EasyAnimate パイプラインを使用して画像または動画を生成します。

例:

>>> import torch
>>> from diffusers import EasyAnimatePipeline
>>> from diffusers.utils import export_to_video

>>> # Models: "alibaba-pai/EasyAnimateV5.1-12b-zh"
>>> pipe = EasyAnimatePipeline.from_pretrained(
...     "alibaba-pai/EasyAnimateV5.1-7b-zh-diffusers", torch_dtype=torch.float16
... ).to("cuda")
>>> prompt = (
...     "A panda, dressed in a small, red jacket and a tiny hat, sits on a wooden stool in a serene bamboo forest. "
...     "The panda's fluffy paws strum a miniature acoustic guitar, producing soft, melodic tunes. Nearby, a few other "
...     "pandas gather, watching curiously and some clapping in rhythm. Sunlight filters through the tall bamboo, "
...     "casting a gentle glow on the scene. The panda's face is expressive, showing concentration and joy as it plays. "
...     "The background includes a small, flowing stream and vibrant green foliage, enhancing the peaceful and magical "
...     "atmosphere of this unique musical performance."
... )
>>> sample_size = (512, 512)
>>> video = pipe(
...     prompt=prompt,
...     guidance_scale=6,
...     negative_prompt="bad detailed",
...     height=sample_size[0],
...     width=sample_size[1],
...     num_inference_steps=50,
... ).frames[0]
>>> export_to_video(video, "output.mp4", fps=8)

encode_prompt

< >

( prompt: str | list[str]num_images_per_prompt: int = 1do_classifier_free_guidance: bool = Truenegative_prompt: str | list[str] | None = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_attention_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_attention_mask: typing.Optional[torch.Tensor] = Nonedevice: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = Nonemax_sequence_length: int = 256 )

パラメータ

  • prompt (str または list[str]、省略可能) — エンコードするプロンプト
  • device — (torch.device): torch デバイス
  • dtype (torch.dtype) — torch の dtype
  • num_images_per_prompt (int) — 1つのプロンプトに対して生成する画像の数
  • do_classifier_free_guidance (bool) — classifier free guidance を使用するかどうか
  • negative_prompt (str または list[str]、省略可) — 画像生成をガイドしないプロンプトです。未定義の場合、代わりに negative_prompt_embeds を渡す必要があります。ガイダンスを使用していない場合は無視されます(guidance_scale が 1 未満の場合は無視されます)。
  • prompt_embeds (torch.Tensor, 任意) — 事前に生成されたテキスト埋め込み。テキスト入力の調整、例えばプロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、prompt 入力引数からテキスト埋め込みが生成されます。
  • negative_prompt_embeds (torch.Tensor, 任意) — 事前に生成されたネガティブなテキスト埋め込みです。テキスト入力の調整、例えばプロンプトの重み付けなどを簡単に実行できます。指定されない場合、negative_prompt 入力引数から negative_prompt_embeds が生成されます。
  • prompt_attention_mask (torch.Tensor, 任意) — プロンプト用のアテンションマスクです。prompt_embeds を直接渡す場合に必要です。
  • negative_prompt_attention_mask (torch.Tensor, 任意) — ネガティブプロンプト用のアテンションマスクです。negative_prompt_embeds を直接渡す場合に必要です。
  • max_sequence_length (int、任意) — プロンプトに使用する最大シーケンス長。

プロンプトをテキストエンコーダーの隠れ状態にエンコードします。

EasyAnimatePipelineOutput

クラス diffusers.pipelines.easyanimate.pipeline_output.EasyAnimatePipelineOutput

< >

( frames: Tensor )

パラメータ

  • frames (torch.Tensor, np.ndarray, or list[list[PIL.Image.Image]]) — 動画出力のリストです。batch_size, 長のネストされたリストであり、各サブリストが num_frames. 長のノイズ除去済み PIL 画像シーケンスを含む形式をとることもできます。また、(batch_size, num_frames, channels, height, width) の形状を持つ NumPy 配列や Torch テンソルとしても指定できます。

EasyAnimate パイプライン用の出力クラスです。

Update on GitHub