Skip to content

Commit 4c08ffc

Browse files
mignonjiaclaude
andauthored
[feat] World model training using third person games (#1443)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent af4a775 commit 4c08ffc

37 files changed

Lines changed: 4618 additions & 98 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"alpha_yaw": 0.08734091699186919,
3+
"alpha_pitch": 0.08169667696275307,
4+
"alpha_turn": 5.724587470723463e-17,
5+
"beta_fwd": 0.02842768078408099,
6+
"beta_strafe": 0.022531015077067108,
7+
"focal_length": 457.0,
8+
"frame_shape": [
9+
352,
10+
640
11+
],
12+
"calibrated_from": [
13+
"1_wasd_only",
14+
"camera",
15+
"camera4hold_alpha1",
16+
"fully_random",
17+
"wasdonly_alpha1",
18+
"wasd4holdrandview_simple_1key1mouse1"
19+
],
20+
"residual_rms": 15.890399609478676,
21+
"n_equations": 4125232
22+
}

docs/training/train_infra.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ training:
161161
decay_interval_steps: 0
162162
```
163163

164+
`training.data.data_path` can also mix multiple preprocessed datasets by using a mapping from dataset path to repeat count:
165+
166+
```yaml
167+
training:
168+
data:
169+
data_path:
170+
data/zeldam2-clean: 1
171+
data/multi3d_games: 2
172+
```
173+
174+
The repeat count duplicates that dataset's parquet file list before shuffling/sampling, so the example above trains with roughly twice as much `multi3d_games` exposure as `zeldam2-clean`. Paths are just suggested locations; use any local path that contains a FastVideo preprocessed parquet dataset.
175+
164176
See [Training Trackers](trackers.md) to configure Weights & Biases or SwanLab,
165177
including SwanLab installation and authentication.
166178

@@ -326,6 +338,40 @@ Self-Forcing inherits all DMD2 parameters, plus:
326338
| `enable_gradient_in_rollout` | `true` | Enable backprop through rollout |
327339
| `start_gradient_frame` | `0` | Frame index where gradients begin |
328340

341+
### Streaming Long Tuning
342+
343+
`StreamingLongTuningMethod` extends Self-Forcing for LongLive-style rollouts. It
344+
keeps a streaming state, generates overlapping chunks, and trains only the new
345+
frames while preserving context from earlier chunks.
346+
347+
For the MatrixGame2/Zelda world-model example, self-forcing and long tuning are
348+
separate runs: first train or load the 1k-step self-forcing checkpoint using
349+
`examples/train/scenario/worldmodel/zelda/self_forcing_causal_i2v.yaml`,
350+
then run
351+
`examples/train/scenario/worldmodel/zelda/streaming_long_tuning_causal_i2v.yaml`
352+
from that checkpoint for the 3k-step streaming long-tuning stage.
353+
354+
```yaml
355+
method:
356+
_target_: fastvideo.train.methods.distribution_matching.streaming_long_tuning.StreamingLongTuningMethod
357+
streaming_chunk_size: 9
358+
streaming_max_length: 39
359+
streaming_fixed_overlap_latents: 3
360+
streaming_reencode_overlap_anchor: true
361+
streaming_anchor_inject_k: 1
362+
streaming_require_full_blocks: true
363+
multi_phased_distill_schedule:
364+
- stage: streaming_long
365+
start_step: 0
366+
end_step: 3000
367+
num_latent_t: 39
368+
streaming_training: true
369+
```
370+
371+
See
372+
`examples/train/scenario/worldmodel/zelda/streaming_long_tuning_causal_i2v.yaml`
373+
for a complete MatrixGame2/Zelda configuration.
374+
329375
---
330376

331377
## Callbacks

examples/train/configs/distribution_matching/wan/self_forcing_causal_t2v.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ callbacks:
100100
sampling_steps: [4]
101101
sampling_timesteps: [1000, 750, 500, 250]
102102
num_frames: 81
103-
# Validation/inference uses standard CFG in both clean and Self-Forcing,
104-
# so this directly matches Self-Forcing guidance_scale=3.0.
105-
guidance_scale: 3.0
106103

107104
pipeline:
108105
flow_shift: 5
Lines changed: 96 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,119 @@
11
# World-Model: Matrix-Game 2.0 I2V
22

3-
Three training scenarios for the Matrix-Game 2.0 I2V world model on the
4-
new YAML-driven trainer (`fastvideo/train/entrypoint/train.py`).
3+
Training scenarios for the Matrix-Game 2.0 I2V world model on Solaris (Minecraft)
4+
data and Zelda data, using the new YAML-driven trainer
5+
(`fastvideo/train/entrypoint/train.py`).
6+
7+
## Solaris Configs
8+
9+
| Config | Method | Student | Notes |
10+
|---|---|---|---|
11+
| `solaris/finetune_i2v.yaml` | `FineTuneMethod` | `MatrixGame2Model` (bidirectional) | Multi-step SFT from `mg_bidirectional_Solaris`. |
12+
| `solaris/dfsft_causal_i2v.yaml` | `DiffusionForcingSFTMethod` | `MatrixGame2CausalModel` | Diffusion-Forcing SFT with chunkwise timesteps. |
13+
| `solaris/self_forcing_causal_i2v.yaml` | `SelfForcingMethod` | `MatrixGame2CausalModel` | Matrix-Game 2.0 DMD/Self-Forcing distillation; teacher = bidirectional, critic = bidirectional. |
14+
15+
## Zelda Configs
516

617
| Config | Method | Student | Notes |
718
|---|---|---|---|
8-
| `finetune_i2v.yaml` | `FineTuneMethod` | `MatrixGame2Model` (bidirectional) | Multi-step SFT from `mg_bidirectional_Solaris`. |
9-
| `dfsft_causal_i2v.yaml` | `DiffusionForcingSFTMethod` | `MatrixGame2CausalModel` | Diffusion-Forcing SFT with chunkwise timesteps. |
10-
| `self_forcing_causal_i2v.yaml` | `SelfForcingMethod` | `MatrixGame2CausalModel` | DMD/Self-Forcing distillation; teacher = bidirectional, critic = bidirectional. |
19+
| `zelda/finetune_i2v.yaml` | `FineTuneMethod` | `MatrixGame2Model` (bidirectional) | Zelda bidirectional I2V finetuning from `FastVideo/Matrix-Game-2.0-Base-Diffusers`. Uses 33-frame clips and Zelda validation with action overlays. |
20+
| `zelda/dfsft_causal_i2v.yaml` | `DiffusionForcingSFTMethod` | `MatrixGame2CausalModel` | Zelda causal Diffusion-Forcing SFT from `mignonjia/mg_bidirectional_zelda`. Uses the same Zelda data, resolution, optimizer, and validation defaults as the Zelda finetune config. |
21+
| `zelda/self_forcing_causal_i2v.yaml` | `SelfForcingMethod` | `MatrixGame2CausalModel` | Zelda DMD/Self-Forcing distillation; student init = `mignonjia/mg_causal_zelda`, teacher = bidirectional (`mignonjia/mg_bidirectional_zelda`), critic = bidirectional. |
22+
| `zelda/streaming_long_tuning_causal_i2v.yaml` | `StreamingLongTuningMethod` | `MatrixGame2CausalModel` | LongLive-style streaming long tuning from the 1k-step Zelda self-forcing checkpoint. |
23+
24+
Zelda world-model distillation is a two-run workflow: first run
25+
`zelda/self_forcing_causal_i2v.yaml` to train or load the 1k-step
26+
self-forcing checkpoint (`mignonjia/mg_sf_distilled_zelda_1k_steps`), then run
27+
`zelda/streaming_long_tuning_causal_i2v.yaml` for the 3k-step streaming
28+
long-tuning stage. The long-tuning YAML starts from that 1k-step checkpoint; it
29+
does not run the short self-forcing stage inside the same config.
30+
31+
## Zelda Training Data
32+
33+
The Zelda training configs use `data/zeldam2-clean` as a suggested local path.
34+
Download the dataset from Hugging Face before running those configs:
35+
36+
```bash
37+
python scripts/huggingface/download_hf.py \
38+
--repo_id mignonjia/zeldam2-clean \
39+
--local_dir data/zeldam2-clean \
40+
--repo_type dataset
41+
```
42+
43+
You can store the dataset elsewhere; update `training.data.data_path` in the
44+
YAML to point at that location.
45+
46+
## Multi3D Training Data
47+
48+
`zelda/finetune_i2v.yaml` includes an optional, commented-out Multi3D entry.
49+
Enable it only when you want to mix Zelda with multi-game data from
50+
`data/multi3d_games`. You can store this dataset anywhere; before enabling it,
51+
update the matching commented `training.data.data_path` key in the YAML to the
52+
correct location.
53+
54+
To mix datasets in a training YAML, set `training.data.data_path` to a
55+
path-to-repeat-count mapping. For example, `zelda/finetune_i2v.yaml` can use
56+
`data/zeldam2-clean: 1` and `# data/multi3d_games: 10`; uncommenting the
57+
Multi3D entry repeats the multi-game parquet list ten times before training
58+
samples are shuffled.
59+
60+
## World Model Validation Data
61+
62+
The Zelda validation configs expect a small public validation bundle under
63+
`data/zelda_validation_data`.
64+
65+
Download it from Hugging Face before running the Zelda scenarios:
66+
67+
```bash
68+
python scripts/huggingface/download_hf.py \
69+
--repo_id mignonjia/zelda_validation_data \
70+
--local_dir data/zelda_validation_data \
71+
--repo_type dataset
72+
```
73+
74+
The bundle contains `validation_zelda.json`, `images/`, and `actions/`.
75+
The Zelda configs point
76+
`callbacks.validation.dataset_file` at
77+
`data/zelda_validation_data/validation_zelda.json`.
1178

