Diffusers documentation
Kandinsky 6
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-Diffusers | Kandinsky6TI2VAPipeline | Flow matching、guidance_scale=5.0、50ステップ |
kandinskylab/Kandinsky-6.0-Pro-distill-5s-Diffusers | Kandinsky6TI2VAPipeline | 蒸留済み、guidance_scale=1.0、10ステップ |
kandinskylab/Kandinsky-6.0-Lite-5s-Diffusers | Kandinsky6TI2VAPipeline | Flow matching、guidance_scale=5.0、50ステップ |
kandinskylab/Kandinsky-6.0-Lite-distill-5s-Diffusers | Kandinsky6TI2VAPipeline | 蒸留済み、guidance_scale=1.0、10ステップ |
kandinskylab/Kandinsky-6.0-Pro-pretrain-5s-Diffusers | Kandinsky6TI2VAPipeline | Flow matching、guidance_scale=5.0、50ステップ |
kandinskylab/Kandinsky-6.0-Lite-pretrain-5s-Diffusers | Kandinsky6TI2VAPipeline | Flow matching、guidance_scale=5.0、50ステップ |
kandinskylab/Kandinsky-6.0-VSR-5s-Diffusers | Kandinsky6SRPipeline | Flow matchingによる超解像 |
kandinskylab/Kandinsky-6.0-VSR-distilled2steps-5s-Diffusers | Kandinsky6SRPipeline | 蒸留されたスーパーレゾリューション、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
< source >( 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__
< source >( 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
< source >( 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
< source >( 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
< source >( 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
< source >( 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
< source >( 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
< source >( 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 )
パラメータ
- transformer (Kandinsky6SRTransformer3DModel) — 潜在タイルを精錬する Transformer です。
- vae (Kandinsky6SRVAE) — 入力動画をエンコードし、精細化されたタイルをデコードするために使用される因果的ビデオK-VAE。
- scheduler (FlowMatchEulerDiscreteScheduler または PiflowScheduler) —
transformerと組み合わせてタイルのノイズ除去に使用するスケジューラーです。蒸留済みチェックポイントには PiflowScheduler が同梱されています。 - latent_upscaler (Kandinsky6SRLatentUpscalerBank、任意) — サポートされているスケール用の Latent アップスケーラー。
Kandinsky 6 による動画スーパーリゾリューションのパイプライン。
動画は重複する空間タイルに分割され、各タイルはモデルが学習されたタイルサイズ(transformer.config.tile_sizes)のいずれかによって SR transformer で精錬され、精錬されたタイルは Hann ウィンドウを用いて再合成されます。パイプラインに latent_upscaler が存在する場合、タイルは動画全体の K-VAE 潜在変数から切り出され、潜在空間内でアップスケールされます。それ以外の場合は、ピクセルタイルが双線形補間によってアップスケールされ、エンコードされます。
このモデルは DiffusionPipeline を継承しています。すべてのパイプラインに実装されている汎用的なメソッド(ダウンロード、保存、特定のデバイスでの実行など)については、スーパークラスのドキュメントを参照してください。
__call__
< source >( 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)スケーリングされた K-VAE 潜在変数を [-1, 1] の (batch_size, channels, num_frames, height, width) 形式の動画にデコードします。
(batch_size, channels, num_frames, height, width) の [-1, 1] 範囲の動画を、VAE の scaling_factor でスケーリングされた K-VAE 潜在変数にエンコードします。
Kandinsky6SRLatentUpscalerBank
class diffusers.Kandinsky6SRLatentUpscalerBank
< source >( 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
< source >( latents: Tensorscale: intreturn_dict: bool = True )
Kandinsky6TI2VAPipelineOutput
class diffusers.Kandinsky6TI2VAPipelineOutput
< source >( 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
< source >( frames: typing.Union[torch.Tensor, numpy.ndarray, list[list[PIL.Image.Image]]] )
Kandinsky6SRPipelineの出力クラスです。