Add MoEDispatcher for expert-parallel token dispatch/combine#492
Closed
Add MoEDispatcher for expert-parallel token dispatch/combine#492
Conversation
Promotes the dispatch/combine kernels from examples/31_expert_sharded_moe/ into iris/ccl/ as a production MoEDispatcher class with pre-allocated buffers and a handle-based API. Dispatch routes tokens to expert-owning ranks via direct iris.store scatter; combine sends results back with masked reduction. New files: - iris/ccl/moe_utils.py: ExptAssignment, RaggedTensorMetadata, topk, BitmatrixMetadata, and masked reduce kernel - iris/ccl/moe_dispatch.py: MoEDispatcher, DispatchHandle, MoEDispatchConfig, and the Triton dispatch/combine kernels - tests/ccl/test_moe_dispatch.py: E2E, dispatch-only, combine-only, buffer reuse, topk=1, and handle immutability tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Pre-allocated dispatch/combine buffers were hardcoded to bfloat16, causing Triton compilation errors when used with float32 inputs (tl.dot operand type mismatch). Now accepts a dtype parameter (default: bfloat16) that controls buffer allocation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Benchmarks iris MoEDispatcher (direct iris.store scatter) against a naive approach using torch.distributed.all_gather + host-side sorting across various batch sizes, hidden dims, and topk values. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ruff F821 flagged `dispatcher` as undefined in a lambda inside a loop. Convert to a def with default args to eagerly bind the loop variable. Also apply ruff auto-fixes (unused `time` import, f-strings without placeholders). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
examples/31_expert_sharded_moe/to productioniris.cclmoduleMoEDispatcherclass with pre-allocated buffers and handle-based API (dispatch()→combine())moe_utils.pywith routing helpers (ExptAssignment, RaggedTensorMetadata, topk, reduce)ctx.ccl.moe_dispatcher()factory methodKey Design
iris.store()scatter — no AllToAll/AllToAllv; sparse per-token routing via symmetric heap__init__— dispatch, combine, all-gather routing buffers allocated oncedispatch()returns opaqueDispatchHandleconsumed bycombine()_convert_dp_to_epand_convert_ep_to_dpare identical to the examplePerformance (iris vs naive all_to_all)
iris shows near-constant latency, winning at T_local >= 48 tokens/rank with up to 8.8x speedup.
Full performance study: https://gist.github.com/mawad-amd/c43c02e3662a180a88e26faa31c62f52
Test plan
🤖 Generated with Claude Code