已合并
动态shape场景下表达式中存在Max及除数是符号变量的单项式//和%运算适配 #42762
zzll创建于 7月25日
动态shape场景下表达式中存在Max及除数是符号变量的单项式//和%运算适配 #42762
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 zzll 的贡献)atomgit-bot
7月25日 评论:
7月25日 评论:
变更摘要
此 PR 将动态 shape 场景下「移除未使用的升维轴(dim-up axes)」的逻辑从 ir.py 的 rebuild_flattened_dims 函数中提取并重构,迁移至 triton.py 的 NPUIndexTritonKernel 类中,作为独立的 _remove_unused_dim_up_axes 方法。重构后的逻辑在代码生成流程中更精确的位置(_transform_schedule_indexing 之后、_record_store_unified_indexing 之前)执行,并增加了对 schedule 节点的遍历、range_tree_nodes 的正确清理(通过 node.parent.remove_entry)、以及残留替换候选的清理(_drop_dead_substitution_candidates),从而避免因过早判定而误删仍被 Store 索引引用的轴。
主要改动
- 将升维轴清理逻辑从
ir.py迁移至triton.py:删除了rebuild_flattened_dims中基于kernel.expr_substituted和kernel.range_tree_nodes直接删除未使用升维轴的代码块(共 11 行),改为在NPUIndexTritonKernel中新增_remove_unused_dim_up_axes方法统一处理。 - 新增
_index_symbol_users方法:遍历node_schedule中所有节点的_body.indexing,建立符号到索引键的映射;若某节点缺少变换后索引则返回None,避免基于不完整信息做出错误删除判断。 - 新增
_drop_dead_substitution_candidates方法:在移除未使用升维轴后,清理range_tree_nodes_substituted中那些重建已删除轴的父扩展候选,防止代码生成引用不存在的变量。 - 改进
range_tree_nodes的删除方式:原实现直接del kernel.range_tree_nodes[var],新实现改为通过node.parent.remove_entry(var)正确地从父节点中移除条目,确保数据结构一致性。 - 调整执行时机:
_remove_unused_dim_up_axes被插入到_transform_schedule_indexing与_record_store_unified_indexing之间,确保父轴已展开后再判定使用关系,避免广播维度被误删。


ascend-robot
7月25日 评论:
7月25日 评论:
atomgit-bot
7月25日 评论:
7月25日 评论:
代码审查
审查完毕
已审查文件
共 2 个文件,均已审查:
| 文件 | 结果 |
|---|---|
torch_npu/_inductor/codegen/ir.py |
✅ 无问题(仅删除旧逻辑,无残留引用,移除了存在 bug 的旧代码) |
torch_npu/_inductor/codegen/triton.py |
⚠️ 发现 2 个问题(1 个 P2 逻辑缺陷 + 1 个 P3 死代码) |
发现摘要
| 优先级 | 数量 | 说明 |
|---|---|---|
| P0 | 0 | — |
| P1 | 0 | — |
| P2 | 1 | _drop_dead_substitution_candidates 在部分候选失效时未更新 range_tree_nodes_substituted,失效候选残留可能导致后续 codegen 引用未定义变量 |
| P3 | 1 | dim_up_temp 字段只写不读,是重构后的残留死代码 |
总体风险评估:中等。P2 问题在特定场景下(一个 var 有多个替换候选,且仅部分候选引用了被移除的升维轴)会触发,可能导致生成的 Triton kernel 引用未定义变量。修复简单(加一行 else 赋值),建议在合入前修复。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 2 |
💬 仅评论


7月25日 添加了label:ascend-cla/yes
此处折叠了82条消息 查看更多
ascend-robot
7月25日 评论:
7月25日 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


ascend-robot
7月25日 评论:
7月25日 评论:
流水线 pytorch_gitcode_PR_multiVersion#13195 [ commitID:f80bfc91 ] 已完成


7月25日 删除了label:SC-RUNNING
7月25日 添加了label:SC-FAIL
ascend-robot
7月25日 评论:
7月25日 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


#3358
【合入来源】
【修改方案】
【资料变更】
【接口变更】
【功能验证】
【CheckList】