Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
脚本如下:
import torch import numpy as np import torch_npu # 导入NPU适配库,必须放在torch之后[reference:2][reference:3] torch.manual_seed(42) np.random.seed(42) device = "npu" if torch.npu.is_available() else "cpu" print(f"使用设备: {device}") input_cpu = torch.tensor( np.random.uniform(-100, 100, size=(1, 1, 1, 1)), dtype=torch.float16 ) input_tensor = input_cpu.npu() if device == "npu" else input_cpu k = 1 dim = 0 keepdim = False # torch.kthvalue默认keepdim=False values, indices = torch.kthvalue(input_tensor, k=k, dim=dim, keepdim=keepdim) values_cpu = values.cpu() indices_cpu = indices.cpu() print("Input tensor (on NPU):") print(input_tensor) print(f"\nShape: {input_tensor.shape}, dtype: {input_tensor.dtype}, device: {input_tensor.device}") print(f"\ntorch.kthvalue(input, k={k}, dim={dim})") print("Values:", values_cpu) print("Indices:", indices_cpu) print("Values shape:", values_cpu.shape) print("Indices shape:", indices_cpu.shape)
报错信息为 Input tensor's format[NCHW] should be same with output's format[NCL]. Params check failed.
Input tensor's format[NCHW] should be same with output's format[NCL]. Params check failed.
昇腾硬件型号:950PR CANN版本:最新周构建包
见第一章
💡 备注(选填)
/assign
Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
一、问题描述 (必填)
脚本如下:
import torch import numpy as np import torch_npu # 导入NPU适配库,必须放在torch之后[reference:2][reference:3] torch.manual_seed(42) np.random.seed(42) device = "npu" if torch.npu.is_available() else "cpu" print(f"使用设备: {device}") input_cpu = torch.tensor( np.random.uniform(-100, 100, size=(1, 1, 1, 1)), dtype=torch.float16 ) input_tensor = input_cpu.npu() if device == "npu" else input_cpu k = 1 dim = 0 keepdim = False # torch.kthvalue默认keepdim=False values, indices = torch.kthvalue(input_tensor, k=k, dim=dim, keepdim=keepdim) values_cpu = values.cpu() indices_cpu = indices.cpu() print("Input tensor (on NPU):") print(input_tensor) print(f"\nShape: {input_tensor.shape}, dtype: {input_tensor.dtype}, device: {input_tensor.device}") print(f"\ntorch.kthvalue(input, k={k}, dim={dim})") print("Values:", values_cpu) print("Indices:", indices_cpu) print("Values shape:", values_cpu.shape) print("Indices shape:", indices_cpu.shape)报错信息为
Input tensor's format[NCHW] should be same with output's format[NCL]. Params check failed.二、环境信息 (可选)
昇腾硬件型号:950PR
CANN版本:最新周构建包
三、重现步骤 (可选)
见第一章
四、预期结果 (可选)
💡 备注(选填)