Repository navigation
[graph_trainer] Add EP overlap eager chunking scaffolding - #3363
Conversation
7b0065b to
5a5c076
Compare
60ac042 to
3178797
Compare
f8b4a0c to
c1314bb
Compare
c1314bb to
60a804e
Compare
60a804e to
e62b4d9
Compare
802b756 to
44d3d19
Compare
44d3d19 to
8f5e7a5
Compare
| return chunk_dim, chunk_strategy, module_fqn | ||
|
|
||
|
|
||
| def enabled_compile_feature_names( |
There was a problem hiding this comment.
nit: this name was confusing to me upon first read, perhaps we can rename it to trace_input_prepare_keys or something like that -- if only usage is for that purpose.
There was a problem hiding this comment.
Renamed this to trace_input_preparer_keys, which is the actual contract at the trainer callsite.
| from torchtitan.tools.logging import logger | ||
|
|
||
|
|
||
| def _matches_module_fqn(pattern: str, fqn: str) -> bool: |
There was a problem hiding this comment.
this feels useful to other (future) passes too, could be in common_utils.py (not needed for this PR)
There was a problem hiding this comment.
Moved this into common_utils.matches_module_fqn_pattern and reused it from the eager chunking path,
| self.dim = _chunk_dim_index(chunk_dim) | ||
|
|
||
| def __call__(self, *args: Any, **kwargs: Any) -> Any: | ||
| # Step 2: infer the full extent from the first tensor input that carries |
There was a problem hiding this comment.
Is there a Step 1 missing or stale comment?
There was a problem hiding this comment.
Removed the stale numbered step comments from the wrapper body. The file-level docstring now carries the high-level algorithm, and the inline comments only cover the non-obvious input contract and BlockMask handling. The Steps were becoming non-linear while reading.
| if ( | ||
| isinstance(value, torch.Tensor) | ||
| and value.dim() > self.dim | ||
| and value.shape[self.dim] == full_extent |
There was a problem hiding this comment.
could we have a scenario where shape[chunked dim] == full_extent, but it is some unrelated dimension that we should not chunk? Perhaps this is unlikely.
There was a problem hiding this comment.
I have significantly simplified the eager chunking contract. Removed the shape-equality heuristic. Eager chunking now validates the selected root module's forward contract and chunks only the supported inputs: the single MoE activation for layers.*.moe, or transformer-block activation/positions plus BlockMask for layers.* batch chunking. Unsupported extra tensor inputs now raise an actionable error instead of being chunked by matching extent. This is better than silent incorrectness
| if isinstance(value, BlockMask): | ||
| if self.chunk_dim != "batch": | ||
| return [value, value] | ||
| from torch.distributed.pipelining.microbatch import _split_block_mask |
There was a problem hiding this comment.
(can be in a follow-up) Can we add a brief comment aboutt what _split_block_mask does and why we are using it here?
There was a problem hiding this comment.
Added the comment. The wrapper uses PyTorch's _split_block_mask so batch chunking keeps FlexAttention BlockMask batch metadata consistent with the activation chunks instead of duplicating stale mask metadata.
| # real backend (see ParallelDims._mesh_exist), even at degree 1, so that | ||
| # MixedPrecisionPolicy's param_dtype cast still applies in single-GPU runs. | ||
| model = apply_simple_fsdp(model, parallel_dims=parallel_dims, training=training) | ||
| apply_ep_overlap_eager_chunking(model, compile_config) |
There was a problem hiding this comment.
nit: Can we rename this to maybe_apply_ep_overlap_eager_chunking ? Since it doesn't take any effect if chunk strategy is eager or compile is disabled.
There was a problem hiding this comment.
Renamed the helper to maybe_apply_ep_overlap_eager_chunking and made the compile-disabled case an explicit no-op.
| h = torch.tensor(0) | ||
| q_idx = torch.tensor(1) | ||
| kv_idx = torch.tensor(0) | ||
| self.assertFalse(seen_masks[0].mask_mod(b, h, q_idx, kv_idx).item()) |
There was a problem hiding this comment.
Perhaps this is covered in follow-up PRs, are there tests that assert that chunk_id/chunk_region_fqn and other metadata survive as expected on the split/body nodes?
There was a problem hiding this comment.
Yes those tests were added in the scheduling pass commit but now I moved one in this commit. It runs the eager chunking path through tracing and checks that the traced chunk nodes retain chunk_id and chunk_region_fqn metadata in test_eager_chunking_traces_overlap_metadata
Add the public EP-overlap chunking config, eager module wrappers, trace-input preparation, and eager chunk metadata population. The eager path gives graph_trainer a reference chunking implementation before the graph rewrite and scheduling passes are introduced. Wire the eager wrapper into supported MoE model parallelization and include the EP overlap config in the precompile fingerprint. Test Plan:\n- Covered by focused graph_trainer pass/precompile tests and the final stack validation. stack-info: PR: #3363, branch: sanketpurandare/stack/17
Stacked PRs:
[graph_trainer] Add EP overlap eager chunking scaffolding
Add the public EP-overlap chunking config, eager module wrappers, trace-input preparation, and eager chunk metadata population. The eager path gives graph_trainer a reference chunking implementation before the graph rewrite and scheduling passes are introduced.
Wire the eager wrapper into supported MoE model parallelization and include the EP overlap config in the precompile fingerprint.
Test Plan:\n- Covered by focused graph_trainer pass/precompile tests and the final stack validation.