mirror of
https://github.com/deepseek-ai/DeepEP.git
synced 2026-11-05 00:47:32 +00:00
[PR #800] Support optional topk_weights in the reference dispatch #794
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/DeepEP#794
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?
📋 Pull Request Information
Original PR: https://github.com/deepseek-ai/DeepEP/pull/800
Author: @lsyx6399
Created: 10/27/2026
Status: 🔄 Open
Base:
main← Head:fix/refs-dispatch-optional-topk-weights📝 Commits (1)
767af27Support optionaltopk_weightsin the reference dispatch📊 Changes
3 files changed (+219 additions, -6 deletions)
View changed files
📝
deep_ep/utils/refs.py(+7 -6)➕
tests/utils/_run_refs_test.py(+121 -0)➕
tests/utils/test_refs.py(+91 -0)📄 Description
Problem
The real
EPBuffer.dispatch(deep_ep/buffers/ep.py) already supports optional top-k weights:The pure-torch reference implementation in
deep_ep/utils/refs.pydid not match this contract:dispatchassumedtopk_weightswas always present (it calledtopk_weights[...],torch.cat(..., topk_weights.dtype), anddist.all_to_all_single(recv_topk_weights, ...)unconditionally), so passingtopk_weights=None— a documented, supported input of the real kernel — raisedAttributeError: 'NoneType' object has no attribute ....This left the optional-weights path:
weights=Nonecase), andtests/ep/test_ep.pyalways generatestopk_weightsviatorch.topk, neverNone).The stale
# TODO: make top-k weight fully optionalinrefs.pyconfirms this was a known gap.Fix
Align the reference with the real kernel:
topk_weights is None, skip the weights send/recv and returnrecv_topk_weights=None.recv_topk_weights is None when topk_weights is not provided, matchingep.py's wording.# TODO: make top-k weight fully optional.combine/generate_pre_combine_data/ordered_accumulateare unchanged — they don't carry weights.Tests
Added
tests/utils/test_refs.py(+ workertests/utils/_run_refs_test.py): a 2-rankgloogroup on CPU, with no compileddeep_ep._C, NCCL, GPU, or NPU required.refsviaimportlibwith the package-leveldeep_ep._C/ NCCL / JIT init stubbed, so it runs anywhere.subprocess.Popen) since gloo collectives block until every rank joins.Cases verified:
recv_topk_weights is Nonewhentopk_weights=None.recv_x,recv_topk_idx,recv_src_token_idx,num_recv_tokens_per_rankall match.recv_topk_weightshas the expected shape.use_fp8 = isinstance(x, tuple)path) +weights=Nonestill exchanges the SF tensor correctly. (Real FP8 dtypes need a GPU; here both tuple members arefloat32so gloo can exchange them, exercising the same SF branch on CPU.)Verified: the test passes on this fix and fails on the pre-fix
refs.py(the worker raisesAttributeErrorand emits noRESULTline), confirming the test exercises the gap.Behavior impact
topk_weights=Nonepath changes (previously crashed, now returnsNoneweights as the real kernel does).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.