code/: mirror of wizard27-clean f853184 (scripts as trained)
Browse filesFiles changed (16)
- code/README.md+5-6
- code/docs/DATA.md+2
- code/docs/TRAINING.md+19-18
- code/scripts/train/1_bidirectional.sh+12-9
- code/scripts/train/2_causal.sh+12-4
- code/scripts/train/3_causal_selfaug.shDeleted-9
- code/scripts/train/3_consistency.shAdded+14
- code/scripts/train/4_consistency.shDeleted-7
- code/scripts/train/4_dmd.shAdded+12
- code/scripts/train/5_dmd.shDeleted-9
- code/scripts/train/common.sh+6-2
- code/wizard/distill/consistency.py+4-2
- code/wizard/distill/consistency_selfaug.py+1-1
- code/wizard/distill/consistency_selfaug_future.pyAdded+35
- code/wizard/train/bidirectional.py+7-2
- code/wizard/train/causal_selfaug.py+1-1
89 unmodified lines909192939495969798993 unmodified lines10310410510610710810911089 unmodified lines| Stage | Module | Script ||---|---|---|| 1. Bidirectional teacher | `wizard.train.bidirectional` | `scripts/train/1_bidirectional.sh` || 2. Causal teacher forcing | `wizard.train.causal` | `scripts/train/2_causal.sh` || 2b. History self-augmentation | `wizard.train.causal_selfaug` | `scripts/train/3_causal_selfaug.sh` || 3. Consistency distillation | `wizard.distill.consistency_selfaug` | `scripts/train/4_consistency.sh` || 4. Distribution matching distillation | `wizard.distill.dmd` | `scripts/train/5_dmd.sh` |Commands, hyper-parameters and the data layout: [docs/TRAINING.md](docs/TRAINING.md) and [docs/DATA.md](docs/DATA.md).3 unmodified lines| File | Model | Sampling ||---|---|---|| `causal_dmd/ema_step480.safetensors` | real-time 2-step student (stage 4, DMD) | `causal` / `world`, 2 steps || `causal_cd/ema_step10000.safetensors` | consistency-distilled student (stage 3), the starting point of DMD | `causal` / `world`, 2 steps || `causal_teacher/dit_step11000.safetensors` | causal teacher (stage 2) | teacher of stage 3 || `bidirectional_main/dit_step35000.safetensors` | bidirectional teacher (stage 1), the model of the paper's main table | `bidirectional`, 30 steps, CFG 3 || `bidirectional/dit_step35000.safetensors` | bidirectional teacher trained with the world-edit clips as well | `bidirectional`, 30 steps, CFG 3 |89 unmodified lines9091929394959697983 unmodified lines10210310410510610710810989 unmodified lines| Stage | Module | Script ||---|---|---|| 1. Bidirectional teacher | `wizard.train.bidirectional` | `scripts/train/1_bidirectional.sh` || 2. Causal teacher (teacher forcing + history self-augmentation) | `wizard.train.causal_selfaug` | `scripts/train/2_causal.sh` || 3. Consistency distillation | `wizard.distill.consistency_selfaug_future` | `scripts/train/3_consistency.sh` || 4. Distribution matching distillation | `wizard.distill.dmd` | `scripts/train/4_dmd.sh` |Commands, hyper-parameters and the data layout: [docs/TRAINING.md](docs/TRAINING.md) and [docs/DATA.md](docs/DATA.md).3 unmodified lines| File | Model | Sampling ||---|---|---|| `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 || `causal_cd/ema_step10000.safetensors` | consistency-distilled student (stage 3) of that earlier run, the starting point of its DMD | `causal` / `world`, 2 steps || `causal_teacher/dit_step11000.safetensors` | causal teacher (stage 2) | teacher of stage 3 || `bidirectional_main/dit_step35000.safetensors` | bidirectional teacher (stage 1), the model of the paper's main table | `bidirectional`, 30 steps, CFG 3 || `bidirectional/dit_step35000.safetensors` | bidirectional teacher trained with the world-edit clips as well | `bidirectional`, 30 steps, CFG 3 |
13 unmodified lines1415161718195 unmodified lines25262728293013 unmodified linesscenefly/ revisit sequences (SceneFly), rows.jsonlscenefly_replay/ revisit sequences replayed backwards, rows.jsonlsynth_lookback_geo/ synthetic look-back sequences (camera turns away and back), rows_full.jsonl```Each row belongs to a **group**, used for the mixing weights (`--group_rep group:weight,...`):5 unmodified lines| `roam` | roaming recordings || `sfly`, `sfly_replay`, `lookback`, `lookback0` | revisits: the camera comes back to a place it has seen || `ww`, `er`, `ue`, `bk` | duels |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 with13 unmodified lines141516171819205 unmodified lines2627282930313213 unmodified linesscenefly/ revisit sequences (SceneFly), rows.jsonlscenefly_replay/ revisit sequences replayed backwards, rows.jsonlsynth_lookback_geo/ synthetic look-back sequences (camera turns away and back), rows_full.jsonlworldedit/ world-edit clips (objects / terrain changing in front of the camera), rows_train.jsonl, mem_index.pt, bank/ (read with WEDIT=1)```Each row belongs to a **group**, used for the mixing weights (`--group_rep group:weight,...`):5 unmodified lines| `roam` | roaming recordings || `sfly`, `sfly_replay`, `lookback`, `lookback0` | revisits: the camera comes back to a place it has seen || `ww`, `er`, `ue`, `bk` | duels || `wedit` | world edits (stages 1 from 3k, 2 and 3) |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
7 unmodified lines89101112131415161718192021222324252627282930313233343 unmodified lines383940414243441 unmodified line4647484950517 unmodified lines## Pipeline```bashbash scripts/train/1_bidirectional.sh runs/bidir # 0 -> 30kPHASE=2 INIT=runs/bidir/dits/dit_step30000.safetensors STEP0=30000 \bash scripts/train/1_bidirectional.sh runs/bidir # 30k -> 35kbash scripts/train/2_causal.sh runs/bidir/dits/dit_step35000.safetensors runs/causalSA_P=0.7 SA_MAX=0.5 SA_GROUPS=all \bash scripts/train/3_causal_selfaug.sh runs/causal/dits/dit_step3000.safetensors 3000 runs/causal_sa 3500bash scripts/train/3_causal_selfaug.sh runs/causal_sa/dits/dit_step3500.safetensors 3500 runs/causal_sa2 11000bash scripts/train/4_consistency.sh runs/causal_sa2/dits/dit_step11000.safetensors runs/cdbash scripts/train/5_dmd.sh runs/cd/ema/ema_step10000.safetensors runs/bidir/dits/dit_step35000.safetensors runs/dmd```## Stages| Stage | Steps | Batch | LR | Notes ||---|---|---|---|---|| 1. Bidirectional | 30k + 5k | 8 | 1e-5 (condition layers 1e-4) | phase 2: unknown cells carry no coordinates, `p_unk2 0.5` || 2. Causal teacher forcing | 3k | 8 | 1e-5 | history window 20 + sink 1; memory from the past only || 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 || 3. Consistency distillation | 10k | 8 | 2e-6, EMA 0.99 | N = 48 levels, 2 sampling steps (1000, 500), teacher CFG 3 || 4. DMD | 400+ | 32 (8 × accum 4) | 2e-6 / critic 4e-7 | critic : student = 5 : 1, real score CFG 3 |Hyper-parameters not set in the scripts keep the defaults of each module's argument parser.3 unmodified linesstage 3 the teacher keeps the clean history and only the student / EMA read the augmented one.**Resuming DMD.** Every save also writes `student_last.safetensors` and `fake_last.safetensors`:`EXTRA="--fake runs/dmd/fake_last.safetensors --step0 <N>" bash scripts/train/5_dmd.sh runs/dmd/ema/ema_step<N>.safetensors ...`## Training-time switches (environment)1 unmodified line|---|---|---|| `UNK_NOCOORD=1` | all | unknown cells carry no world coordinates || `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 || `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 || `MEM_FUTURE=1` | 2b | SceneFly windows may also retrieve frames after the window || `SA_P`, `SA_MAX`, `SA_GROUPS` | 2b, 3 | history self-augmentation |7 unmodified lines89101112131415161718192021222324252627282930313233343 unmodified lines383940414243441 unmodified line464748495051527 unmodified lines## PipelineThe scripts reproduce the run that produced the released `bidirectional`, `causal_teacher` checkpoints and the current distillation chain:```bashbash scripts/train/1_bidirectional.sh runs/bidir # 0 -> 3k, then + world-edit clips 3k -> 35kbash scripts/train/2_causal.sh runs/bidir/dits/dit_step35000.safetensors runs/causal # 0 -> 11kbash scripts/train/3_consistency.sh runs/causal/dits/dit_step11000.safetensors runs/cd # 0 -> 10kbash scripts/train/4_dmd.sh runs/cd/ema/ema_step10000.safetensors runs/bidir/dits/dit_step35000.safetensors runs/dmd # 500```Our runs were interrupted and resumed (the scripts' comments say how): stage 1 phase 2 restarted from the 3k checkpointwhen the world-edit clips were added; stage 2 was resumed from its own checkpoints (seed = resume step); stage 3 ran 0 -> 2.7kand was then warm-started from its 2k EMA (`STUDENT_INIT`, `STEP0=2000`, `SEED=1`) to 10k.## Stages| Stage | Steps | Batch | LR | Notes ||---|---|---|---|---|| 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 || 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 || 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 || 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 |Hyper-parameters not set in the scripts keep the defaults of each module's argument parser.3 unmodified linesstage 3 the teacher keeps the clean history and only the student / EMA read the augmented one.**Resuming DMD.** Every save also writes `student_last.safetensors` and `fake_last.safetensors`:`EXTRA="--fake runs/dmd/fake_last.safetensors --step0 <N>" bash scripts/train/4_dmd.sh runs/dmd/ema/ema_step<N>.safetensors ...`## Training-time switches (environment)1 unmodified line|---|---|---|| `UNK_NOCOORD=1` | all | unknown cells carry no world coordinates || `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 || `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` || `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 || `MEM_FUTURE=1` | 2 | SceneFly windows may also retrieve frames after the window (stage 3 does the same through `wizard.distill.consistency_selfaug_future`) || `SA_P`, `SA_MAX`, `SA_GROUPS` | 2, 3 | history self-augmentation |
12345678910111213#!/bin/bash# Stage 1: bidirectional teacher, from the official Wan2.2-TI2V-5B weights.# bash scripts/train/1_bidirectional.sh <out dir># Our teacher was trained in two phases on 8 GPUs: phase 1 (0 -> 30k steps, p_trueunk 0.3, p_memunk 0.5) and# 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.set -e; source "$(dirname "$0")/common.sh"; OUT=$1if [ "${PHASE:-1}" = 1 ]; thenlaunch fsdp.yaml wizard.train.bidirectional --data $D/windows --out $OUT --max_steps 30000 --save_every 1000 --num_workers 6 \$MIX --p_memunk 0.5 --mem_loss_w 3 --mem_index mem_index_both.pt --extra_rows $ROWS --p_trueunk 0.3elselaunch fsdp.yaml wizard.train.bidirectional --data $D/windows --out $OUT --init $INIT --step0 ${STEP0:-30000} --max_steps 35000 --save_every 1000 --num_workers 6 \$MIX --p_memunk 0 --mem_loss_w 3 --mem_index mem_index_both.pt --extra_rows $ROWS --p_trueunk 0 --p_unk2 0.5fi12345678910111213141516#!/bin/bash# Stage 1: bidirectional teacher, from the official Wan2.2-TI2V-5B weights (released as weights/bidirectional/dit_step35000).# bash scripts/train/1_bidirectional.sh <out dir> both phases; PHASE=1 or PHASE=2 runs one of them# 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.# Phase 1 (0 -> 3000) without the world-edit clips; phase 2 (3000 -> 35000) restarts from the 3000 checkpoint with WEDIT=1 and the# world-edit rows added (the clips became available then; the warm-up restarts with the run).set -e; source "$(dirname "$0")/common.sh"; OUT=$1ARGS="--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 \--p_memunk 0 --p_trueunk 0 --p_unk2 0.5"if [ "${PHASE:-1}" = 1 ]; thenlaunch fsdp.yaml wizard.train.bidirectional $ARGS --max_steps 3000 --extra_rows $ROWSfiif [ -z "$PHASE" ] || [ "$PHASE" = 2 ]; thenWEDIT=1 launch fsdp.yaml wizard.train.bidirectional $ARGS --init $OUT/dits/dit_step3000.safetensors --step0 3000 --max_steps 35000 \--extra_rows $ROWS,$WEDIT_ROWSfi
123456#!/bin/bash# Stage 2: causal teacher forcing from the bidirectional teacher (history window 20 + sink 1).# bash scripts/train/2_causal.sh <bidirectional dit> <out dir> [max steps]set -e; source "$(dirname "$0")/common.sh"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 \$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 51234567891011121314#!/bin/bash# Stage 2: causal teacher, teacher forcing with history self-augmentation, from the bidirectional teacher (released as weights/causal_teacher/dit_step11000).# bash scripts/train/2_causal.sh <bidirectional dit_step35000> <out dir> [max steps]# 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.# 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# reads has seen (MEMW_HISTW / MEMW_SINK); SceneFly memory from before and after the window (MEM_FUTURE=1); the world-edit clips (WEDIT=1).# Ours ran to 11000, resumed from its own checkpoints (at 4000; the run was planned for 10000 and extended): to continue,# INIT=<out>/dits/dit_step<N>.safetensors STEP0=<N> bash scripts/train/2_causal.sh ... (seed = N, as ours)set -e; source "$(dirname "$0")/common.sh"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}STEP0=${STEP0:-0}launch fsdp.yaml wizard.train.causal_selfaug --data $D/windows --out $2 --init ${INIT:-$1} --step0 $STEP0 --seed $STEP0 --max_steps ${3:-11000} \--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 \--extra_rows $ROWS,$LOOKBACK_ROWS,$WEDIT_ROWS --p_trueunk 0 --p_unk2 0.5 --log_every 5 --grad_accum $GRAD_ACCUM
123456789#!/bin/bash# Stage 2b: causal teacher forcing with history self-augmentation, adding the look-back (revisit) data.# bash scripts/train/3_causal_selfaug.sh <causal dit> <step0> <out dir> [max steps]# 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.set -e; source "$(dirname "$0")/common.sh"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}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 \ --window 20 --sink 1 $MIX,lookback:4,lookback0:1 --p_memunk 0 --mem_loss_w 3 --mem_index mem_index.pt \ --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}1234567891011121314#!/bin/bash# Stage 3: consistency distillation into a 2-step causal student (teacher reads the clean history, student / EMA the self-augmented one).# bash scripts/train/3_consistency.sh <causal teacher dit_step11000> <out dir> [max steps]# 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# 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.# Ours: 0 -> 2700 (seed 0; only the EMA was saved), then warm-started from ema_step2000 to 10000:# STUDENT_INIT=<out>/ema/ema_step2000.safetensors STEP0=2000 SEED=1 bash scripts/train/3_consistency.sh <teacher> <out2># (student and EMA both start from that EMA, the teacher stays the causal teacher, the warm-up restarts).set -e; source "$(dirname "$0")/common.sh"export WEDIT=1 SA_P=${SA_P:-0.7} SA_MAX=${SA_MAX:-0.5} SA_GROUPS=${SA_GROUPS:-lookback,lookback0,sfly,sfly_replay}WARM=""; [ -n "$STUDENT_INIT" ] && WARM="--student_init $STUDENT_INIT --step0 ${STEP0:-0}"launch fsdp_dmd.yaml wizard.distill.consistency_selfaug_future --data $D/windows --ckpt $1 --out $2 --max_steps ${3:-10000} --save_every 1000 \ --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 \ --p_trueunk 0 --p_unk2 0.5 $WARM1234567#!/bin/bash# Stage 3: consistency distillation into a 2-step causal student (teacher reads the clean history, student / EMA the self-augmented one).# bash scripts/train/4_consistency.sh <causal teacher dit> <out dir> [max steps]set -e; source "$(dirname "$0")/common.sh"export SA_P=${SA_P:-0.7} SA_MAX=${SA_MAX:-0.5} SA_GROUPS=${SA_GROUPS:-lookback,lookback0,sfly,sfly_replay}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 \ $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.5123456789101112#!/bin/bash# 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,# 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),# heavier mixing of the entry / revisit groups and the roaming bank (mem_index.pt).# bash scripts/train/4_dmd.sh <consistency ema_step10000> <bidirectional dit_step35000> <out dir> [max steps]# Ours: 500 steps, saving every 100 (an EMA, student_last and fake_last each time). To continue a run:# EXTRA="--fake <out>/fake_last.safetensors --step0 <N>" bash scripts/train/4_dmd.sh <out>/ema/ema_step<N>.safetensors ...set -e; source "$(dirname "$0")/common.sh"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 \ --levels 1000,500 --num_workers 4 \ --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 \ --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 $EXTRA123456789#!/bin/bash# Stage 4: DMD of the 2-step student; real / fake score = the bidirectional teacher (CFG 3). Batch = NGPU x accum 4.# bash scripts/train/5_dmd.sh <consistency EMA> <bidirectional dit> <out dir> [max steps]# To continue a run: STUDENT=<out>/ema/ema_step<N>.safetensors and EXTRA="--fake <out>/fake_last.safetensors --step0 <N>".set -e; source "$(dirname "$0")/common.sh"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 \ --levels 1000,500 --num_workers 4 \ --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 \ --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 $EXTRA1 unmodified line2345678910111 unmodified lineexport WAN_CKPT=${WAN_CKPT:-checkpoints/Wan2.2-TI2V-5B}export WIZARD_DATA=${WIZARD_DATA:-data}export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:Trueexport UNK_NOCOORD=1 MEMW_COVER=1 # unknown (dark-green) cells carry no coordinates; memory loss weight only on uncovered cellsNGPU=${NGPU:-8}D=$WIZARD_DATA# --group_rep last: scripts 3 and 4 append ",lookback:4,lookback0:1" to itMIX="--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"ROWS="$D/scenefly/rows.jsonl,$D/scenefly_replay/rows.jsonl"launch() { accelerate launch --config_file configs/accelerate/$1 --num_processes $NGPU --main_process_port ${PORT:-29500} -m "${@:2}"; }1 unmodified line234567891011121314151 unmodified lineexport WAN_CKPT=${WAN_CKPT:-checkpoints/Wan2.2-TI2V-5B}export WIZARD_DATA=${WIZARD_DATA:-data}export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:Trueexport UNK_NOCOORD=1 MEMW_COVER=1 # every stage: unknown (dark-green) cells carry no coordinates; "seen" for the memory loss weight by projected coverageNGPU=${NGPU:-8}D=$WIZARD_DATA# every stage has an effective batch of 8 windows per optimizer step (DMD: 32): GRAD_ACCUM defaults to 8 / NGPUGRAD_ACCUM=${GRAD_ACCUM:-$((8 / NGPU))}# --group_rep last: stages 2 and 3 append ",lookback:4,lookback0:1" to itMIX="--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"ROWS="$D/scenefly/rows.jsonl,$D/scenefly_replay/rows.jsonl"LOOKBACK_ROWS="$D/synth_lookback_geo/rows_full.jsonl"WEDIT_ROWS="$D/worldedit/rows_train.jsonl" # read with WEDIT=1 (adds worldedit/mem_index.pt and its memory banks)launch() { accelerate launch --config_file configs/accelerate/$1 --num_processes $NGPU --main_process_port ${PORT:-29500} -m "${@:2}"; }
63 unmodified lines6465666768694 unmodified lines747576777879805 unmodified lines8687888990916 unmodified lines989910010110210310463 unmodified linesap.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="")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)ap.add_argument("--limit", type=int, default=0)a = ap.parse_args()a.mem_warp = a.mem_wrope = a.no_coords = a.empty_actor = a.skeleton_depth_cond = a.coords_only = Falsea.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.04 unmodified lineslog = (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)models = []for _ in range(3):m = A.build_model(a); info = m.load_state_dict(st.load_file(a.ckpt), strict=False)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)cores = list(models); student, ema, teacher = models; student.use_gradient_checkpointing = True; ema.use_gradient_checkpointing = False; teacher.use_gradient_checkpointing = Falserows = [json.loads(l) for l in open(os.path.join(a.data, "rows.jsonl"))]5 unmodified linestrain = [r for r in rows for _ in range(nrep(r))]c = collections.Counter(r["group"] for r in train)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}")log(f"rows {len(rows)} -> {len(train)}:", {k: f"{v} ({100 * v / len(train):.1f}%)" for k, v in sorted(c.items())})ds = A.ARData(a.data, train, a); log(f"SceneFly memory picks kept past-only: {ds.past_info[1]} of {ds.past_info[0]}")if main_: json.dump(vars(a), open(os.path.join(a.out, "args.json"), "w"), indent=1)6 unmodified linesstudent, ema, teacher, opt, dl, sch = accel.prepare(student, ema, teacher, opt, dl, sch)sched = FlowMatchScheduler(shift=5.0).to(accel.device); sigmas, tsteps = cd_axis(sched, a.N, accel.device)idx_rng = torch.Generator(device="cpu").manual_seed(1234 + a.seed) # same consistency level on every rankstep, t0, it = 0, time.time(), iter(dl); student.train()while step < a.max_steps:try: b = next(it)except StopIteration: it = iter(dl); b = next(it)63 unmodified lines646566676869704 unmodified lines757677787980815 unmodified lines878889909192936 unmodified lines10010110210310410510663 unmodified linesap.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="")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)ap.add_argument("--limit", type=int, default=0)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)")a = ap.parse_args()a.mem_warp = a.mem_wrope = a.no_coords = a.empty_actor = a.skeleton_depth_cond = a.coords_only = Falsea.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.04 unmodified lineslog = (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)models = []for _ in range(3):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]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)cores = list(models); student, ema, teacher = models; student.use_gradient_checkpointing = True; ema.use_gradient_checkpointing = False; teacher.use_gradient_checkpointing = Falserows = [json.loads(l) for l in open(os.path.join(a.data, "rows.jsonl"))]5 unmodified linestrain = [r for r in rows for _ in range(nrep(r))]c = collections.Counter(r["group"] for r in train)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}")if a.student_init: log(f"warm start: student + EMA <- {a.student_init}, step counter from {a.step0}")log(f"rows {len(rows)} -> {len(train)}:", {k: f"{v} ({100 * v / len(train):.1f}%)" for k, v in sorted(c.items())})ds = A.ARData(a.data, train, a); log(f"SceneFly memory picks kept past-only: {ds.past_info[1]} of {ds.past_info[0]}")if main_: json.dump(vars(a), open(os.path.join(a.out, "args.json"), "w"), indent=1)6 unmodified linesstudent, ema, teacher, opt, dl, sch = accel.prepare(student, ema, teacher, opt, dl, sch)sched = FlowMatchScheduler(shift=5.0).to(accel.device); sigmas, tsteps = cd_axis(sched, a.N, accel.device)idx_rng = torch.Generator(device="cpu").manual_seed(1234 + a.seed) # same consistency level on every rankstep, t0, it = a.step0, time.time(), iter(dl); student.train()while step < a.max_steps:try: b = next(it)except StopIteration: it = iter(dl); b = next(it)
1234"""Stage 3 (used): consistency distillation with history self-augmentation.As `wizard.distill.consistency`, but with probability SA_P the history read by the student and the EMA is replaced by the teacher'sone-step x0 estimate of a noised copy, while the teacher keeps reading the clean ground-truth history: the student must match the1234"""Stage 3: consistency distillation with history self-augmentation (the released run enters through `wizard.distill.consistency_selfaug_future`).As `wizard.distill.consistency`, but with probability SA_P the history read by the student and the EMA is replaced by the teacher'sone-step x0 estimate of a noised copy, while the teacher keeps reading the clean ground-truth history: the student must match the
1234567891011121314151617181920212223242526272829303132333435"""Stage 3 entry point of the released chain: `wizard.distill.consistency_selfaug` with PAST + FUTURE memory candidates, as thecausal teacher was trained (`wizard.train.causal_selfaug` with MEM_FUTURE=1): SceneFly forward windows keep memory picks >= 3 s beforethe window or >= 3 s after its end. `wizard.distill.consistency` alone (and `wizard.distill.dmd`) use `wizard.train.causal.ARData`= past only. Inference is unchanged (past memory only). Also a free-disk guard for the periodic EMA saves (CD_FREE_GB, default 15):an intermediate save is skipped rather than crash, the last one waits for space. arguments and environment exactly as wizard.distill.consistency_selfaug"""import os, jsonimport wizard.train.causal as Aclass ARDataFuture(A.ClipDataset): def __init__(self, root, rows, a): A.ClipDataset.__init__(self, root, rows, a) info = json.load(open(f"{A.SFLY}/index.json")) if os.path.exists(f"{A.SFLY}/index.json") else {} sf = A.lt(f"{A.SFLY}/mem_index.pt") if os.path.exists(f"{A.SFLY}/mem_index.pt") else {} n0 = n1 = 0 for name in sf: if name not in info or name not in self.mem_index: continue f0 = int(info[name]["f0"]); e = dict(self.mem_index[name]) 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"]] 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 self.past_info = (n0, n1); print(f"MEM_FUTURE SceneFly picks kept (>= 3 s before or after the window): {n1} of {n0}", flush=True)A.ARData = ARDataFutureimport wizard.distill.consistency_selfaug # installs its cd_loss into wizard.distill.consistencyimport wizard.distill.consistency as CDimport sys, time, shutil_save = CD.st.save_file; FREE_GB = float(os.environ.get("CD_FREE_GB", 15))def _guarded_save(sd, path, *x, **k): """the disk is shared and often full: skip an intermediate EMA save rather than crash; the last one waits for space""" last = "--max_steps" in sys.argv and f"ema_step{sys.argv[sys.argv.index('--max_steps') + 1]}." in os.path.basename(path) while shutil.disk_usage(os.path.dirname(path)).free < FREE_GB * 2 ** 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) if not last: return time.sleep(60) return _save(sd, path, *x, **k)CD.st.save_file = _guarded_saveif __name__ == "__main__": CD.main()4 unmodified lines56789101168 unmodified lines80818283848533 unmodified lines1191201211221231241254 unmodified linesdataset (`ClipDataset`), `collate` and the data-root constants used by the later stages.accelerate launch --config_file configs/accelerate/fsdp.yaml --num_processes 8 -m wizard.train.bidirectional \--data $WIZARD_DATA/windows --out runs/bidir [data / mixing arguments]"""import os, sys, time, argparse, json, random, collections, mathimport numpy as npimport torch, torch.nn.functional as F68 unmodified linesfor root in (SFLY, SFLY + "_replay", SFLY + "_replay_test"): # replay windows read the same videos' banks (in scenefly)if os.path.exists(f"{root}/mem_index.pt"):si = lt(f"{root}/mem_index.pt"); self.mem_index.update(si); self.mroot.update({v["seg"]: SFLY for v in si.values()})self.with_prev = [i for i, r in enumerate(rows) if r["prev"]]def __len__(self): return len(self.rows)33 unmodified linesdef __getitem__(self, i):r = self.rows[i]; a = self.aif r["group"] in ("roam", "sfly", "sfly_replay"): return self.roam(r) # SceneFly = roam layout, no charactersc = 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"]u2 = f"{PROXY}_unk2/clip_{r['key']}.pt"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.py4 unmodified lines56789101112131468 unmodified lines838485868788899033 unmodified lines1241251261271281291304 unmodified linesdataset (`ClipDataset`), `collate` and the data-root constants used by the later stages.accelerate launch --config_file configs/accelerate/fsdp.yaml --num_processes 8 -m wizard.train.bidirectional \--data $WIZARD_DATA/windows --out runs/bidir [data / mixing arguments]Environment: UNK_NOCOORD=1 (unknown cells carry no coordinate token), MEMW_COVER / MEMW_HISTW / MEMW_SINK (which cells get the memoryloss weight), WEDIT=1 (add the world-edit windows of worldedit/: their memory index and banks; rows via --extra_rows)."""import os, sys, time, argparse, json, random, collections, mathimport numpy as npimport torch, torch.nn.functional as F68 unmodified linesfor root in (SFLY, SFLY + "_replay", SFLY + "_replay_test"): # replay windows read the same videos' banks (in scenefly)if os.path.exists(f"{root}/mem_index.pt"):si = lt(f"{root}/mem_index.pt"); self.mem_index.update(si); self.mroot.update({v["seg"]: SFLY for v in si.values()})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 bankssi = 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()})self.with_prev = [i for i, r in enumerate(rows) if r["prev"]]def __len__(self): return len(self.rows)33 unmodified linesdef __getitem__(self, i):r = self.rows[i]; a = self.aif r["group"] in ("roam", "sfly", "sfly_replay", "wedit"): return self.roam(r) # SceneFly / world edit = roam layout, no charactersc = 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"]u2 = f"{PROXY}_unk2/clip_{r['key']}.pt"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
1234"""Stage 2b: causal teacher forcing with history self-augmentation.Under teacher forcing the clean history already contains almost everything, so the model never learns that memory should correct adrifting history. With probability SA_P (the same decision on every rank) the clean history is replaced by the model's own one-step1234"""Stage 2 (used, scripts/train/2_causal.sh): causal teacher forcing with history self-augmentation.Under teacher forcing the clean history already contains almost everything, so the model never learns that memory should correct adrifting history. With probability SA_P (the same decision on every rank) the clean history is replaced by the model's own one-step
code/README.md+5-6
code/docs/DATA.md+2
code/docs/TRAINING.md+19-18
code/scripts/train/1_bidirectional.sh+12-9
code/scripts/train/2_causal.sh+12-4
code/scripts/train/3_causal_selfaug.shDeleted-9
code/scripts/train/3_consistency.shAdded+14
code/scripts/train/4_consistency.shDeleted-7
code/scripts/train/4_dmd.shAdded+12
code/scripts/train/5_dmd.shDeleted-9
code/scripts/train/common.sh+6-2
code/wizard/distill/consistency.py+4-2
code/wizard/distill/consistency_selfaug.py+1-1
code/wizard/distill/consistency_selfaug_future.pyAdded+35
code/wizard/train/bidirectional.py+7-2
code/wizard/train/causal_selfaug.py+1-1