1279
## Usage
1380

81+
### Solaris
82+
1483
```bash
1584
bash examples/train/run.sh \
16-
examples/train/scenario/worldmodel/finetune_i2v.yaml
85+
examples/train/scenario/worldmodel/solaris/finetune_i2v.yaml
86+
87+
bash examples/train/run.sh \
88+
examples/train/scenario/worldmodel/solaris/dfsft_causal_i2v.yaml
89+
90+
bash examples/train/run.sh \
91+
examples/train/scenario/worldmodel/solaris/self_forcing_causal_i2v.yaml
92+
```
93+
94+
### Zelda
95+
96+
```bash
97+
# Finetuning / DFSFT
98+
bash examples/train/run.sh \
99+
examples/train/scenario/worldmodel/zelda/finetune_i2v.yaml
100+
101+
bash examples/train/run.sh \
102+
examples/train/scenario/worldmodel/zelda/dfsft_causal_i2v.yaml
17103

104+
# Distillation / long tuning
18105
bash examples/train/run.sh \
19-
examples/train/scenario/worldmodel/dfsft_causal_i2v.yaml
106+
examples/train/scenario/worldmodel/zelda/self_forcing_causal_i2v.yaml
20107

21108
bash examples/train/run.sh \
22-
examples/train/scenario/worldmodel/self_forcing_causal_i2v.yaml
109+
examples/train/scenario/worldmodel/zelda/streaming_long_tuning_causal_i2v.yaml
23110
```
24111

