Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
74c0c72
add mg3 model
H1yori233 Mar 28, 2026
202a81b
light vae for mg3
H1yori233 Mar 29, 2026
4dd54bf
cleanup
H1yori233 Mar 30, 2026
c383441
fix action
H1yori233 Mar 30, 2026
0cf1c10
some check in denoising stage
H1yori233 Mar 30, 2026
941e843
update model
H1yori233 Mar 30, 2026
ece6fab
Merge remote-tracking branch 'origin/main' into feat/kaiqin/add-mg-3
H1yori233 Mar 31, 2026
1ae0efe
cleanup and precommit
H1yori233 Apr 1, 2026
9146d1e
Merge remote-tracking branch 'origin/main' into feat/kaiqin/add-mg-3
H1yori233 May 14, 2026
99be70d
rename matrixgame2
H1yori233 May 14, 2026
5a040f5
inference script
H1yori233 May 15, 2026
71caee7
Merge remote-tracking branch 'origin/main' into feat/kaiqin/add-mg-3
H1yori233 May 18, 2026
b92d9de
cleanup
H1yori233 May 18, 2026
1c26c2b
align light vae
H1yori233 May 18, 2026
1715b18
some fix
H1yori233 May 18, 2026
5b3be80
update doc
H1yori233 May 18, 2026
d209f16
grid_sizes use tuple instead of tensor
H1yori233 May 19, 2026
a067cf2
removed unnecessary device transfers and optimized tensor creation fo…
H1yori233 May 19, 2026
956e85a
Improved tensor creation by ensuring proper generator type and added …
H1yori233 May 19, 2026
4f8b730
Refactor video file handling in SSIM test
H1yori233 May 19, 2026
d2e2041
some fix
H1yori233 May 19, 2026
d296ccf
some fix
H1yori233 May 19, 2026
a1de2d7
remove kvcache dead code
H1yori233 May 19, 2026
fd35b66
remove deadcode
H1yori233 May 19, 2026
96505d1
remove onboarding
H1yori233 May 19, 2026
853db84
configuration and inference parameters
H1yori233 May 19, 2026
df40e2c
some fix
H1yori233 May 19, 2026
3528141
fix name
H1yori233 May 19, 2026
f63cef0
[bugfix]: assert batch_size=1 contract for MG3 extrinsics
SolitaryThinker May 27, 2026
d0f9d12
[ci]: lower MG3 SSIM test resolution + add L40S device fallback
SolitaryThinker May 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/inference/support_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pipeline initialization and sampling.
| Matrix Game 2.0 Base Distilled | `FastVideo/Matrix-Game-2.0-Base-Distilled-Diffusers` | 352x640 | ⭕ | ⭕ | ⭕ | ⭕ | ⭕ |
| Matrix Game 2.0 GTA Distilled | `FastVideo/Matrix-Game-2.0-GTA-Distilled-Diffusers` | 352x640 | ⭕ | ⭕ | ⭕ | ⭕ | ⭕ |
| Matrix Game 2.0 TempleRun Distilled | `FastVideo/Matrix-Game-2.0-TempleRun-Distilled-Diffusers` | 352x640 | ⭕ | ⭕ | ⭕ | ⭕ | ⭕ |
| Matrix Game 3.0 Base Distilled | `FastVideo/Matrix-Game-3.0-Base-Distilled-Diffusers` | 720x1280 | ⭕ | ⭕ | ⭕ | ⭕ | ⭕ |
| GEN3C Cosmos 7B | `FastVideo/GEN3C-Cosmos-7B-Diffusers` | 704px1280p | ❌ | ❌ | ❌ | ⭕ | ⭕ |

**Note**: Wan2.2 TI2V 5B has some quality issues when performing I2V generation. We are working on fixing this issue.
Expand Down
35 changes: 35 additions & 0 deletions examples/inference/basic/basic_matrixgame3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from fastvideo import VideoGenerator

MODEL_PATH = "FastVideo/Matrix-Game-3.0-Base-Distilled-Diffusers"
IMAGE_URL = "https://raw.githubusercontent.com/SkyworkAI/Matrix-Game/main/Matrix-Game-3/demo_images/001/image.png"
PROMPT = "A colorful, animated cityscape with a gas station and various buildings."
OUTPUT_PATH = "video_samples_matrixgame3"


