Skip to content

Fix MoE permutation on gfx1250 w/ Triton 3.8, faster row_id_map - #791

Open
matthiasdiener wants to merge 3 commits into
devfrom
mdiener/gfx1250-moe-permute
Open

matthiasdiener wants to merge 3 commits into
devfrom
mdiener/gfx1250-moe-permute

Conversation

@matthiasdiener

@matthiasdiener matthiasdiener commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

Triton 3.8 miscompiles MoE permutation on gfx1250 for multi-warp kernels that apply both tl.cumsum and a reduction to the same block. Triton 3.9 fixes that miscompilation, but the code is slow on both versions (as well as on gfx950).

  • Token-major row_id_map (all AMD GPUs): three new kernels count each expert's tokens per block of tokens, prefix-sum the counts over blocks, then write each block's rows. They read whole token rows, need no sort, and none of them both scans and reduces a block. The row_id_map format is unchanged.
  • gfx1250 only: unpermute_with_mask_map unpermutes the probs in a kernel of their own (_unpermute_probs_kernel) instead of in the first hidden blocks of _unpermute_kernel. Other GPUs keep the fused kernel.

Performance results: https://github.com/AMD-ROCm-Internal/frameworks-internal/issues/395#issue-6169144290

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Change A
  • Change B

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@matthiasdiener matthiasdiener self-assigned this Nov 2, 2026
@matthiasdiener matthiasdiener added the ci-level 1 CI test level 1 label Nov 2, 2026
@matthiasdiener
matthiasdiener force-pushed the mdiener/gfx1250-moe-permute branch from a0e5a61 to c6b49d4 Compare November 2, 2026 21:50
@matthiasdiener matthiasdiener changed the title Fix MoE permutation on gfx1250 w/ Triton 3.8, faster row_id_map on all GPUs Fix MoE permutation on gfx1250 w/ Triton 3.8, faster row_id_map Nov 2, 2026
@matthiasdiener
matthiasdiener marked this pull request as ready for review November 2, 2026 23:09

# The row_id_map from token-major passes over the routing map: block counts per expert, their
# prefix sums, then each block's rows. Triton 3.8 on gfx1250 miscompiles multi-warp kernels that
# both scan and reduce a block, as _row_id_map_pass_1_kernel does, so none of these does both.

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.

Maybe add Triton ticket so it is easier to track

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

Labels

ci-level 1 CI test level 1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants