hybrid unordered kernels: guard token_map_at_dispatch bit packing at JIT time - #12
Open
Xuan-1998 wants to merge 1 commit into
Open
Conversation
`pack_combine_recv_addr` in `combine_utils.cuh` packs rank/slot/channel
into 5/14/12 bits by shifting and ORing without any mask. Callers pass
unchecked ints:
- `hybrid_dispatch_unordered.cuh` writes the packed word into
`token_map_at_dispatch[token][k]`
- `hybrid_combine_unordered.cuh` reads it back and asserts only that
the channel bits match the channel it is running on
If `slot` exceeds 16383 (its 14-bit field) it bleeds into the rank
field at bit 26; the channel bits stay intact so the runtime
`EP_DEVICE_ASSERT(channel == channel_idx)` still passes. The result is
a misrouted combine partial with no visible failure, or a hang in the
arrival-count wait when the corrupted rank never sends.
Slot is `combine_slot`, bounded by `kNumMaxTokensPerChannel * kNumTopk`.
For a large `kNumMaxTokensPerRank` with few channels and topk >= 8
this can exceed 16383. rank and channel have the same silent-overflow
shape at 32 / 4096. All three bounds are compile-time constants on
the two kernel templates, so `EP_STATIC_ASSERT` at the top of each
kernel body catches the bad instantiation at NVRTC JIT time with a
clear message that names the offending template parameter, instead
of at runtime with a misrouted put.
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.
The bug
pack_combine_recv_addrindeep_ep/include/deep_ep/impls/combine_utils.cuh:38-40packs(rank, slot, channel)into an int32 by shifting into 5/14/12 bit fields with no runtime mask:Callers pass unchecked ints:
hybrid_dispatch_unordered.cuh:704writes the packed word intotoken_map_at_dispatch[token][k].hybrid_combine_unordered.cuh:719reads it back and asserts onlychannel == channel_idx(the low 12 bits).If
slotexceeds its 14-bit field (16383), its high bits bleed into the rank field at bit 26.channel_idxstays intact, so the runtimeEP_DEVICE_ASSERT(channel == channel_idx)athybrid_combine_unordered.cuh:722still passes. The kernel then routes the partial to a wrong scale-out rank and either misdirects the reduction or hangs in the arrival-count wait at:752-767because the corrupted rank never sends.Slot is
combine_slot, bounded bykNumMaxTokensPerChannel * kNumTopk. Bothrank(bounded bykNumScaleoutRanks, 5-bit field) andchannel(bounded bykNumChannels, 12-bit field) have the same silent-overflow shape at 32 / 4096.The fix
Instantiations of the two hybrid unordered kernels have all three bounds as compile-time constants. Add
EP_STATIC_ASSERTs at the top of each kernel body, so an out-of-range template combination fails to instantiate at NVRTC JIT compile time (percsrc/kernels/elastic/dispatch.hpp:108) with a message that names the offending parameter — instead of a silent misrouted put at runtime.Diff
deep_ep/include/deep_ep/impls/combine_utils.cuh: a 6-line comment abovepack_combine_recv_addrdocumenting the caller contract and pointing at the enforcing sites.deep_ep/include/deep_ep/impls/hybrid_dispatch_unordered.cuh: threeEP_STATIC_ASSERTs at the top ofhybrid_unordered_dispatch_impl(line 180 area).deep_ep/include/deep_ep/impls/hybrid_combine_unordered.cuh: same threeEP_STATIC_ASSERTs at the top ofhybrid_unordered_combine_impl(line 59 area).No runtime path change. Total 35 lines added.
Verification
nvcc -std=c++17 -arch=sm_90 -cagainst the realnccl.h: passes.AI disclosure
Found and drafted with Claude Code. Every claim above was verified against source line by line before I opened the PR.