已关闭
[Bug-Report|缺陷反馈]: CANN 9.1.0 版本 使用 flat_idx = sub_score_reshape.topk(total, dim=-1).indices 算子,在相同输入下,多次执行算子有时返回结果相同,有时不相同,请定位,详见问题描述,谢谢 #2641
LetsAiGo创建于 23 天前关闭于 18 天前
陈思
22 天前 评论:
22 天前 评论:
收到反馈,正在联系算子责任人,请稍等


zhanghedong
22 天前 评论:
22 天前 评论:
已知晓,修复中。


22 天前 将 zhanghedong 设为负责人
18 天前 issue状态由 进行中 改变为 已完成
18 天前 关闭了 issue
cy_hw
14 天前 评论:
14 天前 评论:
您好,问题已解决合入主线,待后续商分版本上线后即可解决。


14 天前 删除了关联的pull request:解决TopkV2算子偶现的精度问题
14 天前 添加了label:resolved
Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
一、问题描述 (必填)
CANN 9.1.0 版本 使用 flat_idx = sub_score_reshape.topk(total, dim=-1).indices 算子,在相同输入下,多次执行算子,有时返回结果相同,有时不相同
flat_idx = sub_score_reshape.topk(total, dim=-1).indices
代码片段:

相同输入下不同批次,有的相同,有的不同,如下所示:

二、环境信息 (可选)
昇腾硬件型号: Ascend950PR
CNN版本信息:
node-10-31-200-119(@😃:opp# cat version.info
Version=9.1.0
version_dir=cann
required_package_runtime_version=">=8.5"
required_package_ge-executor_version=">=8.5"
required_package_metadef_version=">=8.5"
required_package_asc-devkit_version=">=8.5"
required_package_bisheng-compiler_version=">=8.5"
timestamp=20260730_231653901
操作系统: x86_64
三、重现步骤 (可选)
多次运行相同的代码,
四、预期结果 (可选)
相同的输入情况下,多次运行返回的结果相同
💡 备注(选填)
定位信息参考:
运行如下代码测试发现:TopK算子正常返回最大值的,但是存在未被选中的数值中存在比选中的还大的值,
import torch
import torch_npu
def has_rank_violation(x_cpu, k, loops=200):
x = x_cpu.npu()
for _ in range(loops):
_, idx = x.topk(k, dim=-1)
torch.npu.synchronize()
def test_npu_topk_large_quantized_duplicate_values_break_rank():
h, n, k = 2, 156025, 3160
x = torch.randint( 0, 256, (h, n),generator=torch.Generator().manual_seed(123), dtype=torch.int32,).to(torch.float32) / 256.0
assert has_rank_violation(x, k, loops=200) is not None
def test_npu_topk_large_unique_values_not_repro():
n, k = 156025, 3160
x = torch.stack([
torch.randperm(n, generator=torch.Generator().manual_seed(1)).to(torch.float32),
torch.randperm(n, generator=torch.Generator().manual_seed(2)).to(torch.float32),
]) / float(n)
正常优选选中大者,但是存在未被选中的数值中存在比选中的还大的值,如下图所示:
