yuzhewu207 commited on
Commit
be18742
·
verified ·
1 Parent(s): 69e0f40

code/: mirror of wizard27-clean f853184 (scripts as trained)

Browse files
code/README.md CHANGED
@@ -90,10 +90,9 @@ Each run writes `out.mp4` (generation | proxy) and `out_gen.mp4` (generation onl
90
  | Stage | Module | Script |
91
  |---|---|---|
92
  | 1. Bidirectional teacher | `wizard.train.bidirectional` | `scripts/train/1_bidirectional.sh` |
93
- | 2. Causal teacher forcing | `wizard.train.causal` | `scripts/train/2_causal.sh` |
94
- | 2b. History self-augmentation | `wizard.train.causal_selfaug` | `scripts/train/3_causal_selfaug.sh` |
95
- | 3. Consistency distillation | `wizard.distill.consistency_selfaug` | `scripts/train/4_consistency.sh` |
96
- | 4. Distribution matching distillation | `wizard.distill.dmd` | `scripts/train/5_dmd.sh` |
97
 
98
  Commands, hyper-parameters and the data layout: [docs/TRAINING.md](docs/TRAINING.md) and [docs/DATA.md](docs/DATA.md).
99
 
@@ -103,8 +102,8 @@ All weights are DiT checkpoints fine-tuned from Wan2.2-TI2V-5B (the VAE and T5 a
103
 
104
  | File | Model | Sampling |
105
  |---|---|---|
106
- | `causal_dmd/ema_step480.safetensors` | real-time 2-step student (stage 4, DMD) | `causal` / `world`, 2 steps |
107
- | `causal_cd/ema_step10000.safetensors` | consistency-distilled student (stage 3), the starting point of DMD | `causal` / `world`, 2 steps |
108
  | `causal_teacher/dit_step11000.safetensors` | causal teacher (stage 2) | teacher of stage 3 |
109
  | `bidirectional_main/dit_step35000.safetensors` | bidirectional teacher (stage 1), the model of the paper's main table | `bidirectional`, 30 steps, CFG 3 |
110
  | `bidirectional/dit_step35000.safetensors` | bidirectional teacher trained with the world-edit clips as well | `bidirectional`, 30 steps, CFG 3 |
 
90
  | Stage | Module | Script |
91
  |---|---|---|
92
  | 1. Bidirectional teacher | `wizard.train.bidirectional` | `scripts/train/1_bidirectional.sh` |
93
+ | 2. Causal teacher (teacher forcing + history self-augmentation) | `wizard.train.causal_selfaug` | `scripts/train/2_causal.sh` |
94
+ | 3. Consistency distillation | `wizard.distill.consistency_selfaug_future` | `scripts/train/3_consistency.sh` |
95
+ | 4. Distribution matching distillation | `wizard.distill.dmd` | `scripts/train/4_dmd.sh` |
 
96
 
97
  Commands, hyper-parameters and the data layout: [docs/TRAINING.md](docs/TRAINING.md) and [docs/DATA.md](docs/DATA.md).
98
 
 
102
 
103
  | File | Model | Sampling |
104
  |---|---|---|
105
+ | `causal_dmd/ema_step480.safetensors` | real-time 2-step student (stage 4, DMD), distilled from `bidirectional_main` (an earlier run of the chain; the student trained with the scripts below from `bidirectional` will replace it) | `causal` / `world`, 2 steps |
106
+ | `causal_cd/ema_step10000.safetensors` | consistency-distilled student (stage 3) of that earlier run, the starting point of its DMD | `causal` / `world`, 2 steps |
107
  | `causal_teacher/dit_step11000.safetensors` | causal teacher (stage 2) | teacher of stage 3 |
108
  | `bidirectional_main/dit_step35000.safetensors` | bidirectional teacher (stage 1), the model of the paper's main table | `bidirectional`, 30 steps, CFG 3 |
109
  | `bidirectional/dit_step35000.safetensors` | bidirectional teacher trained with the world-edit clips as well | `bidirectional`, 30 steps, CFG 3 |
code/docs/DATA.md CHANGED
@@ -14,6 +14,7 @@ roam_memory/ roaming memory banks, mem_index*.pt, rep_keys_both30.json
14
  scenefly/ revisit sequences (SceneFly), rows.jsonl
15
  scenefly_replay/ revisit sequences replayed backwards, rows.jsonl
16
  synth_lookback_geo/ synthetic look-back sequences (camera turns away and back), rows_full.jsonl
 
17
  ```
18
 
19
  Each row belongs to a **group**, used for the mixing weights (`--group_rep group:weight,...`):
@@ -25,6 +26,7 @@ Each row belongs to a **group**, used for the mixing weights (`--group_rep group
25
  | `roam` | roaming recordings |
26
  | `sfly`, `sfly_replay`, `lookback`, `lookback0` | revisits: the camera comes back to a place it has seen |
27
  | `ww`, `er`, `ue`, `bk` | duels |
 
28
 
29
  The pre-encoded data is released in [`yuzhewu207/wizard-precoded`](https://huggingface.co/datasets/yuzhewu207/wizard-precoded) (the exact files the models were trained on, minus the WildWorld windows; see the WildWorld note in the README): group `ww` has no rows). Restore it with
30
 
 
14
  scenefly/ revisit sequences (SceneFly), rows.jsonl
15
  scenefly_replay/ revisit sequences replayed backwards, rows.jsonl
16
  synth_lookback_geo/ synthetic look-back sequences (camera turns away and back), rows_full.jsonl
17
+ worldedit/ world-edit clips (objects / terrain changing in front of the camera), rows_train.jsonl, mem_index.pt, bank/ (read with WEDIT=1)
18
  ```
19
 
20
  Each row belongs to a **group**, used for the mixing weights (`--group_rep group:weight,...`):
 
26
  | `roam` | roaming recordings |
27
  | `sfly`, `sfly_replay`, `lookback`, `lookback0` | revisits: the camera comes back to a place it has seen |
28
  | `ww`, `er`, `ue`, `bk` | duels |
29
+ | `wedit` | world edits (stages 1 from 3k, 2 and 3) |
30
 
31
  The pre-encoded data is released in [`yuzhewu207/wizard-precoded`](https://huggingface.co/datasets/yuzhewu207/wizard-precoded) (the exact files the models were trained on, minus the WildWorld windows; see the WildWorld note in the README): group `ww` has no rows). Restore it with
32
 
code/docs/TRAINING.md CHANGED
@@ -8,27 +8,27 @@ export WAN_CKPT=/path/to/Wan2.2-TI2V-5B WIZARD_DATA=/path/to/data
8
 
9
  ## Pipeline
10
 
 
 
11
  ```bash
12
- bash scripts/train/1_bidirectional.sh runs/bidir # 0 -> 30k
13
- PHASE=2 INIT=runs/bidir/dits/dit_step30000.safetensors STEP0=30000 \
14
- bash scripts/train/1_bidirectional.sh runs/bidir # 30k -> 35k
15
- bash scripts/train/2_causal.sh runs/bidir/dits/dit_step35000.safetensors runs/causal
16
- SA_P=0.7 SA_MAX=0.5 SA_GROUPS=all \
17
- bash scripts/train/3_causal_selfaug.sh runs/causal/dits/dit_step3000.safetensors 3000 runs/causal_sa 3500
18
- bash scripts/train/3_causal_selfaug.sh runs/causal_sa/dits/dit_step3500.safetensors 3500 runs/causal_sa2 11000
19
- bash scripts/train/4_consistency.sh runs/causal_sa2/dits/dit_step11000.safetensors runs/cd
20
- bash scripts/train/5_dmd.sh runs/cd/ema/ema_step10000.safetensors runs/bidir/dits/dit_step35000.safetensors runs/dmd
21
  ```
22
 
 
 
 
 
23
  ## Stages
24
 
25
  | Stage | Steps | Batch | LR | Notes |
26
  |---|---|---|---|---|
27
- | 1. Bidirectional | 30k + 5k | 8 | 1e-5 (condition layers 1e-4) | phase 2: unknown cells carry no coordinates, `p_unk2 0.5` |
28
- | 2. Causal teacher forcing | 3k | 8 | 1e-5 | history window 20 + sink 1; memory from the past only |
29
- | 2b. History self-augmentation | 3k → 3.5k → 11k | 8 | 1e-5 | `SA_P 0.7 / SA_MAX 0.5` on all clips, then `0.5 / 0.25` on revisit clips |
30
- | 3. Consistency distillation | 10k | 8 | 2e-6, EMA 0.99 | N = 48 levels, 2 sampling steps (1000, 500), teacher CFG 3 |
31
- | 4. DMD | 400+ | 32 (8 × accum 4) | 2e-6 / critic 4e-7 | critic : student = 5 : 1, real score CFG 3 |
32
 
33
  Hyper-parameters not set in the scripts keep the defaults of each module's argument parser.
34
 
@@ -38,7 +38,7 @@ one-step estimate from a noised copy (`σ ~ U(0, SA_MAX)`); frame 0, the memory
38
  stage 3 the teacher keeps the clean history and only the student / EMA read the augmented one.
39
 
40
  **Resuming DMD.** Every save also writes `student_last.safetensors` and `fake_last.safetensors`:
41
- `EXTRA="--fake runs/dmd/fake_last.safetensors --step0 <N>" bash scripts/train/5_dmd.sh runs/dmd/ema/ema_step<N>.safetensors ...`
42
 
43
  ## Training-time switches (environment)
44
 
@@ -46,6 +46,7 @@ stage 3 the teacher keeps the clean history and only the student / EMA read the
46
  |---|---|---|
47
  | `UNK_NOCOORD=1` | all | unknown cells carry no world coordinates |
48
  | `MEMW_COVER=1` | all | cells the window's first frame has not seen but a retrieved memory frame has get loss weight `--mem_loss_w`; "seen" by projected coverage |
49
- | `MEMW_HISTW`, `MEMW_SINK` | 2b | "seen" also by every clean history frame the noisy frame reads (window + sink), so the weight sits where only memory can tell |
50
- | `MEM_FUTURE=1` | 2b | SceneFly windows may also retrieve frames after the window |
51
- | `SA_P`, `SA_MAX`, `SA_GROUPS` | 2b, 3 | history self-augmentation |
 
 
8
 
9
  ## Pipeline
10
 
11
+ The scripts reproduce the run that produced the released `bidirectional`, `causal_teacher` checkpoints and the current distillation chain:
12
+
13
  ```bash
14
+ bash scripts/train/1_bidirectional.sh runs/bidir # 0 -> 3k, then + world-edit clips 3k -> 35k
15
+ bash scripts/train/2_causal.sh runs/bidir/dits/dit_step35000.safetensors runs/causal # 0 -> 11k
16
+ bash scripts/train/3_consistency.sh runs/causal/dits/dit_step11000.safetensors runs/cd # 0 -> 10k
17
+ bash scripts/train/4_dmd.sh runs/cd/ema/ema_step10000.safetensors runs/bidir/dits/dit_step35000.safetensors runs/dmd # 500
 
 
 
 
 
18
  ```
19
 
20
+ Our runs were interrupted and resumed (the scripts' comments say how): stage 1 phase 2 restarted from the 3k checkpoint
21
+ when the world-edit clips were added; stage 2 was resumed from its own checkpoints (seed = resume step); stage 3 ran 0 -> 2.7k
22
+ and was then warm-started from its 2k EMA (`STUDENT_INIT`, `STEP0=2000`, `SEED=1`) to 10k.
23
+
24
  ## Stages
25
 
26
  | Stage | Steps | Batch | LR | Notes |
27
  |---|---|---|---|---|
28
+ | 1. Bidirectional | 3k + 32k | 8 | 1e-5 (condition layers 1e-4) | unknown cells without coordinates, `p_unk2 0.5`, memory loss weight 3; world-edit clips (`WEDIT=1`) from 3k |
29
+ | 2. Causal teacher | 11k | 8 | 1e-5 (condition layers 1e-5) | history window 20 + sink 1; history self-augmentation `SA_P 0.5 / SA_MAX 0.25` on revisit clips; memory from before and after the window |
30
+ | 3. Consistency distillation | 10k | 8 | 2e-6, EMA 0.99 | N = 48 levels, 2 sampling steps (1000, 500), teacher CFG 3, `SA_P 0.7 / SA_MAX 0.5`; memory before and after the window |
31
+ | 4. DMD | 500 | 32 (8 × accum 4) | 2e-6 / critic 4e-7 | critic : student = 5 : 1, real score = the stage-1 model with CFG 3; memory from the past only, no world-edit clips |
 
32
 
33
  Hyper-parameters not set in the scripts keep the defaults of each module's argument parser.
34
 
 
38
  stage 3 the teacher keeps the clean history and only the student / EMA read the augmented one.
39
 
40
  **Resuming DMD.** Every save also writes `student_last.safetensors` and `fake_last.safetensors`:
41
+ `EXTRA="--fake runs/dmd/fake_last.safetensors --step0 <N>" bash scripts/train/4_dmd.sh runs/dmd/ema/ema_step<N>.safetensors ...`
42
 
43
  ## Training-time switches (environment)
44
 
 
46
  |---|---|---|
47
  | `UNK_NOCOORD=1` | all | unknown cells carry no world coordinates |
48
  | `MEMW_COVER=1` | all | cells the window's first frame has not seen but a retrieved memory frame has get loss weight `--mem_loss_w`; "seen" by projected coverage |
49
+ | `WEDIT=1` | 1 (from 3k), 2, 3 | add the world-edit clips' memory index and banks (`worldedit/`); their rows come with `--extra_rows worldedit/rows_train.jsonl` |
50
+ | `MEMW_HISTW`, `MEMW_SINK` | 2 | "seen" also by every clean history frame the noisy frame reads (window + sink), so the weight sits where only memory can tell |
51
+ | `MEM_FUTURE=1` | 2 | SceneFly windows may also retrieve frames after the window (stage 3 does the same through `wizard.distill.consistency_selfaug_future`) |
52
+ | `SA_P`, `SA_MAX`, `SA_GROUPS` | 2, 3 | history self-augmentation |
code/scripts/train/1_bidirectional.sh CHANGED
@@ -1,13 +1,16 @@
1
  #!/bin/bash
2
- # Stage 1: bidirectional teacher, from the official Wan2.2-TI2V-5B weights.
3
- # bash scripts/train/1_bidirectional.sh <out dir>
4
- # Our teacher was trained in two phases on 8 GPUs: phase 1 (0 -> 30k steps, p_trueunk 0.3, p_memunk 0.5) and
5
- # phase 2 (30k -> 35k: every unknown cell without coordinates, p_unk2 0.5, p_memunk 0). Set PHASE=2 INIT=<phase-1 dit> STEP0=30000 for phase 2.
 
6
  set -e; source "$(dirname "$0")/common.sh"; OUT=$1
 
 
7
  if [ "${PHASE:-1}" = 1 ]; then
8
- launch fsdp.yaml wizard.train.bidirectional --data $D/windows --out $OUT --max_steps 30000 --save_every 1000 --num_workers 6 \
9
- $MIX --p_memunk 0.5 --mem_loss_w 3 --mem_index mem_index_both.pt --extra_rows $ROWS --p_trueunk 0.3
10
- else
11
- launch fsdp.yaml wizard.train.bidirectional --data $D/windows --out $OUT --init $INIT --step0 ${STEP0:-30000} --max_steps 35000 --save_every 1000 --num_workers 6 \
12
- $MIX --p_memunk 0 --mem_loss_w 3 --mem_index mem_index_both.pt --extra_rows $ROWS --p_trueunk 0 --p_unk2 0.5
13
  fi
 
1
  #!/bin/bash
2
+ # Stage 1: bidirectional teacher, from the official Wan2.2-TI2V-5B weights (released as weights/bidirectional/dit_step35000).
3
+ # bash scripts/train/1_bidirectional.sh <out dir> both phases; PHASE=1 or PHASE=2 runs one of them
4
+ # Batch 8 (ours: 4 GPUs x --grad_accum 2), lr 1e-5 / condition layers 1e-4, seed 0, the same data mixing from step 0.
5
+ # Phase 1 (0 -> 3000) without the world-edit clips; phase 2 (3000 -> 35000) restarts from the 3000 checkpoint with WEDIT=1 and the
6
+ # world-edit rows added (the clips became available then; the warm-up restarts with the run).
7
  set -e; source "$(dirname "$0")/common.sh"; OUT=$1
8
+ ARGS="--data $D/windows --out $OUT --save_every 1000 --num_workers 6 --grad_accum $GRAD_ACCUM $MIX --mem_loss_w 3 --mem_index mem_index_both.pt \
9
+ --p_memunk 0 --p_trueunk 0 --p_unk2 0.5"
10
  if [ "${PHASE:-1}" = 1 ]; then
11
+ launch fsdp.yaml wizard.train.bidirectional $ARGS --max_steps 3000 --extra_rows $ROWS
12
+ fi
13
+ if [ -z "$PHASE" ] || [ "$PHASE" = 2 ]; then
14
+ WEDIT=1 launch fsdp.yaml wizard.train.bidirectional $ARGS --init $OUT/dits/dit_step3000.safetensors --step0 3000 --max_steps 35000 \
15
+ --extra_rows $ROWS,$WEDIT_ROWS
16
  fi
code/scripts/train/2_causal.sh CHANGED
@@ -1,6 +1,14 @@
1
  #!/bin/bash
2
- # Stage 2: causal teacher forcing from the bidirectional teacher (history window 20 + sink 1).
3
- # bash scripts/train/2_causal.sh <bidirectional dit> <out dir> [max steps]
 
 
 
 
 
4
  set -e; source "$(dirname "$0")/common.sh"
5
- launch fsdp.yaml wizard.train.causal --data $D/windows --out $2 --init $1 --step0 0 --max_steps ${3:-3000} --save_every 500 --num_workers 6 --window 20 --sink 1 \
6
- $MIX --p_memunk 0 --mem_loss_w 3 --mem_index mem_index.pt --extra_rows $ROWS --p_trueunk 0 --p_unk2 0.5 --log_every 5
 
 
 
 
1
  #!/bin/bash
2
+ # Stage 2: causal teacher, teacher forcing with history self-augmentation, from the bidirectional teacher (released as weights/causal_teacher/dit_step11000).
3
+ # bash scripts/train/2_causal.sh <bidirectional dit_step35000> <out dir> [max steps]
4
+ # History window 20 + sink 1; batch 8 (ours: 8 GPUs, from 4000 on 4 GPUs x --grad_accum 2); lr 1e-5 (condition layers 1e-5); seed 0.
5
+ # Self-augmentation SA_P 0.5, sigma <= 0.25 on the revisit groups; memory loss weight 3 on cells no clean history frame the noisy frame
6
+ # reads has seen (MEMW_HISTW / MEMW_SINK); SceneFly memory from before and after the window (MEM_FUTURE=1); the world-edit clips (WEDIT=1).
7
+ # Ours ran to 11000, resumed from its own checkpoints (at 4000; the run was planned for 10000 and extended): to continue,
8
+ # INIT=<out>/dits/dit_step<N>.safetensors STEP0=<N> bash scripts/train/2_causal.sh ... (seed = N, as ours)
9
  set -e; source "$(dirname "$0")/common.sh"
10
+ export WEDIT=1 MEMW_HISTW=20 MEMW_SINK=1 MEM_FUTURE=1 SA_P=${SA_P:-0.5} SA_MAX=${SA_MAX:-0.25} SA_GROUPS=${SA_GROUPS:-lookback,lookback0,sfly,sfly_replay}
11
+ STEP0=${STEP0:-0}
12
+ launch fsdp.yaml wizard.train.causal_selfaug --data $D/windows --out $2 --init ${INIT:-$1} --step0 $STEP0 --seed $STEP0 --max_steps ${3:-11000} \
13
+ --save_every 500 --num_workers 6 --window 20 --sink 1 $MIX,lookback:4,lookback0:1 --p_memunk 0 --mem_loss_w 3 --mem_index mem_index_both.pt \
14
+ --extra_rows $ROWS,$LOOKBACK_ROWS,$WEDIT_ROWS --p_trueunk 0 --p_unk2 0.5 --log_every 5 --grad_accum $GRAD_ACCUM
code/scripts/train/3_causal_selfaug.sh DELETED
@@ -1,9 +0,0 @@
1
- #!/bin/bash
2
- # Stage 2b: causal teacher forcing with history self-augmentation, adding the look-back (revisit) data.
3
- # bash scripts/train/3_causal_selfaug.sh <causal dit> <step0> <out dir> [max steps]
4
- # Ours: from the stage-2 checkpoint at 3000, to 3500 with SA_P=0.7 SA_MAX=0.5 SA_GROUPS=all, then to 11000 with the defaults below.
5
- set -e; source "$(dirname "$0")/common.sh"
6
- export MEMW_HISTW=20 MEMW_SINK=1 MEM_FUTURE=1 SA_P=${SA_P:-0.5} SA_MAX=${SA_MAX:-0.25} SA_GROUPS=${SA_GROUPS:-lookback,lookback0,sfly,sfly_replay}
7
- launch fsdp.yaml wizard.train.causal_selfaug --data $D/windows --out $3 --init $1 --step0 $2 --max_steps ${4:-11000} --seed 5 --save_every 500 --num_workers 6 \
8
- --window 20 --sink 1 $MIX,lookback:4,lookback0:1 --p_memunk 0 --mem_loss_w 3 --mem_index mem_index.pt \
9
- --extra_rows $ROWS,$D/synth_lookback_geo/rows_full.jsonl --p_trueunk 0 --p_unk2 0.5 --log_every 5 --grad_accum ${GRAD_ACCUM:-1}
 
 
 
 
 
 
 
 
 
 
code/scripts/train/3_consistency.sh ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Stage 3: consistency distillation into a 2-step causal student (teacher reads the clean history, student / EMA the self-augmented one).
3
+ # bash scripts/train/3_consistency.sh <causal teacher dit_step11000> <out dir> [max steps]
4
+ # Teacher CFG 3, N 48, lr 2e-6, EMA 0.99 from step 200, window 20 + sink 1, 8 GPUs x 1 window; memory candidates past + future as the
5
+ # teacher was trained (wizard.distill.consistency_selfaug_future), the world-edit clips (WEDIT=1); SA_P 0.7, sigma <= 0.5 on the revisit groups.
6
+ # Ours: 0 -> 2700 (seed 0; only the EMA was saved), then warm-started from ema_step2000 to 10000:
7
+ # STUDENT_INIT=<out>/ema/ema_step2000.safetensors STEP0=2000 SEED=1 bash scripts/train/3_consistency.sh <teacher> <out2>
8
+ # (student and EMA both start from that EMA, the teacher stays the causal teacher, the warm-up restarts).
9
+ set -e; source "$(dirname "$0")/common.sh"
10
+ export WEDIT=1 SA_P=${SA_P:-0.7} SA_MAX=${SA_MAX:-0.5} SA_GROUPS=${SA_GROUPS:-lookback,lookback0,sfly,sfly_replay}
11
+ WARM=""; [ -n "$STUDENT_INIT" ] && WARM="--student_init $STUDENT_INIT --step0 ${STEP0:-0}"
12
+ launch fsdp_dmd.yaml wizard.distill.consistency_selfaug_future --data $D/windows --ckpt $1 --out $2 --max_steps ${3:-10000} --save_every 1000 \
13
+ --cfg 3 --window 20 --sink 1 --seed ${SEED:-0} $MIX,lookback:4,lookback0:1 --mem_index mem_index_both.pt --extra_rows $ROWS,$LOOKBACK_ROWS,$WEDIT_ROWS \
14
+ --p_trueunk 0 --p_unk2 0.5 $WARM
code/scripts/train/4_consistency.sh DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- # Stage 3: consistency distillation into a 2-step causal student (teacher reads the clean history, student / EMA the self-augmented one).
3
- # bash scripts/train/4_consistency.sh <causal teacher dit> <out dir> [max steps]
4
- set -e; source "$(dirname "$0")/common.sh"
5
- export SA_P=${SA_P:-0.7} SA_MAX=${SA_MAX:-0.5} SA_GROUPS=${SA_GROUPS:-lookback,lookback0,sfly,sfly_replay}
6
- launch fsdp_dmd.yaml wizard.distill.consistency_selfaug --data $D/windows --ckpt $1 --out $2 --max_steps ${3:-10000} --save_every 500 --cfg 3 --window 20 --sink 1 \
7
- $MIX,lookback:4,lookback0:1 --mem_index mem_index.pt --extra_rows $ROWS,$D/synth_lookback_geo/rows_full.jsonl --p_trueunk 0 --p_unk2 0.5
 
 
 
 
 
 
 
 
code/scripts/train/4_dmd.sh ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Stage 4: DMD of the 2-step student; real score and the fake score's start = the bidirectional teacher (CFG 3). Batch = 8 GPUs x accum 4 = 32,
3
+ # lr 2e-6 / critic 4e-7, 5 critic updates per student update, levels 1000,500. Memory candidates past only, no world-edit clips (no WEDIT),
4
+ # heavier mixing of the entry / revisit groups and the roaming bank (mem_index.pt).
5
+ # bash scripts/train/4_dmd.sh <consistency ema_step10000> <bidirectional dit_step35000> <out dir> [max steps]
6
+ # Ours: 500 steps, saving every 100 (an EMA, student_last and fake_last each time). To continue a run:
7
+ # EXTRA="--fake <out>/fake_last.safetensors --step0 <N>" bash scripts/train/4_dmd.sh <out>/ema/ema_step<N>.safetensors ...
8
+ set -e; source "$(dirname "$0")/common.sh"
9
+ launch fsdp_dmd.yaml wizard.distill.dmd --data $D/windows --student $1 --real $2 --out $3 --accum 4 --max_steps ${4:-500} --save_every 100 --cfg 3 \
10
+ --levels 1000,500 --num_workers 4 \
11
+ --group_rep e1o:8,e2o:8,e1n:8,e2n:8,e1x:8,turn:16,roam:4,sfly:8,sfly_replay:12,lookback:8,lookback0:2,ww:2,er:2,ue:2,bk:2 --rep_mem 16 \
12
+ --rep_keys $D/roam_memory/rep_keys_both30.json --mem_index mem_index.pt --extra_rows $ROWS,$LOOKBACK_ROWS --p_trueunk 0 --p_unk2 0.5 $EXTRA
code/scripts/train/5_dmd.sh DELETED
@@ -1,9 +0,0 @@
1
- #!/bin/bash
2
- # Stage 4: DMD of the 2-step student; real / fake score = the bidirectional teacher (CFG 3). Batch = NGPU x accum 4.
3
- # bash scripts/train/5_dmd.sh <consistency EMA> <bidirectional dit> <out dir> [max steps]
4
- # To continue a run: STUDENT=<out>/ema/ema_step<N>.safetensors and EXTRA="--fake <out>/fake_last.safetensors --step0 <N>".
5
- set -e; source "$(dirname "$0")/common.sh"
6
- launch fsdp_dmd.yaml wizard.distill.dmd --data $D/windows --student $1 --real $2 --out $3 --accum 4 --max_steps ${4:-400} --save_every 15 --cfg 3 \
7
- --levels 1000,500 --num_workers 4 \
8
- --group_rep e1o:8,e2o:8,e1n:8,e2n:8,e1x:8,turn:16,roam:4,sfly:8,sfly_replay:12,lookback:8,lookback0:2,ww:2,er:2,ue:2,bk:2 --rep_mem 16 \
9
- --rep_keys $D/roam_memory/rep_keys_both30.json --mem_index mem_index.pt --extra_rows $ROWS,$D/synth_lookback_geo/rows_full.jsonl --p_trueunk 0 --p_unk2 0.5 $EXTRA
 
 
 
 
 
 
 
 
 
 
code/scripts/train/common.sh CHANGED
@@ -2,10 +2,14 @@
2
  export WAN_CKPT=${WAN_CKPT:-checkpoints/Wan2.2-TI2V-5B}
3
  export WIZARD_DATA=${WIZARD_DATA:-data}
4
  export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
5
- export UNK_NOCOORD=1 MEMW_COVER=1 # unknown (dark-green) cells carry no coordinates; memory loss weight only on uncovered cells
6
  NGPU=${NGPU:-8}
7
  D=$WIZARD_DATA
8
- # --group_rep last: scripts 3 and 4 append ",lookback:4,lookback0:1" to it
 
 
9
  MIX="--rep_mem 8 --rep_keys $D/roam_memory/rep_keys_both30.json --group_rep e1o:2,e2o:2,e1n:2,e2n:2,e1x:2,turn:2,roam:2,sfly:4,sfly_replay:6"
10
  ROWS="$D/scenefly/rows.jsonl,$D/scenefly_replay/rows.jsonl"
 
 
11
  launch() { accelerate launch --config_file configs/accelerate/$1 --num_processes $NGPU --main_process_port ${PORT:-29500} -m "${@:2}"; }
 
2
  export WAN_CKPT=${WAN_CKPT:-checkpoints/Wan2.2-TI2V-5B}
3
  export WIZARD_DATA=${WIZARD_DATA:-data}
4
  export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
5
+ export UNK_NOCOORD=1 MEMW_COVER=1 # every stage: unknown (dark-green) cells carry no coordinates; "seen" for the memory loss weight by projected coverage
6
  NGPU=${NGPU:-8}
7
  D=$WIZARD_DATA
8
+ # every stage has an effective batch of 8 windows per optimizer step (DMD: 32): GRAD_ACCUM defaults to 8 / NGPU
9
+ GRAD_ACCUM=${GRAD_ACCUM:-$((8 / NGPU))}
10
+ # --group_rep last: stages 2 and 3 append ",lookback:4,lookback0:1" to it
11
  MIX="--rep_mem 8 --rep_keys $D/roam_memory/rep_keys_both30.json --group_rep e1o:2,e2o:2,e1n:2,e2n:2,e1x:2,turn:2,roam:2,sfly:4,sfly_replay:6"
12
  ROWS="$D/scenefly/rows.jsonl,$D/scenefly_replay/rows.jsonl"
13
+ LOOKBACK_ROWS="$D/synth_lookback_geo/rows_full.jsonl"
14
+ WEDIT_ROWS="$D/worldedit/rows_train.jsonl" # read with WEDIT=1 (adds worldedit/mem_index.pt and its memory banks)
15
  launch() { accelerate launch --config_file configs/accelerate/$1 --num_processes $NGPU --main_process_port ${PORT:-29500} -m "${@:2}"; }
code/wizard/distill/consistency.py CHANGED
@@ -64,6 +64,7 @@ def main():
64
  ap.add_argument("--group_rep", default="e1o:2,e2o:2,e1n:2,e2n:2,e1x:2,turn:2,roam:2"); ap.add_argument("--rep_mem", type=int, default=0); ap.add_argument("--rep_keys", default="")
65
  ap.add_argument("--extra_rows", default=""); ap.add_argument("--mem_index", default="mem_index.pt"); ap.add_argument("--p_trueunk", type=float, default=0.0); ap.add_argument("--p_unk2", type=float, default=0.0)
66
  ap.add_argument("--limit", type=int, default=0)
 
67
  a = ap.parse_args()
68
  a.mem_warp = a.mem_wrope = a.no_coords = a.empty_actor = a.skeleton_depth_cond = a.coords_only = False
69
  a.p_memunk = 0.0; a.mem_loss_w = 1.0; a.p_text_drop = 0.0; a.p_memnoise = 0.0; a.memnoise = 0.0; a.p_ident = 0.0
@@ -74,7 +75,7 @@ def main():
74
  log = (lambda *x: (print(*x, flush=True), open(os.path.join(a.out, "train.log"), "a").write(" ".join(map(str, x)) + "\n"))) if main_ else (lambda *x: None)
75
  models = []
76
  for _ in range(3):
77
- m = A.build_model(a); info = m.load_state_dict(st.load_file(a.ckpt), strict=False)
78
  bad = [k for k in info.missing_keys if "rope" not in k]; assert not bad and not info.unexpected_keys, (bad[:5], info.unexpected_keys[:5]); models.append(m)
79
  cores = list(models); student, ema, teacher = models; student.use_gradient_checkpointing = True; ema.use_gradient_checkpointing = False; teacher.use_gradient_checkpointing = False
80
  rows = [json.loads(l) for l in open(os.path.join(a.data, "rows.jsonl"))]
@@ -86,6 +87,7 @@ def main():
86
  train = [r for r in rows for _ in range(nrep(r))]
87
  c = collections.Counter(r["group"] for r in train)
88
  log(f"CD (teacher cfg {a.cfg}, all window {a.window}+{a.sink}) <- {a.ckpt}; world {accel.num_processes}; N {a.N} lr {a.lr}")
 
89
  log(f"rows {len(rows)} -> {len(train)}:", {k: f"{v} ({100 * v / len(train):.1f}%)" for k, v in sorted(c.items())})
90
  ds = A.ARData(a.data, train, a); log(f"SceneFly memory picks kept past-only: {ds.past_info[1]} of {ds.past_info[0]}")
91
  if main_: json.dump(vars(a), open(os.path.join(a.out, "args.json"), "w"), indent=1)
@@ -98,7 +100,7 @@ def main():
98
  student, ema, teacher, opt, dl, sch = accel.prepare(student, ema, teacher, opt, dl, sch)
99
  sched = FlowMatchScheduler(shift=5.0).to(accel.device); sigmas, tsteps = cd_axis(sched, a.N, accel.device)
100
  idx_rng = torch.Generator(device="cpu").manual_seed(1234 + a.seed) # same consistency level on every rank
101
- step, t0, it = 0, time.time(), iter(dl); student.train()
102
  while step < a.max_steps:
103
  try: b = next(it)
104
  except StopIteration: it = iter(dl); b = next(it)
 
64
  ap.add_argument("--group_rep", default="e1o:2,e2o:2,e1n:2,e2n:2,e1x:2,turn:2,roam:2"); ap.add_argument("--rep_mem", type=int, default=0); ap.add_argument("--rep_keys", default="")
65
  ap.add_argument("--extra_rows", default=""); ap.add_argument("--mem_index", default="mem_index.pt"); ap.add_argument("--p_trueunk", type=float, default=0.0); ap.add_argument("--p_unk2", type=float, default=0.0)
66
  ap.add_argument("--limit", type=int, default=0)
67
+ ap.add_argument("--student_init", default="", help="warm start: student + EMA from this checkpoint, the teacher stays --ckpt"); ap.add_argument("--step0", type=int, default=0, help="step counter starts here (save names continue the old run)")
68
  a = ap.parse_args()
69
  a.mem_warp = a.mem_wrope = a.no_coords = a.empty_actor = a.skeleton_depth_cond = a.coords_only = False
70
  a.p_memunk = 0.0; a.mem_loss_w = 1.0; a.p_text_drop = 0.0; a.p_memnoise = 0.0; a.memnoise = 0.0; a.p_ident = 0.0
 
75
  log = (lambda *x: (print(*x, flush=True), open(os.path.join(a.out, "train.log"), "a").write(" ".join(map(str, x)) + "\n"))) if main_ else (lambda *x: None)
76
  models = []
77
  for _ in range(3):
78
+ m = A.build_model(a); info = m.load_state_dict(st.load_file(a.student_init if (a.student_init and len(models) < 2) else a.ckpt), strict=False) # models = [student, ema, teacher]
79
  bad = [k for k in info.missing_keys if "rope" not in k]; assert not bad and not info.unexpected_keys, (bad[:5], info.unexpected_keys[:5]); models.append(m)
80
  cores = list(models); student, ema, teacher = models; student.use_gradient_checkpointing = True; ema.use_gradient_checkpointing = False; teacher.use_gradient_checkpointing = False
81
  rows = [json.loads(l) for l in open(os.path.join(a.data, "rows.jsonl"))]
 
87
  train = [r for r in rows for _ in range(nrep(r))]
88
  c = collections.Counter(r["group"] for r in train)
89
  log(f"CD (teacher cfg {a.cfg}, all window {a.window}+{a.sink}) <- {a.ckpt}; world {accel.num_processes}; N {a.N} lr {a.lr}")
90
+ if a.student_init: log(f"warm start: student + EMA <- {a.student_init}, step counter from {a.step0}")
91
  log(f"rows {len(rows)} -> {len(train)}:", {k: f"{v} ({100 * v / len(train):.1f}%)" for k, v in sorted(c.items())})
92
  ds = A.ARData(a.data, train, a); log(f"SceneFly memory picks kept past-only: {ds.past_info[1]} of {ds.past_info[0]}")
93
  if main_: json.dump(vars(a), open(os.path.join(a.out, "args.json"), "w"), indent=1)
 
100
  student, ema, teacher, opt, dl, sch = accel.prepare(student, ema, teacher, opt, dl, sch)
101
  sched = FlowMatchScheduler(shift=5.0).to(accel.device); sigmas, tsteps = cd_axis(sched, a.N, accel.device)
102
  idx_rng = torch.Generator(device="cpu").manual_seed(1234 + a.seed) # same consistency level on every rank
103
+ step, t0, it = a.step0, time.time(), iter(dl); student.train()
104
  while step < a.max_steps:
105
  try: b = next(it)
106
  except StopIteration: it = iter(dl); b = next(it)
code/wizard/distill/consistency_selfaug.py CHANGED
@@ -1,4 +1,4 @@
1
- """Stage 3 (used): consistency distillation with history self-augmentation.
2
 
3
  As `wizard.distill.consistency`, but with probability SA_P the history read by the student and the EMA is replaced by the teacher's
4
  one-step x0 estimate of a noised copy, while the teacher keeps reading the clean ground-truth history: the student must match the
 
1
+ """Stage 3: consistency distillation with history self-augmentation (the released run enters through `wizard.distill.consistency_selfaug_future`).
2
 
3
  As `wizard.distill.consistency`, but with probability SA_P the history read by the student and the EMA is replaced by the teacher's
4
  one-step x0 estimate of a noised copy, while the teacher keeps reading the clean ground-truth history: the student must match the
code/wizard/distill/consistency_selfaug_future.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Stage 3 entry point of the released chain: `wizard.distill.consistency_selfaug` with PAST + FUTURE memory candidates, as the
2
+ causal teacher was trained (`wizard.train.causal_selfaug` with MEM_FUTURE=1): SceneFly forward windows keep memory picks >= 3 s before
3
+ the window or >= 3 s after its end. `wizard.distill.consistency` alone (and `wizard.distill.dmd`) use `wizard.train.causal.ARData`
4
+ = past only. Inference is unchanged (past memory only). Also a free-disk guard for the periodic EMA saves (CD_FREE_GB, default 15):
5
+ an intermediate save is skipped rather than crash, the last one waits for space.
6
+ arguments and environment exactly as wizard.distill.consistency_selfaug"""
7
+ import os, json
8
+ import wizard.train.causal as A
9
+ class ARDataFuture(A.ClipDataset):
10
+ def __init__(self, root, rows, a):
11
+ A.ClipDataset.__init__(self, root, rows, a)
12
+ info = json.load(open(f"{A.SFLY}/index.json")) if os.path.exists(f"{A.SFLY}/index.json") else {}
13
+ sf = A.lt(f"{A.SFLY}/mem_index.pt") if os.path.exists(f"{A.SFLY}/mem_index.pt") else {}
14
+ n0 = n1 = 0
15
+ for name in sf:
16
+ if name not in info or name not in self.mem_index: continue
17
+ f0 = int(info[name]["f0"]); e = dict(self.mem_index[name])
18
+ ch = [[(f, g) for f, g in c if f <= f0 - A.GAP_F or f >= f0 + 121 + A.GAP_F] for c in e["chunks"]]
19
+ n0 += sum(len(c) for c in e["chunks"]); n1 += sum(len(c) for c in ch); e["chunks"] = ch; self.mem_index[name] = e
20
+ self.past_info = (n0, n1); print(f"MEM_FUTURE SceneFly picks kept (>= 3 s before or after the window): {n1} of {n0}", flush=True)
21
+ A.ARData = ARDataFuture
22
+ import wizard.distill.consistency_selfaug # installs its cd_loss into wizard.distill.consistency
23
+ import wizard.distill.consistency as CD
24
+ import sys, time, shutil
25
+ _save = CD.st.save_file; FREE_GB = float(os.environ.get("CD_FREE_GB", 15))
26
+ def _guarded_save(sd, path, *x, **k):
27
+ """the disk is shared and often full: skip an intermediate EMA save rather than crash; the last one waits for space"""
28
+ last = "--max_steps" in sys.argv and f"ema_step{sys.argv[sys.argv.index('--max_steps') + 1]}." in os.path.basename(path)
29
+ while shutil.disk_usage(os.path.dirname(path)).free < FREE_GB * 2 ** 30:
30
+ print(f"LOW_DISK {shutil.disk_usage(os.path.dirname(path)).free / 2 ** 30:.1f} GB free: {'waiting to save' if last else 'SKIPPED'} {os.path.basename(path)}", flush=True)
31
+ if not last: return
32
+ time.sleep(60)
33
+ return _save(sd, path, *x, **k)
34
+ CD.st.save_file = _guarded_save
35
+ if __name__ == "__main__": CD.main()
code/wizard/train/bidirectional.py CHANGED
@@ -5,7 +5,10 @@ channels, world-coordinate tokens on background cells, retrieved memory frames a
5
  dataset (`ClipDataset`), `collate` and the data-root constants used by the later stages.
6
 
7
  accelerate launch --config_file configs/accelerate/fsdp.yaml --num_processes 8 -m wizard.train.bidirectional \
8
- --data $WIZARD_DATA/windows --out runs/bidir [data / mixing arguments]"""
 
 
 
9
  import os, sys, time, argparse, json, random, collections, math
10
  import numpy as np
11
  import torch, torch.nn.functional as F
@@ -80,6 +83,8 @@ class ClipDataset(torch.utils.data.Dataset):
80
  for root in (SFLY, SFLY + "_replay", SFLY + "_replay_test"): # replay windows read the same videos' banks (in scenefly)
81
  if os.path.exists(f"{root}/mem_index.pt"):
82
  si = lt(f"{root}/mem_index.pt"); self.mem_index.update(si); self.mroot.update({v["seg"]: SFLY for v in si.values()})
 
 
83
  self.with_prev = [i for i, r in enumerate(rows) if r["prev"]]
84
 
85
  def __len__(self): return len(self.rows)
@@ -119,7 +124,7 @@ class ClipDataset(torch.utils.data.Dataset):
119
 
120
  def __getitem__(self, i):
121
  r = self.rows[i]; a = self.a
122
- if r["group"] in ("roam", "sfly", "sfly_replay"): return self.roam(r) # SceneFly = roam layout, no characters
123
  c = lt(f"{DS}/samples/clips/clip_{r['key']}.pt"); g = lt(f"{self.O}/geometry/clip_{r['key']}.pt"); pv = lt(f"{PROXY}/clip_{r['key']}.pt"); act = pv["cond"] if not os.environ.get("SKELETON_DEPTH_COND") else c["cond"]
124
  u2 = f"{PROXY}_unk2/clip_{r['key']}.pt"
125
  if getattr(a, "p_unk2", 0.0) > 0 and os.path.exists(u2) and random.random() < a.p_unk2: pv = lt(u2); act = pv["cond"] # unk2_build.py
 
5
  dataset (`ClipDataset`), `collate` and the data-root constants used by the later stages.
6
 
7
  accelerate launch --config_file configs/accelerate/fsdp.yaml --num_processes 8 -m wizard.train.bidirectional \
8
+ --data $WIZARD_DATA/windows --out runs/bidir [data / mixing arguments]
9
+
10
+ Environment: UNK_NOCOORD=1 (unknown cells carry no coordinate token), MEMW_COVER / MEMW_HISTW / MEMW_SINK (which cells get the memory
11
+ loss weight), WEDIT=1 (add the world-edit windows of worldedit/: their memory index and banks; rows via --extra_rows)."""
12
  import os, sys, time, argparse, json, random, collections, math
13
  import numpy as np
14
  import torch, torch.nn.functional as F
 
83
  for root in (SFLY, SFLY + "_replay", SFLY + "_replay_test"): # replay windows read the same videos' banks (in scenefly)
84
  if os.path.exists(f"{root}/mem_index.pt"):
85
  si = lt(f"{root}/mem_index.pt"); self.mem_index.update(si); self.mroot.update({v["seg"]: SFLY for v in si.values()})
86
+ if os.environ.get("WEDIT") == "1" and os.path.exists(f"{DS}/worldedit/mem_index.pt"): # WEDIT=1: the world-edit windows (group wedit), memroam layout under their own root, own banks
87
+ si = lt(f"{DS}/worldedit/mem_index.pt"); self.mem_index.update(si); self.mroot.update({v["seg"]: f"{DS}/worldedit" for v in si.values()})
88
  self.with_prev = [i for i, r in enumerate(rows) if r["prev"]]
89
 
90
  def __len__(self): return len(self.rows)
 
124
 
125
  def __getitem__(self, i):
126
  r = self.rows[i]; a = self.a
127
+ if r["group"] in ("roam", "sfly", "sfly_replay", "wedit"): return self.roam(r) # SceneFly / world edit = roam layout, no characters
128
  c = lt(f"{DS}/samples/clips/clip_{r['key']}.pt"); g = lt(f"{self.O}/geometry/clip_{r['key']}.pt"); pv = lt(f"{PROXY}/clip_{r['key']}.pt"); act = pv["cond"] if not os.environ.get("SKELETON_DEPTH_COND") else c["cond"]
129
  u2 = f"{PROXY}_unk2/clip_{r['key']}.pt"
130
  if getattr(a, "p_unk2", 0.0) > 0 and os.path.exists(u2) and random.random() < a.p_unk2: pv = lt(u2); act = pv["cond"] # unk2_build.py
code/wizard/train/causal_selfaug.py CHANGED
@@ -1,4 +1,4 @@
1
- """Stage 2b: causal teacher forcing with history self-augmentation.
2
 
3
  Under teacher forcing the clean history already contains almost everything, so the model never learns that memory should correct a
4
  drifting history. With probability SA_P (the same decision on every rank) the clean history is replaced by the model's own one-step
 
1
+ """Stage 2 (used, scripts/train/2_causal.sh): causal teacher forcing with history self-augmentation.
2
 
3
  Under teacher forcing the clean history already contains almost everything, so the model never learns that memory should correct a
4
  drifting history. With probability SA_P (the same decision on every rank) the clean history is replaced by the model's own one-step