已关闭
[Bug-Report|缺陷反馈]: 【易用性】 pypto.loop_unroll 配合 unroll_list>1 时 RegisterCopy pass 寄存器拷贝路径选择错误导致静默数据损坏(token[1..N-1] 损坏、token[0] 正确);上游未修复仅知识库提供 workaround #3195
liuxiaoxiao11创建于  9月1日关闭于  9月7日
liuxiaoxiao11成员
9月1日 创建

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

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

pypto.loop_unroll 配合 unroll_list 参数(unroll 因子 > 1)时,C++ 编译管线的 RegisterCopy pass 对 tensor 的寄存器拷贝逻辑存在 bug:某些 unroll 配置下 tensor 的 Copy 路径选择错误,导致数据写入位置偏移。表现为循环展开后 token[0] 结果正确,但 token[1..N-1] 数据损坏(静默,无报错)。

知识库(pypto-precision-debug SKILL.md:274)明确记录:

Issue #223, #341 - RegisterCopy pass 在处理 unroll 场景时,对 tensor 的寄存器拷贝逻辑存在 bug,某些 unroll 配置下 tensor 的 Copy 路径选择错误,导致数据写入位置偏移。设置 unroll_list=[1] 可关闭循环展开,规避此问题。

该 bug 在两处知识库引用:pypto-precision-debug/SKILL.md:38,274 和 pypto-op-lint/checks/d1_framework.py:1336。上游 pypto 仓未修复此 bug,仅有 workaround(unroll_list=[1] 关闭循环展开)。

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

服务器/NPU 型号: Ascend910 (16 devices)
PyPTO 版本/Commit: 0.2.1 (pip) / 源码 HEAD 41b340b76
CANN 版本: 9.2.0 (V100R001C25B114)
Python 版本: 3.11.15
操作系统: Huawei Cloud EulerOS 2.0 (aarch64)

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

source /home/operation/Ascend/ascend-toolkit/set_env.sh && export TILE_FWK_DEVICE_ID=0
cd issues/issue-10 && python repro_loop_unroll.py(最小复现触发 F00003,非 RegisterCopy bug)
知识库核查:查看 pypto-precision-debug/SKILL.md:38,274 确认 Issue #223/#341 引用
lint 核查:查看 d1_framework.py:1336 确认 lint 中的已知问题提示
上游核查:git -C /home/l00605417/pypto log --oneline origin/master --all --grep="RegisterCopy|unroll" 确认无修复

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

RegisterCopy pass 应正确处理 unroll 场景下的 tensor 寄存器拷贝,unroll_list > 1 时不应导致数据损坏。在 bug 修复前,loop_unroll 接口应在 unroll_list > 1 时发出警告提示已知 bug 和 workaround。

知识库引用(pypto-precision-debug/SKILL.md:274):

依据参考:Issue #223, #341 - RegisterCopy pass 在处理 unroll 场景时,对 tensor 的
寄存器拷贝逻辑存在 bug,某些 unroll 配置下 tensor 的 Copy 路径选择错误,导致数据
写入位置偏移。设置 unroll_list=[1] 可关闭循环展开,规避此问题。
NPU 复现尝试(issues/issue-10/evidence_npu_attempt.log):

ERROR: RenderedParserError: ErrCode: F00003, RuntimeError: CHECK FAILED:
dstShape.size() == srcShape.size() - Assemble: src and dest requires same shape
(此为 kernel 语法问题,非 RegisterCopy bug 本身)

上游 git log(issues/issue-10/evidence_upstream_check.log):

3788ac5a7 fix(machine): Stop raising stitch_function_max_num with unroll in non-memory-driven mode
5e9a4e545 fix(machine): Rollback unroll_list and stitch_max_num, while maintaining with memory-driven operations

无 RegisterCopy 修复提交

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

复现状态:⚠️ 部分确认。知识库(Issue #223/#341)确认 bug 存在并提供 workaround;NPU 最小复现因 kernel 语法复杂性未达成(触发 F00003 而非 RegisterCopy 损坏)。

上游核对(2026-09-01,HEAD 41b340b76):上游有 4 个 unroll 相关提交但均不涉及 RegisterCopy pass 修复。归入结局 ②:上游至今没写。

仓分类:pypto(C++ RegisterCopy pass),pypto-gym(附——知识库文档化 workaround)。完整证据目录:issues/issue-10/README.md。c3f3f8f4df99488784078ce4b72918e2.zip

likedislike
Lliuxiaoxiao11成员
9月1日 添加了label:bug-report
Lliuxiaoxiao11成员
9月2日 将 songle1 设为负责人
宋乐成员
9月2日 评论:

将分析pypto.loop_unroll机制

likedislike
李李俊谕成员
9月2日 将 KaiqiJin 设为负责人
李李俊谕成员
9月2日 移除了负责人 songle1
袁野袁野成员
9月3日 添加了label:Passes
袁野袁野成员
9月3日 issue类型由 任务 改变为 缺陷
KaiqiJinKaiqiJin成员
9月3日 将 hwwangmingjun 设为负责人
KaiqiJinKaiqiJin成员
9月3日 将 seu_chang 设为负责人
KaiqiJinKaiqiJin成员
9月3日 移除了负责人 hwwangmingjun
KaiqiJinKaiqiJin成员
9月3日 移除了负责人 KaiqiJin
KaiqiJin
KaiqiJin成员
9月3日 评论:

@seu_chang 麻烦帮忙看下unrolllist的问题

likedislike
宋宋乐成员
9月7日 将 xiaoyueyueyueyue 设为负责人
LiuChang
LiuChang成员
9月7日 评论:

附件中提供的用例执行之后报错:CHECK_OP(dstShape.size() == srcShape.size()) << "Assemble: src and dest requires same shape";
pypto.assemble(src, offsets, dst) 的语义是“把 N 维小张量 src 写入 N 维大张量 dst 的 offsets 位置”——要求 src 和 dst 维度数(秩)相同,它不会自动把低维 src 升维。
提供的复现脚本里:

  1. x 是 (8, 4) 的 2D 张量,idx 是 loop_unroll 产生的 SymbolicScalar
  2. x[idx, :] 走 tensor.py:329-334:先把整数索引转成 slice(idx, idx+1) 做 view(得到 (1, 4)),再 reshape 把长度为 1 的维压掉 → 返回 1D 张量 shape (4,)
  3. 所以 row = pypto.add(x[idx,:], x[idx,:]) 是 1D (4,)
  4. pypto.assemble(row, [idx, 0], y):src 秩 = 1,dst y 秩 = 2 → 2 != 1 → 检查失败
    使用: row = pypto.add(x[idx:idx+1, :], x[idx:idx+1, :]) —— 用 slice 切行,报错消失。

并没有出现文中所述Register Copy相关的问题。

与ISSUE中所述吻合:

复现状态:NPU 最小复现因 kernel 语法复杂性未达成(触发 F00003 而非 RegisterCopy 损坏)。
likedislike
LiuChang
LiuChang成员
9月7日 评论:

开发者你好,此issue计划关闭,如有问题欢迎继续讨论

likedislike
LiuChangLiuChang成员
9月7日 issue状态由 待办的 改变为 已完成
LiuChangLiuChang成员
9月7日 关闭了 issue