Closed
[Bug-Report|缺陷反馈]: aclnnMoeUpdateExpert 在 balanceMode=0 且 F < worldSize+1 时按资料允许的 F 配置读越界,输出被写成 0 #7597
liuhanwen8Add on 13 days agoClosed at 23 hours ago
13 days ago Added label: bug-report
周云飞
13 days ago Comments:
13 days ago Comments:
感谢反馈。按您提供的索引计算,balanceMode=0 且 count=worldSize 时,rankId 最大可达 worldSize;若 F 不足,可能读到其他行甚至表外数据。您报告的 F=3 和 F=2 结果分别符合这两种情况,但具体实现和资料约束仍需进一步核实。
临时规避可将 F 设为 worldSize+1,并为每行填入与实际 count 对应的有效实例号。处理方向上,可以评估在 balanceMode=0 时增加列数校验,或按实际访问范围检查;前者可能限制原本可用的较小 F,后者需要确认 tiling 阶段能否取得 count。资料中的列数与实例号要求也需要一并核对,错误码 561002 是否适用尚待确认。


12 days ago Assign weixin_49300047 as responsible person
3 days ago Assign Yuyu-Li as responsible person
3 days ago Removed responsible person weixin_49300047
3 days ago Associated pull request
1 day ago Assign SuperYuan as responsible person
1 day ago Associated pull request
23 hours ago Close issue
23 hours ago changed custom state from 待办的 to 已完成
21 hours ago Added label: resolved
现象
aclnnMoeUpdateExpert资料把eplbTable列数F声明为[2, worldSize+1],即F=2是合法配置。但
balanceMode=0分支要求能读到flat[off + rankId],rankId上界是worldSize:op_kernel/moe_update_expert.h:192-195:modeValue = Ceil(worldSize, count);rankId = localRankId/modeValue + 1(≤worldSize);flat[tableOffset + rankId]op_host/op_tiling/moe_update_expert_tiling.cpp:394-398:只校验1 < F <= worldSize+1,不校验
F-1 >= max(rankId) = worldSize当
count == worldSize时modeValue = 1、rankId最大取到worldSize,于是需要
F >= worldSize+1;而资料允许F=2⇒ 读越过整张表。实测(
worldSize=8、localRankId=7、eplbTable第 0 行count=8、其余行实例号全为999):[:,0]108(=100+8,合法)0(实为下一行 count 列)0(垃圾)放大验证:
BS=512, K=16, F=2, count=8, rank=7→ 输出唯一值[0],而合法实例号是999。期望
二选一(任一即可自洽):
balanceMode=0时 tiling 补F - 1 >= max(rankId) = worldSize(即F >= worldSize+1),不满足返回 561002;或
2改为worldSize + 1,并说明count == worldSize时的实例号数量要求。环境
Ascend950PR_957c,8 卡机,用 NPU6);Ubuntu 24.04 / kernel 6.8 / 驱动 25.7.rc1Ascend-cann-950算子包,2026-11-11 构建)cann/ops-transformermastera1e54cce(2026-11-14),mc2/moe_update_expert复现步骤
source ${ASCEND_HOME_PATH}/set_env.sh;ASCEND_RT_VISIBLE_DEVICES=6g++ -O2 -std=c++17 probe_mue_oob.cpp -o probe_mue_oob -I${ASCEND_HOME_PATH}/include -I${ASCEND_HOME_PATH}/include/aclnnop -L${ASCEND_HOME_PATH}/lib64 -lascendcl -lnnopbase -lopapi -lpthread./probe_mue_oob,观察 F=9 / F=3 / F=2 三档的rc1/rc2与col0e[0]改成1(modeValue=8、rankId=1),此时 F=3 不越界,输出应为101复现脚本
#include <cstdio> #include <cstdint> #include <vector> #include "acl/acl.h" #include "aclnnop/aclnn_moe_update_expert.h" template <typename T> static aclTensor* Make(const std::vector<T>& h, std::vector<int64_t> sh, void** d, aclDataType dt) { int64_t n = 1; for (auto v : sh) n *= v; size_t b = n * sizeof(T); aclrtMalloc(d, b, ACL_MEM_MALLOC_HUGE_FIRST); aclrtMemcpy(*d, b, h.data(), b, ACL_MEMCPY_HOST_TO_DEVICE); std::vector<int64_t> st(sh.size(), 1); for (int64_t i = (int64_t)sh.size() - 2; i >= 0; --i) st[i] = st[i+1] * sh[i+1]; return aclCreateTensor(sh.data(), sh.size(), dt, st.data(), 0, ACL_FORMAT_ND, sh.data(), sh.size(), *d); } // F 可变;count=8 = worldSize,使 modeValue=1、rankId=8(rank=7) static void Run(int F) { const int BS = 8, K = 2, MOE = 3, RANK = 7, WS = 8; std::vector<int32_t> ids(BS * K, 0); // 全部指向第 0 行 std::vector<int32_t> e(MOE * F, 0); e[0] = 8; // count = worldSize → modeValue = 1 for (int c = 1; c < F; ++c) e[c] = 100 + c; for (int r = 1; r < MOE; ++r) { e[r*F] = 1; e[r*F+1] = 999; } std::vector<int32_t> oi(BS*K, 0); std::vector<uint8_t> om(BS*K, 0); void *di=0,*de=0,*d1=0,*d2=0; aclTensor *ti=Make(ids,{BS,K},&di,ACL_INT32), *te=Make(e,{MOE,F},&de,ACL_INT32); aclTensor *t1=Make(oi,{BS,K},&d1,ACL_INT32), *t2=Make(om,{BS,K},&d2,ACL_BOOL); uint64_t ws=0; aclOpExecutor* ex=nullptr; auto r1 = aclnnMoeUpdateExpertGetWorkspaceSize(ti,te,nullptr,nullptr,nullptr, RANK,WS,0,t1,t2,&ws,&ex); printf("F=%-2d read=flat[%d] last=flat[%d] oob=%d ", F, 0*F+RANK+1, MOE*F-1, (0*F+RANK+1) > (MOE*F-1)); if (r1) { printf("rc1=%d (rejected)\n", (int)r1); return; } void* w=nullptr; if (ws) aclrtMalloc(&w, ws, ACL_MEM_MALLOC_HUGE_FIRST); aclrtStream s=nullptr; aclrtCreateStream(&s); auto r2 = aclnnMoeUpdateExpert(w, ws, ex, s); aclrtSynchronizeStream(s); std::vector<int32_t> g(BS*K,-1); aclrtMemcpy(g.data(), BS*K*4, d1, BS*K*4, ACL_MEMCPY_DEVICE_TO_HOST); printf("rc1=%d rc2=%d col0=[", (int)r1, (int)r2); for (int i=0;i<BS;++i) printf("%d%s", g[i*K], i+1<BS?",":""); printf("]\n"); } int main() { aclInit(nullptr); aclrtSetDevice(0); aclrtContext c; aclrtCreateContext(&c, 0); aclrtSetCurrentContext(c); Run(9); Run(3); Run(2); aclrtDestroyContext(c); aclFinalize(); return 0; }实测输出(
probe_mue_oob,Ascend950PR / CANN 9.3.0):设备侧
plog对这三次调用无任何 ERROR 行。影响
F=2..worldSize的配置,配合count=worldSize就进入越界读;读到的相邻内存被当作专家号写入输出,后续
aclnnMoeDistributeDispatchV2/V3按此分发 token,表现为「token 全丢」或「路由到错误专家」,且两段返回码都是 0。
BS*K放大(BS=512,K=16时整块输出被写成 0),不影响其它算子内存,但输出不可恢复。
建议
CheckInputShape增补:balanceMode=0时要求F - 1 >= worldSize,否则 561002。count的实际最大值算max(rankId)并校验F,允许F取更小区间的同时不越界(例如
modeValue用Ceil(W, count)后校验rankId <= F-1)。F ∈ [2, worldSize+1],需说明「count == worldSize时实例号列数必须 ≥ worldSize」。