Closed
[Bug]:jitCompile为enable时is_jit_compile_flase 优先根据jitCompileInit判定 #5251
JesseAdd on  Sep 29Closed at  Oct 8
Jesse
JesseCollaborators
Sep 29 Create

在提交新问题之前,请确保您已经在社区中搜索过相关问题,并使用了社区中提供的资源/工具后,仍未找到满意的解决方式。

⚠️ 安全信息提醒:请仔细检查提供的文本内容,确保其不包含敏感数据信息,包括但不限于:

  • API 令牌或密钥
  • 密码或身份验证凭证
  • 私有网址或接口地址
  • 个人或机密数据
  • ...

在分享配置信息或代码示例时,请将敏感信息脱敏处理,或使用 <TOKEN> 等占位符替代原有内容。

环境信息

pta2.7.1+

🐛 问题描述

显式开启 JIT Compile 后状态查询仍返回关闭

问题场景

在 NPU 已完成初始化、初始化阶段记录的 JIT Compile 状态为关闭时,再通过接口显式开启 JIT Compile:

import torch
import torch_npu

print(torch_npu.npu.is_jit_compile_false())
torch_npu.npu.set_compile_mode(jit_compile=True)
print(torch_npu.npu.is_jit_compile_false())

此时内部配置为:

jitCompile=enable
jitCompileInit=disable

预期第二次查询返回 False,表示当前 JIT Compile 已开启;实际仍返回 True,导致以下断言失败:

self.assertFalse(torch_npu.npu.is_jit_compile_false())

该问题受npu初始化行为影响。若 test_jit_compile_false 先执行,它会在初始化前显式设置 jitCompile,使后续测试无法构造 jitCompileInit=disable、jitCompile=enable 的状态,因此问题会被掩盖。需要注意不同测试框架会影响 NPU 初始化时机。

原因分析

jitCompileInit 表示 NPU 初始化阶段读取并保存的初始状态,jitCompile 表示用户后续显式设置的当前状态。

原有 is_jit_compile_false 判断逻辑只在 jitCompile=disable 时直接返回 True。当 jitCompile=enable 时,代码仍继续读取 jitCompileInit;如果初始值为 disable,最终仍返回 True:

jitCompile=enable
        ↓ 未直接返回
jitCompileInit=disable
        ↓
返回 True

因此,初始化状态错误地覆盖了更新后的显式配置。该问题本质上是配置优先级错误,并非 Ascend 910B2 与 910B4 的设备类型判断差异。

修改方案

调整 is_jit_compile_false 的判断优先级:

  1. 如果存在有效的显式配置 jitCompile,直接以该配置为准:
    • disable 返回 True;
    • enable 返回 False。
  2. 仅当 jitCompile 未设置或不是有效值时,才回退读取 jitCompileInit。

修改主要是添加jitCompile=enable的判断逻辑:

    if (option_value.value() == "enable") {
        Py_RETURN_FALSE;
    }
}

不修改或清除 jitCompileInit,因为它仍用于表示初始化阶段的状态;只修正查询时的优先级关系。

欢迎加入社区,感谢您对社区的贡献 🎉!

likedislike
JesseJesseCollaborators
Sep 29 Added label: bug
TorchNPU-BotTorchNPU-BotCollaborators
Sep 29 Added label: triage-reviewmodule: core
TorchNPU-Bot
TorchNPU-BotCollaborators
Sep 29 Comments:

问题为 is_jit_compile_false 接口配置优先级逻辑错误,属核心运行时配置管理问题
添加分类标签:module: core。
当前分类由社区bot提供,如分类有误请在评论中回复。

likedislike
JesseJesseCollaborators
Sep 29 Change title to "[Bug]:is_jit_compile_flase返回值受", originally titled "[Bug]: ".
JesseJesseCollaborators
Sep 29 Change title to "[Bug]:CompileInit为enable时is_jit_compile_flase 优先根据jitCompileInit判定", originally titled "[Bug]:is_jit_compile_flase返回值受".
TorchNPU-BotTorchNPU-BotCollaborators
Sep 29 Added label: bot-triaged; Removed label: triage-review
TorchNPU-Bot
TorchNPU-BotCollaborators
Sep 29 Comments:

检测到当前 issue 已关联 PR,自动添加标签:bot-triaged

likedislike
JesseJesseCollaborators
Sep 29 Associated pull request
12 event messages are collapsed here。 See more
JesseJesseCollaborators
Sep 30 Modify description of issue
chenrayray
chenrayrayCollaborators
Oct 8 Comments:

因为本单相关实施 PR 已全部结束(13 个已合入、0 个已关闭),按照本轮 issue 整理规则,先关闭此单。

核对的 PR:

如仍有问题或需要继续推进,请重新打开,并补充当前 PyTorch / TorchNPU / CANN 版本、硬件环境、复现步骤及相关日志;需求类请补充尚未完成的具体内容。

likedislike
chenrayraychenrayrayCollaborators
Oct 8 Close issue
chenrayraychenrayrayCollaborators
Oct 8 changed custom state from TODO to DONE
ascend-robotascend-robotCollaborators
Oct 8 Added label: resolved