mirror of
https://github.com/deepseek-ai/DeepGEMM.git
synced 2026-11-05 00:47:26 +00:00
[GH-ISSUE #410] [RFC] Chunk-ready symmetric-buffer protocol for streaming MegaMoE inputs #186
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/DeepGEMM#186
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @0z5a on GitHub (Aug 17, 2026).
Original GitHub issue: https://github.com/deepseek-ai/DeepGEMM/issues/410
Summary
I would like to discuss an opt-in, chunk-ready producer/consumer protocol for MegaMoE's symmetric input buffer.
Today the caller fills the full
x,x_sf,topk_idx, andtopk_weightsranges before callingfp8_fp4_mega_moe. The mega-kernel overlaps dispatch, expert compute, and combine internally, but this whole-batch handoff prevents the router/TopK/input-layout producers from overlapping with dispatch of earlier token chunks.The proposed direction is a fixed-capacity ring of token chunks. Producers publish routing and activation-layout readiness with generation counters; MegaMoE consumes ready chunks and publishes safe reuse. This is an RFC rather than a performance claim: the protocol, progress guarantees, and incremental expert scheduling need agreement before implementation.
Motivation
The current public flow is effectively:
The desired overlap is within one MoE layer, across token chunks:
chunkhere means a token micro-batch within the same MoE invocation, not a transformer layer. This proposal does not try to pipeline across layer dependencies.The current SM100 dispatch path also performs whole-invocation expert counting, a grid sync, and a cross-rank barrier before pulling token data. Therefore this cannot be implemented correctly by adding one
readyflag around the existing kernel. It requires an explicit chunk-aware counting/scheduling contract.Proposed protocol
This is a non-binding sketch intended to make the correctness questions concrete.
Fixed-capacity ring
Allocate the front-end staging area statically with:
num_slotstokens_per_slotx,x_sf,topk_idx, andtopk_weightsAll allocation and shapes remain fixed so the path can be captured and replayed by CUDA Graphs. There should be no allocation or shape-dependent host work during replay.
Independent readiness generations
Routing and activation layout can finish in either order, so a single ordered enum is awkward. For source rank
r, slots, and expected generationg, use independent monotonic generations:The consumer may read a slot only after both ready generations match
g. The producer may reuse it forg + ring_sizeonly after the required consumer acknowledgements are complete.An
(epoch, sequence)value, or a sufficiently wide monotonic sequence, should prevent ABA across ring wrap and CUDA Graph replay.Memory ordering
For each ready generation:
Slot reuse needs the reverse handoff: consumers finish all reads, publish completion with release semantics, and the owner observes completion with acquire semantics before overwriting the slot.
For the first implementation, reuse could conservatively wait until the chunk's combine is complete. If the kernel can prove that no slot-resident payload or metadata is referenced after all remote pulls, an earlier
input_consumedacknowledgement could be a later optimization.Because a source chunk may feed several destination ranks,
consumed_genprobably needs either per-rank acknowledgements or a collective/bitmask completion rule. The exact primitive should reuse DeepGEMM's existing NVLink barrier and acquire/release conventions where possible.Chunk-aware dispatch scheduling
The dispatch side needs to replace the whole-invocation count/sync barrier with one of these (or another maintainer-preferred design):
The second option may preserve packing efficiency, but it needs a precise rule for when an expert block is complete and may be consumed by L1. In both cases, source metadata must include the logical token index so combine writes back to the original output position.
Consumers can initially wait for all source ranks' routing/layout readiness for generation
g. Processing source ranks independently could be a later optimization; it should not be required by the first protocol.Progress and deadlock requirements
A persistent consumer must not occupy all SM resources while spinning on data that can only be produced by kernels that have not run yet. A streamed path therefore needs an explicit progress mechanism, for example:
Correctness must not depend on overlap actually occurring. Serialized execution should remain valid, and a slow or empty source rank must not deadlock other ranks.
API direction
I suggest keeping the current batch-ready API unchanged and adding an opt-in streamed mode. Conceptually:
The actual publish operations should be device-side; the Python sketch only shows allocation and invocation. A device-visible descriptor could carry slot strides, metadata pointers, expected generation, total tokens, and the number of valid chunks.
The existing full-batch path should remain the default and a correctness fallback.
Suggested implementation slices
These should be separate PRs rather than one large change.
Validation plan
I do not have a B200/NVSwitch performance result for this protocol yet; this RFC is meant to agree on the interface and correctness model first.
Non-goals
Related work
Questions for maintainers
SymmBuffer, or should the caller own the ring metadata and pass a descriptor to MegaMoE?route_ready_genandlayout_ready_gencounters a reasonable contract, or would one combined publish point be preferable?If the direction is acceptable, I can start with the protocol/allocation slice and keep the existing path untouched.
@200lz commented on GitHub (Aug 24, 2026):
I’m interested in working on the correctness side of the first slice. Rather than changing the MegaMoE dispatch path initially, I’d like to prototype/test the ring generation state machine, including repeated wraparound, independent route/layout publication order, delayed consumers, and CUDA Graph replay. This could either become part of the protocol/allocation PR or a separate test-focused PR. I’ll keep the existing batch-ready path untouched.