mindnlp icon indicating copy to clipboard operation
mindnlp copied to clipboard

ops.topk计算结果有误 / ops.sort问题

Open guxinyu1225 opened this issue 1 year ago • 0 comments

Describe the bug/ 问题描述 (Mandatory / 必填) ops.topk求出tensor结果有误,mindspore中的一个tensor[[-3.4028235e+38 -2.0206820e+01 -3.4028235e+38 ... -3.4028235e+38 -3.4028235e+38 -3.4028235e+38]],只有索引为1和96104的值不为-3.4028235e+38,其他均为-3.4028235e+38,用ops.topk求4个最大元素对应的索引,求出索引的值为[1, 96104, -1, -1],而pytorch的结果是[ 1, 96104, 0, 2]

将ops.topk改为ops.sort的时候,输入相同的tensor直接卡住无响应

  • Hardware Environment(Ascend/GPU/CPU) / 硬件环境:GPU

  • Software Environment / 软件环境 (Mandatory / 必填): -- MindSpore version (e.g., 1.7.0.Bxxx) : 2.2.14 -- Python version (e.g., Python 3.7.5) : 3.9.11 -- OS platform and distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 20.04.4

  • Excute Mode / 执行模式 (Mandatory / 必填)(PyNative/Graph): PyNative

To Reproduce / 重现步骤 (Mandatory / 必填)

  1. 加载tensor value 链接: https://pan.baidu.com/s/1renSO8veantlFOTdNVn3bg?pwd=jhu3 提取码: jhu3
  2. 用ops.topk求这个tensor前4个最大值 / 用ops.sort对这个tensor排序
  3. 测试代码 import numpy as np import mindspore from mindspore import ops, Tensor

numpy_array = np.loadtxt('tensor_values.txt', delimiter=',') tensor = Tensor(numpy_array, dtype=mindspore.float32) sorted_scores, sorted_indices = ops.topk(tensor, 4, dim=-1, largest=True, sorted=True) print(sorted_indices)

Expected behavior / 预期结果 (Mandatory / 必填) [1 96104 0 2]

Screenshots/ 日志 / 截图 (Mandatory / 必填) 283d64c8_14506514

Additional context / 备注 (Optional / 选填) 该bug导致PegasusX模型迁移后slow test中test_seq_to_seq_generation报错,同时导致后面的PegasusStandaloneDecoderModelTest CopyTensorDataToDevice报错 截屏2024-08-05 20 15 12

若skip掉test_seq_to_seq_generation,则后面的不会报错 截屏2024-08-05 20 12 03

guxinyu1225 avatar Aug 06 '24 07:08 guxinyu1225