Skip to content

[graph_trainer] Add EP overlap eager chunking scaffolding - #3363

Merged
sanketpurandare merged 1 commit into
mainfrom
sanketpurandare/stack/17
Jun 26, 2026
Merged

sanketpurandare merged 1 commit into
mainfrom
sanketpurandare/stack/17

Conversation

@sanketpurandare

@sanketpurandare sanketpurandare commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

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.

@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/17 branch from 7b0065b to 5a5c076 Compare May 15, 2026 03:03
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/16 branch from 60ac042 to 3178797 Compare May 15, 2026 03:03
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 15, 2026
@sanketpurandare
sanketpurandare marked this pull request as draft May 15, 2026 09:36
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/16 to main May 15, 2026 09:36
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/17 branch 2 times, most recently from f8b4a0c to c1314bb Compare May 15, 2026 09:36
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/16 May 15, 2026 09:36
@sanketpurandare
sanketpurandare marked this pull request as ready for review May 15, 2026 09:37
@sanketpurandare
sanketpurandare marked this pull request as draft May 22, 2026 19:02
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/16 to main May 22, 2026 19:02
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/17 branch from c1314bb to 60a804e Compare May 22, 2026 19:03
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/16 May 22, 2026 19:03
@sanketpurandare
sanketpurandare marked this pull request as ready for review May 22, 2026 19:03
@sanketpurandare
sanketpurandare marked this pull request as draft May 26, 2026 05:28
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/16 to main May 26, 2026 05:28
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/17 branch from 60a804e to e62b4d9 Compare May 26, 2026 05:29
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/16 May 26, 2026 05:29
@sanketpurandare
sanketpurandare marked this pull request as draft June 10, 2026 23:49
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/16 to main June 10, 2026 23:49
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/17 branch from 802b756 to 44d3d19 Compare June 10, 2026 23:50
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/16 June 10, 2026 23:50
@sanketpurandare
sanketpurandare marked this pull request as ready for review June 10, 2026 23:50
@sanketpurandare
sanketpurandare marked this pull request as draft June 12, 2026 20:15
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/16 to main June 12, 2026 20:15
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/17 branch from 44d3d19 to 8f5e7a5 Compare June 12, 2026 20:15
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/16 June 12, 2026 20:15
@sanketpurandare
sanketpurandare marked this pull request as ready for review June 12, 2026 20:15
@sanketpurandare
sanketpurandare marked this pull request as draft June 15, 2026 17:37
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/16 to main June 15, 2026 17:37
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/16 June 15, 2026 17:37
@sanketpurandare
sanketpurandare marked this pull request as ready for review June 15, 2026 17:37
@sanketpurandare
sanketpurandare marked this pull request as draft June 15, 2026 17:53
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/16 to main June 15, 2026 17:53
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/16 June 15, 2026 17:53
@sanketpurandare
sanketpurandare marked this pull request as ready for review June 15, 2026 17:53
@sanketpurandare
sanketpurandare marked this pull request as draft June 22, 2026 18:30
Comment thread torchtitan/models/common/decoder.py Resolved
return chunk_dim, chunk_strategy, module_fqn


def enabled_compile_feature_names(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels useful to other (future) passes too, could be in common_utils.py (not needed for this PR)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a Step 1 missing or stale comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@sanketpurandare sanketpurandare Jun 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
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.

RFC: Graph-Based EP Overlap For GraphTrainer

3 participants