Repository navigation
[graph_trainer] Use tlparse_log_graph_pass for GraphPP and GA graph dumps - #5035
Merged
Merged
Conversation
…umps GraphPP and gradient-accumulation code dumped graphs to tlparse through graph_pp.utils.trace_graph_pp_graph, a near copy of debug_utils.tlparse_log_graph_pass, the helper graph passes use. Replace every trace_graph_pp_graph call with tlparse_log_graph_pass and remove it, so all graph dumps use one helper and one format (expanded signature plus autograd_backward / seq_nr metadata). Also drop the graph_pp_ prefix from the gradient-accumulation and FSDP extraction artifact names (e.g. graph_pp_fsdp_unshard -> fsdp_unshard), since these graphs are not GraphPP-specific.
SherlockNoMad
requested review from
IvanKobzarev,
aditvenk,
sanketpurandare and
tianyu-l
as code owners
October 2, 2026 23:23
aditvenk
approved these changes
Oct 3, 2026
SherlockNoMad
added a commit
that referenced
this pull request
Oct 5, 2026
…ation path (#5038) Rebased onto `main` after #5035 landed. ## Why SPMD with gradient accumulation builds its first / middle / last graphs with three FSDP extractor calls. Each call also built, linted, and dumped the *collective* half of the split (the unshard or reduce-grad graph), but this path only reads its names (`unshard_output_names`, `reduce_grad_input_names`). In a DeepSeek-V3 16B FSDP=4/EP=4 GA=3 run, 3 of the 6 graphs those calls built (`fsdp_reduce_grad` and two `fsdp_unshard`) were discarded. ## What - Replace each extractor's `extract_*` boolean with one mode, `FSDPExtractionMode = Literal["keep", "cut", "split"]`: - `keep`: return the input graph (the reduce extractor still reports `reduction_node_names`, which PP uses). - `cut`: remove the collectives from the compute graph only; no collective module. - `split` (default): also return the collectives as `unshard_module` / `reduce_grad_module`. SPMD with GA uses `cut`; PP uses `split`; both use `keep` when not splitting. This also avoids the meaningless "don't extract, but build the module" combination two booleans would allow. - With `cut`: - The unshard graph is still extracted, because the compute graph's DCE needs its node set (impure nodes computable from the parameters, e.g. waits and prefetch launches). Only module creation, cleanup, and the dump are skipped. `unshard_output_names` comes from `compute_param_inputs`, which are exactly that graph's outputs. - The reduce-grad graph is not extracted at all. `reduce_grad_input_names` comes from the unique reduction inputs, which are exactly that graph's placeholders (`_extract_graph_with_inputs_outputs` names placeholders `node.name`). - Rename `GraphPPFSDPUnshardExtraction` -> `FSDPUnshardExtraction` and `GraphPPFSDPReduceGradExtraction` -> `FSDPReduceGradExtraction`; SPMD gradient accumulation uses them too. The graphs that are kept are unchanged. ## Tests - Bitwise-identical loss and grad_norm vs. `main`, 10 steps, `seed=42`, `deterministic=True` (`scripts/loss_compare.py --metrics loss,grad_norm --assert-equal`): - Llama3 debug, SPMD GA, FSDP=4, first/last - Llama3 debug, SPMD GA, FSDP=4, every/every - DSv3 debug, PP=2 x FSDP=2 x EP=2, Interleaved1F1B (PP extractor path, incl. the new `reduce_grad_input_names` source) - In `split` mode, temporarily asserted the new `unshard_output_names` equals `output_names(unshard_module)`; held across the graph PP tests. - `test_graph_pp_runner.py`, `test_graph_pp_passes.py`: 111 passed, 1 skipped. - pre-commit clean.
SherlockNoMad
added a commit
that referenced
this pull request
Oct 5, 2026
Regenerated on current `main` (the earlier version predated #4999, #5001, #5003, #5035, #5038 and the Dist-MoE adapter #4541, which all touched `graph_builder.py`). ## Why `graph_builder.py` had grown to ~2650 lines mixing the stage-graph provider, shared helpers, SPMD graph construction (with and without gradient accumulation), and PP stage graph construction. Splitting it along the execution paths (SPMD / PP) makes each path readable on its own. ## What | File | Contents | |---|---| | `graph_builder.py` (~290 lines) | `GraphExecutionPlan`, placement types, `GraphTrainerStageGraphProvider`, the provider's Dist-MoE slot lookup | | `graph_builder_utils.py` (~310) | `GraphTrainerConfigView`, FSDP bucketing helpers, graph execute/pack/compile helpers shared by both paths | | `spmd_graph_builder.py` (~360) | joint-graph tracing shared by both SPMD paths; SPMD without gradient accumulation executor and builder | | `spmd_gradient_accumulation_graph_builder.py` (~810) | SPMD with gradient accumulation: first / middle / last graphs, their executor, accumulation, edge-graph bucketing | | `graph_pp/pp_graph_builder.py` (~1020) | PP stage graphs, partitioning, overlap graphs, the Dist-MoE activation-slot rewrite used by PP stages | **Pure code move.** All 45 top-level definitions are AST-identical to `main` (checked by script), except: - `spmd_graph_builder.py` imports `GraphExecutionPlan` under `TYPE_CHECKING` and quotes its annotations, to avoid an import cycle with `graph_builder.py`. - Each file has only the imports it uses, its own `logger`, and keeps `graph_builder.py`'s `from __future__ import annotations` (needed for the `TYPE_CHECKING`-only Dist-MoE annotations). Callers (`pipeline.py`, `precompile_main.py`, tests) and `mock.patch` targets are updated to the new modules. **Second commit** moves the SPMD gradient-accumulation code out of `spmd_graph_builder.py` (it was ~70% of that file), so the simple SPMD path reads on its own. The only non-move change is the dispatch: `_build_fwd_bwd_graphs` used to trace and then branch on `plan.has_gradient_accumulation`; its tracing becomes `_trace_spmd_stage_graph` (shared), `_build_fwd_bwd_graphs` builds only SPMD without gradient accumulation, the new `_build_gradient_accumulation_fwd_bwd_graphs` builds the GA path, and `GraphTrainerStageGraphProvider` picks between them as it already does for PP. The new module imports from `spmd_graph_builder.py`, not the reverse. ## Tests - `test_graph_pp_runner.py`, `test_graph_pp_passes.py`, `test_trace_module.py`: 169 passed, 4 skipped, 2 failed. Both failures reproduce on unmodified `main`: - `test_dist_moe_slot_is_an_explicit_stage_graph_input`: `dist_moe` package not installed locally. - `test_initializes_one_stage_pipeline_runtime`: its `SimpleNamespace` config lacks the new `dist_moe` field read at `trainer.py:108`. - Bitwise-identical loss and grad_norm vs. `main`, 10 steps, `seed=42`, `deterministic=True` (`scripts/loss_compare.py --assert-equal`): SPMD GA first/last (FSDP=4), SPMD GA without FSDP (1 GPU), SPMD without GA (FSDP=4). - `precompile_main` / `trainer` import check passes. - pre-commit clean.
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.
Why
GraphPP and gradient-accumulation code dumped graphs to tlparse through
graph_pp.utils.trace_graph_pp_graph, a near copy ofdebug_utils.tlparse_log_graph_pass, which graph passes already use. Two helpers for the same artifact meant two dump formats in one tlparse report.What
trace_graph_pp_graph(name, gm)calls withtlparse_log_graph_pass(gm, graph_name=name)(grad_accumulation.py,graph_pp/partition.py,graph_pp/split_fsdp_collectives.py,graph_pp/split_di_dw.py,graph_pp/graph_multiplex.py) and removetrace_graph_pp_graph.autograd_backward/seq_nrmetadata.graph_pp_prefix from the gradient-accumulation and FSDP extraction artifact names (e.g.graph_pp_fsdp_unshard->fsdp_unshard,graph_pp_before_insert_graph_gradient_accumulation->before_insert_graph_gradient_accumulation), since those graphs are not GraphPP-specific. Partition, dI/dW, and multiplex dumps keepgraph_pp_.No behavior change beyond tlparse artifact names and format.
Tests
test_graph_pp_runner.py,test_graph_pp_passes.py: 111 passed, 1 skipped.