已开启
2.14 pr #7
rmch创建于  8月4日
rmch成员
8月4日 创建

Check 修复 Windows 平台下 Inductor 生成的 fused kernel 名称过长(超过 MAX_PATH 260 字符限制)导致缓存文件无法打开的问题,在 Windows 上截断并追加 hash。 "对 get_fused_kernel_name 执行 git grep,torch_npu 中有多处直接引用:

torch_npu/_inductor/codegen/scheduling.py:208 的 NPUTritonScheduling 直接调用 get_fused_kernel_name(node_schedule, config.triton.descriptive_names) 生成 kernel 名称;
torch_npu/_inductor/codegen/triton.py:719 的 NPU Triton codegen 也调用 get_fused_kernel_name;
torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/codegen/meta_kernel.py:319 和 mlir.py:24 在 MLIR 后端路径中同样引用该函数。

→ 上述调用方在 Windows 上构建 NPU Triton kernel 缓存路径时,若 kernel 名称超过 50 字符,get_fused_kernel_name 的返回值将被截断并追加 hash 后缀
→ 若 torch_npu 在 Windows 上运行 NPU Triton 编译(例如通过 torch_npu/_inductor/codegen/scheduling.py 的 NPUTritonScheduling),截断后的名称保证缓存路径不超 MAX_PATH,NPU kernel 缓存文件可正常创建和打开
→ 若 kernel 名称本身不超过 50 字符(小型融合图),此修改不触发,行为与之前相同。此 PR 修复 Windows 平台 NPU inductor 编译路径的缓存文件写入问题,为正向修复。" medium 否 是
Check 修复 Inductor SizeVarAllocator.simplify_with_ranges 在递归静态求值时丢失 loop-local 变量范围的 bug,解决 symbolic shape 推导崩溃。torch-npu 的 Inductor 路径大量使用 simplify_with_ranges,需评估兼容性。 "对 simplify_with_rangesSizeVarAllocator_maybe_evaluate_staticvar_to_range 执行 git grep,torch_npu 中存在直接引用:

torch_npu/_inductor/codegen/triton.py:1615 调用 V.graph.sizevars.simplify_with_ranges(expr, self.var_ranges()),这是 NPU Triton codegen 在处理 loop index 表达式时的核心调用。
torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/ir.py:621 也调用 V.graph.sizevars.simplify_with_ranges(index, var_ranges),用于 MLIR 后端的 IR 下降。
torch_npu/_inductor/codegen/__init__.py:42 通过 sizevars.SizeVarAllocator.simplify = simplify 对 simplify 方法打补丁,直接依赖上游 SizeVarAllocator.simplify 的接口和语义。
→ 若上游 ShapeEnv.simplify 在递归 _maybe_evaluate_static 时丢失 local ranges,NPU Triton codegen 路径(triton.py:1615)在处理包含 Max/Min/FloorDiv 的复杂 loop index 表达式时同样会崩溃,错误信息为 'vr must not be None for symbol q3'。

此修复通过透传 local var_to_range 上下文解决该问题,对 NPU Triton codegen 和 MLIR 后端的 symbolic shape 推导均有正向改善,使上述调用点在复杂模型(如含嵌套 attention 或大 sequence length 的模型)编译时更稳定。" medium 否 是
Check 在 Inductor Triton epilogue 用户自定义 kernel 融合路径中增加写索引等于读索引的强制校验,修复融合时 store 操作数错误的 bug。torch-npu 的 Triton codegen 路径有独立实现,需评估是否受此 scheduler 变更影响。 PR #184248 在 Inductor Triton 后端的 user-defined triton kernel epilogue 融合路径中新增了正确性校验守卫(写索引必须等于读索引),改动文件为 torch/_inductor/codegen/triton.py 和 torch/_inductor/scheduler.py。三重核查:①torch_npu/_inductor/codegen/scheduling.py:83 处 NPUTritonScheduling 继承自 TritonScheduling,且未覆写 codegen_user_defined_triton_kernel_node,upstream 修复通过继承透明生效;②torch_npu/_inductor/codegen/triton.py fork(NPUIndexTritonKernel)不含 TritonScheduling 的 epilogue codegen 路径,无耦合;③torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/scheduler.py(136 行)仅 patch get_read_write_buffers_sizes,与 epilogue 无关。建议确认 NPU 环境下是否存在 user-defined triton kernel 与 pointwise epilogue 算子融合场景;若存在,需验证继承链路正确触发上游守卫。 low 否 是 compile_stage:Inductor
Check 修复 Inductor 内存规划器对 buffer reuse 输出别名处理的错误,当某个 buffer 名通过 reuse 链接到另一个有 OUTPUT user 的 buffer 时,现在也会正确将其标记为 output-like,防止内存池提前销毁导致生成代码中出现 UnboundLocalError。 "对 memory_planning、MemoryPlanner、compute_buffer_groups 执行 git grep,在 torch_npu 源码中发现:

torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/codegen/wrapper.py:74 从 torch._inductor.codegen.memory_planning 导入 _align 函数。

torch_npu/_inductor/lowering_fx.py:266 同样从 torch._inductor.codegen.memory_planning 导入 _align。

此 PR 修改的是 memory_planning.py 中 MemoryPlanner.compute_buffer_groups() 方法的逻辑(+5/-1),修复 buffer 组 output-like 标记遗漏的问题。torch_npu 的两处引用仅使用 _align 辅助函数,不依赖 MemoryPlanner.compute_buffer_groups 的内部逻辑。但 NPUWrapperCodeGen(torch_npu/_inductor/codegen/wrapper.py)继承自上游 PythonWrapperCodegen,若该路径使用了 MemoryPlanner,则 NPU Triton codegen 路径下 reused output alias 的 UnboundLocalError 问题将随此修复获益。" medium 否 是
Check 修复 Inductor 在 CPU 和 MPS 后端对 bf16/fp16 输入的 add/sub 操作中 Python 浮点标量精度处理不一致问题,通过为 register_pointwise/make_pointwise 增加 round_scalars_to_tensor_dtype 标志,使 Inductor 与 eager 行为对齐,仅影响 CPU 和 MPS 路径,CUDA 不受影响。 上游 PR #186818 在 torch/_inductor/lowering.py 中为 aten.add 和 aten.sub 的 register_pointwise 调用新增了 round_scalars_to_tensor_dtype 标志(仅限 CPU 和 MPS backend,CUDA 路径不变)。torch_npu 存在两个 fork lowering 文件:torch_npu/_inductor/lowering_fx.py(第 1792-1828 行分别注册 aten.add/aten.sub)和 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py(第 6533/6617 行),二者均有各自的 register_pointwise 实现(不含 round_scalars_to_tensor_dtype 参数),并独立注册 aten.add/aten.sub。由于该标志明确限定仅对 CPU/MPS 生效,NPU lowering 走自己的 fork 路径,不经过上游 register_pointwise 的新参数分支。人工确认 NPU 上 bf16/fp16 标量与张量 dtype 的舍入行为是否与 eager 模式一致即可,无需修改代码。 low 待确认 是 compile_stage:Inductor
Check 修复 Regional Inductor Python wrapper codegen 中未解析符号变量问题:当子模块的 FakeTensor 元数据包含形如 2u0 的表达式维度时,wrapper 代码生成时遗漏了 u0 的本地定义,导致运行时 NameError。修复方法是在 wrapper 输入符号赋值时,通过解方程从运行时 tensor 尺寸中反推单一缺失符号。 上游 PR #185890 修复了 PythonWrapperCodegen(torch/_inductor/codegen/wrapper.py)在 Regional Inductor 场景下对含表达式的输入维度(如 2u0)符号缺失的处理逻辑。torch_npu 的 NPUWrapperCodeGen(torch_npu/_inductor/codegen/wrapper.py:131)继承自 PythonWrapperCodegen,未覆写相关符号解析方法(仅覆写 generate_node_numel_expr、codegen_input_size_asserts、define_kernel 等 NPU 专属方法)。该 bug fix 通过继承透明生效于 NPU 路径。人工确认 NPU Regional Inductor 场景下带非单纯符号维度的 tensor 编译不受影响即可,无需修改 torch_npu 代码。 low 待确认 是 compile_stage:Inductor
Check 新增 autotuning_inputs 日志 artifact,通过 TORCH_LOGS=autotuning_inputs 启用,为每个待自动调优的 Triton kernel 输出输入 tensor 的 shape/dtype/stride 等详细信息,该 artifact 默认关闭且独立于 +inductor 日志通道。 上游 PR #184399 为 Inductor 新增 autotuning_inputs 日志 artifact(B 轨新功能),在 triton_heuristics.py 的自动调优流程中记录每个 Triton kernel 的输入 tensor shape/dtype/stride。torch_npu 的 NPUCachingAutotuner(torch_npu/_inductor/npu_triton_heuristics.py:413)继承自 CachingAutotuner 并覆写了 autotune_to_one_config(第 663 行),但未调用上游新增的 autotuning_inputs artifact 日志逻辑。该 artifact 默认不开启(opt-in via TORCH_LOGS=autotuning_inputs),当前不影响 NPU 主路径;若需支持此调试能力,可在 NPUCachingAutotuner.autotune_to_one_config 中参照上游同步添加 autotuning_inputs artifact 日志,非紧急。 low 待确认 是 compile_stage:Inductor
Check 修复 torch.compile 对 diagonal_scatter 的 backward 分解(decomposition)中存在的错误输出问题,修正了 _refs/init.py 中 diagonal_scatter 分解实现在计算 MutationLayout stride 时的 bug,使 Inductor IR 中的 layout 正确反映对角线索引模式。 "对 diagonal_scatter 执行 git grep,在 torch_npu 源码中发现:

torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:1887 注册了 aten.diagonal_scatter 的 NPU lowering,:1888 定义了 diagonal_scatter 函数,为 torch_npu MLIR 路径的独立实现。

此 PR 修复的是 torch/_refs/init.py 中 diagonal_scatter 的 AOT decomposition 实现(修复 MutationLayoutSHOULDREMOVE 中 stride 计算错误)。torch_npu 的 MLIR 路径通过 inductor_patch/lowering.py:1887 注册了独立的 NPU lowering,不走上游 _refs 分解路径。但 torch_npu 的 Triton codegen 路径(非 MLIR 路径)可能未注册独立 lowering 而依赖上游 decomposition,此时将在上游修复后获得正确的 diagonal_scatter backward 结果。需确认 NPUTritonScheduling 路径下 diagonal_scatter 是否有独立实现或走 fallback decomposition。" low 待确认 是
Check 在 FX readable 打印时,对 AOT joint graph 中来自 backward 的节点 stack trace 添加 'Backward of forward node:' 前缀标记,利用 autograd_backward 元数据区分前向/后向 stack 注释。 "torch_npu 在图模式代码生成路径中多处调用 print_readable() 获取 FX graph 的可读表示,并将其用于哈希和元数据注释。

torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/codegen/meta_kernel.py:335 调用 traced_graph.print_readable(print_output=False) 的返回值参与 code_hash() 计算内核哈希;:416mlir_kernel._gm.print_readable(print_output=False) 嵌入 metadata_commenttorch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/codegen/mlir.py:126 同样将 print_readable() 输出用于 MLIR kernel 的 metadata_comment。

耦合链路:
torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/codegen/meta_kernel.py:335code_hash(traced_graph.print_readable(print_output=False) + kernel_name) 直接消费 torch.fx.graph.Graph.print_readable() 的返回字符串。
→ 上游 PR 修改 torch/fx/graph.py 在 print_readable 输出中为 backward 节点添加 'Backward of forward node:' 前缀注释;这将改变 AOT joint graph 的 print_readable 字符串内容。
→ 若 meta_kernel.py:335 的哈希输入字符串发生变化,已缓存的 NPU kernel 元数据(基于旧格式哈希)将失效,首次运行时会触发重新编译,之后将以新格式稳定运行。这是一次性缓存失效,不影响功能正确性,但需要在升级时预热 kernel cache。" medium 待确认 是
Check 对 inductor Triton wrapper 代码生成进行多项改进,包括重构 triton.py codegen 和 cpp_wrapper_cpu.py 的 kernel launch 代码,提升 Triton kernel 封装生成质量。 PR 187331 修复两处 cpp_wrapper bug:①Python fallback 返回值解包跳过 MutationOutput;②Triton config 在 cpp_wrapper 下不生成 tensor-pointer 16-byte 对齐元数据。torch_npu 的 fork triton.py(torch_npu/_inductor/codegen/triton.py:52 导入 config_of/signature_of/signature_to_meta)未复制上游 alignment-metadata 生成逻辑,不受 16-byte 对齐修复影响;torch_npu/_inductor/codegen/cpp_wrapper.py 从上游 cpp_wrapper_cpu 导入 CppWrapperCpu 但未覆写 python fallback 返回値解包逻辑,MutationOutput bug 修复透明生效。人工确认 CppWrapperNpu 的 Python fallback 路径无类似 MutationOutput 索引错误即可,无需修改代码。 low 待确认 是 compile_stage:Inductor
Check 在 inductor IR 层新增复数 tensor 拆分支持,将 complex dtype tensor 分解为实部/虚部,使 Triton codegen 能处理复数类型输入,仅新增逻辑不改变现有路径。 PR 184435 仅在 torch/_inductor/ir.py 中新增 ArgProperty TypedDict 并收紧 ExternKernel schema arg 元数据的类型注解(+41行,全部为 TypedDict 定义和类型签名调整),无运行时行为变化。git grep ArgProperty 在 torch_npu 全包 0 命中,torch_npu fork 文件(torch_npu/_inductor/codegen/ir_fx.py / inductor_patch/ir.py)均无 ArgProperty 引用,类型注解变更在 Python 运行时无影响,无需适配。 low 否 否 compile_stage:Inductor
Check 优化 Triton matmul 模板的 prologue load,将循环不变量提升到 K-loop 外,提升 GEMM 性能,同时新增 select_algorithm.py 中的配套逻辑判断 tail-K 边界。 git grep 搜索 select_algorithm\|TritonTemplateKernel 在 torch_npu/ 非测试文件命中:torch_npu/_inductor/codegen/triton.py:1806from torch._inductor.select_algorithm import TritonTemplateKerneltorch_npu/_inductor/codegen/triton.py:1808isinstance(V.kernel, TritonTemplateKernel) 做类型判断;torch_npu/_inductor/lowering_fx.py:269torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/codegen/wrapper.py:78 均导入 extern_kernels from select_algorithm。耦合链路:torch_npu/_inductor/codegen/triton.py:1806TritonTemplateKernel 直接引用被 PR 修改的 select_algorithm.py 中的类 → torch_npu/_inductor/codegen/triton.py:1808isinstance(V.kernel, TritonTemplateKernel) 判断依赖该类结构不变 → PR 在 select_algorithm.py 新增了 207 行 prologue hoisting 逻辑,若新增接口导致 TritonTemplateKernel 类签名或 load_input hook 协议改变,则 torch_npu triton.py 中基于该类的路径将失效,导致 NPU 的 Triton 模板内核 codegen 路径异常。需重点确认 TritonTemplateKernel.load_input 接口兼容性。 medium 待确认 是
Check 为 Triton codegen 添加 cooperative reduction 支持,通过跨 thread block 分割工作并使用 atomic 操作合并部分结果。新增 config.py 中的阈值配置选项。 PR 183661 新增 cooperative_reduction_max_cache_size_ratio 配置项(torch/_inductor/config.py),并在 lowering.py 中添加基于 CUDA L2 cache 大小的 two-pass variance 协作归约选择逻辑。torch_npu 已在 npu_choices.py 中实现自己的 should_use_persistent_reduction(接受 cooperative_reduction: bool 参数),并通过 InductorChoices.should_use_persistent_reduction = should_use_persistent_reduction 覆盖上游。新增的 cooperative_reduction_max_cache_size_ratio 阈値基于 CUDA 设备 L2 cache 物理参数,NPU 无等价概念,NPU 路径由 npu_choices.py 独立控制。人工确认 npu_choices.py 的 cooperative_reduction 行为无需同步上游新阈値即可。 low 待确认 是 compile_stage:Inductor
Check 修复 FlexAttention 在 AOTAutograd 缓存中因 lambda 函数无法 pickle 导致的 cache miss,通过让 Dynamo 的 torch._check 接受 str/None 消息类型解决序列化问题,同时更新 graph_break_registry。 PR 修复了 FlexAttention 中 AOTAutograd 缓存 miss 问题,核心改动在 torch/_dynamo/variables/torch.py:使 TorchVariable.call_function 在处理 torch._check* 系列函数时,接受 str 和 None 类型的 message 参数(而不仅限于可调用对象),从而避免 lambda 函数无法被 pickle 导致的缓存 miss。同时修改 flex_attention.py 将 block-mask 长度检查消息从嵌套 lambda 改为模块级字符串常量。torch_npu 在 torch_npu/npu/_graph_tree.py:1043 处使用 torch._check(False, lambda: error_msg) 形式,但这是运行时调用,不经过 Dynamo 图捕获路径,不受 variables/torch.py 变更影响。torch_npu 的 _dynamo.py 从 variables/torch.py 导入 TorchCtxManagerClassVariable 和 TorchInGraphFunctionVariable,但未覆写 torch._check* 的处理逻辑,改动经继承透明生效。torch_npu 未 fork torch/_dynamo/variables/torch.py 或 torch/nn/attention/flex_attention.py。建议确认 torch_npu 环境下使用 FlexAttention 时 AOT 缓存功能正常,无需修改代码。涉及文件:torch_npu/npu/_graph_tree.py(运行时 torch._check 使用),torch_npu/utils/_dynamo.py(variables/torch.py 的导入点)。 low 否 是 compile_stage:Dynamo
Check 为 torch._higher_order_ops.map 新增对 xs 输入原地修改(mutation)的支持,涉及 map.py 和 higher_order_ops.py 的大幅重构,并新增20个图中断注册项,影响 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:128 注册的 _foreach_map lowering 路径。 PR 为 map HOP 新增输入 mutation 支持(B 轨新功能),核心改动在 torch/_higher_order_ops/map.py(+96/-65)和 torch/_dynamo/variables/higher_order_ops.py(+68/-2)。功能对等三问评估:①map HOP 是设备无关的控制流原语,输入 mutation 支持是语义层改动,不针对特定后端;②NPU 用户使用 torch.compile + map HOP 时会触发此路径,mutation 语义由 upstream 透明处理;③torch_npu 无自定义 MapHigherOrderVariable 实现,也无 torch/_higher_order_ops/map.py 的 fork,新增的 mutation 支持经继承自动适用于 NPU 路径,不会导致功能缺失。torch_npu 仅对 _foreach_map(不同于标准 map HOP)有 lowering 注册(torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:808),标准 map HOP 无定制处理。graph_break_registry.json 新增条目由 linter 工具维护,torch_npu 源码不直接依赖。建议在 NPU 环境运行 test/functorch/test_control_flow.py 中与 map 输入 mutation 相关的新增测试用例,确认无回归。涉及文件:torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py(_foreach_map 注册,与本 PR 的标准 map 无直接关系),test/dynamo/test_higher_order_ops.py(torch_npu 自带 HOP 测试)。 low 否 是 compile_stage:Dynamo
Test 修复 Inductor cpp wrapper 中 python-only 输入(OpaqueObjectState)被错误打包为 AtenTensorHandle 导致后续 tensor 输入索引偏移的 bug,保持输入 slot 原始位置。 "此 PR 修改 torch/_inductor/codegen/cpp_wrapper_cpu.py 中 pack_input 相关逻辑,修复 python-only 输入(OpaqueObjectState)在 cpp wrapper 中的 slot 处理。

git grep 确认 torch_npu/_inductor/codegen/cpp_wrapper.py:18 中存在直接继承:
from torch._inductor.codegen.cpp_wrapper_cpu import CppWrapperCpu
且 torch_npu/_inductor/init.py:11 通过 patch_codegen_with_cpp_wrapper() 和 CppWrapperNpu 激活 cpp wrapper 路径。

耦合链路:torch_npu/_inductor/codegen/cpp_wrapper.py 的 CppWrapperNpu 继承 CppWrapperCpu(来自 torch/_inductor/codegen/cpp_wrapper_cpu.py)→ 此 PR 修改 CppWrapperCpu 中 pack_input 的 python-only input 跳过逻辑 → 若 torch_npu 的 AOTI 编译路径存在 OpaqueObjectState 类型输入,此前可能出现 tensor 输入 index 偏移错误导致 C++ 生成代码访问错误 slot。

影响类型:运行时逻辑修复,影响 NPU AOTI cpp wrapper 的输入处理正确性。

验证方法:运行 test/_inductor/test_aclgraph_update_plan_compile.py 中启用 cpp_wrapper 场景的测试用例,确认 python-only 输入与 tensor 输入混合时 slot 索引正确。检查 test/npu/test_public_bindings.py 中 torch_npu._inductor.codegen.cpp_wrapper 相关测试通过。

潜在风险:CppWrapperNpu 继承 CppWrapperCpu,若上游新增 pack_input 调用约定或参数签名变更,NPU 子类需同步验证 override 方法的 slot 索引逻辑与父类保持一致,避免 AOTI 生成代码访问错误的输入 slot。" medium 否 是
Test 新增 aten.shallow_copy_data_ 算子以支持 torch.compile 下 tensor.data = 的跨设备赋值,替换原本不支持跨设备的 aten.set_.source_Tensor,含 Dynamo/AOTAutograd/FakeTensor/Inductor 全栈支持。 "本 PR 新增 aten.shallow_copy_data_ 算子(B 轨新功能),用于在 torch.compile 下处理跨设备 tensor.data = ... 赋值。NPU 适配关注三条耦合链路:

(1)ACLGraph mutation 检测路径:torch_npu/npu/_graph_tree.py:2072 调用 check_for_mutation()(从 torch._inductor.cudagraph_utils import),torch_npu/utils/_graph_tree.py:309,352 调用 find_input_mutations()(从 torch.dynamo.backends.cudagraphs import)。上游新增 aten.shallow_copy_data 后,check_for_mutation 和 find_input_mutations 的行为已更新以识别该 op 为 storage mutation,ACLGraph 侧需验证能否正确处理含此 op 的图(跨设备场景下 NPU tensor 的 data 指针被替换)。

(2)Inductor lowering 路径:torch_npu/_inductor/lowering.py:85 以 make_fallback = npu_make_fallback 覆盖上游 make_fallback,torch_npu/inductor/lowering.py:167 迭代 lowering.lowerings 注册 fallback。上游 lowering.py 将 aten.shallow_copy_data 加入 allowed_mutation_ops 并注册了专属 lowering,torch_npu 的 fallback 注册逻辑需确认不会错误地给该 op 套 fallback,否则导致跨设备 data 赋值走错路径。

(3)FakeTensor fake_device 路径:上游 fake_impls.py 新增对 aten.shallow_copy_data_ 的 FakeTensor 实现(更新 fake_device)。torch_npu/utils/_inductor.py 有 FakeTensorMode 依赖(:106,:164),torch_npu/utils/serialization.py:365,408,409 使用 fake_device 属性。需验证 NPU FakeTensor 在 cross-device shallow_copy_data 下 fake_device 更新逻辑的正确性。

建议在 NPU 跨设备场景(npu tensor.data = cpu tensor)和同设备场景下各运行 torch.compile + ACLGraph 测试,确认 mutation 检测、graph capture、lowering 路径均无误。" medium 是 是 compile_stage:AOTAutograd
Check 在 Inductor IR 中引入 OrderingBarrier(继承 NopKernel)作为新调度顺序控制节点,通过 get_mutation_names()/mutation_names 构建重命名链,使用 WeakDep 的 ordering_only 标志避免真实数据依赖。 本 PR 引入 OrderingBarrier(新的 NopKernel 子类 IR 节点),用于替换 control_deps pass-through 的排序机制,同时给 scheduler.py 的 WeakDep 新增 ordering_only/is_fake 标志。需人工确认以下两个耦合点:①torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/config.py:8 直接 import control_deps,以及 npu_lowering.py:3 直接 import ControlDeps 并在 line 88 用于过滤 lowerings——上游将 control_deps 的 lowering 从直接产出 NopKernel 改为产出 OrderingBarrier(NopKernel 子类),接口本身未变,但 torch_npu 的过滤逻辑 isinstance(op, ControlDeps) 是否仍正确需人工核查;②torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/npu_inductor_plugin.py:291-338 有大量自定义 WeakDep 调度逻辑(fusable_weak_dep、prune_redundant_weakdeps),upstream scheduler.py 新增 ordering_only=True 的 WeakDep(is_fake=True) 语义——需确认 npu_inductor_plugin.py 的 WeakDep 处理分支是否会错误融合或跳过 is_fake=True 的 OrderingBarrier 产生的排序依赖。两处均不涉及签名变化,但行为语义有微调,建议运行 torch_npu 侧等价测试验证。 low 否 是 compile_stage:Inductor
Check 将 Dynamo 内部多处 str/Any 类型注解替换为 typing.Literal 精确类型别名(StanceStr、SetSubgraphInputs 等),并将 proxy_call_hook 的 hook_type 从 **kwargs 提升为显式关键字参数,行为保持不变。 PR 188486 将 torch/_dynamo/ 多处裸 str 类型替换为 typing.Literal 别名(StanceStr、SetSubgraphInputs、StaticInputType、OptimizeDDPMode、HookType),并将 compiled_autograd.py 中 proxy_call_hook 的 hook_type 从 *kwargs 提升为显式关键字参数。三重核查均无耦合:torch_npu 产品代码中 proxy_call_hook 0 命中;set_stance 仅命中 test/ 测试文件;speculate_subgraph/get_static_address_type/get_optimize_ddp_mode 0 命中;改动文件均不在 npu_source_map.md 的 fork 清单中;torch_npu/utils/_dynamo.py 对 TensorVariable.call_method 的 monkey-patch 与 compiled_autograd.proxy_call_hook 无交叉。本 PR 属纯类型注解改动,运行时行为完全不变,torch_npu 无需修改代码。确认 torch_npu/utils/_dynamo.py(proxy_call_hook 零耦合)和 torch_npu/dynamo/init.py(set_stance 零耦合)均未受影响即可关闭本条目。 low 否 是 compile_stage:Dynamo
Check 修复 Dynamo 对 set/frozenset 子类的比较 guard 错误:使用基类 set 迭代和大小 API 替代可被重载的 iter/len,同步修改 guards.py、source.py、utils.py、builder.py 及 guards.cpp。 PR 186763 修复 set/frozenset 子类比较 guard 行为,Dynamo 在物化 set 子类内容、重建 guard source 及 C++ guard 检查时改为直接调用基类 API,涉及 torch/_dynamo/guards.py、source.py、utils.py、variables/builder.py 及 guards.cpp。三重核查:torch_npu 产品代码中未引用 SetVariable、SetItemSource、richcompare 等 guard 内部符号(0 命中);torch_npu/_inductor/ascend_npu_ir/.../wrapper.py:86-91 和 torch_npu/_inductor/lowering_fx.py:280-284 仅引用 torch._C.dynamo.guards.assert_size_stride/empty_strided
等工具函数,与本 PR 修改的 Python guard 物化逻辑无交叉;torch_npu/utils/_dynamo.py:313 import wrap_fx_proxy_cls from builder,但本 PR 对 builder.py 的改动不涉及 wrap_fx_proxy_cls 签名;改动文件均不在 fork 清单。本 PR 为正确性修复,torch_npu 无需修改代码,确认 torch_npu/_inductor/lowering_fx.py 和 wrapper.py 中 guards 工具引用不受影响即可关闭。 low 否 是 compile_stage:Dynamo
Check 将 torch/_dynamo/variables/ 下多个文件中残留的 tx: Any 参数注解替换为 InstructionTranslator 类型,纯类型注解变更,不改变运行时行为。 PR 184800 将 torch/_dynamo/variables/ 下 constant.py、dicts.py、distributed.py、functions.py、misc.py、script_object.py、torch.py 中 tx: Any 注解替换为 tx: "InstructionTranslator",共 46 行纯注解改动,运行时行为完全不变。三重核查:torch_npu/utils/_dynamo.py:28 以 TYPE_CHECKING 守卫 import InstructionTranslator,仅用于类型注释,运行时不执行;torch_npu/utils/_dynamo.py 中对 TensorVariable.call_method(:405-406)、SkipFunctionVariable.new(:403-404)、UserDefinedClassVariable.new(:401-402)的 monkey-patch 签名均未受本 PR 影响(本 PR 只改上游方法内部 tx 注解,不改这些 patch 点的参数列表);改动文件均不在 fork 清单。纯类型注解,A 轨,无需任何适配,判定为 none。 low 否 否 compile_stage:Dynamo
Check 修复 cpp_wrapper 的 _compatible_with_stableivalue 逻辑,对含 SymInt/SymBool/SymFloat 参数的自定义算子改用 boxed dispatch 路径,修改 torch/_inductor/codegen/cpp_wrapper_cpu.py。 此 PR 修改 torch/_inductor/codegen/cpp_wrapper_cpu.py,在 _compatible_with_stableivalue 中额外拒绝 real_type 包含 SymInt/SymBool/SymFloat 的 schema,使其走 boxed dispatch 路径。经 git grep 确认,torch_npu 中未直接使用 _compatible_with_stableivalue 符号,但 torch_npu/_inductor/codegen/cpp_wrapper.py:18 通过 from torch._inductor.codegen.cpp_wrapper_cpu import CppWrapperCpu 导入上游基类,且 torch_npu/_inductor/codegen/cpp_wrapper.py:200 定义 class CppWrapperNpu(CppWrapperCpu) 继承上游基类。这意味着 _compatible_with_stableivalue 的修复将通过继承直接作用于 CppWrapperNpu,且 torch_npu/_inductor/codegen/cpp_wrapper.py:391 和 :801 通过 CppWrapperCpu.define_kernel() 和 CppWrapperCpu.generate_kernel_call() 调用上游路径。若 torch-npu 中存在使用 SymInt 参数的自定义算子,本 PR 修复后这些算子将正确走 boxed dispatch,建议验证 torch-npu cpp_wrapper 路径的 SymInt 算子行为。 low 否 是
Check 修复 cpp_wrapper 的 _compatible_with_stableivalue 逻辑,对含 Any 类型参数的分布式算子(如 all_gather_into_tensor)改走 fallback 路径,解决 moco 模型 cpp_wrapper 失败问题。 此 PR 修改 torch/_inductor/codegen/cpp_wrapper_cpu.py 中的 _compatible_with_stableivalue 检查,使含 Any 类型参数的算子正确走 fallback 路径而非 aoti_torch_call_dispatcher 失败路径。经 git grep 确认,torch_npu 中未直接使用 _compatible_with_stableivalue 符号,但 torch_npu/_inductor/codegen/cpp_wrapper.py:18 通过 from torch._inductor.codegen.cpp_wrapper_cpu import CppWrapperCpu 导入上游基类,torch_npu/_inductor/codegen/cpp_wrapper.py:200 定义 class CppWrapperNpu(CppWrapperCpu) 继承上游基类,且 torch_npu/_inductor/codegen/cpp_wrapper.py:801 通过 CppWrapperCpu.generate_kernel_call() 调用上游路径。HCCL 分布式通信算子(如 all_gather_into_tensor)的 schema 包含 Any 类型 group_name 参数,本 PR 修复后 cpp_wrapper 将正确将其路由到 fallback/boxed 路径,避免这类算子在 cpp_wrapper 路径下触发 aoti_torch_call_dispatcher 失败。执行包含 HCCL 算子的 cpp_wrapper 集成测试(torch_npu/_inductor/codegen/cpp_wrapper.py 对应的 inductor 测试用例)可确认路由正确性。 low 否 是
Check 修复 Dynamo tensor isinstance 优化路径未考虑自定义 instancecheck metaclass 的问题,对带有自定义 instancecheck 的 classinfo 触发 graph-break,保留标准类型(dtype pseudo-type、Parameter、Buffer、ABCMeta)的快路径。 PR 186491 修改 torch/_dynamo/variables/builtin.py 的 isinstance 处理逻辑:对 classinfo 的 metaclass 定义了自定义 instancecheck 的情形,不再 constant-fold,改为触发 graph-break。torch_npu 存在两处潜在交叉点:①torch_npu/utils/_dynamo.py:282 对 BuiltinVariable.call_id 进行赋值式 monkey-patch(BuiltinVariable.call_id = _wrap_call_id),但该 patch 仅拦截 call_id 方法,与 isinstance 的 call_isinstance 代码路径正交,签名不受影响;②torch_npu/contrib/transfer_to_npu.py:59-60 的 _TorchTypeProxyMeta 定义了自定义 instancecheck,但该 metaclass 仅用于 transfer_to_npu 场景下的代理,不在 Dynamo compile 主路径下被 isinstance 检查触发。建议确认 NPU dynamo 测试能通过新增的 graph-break 场景;确认 _wrap_call_id 补丁在新版 builtin.py 中继续有效。无需修改 torch_npu 代码。 low 否 是 compile_stage:Dynamo
Test 在 bound_sympy 前增加 _rewrite_for_value_range_analysis 预处理步骤,将 cbase - c(base%divisor) 形式的算术表达式重写为等价 FloorDiv 形式,修复 SymPy 值域推断给出错误负数下界的 bug,涵盖 PythonMod、sympy.Mod 三种变体。 "torch-npu 在 torch_npu/_inductor/codegen/triton.py:70 处直接从 torch.utils._sympy.value_ranges 导入 bound_sympy 函数,并在 torch_npu/_inductor/codegen/triton.py:1833 处调用 bound_sympy(x) 执行 NPU Triton kernel 的索引值域推断。

