Closed
[Bug-Report|缺陷反馈]: moe_init_routing_quant: ST在K>1时生成重复rowIdx导致Golden反向映射错误 #7777
zhu_qiAdd on 12 days agoClosed at 4 days ago
周云飞
12 days ago Comments:
12 days ago Comments:
按反馈中的初始化和反向映射代码,K>1 时重复的 rowIdx 会使 Golden 对同一位置重复赋值,无法正确验证多专家路由;这还不能说明算子 Kernel 存在缺陷。
一个可行的处理方向是在 ST 初始化中按 torch.arange(N*K).reshape(K, N).transpose(0, 1) 生成唯一索引,保留 int32 类型和设备转换,并补充 K>1 精度用例,检查索引是否恰好覆盖 [0, N*K)。据反馈,现有 201 个用例均为 K=1,尚未触发该问题;上述分析尚未经过上板测试。


12 days ago Assign kdy18482276080 as responsible person
4 days ago Associated pull request
4 days ago Close issue
4 days ago changed custom state from 待办的 to 已完成
3 days ago Added label: resolved
一、问题描述
moe_init_routing_quant 系统测试的 init_by_input_data 使用 arange(N).reshape(-1, 1).expand(N, K) 构造 rowIdx。当 K>1 时,同一 token 的多个专家路由会得到重复的源索引,导致 Golden 反向映射覆盖赋值,其余位置保留初始零值。该问题属于测试数据及参考结果错误,不是已验证的算子 Kernel 缺陷。
二、代码位置与证据
基于本地提交 57360e39ab09f4da51ed0eae0f0b24a9f912c731。
文件:moe/moe_init_routing_quant/tests/st/aclnnMoeInitRoutingQuant/executor_aclnnMoeInitRoutingQuant.py,第 73–81 行:
input_data.kwargs["rowIdx"] = ( torch.arange(input_data.kwargs["expertIdx"].size(0)) .reshape(-1, 1) .expand( input_data.kwargs["expertIdx"].size(0), input_data.kwargs["expertIdx"].size(1), ) .to(torch.int32) .to(input_data.kwargs["expertIdx"].device) )同文件第 34–37 行执行反向映射:
expanded_row_idx = np.zeros(expanded_dst_to_src_row.shape).astype(np.int32) expanded_row_idx[expanded_dst_to_src_row] = np.arange( expanded_dst_to_src_row.shape[-1] )仓内 examples/test_aclnn_moe_init_routing_quant.cpp 第 96 行对 N=3、K=2 使用 rowIdx={0,3,1,4,2,5},与当前 ST 初始化不同。
三、复现与影响
取 N=3、K=2,expertIdx=[[1,2],[0,1],[0,2]]。
当前初始化得到 rowIdx=[[0,0],[1,1],[2,2]];应生成 [[0,3],[1,4],[2,5]]。
按专家稳定排序后,当前反向映射的写入索引为 [1,2,0,1,0,2],只覆盖输出的 0、1、2 位置,3、4、5 保留初始零值。Kernel 使用这些重复索引也会发生重叠写入,不能用于验证合法路由输入的精度。
已检查当前 atk_aclnnMoeInitRoutingQuant.json 共 201 个用例,K 均为 1,因此当前配置尚未触发该问题,且缺少 K>1 覆盖。
本次为静态分析及索引逻辑复核,未运行 Ascend 编译、ATK 或上板测试。
四、建议修复
使用如下形式构造唯一源索引,保留 int32 和设备转换:
n, k = input_data.kwargs["expertIdx"].shape row_idx = torch.arange(n * k).reshape(k, n).transpose(0, 1)补充 K>1 的精度用例,并检查 rowIdx 展平后恰好覆盖 [0, N*K)。
严重级别建议:P2。