Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
Ascend 950 的 Median / NanMedian 在多核 radix 路径中,可能将输入中的负 subnormal(次正规数)误计为 NaN,导致中位数和索引错误;输入本身可以完全不含 NaN / Inf。
根因位于 index/kth_value/op_kernel/arch35/common/kth_value_radix_more_core_base.h:PreProcess 原地将浮点输入转换为 radix key,随后 OnRadixInputLoaded 又将这段已改写的数据按浮点值统计 NaN。例如 FP32 负 subnormal 的位模式 0x80000001 被转换为 key 0x7ffffffe,后者按 FP32 解读就是 NaN。Median 的 NaN 传播和 NanMedian 的非 NaN 中位秩计算因此受到影响。即使正确中位数是普通数值,只要输入含有这些负 subnormal,也可能触发。
index/kth_value/op_kernel/arch35/common/kth_value_radix_more_core_base.h
PreProcess
OnRadixInputLoaded
0x80000001
0x7ffffffe
8b3f093
(1, 1, 151992)
dim=-1
[-1e-38, -1e-40]
index/median/tests/assets/golden.py
index/nan_median/tests/assets/golden.py
median_sch02_fp32_negative_subnormal
nan_median_sch02_fp32_negative_subnormal
NaN 统计应针对原始输入,不能将 radix key 的位模式当成浮点值判断。有限值(包括 subnormal)不应被计为 NaN;真正的 NaN 保持 Median 传播、NanMedian 忽略的既有语义。values 与 indices 应符合各算子的 golden。
精度报错
Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
Describe the current behavior / 问题描述 (Mandatory / 必填)
Ascend 950 的 Median / NanMedian 在多核 radix 路径中,可能将输入中的负 subnormal(次正规数)误计为 NaN,导致中位数和索引错误;输入本身可以完全不含 NaN / Inf。
根因位于
index/kth_value/op_kernel/arch35/common/kth_value_radix_more_core_base.h:PreProcess原地将浮点输入转换为 radix key,随后OnRadixInputLoaded又将这段已改写的数据按浮点值统计 NaN。例如 FP32 负 subnormal 的位模式0x80000001被转换为 key0x7ffffffe,后者按 FP32 解读就是 NaN。Median 的 NaN 传播和 NanMedian 的非 NaN 中位秩计算因此受到影响。即使正确中位数是普通数值,只要输入含有这些负 subnormal,也可能触发。Environment Information / 环境信息 (Mandatory / 必填)
8b3f093。Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)
(1, 1, 151992),dim=-1,取值范围[-1e-38, -1e-40],全部为负 subnormal。index/median/tests/assets/golden.py或index/nan_median/tests/assets/golden.py,比较 values 和 int64 indices;本场景实际命中 schId=2、tiling key=258。median_sch02_fp32_negative_subnormal与nan_median_sch02_fp32_negative_subnormal,均使用零容差。修复前出现精度失败,修复后通过;正 subnormal 为对照场景。Describe the expected behavior / 预期结果 (Mandatory / 必填)
NaN 统计应针对原始输入,不能将 radix key 的位模式当成浮点值判断。有限值(包括 subnormal)不应被计为 NaN;真正的 NaN 保持 Median 传播、NanMedian 忽略的既有语义。values 与 indices 应符合各算子的 golden。
Related log / screenshot / 日志 / 截图 (Mandatory / 必填)
精度报错
Special notes for this issue/备注 (Optional / 选填)