Skip to content

[graph_trainer] Refactor passes.py into focused modules - #3319

Merged
SherlockNoMad merged 2 commits into
mainfrom
refactor-passes-split
May 11, 2026
Merged

SherlockNoMad merged 2 commits into
mainfrom
refactor-passes-split

Conversation

@SherlockNoMad

@SherlockNoMad SherlockNoMad commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Code Move Only!

Summary

  • Split the monolithic passes.py (~1037 lines) into focused modules, keeping passes.py as the orchestration layer (~400 lines):
    • memory_policy.py — SAC tagging, default/eager/offload policies, and tag_with_memory_policy_pass
    • inductor_passes.py — regional_inductor_pass, full_inductor_compilation_pass, and annotate_flex_attention_for_regional_inductor_pass
    • cudagraph.py — cudagraph_pass and insert_kernel_annotations_pass (appended to existing file)
    • registry.py — MEMORY_POLICY_REGISTRY, PASS_PIPELINE_REGISTRY, POST_INIT_HOOKS, PRE_TRAIN_STEP_HOOKS and their decorators (breaks circular dep between passes.py and memory_policy.py)
  • Code-move only — all function bodies are identical; the only diffs are removing local imports that became unnecessary when code moved to the same file
  • Updated test_passes.py imports to use new module paths

Test plan

  • ruff check --select F401 passes clean (no unused imports)
  • pytest torchtitan/experiments/graph_trainer/tests/test_passes.py -x
  • pytest torchtitan/experiments/graph_trainer/tests/test_precompile.py -x
  • pre-commit run --all-files

SherlockNoMad and others added 2 commits May 11, 2026 13:33
Split the 1037-line passes.py into focused modules:
- memory_policy.py: SAC tagging and registered memory policies
- inductor_passes.py: regional/full Inductor compilation + FlexAttention annotation
- cudagraph.py: moved cudagraph_pass and insert_kernel_annotations_pass here

passes.py remains as the orchestration layer (~426 lines) with pass
list construction, apply_graph_passes, and registries.
Move MEMORY_POLICY_REGISTRY, PASS_PIPELINE_REGISTRY, POST_INIT_HOOKS,
PRE_TRAIN_STEP_HOOKS and their register_* decorators into registry.py.
This breaks the circular dependency between passes.py and memory_policy.py.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 11, 2026
@SherlockNoMad SherlockNoMad added the ciflow/h100.8 Trigger H100.8 CI label May 11, 2026
@SherlockNoMad
SherlockNoMad merged commit 1a0fe3e into main May 11, 2026
21 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/h100.8 Trigger H100.8 CI ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants