Repository navigation
[dist_moe] Reset context after PP metadata inference - #5084
Conversation
| self._metadata_inference_cleanup_handle = ( | ||
| pp_schedule.register_post_metadata_inference_cleanup( | ||
| self.context.reset | ||
| ) | ||
| ) |
There was a problem hiding this comment.
runtime.py:371 registers cleanup on pp_schedule. GraphPP passes its analysis-only liveness schedule, but metadata inference runs on a different execution schedule.
It works today only because copy.copy(schedule) shares the callback dictionary. Add an explicit registrar that forwards to GraphRuntime.schedule.
There was a problem hiding this comment.
Added GraphRuntime.register_post_metadata_inference_cleanup() as an explicit registrar that delegates to GraphRuntime.schedule, and passed it separately from pipeline_liveness_schedule into DistMoeRuntime. Eager PP still registers directly on its single schedule. The existing GraphTrainer test now uses distinct liveness and execution schedules and invokes the registrar to verify that registration targets the execution schedule and returns its handle. The focused eager and GraphTrainer Dist-MoE suites pass (46 passed), and focused Pyrefly reports zero errors for runtime.py.
c6c808a to
112f731
Compare
Dynamic PP metadata inference executes real model forwards before the first training step. Register the Dist-MoE context reset through PyTorch's post-metadata-inference cleanup API so probe activation state cannot enter the real schedule. Runtime teardown owns and removes the registration. Test Plan: ``` python -m pytest -q tests/unit_tests/cpu/test_dist_moe.py pyrefly check torchtitan/models/common/dist_moe/runtime.py pre-commit run --files torchtitan/models/common/dist_moe/runtime.py tests/unit_tests/cpu/test_dist_moe.py ```
GraphTrainer retains a pre-rewrite pipeline schedule for activation-liveness analysis, but metadata inference executes on GraphRuntime.schedule. Registering cleanup on the liveness copy worked only because copy.copy shared its callback dictionary with the execution schedule. Give GraphRuntime an explicit cleanup registrar and thread it independently from the liveness schedule into DistMoeRuntime. Eager PP continues to register directly on its single schedule. This change was authored with assistance from Codex. Test Plan: ``` python -m pytest -q tests/unit_tests/cpu/test_dist_moe.py torchtitan/experiments/graph_trainer/tests/test_dist_moe.py pyrefly check torchtitan/models/common/dist_moe/runtime.py SKIP=pyrefly-check pre-commit run --files torchtitan/models/common/dist_moe/runtime.py torchtitan/experiments/graph_trainer/graph_pp/runner.py torchtitan/experiments/graph_trainer/trainer.py torchtitan/experiments/graph_trainer/tests/test_dist_moe.py tests/unit_tests/cpu/test_dist_moe.py ```
112f731 to
505e248
Compare
Summary
Dynamic pipeline metadata inference executes representative model forwards before the first training step. Dist-MoE owns activation state outside the stage module, so PipelineStage's module and FSDP cleanup cannot release that state.
Register
DistMoeRuntime.context.resetthrough PyTorch's post-metadata-inference cleanup API. The runtime owns the returned handle and removes it during constructor rollback and normal teardown.This replaces the validation-only private schedule monkeypatch. It does not change pipeline schedules, activation-slot coloring, Dist-MoE kernels, or static-metadata execution.
Dependency
Depends on pytorch/pytorch#199884. Keep this PR in draft until that API lands, then rebase on the corresponding PyTorch baseline and rerun the gates below.
Test plan
python -m pytest -q tests/unit_tests/cpu/test_dist_moe.py(38 passed)torchtitan/models/common/dist_moe/runtime.py(0 errors)video.pyerror