FastVideo icon indicating copy to clipboard operation
FastVideo copied to clipboard

[misc] Codebase structure audit: ranked P1/P2 changes

Open fv-superagent opened this issue 1 month ago • 1 comments

Audit of FastVideo against the untangle-codebase lenses (hidden links, needless links, surplus, special cases). Static analysis only; no code changed. Ranked by payoff. P1 items are behavior-neutral under the repo's small-diff and SSIM/performance rules.

P1

1. Enforce the two-stack training boundary

fastvideo/AGENTS.md says imports between fastvideo/train/ and fastvideo/training/ are forbidden. 13 files in fastvideo/train/ import fastvideo/training/ today: callbacks/ema.py, callbacks/posthoc_ema.py, callbacks/validation.py, methods/base.py, methods/rl/diffusion_nft.py, models/cosmos/cosmos.py, models/hunyuan/hunyuan.py, models/hunyuan15/hunyuan15.py, models/kandinsky5/kandinsky5.py, models/matrixgame2/matrixgame2.py, models/wan/wan.py, utils/optimizer.py, utils/tracking.py. The modular trainer's EMA, checkpointing, optimizer/scheduler and tracking paths depend on the frozen legacy stack, so a legacy change breaks them silently. Add fastvideo/tests/contract/test_training_stack_boundary.py using the shrink-only allowlist pattern already in fastvideo/tests/contract/test_env_policy.py: new coupling fails, and fixing an allowlisted site requires deleting its entry. Test-only, no runtime behavior.

2. Stop copying the denoising verify_input check sets

Three distinct check sets are each duplicated, 7 methods total across 6 files: pipelines/basic/wan/stages/causal_denoising.py:117, pipelines/stages/matrixgame2_denoising.py:730, pipelines/stages/matrixgame3_denoising.py:36 (one set); pipelines/stages/latent_preparation.py:150 and pipelines/basic/ltx2/stages/ltx2_latent_preparation.py:269; pipelines/stages/denoising.py:670 and pipelines/stages/sr_denoising.py:322. The bodies are AST-identical. Move each set into one module-level helper in fastvideo/pipelines/stages/ and call it from each method. The checks are unchanged, so verification output is identical. Adding or changing an input check then happens once instead of up to three times.

P2

3. Replace model-name branches in shared code with declared capabilities

models/loader/component_loader.py branches on Cosmos25 and Gen3C (:881-886), MMAudioVAE and Kandinsky6AudioVAE (:1108-1119), Cosmos25 again (:1302-1303), MiniMaxH3 (:1329) and LTX2 (:1534); models/loader/fsdp_load.py:533 branches on MiniMaxH3; pipelines/stages/decoding.py:87,176 branches on LingBotVideo; component_loader.py:1311 lazy-imports a specific pipeline. Each is a requirement the shared path never modeled, the same class as #1254. Declaring these as per-component capabilities removes the branches and the models -> pipelines import. Stage one capability at a time with the loader tests and an SSIM run; it touches loading, so it is not P1.

4. Move the shared primitives out of the legacy stack

fastvideo/train/ pulls about 19 symbols from fastvideo/training/: EMA_FSDP, normalize_dit_input, compute_density_for_timestep_sampling, get_sigmas, shift_timestep, ModelWrapper/OptimizerWrapper/SchedulerWrapper/get_scheduler, Trackers/initialize_trackers, and checkpoint helpers. Relocating them into the new stack, or a neutral module, lets the legacy stack import from the new one, and then the allowlist from item 1 burns down. Needs a maintainer call because it crosses the two-stack boundary.

5. Keep the MLX and CUDA H3 reference paths in sync

fastvideo/mlx_runtime/minimax_h3_reference.py and fastvideo/pipelines/basic/minimax_h3/reference.py share sample_reference_video_frames and build_ref2va_presentation. Share one source or add a parity test; today the two can drift.

6. Decide per family on the forked model ports

Large identical bodies exist between sibling ports: cosmos2_5/gen3c, hunyuanvideo/hunyuanvideo15, kandinsky5/kandinsky6, lingbotworld/lingbotworld2, matrixgame2/matrixgame3, clip/siglip. For each family, accept the fork as intentional or share a base. Do not refactor model internals without SSIM coverage for that model.

7. Small convention cleanups

Replace the remaining direct logging.getLogger calls with init_logger(__name__) in non-excluded files (eval/worker.py, train/methods/knowledge_distillation/kd.py, worker/multiproc_executor.py). The three overfit preprocess scripts (pipelines/preprocess/preprocess_cosmos25_overfit.py, preprocess_cosmos_overfit.py, preprocess_hunyuan_overfit.py) share an identical load_video.

Not doing

  • The skill's "fix everything until nothing left" loop. It conflicts with the SSIM/performance gates, the small-diff review rule, and the freeze on legacy pipelines.
  • The skill's Tests option. Deleting tests that "can't fail" conflicts with the repo rule against weakening tests.
  • A wholesale chase of import cycles. There are 27 module-level 2-cycles and one 202-module SCC (configs 103, pipelines 37, models 21, rest smaller); most are registry/registration patterns. Document, do not rewrite.
  • A naive dead-code sweep. Eval metrics and model classes resolve by name, so a text scan reports 157 modules as unreferenced; that number is not a work list.
  • Reformatting pre-commit-excluded dirs (third_party/, dataset/, models/).

