Skip to content

Support ragged_sort_use_single_sparsecore flag to restrict token sorting to 1 SparseCore#4513

Open
Shuwen-Fang wants to merge 1 commit into
AI-Hypercomputer:mainfrom
Shuwen-Fang:sort_one_sparsecore
Open

Support ragged_sort_use_single_sparsecore flag to restrict token sorting to 1 SparseCore#4513
Shuwen-Fang wants to merge 1 commit into
AI-Hypercomputer:mainfrom
Shuwen-Fang:sort_one_sparsecore

Conversation

@Shuwen-Fang

@Shuwen-Fang Shuwen-Fang commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Motivation

If token sorting is on both sparsecores, sometimes it interferes with FSDP all gather scheduling and prevent it from overlapping (e.g. custom Qwen model).
We can update the sorting kernels to schedule token sorting on one sparsecore only. This can make sorting slightly longer, but will enable FSDP all gathers to overlap better.

XProf Traces

bug: b/525027581

Checklist

  • I have performed a self-review of my code.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed.

…ing to 1 SparseCore

Motivation:
If token sorting is on both sparsecores, sometimes it interferes with FSDP all gather scheduling and prevent it from overlapping (e.g. custom Qwen model).
We can update the sorting kernels to schedule token sorting on one sparsecore only. This can make sorting slightly longer, but will enable FSDP all gathers to overlap better.

XProf Traces:
- Baseline (2 SparseCores): https://xprof.corp.google.com/?session_id=shuwenf-12635063694751230364
- Single SparseCore (ragged_sort_use_single_sparsecore=True): https://xprof.corp.google.com/?session_id=shuwenf-7290787811420351875
@Shuwen-Fang
Shuwen-Fang force-pushed the sort_one_sparsecore branch from 16ebffc to 87453fe Compare July 17, 2026 00:20
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/maxtext/layers/moe.py 90.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@gobbleturk gobbleturk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Either in this PR or as a followup we may want more flexibility - choosing number of SC individually of fwd combine, fwd dispatch, bwd combine, bwd dispatch

Comment thread tests/unit/moe_test.py
)

@pytest.mark.tpu_only
def test_ragged_sort_single_sparsecore(self):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why not use the self._run_ragged_sort_loss_and_grad function, which already implemented the correctness checks

@NuojCheng NuojCheng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You might need to implement the same thing for ragged gather reduce v2 kernel, https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/kernels/ragged/ragged_gather_reduce_v2.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants