[misc] Codebase structure audit: ranked P1/P2 changes
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
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:1importsconfigs/pipelines/__init__.py:19, which importsfastvideo.registry, which imports every pipeline config andpipelines.basic. Anyfastvideo.*import pulls 417 modules, 108 underpipelines.basic.import fastvideo.versionreachesconfigs/pipelines/base.py:7(import torch) here, since torch is absent. A lazyfastvideo/__init__.pyand dropping the registry re-export shrink every low-level import. configs/imports up intopipelines/.configs/pipelines/__init__.py:18importsLTX2T2VConfigfrompipelines/basic/ltx2/pipeline_configs.py, andconfigs/pipelines/pika_h3_flex.py:90importspipelines.basic.pika_h3_flex.buckets.configs/AGENTS.md:61forbids this direction.layers/importsmodels/. 11 edges in 9 files reach generic helpers inmodels/parameter.pyandmodels/utils.py, whose own TODO says move it elsewhere.layers/quantization/nvfp4_config.pyalso hardcodes MiniMax-H3 logic and arange(48)that duplicatesLTX2VideoConfig.num_layers = 48.- Wheel ships
comfyui,testsandfastvideo.testsas top-level packages (208 packages frompyproject.toml:270-273).[tool.wheel]is dead config, anddocker/rocm7_1.Dockerfile:30installspyproject_other.tomlas 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 oflayers/anddistributed/. 16 of 50fastvideo/tests/mlx/files are missing from the macOS workflow's explicit list.@pytest.mark.nightlyis 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 inmodels/dits/andmodels/vaes/.models/dits/wan_s2v.pyre-implements the Wan transformer and missed QAT work sincec520878fd. Camera and Plucker math is copied inlingbotworldandlingbotworld2(drifted), andmatrixgame3/utils.py:8imports the v1 copy. Family stages are split between sharedpipelines/stages/andbasic/<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.htmlroute),fastvideo/platforms/cuda.py:243. scripts/checkpoint_conversion/AGENTS.mdlists 8 of 23 converters; naming table is violated bywan_animate_relight_lora.pyandpush_magi_human_to_hf.py.tests/local_tests/README.mdnames 8 of 28 test dirs; 9 landedPORT_STATUS.mdremain.docs/design/training_architecture.md:251,255reference two configs that no longer exist underexamples/train/.fastvideo/performance_dashboard/api.py:22-23resolves the frontend to<repo>/performance_dashboard/frontend/dist; the frontend is atapps/performance_dashboard/frontend.- Root
__init__.pyduplicatescomfyui/__init__.py.collect_env.pyis neither packaged nor a console script, though the bug template tells users to run it.pyproject.toml:7andfastvideo/version.py:1both carry the version, but onlypyproject.tomlgates publishing.
Evidence:
- Import closure, parent-package edges included:
fastvideo.layers.linear,fastvideo.versionandfastvideo.attention.layereach reach 417 modules, 108 underfastvideo.pipelines.basic.python3 -c "import fastvideo.version"stops atconfigs/pipelines/base.py:7. grep -rn "fastvideo.pipelines" fastvideo/configs --include=*.pyreturns the two edges above.grep -rn "from fastvideo.models" fastvideo/layers --include=*.py | wc -lis 11.find_packages(where=".", exclude=[...from pyproject...])returns 203 packages at the repo root plus 4 and 1 from the two app roots, withcomfyui,testsandfastvideoas top-level names.grep -rn "tests/hooks\|tests/audio\|tests/layers\|tests/distributed" .buildkite .github/workflowshas 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 -lis 116.diff -u fastvideo/models/dits/lingbotworld/cam_utils.py fastvideo/models/dits/lingbotworld2/cam_utils.pyis 38 changed lines.
— fv-superagent · 417 modules, and not one of them asked · run by aryan5v