Diffusers documentation

Kandinsky 6

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.43.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Kandinsky 6

Kandinsky 6 は Kandinsky Lab による動画生成モデルのファミリーです。メインモデルは、単一のマルチモーダル拡散トランスフォーマーを用いて、テキストまたは参照画像から動画と同期した音声を生成します。動画と音声の潜在変数は、2つのモーダル間で相互にクロスアテンションを行う融合ブロックを通じて同時にノイズ除去され、それぞれが独自の Qwen2.5-VL テキストブランチと CLIP のプーリング埋め込みで条件付けられます。また、別個の超解像モデルが、因果的な 3D K-VAE の潜在空間において、生成された動画をタイル単位でアップスケーリングします。

Hub上のKandinsky Lab組織では、ベースモデルとスーパーリゾリューションモデルの両方に関する、flow-matching版および蒸留版を含む、公式チェックポイントの一式を確認できます。

蒸留済みチェックポイントは、少ステップのPiflowSchedulerに同梱されており、guidance_scale=1.0で実行する必要があります。

利用可能なモデル

モデルパイプライン注記
kandinskylab/Kandinsky-6.0-Pro-5s-DiffusersKandinsky6TI2VAPipelineFlow matching、guidance_scale=5.0、50ステップ
kandinskylab/Kandinsky-6.0-Pro-distill-5s-DiffusersKandinsky6TI2VAPipeline蒸留済み、guidance_scale=1.0、10ステップ
kandinskylab/Kandinsky-6.0-Lite-5s-DiffusersKandinsky6TI2VAPipelineFlow matching、guidance_scale=5.0、50ステップ
kandinskylab/Kandinsky-6.0-Lite-distill-5s-DiffusersKandinsky6TI2VAPipeline蒸留済み、guidance_scale=1.0、10ステップ
kandinskylab/Kandinsky-6.0-Pro-pretrain-5s-DiffusersKandinsky6TI2VAPipelineFlow matching、guidance_scale=5.0、50ステップ
kandinskylab/Kandinsky-6.0-Lite-pretrain-5s-DiffusersKandinsky6TI2VAPipelineFlow matching、guidance_scale=5.0、50ステップ
kandinskylab/Kandinsky-6.0-VSR-5s-DiffusersKandinsky6SRPipelineFlow matchingによる超解像
kandinskylab/Kandinsky-6.0-VSR-distilled2steps-5s-DiffusersKandinsky6SRPipeline蒸留されたスーパーレゾリューション、2ステップ

テキスト/画像から動画と音声へ

import torch
from diffusers import Kandinsky6TI2VAPipeline
from diffusers.utils import encode_video

pipe = Kandinsky6TI2VAPipeline.from_pretrained(
    "kandinskylab/Kandinsky-6.0-Pro-distill-5s-Diffusers", torch_dtype=torch.bfloat16
)
pipe.enable_model_cpu_offload()

output = pipe(
    prompt="A cat and a dog baking a cake together in a kitchen.",
    height=480,
    width=864,
    num_frames=121,
    num_inference_steps=10,
    guidance_scale=1.0,
)
encode_video(
    output.frames[0],
    fps=24,
    output_path="output.mp4",
    audio=output.audio[0][None],
    audio_sample_rate=pipe.audio_sample_rate,
)

image= を渡して最初のフレームを参照画像で条件付けし、sample_audio=False を渡して動画のみを生成し、expand_prompts=True を渡して Qwen2.5-VL テキストエンコーダーが短いプロンプトを詳細なプロンプトに書き換えるようにします。

ビデオ超解像

Kandinsky6SRPipeline は、Kandinsky6TI2VAPipeline が生成したフレームを 2、4、または 2.25(1.125 倍の双線形事前アップスケールに続けて 2 倍パス)にアップスケールします。動画は重複するタイルに分割され、各タイルは SR transformer が学習されたタイルサイズのいずれかで精錬され、その後 Hann ウィンドウを用いてタイルがブレンドされて再結合されます。

# required: lets inductor pick flex-attention tiles that fit the SR block mask
torch._inductor.config.max_autotune = True  

