Skip to content

inference moe expert sp padding - #4080

Open
acisseJZhong wants to merge 7 commits into
gh/acisseJZhong/28/basefrom
gh/acisseJZhong/28/head
Open

inference moe expert sp padding#4080
acisseJZhong wants to merge 7 commits into
gh/acisseJZhong/28/basefrom
gh/acisseJZhong/28/head

Conversation

@acisseJZhong

@acisseJZhong acisseJZhong commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Summary

Pad MoE inputs to the expert sequence-parallel degree before routing, then
trim the output to its original length. This ensures equal TP shards for
uneven decode batches and removes virtual-padding bookkeeping from token
dispatchers.

Adds a TP=EP=4 vLLM test covering a three-request decode batch and verifying
bitwise decode/prefill parity.

Test Plan

CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --standalone --nproc-per-node=4     -m pytest -q     torchtitan/experiments/rl/tests/test_generator.py::test_vllm_uneven_decode_tp_padding

[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 7, 2026
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Aug 7, 2026
ghstack-source-id: 7eac073
Pull-Request: #4080
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Aug 7, 2026
ghstack-source-id: ae72c77
Pull-Request: #4080
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Aug 7, 2026
ghstack-source-id: 36cd98b
Pull-Request: #4080
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Aug 7, 2026
ghstack-source-id: 86db615
Pull-Request: #4080
expert_parallel_degree: int = 1
"""Expert parallelism degree for MoE layers. 1 means disabled."""

enable_sequence_parallel: bool = False

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.

The moe part of change looks good to me. But why we would ever enable SP for generator in general? (I know that we are always using expert sp)

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 added this flag just in case we want to turn on SP for inference later. For uneven inference when dense SP on, vllm model runner will pad the global input for us to make sure it's evenly divided. Therefore I need to pass enable_sp in Compilation Config into vllm.

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.

Let's separate it in a different PR if it's needed (with symmetric-memory based AG / RS). Right now it doesn't seem to benefit anyone, so let's split the complexity.

@acisseJZhong acisseJZhong Aug 7, 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.

but it we don't do this, if someone run uneven inference when dense SP on, spmd_types will error out. It's not able to turn R -> S(1) due to unevenness. We need to set enable_sp in Compilation Config for vllm model runner to pad.

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.

if someone run uneven inference when dense SP on

why would they

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.

you can't control what users would do? why leaving SP + unevenness buggy when we can fix it?

however I admit at this point no user would try this, so doesn't matter.

[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Aug 7, 2026
ghstack-source-id: ba3fcbd
Pull-Request: #4080
[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Aug 7, 2026
ghstack-source-id: 0fa1079
Pull-Request: #4080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl 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.

2 participants