def main():
generator = VideoGenerator.from_pretrained(
MODEL_PATH,
num_gpus=1,
use_fsdp_inference=False,
dit_cpu_offload=False,
vae_cpu_offload=False,
text_encoder_cpu_offload=True,
pin_cpu_memory=True,
)

generator.generate_video(
prompt=PROMPT,
image_path=IMAGE_URL,
height=720,
width=1280,
num_frames=57,
num_inference_steps=3,
guidance_scale=1.0,
seed=42,
output_path=OUTPUT_PATH,
save_video=True,
)


if __name__ == "__main__":
main()
17 changes: 17 additions & 0 deletions fastvideo/api/matrixgame3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: Apache-2.0
from dataclasses import dataclass

from fastvideo.api.sampling_param import SamplingParam


@dataclass
class MatrixGame3SamplingParam(SamplingParam):
height: int = 720
width: int = 1280
num_frames: int = 57
fps: int = 25
guidance_scale: float = 1.0
num_inference_steps: int = 3
negative_prompt: str = ""
num_iterations: int | None = None
use_base_model: bool = False
79 changes: 79 additions & 0 deletions fastvideo/configs/models/dits/matrixgame3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from dataclasses import dataclass, field

import torch
from fastvideo.configs.models.dits.wanvideo import WanVideoArchConfig, WanVideoConfig


def _is_transformer_block(param_name: str, module: torch.nn.Module) -> bool:
return bool("blocks" in param_name and param_name.split(".")[-1].isdigit())


@dataclass
class MatrixGame3WanVideoArchConfig(WanVideoArchConfig):
param_names_mapping: dict = field(
default_factory=lambda: {
r"^patch_embedding\.(weight|bias)$": r"patch_embedding.proj.\1",
r"^patch_embedding_wancamctrl\.(.*)$": r"camera_patch_embedding.proj.\1",
r"^time_embedding\.0\.(.*)$": r"condition_embedder.time_embedder.mlp.fc_in.\1",
r"^time_embedding\.2\.(.*)$": r"condition_embedder.time_embedder.mlp.fc_out.\1",
r"^time_projection\.1\.(.*)$": r"condition_embedder.time_modulation.linear.\1",
r"^head\.head\.(.*)$": r"proj_out.\1",
r"^head\.modulation$": r"scale_shift_table",
r"^blocks\.(\d+)\.self_attn\.q\.(.*)$": r"blocks.\1.to_q.\2",
r"^blocks\.(\d+)\.self_attn\.k\.(.*)$": r"blocks.\1.to_k.\2",
r"^blocks\.(\d+)\.self_attn\.v\.(.*)$": r"blocks.\1.to_v.\2",
r"^blocks\.(\d+)\.self_attn\.o\.(.*)$": r"blocks.\1.to_out.\2",
r"^blocks\.(\d+)\.self_attn\.norm_q\.(.*)$": r"blocks.\1.norm_q.\2",
r"^blocks\.(\d+)\.self_attn\.norm_k\.(.*)$": r"blocks.\1.norm_k.\2",
r"^blocks\.(\d+)\.cross_attn\.q\.(.*)$": r"blocks.\1.attn2.to_q.\2",
r"^blocks\.(\d+)\.cross_attn\.k\.(.*)$": r"blocks.\1.attn2.to_k.\2",
r"^blocks\.(\d+)\.cross_attn\.v\.(.*)$": r"blocks.\1.attn2.to_v.\2",
r"^blocks\.(\d+)\.cross_attn\.o\.(.*)$": r"blocks.\1.attn2.to_out.\2",
r"^blocks\.(\d+)\.cross_attn\.norm_q\.(.*)$": r"blocks.\1.attn2.norm_q.\2",
r"^blocks\.(\d+)\.cross_attn\.norm_k\.(.*)$": r"blocks.\1.attn2.norm_k.\2",
r"^blocks\.(\d+)\.ffn\.0\.(.*)$": r"blocks.\1.ffn.fc_in.\2",
r"^blocks\.(\d+)\.ffn\.2\.(.*)$": r"blocks.\1.ffn.fc_out.\2",
r"^blocks\.(\d+)\.norm3\.(.*)$": r"blocks.\1.self_attn_residual_norm.norm.\2",
r"^blocks\.(\d+)\.modulation$": r"blocks.\1.scale_shift_table",
})
patch_size: tuple[int, int, int] = (1, 2, 2)
in_channels: int = 48
out_channels: int = 48
num_attention_heads: int = 24
attention_head_dim: int = 128
ffn_dim: int = 14336
num_layers: int = 30
text_len: int = 512
image_dim: int = 0
use_text_crossattn: bool = True
use_memory: bool = True
sigma_theta: float = 0.8
camera_embed_in_channels: int = 1536
action_config: dict = field(
default_factory=lambda: {
"blocks": list(range(15)),
"enable_mouse": True,
"enable_keyboard": True,
"heads_num": 16,
"hidden_size": 128,
"img_hidden_size": 3072,
"keyboard_dim_in": 6,
"keyboard_hidden_dim": 1024,
"mouse_dim_in": 2,
"mouse_hidden_dim": 1024,
"mouse_qk_dim_list": [8, 28, 28],
"patch_size": [1, 2, 2],
"qk_norm": True,
"qkv_bias": False,
"rope_dim_list": [8, 28, 28],
"rope_theta": 256,
"vae_time_compression_ratio": 4,
"windows_size": 3,
})