sr_pipe = Kandinsky6SRPipeline.from_pretrained(
    "kandinskylab/Kandinsky-6.0-VSR-distilled2steps-5s-Diffusers", torch_dtype=torch.bfloat16
)
# The SR transformer always runs NABLA sparse attention on the `flex` backend. Compile it, otherwise flex falls
# back to an eager implementation that needs far more memory at video resolutions.
sr_pipe.enable_model_cpu_offload()
sr_pipe.transformer.set_attention_backend("flex")
sr_pipe.transformer.compile_repeated_blocks(fullgraph=True)

upscaled = sr_pipe(video=output.frames[0], resolution_scale=2.25, num_inference_steps=2).frames[0]

メモリ最適化

一般的なテクニックについては、メモリ使用量の削減ガイドを参照してください。Kandinsky6TI2VAPipelineとKandinsky6SRPipelineの両方は、モデルオフローディング(上記で使用)をサポートしており、速度を犠牲にしてフットプリントを小さくする場合は、シーケンシャルCPUオフローディングも利用できます。

pipe.enable_sequential_cpu_offload()

Kandinsky6TI2VAPipelineの動画VAEは、高解像度や長時間の動画に対応するため、tiled decodingもサポートしています:

pipe.vae.enable_tiling()

注記

  • height と width は、動画 VAE の空間圧縮率と transformer の patch サイズの積で割り切れる必要があります。デフォルトの Kandinsky6TI2VAPipeline 設定では 16 です(圧縮率が 8 の AutoencoderKLHunyuanVideo、patch_size=(1, 2, 2))。上記の例で使用されている 480x864 はこの条件を満たしています。
  • Kandinsky6SRPipelineの入力videoは、整数kに対して1 + k * vae_scale_factor_temporalフレームである必要があります(デフォルトのK-VAE設定では時間方向の圧縮比が4であるため、121フレームは有効ですが120フレームは不可です) — アップスケールする前に、この条件を満たさない場合は動画をトリミングまたはパディングしてください。
  • expand_prompts=True を設定すると、デノイジングの前に追加の生成パスを実行するために、すでに読み込まれている Qwen2.5-VL のテキストエンコーダーを再利用します。これによりレイテンシは増加しますが、追加のモデル重みは必要ありません。
  • 繰り返し推論を高速化するために、繰り返しされる Transformer ブロックをコンパイルします:
    pipe.transformer.compile_repeated_blocks(fullgraph=True)

Kandinsky6TI2VAPipeline

class diffusers.Kandinsky6TI2VAPipeline

< >

( transformer: Kandinsky6Transformer3DModelvae: AutoencoderKLHunyuanVideotext_encoder: Qwen2_5_VLForConditionalGenerationtokenizer: Qwen2_5_VLProcessortext_encoder_2: CLIPTextModeltokenizer_2: CLIPTokenizerscheduler: diffusers.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler | diffusers.schedulers.scheduling_piflow.PiflowScheduleraudio_vae: diffusers.models.autoencoders.autoencoder_mmaudio.MMAudioVAE | None = Nonevocoder: diffusers.models.autoencoders.mmaudio_vocoder.MMAudioVocoder | None = None )

パラメータ

  • transformer (Kandinsky6Transformer3DModel) — 動画と音声の潜在変数をノイズ除去するマルチモーダルな Transformer です。
  • vae (AutoencoderKLHunyuanVideo) — 参照画像をエンコードし、生成された動画をデコードするために使用される動画 VAE。
  • text_encoder (Qwen2_5_VLForConditionalGeneration) — トークンレベルのテキスト埋め込みを提供し、必要に応じてプロンプトの拡張を行う Qwen2.5-VL モデルです。
  • tokenizer (Qwen2_5_VLProcessor) — text_encoder のプロセッサです。
  • text_encoder_2 (CLIPTextModel) — プーリングされたテキスト埋め込みを提供する CLIP テキストエンコーダー。
  • tokenizer_2 (CLIPTokenizer) — text_encoder_2 の Tokenizer。
  • scheduler(FlowMatchEulerDiscreteScheduler または PiflowScheduler)— transformer と組み合わせて潜在変数のノイズ除去に使用されるスケジューラーです。蒸留済みチェックポイントには PiflowScheduler が同梱されており、guidance_scale=1.0 を指定して実行する必要があります。
  • audio_vae (MMAudioVAE、任意) — 生成されたオーディオの潜在変数をメルスペクトログラムにデコードするために使用されるオーディオ VAE。sample_audio=True の場合のみ必要です。
  • vocoder (MMAudioVocoder、任意) — audio_vae がデコードしたメルスペクトログラムを波形に変換するために使用される Vocoder。sample_audio=True の場合のみ必要です。

