Repository navigation
Add MoE token permute/reorder kernels - #711
Merged
Merged
Conversation
AkshitaB
force-pushed
the
akshitab/moe-scaled-grouped-mm
branch
from
June 9, 2026 01:05
a175224 to
fc2e3fe
Compare
AkshitaB
force-pushed
the
akshitab/moe-permute-reorder
branch
from
June 9, 2026 01:05
590b903 to
6149204
Compare
AkshitaB
force-pushed
the
akshitab/moe-scaled-grouped-mm
branch
from
June 9, 2026 05:16
fc2e3fe to
8e754fa
Compare
AkshitaB
force-pushed
the
akshitab/moe-permute-reorder
branch
from
June 9, 2026 05:16
6149204 to
23fa8cc
Compare
AkshitaB
force-pushed
the
akshitab/moe-scaled-grouped-mm
branch
from
June 9, 2026 05:25
8e754fa to
a55fdcc
Compare
AkshitaB
force-pushed
the
akshitab/moe-permute-reorder
branch
from
June 9, 2026 05:25
23fa8cc to
ee8ffee
Compare
AkshitaB
force-pushed
the
akshitab/moe-scaled-grouped-mm
branch
from
June 9, 2026 05:29
a55fdcc to
b241adc
Compare
AkshitaB
force-pushed
the
akshitab/moe-permute-reorder
branch
from
June 9, 2026 05:29
ee8ffee to
e76dd17
Compare
AkshitaB
force-pushed
the
akshitab/moe-scaled-grouped-mm
branch
from
June 9, 2026 05:45
b241adc to
8a28d7f
Compare
AkshitaB
force-pushed
the
akshitab/moe-permute-reorder
branch
2 times, most recently
from
June 9, 2026 06:25
52b51f8 to
f8a2371
Compare
Base automatically changed from
akshitab/moe-scaled-grouped-mm
to
akshitab/moe-v2-core
June 9, 2026 06:37
Three CUDA-backed kernels used to reshape token batches around the routing path:
* moe_chunk_reorder - moe_chunk_permute / moe_chunk_unpermute: reorder tokens
between chunked layouts (e.g., grouping tokens by expert).
* moe_permute_drop - moe_permute_drop_fwd: fused permute-and-drop for tokens
over per-expert capacity.
* moe_unpermute_bwd - backward pass that restores the original token order.
Each module ships its .cpp/.cu sources and loads the extension lazily via
load_cuda_extension, so the wrappers are import-safe on CPU.
Co-Authored-By: Akshita Bhagia <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
AkshitaB
force-pushed
the
akshitab/moe-permute-reorder
branch
from
June 9, 2026 06:38
f8a2371 to
eb25f6a
Compare
Document the public entry points (moe_chunk_permute, moe_chunk_unpermute, moe_permute_drop_fwd, moe_unpermute_bwd) and declare __all__ at the submodule level, matching the rest of the kernels package. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…9 lane The .cu kernel extensions JIT-build with nvcc, which the existing GPU images lack, so those tests fail with "CUDA_HOME not set". Skip src/test/kernels on the torch 2.9 "Test (GPU)" job and add a trial job on tianhuat/olmo-core-torch210-2404-cu128, which ships the CUDA toolkit. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Each kernel module had its own _load_cuda_extension() with duplicated module-global caching and build/error-wrapping boilerplate. Add a LazyCudaExtension helper in cuda_extension_utils that memoizes the build, caches and re-raises (chained) build errors, and resolves sources relative to the kernels/cuda directory. Convert grouped_mm and the permute/reorder kernels to a small LazyCudaExtension config plus a thin wrapper. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Point the torch 2.10 MoE-kernels job at tianhuat/olmo-core-torch210-2404-cu128, which ships the CUDA toolkit (nvcc) needed to JIT-build the .cu kernel extensions, and drop the separate trial job. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
CUDA + Triton/torch MoE token permute, reorder, and unpermute-backward kernels used to route tokens to experts and gather their outputs:
kernels/moe_chunk_reorder.py— chunked permute/unpermute by row-id map, with caller-providedout=/backward-grad buffers for comm-buffer reuse.kernels/moe_permute_drop.py— fused permute-with-drop.kernels/moe_unpermute_bwd.py— unpermute backward kernel.kernels/cuda/*— the C++/CUDA sources, built lazily via the JIT extension loader.The Python wrappers are CPU-import-safe; the CUDA path builds lazily on first use.
Testing
src/test/kernels/moe_chunk_reorder_test.py— CPU reference-path tests for the torch chunk permute/unpermute (out-of-range row zeroing,out=buffer honoring).src/test/kernels/moe_unpermute_bwd_test.py— GPU test (@requires_gpu) checking the unpermute-backward kernel matches an autograd reference with anout=buffer.make checkspasses; CPU tests pass locally; the GPU test skips cleanly without a GPU.