ElasticBuffer silently accepts mismatched cross-rank geometry, then fails with an opaque CUDA assert
Summary
ElasticBuffer requires every rank in the EP group to agree on the buffer
contract. num_max_tokens_per_rank, hidden, num_topk, use_fp8_dispatch,
allow_hybrid_mode, and allow_multiple_reduction all feed
calculate_elastic_buffer_size, and peers must allocate geometrically
identical buffers for the dispatch/combine kernels to address each other
correctly.
Today __init__ accepts these per-rank values silently. A caller doing
padding-free / variable-length MoE (e.g. multimodal packing, where every rank
sees a different number of tokens) naturally derives num_max_tokens_per_rank
from the local token count, so each rank ends up with a different geometry.
The mismatch does not surface at construction time; it appears much later
inside the kernels as an opaque CUDA assertion:
dispatch_copy_epilogue.cuh:107
ptx::deduplicate(dst_expert_idx, lane_idx) or dst_expert_idx == -1
Reproduction
Two-rank EP, with num_max_tokens_per_rank derived from the per-rank local
token count (the padding-free mistake):
num_max_tokens_per_rank = 4096 + rank # rank 0 -> 4096, rank 1 -> 4097
buffer = deep_ep.ElasticBuffer(
group,
num_max_tokens_per_rank=num_max_tokens_per_rank,
hidden=4096,
num_topk=8,
allow_hybrid_mode=False, # single-node NVLink-only
explicitly_destroy=True,
)
Before the fix this constructs silently; the crash shows up later in the dispatch/combine kernel as the assertion above.
Expected behavior
Construction should fail immediately with an actionable ValueError that names
the mismatched parameter and the diverging ranks/values — e.g.
num_max_tokens_per_rank: rank 0 has 4096, rank 1 has 4097 — with a hint to use
a group-wide capacity instead of per-rank local counts.
Proposed fix
__init__ is already collective (it ends in a group.barrier()), so a single
extra all_gather_object at construction time is safe and negligible. Gather
the geometry tuple across the group and raise the ValueError above on any
mismatch. When num_bytes is supplied directly, validate (num_bytes, num_cpu_bytes) instead of the MoE settings.
A patch implementing this is ready; I can open a PR if this is welcome.
Impact
A simple, natural mistake (deriving capacity from local token counts in variable-length / padding-free training) silently corrupts the collective and fails much later with an error that gives no hint of the actual cause. This is very hard to debug in a large MoE run.
@YYuJLiu I saw this issue and opened #810 for it. Sorry, I didn't see that you wanted to open a PR yourself. Let me know if you'd like me to close mine so you can open yours.
Thanks a lot for jumping on this — and for the very kind offer! Since you asked: I do have the patch ready (the all_gather_object validation sketched in the issue, plus host-only tests for the mismatch cases), so I'd be glad to open the PR myself — I've just opened #811. Please feel free to close yours in favor of it, and I'd genuinely welcome your review — your test coverage pointed at exactly the right cases. I'll also add multi-rank NVLink coverage on real Hopper/Blackwell hardware for the actual EPBuffer construction path, which was the gap we both flagged.
For sure, no problem :) Thanks for the heads up. I closed #810 and will take a look at #811.