Kandinsky 6 によるテキスト/画像から動画と音声の生成を行う Pipeline です。

Videoとaudioのlatentsは、Qwen2.5-VLのテキストトークンとCLIPのpooled embeddingを条件として、単一のマルチモーダルtransformerによって同時にdenoiseされます。任意の参照画像は、最初のフレームを条件付けます。

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

__call__

< >

( prompt: str | list[str] | None = Noneimage: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = Nonenegative_prompt: str | list[str] | None = Noneheight: int = 512width: int = 768num_frames: int = 121frame_rate: float = 24.0num_inference_steps: int = 50timesteps: list[int] | None = Nonesigmas: list[float] | None = Noneguidance_scale: float = 5.0num_videos_per_prompt: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneaudio_latents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Nonepooled_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_pooled_prompt_embeds: typing.Optional[torch.Tensor] = Nonesample_audio: bool = Trueexpand_prompts: bool = Falsemax_sequence_length: int = 1024output_type: str = 'pil'return_dict: bool = Truecallback_on_step_end: collections.abc.Callable[[int, int, dict], None] | None = Nonecallback_on_step_end_tensor_inputs: list[str] = ['latents'] ) → Kandinsky6TI2VAPipelineOutput or tuple

パラメータ

  • prompt (str または list[str]、省略可) — 生成をガイドするためのプロンプトです。prompt_embeds が指定されていない場合は必須です。
  • image (PipelineImageInput、任意) — 最初のフレームを条件づける参照画像(image-to-video-and-audio)。
  • negative_prompt (str または list[str]、省略可) — 生成をガイドしないプロンプトです。デフォルトでは Kandinsky 6 のネガティブプロンプトが使用されます。
  • height (int、デフォルトは 512) — 生成される動画の高さ(ピクセル単位)。
  • width (int、デフォルトは 768) — 生成される動画の幅(ピクセル単位)。
  • num_frames (int、デフォルトは121) — 生成されるフレーム数。
  • frame_rate (float、デフォルト値は24.0) — 動画が生成されるフレームレート。同期される音声の長さを設定します。
  • num_inference_steps (int、デフォルトは 50) — デノイジングのステップ数です。蒸留済みチェックポイントを使用する場合は 16 を指定してください。
  • timesteps (list[int]、任意) — 対応するスケジューラー用のカスタムタイムステップ。
  • sigmas (list[float]、省略可) — 対応するスケジューラー用のカスタムシグマ。
  • guidance_scale (float、デフォルト値は5.0) — Classifier-free guidance のスケール。PiflowSchedulerを使用する場合は1.0である必要があります。
  • num_videos_per_prompt (int、デフォルトは 1) — プロンプトごとに生成する動画の数を指定します。
  • generator (torch.Generator または list[torch.Generator]、任意) — 初期ノイズおよび参照画像のエンコーディングに使用されるジェネレーターです。
  • latents (torch.Tensor, 任意) — (batch_size, channels, num_latent_frames, latent_height, latent_width) の形状を持つ、事前生成された動画の潜在変数。
  • audio_latents (torch.Tensor, 任意) — (batch_size, channels, audio_length) の形状を持つ、事前生成されたオーディオの潜在変数です。
  • prompt_embeds (torch.Tensor, 任意) — 事前に生成された Qwen2.5-VL のテキスト埋め込み。
  • pooled_prompt_embeds (torch.Tensor, 任意) — 事前生成された CLIP のプーリング済みテキスト埋め込みです。
  • negative_prompt_embeds (torch.Tensor, 任意) — 事前に生成された、負の Qwen2.5-VL テキスト埋め込み。
  • negative_pooled_prompt_embeds (torch.Tensor, 任意) — 事前に生成された、ネガティブな CLIP プール済みテキスト埋め込みです。
  • sample_audio (bool、デフォルトは True) — 同期されたオーディオを生成するかどうかを指定します。パイプラインに audio_vae と vocoder が存在する必要があります。
  • expand_prompts (bool、デフォルトはFalse) — エンコードの前にexpand_prompts()でプロンプトを書き換えるかどうか。
  • max_sequence_length (int、デフォルトは 1024) — チャットテンプレート適用後のプロンプトトークンの最大数。
  • output_type (str、デフォルトは "pil") — 生成された動画の出力形式: "pil"、"np"、"pt" または "latent"。
  • return_dict (bool、デフォルトはTrue) — プレーンなタプルの代わりにKandinsky6TI2VAPipelineOutputを返すかどうかを指定します。
  • callback_on_step_end (Callable, 省略可) — callback_on_step_end(self, step, timestep, callback_kwargs) の形式で、各デノイジングステップの終了時に呼び出される関数です。リストされたテンソルを上書きする dict を返すことができます。
  • callback_on_step_end_tensor_inputs (list[str]、デフォルトは ["latents"]) — callback_on_step_end に渡されるテンソル入力。_callback_tensor_inputs の部分集合です。

