Pull Request已成功合入, 合并人@ascend-robot
(感谢 huangyunlong 的贡献)变更摘要
此 PR 将 NPU 侧控制"填充未初始化内存"的机制从基于字符串选项(TORCH_NPU_FILL_UNINITIALIZED_MEMORY)的旧方案,重构为通过 NpuContext 单例类直接管理状态,并通过 torch_npu._C 暴露专用的 getter/setter 绑定。核心目的是用类型安全的 C++ API 替代原先通过 _npu_setOption 字典传递字符串选项的方式。
主要改动
- 新增
NpuContext类与globalNpuContext()单例:在EnvVariables.h/.cpp中移除CheckFillUninitializedMemory()函数及对应REGISTER_OPTION_BOOL_FUNCTION宏注册,改为引入NpuContext类(包含_npu_fill_uninitialized_memory布尔成员)及其全局单例访问函数globalNpuContext()。 - 新增 Python 层 getter/setter 绑定:在
Module.cpp中注册_npu_set_fill_uninitialized_memory和_npu_get_fill_uninitialized_memory两个 C 函数,分别调用NpuContext::setNpuFillUninitializedMemory()和npuFillUninitializedMemory()。 - 更新 Python 同步逻辑:
_deterministic.py中_add_deterministic_patch()的 setter 不再构造{"TORCH_NPU_FILL_UNINITIALIZED_MEMORY": ...}字典调用_npu_setOption,改为直接调用torch_npu._C._npu_set_fill_uninitialized_memory(mode)。 - 更新内部调用点:
ResizeNpu.cpp和TensorFactories.cpp中将at_npu::native::env::CheckFillUninitializedMemory()替换为at_npu::native::env::globalNpuContext().npuFillUninitializedMemory()。 - 测试参数修正:
test_torch_fill_uninitialized_memory.py中instantiate_device_type_tests的only_for参数从字符串'privateuse1'修正为元组('privateuse1',)。


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
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/pytorch | ✅ liangsongwei, li_jing_hw (2/2) | ✅ liangsongwei, li_jing_hw (2/1) |
| test | ✅ liangsongwei, li_jing_hw (2/2) | ✅ li_jing_hw, liangsongwei (2/1) |
| torch_npu/utils | ✅ liangsongwei, li_jing_hw (2/2) | ✅ li_jing_hw, liangsongwei (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
huangyunlong2022, thanks for your pull request. All authors of the commits have signed the CLA. 👍


当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.7.1 | ||
| v2.12.0 | ||
| v2.9.0 | ||
| v2.11.0 | ||
| v2.10.0 | ||
| v2.7.1-26.1.0 | ||
| v2.9.0-26.1.0 | ||
| v2.11.0-26.1.0 | ||
| v2.10.0-26.1.0 | ||
| v2.12.0-26.1.0 | ||
| ci-test |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


Linking Issue Notice
@huangyunlong2022 , the pull request must be linked to at least one issue.
If an issue has already been linked, but the needs-issue label remains, you can remove the label by commenting /check-issue .


ascend docs pipeline is running...


✅ 跳过 docs ci 检查,没有需要检查的文档文件


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | codecheck_pre-commit | ✅ | >>> |
| check_error | ✅ | >>> | |
| lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_ARM_A3_Part_01 | 🛑 | >>> |
| UT_ARM_A3_Part_02 | 🛑 | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ✅ | >>> | |
| UT_inductor_Part_01 | ✅ | >>> | |
| UT_inductor_Part_02 | ✅ | >>> | |
| UT_inductor_Part_03 | ✅ | >>> | |
| UT_inductor_Part_04 | ✅ | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Select_Part_02 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


/approve


/approve




【合入来源】
【修改方案】
使用torch_npu._C接口替换option接口
【资料变更】
【接口变更】
【功能验证】
【CheckList】