Repository navigation
Conversation
Resolved conflicts with `git merge-file`; change set unchanged. Signed-off-by: li-lizhe <147392333@qq.com>
li-lizhe
force-pushed
the
fix/dlinfer-moe-expert-ids-device
branch
from
October 22, 2026 22:32
c129b5d to
8fae3fd
Compare
Contributor
Author
|
Gentle ping on this one — it's been quiet for 7 days since the last activity, so I wanted to check whether there's anything else you'd like me to adjust or add before this can move forward. Happy to make changes if so. Thanks! |
This branch has not been deployed
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.
Motivation
DlinferFusedMoEImpl.__init__builds the expert-id map of the current rank with a hardcoded CUDAdevice index:
This backend (
lmdeploy/pytorch/backends/dlinfer/) is the one that serves the non-CUDAaccelerators (Ascend NPU, MACA, Cambricon), where
torch.cuda.current_device()raisesAssertionError: Torch not compiled with CUDA enabled. As a result, building any fused-MoE layerwith
ep_size > 1aborts during construction, before the first forward.Modification
Build the map lazily, on the device of the first input tensor, through a small helper:
self.expert_ids_per_ep_rankis no longer created in__init__; the new_get_expert_ids_per_ep_rank(device)builds it on the given device and caches it (it is rebuiltonly when the device changes).
DlinferFusedMoEImpl.forwardandDlinferFusedMoEW8A8Impl.forwardattach the map fromhidden_states.deviceinstead of the value frozen at construction time.CUDA behaviour is unchanged: the same tensor with the same contents ends up on the same device, it
is just created from the input device instead of from a CUDA device index.
BC-breaking (Optional)
None.
Verification
Ascend NPU (Ascend 910,
torch 2.15.0.dev20260917+cpu+torch_npu 2.15.0.dev20260917+gitec69335,torch.cuda.is_available() == False), with the class body of this file executed verbatim (thecontainer has no
dlinfer/ lmdeploy install, so the dlinfer op wrappers and the base spec classeswere stubbed; only the file under change is real):
Before:
After:
Not tested: an end-to-end MoE model with EP on Ascend (no
dlinferwheel available on thatmachine), and the CUDA / MACA / Cambricon paths — the change is device-agnostic and keeps the
previous CUDA device (
hidden_states.deviceis the current CUDA device there).