戻り値

Kandinsky6TI2VAPipelineOutput または tuple

生成された動画と音声。return_dict=Falseの場合、(frames, audio)のタプル。

生成用の pipeline への呼び出し関数。

例:

>>> import torch
>>> from diffusers import Kandinsky6TI2VAPipeline
>>> from diffusers.utils import encode_video

>>> pipe = Kandinsky6TI2VAPipeline.from_pretrained(
...     "kandinskylab/Kandinsky-6.0-Pro-distill-5s-Diffusers", torch_dtype=torch.bfloat16
... )
>>> pipe.enable_model_cpu_offload()

>>> output = pipe(
...     prompt="A cat and a dog baking a cake together in a kitchen.",
...     height=480,
...     width=864,
...     num_frames=121,
...     num_inference_steps=16,
...     guidance_scale=1.0,
... )
>>> encode_video(
...     output.frames[0],
...     fps=24,
...     output_path="output.mp4",
...     audio=output.audio[0][None],
...     audio_sample_rate=pipe.audio_sample_rate,
... )

encode_image

< >

( image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]height: intwidth: intdevice: devicedtype: dtypenum_videos_per_prompt: int = 1generator: typing.Optional[torch.Generator] = None )

参照画像を、VAEのscaling_factorでスケーリングされた、形状(batch_size, latent_height, latent_width, latent_channels)のファーストフレームの潜変数(latents)にエンコードします。PIL画像はheight x widthにリサイズされ、中央クロップされます。テンソルと配列は、すでにそのサイズである必要があります。潜変数は、バッチ次元に沿ってnum_videos_per_prompt回繰り返されます。

encode_prompt

< >

( prompt: str | list[str]negative_prompt: str | list[str] | None = Nonedo_classifier_free_guidance: bool = Truenum_videos_per_prompt: int = 1prompt_embeds: typing.Optional[torch.Tensor] = Nonepooled_prompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_attention_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_pooled_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_attention_mask: typing.Optional[torch.Tensor] = Nonemax_sequence_length: int = 1024device: typing.Optional[torch.device] = Nonedtype: typing.Optional[torch.dtype] = None )

パラメータ

  • prompt (str または list[str]) — エンコードするプロンプト。
  • negative_prompt (str または list[str]、省略可) — 生成を導くために使用しないプロンプトです。do_classifier_free_guidance が False の場合は無視されます。
  • do_classifier_free_guidance (bool、デフォルトはTrue) — ネガティブプロンプトもエンコードするかどうか。
  • num_videos_per_prompt (int、デフォルトは1) — プロンプトごとに生成される動画の数。埋め込みはこれに応じて繰り返し使用されます。
  • prompt_embeds (torch.Tensor、任意) — 事前生成済みの Qwen2.5-VL テキスト埋め込み。prompt のエンコーディングをスキップします。
  • pooled_prompt_embeds (torch.Tensor, 任意) — 事前生成された CLIP のプーリング済みテキスト埋め込み。prompt_embeds と一緒に指定する必要があります。
  • prompt_attention_mask (torch.Tensor, 省略可) — prompt_embeds のブール値パディングマスクです。
  • negative_prompt_embeds (torch.Tensor, 任意) — 事前に生成された、負の Qwen2.5-VL テキスト埋め込み。
  • negative_pooled_prompt_embeds (torch.Tensor, 任意) — 事前に生成された、ネガティブな CLIP プール済みテキスト埋め込みです。
  • negative_prompt_attention_mask (torch.Tensor, 任意) — negative_prompt_embeds のブール値パディングマスクです。
  • max_sequence_length (int、デフォルトは 1024) — チャットテンプレート適用後のプロンプトトークンの最大数。
  • device (torch.device, 任意) — テキストエンコーダーを実行するデバイス。
  • dtype (torch.dtype、省略可) — 返される埋め込みの Dtype です。

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

