已关闭
[Bug-Report|缺陷反馈]: Ascend 950平台npu_format_cast不支持含零维的空Tensor进行ND/NZ转换 #3015
sunduiyang创建于  26 天前关闭于  25 天前
sunduiyang
sunduiyang
26 天前 创建

一、问题描述 (必填)

Ascend 950平台上,npu_format_cast无法处理shape中包含0的空Tensor,例如:

  • (9, 0)
  • (0, 9)
  • (2, 0, 3)
  • (2, 3, 0)

在ND与FRACTAL_NZ之间进行格式转换时,算子会因空Tensor校验或继续执行TransData tiling而失败,无法完成仅涉及Tensor元数据和存储格式的转换。

问题涉及以下合法转换方向:

  • ND/NCL -> FRACTAL_NZ
  • FRACTAL_NZ -> ND

根因包括:

  1. ND到NZ的参数校验直接拒绝shape中存在0维。
  2. ValidNzShape不允许空NZ Tensor的storage shape包含0维。
  3. 空Tensor完成输入校验后仍进入TransData流程,最终可能出现Failed to execute tiling。

本问题仅涉及Ascend 950 RegBase平台和现有接口支持范围内的输入,不扩展FRACTAL_NZ已有的rank、dtype和源格式约束。

二、环境信息 (可选)

  • 昇腾硬件型号:Ascend950PR_9589
  • CANN版本:9.1.0
  • 操作系统:Ubuntu 22.04.5 LTS
  • 内核版本:5.4.0-125-generic
  • PyTorch版本:2.13.0+cpu
  • torch_npu版本:2.13.0.rc1

三、重现步骤 (可选)

import torch
import torch_npu

x = torch.empty((9, 0), dtype=torch.float16, device="npu")

x_nz = torch_npu.npu_format_cast(x, 29)
x_nd = torch_npu.npu_format_cast(x_nz, 2)
torch.npu.synchronize()

print(x_nz.shape, torch_npu.get_npu_format(x_nz))
print(x_nd.shape, torch_npu.get_npu_format(x_nd))

修复前,ND到NZ或NZ到ND转换无法正常完成。

四、预期结果 (可选)

对于现有接口支持范围内、shape中包含0维的空Tensor:

  1. ND到NZ以及NZ到ND转换成功。
  2. 输出保持输入的逻辑shape、dtype、device和空Tensor属性。
  3. 正确推导和校验NZ storage shape。
  4. workspace size返回0。
  5. 不执行无实际数据需要搬运的TransData流程。
  6. 非空Tensor的格式转换和npu_quant_matmul等下游功能不受影响。

💡 备注(选填)

shape=(0,)属于rank 1,仍受FRACTAL_NZ要求rank为2至6的既有约束,不在本问题修复范围内。

likedislike
sunduiyangsunduiyang
26 天前 添加了label:bug-report
陈思
陈思成员
25 天前 评论:

/assign @sunduiyang

likedislike
CANN-robotCANN-robot成员
25 天前 将 sunduiyang 设为负责人
CANN-robotCANN-robot成员
25 天前 关闭了 issue
CANN-robotCANN-robot成员
25 天前 添加了label:resolved