在 components/omni-npu/src/omni_npu/layers/fused_moe/fused_moe.py 的 fused_moe 函数末尾(约第 107 行):
components/omni-npu/src/omni_npu/layers/fused_moe/fused_moe.py
fused_moe
return torch_npu.npu_moe_finalize_routing(out, None, None, None, topk_weights, expanded_src_to_dst_row, topk_ids).to(torch.bfloat16)
这里直接对 npu_moe_finalize_routing 的输出做了 .to(torch.bfloat16),但函数输入 x 的 dtype 并不一定是 bfloat16。如果模型使用 float16 作为计算精度,这里会强制把输出转成 bfloat16,导致:
npu_moe_finalize_routing
.to(torch.bfloat16)
x
建议改为保持与输入一致的 dtype:
return torch_npu.npu_moe_finalize_routing(out, None, None, None, topk_weights, expanded_src_to_dst_row, topk_ids).to(x.dtype)
或者如果 npu_moe_finalize_routing 本身支持 dtype 保持,直接去掉 .to() 调用。
.to()
您好,openPangu-2.0模型仅支持BF16,当前代码对实际功能无影响。谢谢您的反馈!
在
components/omni-npu/src/omni_npu/layers/fused_moe/fused_moe.py的fused_moe函数末尾(约第 107 行):return torch_npu.npu_moe_finalize_routing(out, None, None, None, topk_weights, expanded_src_to_dst_row, topk_ids).to(torch.bfloat16)这里直接对
npu_moe_finalize_routing的输出做了.to(torch.bfloat16),但函数输入x的 dtype 并不一定是 bfloat16。如果模型使用 float16 作为计算精度,这里会强制把输出转成 bfloat16,导致:建议改为保持与输入一致的 dtype:
return torch_npu.npu_moe_finalize_routing(out, None, None, None, topk_weights, expanded_src_to_dst_row, topk_ids).to(x.dtype)或者如果
npu_moe_finalize_routing本身支持 dtype 保持,直接去掉.to()调用。