expand_prompts

< >

( prompt: str | list[str]tokenizertext_encoderdevice: deviceimage: PIL.Image.Image | list[PIL.Image.Image] | None = Nonemax_sequence_length: int = 1024generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None ) → str or list[str]

パラメータ

  • prompt (str または list[str]) — 展開するプロンプト、またはプロンプトのリスト。
  • tokenizer — Qwen2.5-VL のプロセッサ。例: pipe.tokenizer。
  • text_encoder — Qwen2.5-VL モデル、例: pipe.text_encoder。
  • device (torch.device) — テキストエンコーダーを実行するデバイス。
  • image (PIL.Image.Image または list[PIL.Image.Image]、任意) — image-to-video 呼び出しの参照画像です。
  • max_sequence_length (int、デフォルトは1024) — プロンプトごとに生成されるトークンの最大数。
  • generator (torch.Generator または list[torch.Generator]、省略可) — サンプリングされた拡張のシードを設定します。リストの場合、prompt の長さと一致する必要があり、各アイテムごとに 1 つのジェネレーターを指定します。generate はグローバル RNG から抽選を行うため、このジェネレーターのシードからグローバル RNG がシードされます。その後の randn_tensor 呼び出しでは、引き続き generator を直接使用します。

戻り値

str または list[str]

展開されたプロンプト。

Qwen2.5-VL テキストエンコーダーを使用して、短いプロンプトを詳細な動画+音声プロンプトに書き換えます。参照画像が指定されている場合は、それを根拠として使用します。パイプラインの実行前に単体で使用できるように、staticmethod として実装されています。

prepare_audio_latents

< >

( batch_size: intnum_channels_latents: intaudio_length: intdtype: dtypedevice: devicegenerator: typing.Union[torch.Generator, list[torch.Generator], NoneType]audio_latents: typing.Optional[torch.Tensor] = None )

Transformer の (batch_size, audio_length, channels) レイアウトでオーディオの潜在変数を返します。ユーザーが提供する audio_latents テンソルは、(batch_size, channels, audio_length) レイアウトであることが期待されます。

prepare_latents

< >

( batch_size: intnum_channels_latents: intheight: intwidth: intnum_frames: intdtype: dtypedevice: devicegenerator: typing.Union[torch.Generator, list[torch.Generator], NoneType]latents: typing.Optional[torch.Tensor] = None )

transformer の (batch_size, num_frames, height, width, channels) レイアウトで、video latents を返します。 ユーザーが提供する latents テンソルは、(batch_size, channels, num_frames, height, width) レイアウトであることが期待されます。

Kandinsky6SRPipeline

class diffusers.Kandinsky6SRPipeline

< >

( transformer: Kandinsky6SRTransformer3DModelvae: Kandinsky6SRVAEscheduler: diffusers.schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteScheduler | diffusers.schedulers.scheduling_piflow.PiflowSchedulerlatent_upscaler: diffusers.models.latent_upscaler.latent_upscaler_kandinsky6_sr.Kandinsky6SRLatentUpscalerBank | None = None )

パラメータ

Kandinsky 6 による動画スーパーリゾリューションのパイプライン。

動画は重複する空間タイルに分割され、各タイルはモデルが学習されたタイルサイズ(transformer.config.tile_sizes)のいずれかによって SR transformer で精錬され、精錬されたタイルは Hann ウィンドウを用いて再合成されます。パイプラインに latent_upscaler が存在する場合、タイルは動画全体の K-VAE 潜在変数から切り出され、潜在空間内でアップスケールされます。それ以外の場合は、ピクセルタイルが双線形補間によってアップスケールされ、エンコードされます。

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

