Merged
feat(frontend): Sync compute determinism from torch_npu #5622
songyangyang18Add on Aug 24
feat(frontend): Sync compute determinism from torch_npu #5622
Merged
songyangyang18Add on Aug 24
songyangyang18
songyangyang18Collaborators
Aug 24

PyPTO 编码侧的计算确定性需要与 torch_npu 进程级设置保持一致。

前端同步:在 JIT 编译入口读取 torch_npu.npu._get_deterministic_level(),写入已有 global config 项 compute_determinism_level(取值 0/1/2),后端通过 ConfigManagerNg::GetGlobalConfig 读取。

level 含义与 torch_npu 一致:0 关闭,1 仅确定性,2 强一致性。约定进程内 level 固定,不在运行中切换。

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for songyangyang18's contribution.)
songyangyang18songyangyang18Collaborators
Aug 24 Created pull request, commit 94e760c0
atomgit-bot
atomgit-bot
Aug 24 Comments:

变更摘要

本 PR 将计算确定性(compute determinism)的设置来源改为跟随 torch_npu,不再新增独立的 determinism_options / JSON 配置项。核心思路是:JIT 编译入口在设置配置时读取 torch_npu.npu._get_deterministic_level(),将 level >= 1 视为确定性开启,并通过新增的 config::SetComputeDeterminism 同步到 C++ 进程级开关;同时将该开关纳入编译 cache hash,确定性 level 变化会触发重编。用户需在首次 @jit 编译前调用 torch_npu.npu.set_deterministic_level(1),C++ UT 则可直接调用 config::SetComputeDeterminism(bool)。

主要改动

  • C++ 进程级确定性开关: 在 framework/include/tilefwk/config.h 声明、config_manager.cpp 实现 SetComputeDeterminism(bool) 与 IsComputeDeterminismEnabled(),并在 ConfigStorage 中新增 computeDeterminism 字段(默认 false),Reset() 时一并复位;该开关为进程级状态,不属于 tile_fwk_config 配置项。
  • Python 侧 torch_npu 状态读取: 在 python/pypto/_utils.py 新增 is_torch_npu_compute_determinism_enabled(),通过 torch_npu.npu._get_deterministic_level() 返回值是否 >= 1 判断确定性是否开启(torch_npu 不可用时返回 False)。
  • JIT 编译入口同步: entry.py 的 JitCallableWrapper 在 _set_config_option 中调用 pypto_impl.SetComputeDeterminism(...) 将确定性开关同步到 C++ 后端,并将其纳入编译 cache hash 计算,确定性 level 变化时缓存失效触发重编。
  • Python 绑定: 在 python/src/bindings/controller.cpp 中为 config::SetComputeDeterminism 与 config::IsComputeDeterminismEnabled 增加 pybind 绑定,供 Python 侧调用。
  • 新增单元测试: 新增 python/tests/ut/interface/test_compute_determinism.py,验证 torch_npu 确定性 level 从 0 切换到 1 再切回 0 时,前端 is_torch_npu_compute_determinism_enabled() 与后端 pypto_impl.IsComputeDeterminismEnabled() 状态同步一致。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Aug 24 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 24 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 24 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
framework/src/interface/configs ✅ tsungl4, gaoxingwang (2/2) ✅ tsungl4 (1/1)
python/pypto/frontend ✅ tsungl4, gaoxingwang (2/2) ✅ tsungl4 (1/1)
repo-cann/pypto ✅ tsungl4, gaoxingwang (2/2) ✅ tsungl4 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

songyangyang18, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
138 messages are collapsed here。 See more
lidongsheng
lidongshengCollaborators
Aug 29 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 29 Added label: approved
gaoxingwang
gaoxingwangCollaborators
Aug 29 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Aug 29 Added label: lgtm
CANN-robotCANN-robotCollaborators
Aug 29 Merged pull request