torch_npu/_inductor/codegen/triton.py:70 的 from torch.utils._sympy.value_ranges import bound_sympy, ValueRanges 直接引用了被修改的 bound_sympy 函数
→ bound_sympy 被 torch_npu/_inductor/codegen/triton.py:1833 的索引范围推断逻辑直接调用,用于计算 NPU Triton kernel 代码生成时变量的值域边界
→ 该值域边界推断结果影响 torch_npu/_inductor/codegen/triton.py 中的 mask 生成和 guard 代码逻辑,进而影响 NPU kernel 的正确性保障
→ 若 NPU Triton kernel 中存在类似 alignment 相关的模减算术模式(如 persistent reduction 的 R0_BLOCK 对齐计算),修复前可能生成错误的范围约束,导致 NPU kernel 产生不必要的 mask 或错误的 guard 检查,修复后行为更正确。

需要在 NPU 环境下运行 test/npu/_inductor/ 中的 Triton codegen 相关测试(如 test_triton_tiling.py、test_npu_inductor.py),验证修复后的 bound_sympy 重写逻辑与 NPU kernel 生成的索引边界计算兼容,尤其针对含 persistent reduction block 对齐的场景,确认 NPU 上 kernel 输出正确性无回归。

对 bound_sympy 和 ValueRanges 执行 git grep,除 torch_npu/_inductor/codegen/triton.py:70 外,还在 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/torch_mlir_patch.py:74 发现对 torch.utils._sympy.value_ranges.ValueRanges 的引用,用于 MLIR patch 路径中的 range_constraints 构建。bound_sympy 修复后的值域推断改进可同步惠及该路径中的范围约束计算,NPU MLIR 代码生成路径无需独立适配。" medium 否 是
Check 在 Triton 3.7+ 版本上为 ROCm 路径启用 Inductor-Triton debug assert,通过版本守卫保持与旧版 Triton 的兼容。torch-npu 的 NPUCachingAutotuner 继承自上游 CachingAutotuner,需确认 debug assert 逻辑兼容性。 PR 188075 在 torch/_inductor/runtime/triton_heuristics.py 中新增 ROCm HIP 路径的 debug assert 启用逻辑,且以 is_hip() 条件门控(Triton 3.7+)。torch_npu 通过 torch_npu/_compat/inductor.py 和 torch_npu/_inductor/npu_triton_heuristics.py 深度依赖 torch._inductor.runtime.triton_heuristics(import CachingAutotuner、HeuristicType 等多个符号),但本次改动不涉及任何被 torch_npu 引用符号的签名变更,仅在 is_hip()==True 分支内追加 debug assert 逻辑。NPU 设备走 is_hip()==False 路径,该逻辑不会触发。建议人工确认 torch_npu/_inductor/npu_triton_heuristics.py 与 torch_npu/_compat/inductor.py 中无对 triton_heuristics 内部 debug assert 相关符号的引用;测试文件 test_minifier_isolate.py 的版本门控测试与 NPU 无关,torch_npu 无需同步改动。 low 否 是 compile_stage:Inductor
Test 修复 override_cudagraphs 注解无法跨图断裂帧边界传递的问题,通过在 dynamo utils 增加运行时全局 override 栈,使独立编译的 callee 帧继承 cudagraph 注解,共 320 行。 被改精确符号为 torch/_dynamo/utils.py 新增的 _cudagraph_override 全局状态、decorators.py 的 CudagraphOverrideContextManager 与 output_graph.py 的 OutputGraph.init 中 cudagraph_annotation 种子逻辑。对 override_cudagraphs、cudagraph_annotation、_cudagraph_override 在 tmp/torch_npu 执行 git grep,torch_npu 中未使用这些符号,此 PR 不影响 NPU 功能。补充机制分析:torch_npu 通过 torch_npu/utils/_dynamo.py 对 Dynamo 做设备级适配(如 VariableTracker 相关封装),但并不覆写 OutputGraph 的 cudagraph 注解传播逻辑;NPU 的图捕获走 aclgraph 后端与独立实现的 NPUGraph,cudagraph_annotation 是 CUDA cudagraph 分支的内部状态,NPU 分支不读取该字段。上游修复的是 graph break 后独立帧无法继承注解这一 Dynamo 内部行为,属于运行时 trace 逻辑变化。由于 torch_npu 未依赖该注解字段,320 行改动(含 266 行为测试)不会传导到 NPU 的编译或运行路径。若后续 NPU 需要复用 cudagraph 注解语义再评估适配。 low 否 是
Test 修复 dynamo 中懒初始化模块在符号 shape 下的初始化:将 fake tensor 的符号 shape 具体化为 concrete hint 后再传给 _infer_parameters,避免 SymInt 传入 torch.empty 报错,共 49 行。 上游在 torch/_dynamo/variables/nn_module.py 的 initialize_lazy_module 中,把 fake tensor 的符号形状 concretize 成 concrete hint 后再传给 _infer_parameters(修复 resume function/graph break 后 SymInt 传入 torch.empty 报错)。这是 A 轨对已有 lazy module 追踪逻辑的行为修复。torch_npu 未 fork nn_module.py、未 override NNModuleVariable/UnspecializedNNModuleVariable 的相关方法(torch_npu/utils/_dynamo.py 仅自定义 NPUTorchCtxManagerClassVariable、NPUAutocastModeVariable 及 TensorVariable.call_method 赋值 patch,均与 lazy module 初始化无关),修复经继承透明生效。因 NPU 用户 torch.compile 编译含 LazyModule 的网络会走到该初始化路径,建议在 NPU 上跑 test/dynamo/test_modules.py 的 TestLazyModules 用例(含 test_lazy_batchnorm_with_dict_input)确认动态 shape 下 lazy module 初始化正常,无需改 torch_npu 代码。 low 否 是 compile_stage:Dynamo
Check 将 dynamo 中三处固定键的 dict 载荷改为 TypedDict(TensorSpecializedProps、AotAutogradKwargs、GroupInfo),增强类型检查,共 115 行,其中 AotAutograd 的 kwargs 签名被显式化。 上游为三处固定 key 的 dict payload 引入 TypedDict(TensorSpecializedProps @variables/tensor.py、AotAutogradKwargs @backends/common.py 经 Unpack 透传给 aot_module_simplified、GroupInfo @repro/after_aot.py),并把 TensorVariable.init 的 is_contiguous 注解从 bool|None 修正为 tuple[memory_format,...]|None。PR 自述 type-annotation only、无运行时行为变化。torch_npu 在 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/npu_inductor_plugin.py:171,194 以赋值式 monkey-patch 绑定 AotAutograd.call = wrap_aot_autograd(AotAutograd.call),但 wrap_aot_autograd 的内层 npu_aot_autograd(args, **kwargs) 是签名无关透传(L182,191),上游仅给 **kwargs 增加 Unpack[AotAutogradKwargs] 注解、未改实参结构,故该 patch 不受影响。TensorSpecializedProps/GroupInfo 在 torch_npu 零引用。人工确认后无需改 torch_npu 代码。 low 否 是 compile_stage:Dynamo
Test 在 dynamo 的 VariableTracker 上新增 tp_init_impl 槽位并将 init 路由至此,替换各 VT 内的 if name==init 分支,同时修复 DequeVariable 重初始化截断 bug,共 240 行。 上游在 torch/_dynamo/variables/base.py 的 VariableTracker 新增 tp_init_impl slot,把 init 派发从各 VT 里 if name == "__init__" 分支改为 slot override(list/deque/set/frozenset/dict/defaultdict),并顺带修复 DequeVariable.init 重新初始化时 maxlen 误截断的 bug。这是 A 轨基类新增默认 slot + 子类 override 的重构,torch_npu 无自定义 list/dict/set/deque VT、未 fork variables/ 目录、tp_init_impl/tp_iter_impl 在 torch_npu 零引用,NPU 的自定义 VT(torch_npu/utils/_dynamo.py 的 NPUTorchCtxManagerClassVariable/NPUAutocastModeVariable)不涉及这些容器类型,重构经继承透明生效。因 NPU 用户编译使用内置容器(list/dict/set/deque)的代码会走到这些 VT 的 init 追踪路径且 deque 行为有修正,建议在 NPU 跑 test/dynamo/test_functions.py 相关用例确认容器初始化追踪正常,无需改 torch_npu 代码。 low 否 是 compile_stage:Dynamo
Check 让 dynamo 基类 VariableTracker.getattro_impl 默认优先走 object_generic_getattr(MRO 遍历+描述符协议),无 python_type 时回退 const_getattr,各 VT 不再需单独 opt-in。 该 PR 把 object_generic_getattr 设为基类 VariableTracker.getattro_impl 默认实现,并删除 ConstantVariable/RangeVariable 的 getattro_impl 覆写、修正 UserDefinedClassVariable 的 new 属性解析路径。核查 torch_npu/utils/dynamo.py 后确认:NPU 的自定义 VT(NPUTorchCtxManagerClassVariable、NPUAutocastModeVariable、NpuStreamContextVariable)只覆写 call_function/create/python_type,均未覆写 getattro_impl/var_getattr,也未引用 object_generic_getattr;torch_npu/utils/dynamo.py:402 的赋值式 patch UserDefinedClassVariable.new=UserDefinedClassVariable__new 改的是 VT 构造器(对象实例化),与本 PR 改动的“new 属性经 MRO 解析返回 GetAttrVariable”逻辑不在同一层,互不影响;torch_npu 未 fork 任何 torch/_dynamo/variables/
.py。基类默认实现变更经继承对 NPU 子类透明生效,人工确认 test/dynamo 下 NPU patch 的 getattr 相关用例通过即可,无需改 torch_npu 代码。 low 否 是 compile_stage:Dynamo
Check 在 dynamo 新增 BoundMethodVariable,表示绑定到某 VT 实例的方法,object_generic_getattr 找到带 call_method 的方法时返回它,并修复描述符 tp_descr_get 的无限递归。 该 PR 新增 BoundMethodVariable(torch/_dynamo/variables/misc.py + object_protocol.py + init.py 导出),并修复 MemberDescriptorVariable/GetSetDescriptorVariable 的 tp_descr_get_impl 无限递归。核查 torch_npu 后确认:torch_npu/utils/_dynamo.py 的 import 列表(第12-23 行)从 base/constant/ctx_manager/functions/lists/streams/tensor/torch/user_defined 引入符号,均未 import misc 或 object_protocol,全包未引用 BoundMethodVariable;这是上游内部新增的方法分派 VT(B 轨新增机制),设备无关(纯字节码层方法对象建模,不涉及 NPU 设备),NPU 用户走 torch.compile 会经过 object_generic_getattr 分派但该路径由基类透明处理,torch_npu 无自定义方法 VT、无对应能力缺失后果。人工确认 test/dynamo/test_tp_getattro.py 等 NPU 测试副本通过即可,无需改 torch_npu 代码。 low 否 是 compile_stage:Dynamo
Check 新增 getattro_impl slot 与 GenericGetAttr 基础设施,用 generic_getattr 统一分派替换 builtin.py 中约 180 行 isinstance 分支,使 dynamo 属性访问对齐 CPython tp_slot 协议。 该 PR 是本系列基础设施:新增 getattro_impl slot 与 GenericGetAttr 基础设施(object_protocol.py 的 generic_getattr/object_generic_getattr/mro_lookup/_resolve_descriptor_get),把全体 VT 的 var_getattr 重命名为 getattro_impl,并将 GetAttrBuiltinVariable._call_getattr 的 isinstance 分派集中化。核查 torch_npu 后确认:torch_npu/utils/_dynamo.py 的 NPU 自定义 VT 均未定义 var_getattr/getattro_impl(仅覆写 call_function/create/python_type),故 var_getattr→getattro_impl 重命名不触及任何 NPU 覆写点;torch_npu/dynamo/trace_rule.py 只向 torch_name_rule_map 注入 NPU 函数映射、不涉及 getattr slot;全包无 generic_getattr/mro_lookup/_UnhandledDescriptorError 引用,无 fork 任何 variables/.py。重命名与集中化对 NPU 子类经继承透明生效。人工确认 test/dynamo/test_tp_getattro.py 等 NPU 测试副本通过即可,无需改 torch_npu 代码。 low 否 是 compile_stage:Dynamo
Check 为 dynamo repro CLI 的 argparse Namespace 引入共享 ReproOptions Protocol,替换 after_aot/after_dynamo 中的 options:Any 类型标注,并为 save_dir 加 fail-fast 守卫。 被改符号为 torch/dynamo/repro/init.py 新增的 ReproOptions Protocol 及 after_aot.py/after_dynamo.py 中 repro
入口的类型标注(78 行,主体是把 options:Any 收窄为 Protocol,属类型标注改动,仅 repro_analyze 对 save_dir=None 增加一处 fail-fast 断言的运行时行为)。对 repro/ReproOptions 在 tmp/torch_npu 下 git grep 未命中该调试模块。相关耦合:torch_npu/utils/_dynamo.py:12 从 torch.dynamo.variables.base 导入 VariableTracker,torch_npu/dynamo/trace_rule.py 也 patch 了 dynamo,但均未触碰 repro 调试子系统(该子系统是 minifier/复现工具,只在 TORCHDYNAMO_REPRO* 场景手动触发)。耦合链路:上游 repro 入口的类型收窄不改变函数签名的运行时行为,NPU 的 dynamo 适配走 trace_rule/backend 注册路径,不调用 repro_after_aot/after_dynamo。影响类型为静态类型标注变化,无运行时语义改变(除 --no-save-dir 下 analyze 提前报错,本就是坏路径)。潜在风险几乎为零。因此不影响 NPU 功能,验证方式为确认 NPU 环境下 minifier 复现流程(若使用)仍能正常导入 repro 包。 low 否 是
Check 在 dynamo 用 Protocol 和精确类型替换 guards/decorators/compiled_autograd/functional_export 中固定接口的 Any 标注,去除若干类型抑制,纯类型标注收窄不改运行时行为。 被改符号为 torch/_dynamo/guards.py 的 GuardCheckSpec 回调类型别名、compiled_autograd.py 的 _AOTCompiledFunction Protocol 与 extract_bw_module 返回类型收窄等(121 行,均为类型标注/Protocol 引入,PR 描述明确为 annotation-only,无运行时行为变化)。对 GuardCheckSpec/_AOTCompiledFunction/compiled_autograd 在 tmp/torch_npu 下 git grep 未命中这些具体符号。相关耦合:torch_npu 通过 torch_npu/utils/_dynamo.py:12 导入 torch._dynamo.variables.base.VariableTracker 并 patch dynamo,但本 PR 改的 guards.py/compiled_autograd.py 是编译守卫与编译期 autograd 子系统,NPU 未 patch 这些模块的具体函数。耦合链路:上游收窄 guards 的 get_metadata_fn/eval_fn 与 extract_bw_module 的类型标注 → 不改变函数签名的运行时调用方式与返回值 → NPU 的 dynamo backend/trace_rule 注册不依赖这些类型标注。影响类型为静态类型标注变化,无编译/运行时/数值语义改变。潜在风险:几乎为零,仅当 NPU 有代码以 Any 方式向 guards 传入不满足新 Protocol 的对象时 pyrefly 会告警,但运行时不受影响。因此不影响 NPU 功能,验证方式为随 torch 升级后跑一次 NPU torch.compile 冒烟用例确认 guard 检查正常。 low 否 是
Check 把 dynamo variables/ 中残留的 tx:Any 参数标注统一收窄为 InstructionTranslatorBase,覆盖 base.py 46 个 slot 方法及 constant.py/functions.py,纯类型标注、无运行时行为变化。 上游对 torch/_dynamo/variables/{base,constant,functions}.py 中 tx 参数做纯注解修改(tx: Any → InstructionTranslatorBase),PR 自述 annotation-only、无运行时行为变化、无新增 import、无签名/arity 变化。torch_npu/utils/_dynamo.py 确有自定义 VT 方法(call_function(self, tx, args, kwargs) @L34、TensorVariable_call_method(self, tx, name, args, kwargs) @L96)并以赋值式 monkey-patch 绑定 TensorVariable.call_method = TensorVariable_call_method @L406,但这些方法按位置传递 tx、且上游未改任何方法的参数个数或顺序,仅换类型注解,故对 torch_npu 的调用/patch 无影响。人工确认后无需修改 torch_npu 代码。 low 否 是 compile_stage:Dynamo
Test 将已有的 linalg_vector_norm refs 分解加入默认 core ATen 分解表,使 run_decompositions 不再保留 aten.linalg_vector_norm.default,并修正 dim=() 与可变算子跳过逻辑。 被改符号为 torch/_decomp/init.py 新增登记的 aten.linalg_vector_norm 到 core 分解表,以及 torch/_refs/linalg/init.py 中 dim=() 规范化修正(126 行)。对 linalg_vector_norm 在 tmp/torch_npu 下 git grep 命中两处不同文件:torch_npu/_inductor/dvm/decomp.py:27 在 NPU 的 dvm 后端分解列表中显式登记了 aten.linalg_vector_norm,torch_npu/csrc/aten/AutoCastOps.cpp:120 通过 KERNEL_PRIVATEUSEONE(linalg_vector_norm, fp32_set_opt_dtype) 注册了该算子的 NPU autocast 规则。耦合链路:上游把 linalg_vector_norm 加入 core ATen 分解表 → ExportedProgram.run_decompositions() 及 inductor 编译时该算子被默认展开为更底层的 refs 运算 → torch_npu/_inductor/dvm/decomp.py:27 已在 NPU dvm 后端登记同一算子的分解,与上游新增的 core 分解构成对同一 aten.linalg_vector_norm 的双重分解入口,dvm 后端拿到的将是上游先行分解后的图,NPU 需以上游分解形态为准做处理 → torch_npu/csrc/aten/AutoCastOps.cpp:120 注册的是未分解整算子的 autocast,上游在 export/编译期先分解掉后,该 autocast 注册点在编译路径上不再命中整算子(eager 路径仍命中,因 eager 不走 core 分解)。影响类型为编译/导出期算子分解行为变化,确定影响 NPU 上 export 与 inductor 对 linalg_vector_norm 的处理:dvm 分解入口与上游 core 分解重叠,且编译期 autocast 覆盖点由整算子前移到分解后的子运算。验证方式:在 NPU 上运行 test/test_decomp.py 相关用例及导出含 vector_norm 的模型,确认分解结果与 autocast 生效。 medium 否 是
Check 修复 inductor Triton codegen 对非 float32 输入 signbit 用 x<0 导致 float64 负零丢失符号位的问题,将 libdevice.signbit 路径扩展到 tl.float64,其余 dtype 保持原回退。 上游修复 torch/_inductor/codegen/triton.py 中 signbit 的 Triton codegen:对非 tl.float32 输入原用 x < 0,会丢 float64 负零的符号位,改为把 libdevice.signbit 路径扩展到 tl.float64。这是 CUDA/libdevice 专属 codegen 的边界 bug fix。triton.py 虽在 fork 清单,但 torch_npu 的 fork 文件 torch_npu/_inductor/codegen/triton.py 内 signbit grep 0 命中——NPU 不走上游 Triton 的 signbit codegen,而是通过自有 lowering register_pointwise(aten.signbit, override_return_dtype=torch.bool)(torch_npu/_inductor/lowering_fx.py:1883、ascend_npu_ir/.../inductor_patch/lowering.py:6674)及 npu_triton_helpers 里的 CANN/Ascend libdevice 生成 NPU kernel。上游此 CUDA libdevice.signbit 修改不进入 NPU codegen 路径。人工确认 NPU signbit 对 float64 负零结果正确即可,无需改 torch_npu 代码。 low 否 是 compile_stage:Inductor
Test 放宽 Dynamo 对 out= 张量布局的校验,将原本只接受行主序连续的谓词扩展为同时接受 channels_last 与 channels_last_3d,修复 channels-last 输出在 torch.compile(fullgraph=True) 下被拒导致 graph break 的问题。 上游在 torch/_dynamo/variables/torch.py 将 out= 张量布局判定集中为统一谓词,并放宽为接受 row-major contiguous、channels_last、channels_last_3d 三种 dense 布局。torch_npu 与该类的全部耦合点均不涉及该谓词:torch_npu/dynamo/trace_rule.py:2,53,79 仅把 torch.npu/torch_npu._C 函数映射进 TorchInGraphFunctionVariable;torch_npu/utils/_dynamo.py:379 仅向 TorchInGraphFunctionVariable._get_handlers() 注入 npu stream handler;全仓唯一赋值式 Dynamo patch 是 TensorVariable.call_method(torch_npu/utils/_dynamo.py:406),与 out= 布局判定无关——改动经继承透明生效,NPU 上 channels_last out= 调用从 graph break 变为正常入图。适配动作:torch_npu fork 了 test/dynamo/test_repros.py,把上游新增的 test_out_overload_channels_last(+22 行)同步进该 fork 并在 npu 设备跑通,同时用 NPU 私有 format(如 NZ)张量作 out= 输出各跑一例,确认新谓词对非标准 stride 的拒绝分支在 NPU 上判定正确。 low 否 是 compile_stage:Dynamo
Test 修复 Dynamo guard 序列化:缓存重建用加载进程 TLS 致 autocast 失配重编译,改为序列化 build 期 LocalState。 被改精确符号为 torch/_dynamo/guards.py 的 LocalState 可 pickle 化(+13/-2)、torch/csrc/dynamo/guards.cpp(+38/-2,TENSOR_MATCH 用 root guard manager 保存的 LocalState 构造 TensorCheck)与 torch/_dynamo/package.py。对 GuardsState、build 期 LocalState、load_cache_artifacts 这些被改符号在 torch_npu 执行 git grep,torch_npu 中未发现对被改的 GuardsState 序列化结构与 LocalState pickle 逻辑的引用:TENSOR_MATCH 仅命中 test/dynamo/test_comptime.py:194、test/dynamo/test_guard_control.py:253 等 NPU 测试对 guard 类型字符串的断言,属测试观测而非源码依赖。机制上,torch_npu 复用上游 Dynamo guard 序列化与 precompile 缓存框架而不自行 patch 该路径,NPU 上以 autocast(AutocastPrivateUse1)编译保存缓存后再加载时,同样经过被修复的 LocalState 恢复逻辑,故 NPU autocast 缓存场景随上游一并受益,属间接影响。影响类型为缓存加载正确性/性能修正(运行时):修复前 autocast 外加载缓存会重建缺 Autocast 的期望 key 而失配强制重编译。验证方法:在 NPU 上以 TORCH_CACHING_PRECOMPILE=1 保存后加载,运行 test/dynamo/test_aot_compile.py 的 test_aot_compile_autocast_guard_reload(本 PR 新增 +23 行)确认 autocast 缓存不再触发重编译。潜在风险:LocalState 的 pickle 内容变化使旧版 NPU 缓存产物与新版不兼容,跨版本加载旧缓存可能反序列化失败,需清理陈旧缓存,属静默的缓存兼容性问题。此 PR 未被 Revert,维持 Test。 medium 否 是
Test 修复 Dynamo eager_then_compile 下 rank 变化:陈旧 per-source 动态性数据仅适用已记录维度,更高 rank 回退动态。 上游修复 torch/_dynamo/variables/builder.py 中 eager_then_compile 场景下 per-source dynamism 元组在后续更高 rank 编译时越界索引的问题:过期元数据只对已记录维度生效,超出部分回退 automatic dynamic。torch_npu 对 builder.py 无覆写、无赋值 patch、无 fork:torch_npu/utils/_dynamo.py:313 仅 from torch._dynamo.variables.builder import wrap_fx_proxy_cls,该符号本 PR 未改动,修复经上游路径对 NPU 透明生效;torch_npu 的动态形状挂钩在 _TorchDynamoContext 层(见 npu_source_map,与 builder.py 的 dynamism 元数据逻辑无交集)。适配动作:torch_npu fork 了 test/dynamo/test_decorators.py(上游同文件 +36 行回归用例),把新增 rank-change 用例同步进该 fork,并在 npu 设备用 torch.compile(dynamic=...) 先低 rank 后高 rank 的输入序列复跑,确认 NPU 上 automatic dynamic 回退不再触发 IndexError。 low 否 是 compile_stage:Dynamo
Check 避免导出 CPython 私有 opcode 元数据符号:将 PyOpcode* 重命名加 torch 前缀,消除 hermetic 构建 ODR 冲突。 被改精确符号为 torch/csrc/dynamo/cpython_defs.c(+18/-2,将 PyOpcode* 元数据重命名为 torch_PyOpcode* 以避免 ODR 冲突)。对 _PyOpcode、cpython_defs、NEED_OPCODE_METADATA 在 torch_npu 执行 git grep 均未发现引用:torch_npu 中未使用 cpython_defs.c 的 opcode 元数据符号,也不直接链接该 PEP 523 帧求值集成。此改动纯粹是构建/链接层面的符号命名修正——把内部 opcode 元数据定义本地化重命名,防止与 CPython libpython 的 PyOpcode* 重复定义(ODR 违规),不改任何 Python 可见行为或 Dynamo 的 PEP 523 集成逻辑。torch_npu 的 aclgraph/Dynamo 后端复用上游 torch_python 编译产物,其帧求值走上游同一实现,符号重命名对 NPU 运行时透明。影响类型为构建系统 ODR 修正(编译/链接期),仅影响静态 hermetic 链接场景。验证方法:在 NPU 环境若采用 hermetic 静态链接 CPython,回归 torch/csrc/dynamo/cpython_defs.c 编译并用 nm 确认无 PyOpcode* 外部定义泄漏(PR 已用 nm 校验 3.13/3.14)。潜在风险:仅当 torch_npu 的构建也静态链接 CPython 时相关,否则无影响;若 NPU 侧曾本地引用 THP_PyOpcode_Caches 初始化路径,需确认重命名后局部数据仍可用,属可控的构建期风险,不涉及 NPU 运行时功能。 low 否 否
Check 改进 Dynamo 张量类型不匹配 guard 的重编译提示,统一格式化 expected/actual 类型 repr,guard 精确匹配语义不变。 被改精确符号为 torch/csrc/dynamo/guards.cpp 中两处 verbose 张量 guard 路径(TensorGuards check_verbose,+38/-24)。对 guards.cpp、TensorGuards、check_verbose 在 torch_npu 执行 git grep 均未命中:torch_npu 中未发现对 guards.cpp 内部 verbose 消息格式化函数的直接引用。此改动只涉及重编译日志的字符串格式化——把「expected a tensor type」改为打印精确的 expected/actual 类型 repr,不改 guard 的判定逻辑(仍是精确类型匹配)。torch_npu 的 Dynamo/aclgraph 后端复用上游 guard 编译产物,guard 命中/未命中的行为与本 PR 前完全一致,仅诊断文案改善。影响类型为诊断信息可读性变化,非编译或运行时语义变化。验证方法:在 NPU 上以 TORCH_LOGS=recompiles 运行 test/dynamo/test_recompile_ux.py 的 test_mismatched_type 与 test_mismatched_tensor_type(本 PR 新增 +21 行)确认 NPU 张量的 Parameter→Tensor 重编译提示打印正确类型。潜在风险:torch_npu 中未使用被改的消息格式化符号,此 PR 不影响 NPU 功能,仅改善 NPU 用户排查重编译时看到的日志文案。 low 否 否
Test 修复 FlexAttention 对 0-D 标量 score_mod 偏置的反向梯度支持,改动 dynamo 的 _trace_wrapped_higher_order_op、flex_attention higher-order op、inductor 的 flex 反向 lowering 与 select_algorithm,使可学习标量偏置能正确返回梯度,避免 vmap 与 ComputedBuffer name 断言失败。 此 PR 修复 FlexAttention 在标量(0-D)captured score_mod 偏置上的反向梯度:eager 反向原先抛 vmap out_dim is None 的 BatchedTensor 错误,compiled 反向在 Inductor FlexAttention lowering 抛 AssertionError: ComputedBuffer name must not be None。改动跨 dynamo 与 inductor:torch/_dynamo/_trace_wrapped_higher_order_op.py(+13 -1)、torch/_higher_order_ops/flex_attention.py(+13 -2)、torch/_inductor/kernel/flex/common.py(+30 -18,改的是如何创建 captured buffer 的梯度)与 torch/_inductor/select_algorithm.py(+3)。耦合链路:torch_npu 的 NPU inductor 直接复用上游 inductor 的 select_algorithm 与 higher_order_ops 注册表——torch_npu/_inductor/lowering_fx.py:269 有 from torch._inductor.select_algorithm import extern_kernels,torch_npu/_inductor/codegen/triton.py:1802 有 from torch._inductor.select_algorithm import TritonTemplateKernel,且 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:39-40、:808 大量 import 并 register 上游 torch._higher_order_ops。链路为:上游 flex_attention higher-order op 及其 captured-buffer 梯度创建逻辑(torch/_higher_order_ops/flex_attention.py、torch/_inductor/kernel/flex/common.py)→ torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:39 复用 _higher_order_ops 注册 → torch_npu/_inductor/codegen/triton.py:1802 经 TritonTemplateKernel 生成 NPU 反向 kernel → torch_npu/_inductor/lowering_fx.py:269 的 extern_kernels 调度。影响类型为编译反向语义变化:标量偏置的梯度缓冲创建方式改变,NPU flex attention 反向若走 inductor 路径会承接新的 captured buffer 梯度构造逻辑。验证方法:在 NPU 上运行 test/inductor/test_flex_attention.py 本 PR 新增的标量 score_mod 反向用例,比对 compiled 与 eager 梯度、确认无 ComputedBuffer name must not be None 断言。潜在风险:NPU flex attention 反向的 Triton 模板生成与 buffer 命名路径若未同步上游对 0-D captured buffer 的处理,会在 NPU 上复现 ComputedBuffer name 为 None 的编译期断言失败或标量偏置梯度为空的静默错误,需以上述新用例回归定位断裂点。 medium 否 是
Test 修复 AOTAutograd 分区器 SymInt 绑定:原经 ShapeEnv 替换致存 s0 而反向需 u0,改用未替换占位符表达式。 上游把 partitioner 的 backward SymInt 绑定改为用未替换的 placeholder 表达式(新增 _get_placeholder_expr),并连带改写 PythonWrapperCodegen/CppWrapperCpu 的输入符号 codegen(wrapper.py +88-73、cpp_wrapper_cpu.py +57-32)与 symbolic_shapes 辅助逻辑。torch_npu 未 patch/fork partitioners.py,但确认走被改路径:NPUWrapperCodeGen 继承 PythonWrapperCodegen(torch_npu/_inductor/codegen/wrapper.py:131)且未覆写符号绑定相关方法(仅覆写 write_header/write_prefix/generate_return/define_kernel 等,write_prefix 首行即 super().write_prefix(),wrapper.py:325-326);CppWrapperNpu 覆写 codegen_inputs 但仅前置对齐检查后调 super().codegen_inputs()(torch_npu/_inductor/codegen/cpp_wrapper.py:354-375),上游输入符号绑定改动经继承透明生效;fork 的 lowering 还直接调用 symbolic_shapes 的 free_unbacked_symbols/resolve_unbacked_bindings(torch_npu/_inductor/lowering_fx.py:950、torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:3213-3226)。适配动作:将上游 test/inductor/test_unbacked_symints.py 新增的 150 行 backward 绑定用例移植到 torch_npu 的 test/_inductor/,并回归 torch_npu fork 的 test/dynamo/test_aot_autograd.py(上游同文件 +71 行),重点覆盖 unbacked SymInt(u0 有 replacement)+ backward runtime assertion 场景,确认 NPU wrapper 生成的符号绑定不缺失。 medium 否 是 compile_stage:AOTAutograd
Test 在 Inductor 模式匹配器新增基于值的 get_attr 匹配,使被 trace 的张量常量可转为 PatternExpr 而不误匹配无关属性。 被改精确符号为 torch/_inductor/pattern_matcher.py 中 get_attr 的值匹配逻辑(+173)与 torch/_logging/_internal.py(+9/-3),新增 PatternExpr 转换能力。对 pattern_matcher、PatternExpr、register_replacement 在 torch_npu 执行 git grep:命中 torch_npu/npu/npugraph_ex/init.py:7 的 from torch._inductor.pattern_matcher import fwd_only, SearchFn, ReplaceFn, TraceFn, PatternExpr,并在 :26 以 search_fn_pattern: Union[PatternExpr, None]、:30 调用 pattern_pass_manager.register_replacement;另在 torch_npu/_inductor/npu_fusion_attention_graph.py:165 的 from torch._inductor.pattern_matcher import register_replacement, fwd_only, joint_fwd_bwd 与 :256 的 register_replacement(**register_replacement_kwargs) 处再次直接引用。耦合链路为:上游 pattern_matcher 的 PatternExpr/register_replacement 匹配框架 → torch_npu/npu/npugraph_ex/init.py:30 的 register_replacement 用它注册 NPU 图替换模式,torch_npu/_inductor/npu_fusion_attention_graph.py:256 用它注册 NPU 融合注意力 SFDP 替换 → 两条注册均在 NPU Inductor 后端初始化时执行。本 PR 新增 get_attr 值匹配为增量能力,未删改 PatternExpr/register_replacement 公共签名,故上述两处 NPU 导入与调用不断裂。影响类型为图匹配能力扩展(编译期),可能改变哪些子图被匹配替换。验证方法:在 NPU 上运行 test/inductor/test_pattern_matcher.py(本 PR 新增 +185 行)并回归 npugraph_ex 与 npu_fusion_attention_graph 的模式注册确认无误匹配。潜在风险:若 NPU 图含被 trace 的张量常量属性,新 get_attr 匹配可能使某些子图额外被替换,需确认 npu_fusion_attention_graph 的 SFDP 模式不因新语义产生非预期融合,属行为变化型风险。 medium 否 是
Check 修复 CPU bool 累加 index_put codegen:原子加 fallback 仅限 GPU,为 CPU 补 bool CAS 与 VecMask 重载。 上游将 index_put accumulate 的 atomic-add fallback 由「仅按 dtype」改为「dtype + GPU 设备」门控(torch/_inductor/lowering.py),并只在 CPU 专属的 cpp_prefix.h 增加 bool 原子加支持。torch_npu 通过 torch_npu/_inductor/utils.py:37 的 GPU_TYPES.append("npu") 使 NPU 命中新的 is_gpu 门控,NPU 设备上的 fallback 行为与改动前完全一致。torch_npu fork 的 lowering(torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:3843)仍保留旧的 dtype-only 判定 needs_fallback_due_to_atomic_add_limitations(self.get_dtype()),但该 fork 仅编译 npu 设备图,与上游新逻辑在 NPU 设备上结果相同,无需改码;下次同步该 fork 文件时按上游 device 门控更新第 3843 行即可对齐。cpp_prefix.h/atomic_add_vec 为 CPU CPP codegen 专属,torch_npu 全仓零引用(NPU 走 Triton/CATLASS/MLIR 独立 codegen),不受影响。 low 否 是 compile_stage:Inductor
Check 对 Inductor ComboKernel 分区诊断按分区上下文限流,使等价重编译不再重复发相同 DEBUG 日志,调度启发式保持不变。 被改精确符号为 torch/_inductor/codegen/triton_combo_kernel.py 中 ComboKernel 分区诊断限流逻辑(+86/-4)。对 combo_kernel、ComboKernel 在 torch_npu 执行 git grep:ComboKernel 命中 tools/linter/adapters/docstring_linter-grandfather.json:107 的类记录,combo_kernel 命中 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:208 的 config.combo_kernel_foreach_dynamic_shapes 配置引用。耦合链路为:上游 triton_combo_kernel.py 的分区诊断日志发射 → torch_npu 的 ascend_npu_ir inductor_patch 在 lowering.py:208 读取 combo_kernel 相关 config 决定是否走 combo kernel foreach 动态形状路径;本 PR 只对 DEBUG 日志按分区上下文做去重限流,未改分区/调度启发式与任何 config 语义。影响类型为日志噪音抑制(编译期诊断),非功能变化。验证方法:在 NPU 上运行 test/inductor/test_combo_kernels.py(本 PR 新增 +258 行)确认 NPU combo kernel 编译产物与调度决策不变,仅重复 DEBUG 日志减少。潜在风险:限流按 partition context 去重,若 NPU 侧依赖完整 DEBUG 日志做性能剖析,部分重复上下文日志会被抑制,需确认这不影响 NPU 编译问题排查,属可控的诊断可观测性变化而非正确性风险。 low 否 是
Check 为 Inductor 持久化 worker 显式重置缓存环境变量,使 fresh_cache 不再让子进程残留陈旧缓存目录,并同步 libdevice 路径。 被改精确符号涉及 torch/_inductor/async_compile.py、autotune_process.py、runtime/compile_tasks.py(worker 环境变量重置)与 utils.py(+36),共 649 行大改动。对 async_compile、autotune_process、fresh_cache 在 torch_npu 执行 git grep:async_compile 命中 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/codecache.py:18 的 from torch._inductor.async_compile import (...),autotune_process 命中 torch_npu/contrib/transfer_to_npu.py:537 的 torch._inductor.autotune_process.get_gpu_type = _get_npu_type。耦合链路为:上游 async_compile 的持久化 worker 池启动流程 → torch_npu 的 ascend_npu_ir codecache 复用 async_compile 提交 NPU kernel 编译任务,同时 transfer_to_npu.py 在导入期猴补 autotune_process.get_gpu_type 使其返回 NPU 类型;若本 PR 改动了 worker 进程的环境变量传递或 get_gpu_type 附近逻辑,NPU 的编译子进程缓存目录与 gpu 类型探测可能受影响。影响类型为编译期缓存与子进程环境行为变化,接口未破坏(属内部重构)。验证方法:在 NPU 上运行 test/inductor/test_compile_worker.py(本 PR 新增 +342 行)确认 NPU worker 在 fresh_cache 后不复用陈旧缓存目录,且 transfer_to_npu 的 get_gpu_type patch 仍生效。潜在风险:环境变量重置若把 NPU 编译所需的自定义缓存路径变量一并清空,可能导致 NPU worker 缓存命中率下降或重复编译,属静默的性能问题而非报错。 medium 否 是
Check 在 emulate_precision_casts 模式下为低精度 cast barrier 补回归覆盖,确保 fp16/bf16 convert 不回退。 本 PR 对 torch/_inductor/lowering.py 仅新增 2 行澄清注释(emulate_precision_casts 的显式 convert barrier 行为已存在于 main),其余 167 行全部是 CPU/CUDA 回归测试(test_cpu_repro.py +151、test_cuda_repro.py +16),无任何功能变更。torch_npu fork 了 make_pointwise 的低精度舍入逻辑两处:torch_npu/_inductor/lowering_fx.py:399-428(用 node meta 'low_precision_pointwise_barrier' 门控 fp16/bf16 downcast-upcast,与上游 config.emulate_precision_casts 门控实现已有意分叉)和 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:675-704。因上游净变更为注释+测试,两处 fork 无需改码;维护动作是在下次 fork 同步时对照上游 make_pointwise 的新注释确认两处 fork 的 fp16/bf16 舍入语义未落后,并可把上游 fp16 溢出/bf16 舍入回归用例移植到 torch_npu 的 test/_inductor/(现有 test_check_accuracy.py 同目录)作为 NPU 侧精度基线。 low 否 是 compile_stage:Inductor
Test 让 Dynamo 中 str.split/rsplit/splitlines 的结果建模为带 ValueMutationNew 的可变 ListVariable,匹配 CPython 的新建可变列表语义,使对结果的原地修改不再触发副作用断言并 graph-break。 上游 #188306 修改 torch/_dynamo/variables/constant.py 的 ConstantVariable.call_method,使 str.split/rsplit/splitlines 返回带 ValueMutationNew() 的可变 ListVariable(A 轨纯行为修复,无接口/签名变化)。源码核查确认 torch_npu 未挂钩该符号:torch_npu/utils/_dynamo.py:62/74/254 仅调用 ConstantVariable.create() 构造常量,不调用也不覆写 call_method;仓库内唯一的 call_method 赋值式 patch 是 TensorVariable.call_method = TensorVariable_call_method(torch_npu/utils/_dynamo.py:85),针对 TensorVariable 而非 ConstantVariable,二者无交集;constant.py 不在 npu_source_map fork 清单,改动经上游透明生效,NPU trace 同路径直接受益(str 方法结果可被 shuffle/sort/append 而不再 graph break)。torch_npu 自带上游测试副本 test/dynamo/test_functions.py(git ls-tree HEAD test/dynamo/ 命中),适配动作仅为:下次同步该测试副本时带入上游新增用例 test_str_split_returns_mutable_list,随常规 dynamo 用例集在 NPU 上执行即可,无需修改 torch_npu 代码。 low 否 是 compile_stage:Dynamo
Test 在 Dynamo polyfill 补齐三处迭代器协议边角:序列迭代器增 setstate 与 OverflowError、可调用迭代器重查耗尽。 本 PR 改动 torch/_dynamo/polyfills/builtins.py(+22),为 Dynamo 的 builtins polyfill 补齐三处迭代器协议边角:_SequenceIterator 新增 setstate(负参 clamp 到 0)、next 达 sys.maxsize 抛 OverflowError、_CallableIterator.next 调用后重查耗尽以抛 StopIteration,全部镜像 CPython Objects/iterobject.c,配套 test/dynamo/test_misc.py(+74)与删除 3 个 CPython313 xfail。属 Dynamo trace 时对 Python 迭代器语义的行为对齐。对 _SequenceIterator、_CallableIterator、polyfills 执行 git grep,torch_npu 中未使用这些符号,此 PR 不影响 NPU 功能。耦合链路上,NPU 的 Dynamo 后端在 torch_npu/dynamo/ 与 torch_npu/utils/_dynamo.py:15(引用 InstructionTranslator)通过 backend 注册接入,polyfill 属 Dynamo 前端与后端无关的通用 trace 逻辑,NPU 编译的图在 polyfill 层已完成迭代器展开后才交给 NPU 后端,故 NPU 后端接收的 FX 图行为随之对齐但无需 NPU 侧改动。影响类型为 trace 期迭代器边角语义变化。验证方法:在 NPU 上 torch.compile 含 iter()/callable-iter 边角的模型,确认 trace 结果与 eager 一致。潜在风险:若 NPU 模型依赖旧 polyfill 的错误迭代器语义,新对齐后可能改变图结构,属编译期行为变化需回归验证。 low 否 是
Check 重写 Dynamo 异常处理贴近 CPython 语义,主改 symbolic_convert 异常传播与 functions 调用处理;已被 Revert。 本 PR 重写 Dynamo 异常处理以贴近 CPython,改动 torch/_dynamo/symbolic_convert.py(ExceptionStack 方法改名 set_current_exception→set_raised_exception、get_current_exception→get_raised_exception,新增 do_raise/set_exception_obj/_create_exception_instance,删除 _isinstance_exception)、exc.py、variables/functions.py。torch_npu 与 symbolic_convert 的唯一耦合是 torch_npu/utils/_dynamo.py:15 from torch._dynamo.symbolic_convert import InstructionTranslator——仅 import InstructionTranslator 类本身(用于 patch TensorVariable.call_method 处理 .type()/record_stream),该类未被删除或改名,被改的 ExceptionStack 方法/do_raise 均非 torch_npu 引用符号;torch_npu/_inductor/ascend_npu_ir/.../npu_inductor_plugin.py:156 import 的 unimplemented 也未受影响。人工确认 InstructionTranslator import 路径与 unimplemented 仍可用即可,无需改代码。 low 否 否 compile_stage:Dynamo
Check 将谓词 is_opaque_type/is_opaque_value 重命名为 is_custom_class 系列,旧名保留为发 warning 的兼容包装。 该 PR 把 is_opaque_type→is_custom_class、is_opaque_value→is_custom_class_obj 重命名(41 文件多为 +2-2 同步改名),且 PR 正文明确旧名保留为 log.warning 包装器(向后兼容不破坏调用方)。torch_npu 全包 grep 四个新旧名(is_opaque_type/is_opaque_value/is_custom_class/is_custom_class_obj)均 0 命中,说明 torch_npu 既未 import 也未 patch 这些自定义 class 判定函数,改动完全不触及 NPU 挂钩点(Dynamo 挂钩集中在 torch_npu/dynamo/trace_rule.py 的 torch_name_rule_map 与 torch_npu/utils/_dynamo.py 的两个自定义 VT,均无 opaque_type 依赖)。人工确认即可,无需改码。 low 否 否 compile_stage:Dynamo

