Skip to content

[dist_moe] Support eager expert-output callbacks - #5051

Merged
sanketpurandare merged 1 commit into
mainfrom
sanket/dist-moe-eager-postprocess
Oct 4, 2026
Merged

sanketpurandare merged 1 commit into
mainfrom
sanket/dist-moe-eager-postprocess

Conversation

@sanketpurandare

@sanketpurandare sanketpurandare commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

The Dist-MoE annex supports two post-expert policies: typed fused descriptors and eager callables. TorchTitan currently accepts only RMSNormPostprocess, preventing a model-owned learned postprocess module from using the annex eager path while retaining normal module, optimizer, FSDP, checkpoint, hook, and autograd ownership.

Design

Allow to_dist_moe_postprocess() to return either dist_moe.RMSNormPostprocess or any callable. TorchTitan forwards the exact returned object to dist_moe.ExecutionOptions; it does not execute, wrap, copy, or reinterpret the callback. Returning the module itself therefore preserves nn.Module.__call__, forward hooks, parameters in the state dict, and ordinary input/parameter gradients.

The existing invalid-result check remains strict: objects that are neither the typed descriptor nor callable fail at the TorchTitan integration boundary. Annex marks callable policies as eager, so this does not claim arbitrary-callback make_fx or GraphTrainer support.

Verification

  • Focused callback test proves exact object identity and eager-policy selection.
  • A registered module forward hook executes exactly once.
  • Input and learned-parameter gradients are produced through ordinary autograd.
  • The learned parameter remains in the module state dict.
  • Invalid factory output raises the actionable integration error.
  • Common Dist-MoE plus stacked CUDA-graph selection: 32 passed, 37 deselected.
  • Repository formatting, AST, whitespace, license, flake8, pydoclint, codespell, and link checks pass. Pyrefly reports the same two unrelated main errors described in the lower PR.

This PR is the upper layer of the native GitHub stack and is based on #5050.


Stack created with GitHub Stacks CLI

@pytorch-bot pytorch-bot Bot added ciflow/b200 Trigger B200 CI ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl labels Oct 4, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 4, 2026
@sanketpurandare
sanketpurandare force-pushed the sanket/dist-moe-eager-postprocess branch from ffa1743 to 2525dc9 Compare October 4, 2026 21:55
Base automatically changed from sanket/cudagraph-nondeferred-ga to main October 4, 2026 22:41
Dist-MoE supports both typed fused postprocess descriptors and eager callable postprocessing. TorchTitan currently accepts only RMSNormPostprocess, which prevents model-owned learned postprocessing modules from using the eager contract.

Accept callable results from to_dist_moe_postprocess() and forward the exact object to the annex. Returning the module itself preserves nn.Module.__call__, forward hooks, parameter ownership, state dict entries, and ordinary autograd gradients. Invalid non-callable results still fail at the integration boundary.

Test: python -m pytest -q tests/unit_tests/cpu/test_dist_moe.py tests/unit_tests/cpu/test_trainer.py -k "dist_moe or cuda_graph_accumulation_supports_eager_gradient_reduction" (32 passed)
@sanketpurandare
sanketpurandare force-pushed the sanket/dist-moe-eager-postprocess branch 2 times, most recently from 2525dc9 to 492f5a2 Compare October 4, 2026 22:43
@sanketpurandare
sanketpurandare merged commit 0d04f74 into main Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/b200 Trigger B200 CI ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl 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.

2 participants