|
Download docs/impl/distill.md from teawhite/maliang: direct link, hf CLI and curl.
- Browser
- Download file 30.7 kB
-
https://huggingface.co/teawhite/maliang/resolve/main/docs/impl/distill.md
- Command line
-
hf download hf://teawhite/maliang/docs/impl/distill.md
-
curl -L -o distill.md https://huggingface.co/teawhite/maliang/resolve/main/docs/impl/distill.md
30.7 kB
| # distill β CF++ 3-stage distillation of the gc25d DiT (SPEC Β§8) | |
| Status 2026-10-22: code done; CPU tests green, plus the real-weights gate and the 2-GPU FSDP numerics gate run on GPU; all three | |
| stages, the deploy-twin evaluation and the `live.py` deploy contract smoke-tested on real 5B weights and the real mini dataset | |
| (GPUs 6,7). A review/fix pass followed (see **Review fixes** below): stage-3 numerics now equal deploy, the streamed replay is | |
| exact, the rollout no longer runs on one-step-stale FSDP root parameters, stage-3 resume fast-forwards the LR, and eval_rollout | |
| picks clips by run and can chain clips into 60 s rollouts. | |
| **No full run has been started.** The 8-GPU commands are at the end of this file. **The deploy contract still needs a lead | |
| decision** (Open issue 1): a tested patch is ready. | |
| Upstream = `ref/arope_git/ActionRoPE/distill/` (vendored, unchanged, in `code/arope/distill/`). Design and line refs: | |
| `docs/understand/distill_port.md` Β§8βΒ§9. | |
| ## What | |
| | file (`code/gc25d/gcdistill/`) | role | upstream it forks | | |
| |---|---|---| | |
| | `ar_tf_gc.py` | stage1, teacher-forcing causalization (DeepSpeed ZeRO-2) | `stage1_ar/ar_tf.py` | | |
| | `cd_gc.py` | stage2, causal consistency distillation on the deploy axis, fp32 EMA target (ZeRO-2) | `stage2_cd/cd_arope.py` | | |
| | `dmd_gc.py` | stage3, self-forcing DMD: student / critic / teacher / EMA (FSDP1) | `stage3_dmd/dmd_arope.py` | | |
| | `data_gc.py` | `GcRolloutDataset` (stage3), the frankenstein / contiguous tail slicing, lazy `dataset.GcLatentDataset`, synthetic data, tiny `GcDiT` | `distill/data.py` (the gc subset) | | |
| | `eval_rollout.py` | deploy twin of `codeworld/live.py`: rollout β mp4 (GT \| gen \| cond) + PSNR / ZNCC / brightness-drift json; refuses `/dits/`. One clip (β€ 28 cells) or **chained** consecutive val clips (`--chain_cells 241` = 60 s). Clips/chains are picked **round-robin over val runs** (looks alternate); `summary.json` has per-run and per-subset means | `eval/rollout_eval.py` (role only) | | |
| | `common_gc.sh`, `run_stage{1,2,3}.sh`, `config_stage{1,2,3}.json` | launchers. Each recipe is held in three places (run.sh defaults == argparse == config json) | `common.sh`, `stage*/run.sh`, `stage*/config.json` | | |
| | `gc_dit.py` (**additions only**) | `WAN22_5B_DIT` + `empty_wan_dit()`: a skeleton DiT that loads no base weights, then gets a strict 831-key load. Nothing that existed changed (the `ids` path is untouched). | `codeworld/live.py::empty_wan_dit` | | |
| | tests (`code/gc25d/tests/`) | what | | |
| |---|---| | |
| | `test_gcdit.py` (20) | GcDiT bidirectional β‘ `gc_forward` **bitwise** (ids/parts Γ fp32/bf16); streaming KV β‘ parallel block-causal (float64, β€1e-9), sliding without eviction β‘ absolute **bitwise**, sink/window eviction matches before it happens and diverges after; TF leak: clean fβnoisy f = **0.0**, future = **0.0**, history > 0; condition causality (parallel / TF / streaming, sem term is cell-local); slicing (cell / window / frankenstein frames at N=21..27, K=20); `GcRolloutDataset` on a fake full-size layout; skeleton config == DiffSynth hash `1f5ab770β¦`; real-weights bitparity (gated: `GC_BITPARITY_REAL=1`) | | |
| | `test_stage1.py` (8) | loss wiring (sem β `mask_input` by identity, clean_x = x0, cell 0 = x0 at t=0, never in the loss; analytic oracle β loss exactly 0); no-TF fallback; `tf_clean_stream`; dry run end to end + metadata accepted / rejected by the stage2 gate; `cond_lr` group; defaults; **data contract** of real `GcLatentDataset` vs synthetic vs `GcRolloutDataset` (first 21 cells bitwise equal) | | |
| | `test_stage2.py` (10) | ports of upstream 1β8: CD axis == deploy points; oracle β cd_loss β‘ 0 on every pair (+ negative control); grads only to student (including `gc_sem_cond`); the three forwards share one cond object; cell 0 pinned; `_keep_frame0`; metadata gate; discrete axis warns; **EMA shadow fp32** (bf16 cast refused, 0.99 update math, hard copy); dry run with dits/+ema/ and resume | | |
| | `test_stage3.py` (33: 32 CPU, test_18 needs the mini data; + test_16 GPU-gated) | ports of upstream 1β7: commit at t=0 exactly once per cell (rollout and replay); `first_frame_cond=False` and each cell gets **its own** sem frames, no `offset_win`; grad window == scored tail minus anchor at K=H=20, N=21..27 for **both** tail modes; `score_tail` latent/text/ids/sem alignment; one grad forward per grad cell; eval_idx never has cell 0, critic β‘ teacher β DMD exactly 0; native-scoring gate; **streamed β‘ fused** (rel. 1e-6, both tails, `gc_sem_cond` gets grads); deploy geometry sink 3/w17/cap 20 rollout N=22 with live.py's exact kwargs; argparse guards; dry run; `eval_rollout.deploy_rollout` is the live loop (commits, 4 deploy t per cell, seed reproducibility, `/dits/` refused); metrics json. **Added in the fix pass:** test_13 rollout β‘ deploy loop in (latent dtype, t) under an accelerate-style fp32-output wrapper: bf16 and 1000/752/500/252, fused and streamed, with a negative control (no `_as_latent` β fp32 750.0); test_14 target = rollout output β replay loss, `replay_dev` and student grads exactly 0, and the record pass runs exactly one grad-mode forward per grad cell; test_15 resume fast-forwards lr_g and lr_c (equal to an uninterrupted run); test_16 (`GC_GPU_FSDP=1`, 2 GPUs) real accelerate FSDP with the 2-GPU yaml and `_fsdp_gate`: rollout (dtype, t) == deploy, critic β‘ teacher β dmd_gnorm 0, replay loss / replay_dev / student gnorm exactly 0 (worker: `tests/fsdp_t_parity_worker.py`); test_17 run-stratified selection, chain validity (episode change, missing ext, too short), NaN-masked GT metrics; test_18 `load_chain` on the mini data: the first 28 cells equal `GcRolloutDataset`, clip 1 lands at frame 96 | | |
| | `test_distill_config.py` (7) | three-place recipe equality for each stage (30 / 33 / 36 constants; every config json scalar that is an argparse dest is compared); argparse defaults == SPEC Β§8; launchers default to 8 GPUs, assert eff batch, require absolute OUT; smoke yamls exist | | |
| `scripts/distill_smoke/` (smoke helpers, not imported by training): | |
| * `export_base_gc.py`: base Wan + zero-init `gc_sem_cond` (parts) exported as an 831-key gc ckpt. Also checks the skeleton build against the | |
| pipeline build: state dict, attributes, and a 2-cell forward, all bitwise equal. | |
| * `live_path_check.py`: the deploy-contract check (below). Default: the unchanged `ref/` live.py with `vocab` injected. | |
| `--no_inject --live_py <patched package>/code/gc25d/codeworld/live.py`: no injection, no pre-import, so live.py uses its own | |
| package's `model.py` / `gc_dit.py` (the patch under decision). | |
| * `deploy_vocab/live_vocab.patch` + `deploy_vocab/make_patched_deploy.sh <DST>`: the proposed deploy patch (Open issue 1). The | |
| script copies `ref/gc25d-live-demo/code/gc25d` to `<DST>` and never touches `ref/`. | |
| * `replay_exact_check.py`: real weights, single GPU or `--fsdp` under accelerate: rollout(record) β streamed replay with target = | |
| rollout output, per exit step and clip. Every probe must give replay loss = replay_dev = student gnorm = 0. | |
| `configs/accelerate_zero2_2gpu_ga1.yaml` and `configs/accelerate_fsdp_dmd_2gpu.yaml` are 2-GPU smoke variants of the 8-GPU yamls, with only | |
| `num_processes` changed. | |
| ## How (what changed vs upstream, and why) | |
| * **Condition.** The model is `GcDiT` everywhere: AropeDiT with `mask_channel=False` plus `gc_sem_cond`. Semantic ids (uint8) go through | |
| `mask_input` (parallel paths and both TF halves) or `mask_in_k` (streaming). `offset_px` / `offset_win` are always `None`, so RoPE is the | |
| plain table. Slicing follows distill_port Β§3.1: | |
| * cell 0 = frame 0; | |
| * cell k = frames 4kβ3β¦4k; | |
| * frankenstein tail = `cat(frame 0, frames 4aβ3β¦4N)`, with T = 4(1+K)β3 = 81 for K=20, so teacher and critic see a regular 21-cell clip. | |
| The vocab is read from the ckpt (`ckpt_vocab`) at every stage. The data side collapses partsβids only if the model is `ids`. | |
| * **Loss (stage1).** Uniform per-cell MSE times the per-cell bsmntw bell weight. There is no ARoPE known/new weight map. Cell 0 stays clean | |
| at t=0 and is excluded from the loss. The ARoPE `action_dropout` is removed. anchor/hist/ctx context dropouts are kept (they do not depend | |
| on the condition) and default to 0. Text 0.1 / cond 0.05 / UNKNOWN-mask 0.5 dropouts come from `dataset.GcLatentDataset` (SFT, SPEC Β§7). | |
| Workers are non-persistent and `set_epoch` is called every epoch, because that dataset draws by (seed, epoch, index). | |
| * **Stage3 data.** `GcRolloutDataset` returns: | |
| * `z0 = latent[:, :1]`; | |
| * `sem_ids = cat(cond[81], cond_ext[28])` = 109 frames; | |
| * `context` / `context_ids` for 28 cells, from 21 clip prompts + 7 ext prompts. | |
| Only train rows with `has_ext` and without `drop` are used (mini: 84/100). Per step the batch is sliced to 1+N cells and 4N+1 frames, with | |
| N β [21, 27] drawn in sync across ranks. Upstream's `extend_offsets` / `extend_context("hold")` are dropped. Holding a moving semantic map | |
| would train "standing still" (distill_port Β§6.6). | |
| * **KV.** Recency only (`GcKVDriver`): sink 3 + window 17, rope cap 20. World-Canvas, revisit and offset machinery are deleted. | |
| * **Scored tail.** The default is `--tail_mode frankenstein` (the gc25d_v8 ckpt metadata); `contiguous` is kept for comparison. The grad | |
| window is identical in both modes (`grad_start_range` is verbatim upstream). | |
| * **Grad clip in stage1 is 10.0 in all three places.** Upstream argparse/config say 1.0; its run.sh and RUNBOOK say 10.0 is effective. | |
| * **Stage-3 numerics = deploy numerics (new; upstream does not have this).** Inside the model the timestep is cast to the | |
| **latent dtype** (`arope_dit._per_token_timestep_pf`). Deploy (`live.py`, unwrapped bf16 model) keeps `v`, `den` and the | |
| re-noised latent in bf16, so it runs at t = **1000 / 752 / 500 / 252** (bf16-rounded). SFT (`train.py:203`), stage 1 and | |
| stage 2 also see bf16 t. `accelerate.prepare` wraps the model's forward in `convert_outputs_to_fp32`, so in training `v` is fp32 | |
| (holding bf16 values). That makes `den` and the re-noised latent fp32, and the rollout ran at **fp32 t 750.0 / 500.6 / 251.6**. | |
| Two pieces fix it: | |
| * `_as_latent(v, noisy)` casts `v` back to the latent dtype (lossless) in the rollout, the streamed replay and the probe. The | |
| x0 estimate and re-noising are then the same bf16 arithmetic as `LiveGame.step_ids`, and the rollout output is bf16 | |
| (asserted, plus a step-0 `[dtype]` gate in `main`). | |
| * `_fsdp_gate` sets `cast_root_forward_inputs=False`, so the FSDP critic and the unwrapped teacher get identical inputs. The | |
| scored tail is bf16, so both see the same bf16 t (e.g. 974.9 β 976), which is also the t the SFT teacher was trained at. | |
| History: the first version only turned the root cast off. That fixed the teacher/critic mismatch (step-0 DMD +0.0092 β 0) but | |
| moved the student off the deploy t. Before that, FSDP's root cast had kept the student on the bf16 t, while the fp32 tail gave | |
| the teacher fp32 t and the critic bf16 t. Verified on real 2-GPU FSDP (`tests/fsdp_t_parity_worker.py`): training rollout | |
| (dtype, t) == `deploy_rollout` == [bf16 1000, 752, 500, 252, commit 0] for every cell. Pre-fix references are kept in | |
| `outputs/_smoke/distill/stage3_ref_bf16cast/` (root cast on) and `outputs/_smoke/distill/stage3/` (root cast off, fp32 rollout). | |
| * **Exact streamed replay (new).** On GPU, SDPA picks a different kernel in grad mode, so a no-grad rollout and the grad-mode | |
| replay differed by ~1 bf16 ulp. That put a spurious term into the surrogate, so gnorm_g had a ~1e-3 floor even at step 0. In the | |
| record pass the exit forward of each grad-window cell now also runs in grad mode, then is detached immediately. Both passes use | |
| the same kernel, and the fused path already worked this way. The replay compares every re-done `den` with the rollout's and logs | |
| `replay_dev` (CSV/jsonl/log line; a `[warn]` names the cells if it is ever > 0). With critic β‘ teacher, step 0 gives dmd = | |
| dmd_gnorm = **gnorm_g = 0 exactly**, so S3-GUARD-3 has no noise floor there. Cost: one transient grad graph per grad cell in | |
| the rollout, the same size as the replay's. | |
| * **Stale FSDP root parameters (new, found while verifying the replay fix; upstream `dmd_arope` has the same bug).** FSDP1 does | |
| not free the **root** unit's unsharded (bf16) parameters after a forward, because it expects a backward to follow | |
| (`_runtime_utils._post_forward_reshard`). Here the root is everything outside the `DiTBlock` units: patch / text / time | |
| embedding, time projection, head and `gc_sem_cond`. The replay ends with a no-grad commit forward, so the root stays unsharded | |
| across `opt_g.step()`. The next forward then sees `needs_unshard() == False` and skips the all-gather. The whole next rollout, | |
| and the first replayed grad cell, therefore ran on the root parameters from **before** the last optimizer step. Symptom: from | |
| step 2 on, replay_dev 0.06β0.17 (first replayed cell exact, ~40 % of elements in later cells off by 1β2 bf16 ulp). Fix: | |
| `_free_fsdp_root(model)` does the same `_reshard(free=True)` that FSDP runs after backward, before `opt_g.step()` (and | |
| defensively before `opt_c.step()`). It is a private FSDP1 API, guarded so it is a no-op when not FSDP or already freed. Verified: | |
| * real 5B, 2-GPU FSDP, 2 optimizer steps at lr 1e-5 (`replay_fsdp_optsteps_free{0,1}.json`): replay_dev 0.0625 and spurious | |
| gnorm 3.8e-3 without the fix; exactly 0 / 0 with it; | |
| * test_16 includes this as a negative and positive control (tiny model: 0.375 vs 0); | |
| * the final smoke has replay_dev 0 on all 5 steps. | |
| * **Stage-3 resume** fast-forwards both LR schedulers to `resume_step` (as stage 2 does; upstream `dmd_arope` restarts the | |
| 100-step warmup). It is still weights-only: generator and critic Adam moments restart (Ξ²1 = 0, so only `v` is lost). The step-0 | |
| "DMD is exactly 0" note is printed only on a fresh, non-dry run. | |
| * **`_budget_gate`** scales the sharded static memory with world size (upstream hard-coded 4 GPUs): 30.3 GiB at 8 GPUs, 93.2 GiB at 2. The | |
| 2-GPU prediction was 107.7 GiB; measured was 103.2 GB. | |
| * **Model build.** `--base_init skeleton` (the default) uses `empty_wan_dit()` and then a strict 831-key `load_gc_ckpt`, which saves a 19 GB | |
| fp32 read per model. It is bitwise identical to `--base_init wan`, checked on real weights. Stage3 loads 4 models per rank in 17β21 s. | |
| * **Launchers.** `DISTILL_NGPU` defaults to 8. `DISTILL_GPUS` selects physical cards (smoke: `6,7`). `CUDA_DEVICE_ORDER=PCI_BUS_ID`. The | |
| idle-GPU guard is fail-closed and can only be made stricter. OUT must be absolute under `/opt/dlami/nvme/`. Eff batch must be 8 (stage1/2: | |
| NGPU Γ GA; stage3: NGPU), and `EFF_BATCH_OVERRIDE=1` is needed for smoke. Ports are 29631 / 29632 / 29636. | |
| * **Metadata (via `gc_dit.save_gc`, GC_META + `vocab`, `data`).** | |
| * stage1: `teacher_forcing, windowed_train, windowed_sink, init_ckpt, tf_noise_aug_max_idx, *_dropout, mask_p`. stage2's metadata gate | |
| reads these and passes or fails on them (tested). | |
| * stage2: `cd_axis, denoise_list, ema_decay, student/teacher_ckpt, role`. | |
| * stage3: `denoise_list, kv_window, sink_size, rope_cap, dmd_score_frames, grad_horizon, tail_mode, rollout_min/max, student/teacher_ckpt, | |
| role, ema_decay`. | |
| * **Kept as upstream (inherited numerics).** In stages 1/2 the DeepSpeed bf16 engine turns autocast off inside the student forward, so it | |
| runs in pure bf16. The stage2 teacher and the EMA run under the outer autocast. Same as ActionRoPE; not changed. | |
| ## Smoke (2 Γ H200, GPUs 6,7, real 5B weights, `data/gc25d_v10_mini`) | |
| Init / "SFT" was the base Wan2.2-TI2V-5B plus a zero-init `gc_sem_cond` (parts), exported as an 831-key gc ckpt | |
| (`outputs/_smoke/distill/init/base_parts.safetensors`). No SFT smoke ckpt existed at the time. The chain was stage1 β stage2 β stage3, each | |
| consuming the previous product. Logs, `train.log`, `config.json` and ckpts are in `outputs/_smoke/distill/<stage>/`. | |
| | stage | config | s/step (steady) | first step | peak mem / GPU | other | | |
| |---|---|---|---|---|---| | |
| | 1 TF | ZeRO-2, 2 GPU GA1, 4 steps, val every 2 (4 val clips Γ 3 t) | **3.5β3.7** | 9.1 s | **56.5 GB** | gnorm 9β16 with the base init (clip 10 active); val 5β6 s; export 10.02 GB (831 BF16 keys); `save_state` slot 66 GB; load 4 s | | |
| | 2 CD | ZeRO-2, 2 GPU GA1, 4 steps, EMA_START=2 | **5.1** | 19.5 s | **85.0 GB** | step-0 cd 0.146 (β 0, as expected on the deploy axis); metadata gate passed; dits/+ema/ exported; axis hits [3,0,1] | | |
| | 3 DMD | FSDP1 2 GPU, Nβ21..22, K=H=20, frankenstein, PROFILE_MEM | **19β25** (rollout 4β15 s by exit step) | 64 s (with probe) | **103.2 GB** (gate predicted 107.7) | preflight OK (2 evictions); `use_orig_params=True`; probe gnorm 5.19; dits/critic/ema exported | | |
| | 3 DMD, **final code** (`stage3_final/`, via `run_stage3.sh`) | same, 5 steps, exits 1/0/3/0/1 | 99β127 β | 186 s β (with probe) | **103.0 GB** | `[fsdp]` root freed before opt_g; step 0: dmd = dmd_gnorm = **gnorm_g = 0 exactly**; **replay_dev = 0 on all 5 steps**; gnorm_g 2e-3β¦5e-3 > 0 from step 1 (S3 guard); lr_g 4e-8 β 1.2e-7 = 2e-6Β·(s+1)/100, lr_c half that; dits/critic/ema exported | | |
| | 3 DMD, intermediate (`stage3_fix/`, `distill_fix/stage3_exit3*`) | before the FSDP-root fix | β | β | 103.1 GB | step 0 exact, but **replay_dev 0.06β0.17 from step 2 on** (~40 % of elements, first replayed cell exact). This led to the stale-root finding (How β Exact streamed replay) | | |
| β Host load average was ~100 from other jobs during this run, and the prep job shared GPUs 6,7 during the intermediate runs. The step | |
| times are not representative; use the first smoke's 19β25 s/step. | |
| Memory profile, stage3 step 0 (GB): after rollout 46.8 β after DMD targets 46.8 β after streamed generator backward 57.5 β after opt_g 75.3 β | |
| after 5 critic steps 103.2. With 8 GPUs, FULL_SHARD divides the 186 GB of sharded state 4Γ further. Expect β 40 GB/GPU (upstream ARoPE: | |
| 38.7 GB, ~22 s/step). | |
| **Deploy twin / contract** (`outputs/_smoke/distill/{eval_rollout,live_path}/`; fix pass: `outputs/_smoke/distill_fix/`): | |
| * `eval_rollout.py`, stage3 smoke EMA, 25 cells (1 + 24, so cond_ext is used), 97 frames, Wan VAE. Runs end to end and writes `rollout.mp4` | |
| (GT \| deploy rollout \| cond, GT black past frame 80), `gen.mp4`, `metrics.json` (per-cell PSNR / ZNCC / luma) and `summary.json`. | |
| * DiT is 617β689 ms per cell (5 forwards; not the fast engine). | |
| * The numbers (PSNR 14.6, ZNCC 0.05, drift β53) are meaningless by construction: the student is an untrained base after 4+4+3 steps, and | |
| the frames collapse to texture after a few cells. | |
| * `scripts/distill_smoke/live_path_check.py` loads the same EMA through **`ref/gc25d-live-demo/code/gc25d/codeworld/live.py` itself**: | |
| `LiveGame(base=False, vae="tae")` β `GcDiT(causal)` + `load_gc_ckpt` (831 strict) β bf16 β TAEHV. It then streams 3 cells with | |
| `reset_ids` + `step_ids` (sink 3 / w17 / cap 20, 4-step renoise, commit at t=0). Results: | |
| * all 4 cell latents are **bitwise identical** to `eval_rollout.deploy_rollout` with the same seed; | |
| * DiT is ~700 ms per cell, TAEHV 5 ms per cell. | |
| The only injection was `vocab=ckpt_vocab(ckpt)`, which live.py does not pass (see Open issues). | |
| * Fix pass, `stage3_fix/ema/ema_step3`: | |
| * `live_path_check` on the unchanged `ref/` live.py with injection (`live_path_ref/`): bitwise equal, 4/4 cells. | |
| * `--no_inject` on the **patched deploy package** (`make_patched_deploy.sh`), with live.py importing its own package's | |
| `model.py` / `gc_dit.py` (`live_path_patched/`): bitwise equal, 4/4 cells. | |
| * The same patched package also loads the gc25d_v8 **ids** ckpt `ref/.../gc25d_v8_dmd_ema500` (`live_path_patched_v8ids/`): vocab | |
| detected as `ids`, bitwise equal to `deploy_rollout`. The patch is backward compatible. | |
| * Fix pass, `eval_rollout --chain_cells 241 --n_clips 2 --vae tae` (`eval_chain241_tae/`): one chain per val run on mini, | |
| R10_s1512 (v10_real) and P9_golden_s2909 (v9_stylized), 11 clips each, 961 frames, ~460 ms/cell DiT under GPU sharing. GT | |
| frames: 162 for v10_real (looks change after clip 1) and 811 for v9_stylized. Writes mp4s, `metrics.json` and `summary.json` | |
| with per_run / per_subset. The numbers (PSNR 15.3, |drift| 33) are again meaningless with the untrained smoke student. | |
| * Fix pass, real-weight replay exactness (`replay_exact_*.json`, `scripts/distill_smoke/replay_exact_check.py`), target = rollout | |
| output: replay loss = replay_dev = student gnorm = **0** for exits 0β3 at N=4 and N=22 on one GPU, for 6 more clips at exit 3, | |
| and under 2-GPU FSDP at N=22 for exits 0β3. | |
| * Fix pass, `GC_GPU_FSDP=1 pytest -k test_16` (`fsdp_t_parity.json`): training rollout (dtype, t) per cell = deploy = [bf16 1000, | |
| 752, 500, 252, commit 0]; dmd_gnorm 0; replay loss / replay_dev / student gnorm 0; after an optimizer step, replay_dev is 0.375 | |
| without `_free_fsdp_root` and 0 with it. | |
| * Final EMA (`stage3_final/ema/ema_step5`): | |
| * the patched deploy package with `--no_inject` is again bitwise equal to `deploy_rollout` (`live_path_patched_final/`); | |
| * `eval_rollout --cells 28 --n_clips 2 --vae wan` (`eval_clip28_wan/`) picks one clip per run (R10_s1512, P9_golden_s2909) | |
| and writes per-run summaries. | |
| Stage1 `--resume auto` was exercised in a follow-up run (`outputs/_smoke/distill/stage1/nohup_resume.log`): | |
| * `accelerator.load_state(state β state_A)` at step 4; | |
| * the LR scheduler fast-forwarded correctly (step 5 lr 2.5e-7 = 1e-5Β·5/200); | |
| * step 5 trained at 56.5 GB, exported `dit_step5`, and rotated to `state_B`. | |
| ## Run (8 GPUs, `DISTILL_NGPU=8` is the default) | |
| ```bash | |
| cd /opt/dlami/nvme/zhiyangdeng/maliang | |
| M=/opt/dlami/nvme/zhiyangdeng/maliang | |
| SFT=$M/outputs/gc25d_v10/step-20000.safetensors # the bidirectional SFT pick (SPEC Β§7); override with the chosen step | |
| # stage1 TF 8000 steps, ZeRO-2 8ΓGA1 = eff 8, lr 1e-5, clip 10, SFT dropouts β outputs/distill/gc25d_v10/stage1_tf/dits/dit_step8000 | |
| SFT=$SFT bash code/gc25d/gcdistill/run_stage1.sh | |
| # stage2 CD 5000 steps, deploy axis 1000/750/500/250, lr 2e-6 Ξ²(0,.999), EMA .99@200 β outputs/distill/gc25d_v10/stage2_cd/ema/ema_step5000 | |
| AR=$M/outputs/distill/gc25d_v10/stage1_tf/dits/dit_step8000.safetensors bash code/gc25d/gcdistill/run_stage2.sh | |
| # stage3 DMD 500 steps, FSDP 8 GPU, sink3/w17/cap20, frankenstein K=H=20, rollout 21..27, criticΓ5, EMA .99@100, save 50 | |
| STUDENT=$M/outputs/distill/gc25d_v10/stage2_cd/ema/ema_step5000.safetensors SFT=$SFT bash code/gc25d/gcdistill/run_stage3.sh | |
| # pick the deploy EMA by long rollouts, not by loss (one GPU per milestone). | |
| # (a) 60 s chains: 241 cells built from consecutive val clips of one run / episode / camera, one chain per val run (10 runs, | |
| # looks alternate). This measures long-horizon drift, the main AR failure mode and what the v8 reference used. | |
| # (b) short horizon with Wan VAE: 28 cells per clip (the longest single-clip condition, 7 cells past the first eviction), | |
| # one clip per val run. | |
| for s in 100 200 300 400 500; do | |
| E=$M/outputs/distill/gc25d_v10/stage3_dmd/ema/ema_step$s.safetensors | |
| ENV="DIFFSYNTH_SKIP_DOWNLOAD=True PYTHONPATH=$M/code/gc25d:$M/code/arope AROPE_ROOT=$M/code/arope \ | |
| HF_HOME=/opt/dlami/nvme/zhiyangdeng/.cache/huggingface TMPDIR=$M/.tmp OMP_NUM_THREADS=8" | |
| env CUDA_VISIBLE_DEVICES=0 $ENV $M/.venv/bin/python code/gc25d/gcdistill/eval_rollout.py --ckpt $E \ | |
| --chain_cells 241 --n_clips 10 --vae tae --out $M/outputs/distill/gc25d_v10/eval/stage3_ema$s/chain241 | |
| env CUDA_VISIBLE_DEVICES=0 $ENV $M/.venv/bin/python code/gc25d/gcdistill/eval_rollout.py --ckpt $E \ | |
| --cells 28 --n_clips 10 --vae wan --out $M/outputs/distill/gc25d_v10/eval/stage3_ema$s/clip28 | |
| done | |
| # summary.json: "mean", "per_subset" (v10_real / v9_stylized) and "per_run". In chain mode the GT metrics (psnr / zncc / | |
| # gt_luma_gap) use only clips with the same `look` as the chain head: v10_real changes look every clip, so there only the | |
| # first 81 frames count, while drift uses the whole chain. Chain numbers are not comparable with clip-mode numbers. | |
| ``` | |
| Each launcher resumes by default: stage1 from `state`, stages 2/3 from `progress.json` (weights only). `RESUME=none` starts fresh. | |
| `FORCE_RUN_DIR=1` overrides the "train.log touched < 10 min ago" guard in stages 2/3. Expected wall time, extrapolated from upstream and the | |
| smoke: | |
| * stage1 β 3.5β4 s/step, β 8β9 h; | |
| * stage2 β 5 s/step, β 7 h; | |
| * stage3 β 20β25 s/step, β 3 h. | |
| Tests: | |
| ```bash | |
| CUDA_VISIBLE_DEVICES="" DIFFSYNTH_SKIP_DOWNLOAD=True PYTHONPATH=$M/code/gc25d:$M/code/arope TMPDIR=$M/.tmp \ | |
| $M/.venv/bin/python -m pytest -q code/gc25d/tests/test_{gcdit,stage1,stage2,stage3,distill_config}.py # ~90 s idle (5 min under load), 77 passed 2 skipped | |
| GC_BITPARITY_REAL=1 GC_BITPARITY_CKPT=<any 831-key gc ckpt> CUDA_VISIBLE_DEVICES=<gpu> ... pytest code/gc25d/tests/test_gcdit.py -k real | |
| GC_GPU_FSDP=1 CUDA_VISIBLE_DEVICES=<2 gpus> ... pytest code/gc25d/tests/test_stage3.py -k test_16 # real FSDP: rollout t == deploy | |
| ``` | |
| ## Open issues | |
| 1. **Deploy contract: lead decision needed.** `live.py` as shipped cannot load a parts-vocab ckpt. `LiveGame` calls | |
| `GcDiT(dit=..., causal=True)`, and live.py inserts **its own** package root at `sys.path[0]`, so it always imports the deploy | |
| package's old `model.py` / `gcdistill/gc_dit.py`, which have no vocab support. PYTHONPATH order cannot fix this. Even with | |
| maliang's `gc_dit`, the default `ids` vocab makes the strict load fail on `proj_in` ([512,1280] vs [512,640]). Fixing it inside | |
| maliang would mean changing `GcDiT`'s default or `load_gc_ckpt` (public behaviour, not allowed), so nothing under `ref/` was | |
| edited. A ready patch, `scripts/distill_smoke/deploy_vocab/`: | |
| * `model.py` and `gcdistill/gc_dit.py` in the deploy package are replaced by maliang's. These are strict supersets, and the | |
| `ids` path is bit-identical. | |
| * `live_vocab.patch` changes live.py in three lines to `GcDiT(..., vocab=ckpt_vocab(ckpt))`. `fast_live.py` and | |
| `gen_server.py` inherit `LiveGame`, so they need no change. | |
| Verified on a patched copy for both the v10 parts EMA and the v8 ids ckpt (see Smoke). Pick one: (a) apply the patch to the deploy | |
| package (`make_patched_deploy.sh` builds it), or (b) amend SPEC Β§8 "Deploy contract (unchanged)". | |
| 2. **Stage-3 numerics now equal deploy** (t 1000/752/500/252, bf16 latents), and so do SFT and stages 1/2. The earlier text here ("cast | |
| fix = train/deploy parity, flip only for A/B") was wrong: the first version of the fix moved the student to fp32 t | |
| 750/500.6/251.6, which neither deploy nor its lineage uses (see How). gc25d_v8 trained with the FSDP root cast on: the student | |
| on the deploy t, but the teacher on fp32 t and the critic on bf16 t. It presumably also had the stale-FSDP-root rollout, which | |
| is inherited from upstream. The current code fixes both; neither should matter much at lr 2e-6, but v8 numbers are not a | |
| bit-exact reference. | |
| 3. **SFT step for the teacher/init** is not decided (v8 used step-6000 out of a longer run). `SFT=` must be set to the chosen SFT ckpt; the | |
| default path `outputs/gc25d_v10/step-20000.safetensors` is only a placeholder. | |
| 4. **Stage2 length is the main quality lever** (WorldMind: 15k > 10k > 2k). 5000 follows v8; go longer if compute allows. | |
| 5. The smoke used a zero-init "SFT", so no quality was measured. The first real signal comes from `eval_rollout --chain_cells 241` on | |
| the stage3 milestones (v8 reference ema500: PSNR 15.85 / ZNCC 0.534 / |drift| 2.9 on 60 s chains). The metric definitions here are | |
| close to those but not proven identical, and v10_real's per-clip look changes limit GT metrics on its chains to the first look. | |
| 6. Smoke artifacts: `outputs/_smoke/distill/` is ~294 GB (10 GB ckpts, stage1 `state_A`/`state_B` slots at 66 GB each, `stage3_fix/` | |
| and `stage3_final/` 30 GB each). `outputs/_smoke/distill_fix/` holds logs, json and mp4s only. All of it can be deleted. | |
| 7. **Stage-3 resume is weights-only.** The LR schedules are now fast-forwarded, but generator and critic Adam moments restart | |
| (Ξ²1 = 0, so only `v` is lost). | |
| ## Review fixes (2026-10-22, fixer pass) | |
| Accepted and fixed: | |
| * **[major] FSDP cast fix broke train/deploy t parity** (both reviewers; verified with a 2-GPU probe: root cast off β student fp32 t | |
| 750.0/500.6/251.597). Fix: `_as_latent` in rollout / replay / probe plus root cast kept off; tests 13 (CPU) and 16 (GPU FSDP); doc | |
| rationale corrected (How, Open issue 2). | |
| * **[major] Stage-3 resume restarted the LR warmup** (reviewer resume showed lr_g 4e-8 = Ξ»(1) at step 4). Fix: fast-forward | |
| `slr_g`/`slr_c` (test 15: resumed lr_g / lr_c == uninterrupted run at steps 4, 5); the step-0 note is printed only on fresh runs. | |
| The old code fails test 15 (lr_g 4e-07 instead of 1e-06). | |
| * **[major] Eval used 8 consecutive windows of one run** and could not measure long-horizon drift. Fix: run-stratified selection | |
| (subsets alternate), per-run / per-subset summaries, `--chain_cells` for 60 s chains from consecutive clips (continuity of | |
| cond_ext vs the next clip asserted on load), look-aware GT; run commands updated (tests 17, 18). | |
| * **[minor] Streamed replay not bitwise on GPU** (gnorm_g floor ~1e-3 at step 0). Fix: grad-mode exit forward in the record pass | |
| plus `replay_dev` logging; step 0 is now exactly 0 on real weights (tests 14, 16). | |
| * **New, found while verifying the replay fix: stale FSDP root parameters** after every generator step. The rollout ran one | |
| optimizer step behind on the root unit. Fix: `_free_fsdp_root` (How; test 16; final smoke replay_dev 0 on every step). | |
| * **[minor] Smoke ran on an earlier file revision.** Re-ran the real-weight stage-3 smoke on the final code through | |
| `run_stage3.sh` (`stage3_final/`, 5 steps, PROFILE_MEM, GPUs 6,7). Re-ran the deploy checks (patched live.py, eval_rollout clip | |
| mode) on its EMA, plus the real-weight bitparity gate and test_16. | |
| Confirmed but not fixed in maliang (out of scope / needs the lead): **[blocker] deploy contract**, Open issue 1. A patch and | |
| verification are provided. `ref/` is untouched. | |
| Rejected: none of the findings were wrong. One part of a proposed fix was not adopted: reviewer 1's option "revert to | |
| `cast_root_forward_inputs=True`". It would put the student back on the deploy t, but it leaves the critic and the teacher seeing | |
| different t whenever the tail is fp32. Keeping it off and making the latents bf16 (reviewer 2's variant) fixes both. Reviewer 1's | |
| "base the guard on a noise floor" is unnecessary now that the replay is exact at step 0. | |