@dataclass
class MatrixGame3WanVideoConfig(WanVideoConfig):
arch_config: MatrixGame3WanVideoArchConfig = field(default_factory=MatrixGame3WanVideoArchConfig)
prefix: str = "Wan"
_compile_conditions: list = field(default_factory=lambda: [_is_transformer_block])
2 changes: 2 additions & 0 deletions fastvideo/configs/models/vaes/wanvae.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,7 @@ class WanVAEConfig(VAEConfig):
use_temporal_tiling: bool = False
use_parallel_tiling: bool = False

use_light_vae: bool = False

def __post_init__(self):
self.blend_num_frames = (self.tile_sample_min_num_frames - self.tile_sample_stride_num_frames) * 2
3 changes: 2 additions & 1 deletion fastvideo/configs/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from fastvideo.configs.pipelines.hunyuangamecraft import HunyuanGameCraftPipelineConfig
from fastvideo.configs.pipelines.hyworld import HYWorldConfig
from fastvideo.configs.pipelines.matrixgame2 import MatrixGame2I2V480PConfig
from fastvideo.configs.pipelines.matrixgame3 import MatrixGame3I2V720PConfig
from fastvideo.pipelines.basic.ltx2.pipeline_configs import LTX2T2VConfig
from fastvideo.registry import get_pipeline_config_cls_from_name
from fastvideo.configs.pipelines.wan import (SelfForcingWanT2V480PConfig, WanI2V480PConfig, WanI2V720PConfig,
Expand All @@ -15,5 +16,5 @@
"HunyuanConfig", "FastHunyuanConfig", "HunyuanGameCraftPipelineConfig", "PipelineConfig", "Hunyuan15T2V480PConfig",
"Hunyuan15T2V720PConfig", "WanT2V480PConfig", "WanI2V480PConfig", "WanT2V720PConfig", "WanI2V720PConfig",
"SelfForcingWanT2V480PConfig", "CosmosConfig", "Cosmos25Config", "LTX2T2VConfig", "HYWorldConfig",
"MatrixGame2I2V480PConfig", "get_pipeline_config_cls_from_name"
"MatrixGame2I2V480PConfig", "MatrixGame3I2V720PConfig", "get_pipeline_config_cls_from_name"
]
18 changes: 18 additions & 0 deletions fastvideo/configs/pipelines/matrixgame3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-License-Identifier: Apache-2.0
from dataclasses import dataclass, field

from fastvideo.configs.models import DiTConfig
from fastvideo.configs.models.dits.matrixgame3 import MatrixGame3WanVideoConfig
from fastvideo.configs.pipelines.wan import WanT2V480PConfig


@dataclass
class MatrixGame3I2V720PConfig(WanT2V480PConfig):
dit_config: DiTConfig = field(default_factory=MatrixGame3WanVideoConfig)
flow_shift: float | None = 5.0
vae_precision: str = "fp32"

def __post_init__(self) -> None:
self.vae_config.load_encoder = True
self.vae_config.load_decoder = True
self.vae_config.use_light_vae = True
11 changes: 11 additions & 0 deletions fastvideo/models/dits/matrixgame3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .action_module import MatrixGame3ActionModule
from .model import MatrixGame3CrossAttention, MatrixGame3TransformerBlock, MatrixGame3WanModel

__all__ = [
"MatrixGame3WanModel",
"MatrixGame3TransformerBlock",
"MatrixGame3CrossAttention",
"MatrixGame3ActionModule",
]

EntryClass = [MatrixGame3WanModel]
Loading
Loading