feat(moe): EP experts forward收纳到kernel底下实现多impls管理,并且添加 NPU grouped matmul的forward分支。#252
Open
werwrewe wants to merge 1 commit into
Open
feat(moe): EP experts forward收纳到kernel底下实现多impls管理,并且添加 NPU grouped matmul的forward分支。#252werwrewe wants to merge 1 commit into
werwrewe wants to merge 1 commit into
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
kevssim
reviewed
Jul 23, 2026
| # observed in practice as garbage split sizes. Force a device sync before | ||
| # reading gathered results back on the host. | ||
| if num_local_tokens_per_expert.device.type == 'npu': | ||
| torch.npu.synchronize() |
Collaborator
There was a problem hiding this comment.
最好使用平台无关的封装:
from twinkle import torch_util
torch_util.synchronize()
kevssim
reviewed
Jul 23, 2026
| # all-to-all, causing EP collective order divergence. | ||
| return permuted_tokens | ||
|
|
||
| if _ep_experts_can_use_npu_gmm(self): |
Collaborator
There was a problem hiding this comment.
更好的做法是把gmm定义成一个接口,有不同的impl,然后在expert_parallel.py中直接调用接口,隐藏impl细节。
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.
kernelize 的 NPU patch 无法生效,导致NPU forward被ep forward覆盖。考虑在ep forward中单独给NPU提供forward。ep forward原实现逐 expert Python 循环,在 EP 闭包内部复用现有 NPU 组件(GmmFunction + npu_swiglu + _get_cached_expert_weights)替换循环实现并行化。每次前向做资格检查,不满足条件自动回退原循环并打印一次 WARNING 说明原因。
端到端验证: loss 曲线与原实现一致,使用ep_fsdp2_lora_qwen3_5_moe.sh 设备2*910B 模型qwen3.5-35B-A3B 每 12 step 约 200s -> 60s。
二编:
改动代码结构,原有EP experts forward也收纳到kernel底下ops里面并且实现多impls管理。测试两种ep forward分支(NPU和逐expert循环)都能跑通,使用ep_fsdp2_lora_qwen3_5_moe.sh 设备2*910B batch8 模型qwen3.5-35B-A3B 16steps NPU时间185s,逐expert循环393s。