已关闭
[Bug-Report|缺陷反馈]:【易用性】gather_in_l1 / gather_in_ub 两个 experimental API 缺陷问题——最小示例也段错误,大 shape 编译失败,报错建议不可执行 #3395
liuxiaoxiao11创建于  9月20日关闭于  9月20日
liuxiaoxiao11
liuxiaoxiao11成员
9月20日 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Describe the current behavior / 问题描述 (Mandatory / 必填)

一句话:gather_in_ub 和 gather_in_l1 是实验性 API,用于把数据从全局内存(GM)搬到片上内存(L1/UB)以提速。但标注为 experimental 却不做任何参数校验,导致最简示例也段错误、大 shape 编译失败、报错建议根本跑不通。

缺陷 1:gather_in_ub 最小示例段错误,程序直接崩溃
最简 docstring 示例——传 6×4 的 tensor、3 个索引、block_size=2、axis=-2——运行后直接 segment fault(程序崩溃)。

类比:你照着 API 文档的示例代码复制粘贴运行,程序直接崩了——说明书上的例子都跑不通。

崩溃调用栈:

segment fault !!!
npu::tile_fwk::TiledGatherInUB(...) ← 崩溃在 gather 展开函数内部
npu::tile_fwk::ExpandOperationInto(...)
标记为 experimental 没问题,但至少应在运行前检查参数是否合法、index 是否越界,而不是直接 crash。

缺陷 2:gather_in_l1 B-matrix FP16 大 shape 编译失败,报错只有 map::at
gather_in_l1(is_b_matrix=True, dtype=FP16) 搭配 num_buffer_tokens >= 8192 时编译失败:

F00003, Failed to compile function 'gather_matmul_pto_kernel'.
map::at
map::at 是 C++ 标准库 std::map 的 key 不存在报错。不告诉你:

哪个操作触发的
什么 shape 下触发的
应该怎么修
小 shape(4096 以下)编译通过且精度正确,说明是 shape 相关的边界问题。

缺陷 3:报错给的修复建议不可执行
遇到 F0000A DYNAMIC_SHAPE_COMPUTE_UNSUPPORTED 报错,建议"Use view in pypto.loop"。按建议修完后触发 F2FFFF FE_INNER_ERROR——说明这个建议没经过验证,根本不可行。

缺陷 4:pypto.arange / pypto.full 不支持 SymbolicScalar 类型
在 JIT kernel 内部,循环变量等很多是 SymbolicScalar(编译期符号值)类型,但 arange/full 的 Python 绑定只接受 Python int,SymbolicScalar 传入时报 View(): incompatible function arguments 或 tile shape error。

Environment / 环境信息 (Mandatory / 必填)

服务器/NPU 型号: Ascend910_9362(A3),16 设备,20 cube cores/40 vector cores per device
PyPTO 版本/Commit: 0.2.1,本地 HEAD 12ef077d0,远端 master 30830736d
CANN 版本: cann-9.2.0(source /home/operation/Ascend/ascend-toolkit/set_env.sh)
Python 版本: 3.13.9
操作系统: Huawei Cloud EulerOS 2.0 (aarch64)
torch / torch_npu 版本: 2.12.0+cu130 / 2.12.0
TILE_FWK_DEVICE_ID: 6(初试)/ 7(segfault)/ 8(scan)——segfault 后设备残留占用

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

环境准备: source /home/operation/Ascend/ascend-toolkit/set_env.sh
export TILE_FWK_DEVICE_ID=6
cd /home/l00605417/lxx/benchmark_runs/fracture-points-0918-gen-tune/issues/3_2_issue_conform/issue-15
2. 复现缺陷 1(gather_in_ub segfault): bash run_gather_ub_segv.sh small
预期看到 segment fault !!! + TiledGatherInUB 调用栈。 3. 复现缺陷 2(gather_in_l1 B-matrix FP16 编译失败,需换设备号,因 segfault 残留): source /home/operation/Ascend/ascend-toolkit/set_env.sh
export TILE_FWK_DEVICE_ID=8
python3 repro_gather_in_l1_zero.py
预期看到 F00003 + map::at 编译错误。

Describe the expected behavior / 预期结果 (Mandatory / 必填)

gather_in_ub 不应在 docstring 最小示例上 segfault,应在编译期或运行前给出约束校验错误。
gather_in_l1(is_b_matrix=True) FP16 路径在大 shape 下应正常编译,或给出含源码位置和 shape 信息的编译错误。
错误诊断中的修复建议(如 "Use view in pypto.loop")应可执行,经过验证。
pypto.arange/pypto.full 应支持 SymbolicScalar 参数,或编译期给出清晰的不支持错误。

gather_in_ub segfault ✅(evidence_gather_ub_segv.log)

segment fault !!!
libtile_fwk_interface.so(npu::tile_fwk::TiledGatherInUB(npu::tile_fwk::Function&, TileShape const&, ...)+0x38)
libtile_fwk_interface.so(npu::tile_fwk::ExpandOperationInto(...)+0x1424)
libtile_fwk_interface.so(npu::tile_fwk::ExpandFunction::ExpandOperation(...)+0x1d4)
第 1 行说明程序崩溃;第 2-4 行是调用栈,崩溃在 TiledGatherInUB 展开函数内部,与历史 session 一致(偏移地址差别 +0x3c vs +0x38),说明不是特定 shape 边界问题。

  1. gather_in_l1 B-matrix FP16 编译失败 ✅(run_gather_in_l1_zero.log)

=== B-Realistic | gather_in_l1_realistic | b=True t=False ===
EXC: PyptoGeneralError: ErrCode: F00003, RuntimeError: Failed to compile function 'gather_matmul_pto_kernel'.
map::at
第 3 行说明仅含 map::at(C++ std::map::at 的 key 不存在异常),无源码位置、无触发操作、无 shape 信息。该错误在 num_buffer_tokens >= 8192(dim=128, block_size=128)时一致触发,小 shape(4096 以下)编译成功且精度 PASS。

Special notes for this issue/备注 (Optional / 选填)

fb0aebfe0e8d405cb3b82558cf5e7d9b.zip

likedislike
liuxiaoxiao11liuxiaoxiao11成员
9月20日 添加了label:bug-report
李俊谕
李俊谕成员
9月20日 评论:

好的,已收到问题,正在安排分析

likedislike
bynshardbynshard成员
9月20日 关联了pull request:fix(operation): Validate GatherInUB inputs and vector tile shapes
bynshardbynshard成员
9月20日 关联了pull request:fix(operation): Validate GatherInUB inputs and vector tile shapes
CANN-robotCANN-robot成员
9月20日 关闭了 issue
CANN-robotCANN-robot成员
9月20日 添加了label:resolved