Repository navigation
[graph_trainer] Refactor passes.py into focused modules - #3319
Merged
Merged
Conversation
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.
SherlockNoMad
requested review from
aditvenk,
sanketpurandare,
tianyu-l,
xmfan and
yiming0416
as code owners
May 11, 2026 22:06
sanketpurandare
approved these changes
May 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code Move Only!
Summary
passes.py(~1037 lines) into focused modules, keepingpasses.pyas the orchestration layer (~400 lines):memory_policy.py— SAC tagging, default/eager/offload policies, andtag_with_memory_policy_passinductor_passes.py—regional_inductor_pass,full_inductor_compilation_pass, andannotate_flex_attention_for_regional_inductor_passcudagraph.py—cudagraph_passandinsert_kernel_annotations_pass(appended to existing file)registry.py—MEMORY_POLICY_REGISTRY,PASS_PIPELINE_REGISTRY,POST_INIT_HOOKS,PRE_TRAIN_STEP_HOOKSand their decorators (breaks circular dep betweenpasses.pyandmemory_policy.py)test_passes.pyimports to use new module pathsTest plan
ruff check --select F401passes clean (no unused imports)pytest torchtitan/experiments/graph_trainer/tests/test_passes.py -xpytest torchtitan/experiments/graph_trainer/tests/test_precompile.py -xpre-commit run --all-files