#
# Apache License, Version 2.0（「ライセンス」）の下でライセンスされています。
# このファイルは、ライセンスに準拠した場合にのみ使用できます。
# ライセンスのコピーは以下から入手できます
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# 適用される法律で要求される場合、または書面による合意がある場合を除き、ソフトウェア
# ライセンスに基づき配布される本ソフトウェアは、「現状のまま」
# 明示的または黙示的を問わず、いかなる種類の保証や条件も付随しません。
# 権限を管理する特定の言語については、ライセンスを参照してください。
# ライセンスの下での制限。-->

  
    
      
    
  

# SkyReels-V2: 無限長の映画生成モデル

Skywork AIのSkyReelsチームによる[SkyReels-V2](https://huggingface.co/papers/2504.13074)。

*動画生成における最近の進歩は、拡散モデルと自己回帰型フレームワークによって牽引されてきましたが、プロンプトへの忠実度、視覚的品質、モーションダイナミクス、再生時間長を調和させるという重要な課題が依然として残っています。具体的には、時間的な視覚的品質を向上させるためにモーションダイナミクスを妥協させたり、解像度を優先するために動画の長さを制限（5〜10秒）したり、ショット構成、俳優の表情、カメラワークといったシネマティックな文法を解釈できない汎用MLLMに起因するショット認識型の生成が不十分であったりします。これらの相互に絡み合った制約は、リアルな長尺動画の合成やプロフェッショナルな映画スタイルの生成を妨げています。これらの制約に対処するため、私たちは、マルチモーダル大規模言語モデル（MLLM）、マルチステージ事前学習、強化学習、Diffusion Forcing Frameworkをシナジーさせる、無限長の映画生成モデルであるSkyReels-V2を提案します。まず、マルチモーダルLLMによる一般的な記述と、サブエキスパートモデルによる詳細なショット言語を組み合わせる、包括的な動画の構造表現を設計しました。次に、人間のアノテーションの支援を得て、SkyCaptioner-V1と名付けられた統合的なVideo Captionerを訓練し、動画データを効率的にラベリングします。さらに、基本的な動画生成のためのプログレッシブ解像度事前学習を確立し、その後、4段階のポストトレーニングによる強化を行います。初期の概念バランス型Supervised Fine-Tuning（SFT）はベースラインの品質を向上させ、人間によるアノテーションと合成歪みデータを用いたモーション特化型の強化学習（RL）トレーニングは動的アーティファクトに対処します。ノイズスケジュールが非減少である私たちのDiffusion Forcingフレームワークは、効率的な探索空間内で長尺動画の合成を可能にし、最終的な高品質SFTは視覚的忠実度を洗練させます。すべてのコードとモデルは、[この https URL](https://github.com/SkyworkAI/SkyReels-V2)で利用可能です。*

すべてのオリジナルのSkyReels-V2チェックポイントは、[Skywork](https://huggingface.co/collections/Skywork/skyreels-v2-6801b1b93df627d441d0d0d9)組織の下で確認できます。

Diffusersでは、以下のSkyReels-V2モデルがサポートされています。
- [SkyReels-V2 DF 1.3B - 540P](https://huggingface.co/Skywork/SkyReels-V2-DF-1.3B-540P-Diffusers)
- [SkyReels-V2 DF 14B - 540P](https://huggingface.co/Skywork/SkyReels-V2-DF-14B-540P-Diffusers)
- [SkyReels-V2 DF 14B - 720P](https://huggingface.co/Skywork/SkyReels-V2-DF-14B-720P-Diffusers)
- [SkyReels-V2 T2V 14B - 540P](https://huggingface.co/Skywork/SkyReels-V2-T2V-14B-540P-Diffusers)
- [SkyReels-V2 T2V 14B - 720P](https://huggingface.co/Skywork/SkyReels-V2-T2V-14B-720P-Diffusers)
- [SkyReels-V2 I2V 1.3B - 540P](https://huggingface.co/Skywork/SkyReels-V2-I2V-1.3B-540P-Diffusers)
- [SkyReels-V2 I2V 14B - 540P](https://huggingface.co/Skywork/SkyReels-V2-I2V-14B-540P-Diffusers)
- [SkyReels-V2 I2V 14B - 720P](https://huggingface.co/Skywork/SkyReels-V2-I2V-14B-720P-Diffusers)

このモデルは、[M. Tolga Cangöz](https://github.com/tolgacangoz) によって提供されました。

> [!TIP]
> 右側のサイドバーにあるSkyReels-V2モデルをクリックすると、動画生成のより多くの例を確認できます。

### _ビジュアル_デモ

以下の例には、次のパラメータがあります。

- `base_num_frames=97`
- `num_frames=97`
- `num_inference_steps=30`
- `ar_step=5`
- `causal_block_size=5`

`vae_scale_factor_temporal=4` の場合、以下の計算により、`5` フレームずつの `5` ブロックが期待されます:

`num_latent_frames: (97-1)//vae_scale_factor_temporal+1 = 25 frames -> 5 blocks of 5 frames each`

そして、潜在空間における最大コンテキスト長は`base_num_latent_frames`で計算されます。

`base_num_latent_frames = (97-1)//vae_scale_factor_temporal+1 = 25 -> 25//5 = 5 blocks`

非同期処理のタイムライン:
```text
┌─────────────────────────────────────────────────────────────────┐
│ Steps:    1    6   11   16   21   26   31   36   41   46   50   │
│ Block 1: [■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■]                       │
│ Block 2:      [■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■]                  │
│ Block 3:           [■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■]             │
│ Block 4:                [■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■]        │
│ Block 5:                     [■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■]   │
└─────────────────────────────────────────────────────────────────┘
```

長時間動画（`num_frames` > `base_num_frames`）の場合: `base_num_frames` は、長時間動画の処理における「スライディングウィンドウサイズ」として機能します。

例: `257`フレームの動画で、`base_num_frames=97`、`overlap_history=17`
```text
┌──── Iteration 1 (frames 1-97) ────┐
│ Processing window: 97 frames      │ → 5 blocks,
│ Generates: frames 1-97            │   async processing
└───────────────────────────────────┘
            ┌────── Iteration 2 (frames 81-177) ──────┐
            │ Processing window: 97 frames            │
            │ Overlap: 17 frames (81-97) from prev    │ → 5 blocks,
            │ Generates: frames 98-177                │   async processing
            └─────────────────────────────────────────┘
                        ┌────── Iteration 3 (frames 161-257) ──────┐
                        │ Processing window: 97 frames             │
                        │ Overlap: 17 frames (161-177) from prev   │ → 5 blocks,
                        │ Generates: frames 178-257                │   async processing
                        └──────────────────────────────────────────┘
```

各イテレーションは、独自の`5`ブロックで非同期処理を独立して実行します。`base_num_frames`は以下を制御します:
1. メモリ使用量（ウィンドウが大きいほどVRAM使用量が増加）
2. モデルのコンテキスト長（トレーニング時の制約と一致させる必要があります）
3. 1反復あたりのブロック数（`base_num_latent_frames // causal_block_size`）

各ブロックは、デノイジングの完了に`30`ステップを要します。ブロック N はステップ `1 + (N-1) x ar_step` から開始します。総ステップ数: `30 + (5-1) x 5 = 50` ステップ

同期モード(`ar_step=0`)では、すべてのブロック/フレームを同時に処理します:
```text
┌──────────────────────────────────────────────┐
│ Steps:       1            ...            30  │
│ All blocks: [■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■] │
└──────────────────────────────────────────────┘
```
総ステップ数: `30` ステップ

非同期処理におけるステップ行列の構築方法の例です。以下のパラメータが与えられた場合: (`num_inference_steps=30, flow_shift=8, num_frames=97, ar_step=5, causal_block_size=5`)
```
- num_latent_frames = (97 frames - 1) // (4 temporal downsampling) + 1 = 25
- step_template = [999, 995, 991, 986, 980, 975, 969, 963, 956, 948,
                   941, 932, 922, 912, 901, 888, 874, 859, 841, 822,
                   799, 773, 743, 708, 666, 615, 551, 470, 363, 216]
```

このアルゴリズムは、以下の条件を満たす`50x25`の`step_matrix`を作成します。
```
- Row 1:  [999×5, 999×5, 999×5, 999×5, 999×5]
- Row 2:  [995×5, 999×5, 999×5, 999×5, 999×5]
- Row 3:  [991×5, 999×5, 999×5, 999×5, 999×5]
- ...
- Row 7:  [969×5, 995×5, 999×5, 999×5, 999×5]
- ...
- Row 21: [799×5, 888×5, 941×5, 975×5, 999×5]
- ...
- Row 35: [  0×5, 216×5, 666×5, 822×5, 901×5]
- ...
- Row 42: [  0×5,   0×5,   0×5, 551×5, 773×5]
- ...
- Row 50: [  0×5,   0×5,   0×5,   0×5, 216×5]
```

`6` 行の詳細な分析:
```
- step_matrix[5]:      [ 975×5,  999×5,   999×5,   999×5,   999×5]
- step_index[5]:       [   6×5,    1×5,     0×5,     0×5,     0×5]
- step_update_mask[5]: [True×5, True×5, False×5, False×5, False×5]
- valid_interval[5]:   (0, 25)
```

主要なパターン: ブロック `i` は、ブロック `i-1` よりも正確に `ar_step=5` ステップ遅れており、後続のブロックがよりクリーンな先行ブロックを条件とする、段階的な「diffusion forcing」効果を生み出します。

### テキストから動画の生成

以下の例は、テキストから動画を生成する方法を示しています。

メモリ使用量の削減に関する詳細については、[メモリ使用量の削減](../../optimization/memory)ガイドを参照してください。

元のリポジトリから:
>--ar_step 5 を使用して非同期推論を有効にできます。非同期推論を行う場合、--causal_block_size 5 の設定が推奨されますが、同期生成では設定すべきではありません... 非同期推論ではシーケンス全体を拡散させるためにより多くのステップが必要になるため、同期モードよりも遅くなります。私たちの実験では、非同期推論は指示追従および視覚的一貫性のパフォーマンスを向上させる可能性があります。

```py
import torch
from diffusers import AutoModel, SkyReelsV2DiffusionForcingPipeline, UniPCMultistepScheduler
from diffusers.utils import export_to_video

model_id = "Skywork/SkyReels-V2-DF-1.3B-540P-Diffusers"
vae = AutoModel.from_pretrained(model_id, subfolder="vae", dtype=torch.float32)

pipeline = SkyReelsV2DiffusionForcingPipeline.from_pretrained(
    model_id,
    vae=vae,
    dtype=torch.bfloat16,
)
pipeline.to("cuda")  # or "mps", "xpu", "cpu"
flow_shift = 8.0  # 8.0 for T2V, 5.0 for I2V
pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config, flow_shift=flow_shift)

prompt = "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."

output = pipeline(
    prompt=prompt,
    num_inference_steps=30,
    height=544,  # 720 for 720P
    width=960,   # 1280 for 720P
    num_frames=97,
    base_num_frames=97,  # 121 for 720P
    ar_step=5,  # Controls asynchronous inference (0 for synchronous mode)
    causal_block_size=5,  # Number of frames in each block for asynchronous processing
    overlap_history=None,  # Number of frames to overlap for smooth transitions in long videos; 17 for long video generations
    addnoise_condition=20,  # Improves consistency in long video generation
).frames[0]
export_to_video(output, "video.mp4", fps=24, quality=8)
```

### First-Last-Frame-to-Video 生成

以下の例では、テキストの説明、開始フレーム、および終了フレームを使用して、image-to-video パイプラインで動画を生成する方法を示しています。

```python
import numpy as np
import torch
import torchvision.transforms.functional as TF
from diffusers import AutoencoderKLWan, SkyReelsV2DiffusionForcingImageToVideoPipeline, UniPCMultistepScheduler
from diffusers.utils import export_to_video, load_image

model_id = "Skywork/SkyReels-V2-DF-1.3B-720P-Diffusers"
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.float32)
pipeline = SkyReelsV2DiffusionForcingImageToVideoPipeline.from_pretrained(
    model_id, vae=vae, dtype=torch.bfloat16
)
pipeline.to("cuda")  # or "mps", "xpu", "cpu"
flow_shift = 5.0  # 8.0 for T2V, 5.0 for I2V
pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config, flow_shift=flow_shift)

first_frame = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_first_frame.png")
last_frame = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/flf2v_input_last_frame.png")

def aspect_ratio_resize(image, pipeline, max_area=720 * 1280):
    aspect_ratio = image.height / image.width
    mod_value = pipeline.vae_scale_factor_spatial * pipeline.transformer.config.patch_size[1]
    height = round(np.sqrt(max_area * aspect_ratio)) // mod_value * mod_value
    width = round(np.sqrt(max_area / aspect_ratio)) // mod_value * mod_value
    image = image.resize((width, height))
    return image, height, width

def center_crop_resize(image, height, width):
    # Calculate resize ratio to match first frame dimensions
    resize_ratio = max(width / image.width, height / image.height)

    # Resize the image
    width = round(image.width * resize_ratio)
    height = round(image.height * resize_ratio)
    size = [width, height]
    image = TF.center_crop(image, size)

    return image, height, width

first_frame, height, width = aspect_ratio_resize(first_frame, pipeline)
if last_frame.size != first_frame.size:
    last_frame, _, _ = center_crop_resize(last_frame, height, width)

prompt = "CG animation style, a small blue bird takes off from the ground, flapping its wings. The bird's feathers are delicate, with a unique pattern on its chest. The background shows a blue sky with white clouds under bright sunshine. The camera follows the bird upward, capturing its flight and the vastness of the sky from a close-up, low-angle perspective."

output = pipeline(
    image=first_frame, last_image=last_frame, prompt=prompt, height=height, width=width, guidance_scale=5.0
).frames[0]
export_to_video(output, "video.mp4", fps=24, quality=8)
```

### Video-to-Video 生成

`SkyReelsV2DiffusionForcingVideoToVideoPipeline` は、指定された動画を拡張します。

```python
import numpy as np
import torch
import torchvision.transforms.functional as TF
from diffusers import AutoencoderKLWan, SkyReelsV2DiffusionForcingVideoToVideoPipeline, UniPCMultistepScheduler
from diffusers.utils import export_to_video, load_video

model_id = "Skywork/SkyReels-V2-DF-1.3B-720P-Diffusers"
vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", dtype=torch.float32)
pipeline = SkyReelsV2DiffusionForcingVideoToVideoPipeline.from_pretrained(
    model_id, vae=vae, dtype=torch.bfloat16
)
pipeline.to("cuda")  # or "mps", "xpu", "cpu"
flow_shift = 5.0  # 8.0 for T2V, 5.0 for I2V
pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config, flow_shift=flow_shift)

video = load_video("input_video.mp4")

prompt = "CG animation style, a small blue bird takes off from the ground, flapping its wings. The bird's feathers are delicate, with a unique pattern on its chest. The background shows a blue sky with white clouds under bright sunshine. The camera follows the bird upward, capturing its flight and the vastness of the sky from a close-up, low-angle perspective."

output = pipeline(
    video=video, prompt=prompt, height=720, width=1280, guidance_scale=5.0, overlap_history=17,
    num_inference_steps=30, num_frames=257, base_num_frames=121#, ar_step=5, causal_block_size=5,
).frames[0]
export_to_video(output, "video.mp4", fps=24, quality=8)
# Total frames will be the number of frames of the given video + 257
```

## 注記

- SkyReels-V2は、[load_lora_weights()](/docs/diffusers/main/ja/api/loaders/lora#diffusers.loaders.SkyReelsV2LoraLoaderMixin.load_lora_weights)によるLoRAをサポートしています。

`SkyReelsV2Pipeline` と `SkyReelsV2ImageToVideoPipeline` は、Diffusion Forcing フレームワークを適用せずに利用することもできます。

## SkyReelsV2DiffusionForcingPipeline[[diffusers.SkyReelsV2DiffusionForcingPipeline]]

#### diffusers.SkyReelsV2DiffusionForcingPipeline[[diffusers.SkyReelsV2DiffusionForcingPipeline]]

```python
diffusers.SkyReelsV2DiffusionForcingPipeline(tokenizer: AutoTokenizer, text_encoder: transformers.models.t5.modeling_t5.T5EncoderModel | transformers.models.umt5.modeling_umt5.UMT5EncoderModel, transformer: SkyReelsV2Transformer3DModel, vae: AutoencoderKLWan, scheduler: UniPCMultistepScheduler)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing.py#L128)

**パラメータ:**

tokenizer (`AutoTokenizer`) : [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5Tokenizer)のTokenizer、具体的には[google/umt5-xxl](https://huggingface.co/google/umt5-xxl)バリアントです。

text_encoder (`UMT5EncoderModel`) : [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5EncoderModel)、具体的には [google/umt5-xxl](https://huggingface.co/google/umt5-xxl) バリアントです。

transformer ([SkyReelsV2Transformer3DModel](/docs/diffusers/main/ja/api/models/skyreels_v2_transformer_3d#diffusers.SkyReelsV2Transformer3DModel)) : エンコードされた画像の潜在変数をデノイズするための条件付き Transformer。

scheduler ([UniPCMultistepScheduler](/docs/diffusers/main/ja/api/schedulers/unipc#diffusers.UniPCMultistepScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラ。

vae ([AutoencoderKLWan](/docs/diffusers/main/ja/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan)) : 動画を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ（VAE）モデル。

SkyReels-V2 と diffusion forcing を用いたテキストから動画への生成（t2v）の Pipeline です。

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

#### __call__[[diffusers.SkyReelsV2DiffusionForcingPipeline.__call__]]

```python
__call__(prompt: str | list[str], negative_prompt: str | list[str] = None, height: int = 544, width: int = 960, num_frames: int = 97, num_inference_steps: int = 50, guidance_scale: float = 6.0, num_videos_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'np', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512, overlap_history: int | None = None, addnoise_condition: float = 0, base_num_frames: int = 97, ar_step: int = 0, causal_block_size: int | None = None, fps: int = 24)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing.py#L598)

**パラメータ:**

prompt (`str` または `list[str]`、*省略可*) : 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。

negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。定義されていない場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイドを使用していない場合は無視されます（`guidance_scale` が `1` 未満の場合は無視されます）。

height (`int`、デフォルトは`544`) : 生成される動画の高さ。

width (`int`、デフォルトは`960`) : 生成される動画の幅。

num_frames (`int`、デフォルトは`97`) : 生成される動画のフレーム数。

num_inference_steps (`int`、デフォルトは`50`) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。

guidance_scale (`float`、デフォルトは `6.0`) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598) で定義されるガイダンススケールです。`guidance_scale` は、[Imagen Paper](https://huggingface.co/papers/2205.11487) の数式 2 の `w` として定義されます。`guidance_scale > 1` を設定することでガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt` のテキストと密接に関連する画像の生成が促されますが、通常は画像の品質低下を伴います。（**T2V では 6.0**、**I2V では 5.0**）

num_videos_per_prompt (`int`、*任意*、デフォルトは 1) : プロンプトごとに生成する画像の数。

generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html)。

latents (`torch.Tensor`, *任意*) : 画像生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダム`generator`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。

prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたテキスト埋め込み。テキスト入力（プロンプトの重み付け）を簡単に調整するために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。

negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたテキスト埋め込み。テキスト入力（プロンプトの重み付け）を簡単に調整するために使用できます。指定されない場合、`negative_prompt` 入力引数からテキスト埋め込みが生成されます。

output_type (`str`、*任意*、デフォルトは`"np"`) : 生成された画像の出力形式。`PIL.Image`または`np.array`から選択します。

return_dict (`bool`、*任意*、デフォルトは `True`) : プレーンなタプルではなく `SkyReelsV2PipelineOutput` を返すかどうか。

attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `self.processor` で定義されている `AttentionProcessor` に渡される kwargs の辞書です。

callback_on_step_end (`Callable`、`PipelineCallback`、`MultiPipelineCallbacks`、*任意*) : 推論中の各デノイジングステップの終了時に呼び出される関数、または `PipelineCallback` または `MultiPipelineCallbacks` のサブクラスです。以下の引数を持ちます: `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`、*optional*、デフォルトは`512`) : プロンプトの最大シーケンス長。

overlap_history (`int`, *任意*、デフォルトは `None`) : 長い動画の滑らかなトランジションのためにオーバーラップさせるフレーム数です。`None` の場合、パイプラインは短い動画生成モードを前提とし、オーバーラップは適用されません。17 または 37 を設定することを推奨します。

addnoise_condition (`float`、*任意*、デフォルトは `0`) : クリーンな条件にノイズを加えることで、長い動画の生成を滑らかにするために使用されます。ノイズが大きすぎると、不整合の原因にもなります。推奨値は 20 ですが、より大きな値を試すこともできます。ただし、50 を超えないことをお勧めします。

base_num_frames (`int`、*任意*、デフォルトは `97`) : 97 または 121 | ベースフレーム数（**540P の場合は 97**、**720P の場合は 121**）

ar_step (`int`, *任意*, デフォルトは `0`) : 非同期推論を制御します（同期モードの場合は 0）。`ar_step=5` を設定すると、非同期推論を有効にできます。非同期推論を行う場合は `causal_block_size=5` の設定を推奨しますが、同期生成では設定すべきではありません。非同期推論ではシーケンス全体を拡散させるのに多くのステップを要するため、同期モードよりも遅くなります。私たちの実験では、非同期推論により、指示追従性能や視覚的一貫性性能が向上する可能性があります。

causal_block_size (`int`、*任意*、デフォルトは`None`) : 各ブロック/チャンクに含まれるフレーム数。非同期推論を使用する場合（ar_step > 0 の場合）に推奨されます。

fps (`int`、*任意*、デフォルトは`24`) : 生成される動画のフレームレート

**戻り値:** `~SkyReelsV2PipelineOutput` または `tuple`

`return_dict` が `True` の場合、`SkyReelsV2PipelineOutput` が返され、それ以外の場合は、最初の要素が生成された画像のリスト、2番目の要素が対応する生成画像に「not-safe-for-work」（nsfw）コンテンツが含まれているかどうかを示す `bool` のリストである `tuple` が返されます。

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

例:
```py
>>> import torch
>>> from diffusers import (
...     SkyReelsV2DiffusionForcingPipeline,
...     UniPCMultistepScheduler,
...     AutoencoderKLWan,
... )
>>> from diffusers.utils import export_to_video

>>> # Load the pipeline
>>> # Available models:
>>> # - Skywork/SkyReels-V2-DF-1.3B-540P-Diffusers
>>> # - Skywork/SkyReels-V2-DF-14B-540P-Diffusers
>>> # - Skywork/SkyReels-V2-DF-14B-720P-Diffusers
>>> vae = AutoencoderKLWan.from_pretrained(
...     "Skywork/SkyReels-V2-DF-14B-720P-Diffusers",
...     subfolder="vae",
...     torch_dtype=torch.float32,
... )
>>> pipe = SkyReelsV2DiffusionForcingPipeline.from_pretrained(
...     "Skywork/SkyReels-V2-DF-14B-720P-Diffusers",
...     vae=vae,
...     torch_dtype=torch.bfloat16,
... )
>>> flow_shift = 8.0  # 8.0 for T2V, 5.0 for I2V
>>> pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=flow_shift)
>>> pipe = pipe.to("cuda")

>>> prompt = "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."

>>> output = pipe(
...     prompt=prompt,
...     num_inference_steps=30,
...     height=544,
...     width=960,
...     guidance_scale=6.0,  # 6.0 for T2V, 5.0 for I2V
...     num_frames=97,
...     ar_step=5,  # Controls asynchronous inference (0 for synchronous mode)
...     causal_block_size=5,  # Number of frames processed together in a causal block
...     overlap_history=None,  # Number of frames to overlap for smooth transitions in long videos
...     addnoise_condition=20,  # Improves consistency in long video generation
... ).frames[0]
>>> export_to_video(output, "video.mp4", fps=24, quality=8)
```

#### encode_prompt[[diffusers.SkyReelsV2DiffusionForcingPipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 226, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing.py#L219)

**パラメータ:**

prompt (`str` または `list[str]`、*省略可能*) : エンコードするプロンプト

negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。定義されていない場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイドを使用していない場合は無視されます（`guidance_scale` が `1` 未満の場合は無視されます）。

do_classifier_free_guidance (`bool`、*任意*、デフォルトは`True`) : classifier free guidance を使用するかどうか。

num_videos_per_prompt (`int`、*optional*、デフォルトは 1) : 各プロンプトに対して生成すべき動画の数。結果の埋め込みを配置する torch デバイス

prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。

negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。

device : (`torch.device`, *任意*): torch デバイス

dtype : (`torch.dtype`, *任意*): torch dtype

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

#### generate_timestep_matrix[[diffusers.SkyReelsV2DiffusionForcingPipeline.generate_timestep_matrix]]

```python
generate_timestep_matrix(num_latent_frames: int, step_template: Tensor, base_num_latent_frames: int, ar_step: int = 5, num_pre_ready: int = 0, causal_block_size: int = 1, shrink_interval_with_mask: bool = False)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing.py#L418)

**パラメータ:**

num_latent_frames (int) : 生成する潜在フレームの総数

step_template (torch.Tensor) : 基本的なタイムステップスケジュール（例: [1000, 800, 600, ..., 0]）

base_num_latent_frames (int) : モデルが1回のフォワードパスで処理できる最大フレーム数

ar_step (int, 任意) : 時間ラグの自己回帰ステップサイズ。0 = 同期、>0 = 非同期。デフォルト値は 5 です。

num_pre_ready (int, 任意) : すでにノイズ除去が完了したフレームの数（例: video2videoタスクのプレフィックスなど）。デフォルト値は0です。

causal_block_size (int, 任意) : 因果ブロックとして処理されるフレーム数。デフォルトは1です。

shrink_interval_with_mask (bool, optional) : 処理間隔を最適化するかを指定します。デフォルトは False です。

**戻り値:** `tuple containing`

- step_matrix (torch.Tensor): 各イテレーションにおける各フレームのタイムステップの行列。Shape: [num_iterations, num_latent_frames]
- step_index (torch.Tensor): タイムステップの参照に使用するインデックス行列。Shape: [num_iterations, num_latent_frames]
- step_update_mask (torch.Tensor): 更新するフレームを示すブールマスク。Shape: [num_iterations, num_latent_frames]
- valid_interval list[tuple]: 各イテレーションの (start, end) 区間のリスト

**例外:** ``ValueError``

- ``ValueError`` -- 指定された設定に対して ar_step が小さすぎる場合

この関数は、時間フレーム全体で協調的なノイズ除去スケジュールを作成するコアの拡散強制アルゴリズムを実装しています。同期生成モードと非同期生成モードの両方をサポートします。

**同期モード**（ar_step=0、causal_block_size=1）：
- 各タイムステップにおいて、すべてのフレームが同時にデノイズされます
- 各フレームは同じノイズ除去軌跡 [1000, 800, 600, ..., 0] をたどります。
- よりシンプルですが、長時間の動画では時間的な一貫性が低くなる可能性があります

**非同期モード**（ar_step>0、causal_block_size>1）：
- フレームは因果ブロックにグループ化され、ブロック/チャンク単位で処理されます
- 各ブロックは、段階的にずらされたパターンでノイズ除去され、「デノイジング・ウェーブ」が形成されます。
- 先行ブロックはよりノイズ除去が進んでおり、後続ブロックはar_stepステップ分遅れています
- より強い時間依存性と、より良い一貫性を生み出します

## SkyReelsV2DiffusionForcingImageToVideoPipeline[[diffusers.SkyReelsV2DiffusionForcingImageToVideoPipeline]]

#### diffusers.SkyReelsV2DiffusionForcingImageToVideoPipeline[[diffusers.SkyReelsV2DiffusionForcingImageToVideoPipeline]]

```python
diffusers.SkyReelsV2DiffusionForcingImageToVideoPipeline(tokenizer: AutoTokenizer, text_encoder: transformers.models.t5.modeling_t5.T5EncoderModel | transformers.models.umt5.modeling_umt5.UMT5EncoderModel, transformer: SkyReelsV2Transformer3DModel, vae: AutoencoderKLWan, scheduler: UniPCMultistepScheduler)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing_i2v.py#L133)

**パラメータ:**

tokenizer (`AutoTokenizer`) : [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5Tokenizer)のTokenizer、具体的には[google/umt5-xxl](https://huggingface.co/google/umt5-xxl)バリアントです。

text_encoder (`UMT5EncoderModel`) : [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5EncoderModel)、具体的には [google/umt5-xxl](https://huggingface.co/google/umt5-xxl) バリアントです。

transformer ([SkyReelsV2Transformer3DModel](/docs/diffusers/main/ja/api/models/skyreels_v2_transformer_3d#diffusers.SkyReelsV2Transformer3DModel)) : エンコードされた画像の潜在変数をデノイズするための条件付き Transformer。

scheduler ([UniPCMultistepScheduler](/docs/diffusers/main/ja/api/schedulers/unipc#diffusers.UniPCMultistepScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラ。

vae ([AutoencoderKLWan](/docs/diffusers/main/ja/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan)) : 動画を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ（VAE）モデル。

SkyReels-V2のdiffusion forcingを用いたImage-to-Video (i2v) 生成用のPipeline。

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

#### __call__[[diffusers.SkyReelsV2DiffusionForcingImageToVideoPipeline.__call__]]

```python
__call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]], prompt: str | list[str] = None, negative_prompt: str | list[str] = None, height: int = 544, width: int = 960, num_frames: int = 97, num_inference_steps: int = 50, guidance_scale: float = 5.0, num_videos_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, image_embeds: typing.Optional[torch.Tensor] = None, last_image: typing.Optional[torch.Tensor] = None, output_type: str | None = 'np', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512, overlap_history: int | None = None, addnoise_condition: float = 0, base_num_frames: int = 97, ar_step: int = 0, causal_block_size: int | None = None, fps: int = 24)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing_i2v.py#L644)

**パラメータ:**

image (`PipelineImageInput`) : 生成を条件づけるための入力画像。画像、画像のリスト、または`torch.Tensor`である必要があります。

prompt (`str` または `list[str]`、*省略可*) : 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。

negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。定義されていない場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイドを使用していない場合は無視されます（`guidance_scale` が `1` 未満の場合は無視されます）。

height (`int`、デフォルトは`544`) : 生成される動画の高さ。

width (`int`、デフォルトは`960`) : 生成される動画の幅。

num_frames (`int`、デフォルトは`97`) : 生成される動画のフレーム数。

num_inference_steps (`int`、デフォルトは`50`) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。

guidance_scale (`float`、デフォルトは`5.0`) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598)で定義されているガイダンススケール。`guidance_scale`は、[Imagen Paper](https://huggingface.co/papers/2205.11487)の式2の`w`として定義されます。`guidance_scale > 1`を設定することでガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt`のテキストと密接に関連した画像の生成が促されますが、通常は画像品質の低下を伴います。（**T2Vでは6.0**、**I2Vでは5.0**）

num_videos_per_prompt (`int`、*任意*、デフォルトは 1) : プロンプトごとに生成する画像の数。

generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html)。

latents (`torch.Tensor`, *任意*) : 画像生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダム`generator`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。

prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたテキスト埋め込み。テキスト入力（プロンプトの重み付け）を簡単に調整するために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。

negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたテキスト埋め込み。テキスト入力（プロンプトの重み付け）を簡単に調整するために使用できます。指定されない場合、`negative_prompt` 入力引数からテキスト埋め込みが生成されます。

image_embeds (`torch.Tensor`, *任意*) : 事前に生成された画像エンベディング。画像入力（重み付け）を簡単に調整するために使用できます。指定されない場合、`image` 入力引数から画像エンベディングが生成されます。

last_image (`torch.Tensor`, *任意*) : 事前に生成された画像エンベディング。画像入力（重み付け）を簡単に調整するために使用できます。指定されない場合、`image` 入力引数から画像エンベディングが生成されます。

output_type (`str`、*任意*、デフォルトは`"np"`) : 生成された画像の出力形式。`PIL.Image`または`np.array`から選択します。

return_dict (`bool`、*任意*、デフォルトは `True`) : プレーンなタプルではなく `SkyReelsV2PipelineOutput` を返すかどうか。

attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `self.processor` で定義されている `AttentionProcessor` に渡される kwargs の辞書です。

callback_on_step_end (`Callable`、`PipelineCallback`、`MultiPipelineCallbacks`、*任意*) : 推論中の各デノイジングステップの終了時に呼び出される関数、または `PipelineCallback` または `MultiPipelineCallbacks` のサブクラスです。以下の引数を持ちます: `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`、*optional*、デフォルトは`512`) : プロンプトの最大シーケンス長。

overlap_history (`int`, *任意*、デフォルトは `None`) : 長い動画の滑らかなトランジションのためにオーバーラップさせるフレーム数です。`None` の場合、パイプラインは短い動画生成モードを前提とし、オーバーラップは適用されません。17 または 37 を設定することを推奨します。

addnoise_condition (`float`、*任意*、デフォルトは `0`) : クリーンな条件にノイズを加えることで、長い動画の生成を滑らかにするために使用されます。ノイズが大きすぎると、不整合の原因にもなります。推奨値は 20 ですが、より大きな値を試すこともできます。ただし、50 を超えないことをお勧めします。

base_num_frames (`int`、*任意*、デフォルトは `97`) : 97 または 121 | ベースフレーム数（**540P の場合は 97**、**720P の場合は 121**）

ar_step (`int`, *任意*, デフォルトは `0`) : 非同期推論を制御します（同期モードの場合は 0）。`ar_step=5` を設定すると、非同期推論を有効にできます。非同期推論を行う場合は `causal_block_size=5` の設定を推奨しますが、同期生成では設定すべきではありません。非同期推論ではシーケンス全体を拡散させるのに多くのステップを要するため、同期モードよりも遅くなります。私たちの実験では、非同期推論により、指示追従性能や視覚的一貫性性能が向上する可能性があります。

causal_block_size (`int`、*任意*、デフォルトは`None`) : 各ブロック/チャンクに含まれるフレーム数。非同期推論を使用する場合（ar_step > 0 の場合）に推奨されます。

fps (`int`、*任意*、デフォルトは`24`) : 生成される動画のフレームレート

**戻り値:** `~SkyReelsV2PipelineOutput` または `tuple`

`return_dict` が `True` の場合、`SkyReelsV2PipelineOutput` が返され、それ以外の場合は、最初の要素が生成された画像のリスト、2番目の要素が対応する生成画像に「not-safe-for-work」（nsfw）コンテンツが含まれているかどうかを示す `bool` のリストである `tuple` が返されます。

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

例:
```py
>>> import torch
>>> from diffusers import (
...     SkyReelsV2DiffusionForcingImageToVideoPipeline,
...     UniPCMultistepScheduler,
...     AutoencoderKLWan,
... )
>>> from diffusers.utils import export_to_video
>>> from PIL import Image

>>> # Load the pipeline
>>> # Available models:
>>> # - Skywork/SkyReels-V2-DF-1.3B-540P-Diffusers
>>> # - Skywork/SkyReels-V2-DF-14B-540P-Diffusers
>>> # - Skywork/SkyReels-V2-DF-14B-720P-Diffusers
>>> vae = AutoencoderKLWan.from_pretrained(
...     "Skywork/SkyReels-V2-DF-14B-720P-Diffusers",
...     subfolder="vae",
...     torch_dtype=torch.float32,
... )
>>> pipe = SkyReelsV2DiffusionForcingImageToVideoPipeline.from_pretrained(
...     "Skywork/SkyReels-V2-DF-14B-720P-Diffusers",
...     vae=vae,
...     torch_dtype=torch.bfloat16,
... )
>>> flow_shift = 5.0  # 8.0 for T2V, 5.0 for I2V
>>> pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=flow_shift)
>>> pipe = pipe.to("cuda")

>>> prompt = "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."
>>> image = Image.open("path/to/image.png")

>>> output = pipe(
...     image=image,
...     prompt=prompt,
...     num_inference_steps=50,
...     height=544,
...     width=960,
...     guidance_scale=5.0,  # 6.0 for T2V, 5.0 for I2V
...     num_frames=97,
...     ar_step=0,  # Controls asynchronous inference (0 for synchronous mode)
...     overlap_history=None,  # Number of frames to overlap for smooth transitions in long videos
...     addnoise_condition=20,  # Improves consistency in long video generation
... ).frames[0]
>>> export_to_video(output, "video.mp4", fps=24, quality=8)
```

#### encode_prompt[[diffusers.SkyReelsV2DiffusionForcingImageToVideoPipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 226, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing_i2v.py#L224)

**パラメータ:**

prompt (`str` または `list[str]`、*省略可能*) : エンコードするプロンプト

negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。定義されていない場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイドを使用していない場合は無視されます（`guidance_scale` が `1` 未満の場合は無視されます）。

do_classifier_free_guidance (`bool`、*任意*、デフォルトは`True`) : classifier free guidance を使用するかどうか。

num_videos_per_prompt (`int`、*optional*、デフォルトは 1) : 各プロンプトに対して生成すべき動画の数。結果の埋め込みを配置する torch デバイス

prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。

negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。

device : (`torch.device`, *任意*): torch デバイス

dtype : (`torch.dtype`, *任意*): torch dtype

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

#### generate_timestep_matrix[[diffusers.SkyReelsV2DiffusionForcingImageToVideoPipeline.generate_timestep_matrix]]

```python
generate_timestep_matrix(num_latent_frames: int, step_template: Tensor, base_num_latent_frames: int, ar_step: int = 5, num_pre_ready: int = 0, causal_block_size: int = 1, shrink_interval_with_mask: bool = False)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing_i2v.py#L464)

**パラメータ:**

num_latent_frames (int) : 生成する潜在フレームの総数

step_template (torch.Tensor) : 基本的なタイムステップスケジュール（例: [1000, 800, 600, ..., 0]）

base_num_latent_frames (int) : モデルが1回のフォワードパスで処理できる最大フレーム数

ar_step (int, 任意) : 時間ラグの自己回帰ステップサイズ。0 = 同期、>0 = 非同期。デフォルト値は 5 です。

num_pre_ready (int, 任意) : すでにノイズ除去が完了したフレームの数（例: video2videoタスクのプレフィックスなど）。デフォルト値は0です。

causal_block_size (int, 任意) : 因果ブロックとして処理されるフレーム数。デフォルトは1です。

shrink_interval_with_mask (bool, optional) : 処理間隔を最適化するかを指定します。デフォルトは False です。

**戻り値:** `tuple containing`

- step_matrix (torch.Tensor): 各イテレーションにおける各フレームのタイムステップの行列。Shape: [num_iterations, num_latent_frames]
- step_index (torch.Tensor): タイムステップの参照に使用するインデックス行列。Shape: [num_iterations, num_latent_frames]
- step_update_mask (torch.Tensor): 更新するフレームを示すブールマスク。Shape: [num_iterations, num_latent_frames]
- valid_interval list[tuple]: 各イテレーションの (start, end) 区間のリスト

**例外:** ``ValueError``

- ``ValueError`` -- 指定された設定に対して ar_step が小さすぎる場合

この関数は、時間フレーム全体で協調的なノイズ除去スケジュールを作成するコアの拡散強制アルゴリズムを実装しています。同期生成モードと非同期生成モードの両方をサポートします。

**同期モード**（ar_step=0、causal_block_size=1）：
- 各タイムステップにおいて、すべてのフレームが同時にデノイズされます
- 各フレームは同じノイズ除去軌跡 [1000, 800, 600, ..., 0] をたどります。
- よりシンプルですが、長時間の動画では時間的な一貫性が低くなる可能性があります

**非同期モード**（ar_step>0、causal_block_size>1）：
- フレームは因果ブロックにグループ化され、ブロック/チャンク単位で処理されます
- 各ブロックは、段階的にずらされたパターンでノイズ除去され、「デノイジング・ウェーブ」が形成されます。
- 先行ブロックはよりノイズ除去が進んでおり、後続ブロックはar_stepステップ分遅れています
- より強い時間依存性と、より良い一貫性を生み出します

## SkyReelsV2DiffusionForcingVideoToVideoPipeline[[diffusers.SkyReelsV2DiffusionForcingVideoToVideoPipeline]]

#### diffusers.SkyReelsV2DiffusionForcingVideoToVideoPipeline[[diffusers.SkyReelsV2DiffusionForcingVideoToVideoPipeline]]

```python
diffusers.SkyReelsV2DiffusionForcingVideoToVideoPipeline(tokenizer: AutoTokenizer, text_encoder: transformers.models.t5.modeling_t5.T5EncoderModel | transformers.models.umt5.modeling_umt5.UMT5EncoderModel, transformer: SkyReelsV2Transformer3DModel, vae: AutoencoderKLWan, scheduler: UniPCMultistepScheduler)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing_v2v.py#L189)

**パラメータ:**

tokenizer (`AutoTokenizer`) : [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5Tokenizer)のTokenizer、具体的には[google/umt5-xxl](https://huggingface.co/google/umt5-xxl)バリアントです。

text_encoder (`UMT5EncoderModel`) : [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5EncoderModel)、具体的には [google/umt5-xxl](https://huggingface.co/google/umt5-xxl) バリアントです。

transformer ([SkyReelsV2Transformer3DModel](/docs/diffusers/main/ja/api/models/skyreels_v2_transformer_3d#diffusers.SkyReelsV2Transformer3DModel)) : エンコードされた画像の潜在変数をデノイズするための条件付き Transformer。

scheduler ([UniPCMultistepScheduler](/docs/diffusers/main/ja/api/schedulers/unipc#diffusers.UniPCMultistepScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラ。

vae ([AutoencoderKLWan](/docs/diffusers/main/ja/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan)) : 動画を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ（VAE）モデル。

SkyReels-V2のdiffusion forcingを用いたVideo-to-Video (v2v) 生成のためのPipelineです。

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

#### __call__[[diffusers.SkyReelsV2DiffusionForcingVideoToVideoPipeline.__call__]]

```python
__call__(video: list[PIL.Image.Image], prompt: str | list[str] = None, negative_prompt: str | list[str] = None, height: int = 544, width: int = 960, num_frames: int = 120, num_inference_steps: int = 50, guidance_scale: float = 6.0, num_videos_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'np', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512, overlap_history: int | None = None, addnoise_condition: float = 0, base_num_frames: int = 97, ar_step: int = 0, causal_block_size: int | None = None, fps: int = 24)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing_v2v.py#L684)

**パラメータ:**

video (`list[Image.Image]`) : 動画生成をガイドするための動画。

prompt (`str` または `list[str]`、*省略可能*) : 動画生成をガイドするためのプロンプトまたはプロンプトのリストです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。

negative_prompt (`str` または `list[str]`、*省略可*) : 動画生成をガイドしないためのプロンプトまたはプロンプトのリストです。定義されていない場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイドを使用していない場合は無視されます（`guidance_scale` が `1` 未満の場合は無視されます）。

height (`int`、デフォルトは`544`) : 生成される動画の高さ。

width (`int`、デフォルトは`960`) : 生成される動画の幅。

num_frames (`int`、デフォルトは`120`) : 生成される動画のフレーム数。

num_inference_steps (`int`、デフォルトは`50`) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。

guidance_scale (`float`、デフォルトは `6.0`) : [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598) で定義されるガイダンススケールです。`guidance_scale` は、[Imagen Paper](https://arxiv.org/pdf/2205.11487.pdf) の数式 2 の `w` として定義されます。`guidance_scale > 1` を設定することでガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt` のテキストと密接に関連する画像の生成が促されますが、通常は画像の品質低下を伴います。（**T2V では 6.0**、**I2V では 5.0**）

num_videos_per_prompt (`int`、*任意*、デフォルトは 1) : プロンプトごとに生成する画像の数。

generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html)。

latents (`torch.Tensor`, *任意*) : 画像生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダム`generator`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。

prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたテキスト埋め込み。テキスト入力（プロンプトの重み付け）を簡単に調整するために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。

negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたテキスト埋め込み。テキスト入力（プロンプトの重み付け）を簡単に調整するために使用できます。指定されない場合、`negative_prompt` 入力引数からテキスト埋め込みが生成されます。

output_type (`str`、*任意*、デフォルトは`"np"`) : 生成された画像の出力形式。`PIL.Image`または`np.array`から選択します。

return_dict (`bool`、*任意*、デフォルトは `True`) : プレーンなタプルではなく `SkyReelsV2PipelineOutput` を返すかどうか。

attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `self.processor` で定義されている `AttentionProcessor` に渡される kwargs の辞書です。

callback_on_step_end (`Callable`、`PipelineCallback`、`MultiPipelineCallbacks`、*任意*) : 推論中の各デノイジングステップの終了時に呼び出される関数、または `PipelineCallback` または `MultiPipelineCallbacks` のサブクラスです。以下の引数を持ちます: `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`、*optional*、デフォルトは`512`) : プロンプトの最大シーケンス長。

overlap_history (`int`, *任意*、デフォルトは `None`) : 長い動画の滑らかなトランジションのためにオーバーラップさせるフレーム数です。`None` の場合、パイプラインは短い動画生成モードを前提とし、オーバーラップは適用されません。17 または 37 を設定することを推奨します。

addnoise_condition (`float`、*任意*、デフォルトは `0`) : クリーンな条件にノイズを加えることで、長い動画の生成を滑らかにするために使用されます。ノイズが大きすぎると、不整合の原因にもなります。推奨値は 20 ですが、より大きな値を試すこともできます。ただし、50 を超えないことをお勧めします。

base_num_frames (`int`、*任意*、デフォルトは `97`) : 97 または 121 | ベースフレーム数（**540P の場合は 97**、**720P の場合は 121**）

ar_step (`int`, *任意*, デフォルトは `0`) : 非同期推論を制御します（同期モードの場合は 0）。`ar_step=5` を設定すると、非同期推論を有効にできます。非同期推論を行う場合は `causal_block_size=5` の設定を推奨しますが、同期生成では設定すべきではありません。非同期推論ではシーケンス全体を拡散させるのに多くのステップを要するため、同期モードよりも遅くなります。私たちの実験では、非同期推論により、指示追従性能や視覚的一貫性性能が向上する可能性があります。

causal_block_size (`int`、*任意*、デフォルトは`None`) : 各ブロック/チャンクに含まれるフレーム数。非同期推論を使用する場合（ar_step > 0 の場合）に推奨されます。

fps (`int`、*任意*、デフォルトは`24`) : 生成される動画のフレームレート

**戻り値:** `~SkyReelsV2PipelineOutput` または `tuple`

`return_dict` が `True` の場合、`SkyReelsV2PipelineOutput` が返され、それ以外の場合は、最初の要素が生成された画像のリスト、2番目の要素が対応する生成画像に「not-safe-for-work」（nsfw）コンテンツが含まれているかどうかを示す `bool` のリストである `tuple` が返されます。

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

例:
```py
>>> import torch
>>> from diffusers import (
...     SkyReelsV2DiffusionForcingVideoToVideoPipeline,
...     UniPCMultistepScheduler,
...     AutoencoderKLWan,
... )
>>> from diffusers.utils import export_to_video

>>> # Load the pipeline
>>> # Available models:
>>> # - Skywork/SkyReels-V2-DF-1.3B-540P-Diffusers
>>> # - Skywork/SkyReels-V2-DF-14B-540P-Diffusers
>>> # - Skywork/SkyReels-V2-DF-14B-720P-Diffusers
>>> vae = AutoencoderKLWan.from_pretrained(
...     "Skywork/SkyReels-V2-DF-14B-720P-Diffusers",
...     subfolder="vae",
...     torch_dtype=torch.float32,
... )
>>> pipe = SkyReelsV2DiffusionForcingVideoToVideoPipeline.from_pretrained(
...     "Skywork/SkyReels-V2-DF-14B-720P-Diffusers",
...     vae=vae,
...     torch_dtype=torch.bfloat16,
... )
>>> flow_shift = 8.0  # 8.0 for T2V, 5.0 for I2V
>>> pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=flow_shift)
>>> pipe = pipe.to("cuda")

>>> prompt = "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."

>>> output = pipe(
...     prompt=prompt,
...     num_inference_steps=50,
...     height=544,
...     width=960,
...     guidance_scale=6.0,  # 6.0 for T2V, 5.0 for I2V
...     num_frames=97,
...     ar_step=0,  # Controls asynchronous inference (0 for synchronous mode)
...     overlap_history=None,  # Number of frames to overlap for smooth transitions in long videos
...     addnoise_condition=20,  # Improves consistency in long video generation
... ).frames[0]
>>> export_to_video(output, "video.mp4", fps=24, quality=8)
```

#### encode_prompt[[diffusers.SkyReelsV2DiffusionForcingVideoToVideoPipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 226, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing_v2v.py#L280)

**パラメータ:**

prompt (`str` または `list[str]`、*省略可能*) : エンコードするプロンプト

negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。定義されていない場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイドを使用していない場合は無視されます（`guidance_scale` が `1` 未満の場合は無視されます）。

do_classifier_free_guidance (`bool`、*任意*、デフォルトは`True`) : classifier free guidance を使用するかどうか。

num_videos_per_prompt (`int`、*optional*、デフォルトは 1) : 各プロンプトに対して生成すべき動画の数。結果の埋め込みを配置する torch デバイス

prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。

negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。

device : (`torch.device`, *任意*): torch デバイス

dtype : (`torch.dtype`, *任意*): torch dtype

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

#### generate_timestep_matrix[[diffusers.SkyReelsV2DiffusionForcingVideoToVideoPipeline.generate_timestep_matrix]]

```python
generate_timestep_matrix(num_latent_frames: int, step_template: Tensor, base_num_latent_frames: int, ar_step: int = 5, num_pre_ready: int = 0, causal_block_size: int = 1, shrink_interval_with_mask: bool = False)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_diffusion_forcing_v2v.py#L504)

**パラメータ:**

num_latent_frames (int) : 生成する潜在フレームの総数

step_template (torch.Tensor) : 基本的なタイムステップスケジュール（例: [1000, 800, 600, ..., 0]）

base_num_latent_frames (int) : モデルが1回のフォワードパスで処理できる最大フレーム数

ar_step (int, 任意) : 時間ラグの自己回帰ステップサイズ。0 = 同期、>0 = 非同期。デフォルト値は 5 です。

num_pre_ready (int, 任意) : すでにノイズ除去が完了したフレームの数（例: video2videoタスクのプレフィックスなど）。デフォルト値は0です。

causal_block_size (int, 任意) : 因果ブロックとして処理されるフレーム数。デフォルトは1です。

shrink_interval_with_mask (bool, optional) : 処理間隔を最適化するかを指定します。デフォルトは False です。

**戻り値:** `tuple containing`

- step_matrix (torch.Tensor): 各イテレーションにおける各フレームのタイムステップの行列。Shape: [num_iterations, num_latent_frames]
- step_index (torch.Tensor): タイムステップの参照に使用するインデックス行列。Shape: [num_iterations, num_latent_frames]
- step_update_mask (torch.Tensor): 更新するフレームを示すブールマスク。Shape: [num_iterations, num_latent_frames]
- valid_interval list[tuple]: 各イテレーションの (start, end) 区間のリスト

**例外:** ``ValueError``

- ``ValueError`` -- 指定された設定に対して ar_step が小さすぎる場合

この関数は、時間フレーム全体で協調的なノイズ除去スケジュールを作成するコアの拡散強制アルゴリズムを実装しています。同期生成モードと非同期生成モードの両方をサポートします。

**同期モード**（ar_step=0、causal_block_size=1）：
- 各タイムステップにおいて、すべてのフレームが同時にデノイズされます
- 各フレームは同じノイズ除去軌跡 [1000, 800, 600, ..., 0] をたどります。
- よりシンプルですが、長時間の動画では時間的な一貫性が低くなる可能性があります

**非同期モード**（ar_step>0、causal_block_size>1）：
- フレームは因果ブロックにグループ化され、ブロック/チャンク単位で処理されます
- 各ブロックは、段階的にずらされたパターンでノイズ除去され、「デノイジング・ウェーブ」が形成されます。
- 先行ブロックはよりノイズ除去が進んでおり、後続ブロックはar_stepステップ分遅れています
- より強い時間依存性と、より良い一貫性を生み出します

## SkyReelsV2Pipeline[[diffusers.SkyReelsV2Pipeline]]

#### diffusers.SkyReelsV2Pipeline[[diffusers.SkyReelsV2Pipeline]]

```python
diffusers.SkyReelsV2Pipeline(tokenizer: AutoTokenizer, text_encoder: transformers.models.t5.modeling_t5.T5EncoderModel | transformers.models.umt5.modeling_umt5.UMT5EncoderModel, transformer: SkyReelsV2Transformer3DModel, vae: AutoencoderKLWan, scheduler: UniPCMultistepScheduler)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2.py#L107)

**パラメータ:**

tokenizer (`T5Tokenizer`) : [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5Tokenizer)のTokenizer、具体的には[google/umt5-xxl](https://huggingface.co/google/umt5-xxl)バリアントです。

text_encoder (`T5EncoderModel`) : [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5EncoderModel)、具体的には [google/umt5-xxl](https://huggingface.co/google/umt5-xxl) バリアントです。

transformer ([SkyReelsV2Transformer3DModel](/docs/diffusers/main/ja/api/models/skyreels_v2_transformer_3d#diffusers.SkyReelsV2Transformer3DModel)) : 入力された潜在変数（latents）のノイズ除去を行う条件付き Transformer。

scheduler ([UniPCMultistepScheduler](/docs/diffusers/main/ja/api/schedulers/unipc#diffusers.UniPCMultistepScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラ。

vae ([AutoencoderKLWan](/docs/diffusers/main/ja/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan)) : 動画を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ（VAE）モデル。

SkyReels-V2 を使用したテキストから動画への生成 (t2v) 用の Pipeline。

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

#### __call__[[diffusers.SkyReelsV2Pipeline.__call__]]

```python
__call__(prompt: str | list[str] = None, negative_prompt: str | list[str] = None, height: int = 544, width: int = 960, num_frames: int = 97, num_inference_steps: int = 50, guidance_scale: float = 6.0, num_videos_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'np', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2.py#L377)

**パラメータ:**

prompt (`str` または `list[str]`、*省略可*) : 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。

negative_prompt (`str` または `list[str]`、*任意*) : 画像生成をガイドしないプロンプトです。定義されていない場合、代わりに `negative_prompt_embeds` を渡す必要があります。guidance を使用していない場合（`guidance_scale < 1`）は無視されます。

height (`int`、デフォルトは`544`) : 生成される画像のピクセル単位の縦幅。

width (`int`、デフォルトは`960`) : 生成される画像の幅（ピクセル単位）。

num_frames (`int`、デフォルトは`97`) : 生成される動画のフレーム数。

num_inference_steps (`int`、デフォルトは`50`) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。

guidance_scale (`float`、デフォルトは`6.0`) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598)で定義されるガイダンススケールです。`guidance_scale`は、[Imagen Paper](https://huggingface.co/papers/2205.11487)の式2の`w`として定義されます。`guidance_scale > 1`を設定することで、ガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt`のテキストと密接に関連した画像の生成が促されますが、通常は画像の品質低下を伴います。

num_videos_per_prompt (`int`、*任意*、デフォルトは 1) : プロンプトごとに生成する画像の数。

generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html)。

latents (`torch.Tensor`, *任意*) : 画像生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダム`generator`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。

prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたテキスト埋め込み。テキスト入力（プロンプトの重み付け）を簡単に調整するために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。

negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力（プロンプトの重み付け）を簡単に調整するために使用できます。指定されない場合、`negative_prompt_embeds` は `negative_prompt` 入力引数から生成されます。

output_type (`str`、*任意*、デフォルトは`"np"`) : 生成された画像の出力形式。`PIL.Image`または`np.array`から選択します。

return_dict (`bool`、*任意*、デフォルトは `True`) : プレーンなタプルではなく `SkyReelsV2PipelineOutput` を返すかどうか。

attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `self.processor` で定義されている `AttentionProcessor` に渡される kwargs の辞書です。

callback_on_step_end (`Callable`、`PipelineCallback`、`MultiPipelineCallbacks`、*任意*) : 推論中の各デノイジングステップの終了時に呼び出される関数、または `PipelineCallback` または `MultiPipelineCallbacks` のサブクラスです。以下の引数を持ちます: `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`、*任意*、デフォルトは`512`) : テキストエンコーダーの最大シーケンス長です。

**戻り値:** `~SkyReelsV2PipelineOutput` または `tuple`

`return_dict` が `True` の場合、`SkyReelsV2PipelineOutput` が返され、それ以外の場合は、最初の要素が生成された画像のリスト、2番目の要素が対応する生成画像に「not-safe-for-work」（nsfw）コンテンツが含まれているかどうかを示す `bool` のリストである `tuple` が返されます。

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

例:
```py
>>> import torch
>>> from diffusers import (
...     SkyReelsV2Pipeline,
...     UniPCMultistepScheduler,
...     AutoencoderKLWan,
... )
>>> from diffusers.utils import export_to_video

>>> # Load the pipeline
>>> # Available models:
>>> # - Skywork/SkyReels-V2-T2V-14B-540P-Diffusers
>>> # - Skywork/SkyReels-V2-T2V-14B-720P-Diffusers
>>> vae = AutoencoderKLWan.from_pretrained(
...     "Skywork/SkyReels-V2-T2V-14B-720P-Diffusers",
...     subfolder="vae",
...     torch_dtype=torch.float32,
... )
>>> pipe = SkyReelsV2Pipeline.from_pretrained(
...     "Skywork/SkyReels-V2-T2V-14B-720P-Diffusers",
...     vae=vae,
...     torch_dtype=torch.bfloat16,
... )
>>> flow_shift = 8.0  # 8.0 for T2V, 5.0 for I2V
>>> pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=flow_shift)
>>> pipe = pipe.to("cuda")

>>> prompt = "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."

>>> output = pipe(
...     prompt=prompt,
...     num_inference_steps=50,
...     height=544,
...     width=960,
...     guidance_scale=6.0,  # 6.0 for T2V, 5.0 for I2V
...     num_frames=97,
... ).frames[0]
>>> export_to_video(output, "video.mp4", fps=24, quality=8)
```

#### encode_prompt[[diffusers.SkyReelsV2Pipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 226, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2.py#L198)

**パラメータ:**

prompt (`str` または `list[str]`、*省略可能*) : エンコードするプロンプト

negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。定義されていない場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイドを使用していない場合は無視されます（`guidance_scale` が `1` 未満の場合は無視されます）。

do_classifier_free_guidance (`bool`、*任意*、デフォルトは`True`) : classifier free guidance を使用するかどうか。

num_videos_per_prompt (`int`、*optional*、デフォルトは 1) : 各プロンプトに対して生成すべき動画の数。結果の埋め込みを配置する torch デバイス

prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。

negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。

device : (`torch.device`, *任意*): torch デバイス

dtype : (`torch.dtype`, *任意*): torch dtype

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

## SkyReelsV2ImageToVideoPipeline[[diffusers.SkyReelsV2ImageToVideoPipeline]]

#### diffusers.SkyReelsV2ImageToVideoPipeline[[diffusers.SkyReelsV2ImageToVideoPipeline]]

```python
diffusers.SkyReelsV2ImageToVideoPipeline(tokenizer: AutoTokenizer, text_encoder: transformers.models.t5.modeling_t5.T5EncoderModel | transformers.models.umt5.modeling_umt5.UMT5EncoderModel, image_encoder: CLIPVisionModelWithProjection, image_processor: CLIPProcessor, transformer: SkyReelsV2Transformer3DModel, vae: AutoencoderKLWan, scheduler: UniPCMultistepScheduler)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_i2v.py#L127)

**パラメータ:**

tokenizer (`T5Tokenizer`) : [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5Tokenizer)のTokenizer、具体的には[google/umt5-xxl](https://huggingface.co/google/umt5-xxl)バリアントです。

text_encoder (`T5EncoderModel`) : [T5](https://huggingface.co/docs/transformers/en/model_doc/t5#transformers.T5EncoderModel)、具体的には [google/umt5-xxl](https://huggingface.co/google/umt5-xxl) バリアントです。

image_encoder (`CLIPVisionModelWithProjection`) : [CLIP](https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPVisionModelWithProjection)、具体的には [clip-vit-huge-patch14](https://github.com/mlfoundations/open_clip/blob/main/docs/PRETRAINED.md#vit-h14-xlm-roberta-large) バリアントです。

transformer ([SkyReelsV2Transformer3DModel](/docs/diffusers/main/ja/api/models/skyreels_v2_transformer_3d#diffusers.SkyReelsV2Transformer3DModel)) : 入力された潜在変数（latents）のノイズ除去を行う条件付き Transformer。

scheduler ([UniPCMultistepScheduler](/docs/diffusers/main/ja/api/schedulers/unipc#diffusers.UniPCMultistepScheduler)) : `transformer` と組み合わせて、エンコードされた画像の潜在変数をデノイズするために使用するスケジューラ。

vae ([AutoencoderKLWan](/docs/diffusers/main/ja/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan)) : 動画を潜在表現にエンコードし、潜在表現からデコードするための変分オートエンコーダ（VAE）モデル。

SkyReels-V2 を使用した Image-to-Video (i2v) 生成用の Pipeline です。

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

#### __call__[[diffusers.SkyReelsV2ImageToVideoPipeline.__call__]]

```python
__call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]], prompt: str | list[str] = None, negative_prompt: str | list[str] = None, height: int = 544, width: int = 960, num_frames: int = 97, num_inference_steps: int = 50, guidance_scale: float = 5.0, num_videos_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, image_embeds: typing.Optional[torch.Tensor] = None, last_image: typing.Optional[torch.Tensor] = None, output_type: str | None = 'np', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_i2v.py#L479)

**パラメータ:**

image (`PipelineImageInput`) : 生成を条件づけるための入力画像。画像、画像のリスト、または`torch.Tensor`である必要があります。

prompt (`str` または `list[str]`、*省略可*) : 画像生成をガイドするためのプロンプトです。未定義の場合、代わりに `prompt_embeds` を渡す必要があります。

negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。定義されていない場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイドを使用していない場合は無視されます（`guidance_scale` が `1` 未満の場合は無視されます）。

height (`int`、デフォルトは`544`) : 生成される動画の高さ。

width (`int`、デフォルトは`960`) : 生成される動画の幅。

num_frames (`int`、デフォルトは`97`) : 生成される動画のフレーム数。

num_inference_steps (`int`、デフォルトは`50`) : デノイジングのステップ数です。デノイジングのステップ数を増やすと、推論速度が遅くなる代わりに、通常はより高品質な画像が得られます。

guidance_scale (`float`、デフォルトは`5.0`) : [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598)で定義されるガイダンススケール。`guidance_scale`は、[Imagen Paper](https://huggingface.co/papers/2205.11487)の式2の`w`として定義されます。`guidance_scale > 1`を設定することで、ガイダンススケールが有効になります。ガイダンススケールを高くすると、`prompt`のテキストと密接に関連する画像の生成が促されますが、通常は画像の品質が低下する傾向があります。

num_videos_per_prompt (`int`、*任意*、デフォルトは 1) : プロンプトごとに生成する画像の数。

generator (`torch.Generator` または `list[torch.Generator]`、*任意*) : 生成を決定論的にするための [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html)。

latents (`torch.Tensor`, *任意*) : 画像生成の入力として使用される、ガウス分布からサンプリングされた事前生成されたノイジー・ラテンツ。異なるプロンプトで同じ生成を調整するために使用できます。指定されない場合、指定されたランダム`generator`を使用してサンプリングを行い、ラテンツのテンソルが生成されます。

prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたテキスト埋め込み。テキスト入力（プロンプトの重み付け）を簡単に調整するために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。

negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたテキスト埋め込み。テキスト入力（プロンプトの重み付け）を簡単に調整するために使用できます。指定されない場合、`negative_prompt` 入力引数からテキスト埋め込みが生成されます。

image_embeds (`torch.Tensor`, *任意*) : 事前に生成された画像エンベディング。画像入力（重み付け）を簡単に調整するために使用できます。指定されない場合、`image` 入力引数から画像エンベディングが生成されます。

last_image (`torch.Tensor`, *任意*) : 生成される動画の末尾を固定するための、image-to-video 条件付け用の最後の画像（オプション）。

output_type (`str`、*任意*、デフォルトは`"np"`) : 生成された画像の出力形式。`PIL.Image`または`np.array`から選択します。

return_dict (`bool`、*任意*、デフォルトは`True`) : プレーンなタプルではなく`WanPipelineOutput`を返すかどうか。

attention_kwargs (`dict`, *任意*) : 指定された場合、[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py) の `self.processor` で定義されている `AttentionProcessor` に渡される kwargs の辞書です。

callback_on_step_end (`Callable`、`PipelineCallback`、`MultiPipelineCallbacks`、*任意*) : 推論中の各デノイジングステップの終了時に呼び出される関数、または `PipelineCallback` または `MultiPipelineCallbacks` のサブクラスです。以下の引数を持ちます: `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`、*optional*、デフォルトは`512`) : プロンプトの最大シーケンス長。

**戻り値:** `~SkyReelsV2PipelineOutput` または `tuple`

`return_dict` が `True` の場合、`SkyReelsV2PipelineOutput` が返され、それ以外の場合は、最初の要素が生成された画像のリスト、2番目の要素が対応する生成画像に「not-safe-for-work」（nsfw）コンテンツが含まれているかどうかを示す `bool` のリストである `tuple` が返されます。

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

例:
```py
>>> import torch
>>> from diffusers import (
...     SkyReelsV2ImageToVideoPipeline,
...     UniPCMultistepScheduler,
...     AutoencoderKLWan,
... )
>>> from diffusers.utils import export_to_video
>>> from PIL import Image

>>> # Load the pipeline
>>> # Available models:
>>> # - Skywork/SkyReels-V2-I2V-1.3B-540P-Diffusers
>>> # - Skywork/SkyReels-V2-I2V-14B-540P-Diffusers
>>> # - Skywork/SkyReels-V2-I2V-14B-720P-Diffusers
>>> vae = AutoencoderKLWan.from_pretrained(
...     "Skywork/SkyReels-V2-I2V-14B-720P-Diffusers",
...     subfolder="vae",
...     torch_dtype=torch.float32,
... )
>>> pipe = SkyReelsV2ImageToVideoPipeline.from_pretrained(
...     "Skywork/SkyReels-V2-I2V-14B-720P-Diffusers",
...     vae=vae,
...     torch_dtype=torch.bfloat16,
... )
>>> flow_shift = 5.0  # 8.0 for T2V, 5.0 for I2V
>>> pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=flow_shift)
>>> pipe = pipe.to("cuda")

>>> prompt = "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."
>>> image = Image.open("path/to/image.png")

>>> output = pipe(
...     image=image,
...     prompt=prompt,
...     num_inference_steps=50,
...     height=544,
...     width=960,
...     guidance_scale=5.0,  # 6.0 for T2V, 5.0 for I2V
...     num_frames=97,
... ).frames[0]
>>> export_to_video(output, "video.mp4", fps=24, quality=8)
```

#### encode_prompt[[diffusers.SkyReelsV2ImageToVideoPipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 226, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_skyreels_v2_i2v.py#L241)

**パラメータ:**

prompt (`str` または `list[str]`、*省略可能*) : エンコードするプロンプト

negative_prompt (`str` または `list[str]`、*省略可能*) : 画像生成をガイドしないプロンプトです。定義されていない場合、代わりに `negative_prompt_embeds` を渡す必要があります。ガイドを使用していない場合は無視されます（`guidance_scale` が `1` 未満の場合は無視されます）。

do_classifier_free_guidance (`bool`、*任意*、デフォルトは`True`) : classifier free guidance を使用するかどうか。

num_videos_per_prompt (`int`、*optional*、デフォルトは 1) : 各プロンプトに対して生成すべき動画の数。結果の埋め込みを配置する torch デバイス

prompt_embeds (`torch.Tensor`, *任意*) : 事前生成されたテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`prompt` 入力引数からテキスト埋め込みが生成されます。

negative_prompt_embeds (`torch.Tensor`, *任意*) : 事前に生成されたネガティブなテキスト埋め込み。テキスト入力の調整、*例えば*プロンプトの重み付けなどを容易に行うために使用できます。指定されない場合、`negative_prompt` 入力引数から negative_prompt_embeds が生成されます。

device : (`torch.device`, *任意*): torch デバイス

dtype : (`torch.dtype`, *任意*): torch dtype

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

## SkyReelsV2PipelineOutput[[diffusers.pipelines.skyreels_v2.pipeline_output.SkyReelsV2PipelineOutput]]

#### diffusers.pipelines.skyreels_v2.pipeline_output.SkyReelsV2PipelineOutput[[diffusers.pipelines.skyreels_v2.pipeline_output.SkyReelsV2PipelineOutput]]

```python
diffusers.pipelines.skyreels_v2.pipeline_output.SkyReelsV2PipelineOutput(frames: Tensor)
```

[ソース](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/skyreels_v2/pipeline_output.py#L9)

**パラメータ:**

frames (`torch.Tensor`、`np.ndarray`、または list[list[PIL.Image.Image]]) : 動画出力のリスト - `batch_size,` 長のネストされたリストであり、各サブリストには `num_frames.` 長のデノイズ済み PIL 画像シーケンスが含まれる場合があります。また、`(batch_size, num_frames, channels, height, width)` の形状を持つ NumPy 配列や Torch テンソルである場合もあります。

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