__call__

< >

( video: typing.Union[list[PIL.Image.Image], list[list[PIL.Image.Image]], numpy.ndarray, torch.Tensor]resolution_scale: float = 2.25num_inference_steps: int = 4timesteps: list[int] | None = Nonesigmas: list[float] | None = Nonelq_noise_scale: float = 0.7min_overlap: float = 0.2tiles_batch_size: int = 1generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Noneoutput_type: str = 'pil'return_dict: bool = True ) → Kandinsky6SRPipelineOutput or tuple

パラメータ

  • video (list[PIL.Image.Image]、np.ndarray または torch.Tensor) — 1 + k * 4 フレームを持つ低解像度動画です。preprocess_video() が受け入れる任意の形式で指定できます。サイズは VAE の空間係数の倍数に切り捨てられます。
  • resolution_scale (float、デフォルトは 2.25) — 空間方向の総アップスケール倍率: 2、4、または 2.25 (1.125 倍の双線形事前アップスケールに続けて 2 倍パスを実行)。
  • num_inference_steps (int、デフォルトは4) — タイルごとのデノイジングステップ数です。蒸留済みチェックポイントを使用する場合は2を指定してください。
  • timesteps (list[int]、任意) — 対応するスケジューラー用のカスタムタイムステップ。
  • sigmas (list[float]、省略可) — 対応するスケジューラー用のカスタムシグマ。
  • lq_noise_scale (float、デフォルト値は0.7) — デノイジングの前に、低解像度ラテンツに混合されるガウスノイズの量(分散保存型)。
  • min_overlap (float, デフォルトは 0.2) — 隣接するタイル間の最小重複量。タイルサイズの割合で表します。
  • tiles_batch_size (int、デフォルトは1) — transformerの1回の呼び出しでデノイズされるタイルの数。
  • generator (torch.Generator または list[torch.Generator]、任意) — タイルに混合されるノイズに使用されるジェネレーター。
  • output_type (str、デフォルトは "pil") — 生成された動画の出力形式: "pil"、"np" または "pt"。
  • return_dict (bool、デフォルトはTrue) — プレーンなタプルではなく、Kandinsky6SRPipelineOutputを返すかどうか。

戻り値

Kandinsky6SRPipelineOutput または tuple

超解像度化された動画。return_dict=False の場合、1要素のタプルです。

スーパーリゾリューション用の pipeline への呼び出し関数。

例:

>>> import torch
>>> from diffusers import Kandinsky6SRPipeline, Kandinsky6TI2VAPipeline
>>> from diffusers.utils import export_to_video

>>> pipe = Kandinsky6TI2VAPipeline.from_pretrained(
...     "kandinskylab/Kandinsky-6.0-Pro-distill-5s-Diffusers", torch_dtype=torch.bfloat16
... )
>>> pipe.enable_model_cpu_offload()
>>> video = pipe(
...     prompt="A cat and a dog baking a cake together in a kitchen.",
...     height=480,
...     width=864,
...     num_inference_steps=16,
...     guidance_scale=1.0,
...     sample_audio=False,
... ).frames[0]

>>> sr_pipe = Kandinsky6SRPipeline.from_pretrained(
...     "kandinskylab/Kandinsky-6.0-VSR-distilled2steps-5s-Diffusers", torch_dtype=torch.bfloat16
... )
>>> # The transformer always runs attention through the `flex` backend; compiling avoids the eager
>>> # fallback's much higher memory use at video resolutions.
>>> sr_pipe.transformer.compile_repeated_blocks(fullgraph=True)
>>> sr_pipe.enable_model_cpu_offload()
>>> output = sr_pipe(video=video, resolution_scale=2.25, num_inference_steps=2)
>>> export_to_video(output.frames[0], "output_sr.mp4", fps=24)

decode_latents

< >

( latents: Tensor )

スケーリングされた K-VAE 潜在変数を [-1, 1] の (batch_size, channels, num_frames, height, width) 形式の動画にデコードします。

encode_video

< >

( video: Tensor )