likedislike
Rrmch成员
8月4日 修改了issue 的描述
rmch成员
8月4日 评论:

Check 将 Dynamo 变量追踪器 TorchScriptObjectVariable 等改名为 CustomClass 系列,属内部重命名重构,同步调用点与测试。 该 PR 把 Dynamo 变量追踪器 TorchScriptObjectVariable→CustomClassObjectVariable、OpaqueObjectClassVariable→CustomClassVariable 重命名(torch/_dynamo/variables/script_object.py 等 +14-14 同步改名)。按 npu_source_map,torch_npu 全部自定义 VariableTracker 仅 NPUTorchCtxManagerClassVariable、NPUAutocastModeVariable(torch_npu/utils/_dynamo.py),不含也不继承被重命名的两个 VT 类;全包 grep 四个新旧类名 0 命中,torch_npu 既未继承这两个类、也未 import 引用、无赋值式 patch,被改上游文件不在 fork 清单。故该重命名对 NPU 透明,人工确认 NPU 的 script object / custom class 图捕获路径无回归即可,无需改码。 low 否 是 compile_stage:Dynamo
Check 将谓词 is_opaque_value_type 等重命名为 is_opaque_constant/symbolic_type,旧名留作发警告的兼容包装。 本 PR 仅将 opaque object 谓词 is_opaque_value_type→is_opaque_constant_type、is_opaque_reference_type→is_opaque_symbolic_type 改名(旧名保留为 deprecated wrapper),改动集中在 torch/_library/opaque_object.py、torch/_dynamo/variables/script_object.py、builder.py 等 opaque/torchbind 处理路径。torch_npu 完全不使用 opaque object 机制:其自定义 VariableTracker 仅 torch_npu/utils/_dynamo.py 的 NPUTorchCtxManagerClassVariable/NPUAutocastModeVariable(只覆写 call_function/create),未继承或覆写 script_object.py 相关类,也未 import opaque_object。A 轨改名改动对 NPU 透明,无需适配。 low 否 否 compile_stage:Dynamo
Test 为 functorch 补齐 searchsorted 标量重载的 batch rule,使 vmap 能经分解处理标量版本并移除对应 xfail。 本 PR 改动 aten/src/ATen/functorch/BatchRulesReduceOps.cpp(+13),为 searchsorted 的 scalar 重载补齐 functorch vmap 的 batch rule(经分解实现),并在 test/functorch/test_vmap.py 移除 3 行对应 xfail。属 functorch/_functorch vmap 变换的行为变更。对 searchsorted 执行 git grep,torch_npu 在 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:2386 处 @register_lowering(aten.searchsorted.Tensor) 注册了 searchsorted 的 NPU inductor lowering,另在 torch_npu/csrc/inductor/aoti_torch/generated/c_shim_npu.h:137 生成了 aoti_torch_npu_searchsorted_Scalar 的 AOTI C-shim。耦合链路:上游为 searchsorted.Scalar 补齐 vmap batch rule → 若用户在 NPU 上对标量版 searchsorted 做 vmap,分解后落到 aten searchsorted → NPU 的 inductor lowering(lowering.py:2386) 或 AOTI c-shim(c_shim_npu.h:137) 执行。影响类型为 functorch 分解规则新增,属 API 能力扩展。验证方法:在 NPU 上跑 test/functorch/test_vmap.py 中 searchsorted scalar 用例,确认 vmap 分解链路在 NPU 算子上数值正确。潜在风险:若 NPU 的 searchsorted 实现对分解产生的标量到张量提升语义处理不同,vmap 结果可能与 CPU 参考不一致,属数值差异。 medium 否 是
Test 为 Inductor 的逐点与归约 Triton 内核启用主机侧 TMA 描述符,含预扫描判定、签名升级与回退,共 534 行大改动。 该 PR 为 host-side TMA 新增能力(B 轨新功能),主体 +222 行落在 torch/_inductor/codegen/triton.py,而 torch_npu 正是 fork 了该上游文件(torch_npu/_inductor/codegen/triton.py),fork 清单命中,'零引用'不构成放行证据。torch_npu/_inductor/utils.py:87-92 的 patch_device_supports_tma 令 NPU 的 _device_supports_tma 返回 torch.npu.is_available() and not torch.version.hip,即 NPU 声明支持 TMA,会走 TMA 相关代码生成分支;torch_npu/_inductor/codegen/cpp_wrapper.py:591-600 已含 nvTmaDesc 相关处理。上游 triton.py 的 host-side TMA 逻辑(signature 升级为 tensordesc、_is_host_tma_materializable、tma_min_block_sizes 泄漏修复)不会自动进入 NPU 的 fork 副本,需在 NPU 环境运行 pointwise/reduction 图模式用例并对比 torch_npu/_inductor/codegen/triton.py 与上游本次改动,评估是否同步 host-side TMA 逻辑。 medium 待确认 是 compile_stage:Inductor
Test 修复 SymNumberMemoDescriptor 对 inference FakeTensor 跳过 memo 的缺陷,改为始终存 memo,改 52 行。 该 PR 改 torch/_subclasses/fake_tensor.py 的 SymNumberMemoDescriptor.set/get,令 inference FakeTensor 也存 memo(仅跳过 _version 存储与 staleness 校验),属 FakeTensor memo 的行为变化、接口/签名不变。torch_npu 全包 grep SymNumberMemoDescriptor 0 命中,且唯一 fork fake_tensor.py 的 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/fake_tensor.py 只复制并 patch run_fallback_kernel(第83-84行 fake_tensor.run_fallback_kernel = _npu_run_fallback_kernel),不涉及 SymNumberMemoDescriptor,故该行为变化对 NPU 经继承透明生效。因涉及 export/AOTI 下 nonzero + boolean indexing 的 unbacked symint 行为,在 NPU 环境跑 test/test_fake_tensor.py 中 inference-mode memo 相关用例验证一致性,无需改码。 low 否 是 compile_stage:Inductor
Test 为 philox 无状态 RNG 算子在 Inductor reinplace 注册表加条目,消除 compile 下函数式变体的额外 clone。 本 PR 改动 torch/_inductor/fx_passes/reinplace.py(+4),向 Inductor 的 reinplace FX pass 的 inplaceable_ops 注册表增加 philox uniform/normal 无状态 RNG 算子条目,使 torch.compile 不再对这些算子的函数式变体做多余 clone,配套 test/test_stateless_rng.py 新增 30 行。属 Inductor FX pass 的编译期就地化重写逻辑变更。对 inplaceable_ops、reinplace、philox 执行 git grep,torch_npu 在 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:2170 处 @register_lowering(torch.ops.rngprims.philox_rand) 注册了 philox_rand 的 NPU lowering,NPU RNG 编译路径直接处理 philox 算子;另一耦合点在 torch_npu/csrc/aten/NPUGeneratorImpl.cpp:82 的 set_philox_offset_per_thread,NPU Generator 维护 philox offset 状态。耦合链路:上游 reinplace pass 对 philox 算子的就地化决策 → torch_npu inductor_patch/lowering.py 的 philox_rand NPU lowering 消费同类算子 → NPUGeneratorImpl 提供 philox offset。影响类型为编译期 buffer 分配与就地化行为变化。验证方法:在 NPU 上跑 test/test_stateless_rng.py 对应无状态 RNG 用例,确认 NPU lowering 下 philox 算子不产生 2x 缓冲分配且数值随机流一致。潜在风险:若 NPU 的 philox lowering 与上游 inplaceable_ops 就地化假设不一致,可能出现 buffer 被提前覆盖导致随机数结果静默错误。 medium 否 是
Test 修复 proxy tracing 无法重建 sympy.Pow 的缺陷,将 pow_by_natural 映射到 operator.pow,改 70 行。 本 PR 修复 torch/fx/experimental/proxy_tensor.py 中 _build_proxy_for_sym_expr 无法重建 sympy.Pow 的 bug,将 _sympy_handlers() 里 pow_by_natural 映射到 operator.pow(仿照已有 maximum/minimum 特例)。这是 dynamic shapes 下 proxy tracing 的内部 helper 修复,torch_npu 未 fork proxy_tensor.py,也未 import 被改的内部符号——torch_npu/_inductor/lowering_fx.py:56 与 ascend_npu_ir/.../meta_kernel.py:39 仅 from torch.fx.experimental.proxy_tensor import make_fx(公共 API),make_fx 内部会经此修复路径。NPU 在 dynamic=True 全归约(如 numel=s0s1**2)场景会走该 proxy 重建路径,行为变化(原会 RuntimeError,现正确重建),在 NPU 上运行 test/fx/test_proxy_tensor_api.py 及动态 shape 全归约用例验证兼容性,无需改 torch_npu 代码。 low 否 是 compile_stage:AOTAutograd
Test 修复上池化解构在 CPU channels-last 输入下总产出连续布局的问题,按建议内存格式重排 2D 路径步长,共 35 行。 该 PR 修改 torch/_decomp/decompositions.py 中 _max_unpoolnd 分解,仅对 CPU 的 2D 情形按 suggest_memory_format(input) 重排输出 stride,使 channels-last 输入编译后与 eager 的 stride 一致(值本就正确,仅 stride 变化);CUDA 2D 与 3D 路径不变。对 max_unpool、decomposition 执行 git grep,torch_npu 存在耦合:torch_npu/_inductor/init.py:81 引入 _register_npu_inductor_decompositons 并在 :143 注册,torch_npu/_inductor/_npu_meta_registration.py:75 的 patch_torch_inductor_decompositions 与 :90 的 patch_torch_decomp_decompositions 覆写上游分解表。耦合链路为:上游 decompositions.py 的 max_unpool2d 分解 stride 语义按设备分支变化 → torch_npu/_inductor/_npu_meta_registration.py 覆写的 NPU 分解表继承 torch._decomp 的基础分解 → torch_npu/_inductor/init.py:143 注册后 NPU inductor 编译 max_unpool2d 时的输出 memory_format 依赖该分解;由于新逻辑以 device 判定(仅 CPU 走重排),NPU(PrivateUse1)不落入 CPU 分支,可能仍产出 contiguous,与 NPU eager 的 channels-last 期望不一致。影响类型为编译期输出 stride/memory_format 变化。验证方法:在 NPU 上以 channels-last 输入 torch.compile 运行 max_unpool2d,比对 eager stride,运行 test/inductor/test_torchinductor.py 的 max_unpool 用例。潜在风险:NPU 编译路径若未针对性对齐 memory_format,会出现 stride 不匹配的 opinfo 失败或下游 channels-last 算子布局退化。 medium 否 是
Test 修复 standalone_compile 对 Tensor 子类的 fake mode 检测,改用 maybe_get_fake_mode 复用旧 mode。 本 PR 改动 torch/_inductor/standalone_compile.py(+4 -2),将 from_graph 路径下对图输出的 isinstance(FakeTensor) 直接判断替换为 maybe_get_fake_mode,使其能穿透可追踪包装子类内层 FakeTensor 复用同一 FakeTensorMode,配套 test/inductor/test_codecache.py 新增 36 行子类回归用例。此为 Inductor standalone_compile 前端的动态形状状态恢复逻辑变更,属编译期行为变化。对 torch_npu 执行 git grep 搜索 maybe_get_fake_mode 与 standalone_compile,torch_npu 中未使用这两个符号,此 PR 不影响 NPU 功能。耦合链路上,NPU 的 Inductor 适配在 torch_npu/_inductor/ 下通过独立的 lowering/wrapper patch 接入,其 FakeTensor 处理位于 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/fake_tensor.py,走 ascend_npu_ir 独立实现,不经过上游 standalone_compile 的 fake mode 检测分支。影响类型为编译期动态形状元数据恢复,不涉及运行时数值或 API 签名。验证方法:若后续 NPU 接入 standalone_compile,应跑 test/inductor/test_codecache.py 的 dynamic_shapes_from_graph 子类用例确认子类图不再回退到新 ShapeEnv。潜在风险:若 NPU 侧未来复用该路径而误建新 ShapeEnv,会导致动态形状 guard 失配而重新编译,属静默性能退化而非报错,需在 NPU 编译栈对齐同一 helper。 low 否 否
Check Inductor 将到达同一首次使用节点的多个输入 size/stride 断言合并为一条 C++ guard,减少热路径重复派发,保留单输入旧路径。 本 PR 为 inductor standalone compile 热路径新增分组 size/stride 断言:torch/_inductor/codegen/wrapper.py 新增 write_assert_size_stride_grouped/_codegen_assert_size_stride_grouped 与 GroupedAssertSizeStrideLine,并改 codegen_deferred_input_asserts 在多断言时合并为一次分组调用;torch/csrc/dynamo/guards.cpp + _C/_dynamo/guards.pyi 新增 assert_size_stride_grouped,现有 assert_size_stride 签名保持不变。torch_npu 的 NPUWrapperCodeGen 经 _NPUKernelCodegenMixin.codegen_input_size_asserts(torch_npu/_inductor/codegen/wrapper.py:76)将 input size assert 直接覆写为 no-op(pass),且未覆写本 PR 修改的 codegen_deferred_input_asserts(0 命中),新增的 assert_size_stride_grouped 也未被引用;torch_npu/_inductor/ir.py:91 的 patch_extern_kernel_codegen_size_asserts 只 patch ExternKernel.codegen_size_asserts(本 PR 未触及)。torch_npu 消费的 assert_size_stride/assert_alignment(ascend_npu_ir/.../codegen/wrapper.py:86,90、lowering_fx.py:280)签名未变。人工确认 NPU 不走上游分组断言路径即可,无需改代码。 low 否 是 compile_stage:Inductor
Check 在 extract_tensor_metadata 热路径将 layout 与稀疏判定读取去重复用,抵消 property 化的指令数回归。 该 PR 仅在 torch/_subclasses/fake_tensor.py 的 extract_tensor_metadata 内把 t.layout 与 is_sparse_any(t) 的重复读取去重(11 次降到 4 次),PR 正文明确产出的 TensorMetadata/dispatch cache key 逐位一致,是纯读去重、无接口/签名/行为变化。torch_npu 唯一 fork 该上游文件的 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/fake_tensor.py 复制的是 run_fallback_kernel(第19-84行)并赋值式 patch fake_tensor.run_fallback_kernel(第83-84行),并未 fork 或引用 extract_tensor_metadata,其 import 的 is_sparse_any(第13行)也与被改函数无关。torch_npu/_inductor/utils.py:18 的 is_mkldnn 判断走独立逻辑、不经 extract_tensor_metadata。人工确认 NPU FakeTensor 元数据路径无回归即可,无需改码。 low 否 是 compile_stage:Inductor
Check 把 CompiledArtifact 序列化校验抽为共享 _validate_and_unpack() 并去重,改 64 行。 被改符号为 torch/_inductor/standalone_compile.py 中 CompiledArtifact._validate_and_unpack 与 _to_binary_bytes、save(format='unpacked') 的重复校验逻辑合并。对 standalone_compile、CompiledArtifact、_validate_and_unpack、_to_binary_bytes 执行 git grep,torch_npu 中未使用这些符号,此 PR 不影响 NPU 功能。补充机制说明:standalone_compile 是上游 inductor 的独立编译产物保存/加载路径,NPU 的 inductor 后端在 torch_npu/_inductor 目录独立实现 codegen 与产物管理,未复用上游 CompiledArtifact 的二进制/unpacked 序列化校验;本 PR 是纯内部重构——把两处 verbatim 的校验拷贝抽成一个 helper 并统一错误消息措辞,(artifact_bytes, cache_info, key) 返回结构与对外 save/load 接口不变。影响类型为内部实现重构,接口签名未变,非运行时或数值路径改动。隐性风险点:因是等价重构且 NPU 未接入该 standalone_compile 路径,无编译产物兼容性影响;若未来 NPU 复用上游 standalone 编译保存,要核对 _validate_and_unpack 的错误措辞变化是否破坏依赖旧消息文本的断言,当前无实际影响。 low 否 否
Check 让 Dynamo minifier repro 回放第三方 Inductor 后端 config 并序列化 Triton 导入,改 192 行。 被改符号为 torch/_dynamo/repro/after_aot.py 的 write_kernel_dependencies 与 torch/_dynamo/debug_utils.py 的 generate_config_string,前者新增探测 triton/triton.
引用并 emit 额外 import,后者把已注册 custom_backend_codegen_configs 的非默认值写入 repro。对 generate_config_string、write_kernel_dependencies、custom_backend_codegen_configs 执行 git grep,torch_npu 中未使用这些符号,此 PR 不影响 NPU 功能。补充机制说明:NPU 的 inductor 后端在 torch_npu/_inductor 目录独立实现 lowering/codegen,其 repro/minifier 复现能力若需要也是走 NPU 自己的调试路径,并不复用上游 after_aot repro 的 config 序列化与 Triton import 注入逻辑;本 PR 仅增强上游 minifier 生成脚本的可复现性(把第三方后端 config 与 Triton 额外 import 写进 repro),属调试工具增强而非编译 IR 语义变化。影响类型为调试/工具层,非运行时或数值路径。隐性风险点:若未来 NPU 复用上游 minifier 生成 repro,要核对 NPU 自定义后端的 ConfigModule 覆盖能否被 generate_config_string 正确回放,否则复现脚本可能漏配后端配置;当前 NPU 未接入该路径,无实际影响。 low 否 否
Check 放宽 Inductor 模板与外部内核注册时的硬断言,使同名等价重复注册被容忍而非崩溃,真正冲突仍报错,共 103 行。 该 PR 修改 torch/_inductor/select_algorithm.py 与 torch/_inductor/codegen/cutedsl/cutedsl_template.py,将 TritonTemplate、CuteDSLTemplate、ExternKernelChoice 注册进程级全局注册表时的硬断言放宽为:同名且等价(模板源码 hash 一致或包装 callable 一致)的重复注册被容忍,真正的异名冲突仍抛错,以修复模块被二次 import 时的导入期崩溃。对 select_algorithm、TritonTemplate 执行 git grep,torch_npu 存在耦合:torch_npu/_inductor/codegen/triton.py:1802 从 torch._inductor.select_algorithm import TritonTemplateKernel 并在 :1804 判断 isinstance,torch_npu/_inductor/lowering_fx.py:269 从 select_algorithm import extern_kernels。耦合链路为:上游 select_algorithm.py 的注册表断言放宽属内部实现健壮性重构,接口签名不变 → torch_npu/_inductor/codegen/triton.py:1802 与 torch_npu/_inductor/lowering_fx.py:269 引用的仍是 TritonTemplateKernel/extern_kernels 类与符号本身,未依赖被改的断言分支,故 NPU inductor 的模板选择逻辑不受行为影响,反而在 NPU 侧存在双重 import 场景时同样受益于不再崩溃。影响类型为内部注册健壮性重构(接口不变)。验证方法:人工确认 torch_npu/_inductor 在初始化时不会因重复注册模板而崩溃,运行 test/inductor/test_template_registration.py。潜在风险:若 NPU 曾依赖旧的严格断言来发现自身模板重名,放宽后同名等价注册被静默接受,需 Review 确认 NPU 自定义模板 hash 计算与上游等价判定一致。 low 否 是
Test 为 linalg_polar 补全 dynamo trace_rules 与 inductor lowering:将 torch._C._linalg.linalg_polar 加入图内 C 绑定函数表,并注册 aten.linalg_polar 的 inductor lowering,修复其在 XPU 上 torch.compile 报错。 上游为设备无关的 linalg_polar 算子补齐 dynamo trace_rule(torch/_dynamo/trace_rules.py 向 torch_c_binding_in_graph_functions 加 torch._C._linalg.linalg_polar)与 inductor lowering(torch/_inductor/lowering.py),修复其在 XPU inductor 下的 skip/MissingOperator 报错。git grep 'linalg_polar' HEAD 在 torch_npu 0 命中——torch_npu 未 fork 上游 torch_c_binding_in_graph_functions 字典,而是在 torch_npu/dynamo/trace_rule.py:56 维护独立的 torch_c_binding_in_graph_functions_npu = dict.fromkeys([...])(仅含 torch_npu._C.npu* 符号),:93 append 到 torch_name_rule_map,与上游被改字典无耦合。linalg_polar 为 CPU/CUDA/XPU dispatch 的通用线代算子(B 轨新增),NPU 若在 npu 上跑 torch.compile 触发 linalg_polar 需依赖上游新增的通用 lowering + 自身 dispatch,改动经上游 lowering 表透明生效,torch_npu 无需改代码。适配方案:无需改 torch_npu 代码;如需覆盖,在 NPU 环境跑 linalg_polar 的 torch.compile 用例(参照上游 test/inductor/test_torchinductor_opinfo.py 的 test_comprehensive_linalg_polar)验证 NPU 后端下 lowering 是否命中或需 fallback。 low 否 是 compile_stage:Dynamo
Shim 修复 expand lowering 缺 implicit 形参,导致 autograd 生成的 expand 反向编译抛 TypeError 失败。 上游修复 torch/_inductor/lowering.py 的 expand lowering 缺失 implicit kwarg 问题——autograd(mean_backward/broadcast-backward)会发射 aten.expand.default(..., implicit=False),register_lowering 原样转发 kwargs,旧签名 def expand(x, sizes) 触发 TypeError: expand() got an unexpected keyword argument 'implicit',导致所有经 autograd 生成 expand 的反向编译失败。git grep 'def expand' HEAD 抓出 torch_npu 有两处 fork 的 expand lowering,签名同样是 def expand(x, sizes) 且均带 @register_lowering(aten.expand):torch_npu/_inductor/lowering_fx.py:948-949 与 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:1178-1179(示例 15 fork 耦合,复制上游函数体带同一 bug)。这两个 NPU lowering 覆盖注册了 aten.expand,NPU 反向编译遇到 autograd 发射的 expand(implicit=False) 时会命中相同 TypeError。适配方案:将两处 def expand(x, sizes) 改为 def expand(x, sizes, implicit=False) 并丢弃 implicit(与上游一致),同步检查同文件 expand_as(lowering_fx.py:976、inductor_patch/lowering.py:1223)转发。验证方法:在 NPU 上编译 torch.compile(lambda a: a.mean()).backward() 等含 autograd expand 的反向图,或移植上游 test/inductor/test_torchinductor.py::test_expand_implicit_kwarg。 high 是 是 compile_stage:Inductor
Check 修复 control_deps lowering 中 OrderingBarrier 的两个依赖键 bug:additional_buffer_deps 改用 operation name 作键、buffer name 作值,且 ordering_only 从 buf.node 而非 SchedulerBuffer 读取,使 barrier 走弱依赖路径并正确排序。 上游修复 control_deps_op_lowering 中 passthrough OrderingBarrier 在 V.graph.additional_buffer_deps 的键/值错误(应 barrier.get_operation_name()→op.get_name(),lowering.py)及 compute_dependencies 中 ordering_only 误读 SchedulerBuffer 而非其 IR node(scheduler.py),使 OrderingBarrier 走弱依赖路径正确定序。git grep 'OrderingBarrier'/'additional_buffer_deps'/'ordering_only' HEAD 在 torch_npu 均 0 命中——torch_npu 未引用这些被改的内部符号。torch_npu 仅把 control_deps 函数当作图算子 target 引用:torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/config.py:8 from torch._inductor.fx_passes.control_dependencies import control_deps、:239 放入 NON_POINTWISE_OPS,torch_npu/_inductor/dvm/mlir_fusion.py:5/:42 放入 GENERATE_LIST,二者只用于融合白名单匹配算子类型,不介入 OrderingBarrier 的依赖键装配与 scheduler 定序内部逻辑。该修复是上游 scheduler+lowering 的设备无关 bug fix,经上游 compute_dependencies 在 NPU Triton 调度路径透明生效。适配方案:无需改 torch_npu 代码;人工确认 NPU 使用 control_deps 的融合白名单(config.py:239、mlir_fusion.py:42)在弱依赖定序修复后行为无回退即可。验证方法:在 NPU 上运行含 control_deps/user-stream 定序的 torch.compile 图,观测算子执行顺序是否正确。 low 否 是 compile_stage:Inductor
Test 改动 Inductor 的 FallbackKernel IR 生成逻辑,单输出的 fallback kernel 不再包裹进 MultiOutputLayout 而直接表示,同时保留未定符号处理与运行时派发的输出命名,属 146 行中等改动。 上游 PR 184279 改变 FallbackKernel 单输出表示:单张量输出不再包进 MultiOutputLayout/MultiOutput,直接以普通 Layout 表示(torch/_inductor/ir.py FallbackKernel.codegen 与 codegen/cpp_wrapper_cpu.py)。torch_npu 存在两处 fork 耦合,isinstance 分类会随之改变:(1) torch_npu/_inductor/codegen/ir_fx.py:282/307/332 的 _patch_baseview_realize/get_bufferisinstance(buffer, (ir.MultiOutput, ir.InputBuffer, ir.ConcatKernel)) 判定多输出走 traced_graph 分支,且 ir_fx.py:796 赋值式 patch ir.MultiOutput.get_traced_graph = _patch_multioutput_get_traced_graph——过去被包成 MultiOutput 的单输出 fallback 现在不再命中该分支;(2) torch_npu/_inductor/ascend_npu_ir/.../inductor_patch/scheduler.py:103/111 的 get_buf_bytes 用 isinstance(buf.layout, MultiOutputLayout)isinstance(user.node.node, MultiOutput) 统计字节数,单输出 fallback 改走 else 分支后字节估算路径变化。另 torch_npu/_inductor/ir.py:87-88 fork 了 FallbackKernel.codegen = codegen_npu,复制了上游 wrapper.generate_fallback_kernel(self) + isinstance(self.layout, Layout) 逻辑,需评估与上游新表示是否一致。非签名破坏,属 fork 行为分叉,需在 NPU 上跑 inductor fallback/custom-op 用例验证 ir_fx 与 scheduler 分类正确、字节统计无回退。 medium 否 是 compile_stage:Inductor
Check 把 user-streams 扩展到 AOT Inductor 的 cpp_wrapper 路径,用线程本地缓存创建 stream/event 并内联发射同步。 [新功能] 上游 PR 182971 为 AOT Inductor 的 GPU cpp_wrapper 新增显式 user-streams 支持:在 torch/_inductor/codegen/cpp_wrapper_gpu.py 内联生成 cudaEventRecord/cudaStreamWaitEvent、per-thread 的 AOTIPerThreadStreamCache/AOTIPerThreadEventCache(新增 codegen/aoti_runtime/streams.h),并在 lowering.py/scheduler.py/stream_utils.py 增加 streams op 的下降与调度。B 轨新功能三问:(1) 设备相关——是,生成的是 CUDA 专属 runtime 调用,NPU 需自研 Ascend 等价物;(2) NPU 默认路径是否触及——否,torch_npu 的 AOTI wrapper 是 torch_npu/_inductor/codegen/cpp_wrapper.py:197 class CppWrapperNpu(CppWrapperCpu),继承 CppWrapperCpu 而非本 PR 修改的 CppWrapperGpu,且 torch_npu 未 fork cpp_wrapper_gpu、未实现 streams op 下降;(3) 缺失后果——NPU 暂缺 AOTI 显式多流能力,属功能空白而非破坏,无现有代码 break 或回退。结论:当前 NPU AOTI 路径不经过被改代码,暂不需改 torch_npu,登记为后续 AOTI 多流对等能力跟进项,若 torch_npu 未来支持 AOTI user-streams 再在 CppWrapperNpu/对应 codegen 补 Ascend stream/event 生成。 low 否 否 compile_stage:Inductor
Check 在 torch/_inductor/runtime/hints.py 新增 InductorMeta(TypedDict) 定义,将 runtime 侧 inductor_meta 从 dict[str,Any] 收窄为强类型 TypedDict,纯类型注解改动,codegen 侧生产者留作后续跟进。 本 PR 为纯类型注解变更(在 torch/_inductor/runtime/hints.py 新增 InductorMeta(TypedDict),将 triton_heuristics.py/autotune_cache.py/coordinate_descent_tuner.py 的 dict[str,Any] 签名替换为 InductorMeta),运行时字典结构与键名不变。git grep 'InductorMeta'/'_InductorMetaTy'/'combo_grid_meta' HEAD 均 0 命中,torch_npu 不引用这些上游新符号。torch_npu fork 文件 torch_npu/_inductor/npu_triton_heuristics.py(复制自上游 triton_heuristics)内部自持 inductor_meta 普通 dict(如 :956 inductor_meta = {} if inductor_meta is None、:1145 独立实现的 foreach),与上游 TypedDict 注解无耦合;torch_npu/_inductor/init.py:154 通过 _compat 层取 CachingAutotuner 并仅 patch benchmark_all_configs(:157),不涉及被改的类型签名。类型注解在运行时被 Python 忽略,NPU 编译/自动调优路径不受影响,无需适配。 low 否 否 compile_stage:Inductor
Check 修复 GEMM 模板自动调优时 CachingAutotuner._make_launchers 保留失败 config 异常导致的引用环,用 finally 丢弃异常打断环,使 256MB L2 flush 缓冲区按引用计数及时释放,避免禁用循环 GC 时 HBM 泄漏。 上游修复 CachingAutotuner._make_launchers 中保留失败 config 异常(exc)造成 traceback→frame→do_bench 的 256MB L2-flush 缓冲区引用环泄漏(在禁用 cyclic GC 时)。torch_npu/_inductor/npu_triton_heuristics.py:543 的 _make_launchers 是上游同名函数的 fork(示例 15 fork 耦合),存在相同代码模式::556 exc = None、:564 循环内 exc = e、:567 循环后引用 exc 构造 RuntimeError,同样保留了异常对象及其 traceback frame 链。但 NPU fork 走自研 benchmarking(:635 do_bench_using_profiling_npu),无 Triton 256MB L2-flush 缓冲区,泄漏体量与触发条件与上游不同。git grep 'get_empty_cache_for_benchmark' HEAD 0 命中,确认 NPU 无该 256MB 缓冲机制。适配方案:人工确认 torch_npu/_inductor/npu_triton_heuristics.py:_make_launchers 是否在禁用 cyclic GC 场景下有等价的 frame/缓冲区滞留,如有则同步上游的 finally 释放 exc 修复;无需改动上游接口。验证方法:参照上游新增用例 test/inductor/test_triton_heuristics.py::TestMakeLaunchersMemory 在 NPU 侧构造 autotune 失败 config 场景观测显存。 low 待确认 是 compile_stage:Inductor
Check 新增 torch._inductor.compile_to_python(gm, example_inputs),作为 torch.compiler.precompile 后端契约的内层:对后 AOTAutograd 的稠密图返回 Inductor 输出模块源码(暴露 call(args))及可选二进制加速缓存,属私有内部入口。 本 PR(818 行,主体为 548 行测试)新增 torch/_inductor/standalone_compile.py(+261)中的 compile_to_python 入口并在 torch/_inductor/init.py 导出,从编译产物上读取最终 wrapper 模块的 source_code。对符号 compile_to_python、standalone_compile 在 tmp/torch_npu 执行 git grep,torch_npu 中未使用 compile_to_python 或 standalone_compile 符号,NPU 未引用该私有入口。间接机制方面:该函数把 codegen 固定为 benchmark_harness=False、cpp_wrapper=False,仅暴露 Python 化的 call(args);NPU Inductor 后端有独立的 codegen 与 wrapper(torch_npu/_inductor/codegen/),若未来 NPU 要对接 torch.compiler.precompile,需自行提供等价的 python 源码导出。影响类型为新增私有 API,无接口破坏。该 PR 已 Reverted,紧迫性进一步降低。需 Check 的是 torch/_inductor/init.py 的 +8 行导出改动是否引入 NPU import 期的符号变化,验证方法为在 NPU 环境 import torch_npu 并访问 torch._inductor 命名空间确认无 ImportError。潜在风险极低:因 NPU 走独立 wrapper 且该 API 是私有入口,正常训练与推理路径不触及;仅当 NPU 后续显式接入 precompile 契约时需补齐 python 源码导出,否则该路径不可用。 low 否 否
Check AOTI 编译期 Triton 自动调优遇到由 tolist() 派生的宽标量索引表达式(如 1000 项符号加法)会因 AST 递归触发 RecursionError;本 PR 用已有的 precomputed-size 机制把这类宽整型表达式提取为单个标量传入 kernel。 本 PR(52 行)改动 torch/_inductor/codegen/simd.py(+33),对仅依赖 host-known size、unbacked-int 或已 precompute 符号的大整型表达式复用 precomputed-size 机制,由 wrapper 计算单标量传入 Triton kernel,避免把千项符号加法内联进 kernel 源码导致 Triton 依赖遍历 RecursionError。对符号 precomputed_size、lookup_precomputed_size、simd 在 tmp/torch_npu 执行 git grep 命中两个不同文件:torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:4388 处 V.graph.sizevars.lookup_precomputed_size(l) 调用了同一 precomputed-size 机制,torch_npu/_inductor/codegen/triton.py:329 的 precomputed_args 方法也维护待 precompute 的索引表达式。耦合链路:上游 simd.py 决定哪些宽 size 表达式被 hoist 为 precomputed 标量 → V.graph.sizevars 维护 precomputed size 表 → torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:4388 与 torch_npu/inductor/codegen/triton.py:329 的 NPU codegen 通过 lookup_precomputed_size/precomputed_args 复用同一批 precomputed 符号。影响类型为编译期 codegen 变化:precompute 的 size 表达式集合变大后,NPU lowering 在 4388 行查表时会看到更多已 precompute 的符号。需 Check 的是 NPU codegen 是否正确处理这些新增的 precomputed 标量参数、是否改变 NPU kernel 的入参签名。验证方法:在 NPU 上编译含 data-dependent tolist() 索引的模型,核对 lookup_precomputed_size 返回的符号被正确传入 NPU kernel。潜在风险是若 NPU wrapper 未同步计算并传入该 hoist 出的标量,kernel 入参缺失导致编译失败或取到未初始化值。 medium 否 是
Check 把 set、dict 视图与 list 的二元/原地 dunder 统一收敛到 tp_slots 槽位分发,修复三处与 CPython 不一致行为。 A轨改动:上游把 SetVariable/DictKeysVariable/DictItemsVariable/BaseListVariable 的 and/xor/sub/add/iadd 等 dunder 分支从 call_method 收敛到 nb
impl/sq_impl slot。git grep 证实 torch_npu master 对这五个被改 VT 类零引用(SetVariable/DictKeysVariable/DictItemsVariable/DictViewVariable/BaseListVariable 均 0 命中);torch_npu 对 call_method 的唯一赋值式 patch 是 TensorVariable.call_method(torch_npu/utils/_dynamo.py:81-82,经 call_method_raw 回落原实现),TensorVariable 不在本 PR 改动范围;torch_npu/utils/_dynamo.py:60 仅 from torch._dynamo.variables.lists import TupleVariable,该类未改名未删除,import 不受影响;builder.py 中 SetVariable 改从 .sets 导入对 torch_npu 无耦合(torch_npu 不导入 SetVariable)。torch_npu test/dynamo/ 副本未收录 test_sets.py/test_dicts.py/test_list.py/test_sequence_ops.py(git ls-tree 0 命中),无 fork 测试需同步。人工确认上述三处排除结论即可,无需改码。 low 否 是 compile_stage:Dynamo
Check 修复 Dynamo 下 set()/frozenset() 带关键字参数静默返回空集的问题,改为按 CPython 语义抛 TypeError。 A轨改动:BuiltinVariable.call_set/call_frozenset 把 kwargs→TypeError 校验前移到位置参数计数之前,使 set(a=1) 正确报错。git grep 证实 torch_npu master 对 call_set/call_frozenset 零引用;torch_npu 对 BuiltinVariable 的唯一赋值式 patch 是 call_id(torch_npu/utils/_dynamo.py:245 保存原实现、:254 赋值替换),call_id 不在本 PR 改动范围且 patch 经 origin_call_id 回落,签名未变;torch_npu/dynamo/trace_rule.py 注入 torch_name_rule_map 的是 NPU 函数映射,不涉及 set/frozenset 构造路径。torch_npu 仓库无 test/dynamo_expected_failures 目录、test/dynamo/ 副本未收录 test_sets.py(git ls-tree 0 命中),PR 删除的 4 个 sentinel 文件与 torch_npu 无关。人工确认 call_id patch 与本改动无交集即可,无需改码。 low 否 是 compile_stage:Dynamo
Check 修复 Dynamo 下无参构造 tuple 子类触发断言崩溃的问题,空参时按 tuple.new 语义构建空元组。 A轨改动:修复 UserDefinedTupleVariable.init 在空参构造(MyTuple())时的 AssertionError,init_args 为空时构建空 TupleVariable。git grep 证实 torch_npu master 对 UserDefinedTupleVariable 零引用;torch_npu 在 user_defined.py 上的挂钩是 UserDefinedClassVariable.new 赋值式 patch 与 _in_graph_classes 替换(torch_npu/utils/_dynamo.py:360-404,patch_user_defined_class_variable),该 patch 只拦截 torch.npu.amp.autocast 与 NPU Tensor 类型常量、其余类(含 tuple 子类)经 __new__raw 回落上游原路径,本修复经回落路径透明生效;UserDefinedClassVariable.new 签名本 PR 未改。torch_npu/dynamo/trace_rule.py 的 rule 注入不涉及 tuple 子类构造。torch_npu test/dynamo/ 副本未收录 test_sequence_ops.py(git ls-tree 0 命中)。人工确认 new 回落链路即可,无需改码。 low 否 是 compile_stage:Dynamo
Check 删除 torch/_dynamo/backends 中 tvm() 冗余 None 检查与 AotAutograd.call 死分支,无行为变化。 本 PR 仅 8 行,删除 torch/_dynamo/backends/common.py 中 AotAutograd.call 永不可达的 use_fallback 分支(use_fallback 被硬编码为 False,-6)与 torch/_dynamo/backends/tvm.py 里 options 赋默认值后紧接的冗余 None 检查(-2),无任何行为变化。torch_npu 对被改类为强耦合:torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/npu_inductor_plugin.py:171 直接 from torch._dynamo.backends.common import AotAutograd,并在 :194 以 AotAutograd.call = wrap_aot_autograd(AotAutograd.call) 对该方法做整体 monkey-patch;torch_npu/utils/_graph_tree.py:15 从同模块导入 aot_autograd 工厂并在 :357 用它构建 aot_npugraphs。耦合链路:NPU inductor 插件包装 AotAutograd.call →(本 PR 删除的死分支所在函数体)→ NPU torch.compile 编译入口。由于被删分支从未执行,且方法签名、返回值与 wrap 时机均不变,NPU 的包装链与 aot_autograd 调用继续成立,编译行为无差异。验证:import torch_npu 后 torch.compile(backend="inductor") 编译任一函数,确认 npu_inductor_plugin 的 AotAutograd 包装仍生效即完成回归。风险点:torch_npu 包装的是函数对象而非复制源码,上游后续若对该函数做结构性改动(如改签名或拆分方法),此类补丁将首先受冲击;本次 8 行死代码清理反而缩小了该函数的漂移面,无需 NPU 侧动作。 low 否 是
Check 为 switch 高阶算子实现 Autograd,并将 cond 与 switch 共用的反向构建逻辑抽取到 utils.py,cond 语义不变。 被改符号:torch/_higher_order_ops/switch.py 新增 switch 的 Autograd 支持(+78/-6,含 int→SymInt 与 None 返回的特殊处理),torch/_higher_order_ops/cond.py 把反向构建的公共逻辑抽到 utils.py(cond.py +5/-20,utils.py +36),cond 的对外接口与语义不变,全 PR 504 行中 359 行为新测试。git grep "higher_order" 显示 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:7033 为 torch.ops.higher_order.cond 注册了 NPU inductor lowering(同文件 7045 行注册 while_loop、7060 行注册 invoke_subgraph),即 NPU 编译路径会消费 cond HOP 及其反向展开出的子图;torch_npu 中未发现对 switch HOP 的引用。耦合链路:torch.cond 反向图构建(本次改由 utils.py 公共函数生成)→ AOTAutograd 展开为前向/反向子图 → NPU inductor 在 lowering.py:7033 处 lower cond 子图。cond 部分属实现搬移,生成的反向子图结构不变,NPU lowering 消费的 IR 形态不受影响。验证:在 NPU 上跑 test/functorch/test_control_flow.py 中 cond backward 相关用例(本 PR 未改其预期结果)确认 ascend_npu_ir 对 cond 反向子图的 lowering 结果与升级前一致。风险点:模型若开始使用带 Autograd 的 switch,NPU inductor 尚无 higher_order.switch 的 lowering 注册,会在 lowering 阶段落入 fallback 或直接报不支持,届时需要在 lowering.py 补注册 switch 分支。 low 否 是
Check 将多个 VT 子类重复的 dict_vt 字段与 get_dict_vt 访问器去重上移到 VariableTracker 基类,行为不变。 无需修改 torch_npu 代码。本 PR 把重复的 dict_vt 字段 + get_dict_vt 访问器从 UserDefinedObjectVariable/用户函数 VT/非特化 nn.Module VT 上收敛到 VariableTracker 基类(base.py 新增 dict_vt=None 可选构造参数与惰性 DunderDictVariable 缓存),行为不变。torch_npu 全部自定义 VT 位于 torch_npu/utils/_dynamo.py(NPUTorchCtxManagerClassVariable、NPUAutocastModeVariable,及对 TensorVariable.call_method、SkipFunctionVariable.new 的 patch),它们不定义、不读取 dict_vt/get_dict_vt,基类新增可选参数为向后兼容默认值,经继承透明生效;torch_npu/dynamo/trace_rule.py 仅向 torch_name_rule_map 注入映射,与 VT dict 视图无关。人工确认动作:核对 torch_npu/utils/_dynamo.py:37 处 AutocastModeVariable(target_values, initial_values=None, **kwargs) 构造调用不受新增 kwarg 影响(已核,新参数带默认值,兼容)即可关闭本条。 low 否 是 compile_stage:Dynamo
Check Dynamo 在 compile_subgraph 时显式关闭所有打开的生成器,确保 finally 块在子图编译边界前执行完毕,已被回退。 无需修改 torch_npu 代码。本 PR 属 A 轨(修改 Dynamo 已有图捕获机制):在 OutputGraph 新增 local_generators 列表与 track_generator/close_local_generators 方法,并在 compile_subgraph 帧退出时显式 close 所有未耗尽的 generator(确保 finally 块执行),同时在 LocalGeneratorObjectVariable.init 登记 generator、gen_close 中清空 e.traceback 打破引用环。三重 grep 证实 torch_npu 与被改符号零耦合:compile_subgraph/LocalGeneratorObjectVariable/gen_close/track_generator/ObservedGeneratorExit 在 torch_npu HEAD 全部 0 命中;唯一交叉点是 torch_npu/utils/_dynamo.py:53-54 以赋值式 patch 覆盖同文件(torch/_dynamo/variables/functions.py)中 SkipFunctionVariable.new,但真实 diff 显示本 PR 未触及 SkipFunctionVariable 类,patch 签名不受影响;torch_npu/dynamo/trace_rule.py 仅向 torch_name_rule_map 注入 NPU 函数映射,不经过 OutputGraph.compile_subgraph 路径;output_graph.py 与 variables/functions.py 均不在 npu_source_map fork 清单中,torch_npu test/dynamo/ 下也无 test_generator.py 副本(git ls-tree 实查确认)。改动为设备无关的字节码级语义修复,经上游主线对 NPU 透明生效,确认上述 grep 证据即可关闭,无需新增测试或代码。 low 否 是 compile_stage:Dynamo
Check 将 AOTAutograd 的 codegen_utils.py 重命名为 codegen.py 并同步更新两处包内导入,纯重命名重构,无行为变化。 A轨纯重命名:torch/_functorch/_aot_autograd/codegen_utils.py 改名为 codegen.py 并重指 runtime_wrappers.py/subclass_codegen.py 两处 import,上游声明无行为变化。git grep 证实 torch_npu master 对 codegen_utils/PySourceBuilder/_compile_and_exec_source/runtime_wrappers/subclass_codegen 全部零引用;torch_npu 对 torch._functorch 的唯一 import 是公共模块 torch._functorch.aot_autograd 的 set_model_name/get_aot_compilation_context(torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/codegen/meta_kernel.py:10),不经过被改私有包 _aot_autograd/codegen_utils;torch_npu 对 AOT 编译链的赋值式 patch 是 AotAutograd.call(torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/npu_inductor_plugin.py:171 import 自 torch._dynamo.backends.common、:194 赋值包裹),与本次改名模块无关。私有模块内部改名、torch_npu 零耦合、零行为变化,无适配动作。 low 否 否 compile_stage:AOTAutograd
Check AOTAutograd 运行时包装器内部重构:epilogue 函数直接绑定进编排全局命名空间,移除冗余 shim 包装。 无需修改 torch_npu 代码。本 PR 是 torch/_functorch/_aot_autograd/runtime_wrappers.py 内部重构:_create_runtime_wrapper 不再把 codegen 的 epilogue 函数经 types.MethodType shim 挂到 epilogue 实例,改为直接作为参数传入 _codegen_epilogue,生成的 orchestration 源码不变。torch_npu 对 runtime_wrappers/_create_runtime_wrapper/_codegen_epilogue/_RuntimeForwardEpilogue/_apply_mutations/_replay_output_aliases 全部 0 引用;torch_npu 在 functorch 侧仅有两个挂钩点且均不受影响:torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/codegen/meta_kernel.py:10 只 import torch._functorch.aot_autograd 的 set_model_name/get_aot_compilation_context(本 PR 未改该模块),torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/npu_inductor_plugin.py:194 的赋值 patch AotAutograd.call = wrap_aot_autograd(AotAutograd.call) 包装的是 torch._dynamo.backends.common.AotAutograd 后端入口、位于 runtime wrapper 外层,内部重构对其透明。人工确认动作:核对 npu_inductor_plugin.py:180-194 的 wrap_aot_autograd 未读取 epilogue 实例属性(已核,未读取)即可关闭本条。 low 否 是 compile_stage:AOTAutograd
Check 修复 fx 算子签名工具对多返回值算子的 return_annotation,改为返回规范的 tuple 泛型注解而非原始类型元组。 torch/fx/operator_schemas.py 仅 1 行修复(另 34 行 test/test_fx.py 回归用例,共 36 行):多返回值算子(如 aten.var_mean.default)的签名 return_annotation 由原始 Python 类型元组 (Tensor, Tensor) 改为经 tuple.class_getitem 构造的规范 tuple[Tensor, Tensor] 注解。取证:git -C tmp/torch_npu grep -n operator_schemas 命中 torch_npu/_inductor/utils.py:103——_fx_node_is_input_dependent_cudagraph_unsafe 在判定 index_put 布尔索引是否 aclgraph 不安全时导入该模块的 normalize_function。耦合链路:torch/fx/operator_schemas.py 的签名构造 → normalize_function 按 signature.parameters 绑定实参 → torch_npu/_inductor/utils.py:103 的 aclgraph 安全性判定 → NPU 图分区决策;normalize_function 只消费参数列表、不读取 return_annotation,因此该调用点行为保持不变。另经 grep 核对,torch_npu/utils/_inductor.py:106 的 FakeTensorMode 推导路径同样不接触 fx 签名注解。影响类型:签名内省元数据的表示变化,无运行时数值路径改动。潜在问题:若未来 torch_npu 代码按元组实例去解构多返回值算子的 return_annotation,取值方式会因其变为泛型别名而不同——当前 grep 显示源码中无此类用法。验证方法:跑 torch_npu 仓库 test/test_fx.py:2290 处 get_signature_for_torch_op 相关用例,确认 NPU 移植用例与新注解格式兼容。 low 否 是
Check 为 Dynamo 的 FakeIdVariable 补齐整数运算槽位,使编译区域内 id() 参与位运算的自定义 hash 不再抛出 TypeError。 纯增量改动:给 torch/_dynamo/variables/constant.py 的 FakeIdVariable 新增整数算术 slots(镜像 ConstantVariable._nb_binary_impl),不改任何既有类接口。源码核查:FakeIdVariable 在 torch_npu 全包 0 命中;torch_npu 唯一 id() 相关的 Dynamo 挂钩是 torch_npu/utils/_dynamo.py:254 的赋值式 patch BuiltinVariable.call_id = _wrap_call_id,其仅拦截 EventVariable 参数(_dynamo.py:247-252,对 Event 用 ConstantVariable.create(id(...)) 返回真实 id),其余全部委托 origin_call_id——本 PR 未改 call_id 签名与语义,patch 透明兼容;_dynamo.py:59/251 对 ConstantVariable 的使用也不受影响(本 PR 未改 ConstantVariable)。改动为设备无关的 Python 语义补全(自定义 hash 做 id 算术不再假 TypeError 图断),对 NPU 经上游代码透明生效。人工确认上述两处 patch 点 grep 结论即可关闭,无需改 torch_npu/utils/_dynamo.py 与 torch_npu/dynamo/trace_rule.py 任何代码。 low 否 否 compile_stage:Dynamo
Check 为 Dynamo 的 deque 建模新增专用正反向迭代器并检测迭代期间的容器变更,行为对齐 CPython 的 RuntimeError 语义。 上游为 DequeVariable 新增 state 计数与 DequeIteratorVariable/DequeReverseIteratorVariable(lists.py),并在 UserDefinedClassVariable.call_function 中新增 deque 迭代器构造分支(user_defined.py)。源码核查:DequeVariable / ListIteratorVariable / DequeIteratorVariable 在 torch_npu 全包 0 命中;torch_npu 对 UserDefinedClassVariable 的赋值式 patch 位于 torch_npu/utils/_dynamo.py:402-404(_in_graph_classes = patched_in_graph_classes__new__ = UserDefinedClassVariable__new__),已 Read 360-404 行确认 new patch 仅拦截 NPU autocast/Tensor 类型、其余走 cls.__new__raw(cls) 回落上游——本 PR 改的是 call_function 方法体,未动 new 签名与 _in_graph_classes 接口,patch 正交兼容;torch_npu/utils/_dynamo.py:60 仅 import TupleVariable,与 lists.py 被改的 deque 相关类无交集。改动为设备无关的 CPython 容器语义对齐,经上游代码对 NPU 透明生效。人工确认上述 patch 点 grep 结论即可,无需修改 torch_npu/utils/_dynamo.py 或 torch_npu/dynamo/trace_rule.py。 low 否 是 compile_stage:Dynamo
Check 将全栈以类型判断识别伪张量的写法统一替换为 is_fake_tensor 辅助函数并新增代码检查规则,为后续 C++ 版伪张量迁移做前置准备,当前无行为变化。 上游将 isinstance(t, FakeTensor) 批量替换为 is_fake_tensor()(为 C++ FakeTensor 迁移铺路),PR 明确声明当前为 no-op(C++ FakeTensor 未启用,Python FakeTensor 类保留)。源码核查确认两类耦合当前均不 break:(1) fork 耦合——torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/fake_tensor.py:84 赋值式 patch fake_tensor.run_fallback_kernel = _npu_run_fallback_kernel,替换体(19-80 行)使用 fake_mode.is_our_fake(e) 与 e.fake_device(40 行),二者在 Python FakeTensor 上仍有效,且本 PR 未改 run_fallback_kernel 的 5 参调用约定;(2) 直接引用——torch_npu 有 10+ 处 isinstance(x, FakeTensor)(torch_npu/_inductor/graph.py:37、torch_npu/_inductor/utils.py:15、torch_npu/_inductor/codegen/wrapper.py:230、torch_npu/_inductor/dvm/fx_pass.py:87/126/137/212、dvm/graph_fusion.py:270 等),本 PR 下语义不变。确认动作:核对上述 grep 清单即可关闭本 PR;同时登记跟进项——待后续 C++ FakeTensor 启用 PR(#188979 栈)落地时,需将上述 isinstance 站点迁移为 torch._subclasses.fake_tensor.is_fake_tensor 并复核 inductor_patch/fake_tensor.py fork 体的 fake_device/is_our_fake 访问方式,届时按 shim 重新评估。torch_npu 当前对 is_fake_tensor 零引用(新符号,B 轨预期状态),本 PR 自身无行为变化故不升级。 low 否 否 compile_stage:AOTAutograd
Check 修复列表推导式 graph break 时复用迭代变量名导致的栈下溢段错误,改按 STORE 指令数分析推导式字节码;已被 Revert。 改动集中在 torch/_dynamo/comprehension_graph_break.py(+39/-89)与 output_graph.py(+4/-1),共 232 行,修复 CPython 字节码层面的段错误并防止 resume 函数把结果变量重置为 Null;labels 含 Reverted,当前主干回到旧字节码模板方案,按 Revert 规则由 Test 降级为 Check。对 comprehension_graph_break 相关符号执行 git grep,torch_npu 中未使用该模块的任何符号;但 NPU 上的 torch.compile 前端完整复用 Dynamo 字节码重写机制:torch_npu/utils/_dynamo.py:245 替换 BuiltinVariable.call_id 参与同一 trace 过程,torch_npu/dynamo/trace_rule.py:2 注册的 NPU 进图函数规则决定哪些调用触发 graph break,而 graph break 的恢复代码正是本 PR 被改逻辑的执行场景,NPU 模型在推导式内发生 graph break 时同样受益于段错误消除。该修复与设备无关,不触碰 NPU 的两处 patch 落点。影响类型:运行时(字节码生成)行为变化。回归手段:重land 后在 NPU 设备跑上游 test/dynamo/test_comprehensions.py 的新增用例,并清理 dynamo 编译缓存目录后重跑一次,规避 Revert 前后字节码差异带来的缓存串扰。隐患点:段错误属进程级崩溃,Revert 期间含推导式 graph break 的 NPU 脚本仍暴露于旧缺陷。 medium 否 是
Test 修复 inductor 因自引用变更拷贝导致调度器祖先计算键错误崩溃的问题:变更传播守卫改按缓冲区名判等,调度器同时容忍自环依赖。 上游修复 Scheduler.compute_ancestors 自环 KeyError(graph.py propagate_mutation 主修复 + scheduler.py 自环容忍防御),而 torch_npu 在 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/npu_inductor_plugin.py:399 以赋值式 patch Scheduler.compute_ancestors = npu_compute_ancestors 整体替换了该方法(enable_graph_trace 开启时生效),替换体 npu_inductor_plugin.py:254-269 复制的是旧版逻辑:第 267 行 ancestors |= name_to_ancestors[dep_node_name] 无自环容忍,上游 defense-in-depth 修复在 NPU graph_trace 路径被遮蔽;主修复 propagate_mutation 在 torch_npu 零引用、经继承透明生效。耦合链路:torch/_inductor/scheduler.py:compute_ancestors -> npu_inductor_plugin.py:399 赋值 patch -> npu_inductor_plugin.py:254 fork 体;另 torch_npu/_inductor/lowering_patch.py:116 对 compute_ancestors 做 baseline 快照/恢复(_snapshot_inductor_attr),恢复路径不受影响。具体动作:在 npu_inductor_plugin.py:262-267 的 dep 循环中同步上游自环守卫(跳过 dep_node_name == node.get_name() 的自依赖),并在 enable_graph_trace=True 下运行 test/inductor/test_auto_functionalize.py 的 test_reinplace_mutated_empty_no_self_edge 回归用例确认 NPU 替换体不再复现 KeyError。方法签名 (self)->None 未变,无 import/接口破坏,故为 test 而非 shim。 medium 是 是 compile_stage:Inductor
Test 为 prims.uniform 新增 inductor 分解规则,使均匀分布随机算子在编译模式下原生降级到 prims.rand 生成,不再依赖回退即时执行实现。 上游为 prims.uniform 新增 decomposition 并改动 torch/_inductor/lowering.py(aten.uniform 从 eager fallback 转为经 prims.rand 原生 lowering),命中 fork 清单文件 torch/_inductor/lowering.py。torch_npu 存在两处耦合:(1) fork 文件 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:2735 仍注册 make_fallback(aten.uniform, warn=False),且该 fork 的 make_fallback(同文件:2107-2119)以 op in torch._decomp.decompositions_for_rng.extra_random_decomps 作为 override_decomp 判据——上游向 decompositions_for_rng 新增 entry 后,fork 内该判据对 uniform 的分支结果会翻转,需同步 fork:删除或调整 :2735 的 uniform fallback 注册以与上游新分解对齐;(2) torch_npu/_inductor/init.py:109 以赋值式 patch inductor_lowering.make_fallback = npu_make_fallback(npu_make_fallback 定义于 torch_npu/_inductor/lowering.py,经 init.py:82 导入),上游本次仅 +1/-1 未改 make_fallback 签名,patch 本身不 break,但 uniform 走原生 lowering 后 NPU 默认 Triton 路径的 RNG 生成代码路径改变,需以 test/_inductor/test_rngprims_philox_rand.py 与 test/test_functionalization_of_rng_ops.py 中已有的 uniform/RNG 用例对比 eager 与 inductor 输出一致性,确认 NPU Triton codegen 对 prims.rand 路径生成的随机数分布正确。 medium 是 是 compile_stage:Inductor
Test 删除 Python wrapper codegen 中过时的符号尺寸/步长反推逻辑,自由符号改由显式图输入传递,C++ wrapper 路径保持不变。 上游重构 torch/_inductor/codegen/wrapper.py(+210/-110):Python wrapper 不再从 tensor 输入反推 symbolic size/stride,改为依赖显式传入的自由符号图输入(C++ wrapper 路径不变)。torch_npu 耦合链路:torch_npu/_inductor/init.py:98-101 将 NPUWrapperCodeGen 注册为 npu 设备 wrapper;torch_npu/_inductor/codegen/wrapper.py:131 NPUWrapperCodeGen(_NPUKernelCodegenMixin, PythonWrapperCodegen) 直接继承被重构基类,其 write_prefix(wrapper.py:325-326,先调 super().write_prefix() 再注入 StaticKernelCompiler 初始化)依赖上游 prefix 段完成符号绑定后再追加内容;mixin 的 generate_node_numel_expr(wrapper.py:56-73)会向 wrapper 写出含自由符号的 numel 表达式(如 s0*64),其可求值性依赖上游新的"符号作为显式图输入"绑定方式。核查确认 NPUWrapperCodeGen 未覆写上游被删改的符号提取逻辑本体(write_prefix 仅追加、codegen_input_size_asserts 为空实现 pass 于 wrapper.py:76-77,不受上游删除逻辑影响),C++ 侧 torch_npu/_inductor/codegen/cpp_wrapper.py:352-373 的 codegen_inputs 覆写走上游声明保持不变的 C++ 路径。改动经继承透明生效但覆盖 NPU 全部动态 shape 编译产物,需运行 torch_npu 仓内 test/_inductor 下动态 shape 用例(含 NPUSubgraphWrapperCodegen 分区子图路径,torch_npu/_inductor/codegen/wrapper.py:356-374)核对生成 wrapper 中自由符号绑定与 numel 表达式求值正确。 medium 否 是 compile_stage:Inductor
Check FX 常量折叠将跳过谓词递归应用到 call_module 子图,子图含被跳节点则整体不折叠。 torch/fx/experimental/const_fold.py(+44/-3)让 split_const_subgraphs 在遇到 call_module 节点时把跳过谓词递归应用到子模块图,折叠范围只减不增,属保守化修复,另 99 行为 test/fx/test_fx_const_fold.py 用例。git grep 取证:split_const_subgraphs、skip_folding_node_fn 在 torch_npu 源码零命中;对 const_fold 的命中全部落在 AOTI 运行时,如 torch_npu/csrc/inductor/aoti_runtime/model.h:227 的 run_const_fold 与 torch_npu/csrc/inductor/aoti_runtime/model_container.h:112——该引用是 AOTI 模型容器在 C++ 侧做权重常量预计算的独立实现,与 torch.fx.experimental.const_fold 的 Python 图变换互不调用,不依赖被改接口。因此结论为:torch_npu 中未使用 split_const_subgraphs,此 PR 不影响 NPU 功能;AOTI 侧 run_const_fold 语义不变。影响类型:FX 图变换行为收敛(少折叠、不多折叠),无 API 变化。核对动作:无需 NPU 专项回归;若三方部署套件在 NPU 图上调用 const_fold,可用折叠后常量节点数作前后对比指标。隐患点:折叠范围收窄使个别图多保留运行时计算,属性能中性偏差,非正确性问题。 low 否 是
Check Inductor IR 层类型重构:process_kernel 的 5 元组返回值等三处松散类型改为 dataclass 与 Protocol,语义保持不变。 类型化重构(5 元组->ProcessKernelResult dataclass、tuple->ExtraIndexingConstraints、新增 _HasAliasingOrMutation Protocol),语义保持。源码核查确认 torch_npu 与全部被改符号零耦合:ExternKernel.process_kernel / simplify_and_reorder / _compute_attrs / recompute_size_and_body / find_device 在 torch_npu 全包(含 fork 文件 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/ir.py 与 inductor_patch/scheduler.py)均 0 命中——scheduler.py fork 仅含 _npu_get_read_write_buffers_sizes(inductor_patch/scheduler.py:27),未复制 _compute_attrs/recompute_size_and_body 区域;ir.py fork 未复制 ExternKernel.process_kernel 调用点。comm_lowering.py 的耦合仅为 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:7156 from torch._inductor.comm_lowering import register_comm_lowerings,该函数签名本 PR 未改,batch_p2p 内部解包重构对其透明。torch_npu/_inductor/lowering_fx.py:178 与 codegen/meta_kernel.py:158 调用的 snode.has_aliasing_or_mutation() 是既有方法,与本 PR 新增的 has_aliasing_or_mutation_for_prologue_fusion Protocol 是不同符号,不受影响。cpp.py 属 CPU CPP codegen,NPU 走独立 Triton/MLIR/DVM codegen 不引用。人工确认上述 grep 结论即可,无需改代码、无需专项测试。 low 否 否 compile_stage:Inductor
Check 收窄 inductor standalone_compile 私有辅助函数的返回元组,去掉两处调用点均未消费的 cache_info 元素,属纯内部清理。 torch/_inductor/standalone_compile.py 的 10 行小改动(+5/-5)把私有辅助函数 CacheCompiledArtifact._validate_and_unpack 的返回值从 (artifact_bytes, cache_info, key) 收窄为 (artifact_bytes, key),_to_binary_bytes 与 save 两个调用点同步更新,模块对外 API(CompiledArtifact 的 save/load 入口)签名不变。对 CacheCompiledArtifact、_validate_and_unpack、standalone_compile 逐一执行 git -C tmp/torch_npu grep 核查,torch_npu 中未使用 CacheCompiledArtifact 与 _validate_and_unpack,此 PR 不影响 NPU 功能。torch_npu 的编译产物生成走自身 NPUWrapperCodeGen 链路,不依赖 standalone_compile 的二进制打包格式;唯一断裂面是第三方直接调用该私有函数并按 3 元组解包的代码,而 grep 已证明 NPU 侧无此类调用。影响类型:纯内部重构,无运行时行为差异;无需 NPU 侧回归动作,升级基线后照常构建即可。 low 否 否
Check 新增 compile_to_python:把 AOTAutograd 包装器与内层编译调用合成自包含 Python 模块。 B 轨新功能:上游新增 torch._functorch.aot_autograd.compile_to_python(torch.compiler.precompile 的外层后端契约),新增文件 to_standalone_python.py/standalone_runtime.py,对 _aot_autograd/codegen.py 仅追加 capture_generated_sources 捕获钩子(加法,不改既有签名)。功能对等三问:①设备相关——standalone 模块内嵌的 inner call 来自 torch._inductor.compile_to_python,其 Triton/C++ 产物是否可在 NPU 独立运行需待 torch.compiler.precompile 正式落地后评估;②非默认路径——该 API 为 opt-in,PR 自述完整特性随 precompile 后续落地,NPU 用户当前默认 torch.compile 路径不经过它;③缺失后果为未来的 precompile/standalone 导出能力缺口,不造成现有功能 break。torch_npu 对被改文件仅有两处相邻耦合且均未被本 PR 触及:torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/codegen/meta_kernel.py:10 从 torch._functorch.aot_autograd 导入 set_model_name/get_aot_compilation_context(本 PR 对 aot_autograd.py 仅 +4 新增函数,不影响该 import);torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/npu_inductor_plugin.py:194 赋值式 patch AotAutograd.call(目标在 torch/_dynamo/backends/common.py,本 PR 未改)。结论:登记跟踪 precompile 特性落地进度即可,当前无需改 torch_npu 代码。 low 否 否 compile_stage:AOTAutograd
Check Inductor 对重复的 foreach 子内核体发射共享 Triton 主体,减少重复代码并加速编译。 上游在 foreach combo kernel 路径(torch/_inductor/codegen/triton_combo_kernel.py +392、codegen/triton.py +139、common.py +17,均为加法)检测相同 pointwise 子内核体并发射共享 Triton body 以降低编译时间。torch_npu 默认 Triton 路径已整体关闭 foreach 调度:torch_npu/_inductor/utils.py:170-176 disable_foreach() 以赋值式 patch Scheduler.create_foreach_nodes = create_foreach_nodes(空实现),并在 torch_npu/_inductor/init.py:166 无条件调用——ForeachKernelSchedulerNode 不会生成,combo kernel 代码生成路径(含本 PR 新增的共享 body 逻辑)在 NPU 主路径不可达;fork 文件 torch_npu/_inductor/codegen/triton.py 对比确认上游 triton.py 改动为纯新增方法(+139/-0),不修改 fork 已复制的既有函数体,无既有逻辑分叉。仅 ascend_npu_ir 插件 fork(torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:208 引用 config.combo_kernel_foreach_dynamic_shapes 且注册 foreach lowering :461/:808)保留 foreach 语义,该插件如后续启用 combo kernel 调度可顺带获得上游共享 body 优化(纯编译时优化,不改 kernel 语义),确认 disable_foreach 仍在 torch_npu/_inductor/init.py:166 生效即可关闭本条。 low 否 是 compile_stage:Inductor
Test Inductor 为 fallback 算子输出新增 dtype 校验,坏的 fake 内核提前报错;已被 Revert。 上游在 fallback 输出元数据校验中新增 dtype 校验(torch/_inductor/ir.py、codegen/wrapper.py、runtime/runtime_utils.py)。torch_npu master 以赋值式 patch 包裹被改路径:torch_npu/_inductor/ir.py:8-28 定义 npu_codegen_size_asserts 并执行 ExternKernel.codegen_size_asserts = npu_codegen_size_asserts(torch_npu/_inductor/init.py:122-124 经 patch_extern_kernel_codegen_size_asserts 安装),该 patch 保留 (self, wrapper) 签名且非跳过分支回调 original_codegen_size_asserts,上游新增的 dtype 断言经此透明流入 NPU 生成代码;但 skip_specific_stride_asserts 命中的算子会连同新 dtype 校验一起被跳过(torch_npu/_inductor/ir.py:17-24 跳过分支),需确认该跳过语义对 dtype 断言是预期行为。适配动作:在 NPU 上执行 test/inductor/test_torchinductor.py 与自定义算子 fallback 用例,重点验证 torch_npu 注册的自定义算子 meta/fake kernel 的输出 dtype 与真实 kernel 一致(dtype 不一致的 meta 现在会 fail-fast 报错而非静默算错),并确认 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/codegen/wrapper.py:86 fork 头部注入的 assert_size_stride = torch._C._dynamo.guards.assert_size_stride 别名与 torch_npu/_inductor/lowering_fx.py:280 的同名别名在上游扩展 dtype 参数后调用不报 TypeError。 medium 否 是 compile_stage:Inductor
Shim 修复通用 view 上动态 slice 边界的 lowering,未决边界回退 eager 校验;已被 Revert。 上游修复 generic view 上动态 slice 边界的 lowering(torch/inductor/lowering.py 的 slice/slice_scatter、torch/_inductor/ir.py 的 SliceView,二者均在 fork 清单)。torch_npu master 把这条路径整体替换,上游修复在 NPU FX 路径被清零,需要手工同步:(1) 赋值式 patch ir.SliceView.create = _patch_sliceview_create(安装点 torch_npu/_inductor/codegen/ir_fx.py:860,函数体 ir_fx.py:473-519 复制旧实现:仅 is_storage_and_layout 快路径处理 stride,否则走通用 reindex,无上游新增的免 stride 元数据动态边界处理;ascend_npu_ir 同构耦合在 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/ir.py:498),需把上游 SliceView.create 的动态边界修复移植进 patch_sliceview_create;(2) torch_npu 重新注册的 slice/slice_scatter lowering 覆盖上游注册——torch_npu/_inductor/lowering_fx.py:1061(@register_lowering(aten.slice))、lowering_fx.py:1217-1232(@register_lowering(aten.slice_scatter),:1232 调 ir.SliceView.normalize_start_end)及 inductor_patch/lowering.py:3047-3061 同构,均无上游本次新增的 unresolved slice_scatter 边界回退(fallback)分支,需同步补齐,否则 unbacked SymInt 边界场景 NPU 仍复现 #183259 的错误行为;(3) 同步后在 NPU 跑 test/inductor/test_unbacked_symints.py 新增用例回归。torch/_inductor/fx_passes/reinplace.py 的改动无 torch_npu 侧耦合(见证据),无需动作。 medium 是 是 compile_stage:Inductor
Test 修复 Inductor 中 max_pool2d_backward 因 decomposition 先于 lowering 执行导致 eager fallback 被绕过的问题,恢复按需回退 eager 的预期行为,避免被融合进 Triton kernel 造成性能劣化。 上游修复 torch/_inductor/lowering.py(+5)中 max_pool2d_backward 的 eager fallback 被 decomposition 提前吞掉的问题(decomp 先于 lowering 执行导致 #182619 的回退机制被绕过、被融进 Triton kernel)。lowering.py 在 npu_source_map fork 清单内,torch_npu 三处耦合:① fork 文件 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:4637-4707 自带 max_pool2d_with_indices_backward 的 register_lowering,经 fallback_max_pool2d_with_indices_backward(:4631)在 dilation!=1 或 window_size>25 时回退 eager——与上游被修复机制同源,需对比该 fork 路径是否同样存在 decomp 先行吞掉 fallback 的 bug 并评估同步上游 5 行修复;② 赋值式 patch torch_npu/_inductor/init.py:109 inductor_lowering.make_fallback = npu_make_fallback(定义于 torch_npu/_inductor/lowering.py:57,签名含 layout_constraint/warn/override_decomp/get_decomp_fn,覆盖上游基础参数,签名不 break);③ torch_npu/_inductor/dvm/decomp.py:29 的 decomp 列表显式含 aten.max_pool2d_with_indices_backward,dvm 路径行为与本修复的 decomp/lowering 顺序直接相关。默认 Triton 路径 torch_npu 未注册自有 maxpool lowering(lowering.py/lowering_fx.py/decomposition.py 中 max_pool 0 命中),上游行为变化在 NPU 直接生效:满足回退条件时 maxpool backward 从 Triton 分解 kernel 改走 eager 算子。需在 NPU 上运行上游同 PR 修改的 test/inductor/test_torchinductor.py 的 max_pool2d backward fallback 用例,确认回退路径正确触发且 eager 算子结果与性能符合预期。 medium 否 是 compile_stage:Inductor

likedislike
rmch成员
8月4日 评论:

Check 为 Inductor 编译工作进程 sidecar 看门狗增加阶段上报:worker 经 fork 继承的共享内存缓冲记录 job、phase 与 pid,看门狗将其折叠进 STATUS 上报至 tlparse,可区分卡在缓存查询还是 Triton 编译。 上游为 Inductor 编译子进程池新增 watchdog 阶段上报(新文件 torch/_inductor/compile_worker/watchdog.py,B 轨新功能,设备无关的可观测性基建,fork 池专用)。torch_npu 两处耦合均不 break:① torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/codecache.py:21 import SubprocPool、:236 直接实例化 SubprocPool(get_compile_threads())——上游改动是在 SubprocPool 内部于 fork 前分配 multiprocessing.Array 并在 watchdog 线程读取,对外构造调用兼容,NPU 经上游类透明获得该能力;② torch_npu/_inductor/npu_triton_heuristics.py:422/441/472 的 NPUCachingAutotuner 覆写了 precompile/_precompile_worker/_precompile_config,未包含上游在 torch/_inductor/runtime/triton_heuristics.py(+3)打的 COMPILING 阶段桩,NPU 编译的 kernel 在 compile_worker_status tlparse 报告中不会显示 compiling 阶段——仅诊断信息缺失,无功能/性能影响。功能对等三问:设备无关;NPU 用户经 ascend_npu_ir 的 process_pool 会碰到 SubprocPool;缺阶段桩仅损失诊断粒度。适配动作:人工确认 codecache.py:236 的 SubprocPool 构造在上游改造后行为不变即可;如需与 CUDA 诊断对齐,可选在 npu_triton_heuristics.py 的 _precompile_config 前打同样的 Phase 桩(不阻塞)。 low 否 是 compile_stage:Inductor
Check 新增 compile-worker sidecar 看门狗线程,周期性将运行超过阈值的编译任务经 STATUS 消息上报父进程并生成 compile_worker_status 结构化追踪工件,便于定位卡死的编译 job。 此 PR 在 torch/_inductor/compile_worker/subproc_pool.py(+103 行)为编译 sidecar(SubprocMain)加装看门狗线程,按 torch/_inductor/config.py 新增的 compile_worker_watchdog_interval_seconds(默认 60 秒,0 关闭)周期性把仍在运行的编译 job 经新增 MsgHeader.STATUS 消息上报父进程,父进程转为 compile_worker_status 结构化追踪工件;191 行改动中 77 行为新测试。torch-npu 耦合点(git grep 追溯):torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/codecache.py:236 的 CustomAsyncCompile.process_pool 直接实例化上游 SubprocPool(get_compile_threads()),NPU 的 MLIR 与 Triton kernel 编译任务全部经此池提交,STATUS 消息与结果消息共用同一条 sidecar 到父进程的管道;torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/npu_inductor_plugin.py:19 引入的 shutdown_compile_workers 负责退出清理,不受本次协议扩展波及。SubprocPool 构造签名与 submit/result 语义均未变,属内部可观测性增强,影响类型为运行时新增后台线程与低频 IPC,编译热路径零额外开销。验证:先跑 python test/inductor/test_compile_worker.py -k TestCompileWorkerWatchdog 上游新用例,再执行 torch_npu 仓 test/_inductor/test_codecache.py 确认 CustomAsyncCompile 建池、编译、关闭全程正常。风险点:NPU 的 MLIR 编译单个 job 常超 60 秒,会周期性触发 STATUS 上报——若 torch-npu 未来自行解析该管道消息,必须同步识别 MsgHeader.STATUS 消息头,否则会把状态消息误当编译结果解包而报错。 low 否 是
Check 三层加固 Inductor 编译进程池:修复 fork 模式管道 fd 泄漏导致 sidecar 死亡后编译永久挂起的根因,新增存活看门狗快速失败 pending futures,teardown 升级 SIGTERM→SIGKILL 兜底。 此 PR 对 torch/_inductor/compile_worker/subproc_pool.py(+173 行,总改动 324 行,其中 132 行为新增测试)做三层加固:①fork 模式 fd 卫生——父进程在 spawn sidecar 后立即关闭自己持有的管道 fd 副本,worker 在 _async_compile_initializer 中关闭继承的 fd,使 sidecar 意外死亡后父进程读端能收到干净 EOF,编译 futures 不再永久挂起;②新增守护线程轮询 sidecar 存活,异常退出时将 pending futures 置为失败并捕获 worker 日志尾部到 trace_structured 工件;③torch/_inductor/compile_worker/utils.py 的 _terminate_process_pool 升级为 SIGTERM→限时等待→SIGKILL,shutdown() 补捕 subprocess.TimeoutExpired。torch-npu 耦合链路:torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/codecache.py:21 导入上游 SubprocPool,同文件 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/codecache.py:236 的 CustomAsyncCompile.process_pool 以 SubprocPool(get_compile_threads()) 建池,NPU 的 MLIR 与 Triton kernel 编译任务全部经此池执行;torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/npu_inductor_plugin.py:42 经 atexit 注册 shutdown_compile_workers,走升级后的 teardown 路径。git grep 确认 torch_npu 未覆写 _terminate_process_pool 与 _async_compile_initializer(无匹配),全部直接继承上游新逻辑,SubprocPool 构造签名与 submit/result 语义未变。影响类型:运行时稳定性增强——此前 NPU 编译 worker 死亡会令 async_compile.wait() 挂死整个分布式作业,现在会快速失败并给出可操作报错。验证:跑上游 python test/inductor/test_compile_worker.py -k test_sidecar_death 系列新用例,再在 NPU 环境执行 torch_npu 仓 test/_inductor 目录的 codecache 用例确认建池、编译、atexit 关闭全流程。风险点:SIGKILL 兜底可能中断正在写编译缓存的 worker,NPU 侧若缓存文件处于半写状态,下次编译走缓存 miss 重编,无正确性问题但存在性能抖动。 medium 否 是
Test Dynamo 的 list/tuple 加法统一经 slot_wrapper 路由,先试 nb_add 再回退 sq_concat,删特判补 deque。 该 PR 属 A 轨(修改已有机制):重构 list/tuple 的 add/radd/iadd 路由,新增 slot_wrapper_add/slot_wrapper_iadd(object_protocol.py),删除 BaseListVariable 对 add 的特判(lists.py),并为 DequeVariable 补 sq_inplace_repeat_impl。核查 torch_npu 的两个 Dynamo 挂钩文件均无耦合:torch_npu/utils/_dynamo.py 只对 TensorVariable.call_method 做赋值式 monkey-patch(第81-82行 TensorVariable.call_method = TensorVariable_call_method),仅处理 name=='type' 分支,不触及 BaseListVariable/DequeVariable 的序列拼接与 slot_wrapper 逻辑;torch_npu/dynamo/trace_rule.py 只向 torch_name_rule_map 注入 NPU 函数映射,与 list add 路由无关。torch_npu 自定义 VT(NpuStreamContextVariable/NPUTorchCtxManagerClassVariable/NPUAutocastModeVariable,均在 torch_npu/utils/_dynamo.py)无一继承 BaseListVariable/DequeVariable 或覆写 add/call_method 的序列拼接分支。改动透明生效,torch_npu 无需修改。 low 否 否 是 compile_stage:Dynamo
Test 重构 Dynamo 的 ConstDictVariable 仅表示纯 dict,OrderedDict 存储拆到新 VT,各构造点改选具体类。 该 PR 属 A 轨:让 ConstDictVariable 只表示 dict,删除 user_cls 运行时分支,把 OrderedDict 存储拆到新的 OrderedItemsDictVariable(ConstDictVariable),NNModuleHooksDictVariable 改为继承它,_cpython_type 同时充当 self.items 的后备容器类。核查 torch_npu 全包无任何生产代码引用这些 dict VT 符号:torch_npu/utils/_dynamo.py 的自定义 VT 与 patch 均围绕 TensorVariable/StreamContextVariable/CtxManager,不构造也不继承 ConstDictVariable/OrderedDictVariable;torch_npu/dynamo/trace_rule.py 的 torch_name_rule_map 注入与 dict VT 表示无关。torch_npu 唯一涉 dict 的生产引用是 torch_npu/_inductor/codegen/scheduling.py 的 immutable_dict(用于 tiling 配置),来自 torch.fx.immutable_collections,与本 PR 改的 Dynamo ConstDictVariable 对 immutable_dict 的追踪表示完全不同层,无耦合。改动透明生效,torch_npu 无需修改。 low 否 否 是 compile_stage:Dynamo
Test 为 Dynamo 新增 AttributeErrorVariable/NameErrorVariable 等异常 VariableTracker,使 StopIteration.value、AttributeError.name/obj、NameError.name 等异常专属属性能在 tracing、重建与真实 raise 中正确 round-trip。 该 PR 属 A 轨兼 B 轨(为已有 ExceptionVariable 体系新增 per-exception VT):新增 _KwargAttrExceptionVariable 基类及 AttributeErrorVariable/NameErrorVariable,支持 StopIteration.value、AttributeError.name/.obj、NameError.name 属性 round-trip,并让 symbolic_convert.py 对未定义名抛 observed NameError 而非 graph break。核查 torch_npu 无耦合:torch_npu/utils/_dynamo.py 的自定义 VT 与 patch 不涉及异常 VT,也不覆写异常构造/getattr;torch_npu/utils/_dynamo.py:281 虽 import 了 torch._dynamo.symbolic_convert.InstructionTranslator,但仅作 NpuStreamContextVariable.create/enter/exit 的类型注解(TYPE_CHECKING 下),不触及本 PR 改动的 NameError 抛出逻辑。功能对等三问:异常属性追踪为设备无关的 CPython 语义对齐,NPU torch.compile 路径不依赖自定义异常 VT,缺失不影响 NPU 图捕获。改动透明生效,torch_npu 无需修改。 low 否 否 是 compile_stage:Dynamo
Test 让 Dynamo 追踪生成器的属性变更以正确处理闭包,在 side_effects 与 variables/base 中记录生成器属性突变,避免闭包变量在生成器场景下丢失更新,配套 40 行测试。 该 PR 属 A 轨:在 side_effects.py 与 variables/base.py 中追踪 generator 属性 mutation 以正确处理 closure。核查 torch_npu 无耦合:torch_npu/utils/_dynamo.py 对 base VariableTracker 无赋值式 monkey-patch,唯一 VT 层 patch 是 TensorVariable.call_method(第81-82行),其重实现签名为 (self, tx, name, args, kwargs),仅处理 name=='type' 分支,与本 PR 改的 base.py generator 属性 mutation 追踪逻辑(influence side_effects 记录)无交集,且本 PR 未改动 call_method 签名;torch_npu 无 fork side_effects.py,也无生产代码引用 SideEffects 类的 generator mutation 分支。torch_npu/dynamo/trace_rule.py 只做 torch_name_rule_map 注入,与 side effects 无关。改动透明生效,torch_npu 无需修改。 low 否 否 是 compile_stage:Dynamo
Test 为 Dynamo 生成器实现子生成器在 .throw/.close 方法中的委托支持,使嵌套生成器的异常抛出与关闭能正确沿委托链传播,配套新增 218 行生成器测试。 该 PR 属 A 轨:在 variables/functions.py 与 symbolic_convert.py 中为 generator 的 .throw()/.close() 实现 subgenerator(yield from 委托)支持。核查 torch_npu 无耦合:torch_npu 全包无 LocalGeneratorObjectVariable 或 generator throw/close 相关引用;torch_npu/utils/_dynamo.py:281 对 symbolic_convert 的 import 仅为 InstructionTranslator 类型注解(TYPE_CHECKING),不触及本 PR 改的 throw/close/subgenerator 逻辑;torch_npu 无 fork functions.py,自定义 VT 均不继承 generator function VT。功能对等三问:subgenerator throw/close 为设备无关的 Python 语义补全,NPU torch.compile 路径不依赖该机制,缺失仅影响特定 generator 代码的 graph break 行为而非 NPU 正确性。改动透明生效,torch_npu 无需修改。 low 否 否 是 compile_stage:Dynamo
Test 修复 AOTAutograd partitioner 在反向图中对被 ShapeEnv 替换的 SymInt 符号未绑定的问题,使反向 sizevar codegen 与 FxGraphCache guard 都能正确解析替换后的符号,避免 KeyError 缓存崩溃。 此 PR 修改 torch/_functorch/partitioners.py(+11 -2)核心逻辑,让 partitioner 在选择反向符号绑定时同时发现未替换与替换后的自由符号,并新增 test/inductor/test_backward_symint_guards.py(112 行)与 test/dynamo/test_aot_autograd.py 覆盖动态形状回归。被改符号为 _free_symbols_without_replacements 及 partitioners 的反向绑定逻辑。对 _free_symbols_without_replacements、partitioners、min_cut 等符号在 tmp/torch_npu 执行 git grep,torch_npu 中未发现引用,仅 torch_npu/utils/_dynamo.py:281 引用了 torch._dynamo.symbolic_convert.InstructionTranslator(属 Dynamo 前端,非 partitioner)。耦合链路上:torch_npu 的图模式后端(torch_npu/_inductor/、torch_npu/dynamo/)复用上游 AOTAutograd 与 partitioners 产出的联合图与反向图,NPU Inductor 后端在此基础上做 lowering/codegen,故 partitioner 生成的反向图符号绑定正确性会间接影响 NPU 动态形状编译缓存的命中与正确性。影响类型为运行时/编译行为变化(反向图符号绑定与 FxGraphCache guard 求值),非接口签名变更,NPU 侧无需改代码。验证方法:在 NPU 环境运行含动态形状(如 offsets 张量尺寸被替换为 b+1 的场景)的 torch.compile 反向训练,检查 FxGraphCache 二次查找不再抛 KeyError,并跑上游 test/inductor/test_backward_symint_guards.py 对齐行为。潜在风险:若 NPU 后端此前依赖旧的仅绑定原始符号的行为,替换目标符号新增绑定后反向 guard 表达式变化,可能引入静默的缓存未命中或重编译,需回归动态 shape 训练精度与性能。 medium 否 否 是
Test Inductor 改按 kernel 实际寻址表达式判定 int32/int64 索引,新增两路溢出检查替代旧代理,修复 chunked 融合溢出。 该 Inductor 索引 dtype 判定重构改动 torch/_inductor/codegen/simd_kernel_features.py(+51 -9),在 select_index_dtype 通过 can_use_32bit_indexing 后新增 any_index_expr_overflows_int32,对每个读写 index 施加常量偏移检查与 bound_sympy 变量缩放上界检查,修复 chunked-slice 融合中 Vx0 项 int32 溢出导致 cudaErrorIllegalAddress 的问题(共 162 行含测试)。对 select_index_dtype、can_use_32bit_indexing 执行 git grep,torch_npu 命中:torch_npu/_inductor/codegen/triton.py:195 定义了 NPU 版 select_index_dtype,并在 torch_npu/_inductor/codegen/init.py:20/34 通过 from torch_npu._inductor.codegen.triton import select_index_dtype 导入后以 TritonScheduling.select_index_dtype = select_index_dtype 覆盖上游同名方法。耦合链路:torch_npu/_inductor/codegen/init.py:34 将 NPU 的 select_index_dtype 注册进 TritonScheduling → 该函数在 NPU Inductor 生成 kernel 前决定 index dtype → 上游若把 int32 判定逻辑从 can_use_32bit_indexing 迁移/拆分到 simd_kernel_features 的 any_index_expr_overflows_int32,而 NPU 侧 select_index_dtype 副本仍沿用旧代理判定,则 NPU 在同类 chunked 融合形状下可能仍误选 int32 造成越界,或过度回退 int64 损失性能。影响类型为编译期索引 dtype 选择(正确性与性能)。验证方法:在 NPU 上运行 test/inductor/test_indexing.py 的 TestIndexExprUpperBounds/TestIndexConstOverflowInt32,并核对 chunked slice gather 大尺寸用例不发生非法地址访问。潜在风险:静默索引 miscompile(int32 溢出越界读写)或 block-pointer codegen 回退 int64 的性能退化。 high 是 否 是
Test 修复 Inductor Triton 嵌套 reduction 外层 block_ptr 未回退的 bug,改为每层记录指针发射回退,避免越界读取致结果截断。 上游改动落在 torch/_inductor/codegen/triton.py 的 TritonKernel 内部 block_ptr 逐层前进记账逻辑(嵌套 reduction 下外层循环用 outer_step - inner_step * inner_num_iter 计算 tl.advance 回退)。该文件在 npu_source_map fork 清单里,torch_npu 复制了整份 triton.py(torch_npu/_inductor/codegen/triton.py,定义 NPUIndexTritonKernel(TritonKernel) @ triton.py:446)。核查两条耦合链路:(1) fork 的 load()/store() 仍调用继承自上游基类的 self.codegen_block_ptr(torch_npu/_inductor/codegen/triton.py:1070 store、torch_npu/_inductor/codegen/triton.py:1400 load),fork 未 override codegen_block_ptr(git grep 'def codegen_block_ptr' 0 命中),故上游对该记账逻辑的修复经继承透明流入;(2) fork 的嵌套 reduction 循环由 NPUIndexTritonKernel.codegen_body/codegen_range 完全自写(torch_npu/_inductor/codegen/triton.py:887-1010),生成显式 Python for 循环并逐迭代重算 indexing,全包零 tl.advance,不把 block_ptr 当作 scf.for 的 iter-arg 跨迭代传递——上游 bug 依赖的 scf.for OOB 机制在 NPU 生成的 Triton 里结构上不成立。因此 torch_npu 无需改代码,但因 fork 同文件且共享继承的 codegen_block_ptr,建议在 NPU 上验证 (a
b).sum()/torch.mean(ab) 这类 [N] 与 [N,1] 广播嵌套 reduction 结果正确,防止 fork 自写循环出现同类截断。 low 否 否 是 compile_stage:Inductor
Test 将 torch.jit.
弃用告警从 DeprecationWarning 改为可见的 FutureWarning,并把 mkldnn 与 distributed.optim 的 TorchScript 编译改为惰性,去除 import 期编译。 被改符号包括 torch.jit._serialization/_freeze/async/script/trace 的弃用告警类别,以及 torch/distributed/optim/functional.py 与 optimizer.py 移除的 @torch.jit.script/@jit.interface 装饰器、torch/utils/mkldnn.py 的惰性 ScriptModule 工厂。对这些符号执行 git grep:torch_npu/jit/register_fusion_pattern.py:9 的 optimize() 直接调用 torch.jit.optimize_for_inference(jit_mod) 对 ScriptModule 做融合优化,torch_npu/utils/serialization.py:264 的加载路径直接调用 torch.jit.load 并在 :254 输出相关提示。→ 这两处构成 torch_npu 对 TorchScript save/load/optimize 接口的依赖链:上游把 jit.save/load/trace 的告警从 DeprecationWarning 升级为默认可见的 FutureWarning,会使 torch_npu 走 jit 路径时新增可见告警,若下游以 -W error::FutureWarning 运行将转为报错;同时 distributed.optim 的 functional 优化器移除顶层 @torch.jit.script 改为纯 Python 执行,行为语义需验证 NPU 上分布式优化器 step 数值一致。影响类型为 API/告警可见性与运行时行为变化。验证方法:在 NPU 上跑 test/test_functional_optim.py 与 torch_npu 融合 pass 加载 ScriptModule 的用例,确认 optimize_for_inference 与 jit.load 不受惰性化影响、告警不误升级为错误。潜在风险:CI 若开启 FutureWarning 转错误会静默中断 NPU jit 加载流程。625 行改动跨 21 文件,需 UT 验证。 medium 否 否 是
Check 将 Dynamo config enable_faithful_generator_behavior 变为弃用 no-op,删除急切生成器分支与死标志。 上游把 enable_faithful_generator_behavior 变为 deprecated no-op 并删除 symbolic_convert.py/functions.py/user_defined.py 中处理 False 分支的死代码(含 is_generator_from_ctx_manager 标志与 _build_inline_tracer override)。属 A 轨修改已有机制。torch_npu 未耦合 Dynamo 生成器 tracing:git grep 三个被改符号在 HEAD 全 0 命中。torch_npu 的 Dynamo 挂钩仅为 torch_npu/dynamo/trace_rule.py:53,79 向 torch_name_rule_map 注入 NPU 函数映射,与 torch_npu/utils/_dynamo.py:355 对 TorchInGraphFunctionVariable._get_handlers() 的 npu stream handler 赋值,二者均不触及 symbolic_convert 的 inline tracer / 生成器路径。config 保留默认 True 且行为不变,NPU 无需改代码,人工确认无影响即可。 low 否 否 是 compile_stage:Dynamo
Test 重写 Dynamo 的 reduce_ex polyfill 对齐 CPython,修复 namedtuple 无 dict 场景。 此 PR 改动 torch/_dynamo/polyfills/copy.py(+40-11)与 test/dynamo/test_misc.py(+36),共 87 行,修复 Dynamo 下 copy.copy/deepcopy namedtuple 时因硬编码返回 obj.dict 而抛 AttributeError 的 graph break。对 reduce_ex、RangeVariable、polyfills 执行 git grep,torch_npu 中未发现对 torch._dynamo.polyfills.copy 的直接引用(仅 torch_npu/utils/hif8_tensor.py:551 自定义了 reduce_ex,属其 HiFloat8Tensor 序列化逻辑,与 Dynamo polyfill 无调用关系)。耦合链路为:torch/_dynamo/polyfills/copy.py 的 reduce_ex polyfill 属 Dynamo 通用 tracing 层 → NPU 编译走 torch_npu 的 aclgraph 后端复用 Dynamo 前端 → 若用户在 NPU 上编译含 copy.deepcopy(namedtuple) 的模型,旧版会 graph break,新版可正常 trace。影响类型为图捕获行为变化(graph break 消除),torch_npu 未 patch 该 polyfill,随上游同步受益。风险是若 NPU 编译流水线曾针对旧 graph break 行为做过 fallback,需跑 NPU 上的 dynamo copy 相关用例确认新 trace 路径无兼容问题。此为纯 Python 前端逻辑变更,落在插件层验证即可。 low 否 否 是
Check 修正 Dynamo RangeVariable.contains,非 int/bool 回退 iter_contains 扫描,对齐 CPython。 上游修复 torch/_dynamo/variables/lists.py 中 RangeVariable.sq_contains:非 int/bool 操作数改走 iter_contains 的 eq 线性扫描(并修正返回 bool)。属 A 轨修改已有 Dynamo 变量方法。torch_npu 未 fork lists.py、未子类化 RangeVariable、未赋值 patch sq_contains/iter_contains:三符号 git grep HEAD 全 0 命中。torch_npu 自定义 VariableTracker 仅 NPUTorchCtxManagerClassVariable 与 _create_npu_autocast_mode_variable(torch_npu/utils/_dynamo.py:17,367),不含 RangeVariable。该修复经继承透明生效,为 CPython 语义对齐的边界 bug fix,NPU 无需改代码,人工确认即可。 low 否 否 是 compile_stage:Dynamo
Test 为 Dynamo 新增 torch.set_autocast_dtype 的 TorchInGraphFunctionVariable 处理器,在 trace 期修改 autocast dtype 后经清理钩子恢复,修复跨 graph break 时全局 autocast 状态变更报错。 上游在 torch/_dynamo/variables/torch.py 为 torch.set_autocast_dtype 新增 TorchInGraphFunctionVariable handler:追踪 _enter_autocast(...,dtype=...) 时应用 trace-time dtype 变更并经 Dynamo cleanup hooks 恢复,修复跨 graph break/restart 时 'Global autocast state changed' 报错。属 A 轨对 _get_handlers() 字典的加项(新增 dict entry,不改结构)。torch_npu 也以赋值式 patch 操作同一字典:torch_npu/utils/_dynamo.py:355 TorchInGraphFunctionVariable._get_handlers()[...] = _handle_npu_device_interface_stream,但仅加 npu stream handler,与新增的 set_autocast_dtype key 不冲突;NPU autocast 走独立路径 NPUTorchCtxManagerClassVariable/_create_npu_autocast_mode_variable(torch_npu/utils/_dynamo.py:17,367-369),未引用 torch.set_autocast_dtype(trace_rule.py/_dynamo.py 中 git grep set_autocast_dtype 0 命中,NPU 侧 set_autocast_dtype 仅为 torch_npu/npu/autocast_utils.py:26 的 C 绑定 eager 封装)。建议在 NPU 跑 autocast enter+graph break+非默认 dtype 的用例,验证 NPU autocast ctx 变量路径的 dtype 恢复行为一致。 low 否 否 是 compile_stage:Dynamo
Check 为 Dynamo 复制 CPython3.14 帧的 PyStackRef_DUP 加判空守卫,避免带断言构建对 null 触发 SIGABRT。 此 PR 改动 torch/csrc/dynamo/cpython_defs.c(+5-1)与 torch/csrc/dynamo/eval_frame.c(+8-1),共 15 行,为 Dynamo 在 eval_frame.c/cpython_defs.c 中复制 CPython 3.14 帧 localsplus 时的 PyStackRef_DUP、PyStackRef_AsPyObjectNew 调用补回 PyStackRef_IsNull 判空,修复 --with-assertions 构建下对 null stackref 触发 SIGABRT。对 PyStackRef_DUP、cpython_defs、eval_frame 执行 git grep,torch_npu 中未发现引用。耦合链路为:torch/csrc/dynamo/eval_frame.c 的 CPython 帧求值 hook 属 Dynamo 的 C 扩展前端,与 CPython 内部 stackref API 绑定 → torch_npu 的 NPU 编译复用 Dynamo 前端但不重实现该 C 层帧复制逻辑(torch_npu 无 cpython_defs/eval_frame 对应文件)→ 该修复对所有后端透明。影响类型为 CPython 3.14 兼容性运行时崩溃修复,torch_npu 随上游 libtorch 同步受益,不需改 NPU 代码。风险是仅在 CPython 3.14 带断言构建下体现,NPU 若在该环境跑 Dynamo 编译需确认修复已生效;验证方法为在 CPython 3.14 --with-assertions 环境跑 NPU 上的 dynamo 编译用例确认无 SIGABRT。属上游 C 扩展缺陷修复,NPU 无适配动作。 low 否 否 是
Check 将 switch 高阶算子的分支索引 clamping 上移到用户侧 switch(...) 调用,集中处理,避免向 dense 实现和 Inductor 下沉 plumbing。 上游把 switch HOP 的 branch index clamping 上移到用户面 switch(...) 调用(torch/_higher_order_ops/switch.py +21/-8,torch/_dynamo/variables/higher_order_ops.py +3/-2),避免向 dense 实现与 Inductor 下沉 plumbing。按 B 轨功能对等三问评估:torch_npu 的 inductor lowering fork(torch_npu/_inductor/ascend_npu_ir/.../inductor_patch/lowering.py)已为 cond(:7013)、while_loop(:7025)、invoke_subgraph(:7050)、with_effects(:7126) 注册 lowering,但对 switch HOP 零注册(git grep 'higher_order.switch' HEAD 0 命中)——NPU Inductor 尚不 lower switch,用户默认路径碰不到;且本改动是设备无关的用户面边界 clamping,不改 dense/Inductor 接口。故 NPU 无需新增代码,人工确认 NPU 未启用 switch HOP 即可。 low 否 否 是 compile_stage:Dynamo
Check 修复 FX GraphModule 序列化时对字符串前向引用注解的处理,把字符串全局项改为字面量绑定而非 import 语句,避免 str 无 name 导致的崩溃。 上游仅修改 torch/fx/graph_module.py 的序列化 import 块格式化逻辑(处理字符串型 forward-reference 注解,避免 str 无 name 触发 Importer.get_name 崩溃),属 A 轨已有机制的边界 bug fix,纯 Python/CPU 侧、设备无关。三重 grep 核查:符号 grep 命中的 Importer/get_name 均在 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/torch_mlir_patch.py:14-210(那是 torch-mlir 的 FxImporter/GraphNodeImporter,与 torch.fx GraphModule 序列化的 Importer.get_name 完全无关);graph_module 命中全部落在 test/ 目录(如 test/fx/test_common_passes.py:12),无 torch_npu 生产代码 fork torch/fx/graph_module.py,也无对被改的序列化 import 块函数的 override 或赋值式 monkey-patch。已排除 override/赋值 patch/fork 三者,torch_npu 未挂钩该符号,改动透明生效。人工确认 NPU 图捕获/序列化路径不受影响即可,无需改代码。 low 否 否 否 compile_stage:Dynamo
Check 优化 CapabilityBasedPartitioner.propose_partitions 复杂度,用按需 DFS 替换缓存传递闭包,内存降为 O(V)、最坏时间 O(V·U),已被 Revert。 被改符号为 torch.fx.passes.infra.partitioner.CapabilityBasedPartitioner 及其 propose_partitions 方法(改用按需 DFS 与 O(V) 快速路径)。在 torch_npu 中执行 git grep 命中直接依赖:torch_npu/_inductor/dvm/graph_fusion.py:14 从 torch.fx.passes.infra.partitioner 直接 import CapabilityBasedPartitioner,:198 定义 class GraphFusionPartitioner(CapabilityBasedPartitioner) 继承该类,:275 调用 self.propose_partitions() 执行图分区,:356 由工厂 GraphFusionPartitioner(...) 实例化。→ GraphFusionPartitioner 继承 CapabilityBasedPartitioner 并复用其 propose_partitions,其产出分区被 torch_npu/_inductor/dvm/graph_fusion.py:292/314/346 的 self.graph_module 融合与 legalize_graph 流程消费,构成 NPU DVM 图融合唯一的分区入口。→ 若上游把 propose_partitions 的分区算法从缓存闭包改为按需 DFS,等价分区上的分组顺序/子图边界若发生语义差异,会直接改变 GraphFusionPartitioner 产出的分区,进而影响 NPU DVM 图融合的子图划分与后续 legalize_graph 结果。影响类型为图分区行为/性能变化。本 PR 声称仅优化复杂度不改分区结果,但带 Reverted 标签已被回退,故其等价性需人工比对确认。验证方法:在 NPU 上跑基于 GraphFusionPartitioner 的 DVM 图融合用例并比对分区数量与子图成员是否一致,重点覆盖含不支持节点的稀疏图。潜在风险:DFS 与闭包在等价分区上的分组顺序差异可能导致 NPU 融合子图边界静默变化。723 行改动(含 382 行测试),需人工 Review 分区等价性。 medium 否 否 是
Test FlexAttention block-mask 校验按 backed/unbacked 分流,避免动态序列长度被特化到首个 BlockMask 长度。 此 PR 改动 torch/nn/attention/flex_attention.py(+45-17)与 test/inductor/test_flex_attention.py(+59),共 121 行,把 block-mask 长度校验的四个无条件 torch._check 拆分为 _validate_block_mask_shape:unbacked 符号长度保留 torch._check,backed 长度回退旧 Python branch/assert,避免动态 query/key 序列长度被 pin 到首个具体 BlockMask 长度而破坏自动动态 shape。对 flex_attention、_validate_block_mask_shape、BlockMask 执行 git grep,torch_npu 中未发现引用。耦合链路为:torch/nn/attention/flex_attention.py 的 BlockMask 形状校验属 PyTorch 前端 attention 模块,其 Dynamo guard 生成行为影响 → torch_npu 若在 NPU 上编译 FlexAttention,走 Dynamo 前端 + inductor 后端捕获该 block-mask 校验 → 修复让 backed 动态序列长度可泛化而非特化。影响类型为动态 shape guard 生成行为变化(编译期特化/重编译),torch_npu 未 patch flex_attention,随上游同步。风险是 NPU 若支持 FlexAttention 编译,旧版会把 query 长度特化到首个 BlockMask 长度导致过度重编译或形状不匹配;验证方法为在 NPU 环境跑 test/inductor/test_flex_attention.py 的 block_mask 动态长度用例确认 guard 泛化正确。此为纯 Python 前端 shape 校验逻辑变更,落在插件层验证,NPU 无 C 层适配动作。 medium 否 否 是
Test 修复 multilabel_margin_loss 前向分解在 -1 填充目标下多计入 u-slot 边际项的数值 bug,使 compile 结果与 eager 一致,并补充填充目标测试样本。 此 PR 修复 torch/_decomp/decompositions.py 中 multilabel_margin_loss 前向分解的数值 bug:当 target 含 -1 填充(标准 ignore 标记)时,原实现未丢弃填充位产生的 u-slot,导致这些槽位 gather input[0] 并贡献虚假边际项,使 compile(inductor 与 aot_eager)的前向 loss 与反向梯度都与 eager 不一致(示例中 1.48 变 1.96);修复复用 target_mask 将损失在 u-slot 轴上对填充位置零(2 行核心改动),并在 common_methods_invocations.py 补充带 -1 的样本使 test_decomp 覆盖该路径。对 multilabel_margin_loss 执行 git grep,torch_npu/csrc/aten/AutoCastOps.cpp:99 的 KERNEL_PRIVATEUSEONE(multilabel_margin_loss, fp32) 处为该算子注册了 NPU autocast fp32 策略,该注册通过 torch_npu/csrc/aten/AutoCastOps.cpp:25 的 TORCH_LIBRARY_IMPL(aten, AutocastPrivateUse1, m) 挂载到 NPU 自动混合精度分发,而 autocast 模式本身由 torch_npu/csrc/utils/AutocastMode.cpp:19 的 set_autocast_enabled(at::kPrivateUse1, ...) 驱动启用,说明 NPU 侧确实接入并执行该算子。耦合链路为:上游分解规则修正 → 该算子在 NPU 上若走 torch.compile/inductor 分解路径,则分解结果随之修正 → torch_npu/csrc/aten/AutoCastOps.cpp:25 注册、torch_npu/csrc/utils/AutocastMode.cpp:19 驱动的 autocast 入口所导向的执行结果对齐。影响类型为数值正确性:若 NPU 依赖该分解,此前 -1 填充目标下的 loss/梯度存在静默错误,修复后与 eager 对齐。验证方法:在 NPU 上跑 test/test_decomp.py -k multilabel_margin_loss 覆盖含 -1 填充目标的样本,比对前向 loss 与输入梯度。潜在风险为静默数值错误:不报错但结果偏大,训练收敛异常。 medium 否 否 是
Test 修复 inductor 在两个有序副作用算子降级为不同 kernel 类型时丢失顺序依赖的 bug,改用 get_operation_name 作为 additional_star_deps 的键以匹配调度器。 上游修复 torch/_inductor/lowering.py 中 with_effects:ORDERED-effectful 算子间的顺序依赖改用 new_op.get_operation_name()(而非 get_name() 的 buffer 名)写入 V.graph.additional_star_deps,与 scheduler 按 operation 名回读一致,避免不同 kernel 类型时顺序依赖被静默丢弃、算子被重排。torch_npu fork 了 lowering:torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:7126-7143 有自有 with_effects,仅调用 ir.EffectfulKernel.create(:7128)并组装输出,未复制上游 additional_star_deps 顺序依赖记录逻辑,故未带同一 bug 也未获同一修复;且 fork 内 get_operation_name 用于其它 lowering(:770,828,7074,7076)。建议在 NPU 上运行 effectful 算子跨 kernel 类型的顺序保序用例,验证 NPU with_effects 下沉不产生同类重排。 low 否 否 是 compile_stage:Inductor
Check 为 AOTInductor extern/ATen kernel 补齐 profiling 输入 shape,扩展 c_shim kernel 参数。 上游在 torch/_inductor/codegen/cpp_wrapper_cpu.py、cpp_wrapper_cpu_array_ref.py、wrapper.py 为 AOTI extern/ATen kernel 在 TORCHINDUCTOR_CPP_ENABLE_KERNEL_PROFILE=1 下补齐 input shape 记录,方式是给 generate_c_shim_extern_kernel_call / _generate_extern_kernel_out_helper 增加带默认值的可选参数(input_handles/num_scalars/output_handle)与新增 _get_profiling_input_handles 方法,向后兼容且仅在 profiling 调试路径生效。torch_npu 确有 fork:torch_npu/_inductor/codegen/cpp_wrapper.py:199 class CppWrapperNpu(CppWrapperCpu)。已打开 fork 对比内容:CppWrapperNpu 覆写的方法为 write_header/generate_kernel_call/define_kernel/generate_args_decl 等(cpp_wrapper.py:322/776/375/548),并未 override 本 PR 改动的 generate_c_shim_extern_kernel_call、_generate_extern_kernel_out_helper、generate_c_shim_extern_kernel_alloc、generate_c_shim_fallback_kernel,这些 C-shim extern kernel codegen 方法从上游 CppWrapperCpu 透明继承。fork 中唯一涉及的 enable_kernel_profile(cpp_wrapper.py:313-320)仅用于决定是否 splice record_function.h 头文件,不触及被改的 extern kernel 记录逻辑。该功能是 profiling 调试特性(PR 自述 no ABI compatibility promise),仅影响 trace 中的 shape 信息,不改主编译/执行接口。人工确认 NPU AOTI cpp_wrapper 的 profiling trace 行为即可,无需改代码。 low 否 否 是 compile_stage:Inductor
Test 修复 Dynamo 复制协程前缀 RESUME 指令时保留了指向失效指令的异常表条目,导致 Python 3.12 协程编译在 propagate 阶段误抛 KeyError,做法是清空复制前缀指令上的 exn_tab_entry。 此 PR 是一处 4 行核心修复(torch/_dynamo/output_graph.py +5 -1,合计 16 行),修复 Python 3.12 协程字节码把异常表条目挂到初始 RESUME 前缀指令上,Dynamo 用 copy.copy() 复制前缀指令后 propagate_inst_exn_table_entries 查找失效指令抛 KeyError 的问题,做法是清空复制前缀指令上的 exn_tab_entry,PR body 标注 Generated by my agent(AI 撰写)。对 output_graph、propagate_inst_exn_table_entries、exn_tab_entry 执行 git grep:torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/npu_inductor_plugin.py:149 处 tracer.output_graph.get_submodule(node.target) 引用了 Dynamo OutputGraph 对象,而 torch_npu/_inductor/init.py:100 通过 register_backend_for_device 把 NPU Inductor 注册为设备后端来承接这些编译产物。耦合链路:上游 Dynamo output_graph.py 编译子图并生成输出字节码 → torch_npu/_inductor/init.py:100 注册的 NPU 后端接收 OutputGraph 产出的 GraphModule → torch_npu 的 npu_inductor_plugin.py:149 在 NPU Inductor 后端从 tracer.output_graph 取子模块以完成 NPU 图编译 → 若上游前缀指令异常表处理改变了生成字节码的 OutputGraph 结构或子图切分时机,NPU 后端从 output_graph 取子模块的路径可能受影响。影响类型为编译期正确性变化(避免协程编译时 KeyError 误触发)。验证方法:在 NPU 环境跑 test/dynamo/test_error_messages.py 的 test_async_return_bytecode_exception_table 与协程/生成器相关用例。潜在风险:NPU 若在 3.12 上编译含协程的模型,未合入该修复会在 propagate 阶段提前抛 KeyError 而非走正常的 unsupported-bytecode 处理,掩盖真实的图中断原因。 medium 否 否 是
Test 修复 FallbackKernel 未记录 re-inplace 算子输出与首参别名,导致内存规划误复用已死输入 buffer 破坏存活的别名输出(影响 _philox_uniform/_philox_normal),改为记录别名保持 buffer 存活。 该 PR 修改 torch/_inductor/ir.py,让 FallbackKernel 为 re-inplaced 变异算子记录 output<->首参 的别名关系,修复内存规划把仍存活的别名输入缓冲区提前判死并复用其存储导致结果损坏的问题。torch_npu 属 A 轨 fork 耦合且走同一内存规划语义:①torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/npu_inductor_plugin.py:233 的 used_or_aliased_buffer_names() 正是通过 buffer.get_inputs_that_alias_output() 遍历别名来计算 set_last_usage()/last_usage(本 PR 补记的别名信息直接决定该函数的存活判定);②torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/scheduler.py:123 的 get_buf_bytes 依赖 buf.get_mutation_names() 处理 NoneLayout 变异缓冲;③torch_npu fork 了上游 ir.py 至 torch_npu/_inductor/codegen/ir_fx.py 与 .../inductor_patch/ir.py(含 FallbackKernel/create 逻辑,见 inductor_patch/lowering.py:2000/2199 的 ir.FallbackKernel.create)。→ 适配方案:核对 ir_fx.py / inductor_patch/ir.py 中 FallbackKernel 是否已包含 output<->首参别名登记,若缺失则同步上游改动,并在 npu_inductor_plugin.py 的 used_or_aliased_buffer_names 上验证 re-inplaced FallbackKernel(如 native_dropout / philox 类变异算子)的别名输入在 last_usage 计算中不被提前释放。→ 验证方法:运行 test/_inductor/test_rngprims_philox_rand.py 的 test_philox_rand_eager_vs_inductor 及 test/_inductor/test_alias.py 确认 NPU 内存规划不复用存活别名存储。 medium 否 否 是 compile_stage:Inductor
Test 修复 Inductor 对 complex64 的 view_as_complex 输出生成 Triton 精确步长拷贝时因不支持复数指针 dtype 报 KeyError 的问题,改走 empty_strided 加 fallback 拷贝保留 eager 步长。 该 PR 修改 torch/_inductor/ir.py:inductor 原先为 complex64 的 view_as_complex 输出生成 Triton pointwise exact-stride copy,而 Triton 签名生成不支持复数指针 dtype,触发 KeyError complex64;修复改为将复数 exact-stride copy 路由到 empty_strided + fallback copy 以保留 eager 输出 stride。torch_npu 属 A 轨 fork 耦合且自带复数处理:①torch_npu fork 了上游 ir.py(torch_npu/_inductor/codegen/ir_fx.py、.../inductor_patch/ir.py,命中 fork 清单);②torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:2839 有 make_fallback(aten.view_as_complex, require_contiguous),lowering.py:2057/843/879 对 view_as_complex 与复数 dtype 有专门分支;③torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/codegen/wrapper.py:105-108 在 config.memory_planning 且 kernel 名含 view_as_complex 时追加 .clone() 规避 view fallback 存储被复用(与本 PR 同类问题);④torch_npu/_inductor/codegen/triton_utils.py:17-18 的 byte_per_numel 显式登记 complex64=8/complex128=16 供 Triton meta 对齐。→ 适配方案:核对 ir_fx.py / inductor_patch/ir.py 的 exact-stride copy 分支是否需同步上游「复数走 empty_strided+fallback copy」改动;确认 NPU 复数路径(view_as_complex 已强制 fallback)不再触发 Triton 签名 KeyError,并评估 wrapper.py 的 .clone() 规避是否可随上游修复精简。→ 验证方法:运行 test/inductor/test_torchinductor.py 中新增的 complex64/view_as_complex 用例与 test/inductor/test_torchinductor_codegen_dynamic_shapes.py 对应用例,在 NPU 上确认 view_as_complex(complex64) 编译产物 stride 与 eager 一致且无签名报错。 medium 否 否 是 compile_stage:Inductor
Check 改进Dynamo异常处理:当用户代码中包含try/except时触发graph break,使异常处理行为对齐eager模式 异常处理graph break仅InstructionTranslator类型注解引用无异常逻辑耦合 low 否 否 是 compile_stage:Dynamo
Check 重新合入 Dynamo 内部属性探查时使用 getattr_static 的变更,修复 innermost_fn 引入额外 Python 帧导致 frame counter 翻倍的问题。 innermost_fn/getattr_static符号torch_npu零引用,纯Dynamo内部实现 low 否 否 是 compile_stage:Dynamo
Check 将 torch.backends.cuda.SDPAParams 路由至 TorchInGraphFunctionVariable,使 SDPAParams 构造在 fullgraph 模式下不再触发 graph break。 SDPAParams fullgraph支持,torch_npu零引用,CUDA专属通路 low 否 否 是 compile_stage:Dynamo
Check 将Dynamo对象协议辅助函数批量重命名以对齐CPython C API命名规范,纯机械重命名无行为变更 23个重命名符号torch_npu零引用,纯机械重命名 low 否 否 否 compile_stage:Dynamo
Check 修正Dynamo cxx pytree polyfill中PyTreeSpec的__eq__和__hash__实现,对齐optree行为 PyTreeSpec变更在Dynamo polyfill层,torch_npu使用C++原生cxx_pytree非polyfill,零耦合 low 否 否 是 compile_stage:Dynamo
Check 将 _is_registered_backend 从 hasattr 改为 isinstance 检查,修复 backend 误判问题 对 _is_registered_backend、_TorchCompileWrapper、_TorchCompileInductorWrapper 等符号执行 git grep,在 torch_npu 中发现引用:torch_npu/utils/_dynamo.py:15 直接从 torch 导入 _TorchCompileWrapper → torch_npu/utils/_dynamo.py:122-123 的 npu_optimize() 函数中使用 isinstance(backend, _TorchCompileWrapper) 检测 backend 类型并读取 compiler_name 属性 → npu_optimize() 在 torch_npu/utils/_dynamo.py:129 被注入为 torch._dynamo.optimize 的替代实现,在 NPU 的 Dynamo 编译入口处被调用。同时 torch_npu/utils/_graph_tree.py:337 的 NpugraphsBackend 类定义了 compiler_name = 'npugraphs',该 backend 通过 torch_npu 的编译注册流程进入 Dynamo。此 PR 将 _is_registered_backend 中的 hasattr 探测改为 isinstance 检查(_TorchCompileInductorWrapper / _TorchCompileWrapper),NPU 代码中已使用 isinstance(backend, _TorchCompileWrapper) 模式与 PR 方向一致。PR 新增的 isinstance 检查逻辑在 registry.py 的 _is_registered_backend 中执行,若 NpugraphsBackend 作为自定义 backend 经过 _is_registered_backend 判断但未被 isinstance 匹配到,将导致 NPU 编译失败。需人工确认 NpugraphsBackend 的注册路径不依赖 is_registered_backend 的 hasattr 旧行为。 low 否 否 是
Check 重构 Dynamo 的 slot dispatch 机制,通过 VariableTracker 的 tp_as
子结构替代 type_implements
* 谓词调度。 tp_as
*重构torch_npu monkey-patch在TensorVariable层级解耦无冲突 low 否 否 是 compile_stage:Dynamo
Check 修复 Dynamo 因 TorchDispatchMode 跳过编译后被永久缓存的问题,改为瞬态跳过 对 TorchDispatchMode、convert_frame 等符号执行 git grep,在 torch_npu 中发现引用:torch_npu/npu/_stream_check.py:13 的 NPUSanitizerDispatchMode 类直接继承 TorchDispatchMode → NPUSanitizerDispatchMode 被 torch_npu/npu/_sanitizer.py:59 的 enable_stream_check() 方法实例化 → enable_stream_check 在 torch_npu/init.py:78 的 apply_sanitizer_patch() 中被注册。同时 torch_npu/npu/graphs.py:88 的 _GraphDispatchMode 也继承 TorchDispatchMode → _GraphDispatchMode 被 torch_npu/npu/graphs.py:189 的 CUDAGraph 初始化创建 → 在 torch_npu/npu/graphs.py:309 的 enter 中激活。此 PR 修改 convert_frame.py 中 TorchDispatchMode 触发的编译跳过行为:将永久跳过改为瞬态跳过。当 NPU 的 NPUSanitizerDispatchMode 或 _GraphDispatchMode 激活时,若触发 Dynamo 编译,此前代码对象会被永久标记为跳过(即使 DispatchMode 退出后也不再编译),PR 修改后该跳过仅在 DispatchMode 激活期间生效。torch_npu 源码中未直接调用 convert_frame(仅在测试文件中引用),此变更为行为改进,不会破坏 NPU 现有功能,且对 NPU 图捕获与编译混合场景更友好。 medium 否 否 是
Check 为 BuiltinVariable 新增 call_setitem 和 call_delitem 方法,将 object_protocol 的 setitem/delitem 分发移至 builtin。 call_setitem/delitem新增方法torch_npu零引用,仅patch call_id不受影响 low 否 否 是 compile_stage:Dynamo
Check 将 _rename_unbacked_to 中异常到 unbacked dest 的断言改为统一合并,解决 ExportProgram 多轮重trace 时的 AssertionError。 "对 _rename_unbacked_to、_unify_unbacked_aliases、symbolic_shapes 执行 git grep,torch_npu 中存在明确的耦合链路:
torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:1164 从 torch.fx.experimental.symbolic_shapes 导入 free_unbacked_symbols
→ torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:3201 从同一模块导入 resolve_unbacked_bindings
→ torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/ir.py:389 调用 ir.free_unbacked_symbols 检查未被支持的符号
此 PR 修改的是 symbolic_shapes.py 中 _rename_unbacked_to 方法的核心行为——原来当 dest 是 unbacked 符号时直接 assert 失败,修复后改为调用 _unify_unbacked_aliases 对所有 alias 进行统一,挑选 backed 终端符号并重定向。torch_npu 的 ascend_npu_ir lowering 层通过 resolve_unbacked_bindings 和 free_unbacked_symbols 与 ShapeEnv 交互,而 _rename_unbacked_to 是 ShapeEnv 内部维护 unbacked 符号 alias 关系的基础方法。若 NPU IR lower 路径触发了 ExportProgram 重 trace(如包含 aten._unique2 等数据依赖算子),修复前的代码会在 NPU 后端同样触发 AssertionError(""{orig_s} -> {dest}""),修复后则正常统一。ir.py:404 处的 is_contiguous_storage_and_layout 判断也依赖 free_unbacked_symbols 的返回值——统一逻辑变更后,backed 终端优先的语义保证 backedness 不被丢失,这对 NPU IR 的 size hint 推断有利。验证方法:在 NPU 环境下对包含数据依赖算子的 ExportProgram 执行多轮重 trace(含 unbacked_bindings),确认不再触发 _rename_unbacked_to 异常。" medium 否 否 是
Check 修复Dynamo中动态SymInt的f-string跨图断点时格式包装器丢失导致的TypeError崩溃 "此 PR 修改 torch/_dynamo/symbolic_convert.py 中 f-string 的 BUILD_STRING 字节码处理——当 f-string 跨 Dynamo 图断点时,对动态 SymInt 的 FORMAT_VALUE 包装器传入 source=None 而非共享 SymInt 的 source,避免格式字符串与 SymInt 共享缓存槽导致类型错误。

耦合链路:
torch_npu 中未发现对被改符号 BUILD_STRING 或 FORMAT_VALUE 的 SymInt 处理逻辑的直接引用,
但 torch_npu 使用 torch._dynamo(通过 torch.compile 入口)进行 NPU 图捕获,所有 Dynamo trace 的字节码解释均经过 symbolic_convert.py 中的符号转换器。
当 NPU 模型代码中包含跨图断点的 f-string 且 f-string 内嵌动态 SymInt(如打印调试信息 f""batch={batch_size}"" 跨图断点),在修复前将触发 TypeError: sequence item N: expected str instance, int found 崩溃。
修复后 source=None 使格式字符串的 SymInt 包装器不与原始 SymInt 共享 source,确保跨图断点后格式字符串正确生成。
影响范围:NPU 上使用 torch.compile 且包含 f-string 动态 SymInt 跨图断点的模型。" medium 否 否 是
Check 为 VariableTracker 引入声明式 tp_methods 分派机制,支持集中化参数校验,暂未迁移任何 VT。 tp_methods声明式dispatch无VT迁移,torch_npu monkey-patch在TensorVariable层解耦 low 否 否 是 compile_stage:Dynamo
Check 修复AotAutograd重入时bw_compiler自引用属性导致嵌套编译异常的问题 "对 aot_autograd、bw_compiler、_is_wrapped_bw_compiler 执行 git grep:
torch_npu/utils/_graph_tree.py:16 通过 from torch._dynamo.backends.common import aot_autograd 直接导入被修改的 AotAutograd 类;
torch_npu/utils/_graph_tree.py:327-331 在 npugraphify 函数中调用 aot_autograd(fw_compiler=forward_npugraphs, bw_compiler=backward_npugraphs, inference_compiler=...) 构建 AOT 编译管道。
此 PR 修改 torch/_dynamo/backends/common.py 中 AotAutograd.call 方法——当 AOT 后端编译第二个独立 graph 发生重入时,bw_compiler 已被包装,原代码的 _is_wrapped_bw_compiler 分支错误执行 bw_compiler.compiler_fn = bw_compiler 造成自引用属性,修复后该分支直接保持 bw_compiler 不变(idempotent)。耦合链路:
→ torch_npu/utils/_graph_tree.py:16 import aot_autograd → torch_npu/utils/_graph_tree.py:327-331 npugraphify 函数调用 aot_autograd() 并传入 bw_compiler=backward_npugraphs
→ torch_npu/utils/_graph_tree.py:353 通过 register_backend 将 NpugraphsBackend 注册为 ""npugraphs"" 后端,其 NpugraphsBackend.call → npugraphify → aot_autograd
→ 当 npugraphs 后端编译包含嵌套 Dynamo 子图(如 FSDP + torch.compile 组合)的模型时,AotAutograd.call 发生重入,bw_compiler=backward_npugraphs 已处于包装状态
→ 修复前:_is_wrapped_bw_compiler 分支执行 bw_compiler.compiler_fn = bw_compiler 产生自引用,破坏 backward_npugraphs 的编译器包装链,导致嵌套编译场景下 NPU npugraphs 图捕获失败
→ 修复后:_is_wrapped_bw_compiler 分支保持 bw_compiler 不动,backward_npugraphs 在重入场景下编译行为正确
断裂点位于 torch/_dynamo/backends/common.py 中 AotAutograd.call 的重入处理逻辑——isinstance(bw_compiler, functools.partial) 判断句。修复前 NPU npugraphs 后端在嵌套编译场景下因 bw_compiler 自引用导致编译异常,修复后恢复正常。受影响范围:NPU npugraphs 后端的嵌套 Dynamo 图编译场景(多图重入)。" medium 否 否 是
Test EventVariable.python_type 返回实际子类类型而非硬编码 torch.Event,修复子类化 Event 的 Dynamo trace 错误。 EventVariable.python_type()修复NPU已有相同monkey-patch,上游合入后变冗余可清理 low 否 否 是 compile_stage:Dynamo
Check 为torch.cond/switch HOP添加input mutation功能支持,引入functionalization组件 switch input mutation支持torch_npu仅实现cond未实现switch零耦合 low 否 否 是 compile_stage:AOTAutograd
Check 将Dynamo UDOV的generic_getattr内部逻辑提取为lookup_instance_dict和call_getattr_fallback独立钩子方法 UDOV hook抽取torch_npu零引用所有符号,纯重构零影响 low 否 否 否 compile_stage:Dynamo
Check 为 disable()/compiler.disable() 提供专用图断原因消息,替代通用 skipped-function 模糊提示。 graph break诊断优化monkey-patch在__new__层级与call_function变更解耦 low 否 否 是 compile_stage:Dynamo
Check 修复子类 fake tracing 导致的嵌套编译,添加线程局部守卫在编译器内部追踪期间强制 eager 执行以避免模式不匹配。 嵌套编译guard torch_npu零引用,NPU编译流程不触发重入条件 low 否 否 是 compile_stage:Dynamo
Check 修复 Dynamo 自动动态 PGO 中 Python int 仍走特化路径的 bug:将已观测变化的 int source 路由到 SymInt 路径。 int specialization路由修复torch_npu VariableBuilder零引用透明生效 low 否 否 是 compile_stage:Dynamo
Test 修复torch.compile中indutor克隆未对齐输入后,输出别名指向错误切片导致计算静默错误的严重Bug,影响FSDP2+DTensor分布式训练场景。 gen_alias_from_base修复透明生效,torch_npu未引用该符号,通过AOTAutograd公共路径自动受益 low 否 否 是 compile_stage:AOTAutograd
Test 修复 Inductor 中 optimization_hint 对 unbacked symint 的 hint 计算忽略 runtime assert 约束导致的负值溢出。 torch_npu 中未直接引用被改符号 _optimization_hint_base。但 torch_npu/_inductor/codegen/catlass/gemm_template.py:779-780 的 Catlass GEMM 模板调用 V.graph.sizevars.optimization_hints(A_layout.size) 获取 size 提示,torch_npu/_inductor/codegen/scheduling.py:263 和 torch_npu/_inductor/codegen/scheduling.py:777-791 的 NPU scheduler 在 kernel 调度时调用 V.graph.sizevars.optimization_hints 确定 grid 大小。torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/scheduler.py:58-62 定义了 NPU 的 try_size_hint 函数,内部调用 V.graph.sizevars.optimization_hint 获取 size 提示,用于 Ascend NPU IR 的调度决策。torch_npu/_inductor/codegen/ir_fx.py:138 和 torch_npu/_inductor/codegen/ir_fx.py:882 的 NPU IR 代码生成也使用 optimization_hint 判断计算规模。耦合链路:上游 _size_hinting.py 的 _optimization_hint_base 变更 → V.graph.sizevars.optimization_hints 的返回值行为变化 → torch_npu/_inductor/codegen/scheduling.py:263 的 NPU scheduler grid 计算 → torch_npu/_inductor/codegen/catlass/gemm_template.py:779 的模板选择 → torch_npu/_inductor/ascend_npu_ir/.../scheduler.py:59 的 NPU IR 调度。上游修复确保 unbacked symint (如 s44 - u0) 在考虑 runtime_assert 约束后返回非负 hint,防止负值导致 storage size 溢出。torch_npu 的 NPU inductor backend 使用优化提示进行性能决策(scheduler tuning、template selection、grid size),若 hint 值在 NPU 路径上因未 tightened 而产生负值,可能导致 NPU kernel 编译或调度异常。需在 NPU 环境验证:1) 含 unbacked symint 的 PrismNet 类模型在 NPU 上 compile 是否正常(不出现 storage size 溢出);2) NPU scheduler 的 optimization_hints 返回值在含 runtime assert 的 unbacked 场景下是否非负;3) Catlass GEMM 模板选择在 NPU 上是否因 hint 值变化产生不同调度决策。 medium 否 否 是
Check 修复 Inductor view lowering 对 raw IR 节点丢弃视图信息导致 transpose 后的 mm 计算结果错误的问题,移除 tuned_mm 中的 .clone 临时绕过。 上游View.create行为变更影响NPU IR中ReinterpretView构造,ir.py:433 monkey-patch需同步适配view layout信息传递 medium 是 "是
• ascend_npu_ir._patch_view_create猴子补丁:适配ReinterpretView构造匹配上游View.create新语义。PyTorch lowering.view()对raw IR节点保留view layout→CUDA View.create传递layout→NPU _patch_view_create构造CANN Graph IR→上游变更后ReinterpretView可能错误丢弃layout→CANN需适配patch使正确传递view layout;建议:同步更新_patch_view_create的ReinterpretView构造逻辑验证transpose+mm场景" 是 compile_stage:Inductor
Check 对 -L 库目录路径添加 shlex.quote 引用,修复 macOS uv Python 安装路径含空格时 C++ 编译失败的问题。 "对 cpp_builder、shlex.quote 执行 git grep,发现 torch_npu 对 cpp_builder 的耦合链路如下:
torch_npu/_inductor/cpp_builder.py:7 通过 import torch._inductor.cpp_builder as cpp_builder 导入上游 cpp_builder 模块
→ torch_npu/_inductor/cpp_builder.py:162 的 patch_get_cpp_torch_device_options 将上游的 get_cpp_torch_device_options 替换为 NPU 定制版本
→ torch_npu/_inductor/codecache.py:26 的 library_paths 和 torch_npu/_inductor/profiler.py:31 的 get_ascend_home 均依赖 cpp_builder 的编译基础设施
此 PR 在 cpp_builder.py 中为 -L 库目录添加 shlex.quote,与 #148271 中为 -I 目录添加的 quote 对齐。由于 torch_npu 的 cpp_builder 是在上游 cpp_builder 基础上 patch 的,上游的 get_command_line 或类似的命令构建函数若被 torch_npu 间接复用,则 -L 路径含空格时同样受益于此次修复。torch_npu 的 _get_optimization_cflags(cpp_builder.py:166)和 get_cpp_torch_device_options(cpp_builder.py:88)均构造编译选项,若这些函数的输出经过上游被改的命令构建路径,则空格处理行为已改变。验证方法:在 NPU C++ 编译的库路径包含空格的场景(如 C:\Program Files...)下编译 NPU inductor 生成的 C++ 扩展,确认链接命令正确。潜在风险:shlex.quote 与 if_npu 路径下的 _get_optimization_cflags 选项组合可能出现重复转义,需验证带空格路径时 NPU inductor 扩展的正确性。" medium 否 否 是
Check 修复ModularIndexing.eval中Add分支在surviving term可能为负时错误剥离项的问题,防止越界内核生成 对 ModularIndexing 执行 git grep,在 torch_npu 中发现大量深度耦合。torch_npu/_inductor/codegen/ir.py:9 导入 from torch._inductor.ir import FloorDiv, ModularIndexing,整文件有 60+ 处引用,包括 split_indexing(line 1027)、extract_coefficient(line 886)、eliminate_modular_indexing(line 961)等核心索引分解函数,构成 NPU Triton/Alight 代码生成的索引表达式引擎。torch_npu/_inductor/codegen/ir_fx.py:247-254 在 fx 图模式的 md.index 查找中使用 ModularIndexing。torch_npu/_inductor/codegen/triton.py:70 导入 ModularIndexing,在 NPU Triton kernel 的 iteration loop(line 597-712)中构造 ModularIndexing 表达式,驱动 NPU 的 grid/block 维度计算。torch_npu/_inductor/lowering_fx.py:68 导入并使用 ModularIndexing 在 lowering 阶段生成索引。torch_npu/_inductor/triton_experimental/codegen/triton.py:47 导入 ModularIndexing,在 SIMT 变量融合(line 1716-1918)和迭代域拆分(line 2031-2081)中大量使用进行索引代数化简。上游 ModularIndexing.eval 的 Add 分支修复(torch/utils/_sympy/functions.py)改变了项剥离的保守性:允许剥离条件从 is_nonnegative is not False 收窄为 is_nonnegative is True,可能拒绝部分 torch_npu codegen 中原本合法的化简,导致生成的 Triton 索引表达式冗余(但不会错误);同时修正了负 base 被错误剥离的 bug,避免 NPU 上生成带越界访问的内核。此变更通过 torch_npu 继承的 ModularIndexing 类在索引化简、loop ordering、split tiling 等路径中生效。 medium 否 否 是
Check 为 Inductor 新增 E8M0 到浮点类型的 bit-level 转换 lowering,处理 NaN/zero 编码后转换到目标 float dtype,替代 ldexp fallback。 E8M0 lowering NPU通过DLConvertor.cpp:88已注册ACL类型映射,无冲突 low 否 否 是 compile_stage:Inductor
Check 修复 cpp_wrapper 模式下单元素 Tensor[] 返回值 fallback 算子因解包逻辑错误导致空指针崩溃的 bug。 对 generate_fallback_kernel_with_runtime_lookup_python、CppWrapperCpu、unsafe_alloc_void_ptr_from_tensor、unsafe_alloc_void_ptrs_from_tensors 等关键符号执行 git grep。torch_npu/_inductor/codegen/catlass/catlass_kernel.py:15 导入 CppWrapperCpu 且 :296 断言 isinstance(wrapper, CppWrapperCpu);torch_npu/_inductor/codegen/cpp_wrapper_npu.py:464 说明其 CppWrapperNpu 继承链为 CppWrapperGpu → CppWrapperCpu;torch_npu/csrc/inductor/aoti_runner/pybind.cpp:47-56 绑定了 unsafe_alloc_void_ptrs_from_tensors 和 unsafe_alloc_void_ptr_from_tensor。torch_npu/csrc/inductor/aoti_runner/pybind.cpp:47 的 unsafe_alloc_void_ptrs_from_tensors → 被 torch_npu/_inductor/codegen/cpp_wrapper_npu.py 继承链中的 generate_fallback_kernel_with_runtime_lookup_python 调用 → 该方法的解包逻辑从此 PR 开始根据 op schema 而非输出节点数选择 PyList_GET_ITEM 或裸 capsule。若 torch_npu 的 cpp_wrapper 模式下遇到单元素 Tensor[] fallback 算子,旧代码错误取到 NULL handle 导致 SIGSEGV,此修复解决了该崩溃路径。需在 NPU 环境的 cpp_wrapper 模式下验证单元素 Tensor[] 返回值的 fallback 算子编译与运行。 medium 否 否 是
Check 在Triton codegen的reduction循环中读取已存buffer前插入debug_barrier,修复跨warp的读后写竞争问题 debug_barrier NPU实验codegen已主动剥离(triton.py:3537注释NPU无warp不需要barrier) low 否 否 是 compile_stage:Inductor
Check 修复 Inductor index propagation 编译时因 inf/nan 转 int 导致的 OverflowError 崩溃。 torch_npu 中未直接引用被改符号 SymPyOps.to_dtype 或 index_propagation。但 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:781-789 定义了 NPU 的 to_dtype 算子覆盖函数,该函数通过 register_fn_to_aten_fn 注册 NPU 的 dtype 转换实现。index_propagation 在常数折叠阶段使用 SymPyOps.to_dtype 进行 dtype 转换,当 inf/nan 转 int 时使用 Python int() 会崩溃。上游修改在 SymPyOps.to_dtype 中对非有限常数值返回 NotImplemented,使折叠回退到 runtime 语义。torch_npu 的 NPU lowering(torch_npu/_inductor/ascend_npu_ir/.../lowering.py:410)也调用 to_dtype 处理 dtype 转换,NPU codegen 路径可能经过同样的 index_propagation 常数折叠阶段。torch_npu 的 Ascend NPU IR 使用 ascend_npu_ir 独立实现来替代 Triton codegen,index_propagation 阶段可能在 NPU Inductor 路径中执行。需验证 NPU 环境下:1) 编译类似 sum(log(zeros), dtype=torch.int32) 的算子在 NPU 上是否正常(不崩溃);2) NPU lowering 中的 to_dtype 实现(lowering.py:781)是否能正确处理 index_propagation 回退后的 runtime dtype cast。 low 否 否 是
Check 将Inductor Triton共享min/max辅助函数改用Triton原生PropagateNan.ALL操作,SM80+可替换compare/select序列为原生指令,同时提供strict_signed_zero可选路径。 triton_helpers NaN传播通过star-import透明继承,NPU已有propagate_nan=True low 否 否 是 compile_stage:Inductor
Test 增强 simplify_with_ranges 使其能折叠嵌套 ModularIndexing 表达式,简化 Inductor 逆索引计算的代码生成。 ModularIndexing折叠5个torch_npu文件直接耦合,NPU索引表达式简化路径自动受益 low 否 否 是 compile_stage:Inductor
Check 将precompile artifact的运行时驱动代码从手写字符串字面量重构为真实类型化函数,通过getsource生成 torch_npu 中未直接引用被改符号 _precompile、_precompile_driver、precompile,但 torch_npu 的 inductor 集成通过 torch_npu/utils/_inductor.py:18-19 注册 NPUDeviceOpOverrides 并走标准 torch._inductor.compile_fx 编译流程。torch.compiler.precompile 是可选功能,capture 时通过 inspect.getsource 将 _precompile_driver.py 中的真实函数发射到 artifact 中。此次重构将运行时驱动从手写字符串改为类型化函数(消除 # noqa: F821、统一 _extract_param_buffers/_fail/_check_structure 辅助函数),artifact 行为不变(不 import torch._precompile_driver,携带文本以保持版本冻结)。torch_npu 中未使用 precompile 功能,但若未来 NPU 用户使用 torch.compiler.precompile 导出 inductor 图,artifact 中包含的驱动代码会调用 torch.compile/inductor 标准入口,对 NPU 后端透明。影响范围:torch.compiler.precompile 的 artifact 格式(驱动文本变化但行为一致,不影响 NPU 运行时)。 low 否 否 是
Check 修复AOTInductor双包装器lazy-autotune下const-graph的codegen与入口参数不匹配 const_graph修复torch_npu codegen_with_cpp_wrapper自行构建real_inputs绕过受影响路径 low 否 否 是 compile_stage:Inductor
Check 支持invoke_subgraph区域的前向/反向使用独立的inductor配置,实现编译选项按阶段分离 invoke_subgraph新功能torch_npu仅注册lowering不含compile options,透明受益 low 否 否 是 compile_stage:Inductor
Check 修复多行 get_raw_stream 代码片段注入 benchmark kernel 时的 IndentationError,调整为先 dedent 再 format。 benchmark kernel格式修复继承生效,NPU单行import不触发多行bug low 否 否 是 compile_stage:Inductor
Check 修复invoke_subgraph在输入mutation区域中处理带别名标注的Tensor!自定义算子时functionalize失败的问题 对 invoke_subgraph、do_auto_functionalize_v2、FunctionalCallableWithEpilogue、auto_functionalized_v2 执行 git grep。torch_npu/inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:7050-7051 注册了 @register_lowering(torch.ops.higher_order.invoke_subgraph) 的 NPU lowering 函数 invoke_subgraph(subgraph_fn, identifier, operands),这是 NPU inductor 处理 invoke_subgraph 算子的关键入口。上游变更修改了 auto_functionalize.py 的 do_auto_functionalize_v2 中 FunctionalCallableWithEpilogue 的 functionalization 路径:当 subgraph 包含输入 mutation 时,将原来指向 C++ functionalize(torch.func.functionalize)的路径改为 Python functionalization(dispatch_functionalize),添加 propagate_input_mutations 参数使 epilogue 的 copy 保持生效。NPU 的 invoke_subgraph lowering 函数本身是 graph-level 的注册,不直接调用 auto_functionalize 内部函数,但 invoke_subgraph 算子被 inductor 调度时的完整流程会经过 auto_functionalize 逻辑进行 functionalize 处理。若 NPU 场景下 invoke_subgraph 的子图中包含带 alias annotation 的 Tensor! 自定义算子,修复前会因 C++ functionalize fallback 拒绝 alias info 而报 RuntimeError,修复后通过 Python functionalization 路径正确完成。torch_npu 的 lowering 注册不与 auto_functionalize 内部实现直接耦合,该 fix 不要求 torch_npu 修改代码,但修复了涉及 NPU invoke_subgraph 使用场景的功能缺陷。 medium 否 否 是
Check 修复自定义 Triton 方言中 HOP 突变分析遗漏读写操作集的问题,暴露 read/write op sets 供外部后端注册自定义算子。 "对 triton_kernel_wrapper_mutation、TritonKernelWrapperMutation、TritonKernelWrapperFunctional 执行 git grep,在 torch_npu 中发现多处关键引用。

耦合链路:

  • torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:28torch._higher_order_ops.triton_kernel_wrap import triton_kernel_wrapper_mutation,并在 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:6992 通过 @register_lowering(triton_kernel_wrapper_mutation) 注册 NPU lowering 处理函数 triton_kernel_wrap_,该函数在 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py:7001kernel_side_table 获取常量参数并构造 ir.UserDefinedTritonKernel
  • torch_npu/_inductor/lowering.py:1030-1031TritonKernelWrapperMutationTritonKernelWrapperFunctional 加入 lowering 映射表,决定算子是否被正确降级。
  • torch_npu/_inductor/dvm/mlir_fusion.py:3 import triton_kernel_wrapper_mutationtorch_npu/_inductor/dvm/mlir_fusion.py:105 将其加入支持的 HOP 集合,torch_npu/_inductor/dvm/mlir_fusion.py:361-363 通过判断 node.target is torch.ops.higher_order.triton_kernel_wrapper_functional/mutation 决定融合行为。

此PR将 triton_kernel_wrap 模块中的 _TRITON_HOP_READS_TRITON_HOP_WRITES_TRITON_HOP_UNKNOWNS 暴露为公开 API 供外部后端注册自定义 op。torch_npu 通过 register_lowering(triton_kernel_wrapper_mutation) 使用该模块,并依赖 TritonKernelWrapperMutation 类型的 lowering 判定。变更主要影响 customize op mutation 分析的准确性——若 torch_npu 的自定义 Triton 方言在未来注册了新的读写 op,需遵循新的 API 模式。当前 torch_npu 的 triton_kernel_wrap_ lowering 函数不涉及自定义 op 注册,接口未被破坏,但需关注该模块 mutation analysis 逻辑变更对功能化(Functionalization)可能导致的副作用。" medium 否 否 是
Test 使能invoke_subgraph区域的嵌套inductor配置,通过HOP元数据将per-region config贯穿编译、代码生成和缓存 invoke_subgraph区域独立fw/bw inductor配置,NPU注册lowering需验证兼容性 medium 否 否 是 compile_stage:Inductor
Check 修复inductor模式匹配器在pattern替换时丢弃用户stream标注的问题,确保非输出中间节点保留正确的stream上下文 对 percolate_tags、_transfer_meta 执行 git grep,torch_npu 中未发现直接引用。torch_npu 多处导入 pattern_matcher 模块对象:torch_npu/_inductor/fx_passes/post_grad.py:5 导入 LoweringPatternEntry,torch_npu/npu/npugraph_ex/init.py:7 导入 SearchFn/ReplaceFn/TraceFn/PatternExpr 等融合注册工具。这些导入使用的是 pattern_matcher 的公开 API(模式注册、融合入口),而本 PR 修改的是 percolate_tags 内部标签传播函数以及 _transfer_meta 的 custom meta 传递,属于 pattern_matcher 模块的内部实现细节。torch_npu/npu/npugraph_ex/init.py:7-9 使用 fwd_only 和 SearchFn 构造融合 pattern,不经过 percolate_tags 的 stream meta 传播路径。torch_npu 的融合匹配流程中,节点 stream 信息由各自后端独立管理,不依赖上游 pattern_matcher 的 custom meta 传播机制。此 PR 不影响 NPU 功能。 low 否 否 是
Check 将Inductor中MX scaled_mm_v2的fallback统一路由到v2 aten kernel,替代之前错误走v1 aten__fp8_mm的路径,修复非swizzle布局的精度问题。 对 scaled_mm_v2、tuned_scaled_mm_v2、aten._scaled_mm 等关键符号执行 git grep:torch_npu/_inductor/lowering_fallback_list.py:87 将 aten._scaled_mm.default 注册在 NPU 的 lowering fallback 列表中。此 PR 修改 torch/_inductor/kernel/mm.py 中 scaled_mm_v2_fallback 的 fallback 路由逻辑——将原先缺少 Triton 模板时错误回退到 v1 的 aten._fp8_mm 路径,统一改为回退到 v2 的 aten._scaled_mm_v2 eager 算子。torch_npu/_inductor/lowering_fallback_list.py:87 的 aten._scaled_mm 注册 → 被 NPU inductor lowerer 在 torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py 中通过 register_lowering 机制引入 → 当 NPU 的 scaled_mm 路径无模板命中时走 fallback,新的统一 fallback 直接调用 aten._scaled_mm_v2,与 NPU 已有的 v2 注册一致。需验证 NPU 上 MXFP8/MXFP4 等非标准 scale 排布在 inductor 编译路径下不再出现 scale_b 方向错误。 medium 否 否 是
Check 将多流场景下 copy_if_misaligned 提升到 prologue 以消除并发对齐修正在不同流间的竞争条件,避免因行序依赖导致的正确性错误。 copy_misaligned hoisting NPU图捕获路径独立调用不经过wrapper codegen low 否 否 是 compile_stage:Inductor
Check 修复scheduler重新计算节点循环体后mutation_renames丢失导致max_pool2d反向梯度计算错误 mutation_renames修复torch_npu全版本零引用,继承Scheduler透明生效 low 否 否 是 compile_stage:Inductor
Check 在 Inductor scheduler 中排除含间接索引(indirect-indexing)的节点,防止其被错误地合入 combo kernel 导致功能异常。 combo kernel排除indirect-indexing NPU通过can_fuse委托继承透明生效 low 否 否 是 compile_stage:Inductor

likedislike
rmch成员
8月4日 评论:

基于 issue #7 正文 54 条和评论补充 117 条记录,我建议 torch_npu 2.14 优先规划以下 5 个新特性。已排除纯类型重构、已 Revert、CPU/CUDA 专属和无需 NPU 适配即可继承的修改。

优先级 新特性 用户价值 开发量
P0 NPU 动态形状安全编译 减少动态训练编译崩溃和静默越界
P0 NPU FlexAttention 训练增强 支持动态稀疏注意力和可学习 score_mod 中高
P1 NPU HOP 控制流与 Mutation 扩展 map/cond/switch 可编译范围
P1 NPU Compile Doctor 定位编译卡死、失败 config 和性能问题
P2 NPU 离线预编译 Python 包 降低部署冷启动,不依赖运行时重新编译

1. NPU 动态形状安全编译

把上游多个零散 PR 整合成统一的 NPU Shape/Index Safety 能力:

  • simplify_with_ranges 递归时完整传递 loop-local range。
  • 根据 kernel 实际 load/store 索引表达式选择 int32/int64。
  • 支持 AOTAutograd backward 中 replaced/unbacked SymInt 绑定。
  • Python wrapper 显式传递自由符号,避免从 tensor shape 反推失败。
  • 加强 ModularIndexingFloorDiv 和 runtime assert 的值域分析。

torch_npu 有多套独立或 fork 后的索引实现,不能只依赖上游自动生效:

建议交付形态:公共的 NPUIndexRangeAnalysis,供默认 Triton、TE 和 MLIR 复用。只有全部实际地址表达式都能证明不溢出时才使用 int32。

验收重点:动态 batch/sequence、chunk/slice、间接索引、动态 backward,在 A2/A5 上无编译失败、无越界、无精度问题。

2. NPU FlexAttention 训练增强

结合 2.14 PR,形成一个用户可感知的 FlexAttention 能力包:

  • 支持 0-D 可学习 score_mod bias 及其 backward gradient。
  • BlockMask 长度支持 unbacked SymInt,避免动态序列长度被首次输入特化。
  • 修复 captured buffer gradient 的 ComputedBuffer name is None
  • 支持 FlexAttention AOTAutograd cache,减少重复编译。
  • 保持 autocast 和动态 shape 可组合使用。

torch_npu 自己维护完整的 FlexAttention lowering 和模板,不能假设上游修改全部透明进入。目前主要适配点是 flex_attention.py

验收标准:

  • scalar、1-D、broadcast captured bias 都能训练。
  • compiled/eager 的 Q/K/V 和 bias gradient 对齐。
  • 动态 Q/KV sequence 二次运行不重新特化。
  • 不通过 fallback 实现。

3. NPU HOP 控制流与输入 Mutation

将以下上游能力组合为 NPU Structured Control Flow:

  • torch._higher_order_ops.map 支持输入 mutation。
  • torch.condswitch 支持分支输入 mutation。
  • switch 支持 Autograd。
  • 自定义 Tensor! 算子在 invoke_subgraph 中正确 functionalize。
  • 外部 Triton/NPU 自定义算子可以注册 read/write op sets。

这能让包含控制流、foreach 优化器、MoE 路由和动态分支的模型保持 fullgraph=True,减少 graph break。

torch_npu 需要重点适配:

  • NPU 自定义算子的 alias/mutation schema。
  • functionalization 后的 mutation rename。
  • scheduler 中 ordering dependency。
  • MLIR、默认 Triton、TE 三后端行为一致。

验收标准是分支和循环中的 mutation 与 eager 一致,并验证 forward、backward、缓存复用和多次调用。

4. NPU Compile Doctor

将编译工作进程看门狗、阶段上报和 autotune 输入日志整合成 NPU 编译诊断工具:

  • 编译超过阈值时上报 kernel、PID 和所处阶段。
  • 区分 cache lookup、Triton/MLIR compile、launcher build、autotune benchmark。
  • worker 异常退出后立即让 pending future 失败,不再永久卡在 async_compile.wait()
  • TORCH_LOGS=autotuning_inputs 输出 shape、dtype、stride、候选 config。
  • 保存最后失败 config、编译缓存目录和编译器错误摘要。

当前 TE 覆写了自己的 NPUCachingAutotuner_precompile_worker,所以上游新增的 phase hook 不会完整覆盖 NPU。MLIR 也直接创建了 SubprocPool

这个特性开发量不大,但对定位“所有 autotune config 编译失败”和长时间卡死非常有价值。

5. NPU 离线预编译 Python 包

跟进 2.14 的 compile_to_python 和未来 torch.compiler.precompile

artifact = torch.compiler.precompile(model, inputs, backend="npu")
artifact.save("model_npu")

目标产物包含:

  • AOTAutograd wrapper。
  • NPU Inductor 生成模块。
  • Triton/MLIR/CATLASS kernel 源码或二进制缓存。
  • shape guard、设备与 SoC 兼容信息。
  • 一个可直接调用的 Python call(args) 接口。

torch_npu 已经具备较好的基础设施:

需要补齐的是生成源码捕获、NPU kernel cache 打包、A2/A5 兼容校验以及动态 shape guard 序列化。

直接收益是部署环境首次运行不再现场编译,降低冷启动并提高产物可复现性。

第一版推荐落地顺序:先做 Compile Doctor,随后推进动态形状安全和 FlexAttention;HOP Mutation 与离线预编译作为两条中期能力线。性能方向的 GEMM prologue hoisting、NPU cooperative reduction 可以作为下一批候选。

likedislike
rmch成员
8月4日 评论:
likedislike
rmch成员
8月4日 评论:
likedislike