25112
Override any field on the command line:
26113

27114
```bash
28115
bash examples/train/run.sh \
29-
examples/train/scenario/worldmodel/dfsft_causal_i2v.yaml \
116+
examples/train/scenario/worldmodel/solaris/dfsft_causal_i2v.yaml \
30117
--training.distributed.num_gpus 8 \
31118
--training.optimizer.learning_rate 1e-5
32119
```

examples/train/scenario/worldmodel/dfsft_causal_i2v.yaml renamed to examples/train/scenario/worldmodel/solaris/dfsft_causal_i2v.yaml

File renamed without changes.

examples/train/scenario/worldmodel/finetune_i2v.yaml renamed to examples/train/scenario/worldmodel/solaris/finetune_i2v.yaml

File renamed without changes.

examples/train/scenario/worldmodel/self_forcing_causal_i2v.yaml renamed to examples/train/scenario/worldmodel/solaris/self_forcing_causal_i2v.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@ callbacks:
9797
guidance_scale: 6.0
9898

9999
pipeline:
100-
flow_shift: 5
100+
flow_shift: 5
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Diffusion-Forcing SFT: Zelda world model I2V Causal
2+
3+
models:
4+
student:
5+
_target_: fastvideo.train.models.matrixgame2.matrixgame2_causal.MatrixGame2CausalModel
6+
init_from: mignonjia/mg_bidirectional_zelda
7+
trainable: true
8+
9+
method:
10+
_target_: fastvideo.train.methods.fine_tuning.dfsft.DiffusionForcingSFTMethod
11+
chunk_size: 3
12+
13+
training:
14+
distributed:
15+
num_gpus: 8
16+
sp_size: 1
17+
tp_size: 1
18+
hsdp_replicate_dim: 1
19+
hsdp_shard_dim: 8
20+
21+
data:
22+
data_path:
23+
data/zeldam2-clean: 1
24+
dataloader_num_workers: 1
25+
train_batch_size: 1
26+
training_cfg_rate: 0.0
27+
seed: 42
28+
num_latent_t: 9
29+
num_height: 480
30+
num_width: 832
31+
num_frames: 33
32+
33+
optimizer:
34+
learning_rate: 2.0e-5
35+
betas: [0.9, 0.95]
36+
weight_decay: 0.0
37+
lr_scheduler: constant
38+
lr_warmup_steps: 0
39+
40+
loop:
41+
max_train_steps: 60000
42+
gradient_accumulation_steps: 1
43+
44+
checkpoint:
45+
output_dir: outputs/matrixgame_finetune/checkpoints/zelda_causal_dfsft
46+
training_state_checkpointing_steps: 5000
47+
checkpoints_total_limit: 3
48+
49+
tracker:
50+
entity: hapo-exp
51+
project_name: mg_1.3b_zelda
52+
run_name: zelda_causal_dfsft
53+
54+
model:
55+
enable_gradient_checkpointing_type: full
56+
57+
dit_precision: fp32
58+
59+
callbacks:
60+
grad_clip:
61+
max_grad_norm: 1.0
62+
validation:
63+
pipeline_target: fastvideo.pipelines.basic.matrixgame2.matrixgame2_causal_dmd_pipeline.MatrixGame2CausalDMDPipeline
64+
dataset_file: data/zelda_validation_data/validation_zelda.json
65+
every_steps: 200
66+
sampling_steps: [40]
67+
sampling_timesteps: [1000, 975, 950, 925, 900, 875, 850, 825, 800, 775,
68+
750, 725, 700, 675, 650, 625, 600, 575, 550, 525,
69+
500, 475, 450, 425, 400, 375, 350, 325, 300, 275,
70+
250, 225, 200, 175, 150, 125, 100, 75, 50, 25]
71+
num_frames: 33
72+
overlay_actions: true
73+
guidance_scale: 6.0
74+
metrics:
75+
enabled: true
76+
names:
77+
- vbench.imaging_quality
78+
- vbench.aesthetic_quality
79+
- vbench.temporal_flickering
80+
- vbench.motion_smoothness
81+
- vbench.subject_consistency
82+
- vbench.background_consistency
83+
- vbench.dynamic_degree
84+
- optical_flow.synthetic_optical_flow
85+
calibration_path: assets/eval/worldmodel_synthetic_flow_calibration.json
86+
skip_missing_deps: true
87+
strict: false
88+
unload_after_validation: true
89+
90+
pipeline:
91+
flow_shift: 5
92+
dit_config:
93+
local_attn_size: 6
94+
sink_size: 1

0 commit comments

Comments
 (0)