(batch_size, channels, num_frames, height, width) の [-1, 1] 範囲の動画を、VAE の scaling_factor でスケーリングされた K-VAE 潜在変数にエンコードします。

Kandinsky6SRLatentUpscalerBank

class diffusers.Kandinsky6SRLatentUpscalerBank

< >

( in_channels: int = 64stage_channels: tuple[int, int, int] = (2048, 1024, 512)num_pre_blocks: int = 5num_mid_blocks: int = 3num_post_blocks: int = 3num_x2_adapter_blocks: int = 2scales: tuple[int, ...] = (2, 4)scaling_factor: float = 0.910344004631042 )

パラメータ

  • in_channels (int、デフォルトは 64) — 潜在チャネルの数です。
  • stage_channels (tuple[int, int, int]、デフォルトは (2048, 1024, 512)) — カスケードの3つのステージのフィーチャー幅です。
  • num_pre_blocks (int、デフォルトは5) — x4モデルの最初のアップサンプリング前の残差ブロックの数。
  • num_mid_blocks (int、デフォルトは3) — 2つのアップサンプルの間の残差ブロックの数。
  • num_post_blocks (int、デフォルトは3) — 最後のアップサンプルの後の残差ブロックの数。
  • num_x2_adapter_blocks (int、デフォルトは2) — x2モデルのアダプターの残差ブロック。
  • scales (tuple[int, ...]、デフォルトは (2, 4)) — アップスケーラーを提供する空間スケール。
  • scaling_factor (float、デフォルトは 0.910344) — 入力ラテンツに想定されるスケール係数(K-VAE の scaling_factor)です。

Kandinsky6SRPipelineで使用される潜在アップスケーラーのバンク: 対応する空間スケールごとに1つのKandinsky6SRLatentUpscalerが、K-VAEの潜在変数に対して動作します。

forward

< >

( latents: Tensorscale: intreturn_dict: bool = True )

パラメータ

  • latents (torch.Tensor、形状 (batch_size, in_channels, num_frames, height, width)) — scaling_factor によってスケーリングされた K-VAE の潜在変数です。
  • scale (int) — 空間的なアップスケール係数。scales のいずれかです。
  • return_dict (bool、デフォルトはTrue) — ~models.autoencoder_kl.DecoderOutputを返すかどうか。

Kandinsky6TI2VAPipelineOutput

class diffusers.Kandinsky6TI2VAPipelineOutput

< >

( frames: typing.Union[torch.Tensor, numpy.ndarray, list[list[PIL.Image.Image]]]audio: typing.Union[torch.Tensor, numpy.ndarray, NoneType] = None )

パラメータ

  • frames (torch.Tensor、np.ndarray、または list[list[PIL.Image.Image]]) — 生成された動画です。batch_size 長さのネストされたリストで、各要素が num_frames 枚の PIL 画像を含む形式、または形状が (batch_size, num_frames, height, width, channels) / (batch_size, num_frames, channels, height, width) の NumPy 配列または torch テンソルです。output_type="latent" の場合、形状が (batch_size, channels, num_latent_frames, latent_height, latent_width) の動画の潜在変数です。
  • audio (torch.Tensor または np.ndarray、省略可) — オーディオ VAE のサンプリングレートで、[-1, 1] の範囲にあり、形状が (batch_size, num_samples) の生成された波形、またはオーディオがサンプリングされなかった場合は None。output_type="latent" を指定した場合は、形状が (batch_size, channels, audio_length) のオーディオ潜在変数です。

Kandinsky6TI2VAPipeline の出力クラスです。

Kandinsky6SRPipelineOutput

class diffusers.Kandinsky6SRPipelineOutput

< >

( frames: typing.Union[torch.Tensor, numpy.ndarray, list[list[PIL.Image.Image]]] )

パラメータ

  • frames (torch.Tensor、np.ndarray、または list[list[PIL.Image.Image]]) — スーパーリゾルブされた動画。batch_size の長さのネストされたリストで、各要素が num_frames 枚の PIL 画像を含むもの、または形状が (batch_size, num_frames, height, width, channels) / (batch_size, num_frames, channels, height, width) の NumPy 配列または torch テンソルです。

Kandinsky6SRPipelineの出力クラスです。

Update on GitHub