Closed
[Bug-Report|缺陷反馈]: MoeInitRoutingV4 HiFloat8 图转换及标杆比较异常 #8490
BruceLPAdd on 5 days agoClosed at 5 days ago
5 days ago Added label: bug-report
5 days ago Associated pull request
周云飞
5 days ago Comments:
5 days ago Comments:
从报告看,图转换需要区分 uint8 存储载体与 HiFloat8 逻辑类型;标杆比较也需要区分逻辑类型和实际参与比较的输出范围。具体转换和比较行为还需进一步确认。
V4 接口定义中,x 支持 Hif8,但未列出 uint8;quant_mode=-1 时,expanded_x 的类型应与 x 一致。一个可行方向是在图转换时按 x_dtype 传递逻辑类型,同时保持输出载体的原始字节。接口定义见 V4 算子说明。
对于标杆,可考虑按逻辑类型解释 FP8 和 HiFloat8 数据,保留对应的 scale 布局,并只比较有效输出;单字节 0 和 3 的比较结果也需要单独核实。关联 PR 的具体改动和状态尚待确认,我们会继续分析这两处问题。


5 days ago Assign BruceLP as responsible person
5 days ago Close issue
5 days ago changed custom state from 待办的 to 已完成
周云飞
5 days ago Comments:
5 days ago Comments:
已通过 PR #16806 修复 MoeInitRoutingV4 的 HiFloat8 图转换:非量化场景下,根据 x_dtype 将 uint8 载体按位转换为 HiFloat8,输出再按位转换回 uint8。
同时调整了 V3/V4 标杆及比较逻辑,包括恢复 FP8/E8M0 类型和 scale 布局、检查有效输出长度、按类型判断 4bit 打包,以及避免 HiFloat8 差值计算溢出;V3 还同步调整了零宽动态量化 scale 的处理。
PR 描述记录了 Ascend 950 上相关图模式、标杆及精度用例通过。
关联 PR:PR #16806


4 days ago Added label: resolved
Describe the current behavior / 问题描述
torch.ops.cann_ops_transformer.moe_init_routing在非量化模式下,以 uint8 承载 HiFloat8 输入并通过x_dtype指定逻辑类型时,TorchAir 图转换将输入保留为DT_UINT8,导致MoeInitRoutingV4选型失败。V4 测试标杆在 FP8/E8M0 透传和 HiFloat8 比较中,对数据类型、scale 布局及有效输出的处理存在偏差,可能导致比较误报或漏报。
Environment Information / 环境信息
Steps to reproduce the issue / 重现步骤
torch.ops.cann_ops_transformer.moe_init_routing,将形状为(4, 4)的 uint8 Tensor 作为x,形状为(4, 2)、值均为 0 的 int32 Tensor 作为expert_idx。quant_mode=-1、x_dtype=torch_npu.hifloat8、active_num=8、expert_capacity=0、expert_num=1、drop_pad_mode=0、expert_tokens_num_type=1、expert_tokens_num_flag=True、active_expert_range=[0, 1],通过 TorchAir 执行 static 或 dynamic 图。0和3。Describe the expected behavior / 预期结果
图模式应按 HiFloat8 解释输入并保持输出载体的原始字节;标杆应按逻辑类型和有效输出范围进行比较,保留对应 scale 布局。
Related log / screenshot / 日志 / 截图
图编译报
MoeInitRoutingV4输入x的DT_UINT8类型不受支持;标杆单字节 HiFloat8 不一致场景可能被误判通过。关联 PR:https://gitcode.com/cann/ops-transformer/merge_requests/16806