Skip to content

Remove self.topk in ReordererSequenceParallel to prevent mutation - #1873

Merged
tianyu-l merged 4 commits into
pytorch:mainfrom
wmhst7:mingheng/mutate_topk
Oct 15, 2025
Merged

tianyu-l merged 4 commits into
pytorch:mainfrom
wmhst7:mingheng/mutate_topk

Conversation

@wmhst7

@wmhst7 wmhst7 commented Oct 14, 2025

Copy link
Copy Markdown
Contributor

See #1806 (comment)
This PR prevents mutation of ReordererSequenceParallel. Because torch.utils.checkpoint.checkpoint is a HOP and has such constraint.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 14, 2025
local_rank = device_mesh.get_local_rank()
# fact: top_scores.shape[0] // self.top_k = batch_size * seq_len // ep_degree
token_indices_experts_sorted += top_scores.shape[0] // self.top_k * local_rank
token_indices_experts_sorted += top_scores.shape[0] // mod.top_k * local_rank

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 you please add a raise ValueError if mod doesn't have top_k attribute, with meaningful error message?

@tianyu-l tianyu-l left a comment •

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.

LGTM, thanks!

Please fix lint.

@tianyu-l
tianyu-l merged commit 4faff04 into pytorch:main Oct 15, 2025
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
…torch#1873)

See
pytorch#1806 (comment)
This PR prevents mutation of ReordererSequenceParallel. Because
torch.utils.checkpoint.checkpoint is a HOP and has such constraint.

---------

Co-authored-by: mingheng.w <[email protected]>
Co-authored-by: tianyu-l <[email protected]>
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
…torch#1873)

See
pytorch#1806 (comment)
This PR prevents mutation of ReordererSequenceParallel. Because
torch.utils.checkpoint.checkpoint is a HOP and has such constraint.

---------

Co-authored-by: mingheng.w <[email protected]>
Co-authored-by: tianyu-l <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

ReordererSequenceParallel (ETP=1) doesn't work with torch.compile + AC

2 participants