Method: AST import graph over 769 non-test modules, AST-body hashing for function-level duplicates (34 groups at 8 statements or more), and targeted greps. Related work: #1254, #1913, merged #1698.

— fv-superagent · run by @aryan5v

fv-superagent avatar Nov 05 '26 18:11 fv-superagent

This is by an automated agent, not a human.

Second-pass audit at 866a3cdb9, from four subagent passes on layering, model-family placement, tests/docs/scripts, and packaging. Everything below is new relative to this issue, #2081, #2082 and #2083. The two P1 items on this issue are still open on main: 13 fastvideo/train/ files import fastvideo/training/, and no boundary contract test exists.

Structural, needs a decision:

  • Package import drags the whole stack. fastvideo/__init__.py:1 imports configs/pipelines/__init__.py:19, which imports fastvideo.registry, which imports every pipeline config and pipelines.basic. Any fastvideo.* import pulls 417 modules, 108 under pipelines.basic. import fastvideo.version reaches configs/pipelines/base.py:7 (import torch) here, since torch is absent. A lazy fastvideo/__init__.py and dropping the registry re-export shrink every low-level import.
  • configs/ imports up into pipelines/. configs/pipelines/__init__.py:18 imports LTX2T2VConfig from pipelines/basic/ltx2/pipeline_configs.py, and configs/pipelines/pika_h3_flex.py:90 imports pipelines.basic.pika_h3_flex.buckets. configs/AGENTS.md:61 forbids this direction.
  • layers/ imports models/. 11 edges in 9 files reach generic helpers in models/parameter.py and models/utils.py, whose own TODO says move it elsewhere. layers/quantization/nvfp4_config.py also hardcodes MiniMax-H3 logic and a range(48) that duplicates LTX2VideoConfig.num_layers = 48.
  • Wheel ships comfyui, tests and fastvideo.tests as top-level packages (208 packages from pyproject.toml:270-273). [tool.wheel] is dead config, and docker/rocm7_1.Dockerfile:30 installs pyproject_other.toml as a second dependency graph (torch 2.12 vs 2.11).
  • Tests with no lane. No Buildkite lane collects fastvideo/tests/hooks/, fastvideo/tests/audio/, or most of layers/ and distributed/. 16 of 50 fastvideo/tests/mlx/ files are missing from the macOS workflow's explicit list. @pytest.mark.nightly is unregistered and 4 of 5 nightly files have no env guard.
  • Model-family placement. MiniMax-H3 spans 116 files across 21 dirs with loose minimax_h3_* modules in models/dits/ and models/vaes/. models/dits/wan_s2v.py re-implements the Wan transformer and missed QAT work since c520878fd. Camera and Plucker math is copied in lingbotworld and lingbotworld2 (drifted), and matrixgame3/utils.py:8 imports the v1 copy. Family stages are split between shared pipelines/stages/ and basic/<model>/stages/ with no rule.

Next: I can take the safe P1 batch below as one docs/chore PR, or open a test-only contract test that maps every test file to a lane. Say which.

Safe P1 batch, plus commands and exact locations

Safe, behavior-neutral:

  • 8 retired-host links remain after #2081: docs/getting_started/installation.md, docs/news.md, examples/inference/basic/README.md, two gradio demos, examples/training/finetune/wan_t2v_1.3B/mixkit/README.md, fastvideo/pipelines/README.md:3 (also a dead .html route), fastvideo/platforms/cuda.py:243.
  • scripts/checkpoint_conversion/AGENTS.md lists 8 of 23 converters; naming table is violated by wan_animate_relight_lora.py and push_magi_human_to_hf.py.
  • tests/local_tests/README.md names 8 of 28 test dirs; 9 landed PORT_STATUS.md remain.
  • docs/design/training_architecture.md:251,255 reference two configs that no longer exist under examples/train/.
  • fastvideo/performance_dashboard/api.py:22-23 resolves the frontend to <repo>/performance_dashboard/frontend/dist; the frontend is at apps/performance_dashboard/frontend.
  • Root __init__.py duplicates comfyui/__init__.py. collect_env.py is neither packaged nor a console script, though the bug template tells users to run it. pyproject.toml:7 and fastvideo/version.py:1 both carry the version, but only pyproject.toml gates publishing.

Evidence:

  • Import closure, parent-package edges included: fastvideo.layers.linear, fastvideo.version and fastvideo.attention.layer each reach 417 modules, 108 under fastvideo.pipelines.basic. python3 -c "import fastvideo.version" stops at configs/pipelines/base.py:7.
  • grep -rn "fastvideo.pipelines" fastvideo/configs --include=*.py returns the two edges above.
  • grep -rn "from fastvideo.models" fastvideo/layers --include=*.py | wc -l is 11.
  • find_packages(where=".", exclude=[...from pyproject...]) returns 203 packages at the repo root plus 4 and 1 from the two app roots, with comfyui, tests and fastvideo as top-level names.
  • grep -rn "tests/hooks\|tests/audio\|tests/layers\|tests/distributed" .buildkite .github/workflows has no lane entry for hooks or audio and only 3 files for layers.
  • git ls-files | grep -i minimax | grep -vE 'tests/|docs|examples/' | wc -l is 116.
  • diff -u fastvideo/models/dits/lingbotworld/cam_utils.py fastvideo/models/dits/lingbotworld2/cam_utils.py is 38 changed lines.

— fv-superagent · 417 modules, and not one of them asked · run by aryan5v

fv-superagent avatar Nov 10 '26 04:11 fv-superagent