| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
skip ci failed testcase Co-authored-by: XianglongZeng<zengxianglong1@huawei.com> # message auto-generated for no-merge-commit merge: !36279 merge master into master skip ci failed testcase Created-by: probiotics_53 Commit-by: XianglongZeng Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 https://gitcode.com/Ascend/op-plugin/pull/4958合入受阻,下掉一批与此次修改无关的门禁失败用例: ## 1. _afd/test_attention_worker_schedule File "/workspace/CODE/pytorch_ut/test/_afd/test_attention_worker_schedule.py", line 4, in <module> import torchair ModuleNotFoundError: No module named 'torchair' [ERROR] ERR99999 UNKNOWN applicaiton exception ## 2. _afd/test_ffn_worker_schedule 同上:ModuleNotFoundError: No module named 'torchair' + ERR99999 UNKNOWN ## 3. custom_ops/test_npu_multi_head_attention File "/workspace/CODE/pytorch_ut/test/custom_ops/test_npu_multi_head_attention.py", line 98 self.assertRtolEqual(cpu_result, npu_result) AssertionError: result error 精度比较失败(NPU 和 CPU 计算结果差异超阈值)。 ## 4. distributed/pipelining/test_schedule(2 个 error) ERROR [0.288s]: test_grad_with_split_b_w schedule._load_actions(...) AttributeError: '_PipelineScheduleRuntime' object has no attribute '_load_actions' ERROR [0.058s]: test_grad_with_v_schedule torch.distributed.init_process_group(...) _PipelineScheduleRuntime API 缺失 _load_actions 方法,distributed 接口不兼容。 ## 5. nn/test_module_hooks File "/workspace/CODE/pytorch_ut/test/nn/test_module_hooks.py", line 1487 with self.assertRaisesRegex(RuntimeError, "Output 0 of BackwardHookFunctionBackward is " AssertionError: expected: "Output 0 of BackwardHookFunctionBackward is a view..." got: "Output 0 of BackwardHookFunction is a view..." PyTorch 报错信息中类名变更(BackwardHookFunctionBackward → BackwardHookFunction),正则匹配失败。 ## 6. test_multiprocessing_api File "/workspace/CODE/pytorch_ut/test/test_multiprocessing_api.py", line 215 self.assertTrue(torch.equal(npu_tensor.cpu(), reconstructed_npu.cpu())) AssertionError: False is not true 多进程 tensor 序列化/反序列化后数据不一致。 ## 7. test_ops _complex(3 个 error,同一根因) RuntimeError: _index_put_impl_:IndexPutKernelNpuOpApi.cpp:82 call aclnnIndexPutImpl failed, error code is 161002 AclNN_Parameter_Error(EZ1001): Tensor self not implemented for DT_COMPLEX64, should be in dtype support list [DT_FLOAT, DT_INT32, DT_INT64, ...] ACL 底层 aclnnIndexPutImpl 不支持 complex64/complex128 数据类型。 ## 总结 | # | 测试 | 根因 | 与 0d CPU tensor 修改关系 | |---|------|------|:--:| | 1 | attention_worker_schedule | 环境缺 torchair 包 | 无关 | | 2 | ffn_worker_schedule | 环境缺 torchair 包 | 无关 | | 3 | multi_head_attention | 精度差异 | 无关 | | 4 | test_schedule | distributed API _load_actions 缺失 | 无关 | | 5 | module_hooks | PyTorch 错误消息类名变更 | 无关 | | 6 | multiprocessing_api | 多进程 tensor 序列化不一致 | 无关 | | 7 | test_ops _complex | ACL 不支持 complex dtype | 无关 | https://gitcode.com/Ascend/op-plugin/pull/4958 涉及的 15 个 test_base_ops/ 测试全部 **success**。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!36279 | 4 个月前 | |
fix(inductor): 修复 TE 回归测试引用及 PyTorch 2.13~2.15 兼容 Co-authored-by: rmch<chenruimin2@huawei.com> # message auto-generated for no-merge-commit merge: !47837 merge codex/fix-te-ci-20261013 into master fix(inductor): 修复 TE 回归测试引用及 PyTorch 2.13~2.15 兼容 Created-by: rmch Commit-by: rmch Merged-by: ascend-robot Description: # 【合入来源】 关联 Issue:[#5394](https://gitcode.com/Ascend/pytorch/issues/5394) - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 修复 Inductor/TE 回归测试中的过期模块引用,以及上游 PyTorch 2.13~2.15 内部 API 变化带来的兼容问题。 # 【修改方案】 1. test_codegen_regressions 中 _can_clamp_1d_grid 已迁移至 launcher_codegen,test_provable_clamp_prover 中三个 helper 已迁移至 codegen.provable_clamp;更新测试导入到当前实现位置。 2. FlexAttention 的精度 API 在 PyTorch 2.13/2.14 中为 get_float32_precision(),在 2.15 中为 set_float32_precision(options, dtype)。按可用 API 选择兼容路径,并在前向及两条反向路径传入 dtype;保留用户显式设置的 FLOAT32_PRECISION。新增旧 getter、新 setter、显式选项三项回归测试。 3. QR fallback 布局补丁兼容 PyTorch 2.13 的五元组返回值与 2.14+ 的 ProcessKernelResult dataclass,仅替换 example output;新增两种结构的兼容测试,继续保留 NPU device gate。 # 【资料变更】 不涉及。 # 【接口变更】 不涉及客户面公共接口变更;仅适配 Inductor 内部 API。 # 【功能验证】 在 PyTorch 2.15.0.dev20261005+cpu + TorchNPU/NPU 环境中验证: - test_codegen_regressions.py:8 passed,包括两项 NPU 编译测试。 - test_provable_clamp_prover.py 内部 unittest:13 passed。 - test_te_qr_fallback_layout_out.py:新增结构兼容测试通过,原有两项 NPU 用例分别通过。 - 修改文件 py_compile 与 git diff --check 通过。 版本兼容依据:核对 PyTorch v2.13.0/v2.14.0 上游源码契约,并通过 mock getter/setter 和 tuple/dataclass 回归测试覆盖旧、新路径。未在完整 PyTorch 2.13/2.14 实机栈运行测试,需门禁版本矩阵继续确认。 本地验证加载本分支 Python 文件并复用已安装的 TorchNPU 二进制、头文件及库;因本机 Torch 2.15 的 ATen 头文件要求 C++20,测试进程临时将 npu_utils.cpp 编译选项由 C++17 调整为 C++20。这些环境调整未包含在本 PR 中。 范围限制:test_codecache 的 3600s 超时及完整 test_dvm_flex_attention 失败尚缺少原始 traceback,本 PR 不将其标记为已解决,也未完整运行 DVM suite。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常(待门禁验证) See merge request: Ascend/pytorch!47837 | 1 天前 | |
[master][bugfix]cann and pta header mixing bulid bugfix Co-authored-by: Dring<17737727613@163.com> # message auto-generated for no-merge-commit merge: !44990 merge master into master [master][bugfix]cann and pta header mixing bulid bugfix Created-by: Dring Commit-by: Dring Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/3991 - [✕ ] 需求 - [ ✓] 问题单 - [ ✓] issue/工单 - [ ✓] 重构优化 - [✕ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 问题现象: PTA 26.1.0 仓库中的 third_party/acl 头文件来自 CANN 9.1.0,而编译环境安装的是 CANN 9.0.0。当同一个编译单元同时包含两套版本的 ACL 头文件时,会出现类似以下错误:aclmdlRITask 未声明、未定义或类型不匹配 aclmdlRITask 是 CANN 9.1.0 头文件所依赖的定义,但 CANN 9.0.0 对应头文件中不存在该定义或定义不兼容。 根因分析: 1 当前头文件查找路径不统一:PTA 源码中大量使用以下写法 #include "third_party/acl/inc/acl/acl_mdl.h" 因为编译命令中包含 PTA 项目根目录,这种写法会直接命中 PTA 26.1.0 仓库内由 CANN 9.1.0 导入的头文件:torch_npu/third_party/acl/inc/acl/acl_mdl.h 但该头文件内部使用的是标准 SDK 相对路径:#include "acl/acl_base.h" 编译器无法相对 acl_mdl.h 所在目录找到 acl/acl_base.h,因此转而按照全部 -I 目录依次搜索。如果 CANN 9.0.0 的 include 路径排在 PTA 内置 ACL 路径前面,就会命中:CANN-9.0.0/include/acl/acl_base.h 同一个翻译单元最终形成: acl_mdl.h -> PTA third_party 中的 CANN 9.1.0 版本 acl_base.h -> 环境 CANN 9.0.0 版本 这是一种“首层头文件由源码路径固定版本、传递头文件由 -I 顺序选择版本”的混合查找模式。 2 问题不局限于 acl_mdl.h 同样风险存在于所有能够继续 include 其他 CANN 头文件的入口,包括: acl/... aml/... profiling/... graph/... ge/... op_proto/... 因此不能只修复出现错误的某一个头文件,也不能只替换 acl_mdl.h。必须统一整个 CANN 头文件族的查找规则。 修改目标: 修改后需要满足 源码不再包含 third_party/acl/inc/... 这种仓库物理路径。 ACL、AML、profiling 等头文件全部通过统一 include root 查找。 一个编译 target 对 CANN 头文件只选择一套版本。 CANN 9.0.0 环境构建时,首层和传递头文件必须全部命中 CANN 9.0.0。 使用 PTA 内置头文件构建时,首层和传递头文件必须全部命中 PTA 内置的同一套版本。 wheel、libtorch_npu、C++ Extension 和 Inductor/AOT 使用同一目录契约 修改方案: 1、代码中使用 PTA 内置 ACL 头文件的地方,删除 third_party/acl/inc/ 物理路径前缀,统一改成从 include root 查找 2、打包或安装时,把 third_party/acl/inc 下需要公开的目录按原相对结构复制到安装产物的公共 include 根目录 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 cann 9.0.0 + pta 26.1.0的vllm-ascend安装验证成功  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [✓ ] 代码注释完备,正确记录错误日志 - [✕ ] 代码实现进行了返回值、空指针等校验 - [✓ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [✓ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44990 | 1 个月前 | |
[test] add InplaceFunction.vjp and NestedIOFunction.backward api test case Co-authored-by: nasa___1<2397662955@qq.com> # message auto-generated for no-merge-commit merge: !45870 merge InplaceFunction_vjp-NestedIOFunction_backward-master into master [test] add InplaceFunction.vjp and NestedIOFunction.backward api test case Created-by: nasa___1 Commit-by: nasa___1 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <span style="color:red"><strong>如有社区 Issue,请关联 Issue 链接</strong></span> > <span style="color:red"><strong>请勿携带内部流程信息(需求链接、问题单、内部issue等)</strong></span> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch-ecosystem/issues/292 https://gitcode.com/Ascend/pytorch-ecosystem/issues/295 - [ ] 重构优化 - [ ] 资料更新 # 1、API功能分析 - torch.autograd.function.InplaceFunction.vjp 用于定义自定义算子在**反向模式自动微分(reverse-mode AD)** 下的 Vector-Jacobian Product,向量-雅可比积,本质上就是自定义 Function 的反向梯度计算规则。假设前向过程为 $y=f(x)$,上游传入输出梯度 $v=\frac{\partial L}{\partial y}$,那么 vjp 计算的是 $$ v^T J_f(x) = \frac{\partial L}{\partial y} \frac{\partial y}{\partial x} = \frac{\partial L}{\partial x} $$ 也就是把输出侧的梯度继续传播回输入侧。 - torch.autograd.function.NestedIOFunction.backward torch.autograd.function.NestedIOFunction.backward 是 PyTorch 内部自动微分(Autograd)机制中用于处理具有嵌套输入/输出结构的自定义算子反向传播的方法。 # 2、上游用例检查情况 | API | PyTorch 2.7.1 上游测试情况 | 是否有直接专项覆盖 | torch-npu 是否建议补充 | | --------------------------------------------------- | --------------------------------------------- | ---------------------------------------- | ---------------- | | torch.autograd.function.InplaceFunction.vjp | Function.vjp 有多处官方测试;InplaceFunction 也有测试 | **没有找到直接针对 InplaceFunction.vjp 的专项测试** | **建议补充** | | torch.autograd.function.NestedIOFunction.backward | NestedIOFunction 类仍保留在源码中 | **没有在 2.7.1 test_autograd.py 中找到直接覆盖** | **建议补充,但优先级较低** | 由于上游测试用例缺失,同时这两个API都需要torch-npu平台算子支撑,因此需要进行测试用例补充。 # 3. 资料检查 1. torch.autograd.function.InplaceFunction.vjp 在上游有独立条目,但是当前资料缺失。 2. torch.autograd.function.NestedIOFunction.backward 在上游有独立条目,当期资料缺失。 因此这两个API都需要进行资料补充。 # 4. API功能测试 测试覆盖场景: | 测试项 | 覆盖内容 | 预期结果 | | --- | --- | --- | | InplaceFunction.vjp NPU 前向计算 | 使用 NPU Tensor 调用自定义 InplaceFunction,在 forward() 中执行原地乘法并通过 mark_dirty() 标记修改 | 前向计算正常完成,输出 Tensor 位于 NPU,数值及 dtype 正确 | | InplaceFunction.vjp 反向 VJP 计算 | 自定义 vjp() 而不实现 backward(),传入非全 1 的 grad_output 执行 output.backward(grad_output),验证 autograd 实际进入 vjp() | vjp() 被正常调用,按照 grad_output × scale 得到正确梯度,梯度 Tensor 位于 NPU | | NestedIOFunction.backward 嵌套梯度恢复 | 构造包含 Tensor、list、tuple 和 None 的 _nested_output 结构,将扁平 NPU 梯度传入 backward(),检查 backward_extended() 接收到的梯度结构 | 扁平梯度能够按照原输出结构正确恢复,list、tuple 和 None 的位置保持正确,Tensor 位于 NPU | | NestedIOFunction.backward 梯度计算与展开 | 在 backward_extended() 中返回包含嵌套 Tensor 和 None 的梯度结果,验证 backward() 对结果进行展开 | 返回结果被正确展开为扁平 tuple,Tensor 数值正确,None 正确保留,Tensor 的 dtype 和 NPU device 均保持正确 | 测试方法 source /usr/local/Ascend/ascend-toolkit/set_env.sh TORCH_DEVICE_BACKEND_AUTOLOAD=1 python test_inplacefunction_vjp_nestediofunction_backward.py -v 测试结果 A2/A3芯片: v2.7.1  v.2.11.0  v2.12.0  A5芯片 v2.7.1  v2.11.0  v2.12.0  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!45870 | 7 天前 | |
| 2 年前 | ||
fix(npu): preserve non-device fields in torch.autograd.profiler_util.Kernel Co-authored-by: hhj-ai<greatesthhj@zju.edu.cn> # message auto-generated for no-merge-commit merge: !42019 merge api-kernel-name-master into master fix(npu): preserve non-device fields in torch.autograd.profiler_util.Kernel Created-by: hhj-ai Commit-by: hhj-ai Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue:https://gitcode.com/Ascend/pytorch/issues/3035 # 【修改方案】 1. torch_npu.contrib.transfer_to_npu 原先在 _patch_nametuple 中处理 namedtuple 的全部位置参数,导致 torch.autograd.profiler_util.Kernel 的非设备字段也被执行 "cuda" 到 "npu" 的替换。例如位置参数 name="cuda_kernel" 会错误变为 "npu_kernel",而关键字参数 name= 不会被改写。 2. 通过 namedtuple 的 _fields 将位置参数映射到字段,只对 device、device_type、map_location、device_id 等设备字段调用现有替换逻辑;torch.autograd.profiler_util.Kernel.name 和 duration 保持原值,关键字参数逻辑不变。 3. 扩展既有 test/contrib/test_transfer_to_npu.py 中 TestTransferToNpu.test_torch_autograd_profiler_util_Kernel(master 当前第 340–373 行),不新增独立测试文件,也不使用代码检查抑制。 4. 覆盖全部三个字段及调用边界: - name:包含 "cuda" 的字符串和空字符串,均保持原值。 - device:普通字符串、空字符串、torch.device、真实调用路径使用的 device_index=0、None、list、tuple、空 dict 和含 "cuda" 的 dict。 - duration:整数零和非零浮点数,均保持原值。 - 调用形式:位置参数、关键字参数、缺少参数、多余位置参数和未知关键字参数。 - Kernel(name, device, duration) 三个参数均为必填参数,没有可选参数,因此“可选参数传入与不传入”不适用。 5. PyTorch 官方在 torch/autograd/profiler_util.py 中定义 Kernel = namedtuple("Kernel", ["name", "device", "duration"]),并在 FunctionEvent.append_kernel 等路径以位置参数构造 Kernel(name, device, duration);官方 test/ 没有 torch.autograd.profiler_util.Kernel.name 的直接测试。已实际检查 torch-npu profiler/autograd 的 test_upstream patch,也无本问题覆盖。本问题由 torch-npu 的 monkey patch 引入,因此回归测试放在既有 contrib 用例中,不新增上游 patch。 # 【资料变更】 本代码 PR 不修改资料。相关支持状态由独立 master 资料 PR !42887 按当前上游目录更新 2.7.1、2.11.0、2.12.0、2.13.0 四个现存页面;上游已删除 2.9.0、2.10.0 资料目录,不恢复已删除页面。v2.9.0、v2.10.0 不再合入本次功能修复。 # 【接口变更】 不涉及公开接口签名变更,仅修复 torch_npu.contrib.transfer_to_npu 对既有 torch.autograd.profiler_util.Kernel 位置参数的转换行为。 # 【功能验证】 修复前在 PyTorch 2.9.0 + torch-npu 2.9.0rc1 环境复现: text Kernel("cuda_kernel", "cuda:0", 100) name: npu_kernel device: npu:0 duration: 100 四个活动分支均对提交中的原样 _patch_nametuple 实现执行隔离回归;本地源码 worktree 未编译 torch_npu._C/libtorch_npu.so,因此没有将该结果表述为完整源码树测试。 bash KERNEL_TRANSFER_SOURCE=<当前分支>/torch_npu/contrib/transfer_to_npu.py \ TORCH_DEVICE_BACKEND_AUTOLOAD=0 \ python3 /workspace/718/verification/test_kernel_patch.py -v text test_keyword_fields ... ok test_non_device_container_and_integer_fields ... ok test_positional_device_dict ... ok test_positional_device_non_scalar_types ... ok test_positional_fields ... ok Ran 5 tests OK | 目标分支 | 验证提交 | 隔离回归 | py_compile | lintrunner | git diff --check | |---|---|---|---|---|---| | master(当前对应 2.13.0) | 0165431359a27750f61cfa44f897fb13937541a5 | 5/5,OK | 通过 | 通过 | 通过 | | v2.7.1 | 642d0dba089cc30f055a02cfdab50a41d2149842 | 5/5,OK | 通过 | 通过 | 通过 | | v2.11.0 | 6c2b85d0894fe7925d93f7923a9046cd87177193 | 5/5,OK | 通过 | 通过 | 通过 | | v2.12.0 | e06754b5e901ee08eec533715636b36996f2c58b | 5/5,OK | 通过 | 通过 | 通过 | 静态检查使用实际命令: bash python3 -m py_compile \ torch_npu/contrib/transfer_to_npu.py \ test/contrib/test_transfer_to_npu.py uvx lintrunner \ torch_npu/contrib/transfer_to_npu.py \ test/contrib/test_transfer_to_npu.py git diff --check upstream/<目标分支>...HEAD 构建态标准目标命令为: bash python -m unittest \ test.contrib.test_transfer_to_npu.TestTransferToNpu.test_torch_autograd_profiler_util_Kernel \ -v 四个 current head 的真实 NPU 目标文件与完整流水线均已通过: | 分支 | contrib/test_transfer_to_npu | 完整流水线 | |---|---|---| | master | SUCCESS,32.1s | ci-pipeline-passed | | v2.7.1 | SUCCESS,29.9s | ci-pipeline-passed | | v2.11.0 | SUCCESS,29.6s | ci-pipeline-passed | | v2.12.0 | SUCCESS,32.5s | ci-pipeline-passed | master 首轮 npu/test_compatibility 因 upstream compatibility 基线漂移失败;UT_ARM_A2_Part_02 分区 retry 终态为 SUCCESS,但 retry 未再次执行该检查,因此不将 compatibility 本身写成“重跑通过”。v2.12.0 首轮 UT_ARM_A2_Part_03(Ascend910B3)的唯一失败项为 npu/test_ipc_event(3600s timeout);唯一一次 UT_ARM_A2_Part_03 retry 在 Ascend910B1 上重新实际执行该用例并于 98.7s 成功,分区 29/29、终态 SUCCESS,完整流水线通过。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 # 【2026-09-12 A5 验证更新】 - 已基于最新目标分支解决冲突,并 squash 为单提交 b14753b11。 - A5(Ascend950PR、CANN 9.1.0)通过 torch_npu_server_runner.py 执行 TestKernelA5.test_kernel_parameters_and_a5_smoke:master 为 1/1 通过。 - 覆盖 torch.autograd.profiler_util.Kernel 的位置参数、关键字参数、容器 device 值、异常参数和实际 NPU 张量 smoke。 - 完整报告:/workspace/a5-verify/tests/docs/测试用例验证结果报告_1789170609.md。 See merge request: Ascend/pytorch!42019 | 15 天前 | |
[master][Fix] Fix static check errors detected by clang-format Co-authored-by: thickhair<zp2165064878@163.com> # message auto-generated for no-merge-commit merge: !44399 merge clang-format-0812 into master [master][Fix] Fix static check errors detected by clang-format Created-by: thickhair Commit-by: thickhair Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/3340 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 修复clang-format错误 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44399 | 2 个月前 | |
[master][bugfix]cann and pta header mixing bulid bugfix Co-authored-by: Dring<17737727613@163.com> # message auto-generated for no-merge-commit merge: !44990 merge master into master [master][bugfix]cann and pta header mixing bulid bugfix Created-by: Dring Commit-by: Dring Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/3991 - [✕ ] 需求 - [ ✓] 问题单 - [ ✓] issue/工单 - [ ✓] 重构优化 - [✕ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 问题现象: PTA 26.1.0 仓库中的 third_party/acl 头文件来自 CANN 9.1.0,而编译环境安装的是 CANN 9.0.0。当同一个编译单元同时包含两套版本的 ACL 头文件时,会出现类似以下错误:aclmdlRITask 未声明、未定义或类型不匹配 aclmdlRITask 是 CANN 9.1.0 头文件所依赖的定义,但 CANN 9.0.0 对应头文件中不存在该定义或定义不兼容。 根因分析: 1 当前头文件查找路径不统一:PTA 源码中大量使用以下写法 #include "third_party/acl/inc/acl/acl_mdl.h" 因为编译命令中包含 PTA 项目根目录,这种写法会直接命中 PTA 26.1.0 仓库内由 CANN 9.1.0 导入的头文件:torch_npu/third_party/acl/inc/acl/acl_mdl.h 但该头文件内部使用的是标准 SDK 相对路径:#include "acl/acl_base.h" 编译器无法相对 acl_mdl.h 所在目录找到 acl/acl_base.h,因此转而按照全部 -I 目录依次搜索。如果 CANN 9.0.0 的 include 路径排在 PTA 内置 ACL 路径前面,就会命中:CANN-9.0.0/include/acl/acl_base.h 同一个翻译单元最终形成: acl_mdl.h -> PTA third_party 中的 CANN 9.1.0 版本 acl_base.h -> 环境 CANN 9.0.0 版本 这是一种“首层头文件由源码路径固定版本、传递头文件由 -I 顺序选择版本”的混合查找模式。 2 问题不局限于 acl_mdl.h 同样风险存在于所有能够继续 include 其他 CANN 头文件的入口,包括: acl/... aml/... profiling/... graph/... ge/... op_proto/... 因此不能只修复出现错误的某一个头文件,也不能只替换 acl_mdl.h。必须统一整个 CANN 头文件族的查找规则。 修改目标: 修改后需要满足 源码不再包含 third_party/acl/inc/... 这种仓库物理路径。 ACL、AML、profiling 等头文件全部通过统一 include root 查找。 一个编译 target 对 CANN 头文件只选择一套版本。 CANN 9.0.0 环境构建时,首层和传递头文件必须全部命中 CANN 9.0.0。 使用 PTA 内置头文件构建时,首层和传递头文件必须全部命中 PTA 内置的同一套版本。 wheel、libtorch_npu、C++ Extension 和 Inductor/AOT 使用同一目录契约 修改方案: 1、代码中使用 PTA 内置 ACL 头文件的地方,删除 third_party/acl/inc/ 物理路径前缀,统一改成从 include root 查找 2、打包或安装时,把 third_party/acl/inc 下需要公开的目录按原相对结构复制到安装产物的公共 include 根目录 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 cann 9.0.0 + pta 26.1.0的vllm-ascend安装验证成功  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [✓ ] 代码注释完备,正确记录错误日志 - [✕ ] 代码实现进行了返回值、空指针等校验 - [✓ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [✓ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44990 | 1 个月前 | |
fix: downgrade internal-format targets to base format on the aclnn path when ALLOW_INTERNAL_FORMAT=disable [master] Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com> # message auto-generated for no-merge-commit merge: !45500 merge fix/aclnn-format-cast-forbid-internal-format-master into master fix: downgrade internal-format targets to base format on the aclnn path when ALLOW_INTERNAL_FORMAT=disable [master] Created-by: wuyouqi1 Commit-by: wuyouqi1 Merged-by: ascend-robot Description: # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/4389 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 allow_internal_format=False 时,npu_format_cast 走 aclnn 路径(7302fba05 引入)未检查该开关:目标为内部格式(FRACTAL_NZ/NC1HWC0/FRACTAL_Z)时直接创建私有格式 tensor,绕过了 aclop 分配层守卫(TensorFactories.cpp unsafe_empty_with_format),与 aclop 路径行为不一致,导致 test_allow_internal_format_false_with_npu_format_cast 类用例失败。 修复:在 MaybeUseAclnnNpuFormatCast 的 IsAclnnFormatCastSupported 分支入口增加降级守卫——allow_internal_format=False 且目标为非 base 格式时,将目标降级为 GetBaseFormat 并 TORCH_WARN_ONCE,与 aclop 路径行为对齐。 关键设计:cast_into_existing 豁免——目标格式等于 src tensor 自身格式时不降级(tensor 重载 npu_format_cast_(self, Tensor src) 中该值恒为 True,属预期:该重载语义为将 src 数据写入已存在 tensor,目标格式是既成事实;若降级会破坏 nz_dst.copy_(nd_src) 后 dst 保持 NZ 布局的既有行为)。int 重载经 same-format 早退后该值恒为 False,守卫正常生效。950 的 IsAclnnOnly 分支不经此守卫,不受影响。 注:此前 !39022 曾在 MaybeUseAclnnNpuFormatCast 入口无条件降级(无 cast_into_existing 豁免),因破坏既有行为被 !39259 回退。本 MR 为带豁免的修正版,同步自 v2.7.1 MR !45183。 # 【资料变更】 op-plugin 仓 MR !5771(allow_internal_format 影响范围说明) # 【接口变更】 不涉及 # 【功能验证】 UT:test/custom_ops/test_npu_format_cast.py TestNpuFormatCastForbidInternalFormat(降级 4 组格式断言 + base 目标不受影响 + 开关开启对照 + copy_ 保持已存在 NZ tensor 格式) See merge request: Ascend/pytorch!45500 | 1 个月前 | |
[feature] support get_buffer for symm mem Co-authored-by: ccyyccyyccyycc<changqiaowei@huawei.com> # message auto-generated for no-merge-commit merge: !46842 merge feat/symm-mem-getbuffer into master [feature] support get_buffer for symm mem Created-by: ccyyccyyccyycc Commit-by: ccyyccyyccyycc Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 https://gitcode.com/Ascend/pytorch/issues/5031 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 - NPUSHMEMSymmetricMemory 构造函数:填 buffers_(每个 group rank 的 Aclshmem_ptr 结果),Aclshmem_ptr 返回 nullptr 时 TORCH_CHECK。无需新增。 - 社区SymmetricMemory通过get_buffer,调用NPUSHMEMSymmetricMemory后端get_buffer_ptrs()、get_buffer_size()等接口,直接返回 buffers_、buffer_size_等。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 | 测试用例 | 验证点 | 类型 | | --- | --- | --- | | test_get_buffer | buffer_size 正确;本地 data_ptr()==本地 tensor;对端 data_ptr()==buffer_ptrs[peer];本地与对端数据值正确;storage_offset=4 子切片地址与数据正确;越界抛 "exceeds the allocated size" | 集成 | | test_get_buffer_alias | 本地 get_buffer(rank)[3:4].fill_ 对本地 tensor 可见;rank0 经 get_buffer(peer)[7:8].fill_ 跨卡写入,synchronize+barrier 后 rank1 本地 tensor[7]==写入值 | 集成 | | test_get_buffer_allocation_lifetime | del tensor+barrier 后仍可 get_buffer,地址与数据保持正确,验证 handle 引用计数保活 allocation | 集成 | 测试执行test_shmem.py   # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!46842 | 6 天前 | |
fix(dynamo): correct compiler initialization test expectations Co-authored-by: zhangrunze<zhangrunze13@huawei.com> # message auto-generated for no-merge-commit merge: !46892 merge fix/compiler-test-expectations into master fix(dynamo): correct compiler initialization test expectations Created-by: zhangrunze13 Commit-by: zhangrunze Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 https://gitcode.com/Ascend/pytorch/issues/5056 # 【修改方案】 修复 test/dynamo/test_compile_trigger.py 中两项与当前实现不一致的 UT 预期: 1. 修正 Inductor 补丁检查的版本分支。 PyTorch <2.15 时,检查 GraphLowering.codegen_with_cpp_wrapper 和 CacheBase.get_system 来自 NPU 兼容层;≥2.15 时,检查初始化前后方法引用保持不变,确认保留上游实现。 2. 修正 has_triton 的 CPU 检测预期。 测试辅助函数增加 include_cpu 参数,覆盖默认排除 CPU、显式启用 CPU、缺少 CPU backend、缺少 Triton 包及 CPU/NPU 同时可用等场景。 本次仅调整测试,不修改生产实现。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!46892 | 20 天前 | |
| 2 年前 | ||
【API一致性任务】test: add torch._C._functorch.is_batchedtensor validation cases on NPU Co-authored-by: cuiyunhao-2026<1830099122@qq.com> # message auto-generated for no-merge-commit merge: !43533 merge test-is-batchedtensor-npu-master into master 【API一致性任务】test: add torch._C._functorch.is_batchedtensor validation cases on NPU Created-by: cuiyunhao-2026 Commit-by: cuiyunhao-2026 Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font> > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> 关联 Issue:https://gitcode.com/Ascend/pytorch/issues/2751 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 适配 API: torch._C._functorch.is_batchedtensor(torch-npu 尚未提供独立验证用例,本 PR 自写用例补齐,按规范 1.3)。 **0. 按导师最新要求的保留判定** 导师公告:资料 PR 已全部打回,且不再接收 NPU 适配 patch 与非硬件相关 API 的新增用例。本 PR 经复核属于**硬件相关**用例,予以保留: - 该 API 用于判断张量是否处于 torch.vmap 批处理分发作用域内,本用例通过 device_type = torch.accelerator.current_accelerator().type 将**真实张量运行在 NPU 设备**上,验证 vmap/batched tensor 在昇腾硬件上的分发行为(普通张量 / vmap 内部 / 嵌套 vmap / 手动 _add_batch_dim / 多 dtype 等); - 用例直接操作 NPU 上的张量与 functorch 分发层,属于规范 1.2②「涉及硬件接口,在 test 目录新增用例」的保留范围,**不属于被关闭的非硬件相关用例**; - 本 PR 为 test/ 自写用例,非 test_upstream NPU 适配 patch,符合"不再接收 NPU 适配 patch"的要求。 **1. 上游社区用例情况分析** 在 PyTorch 上游仓库(github.com/pytorch/pytorch)全量检索 is_batchedtensor 在 test/ 下的引用,仅在 test/functorch/test_eager_transforms.py:4982 一处出现,且位于 helper construct_sum_pyop() 内部,作为 vmap 自定义规则的**控制流分支**,从未被直接 assert 验证。 结论:该 API 在 PyTorch 上游**无独立社区用例**,属规范 **1.3(社区无直接用例,NPU 侧自写用例)** 场景,按规范在 test/ 目录新增自写用例文件,不做 test_upstream patch、不做 API 补齐。 **2. NPU 适配方案** torch._C._functorch.is_batchedtensor 由 PyTorch functorch 分发层提供,torch-npu 基于原生 PyTorch 自动具备,在 NPU 上行为与原生一致,无需修改 API 实现。本 PR 仅补充用例,覆盖其完整输入空间: - 普通张量返回 False; - torch.vmap 内部张量返回 True(含嵌套 vmap); - 手动 _add_batch_dim 包裹后为 True,get_unwrapped 解包后恢复 False; - vmap 作用域外返回 False; - 多种 dtype(float32 / float16 / int32 / bool)结果仅取决于批处理维,与 dtype 无关; - 非张量输入(int)抛出 TypeError。 张量通过 device_type = torch.accelerator.current_accelerator().type 落到 NPU 设备,符合“张量必须运行在 NPU 上”规范(昇腾环境导入 torch 自动导入 torch_npu,current_accelerator() 返回 npu)。 **3. 提交方式(test 目录自写用例,规范 1.3)** 按规范 1.3,在 test/ 目录新增 test/functorch/test_functorch_api.py(同类 torch._C._functorch API 可归集于此文件,便于扩展)。文件遵循 torch-npu 测试规范:Huawei BSD-3 版权头、模块 docstring 说明可扩展与同类归集、从 torch.testing._internal.common_utils 导入 run_tests/TestCase(不直接 import unittest)、导入顺序 torch → torch.testing → functorch、类前后空 2 行、方法间空 1 行、self.assert* 断言、无 print / 无 try-except / 无裸 assert。 按规范 1.3,提交到 2.7.1 / 2.11.0 / 2.12.0 以及 master 四个分支(与 test 目录条款一致)。各分支基线一致、新增文件内容相同,单文件通用。2.9.0 / 2.10.0 已转入维护阶段,不作补齐要求。 **4. API 补齐** 不需要。torch._C._functorch.is_batchedtensor 由 PyTorch functorch 分发层提供,torch-npu 基于原生 PyTorch 自动具备,无需额外实现,故不提交 API 代码。 **5. 多版本分支合入** | 目标分支 | PR | 说明 | |---------|--------|------| | v2.7.1 | https://gitcode.com/Ascend/pytorch/pull/43535 | test 自写用例 | | v2.11.0 | https://gitcode.com/Ascend/pytorch/pull/43534 | test 自写用例 | | v2.12.0 | https://gitcode.com/Ascend/pytorch/pull/43536 | test 自写用例 | | master | https://gitcode.com/Ascend/pytorch/pull/43533 | test 自写用例 | - 按规范 1.3(test 目录用例),**master 需要提交**(与 test_upstream patch 场景不同,后者 master 不需要)。 - 2.9.0 / 2.10.0 已转入维护阶段,不作补齐要求。 # 【资料变更】 不涉及。 依据:torch._C._functorch.is_batchedtensor 为 PyTorch 私有(内部 C++)接口,按规范 2.3「PyTorch 私有接口不需要补充资料」。经核查 docs/zh/native_apis/ 未收录该 API,故不在 PR 中补资料。 # 【接口变更】 不涉及。 依据:torch._C._functorch.is_batchedtensor 由 PyTorch functorch 分发层提供,torch-npu 基于原生 PyTorch 自动具备,无跨代码仓或客户面可见接口变更。 # 【功能验证】 - 离线校验:用例已在真实 Ascend NPU(910B4)环境执行,全部通过; - 运行命令:python test/functorch/test_functorch_api.py; - 运行结果:  See merge request: Ascend/pytorch!43533 | 1 个月前 | |
[test][master] align symbolic_shapes API for issue #1615 Co-authored-by: bingli-2026<davis_ye@foxmail.com> # message auto-generated for no-merge-commit merge: !35696 merge issue1638-no9-master into master [test][master] align symbolic_shapes API for issue #1615 Created-by: bingli-2026 Commit-by: bingli-2026 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [x] issue/工单 关联 issue:[#1615](https://gitcode.com/Ascend/pytorch/issues/1615) # 【修改方案】 本 PR 在 test/fx/test_symbolic_shapes_api.py 补充 4 个目标 API 的定向测试,并在 torch_npu/utils/_dynamo.py 补齐 symbolic_shapes.hint_int 的兼容导出。 兼容 patch 仅在 hint_int 缺失或其签名不含 fallback 时安装;已有完整上游实现时不替换。 修改文件: - test/fx/test_symbolic_shapes_api.py - torch_npu/utils/_dynamo.py # 【API 功能介绍】 1. has_free_unbacked_symbols:判断表达式是否包含未绑定 symbolic shape 符号。 2. hint_int:返回 int 或 SymInt 的整数 hint;无 hint 时使用 fallback。 3. InnerTensorKey:描述内部张量属性访问路径。 4. InnerTensorKey.get:读取路径所指向的对象属性。 # 【上游对齐与完备性】 hint_int 与 PyTorch 契约逐项对齐:精确 int 原样返回;bool 等其他类型断言失败;有具体 hint 的 SymInt 返回 hint;无 hint 的 SymInt 在 fallback=9 时精确返回 9;无 fallback 时抛出数据依赖错误。兼容实现直接调用 SymInt.node.require_hint(fallback),避免自行模拟符号求值语义。 测试覆盖上述 hint_int 分支,并覆盖 has_free_unbacked_symbols 的普通整数和 unbacked SymInt、InnerTensorKey 的构造/相等/哈希、InnerTensorKey.get 的属性读取。 # 【分支说明】 v2.7.1 / v2.9.0 / v2.10.0 / v2.11.0 / v2.12.0 / master 均保持相同的 API 契约和测试行为;各 PR 已同步到各自最新 upstream 目标分支并 squash 为单提交。 # 【测试命令】 bash source env.sh python -u test/fx/test_symbolic_shapes_api.py -v # 【测试结果】 已完成 python -m py_compile、git diff --check、兼容层契约桩测试及 GitCode 推送 Hook 检查。真实 Ascend 设备回归和 PR CI 结果以本次提交触发的流水线为准。 # 【CheckList】 - [x] 仅修改目标测试和必要的兼容层 - [x] 未修改 test/allowlist_for_publicAPI.json - [x] 已同步 upstream 且单提交 - [x] 兼容实现与上游 require_hint(fallback) 语义对齐 See merge request: Ascend/pytorch!35696 | 16 天前 | |
feat: integrate fxrt as in-tree subpackage of torch_npu build and wheel Co-authored-by: chenhaozhe<chenhaozhe1@huawei.com> # message auto-generated for no-merge-commit merge: !45813 merge fxrt-src into master feat: integrate fxrt as in-tree subpackage of torch_npu build and wheel Created-by: c_34 Commit-by: chenhaozhe Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/4733 - [ ] 重构优化 - [ ] 资料更新 ## 目的 将 fxrt(FX 图运行时)以源码方式合入 torch_npu,随 torch_npu 一起编译打包,用户安装 torch_npu 后即可直接使用,无需单独安装 fxrt。 ### 概述 将 FX 图运行时 fxrt 放入 fxrt/ 目录,随 torch_npu 一起构建,以 torch_npu.fxrt 子包的形式发布,不再单独发包。 diff 主体是 fxrt/ 下的源码。对 torch_npu 已有代码的改动为 19 个文件、约 270 行,其中约 200 行是新增测试。 ### 对 torch_npu 的影响 - import torch_npu 不加载 fxrt,行为不变;fxrt 在 import torch_npu.fxrt 时才加载。 - 导入 fxrt 不改动 inductor,需显式调用 torch_npu.fxrt.register_fx_wrapper() 才会接管。 - C++ 接口唯一改动:导出 npu_logging::Logger。 - --disable_fxrt 可构建不含 fxrt 的 wheel。 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) **构建接入**(沿用 torchair 方式) - setup.py:检测到 fxrt/fxrt 时传入 BUILD_FXRT、FXRT_INSTALL_DST、FXRT_TARGET_PYTHON;package_data 增加 fxrt 的 .so。fxrt 暂不提供 C++ 接口,wheel 中不含 fxrt 头文件。 - CMakeLists.txt:在 torch_npu target 之后 add_subdirectory(fxrt/fxrt)。 - ci/build.sh:新增 --disable_fxrt。 fxrt 的依赖(ACL/HCCL stub、nlohmann、DVM)均复用仓库内已有内容,构建时不下载,也不依赖 CANN 安装。fxrt 库的 RPATH 包含 torch_npu/lib,auditwheel 可在 wheel 内解析 libtorch_npu.so 及其依赖。 **日志** - torch_npu/_logging/_internal.py:注册 fxrt 日志别名,TORCH_NPU_LOGS=+fxrt 控制 fxrt 的 C++ 和 Python 日志。 - torch_npu/csrc/logging/Logger.h:Logger 加 TORCH_NPU_API。torch_npu 以 -fvisibility=hidden 编译,fxrt 调用 Logger 成员函数需要导出符号,实现不变。 - TORCH_NPU_LOGS.md:模块表增加 fxrt。 **构建依赖** - nanobind 仅构建时需要(静态链接,运行时不依赖),加入 requirements*-build.txt、.ci/docker/requirements-builder.txt(==2.13.0)、ci/docker 的 Dockerfile 和源码构建指南。 **测试与门禁** - 新增 test/fxrt(7 个用例,fxrt 未构建时跳过):fxrt 后端编译运行;import torch_npu / import torch_npu.fxrt 无副作用;register_fx_wrapper() 注册行为。 - test/npu/test_public_bindings.py:模块名检查跳过 torch_npu.fxrt。fxrt 以顶层包名 fxrt 执行,对象的 __module__ 为 fxrt.*;导入检查不跳过。 - .lintrunner.toml:fxrt C++ 源码纳入 clang-format 检查。 - tools/linter/dictionary.txt:增加 hax`(fxrt 哈希实现中的变量名)。 详见RFC issue # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 当前版本不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 新增demo特性,不涉及历史接口版本变更,demo特性已进行隔离,默认不开启。 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 当前作为demo能力,默认不主动使能的情况下,要求不修改任何pytorch_npu已有逻辑和行为。 主要验证: 1. 构建打包安装行为不影响torch-npu的包。 2. 不主动使能情况下,原有torch-npu行为不受fxrt任何影响。 关于新增依赖的缺陷扫描,主要新增一个nanobind作为构建过程中的python依赖,扫描结果如下,引入依赖版本无安全缺陷报告:  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!45813 | 21 天前 | |
test: add unit tests for torch.jit.ScriptModule.cuda and code_with_constants Co-authored-by: sxj731533731<13791252840@163.com> # message auto-generated for no-merge-commit merge: !41627 merge fix_master into master test: add unit tests for torch.jit.ScriptModule.cuda and code_with_constants Created-by: sxj731533731 Commit-by: sxj731533731 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/2857**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 本次修改为在 test/ 目录下新增针对 torch.jit.ScriptModule 类中 cuda 和 code_with_constants 两个 API 的单元测试用例,具体实现如下: 测试用例文件新增:在 test/jit/ 目录下修改测试文件(如test_scriptmodule.py),继承 PyTorch 标准测试基类 TestCase。 cuda() API 测试: 注:当前在 NPU 环境下无法使用 cuda() 接口(因该接口强依赖 NVIDIA CUDA 运行时),该用例将被跳过; code_with_constants API 测试: 构造包含常量(如 torch.tensor 常量、int 常量等)的 ScriptModule,并通过 torch.jit.script 转换。访问 code_with_constants 属性,断言返回值为包含两个元素的元组:第一个元素为 str 类型的计算图源码,第二个元素为 ConstMap 类型的常量映射。 # 【资料变更】 > “不涉及” # 【接口变更】 >“不涉及” # 【功能验证】 测试场景与测试方法: code_with_constants 属性验证,构造含多种常量的 ScriptModule,断言 code_with_constants 返回值的结构和内容 返回 (str, ConstMap),且常量值匹配 具体demo如下: python def test_script_module_code_with_constants(self): """Test code_with_constants API extraction and inference on NPU device.""" if not hasattr(torch, "npu") or not torch.npu.is_available(): self.skipTest("NPU device is unavailable, skip this test case") # Define a model containing tensor constants and control flow class ModelWithConstants(torch.nn.Module): def __init__(self): super().__init__() self.conv = torch.nn.Conv2d(1, 1, kernel_size=3, padding=1) self.threshold = 0.5 # Register a tensor as a buffer to act as a constant in TorchScript self.register_buffer('scale_factor', torch.tensor([2.0])) def forward(self, x): x = self.conv(x) x = x * self.scale_factor if x.mean() > self.threshold: x = x + 1.0 return x # Initialize model and convert to ScriptModule model = ModelWithConstants() scripted_model = torch.jit.script(model).npu() # Move model to NPU and check device placement self._check_model_device(scripted_model, "npu") # Verify the functionality of code_with_constants API result = scripted_model.code_with_constants code_str, constants = result # Verify the extracted code is a string and contains the forward function signature self.assertIsInstance(code_str, str) self.assertIn("def forward", code_str) # Verify the constants object type self.assertIsInstance(constants, torch.jit._script.ConstMap) 测试命令:python test_jit_scriptmodule.py 测试结果:  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!41627 | 1 个月前 | |
test: add NPU test cases for torch.nn.attention.flex_attention BlockMask.to_string, create_mask, create_nested_block_mask Co-authored-by: gcw_H7sZe82x<2640411208@qq.com> # message auto-generated for no-merge-commit merge: !45154 merge test-flex-attention-apis-master into master test: add NPU test cases for torch.nn.attention.flex_attention BlockMask.to_string, create_mask, create_nested_block_mask Created-by: gcw_H7sZe82x Commit-by: gcw_H7sZe82x Merged-by: ascend-robot Description: ## 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 - 关联 issue: - https://atomgit.com/Ascend/pytorch/issues/3288 (torch.nn.attention.flex_attention.BlockMask.to_string) - https://atomgit.com/Ascend/pytorch/issues/3289 (torch.nn.attention.flex_attention.create_mask) - https://atomgit.com/Ascend/pytorch/issues/3290 (torch.nn.attention.flex_attention.create_nested_block_mask) - 任务分类:1.2②(PyTorch 官方社区无用例或未覆盖完整,且 API 涉及硬件接口) - 三个 API 均属于 torch.nn.attention.flex_attention 模块,故合并到同一测试文件中。 - pytorch 社区没有针对这三个 API 的独立且充分的测试用例,故新增该测试文件,用于验证这些 API 的正确性。 ## 【修改方案】 ### 一、API 功能说明 #### 1. torch.nn.attention.flex_attention.BlockMask.to_string BlockMask 类的字符串可视化方法,返回 BlockMask 的字符串表示。 - **签名**:to_string(self, grid_size: int | tuple[int, int] = (20, 20), limit: int = 4) -> str - **参数**: - grid_size:网格大小,控制输出可视化网格的行列数。为 int 时表示行列均相同;为 tuple 时分别指定行列;为 -1 时输出非压缩版本。 - limit:限制显示的 batch/head 组合数量,超出部分以 "..." 截断。 - **返回值**:str,包含可视化字符(█、空格、░)和 batch 索引的字符串。 - **内部实现**:调用 self.to_dense() 获取稠密掩码张量(涉及设备上的张量操作),再根据 grid_size 和 limit 参数生成可视化字符串。 #### 2. torch.nn.attention.flex_attention.create_mask 根据 mod_fn 函数创建掩码张量。 - **签名**:create_mask(mod_fn, B, H, Q_LEN, KV_LEN, device=None) -> Tensor - **参数**: - mod_fn:mask_mod 或 score_mod 函数,定义掩码模式。 - B:批量大小,为 None 时默认 1。 - H:头数,为 None 时默认 1。 - Q_LEN:查询序列长度。 - KV_LEN:键/值序列长度。 - device:设备,为 None 时使用当前加速器。 - **返回值**:Tensor,形状为 (B, H, Q_LEN, KV_LEN) 的掩码张量。 - **内部实现**:在设备上创建 arange 张量,通过 vmap 对 mod_fn 进行向量化计算,涉及设备上的张量操作。 #### 3. torch.nn.attention.flex_attention.create_nested_block_mask 根据 mask_mod 函数创建与嵌套张量(NJT)兼容的块掩码。 - **签名**:create_nested_block_mask(mask_mod, B, H, q_nt, kv_nt=None, BLOCK_SIZE=128, _compile=False) -> BlockMask - **参数**: - mask_mod:mask_mod 函数,定义掩码模式。 - B:批量大小。 - H:头数。 - q_nt:查询嵌套张量(Jagged layout NJT)。 - kv_nt:键/值嵌套张量,为 None 时使用 q_nt。 - BLOCK_SIZE:块大小。 - **返回值**:BlockMask 对象。 - **版本说明**:该 API 仅在 PyTorch v2.7.1 中存在,v2.11.0,v2.12.0,master 已移除。测试中使用 setUp + self.skipTest() 条件跳过。 ### 二、测试用例完备性说明 PyTorch 社区测试覆盖情况: - BlockMask.to_string:社区在 test/inductor/test_flex_attention.py 中仅通过 str(block_mask) 间接调用(默认参数),grid_size 和 limit 参数均未覆盖。 - create_mask:社区测试中无直接调用。 - create_nested_block_mask:社区测试中无直接调用。 新增测试文件 test/nn/test_npu_block_mask.py,共 28 个测试用例,分为三个测试类: #### TestBlockMaskToString(12 个用例) | 参数 | 覆盖场景 | 测试方法 | | --- | --- | --- | | grid_size | 默认值 (20, 20) | test_to_string_default | | grid_size | int 类型 | test_to_string_grid_size_int | | grid_size | tuple 类型(正方形) | test_to_string_grid_size_tuple | | grid_size | tuple 类型(非正方形) | test_to_string_grid_size_non_square_tuple | | grid_size | -1(非压缩) | test_to_string_grid_size_negative_one | | limit | 0(边界值,立即截断) | test_to_string_limit_zero | | limit | 1(边界值,显示一个后截断) | test_to_string_limit_one | | limit | 大于 batch*head(显示全部) | test_to_string_limit_large | | grid_size + limit | 组合参数 | test_to_string_combined_params | | 返回值 | 包含可视化字符 █ 和空格 | test_to_string_contains_visual_chars | | 返回值 | 包含 batch 索引 (0, 0) | test_to_string_contains_batch_indices | | 等价性 | grid_size int 等价于相同值 tuple | test_to_string_int_equals_tuple | #### TestCreateMask(11 个用例) | 参数 | 覆盖场景 | 测试方法 | | --- | --- | --- | | mod_fn | mask_mod 函数(4参数) | test_create_mask_basic_mask_mod | | mod_fn | score_mod 函数(5参数) | test_create_mask_basic_score_mod | | B | None(默认为 1) | test_create_mask_b_none | | H | None(默认为 1) | test_create_mask_h_none | | B, H | 均为 None | test_create_mask_both_none | | Q_LEN, KV_LEN | 不同长度 | test_create_mask_different_q_kv_len | | 返回值 | 因果掩码值正确性 | test_create_mask_causal_values | | device | 输出在正确设备上 | test_create_mask_device | | mod_fn | prefix LM 掩码 | test_create_mask_prefix_lm | | mod_fn | sliding window 掩码 | test_create_mask_sliding_window | | B, H | 多批量多头 | test_create_mask_multi_batch_heads | #### TestCreateNestedBlockMask(5 个用例,仅 PyTorch v2.7.1) | 参数 | 覆盖场景 | 测试方法 | | --- | --- | --- | | 基本功能 | 返回 BlockMask | test_create_nested_block_mask_basic | | kv_nt | 交叉注意力(显式 kv_nt) | test_create_nested_block_mask_with_kv_nt | | BLOCK_SIZE | 自定义块大小 | test_create_nested_block_mask_block_size | | B, H | 多批量多头 | test_create_nested_block_mask_multi_batch | | device | 输出在正确设备上 | test_create_nested_block_mask_device | ### 三、NPU 适配 - 使用 device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu" 获取 NPU 设备。 - 通过 create_block_mask(mask_mod, B, H, Q_LEN, KV_LEN, device=device_type) 在 NPU 上创建 BlockMask。 - to_string 内部调用 to_dense() 执行设备上的张量操作,验证 NPU 设备上的正确性。 - create_mask 通过 device=device_type 在 NPU 上创建掩码张量,涉及 arange 和 vmap 设备操作。 - create_nested_block_mask 接收嵌套张量(NJT),在 NPU 设备上创建块掩码。 - create_nested_block_mask 仅在 PyTorch v2.7.1 中可用,使用 setUp + self.skipTest() 在不可用时跳过。 ## 【资料变更】 > 不涉及 > > 另行通过资料补齐 PR 提交至 master 分支,本PR仅提交测试文档,详见资料补齐 PR https://atomgit.com/Ascend/pytorch/pull/45155。 ## 【接口变更】 > 不涉及 > > 仅新增测试用例,未修改任何业务代码。 ## 【功能验证】 新增文件:test/nn/test_npu_block_mask.py ### 运行命令 bash # 运行全部测试 python test/nn/test_npu_block_mask.py # 单独运行各 API 测试类 python test/nn/test_npu_block_mask.py TestBlockMaskToString python test/nn/test_npu_block_mask.py TestCreateMask python test/nn/test_npu_block_mask.py TestCreateNestedBlockMask ### torch.nn.attention.flex_attention.BlockMask.to_string 验证结果 bash $ python test/nn/test_npu_block_mask.py TestBlockMaskToString test_to_string_combined_params ... ok test_to_string_contains_batch_indices ... ok test_to_string_contains_visual_chars ... ok test_to_string_default ... ok test_to_string_grid_size_int ... ok test_to_string_grid_size_negative_one ... ok test_to_string_grid_size_non_square_tuple ... ok test_to_string_grid_size_tuple ... ok test_to_string_int_equals_tuple ... ok test_to_string_limit_large ... ok test_to_string_limit_one ... ok test_to_string_limit_zero ... ok ---------------------------------------------------------------------- Ran 12 tests in ...s OK ### torch.nn.attention.flex_attention.create_mask 验证结果 bash $ python test/nn/test_npu_block_mask.py TestCreateMask test_create_mask_basic_mask_mod ... ok test_create_mask_basic_score_mod ... ok test_create_mask_b_none ... ok test_create_mask_both_none ... ok test_create_mask_causal_values ... ok test_create_mask_device ... ok test_create_mask_different_q_kv_len ... ok test_create_mask_h_none ... ok test_create_mask_multi_batch_heads ... ok test_create_mask_prefix_lm ... ok test_create_mask_sliding_window ... ok ---------------------------------------------------------------------- Ran 11 tests in ...s OK ### torch.nn.attention.flex_attention.create_nested_block_mask 验证结果 PyTorch v2.7.1(API 存在): bash $ python test/nn/test_npu_block_mask.py TestCreateNestedBlockMask test_create_nested_block_mask_basic ... ok test_create_nested_block_mask_block_size ... ok test_create_nested_block_mask_device ... ok test_create_nested_block_mask_multi_batch ... ok test_create_nested_block_mask_with_kv_nt ... ok ---------------------------------------------------------------------- Ran 5 tests in ...s OK PyTorch v2.11.0 / v2.12.0 / master(API 已移除,自动跳过): bash $ python test/nn/test_npu_block_mask.py TestCreateNestedBlockMask test_create_nested_block_mask_basic ... skipped 'create_nested_block_mask is only available in PyTorch 2.7' test_create_nested_block_mask_block_size ... skipped 'create_nested_block_mask is only available in PyTorch 2.7' test_create_nested_block_mask_device ... skipped 'create_nested_block_mask is only available in PyTorch 2.7' test_create_nested_block_mask_multi_batch ... skipped 'create_nested_block_mask is only available in PyTorch 2.7' test_create_nested_block_mask_with_kv_nt ... skipped 'create_nested_block_mask is only available in PyTorch 2.7' ---------------------------------------------------------------------- Ran 5 tests in ...s OK (skipped=5) ### 全部测试汇总 | 版本 | 运行命令 | 结果 | | --- | --- | --- | | PyTorch v2.7.1 | python test/nn/test_npu_block_mask.py | Ran 28 tests, OK | | PyTorch v2.11.0 | python test/nn/test_npu_block_mask.py | Ran 28 tests, OK (skipped=5) | | PyTorch v2.12.0 | python test/nn/test_npu_block_mask.py | Ran 28 tests, OK (skipped=5) | | master | python test/nn/test_npu_block_mask.py | Ran 28 tests, OK (skipped=5) | ## 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR 标题正确使用类型标签,如:feat、fix、refactor、docs、test 等 - [x] PR 持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!45154 | 15 天前 | |
fix: fall back to default log level on invalid ASCEND_GLOBAL_LOG_LEVEL Co-authored-by: chen_pengyu<chenpengyu26@huawei.com> # message auto-generated for no-merge-commit merge: !47690 merge master into master fix: fall back to default log level on invalid ASCEND_GLOBAL_LOG_LEVEL Created-by: chen_pengyu Commit-by: chen_pengyu Merged-by: ascend-robot Description: ## 【合入来源】 > **如有社区issue,请关联issue链接** > **请勿携带内部流程信息(需求链接、问题单、内部issue等)** * [x] issue/工单 关联issue:https://gitcode.com/Ascend/pytorch/issues/5342(Fixes #5342) ## 【修改方案】 OptionsManager::isACLGlobalLogOn 被所有 ASCEND_LOG{E,W,I,D} 宏调用,位于日志系统热路径上。当 ASCEND_GLOBAL_LOG_LEVEL 为非法值时,原实现 TORCH_CHECK 抛出异常,而异常路径(formatErrorCode → GetDevice → is_lazy_set_device → ASCEND_LOGW)会重入本函数:magic static 初始化未完成时同线程重入直接卡死;即使去掉 PTA_ERROR,异常中断静态初始化后栈展开中任何 ASCEND_LOGx 重入再次抛异常,std::terminate → abort core dump。详见 issue #5342 调用链分析。 修复:将 isACLGlobalLogOn 改为纯查询函数,严格解析环境变量(拒绝空串/非数字/含非法尾字符/超范围,含 endptr 完整性校验与 int64→int32 收窄绕过问题),非法值一律静默回落到默认级别 ACL_ERROR(3),与 CANN 官方文档《ASCEND_GLOBAL_LOG_LEVEL》“若环境变量未配置/配置为非法值/配置为空,采用默认日志级别”的规范对齐。 行为变化:未配置/合法值 0-4 完全不变;非法值(非数字、空串、超范围、溢出)由“卡死或 core dump”变为“回落默认 error 级别”。 ## 【资料变更】 不涉及。环境变量文档行为与 CANN《环境变量参考》一致,代码向文档对齐。 ## 【接口变更】 不涉及。isACLGlobalLogOn 为内部函数,无公开接口变更。 ## 【功能验证】 1. 新增 UT test/npu/test_ascend_global_log_level.py:子进程模式(因 isACLGlobalLogOn 在函数局部 static 中缓存解析结果,每个取值需独立进程验证)覆盖未设置/合法值 0-4/超范围(5、-1、999)/非数字(abc、0x2、3x)/空串/int64 溢出与 int32 收窄绕过(4294967296、-4294967292)共 6 组用例,断言子进程正常退出(returncode 0)——修复前非法值会卡死(magic static 重入)或 core dump(异常重抛 terminate) 2. 端到端验证(v2.8.0 分支等价修改,CANN 9.2.0 / torch 2.8.0):ASCEND_GLOBAL_LOG_LEVEL=5 python -c "import torch; import torch_npu" 正常启动,不卡死、不 core dump,日志为默认 error 档 3. tools/check_public_environments.py 看护项不受影响(logLevelMode 定义未改动) ## 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] * [x] 代码注释完备,正确记录错误日志 * [x] 代码实现进行了返回值、空指针等校验 * [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等(fix) * [x] PR持续集成流水线(CI)执行通过,代码检查无异常(个人分支暂未触发 CI,合入前补充) See merge request: Ascend/pytorch!47690 | 1 天前 | |
test: Add validation cases for torch.onnx.ONNXProgram.optimize on NPU Co-authored-by: muluzhe<3598510361@qq.com> # message auto-generated for no-merge-commit merge: !43588 merge test-onnx-program-optimize-master into master test: Add validation cases for torch.onnx.ONNXProgram.optimize on NPU Created-by: muluzhe Commit-by: muluzhe Merged-by: ascend-robot Description: ## 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 - 关联 issue: https://gitcode.com/Ascend/pytorch/issues/3490 - 任务分类:1.2②(PyTorch 官方社区无用例,新增用例到 test 目录) - pytorch 社区没有针对 torch.onnx.ONNXProgram.optimize 的独立测试用例,故新增该测试文件,用于验证该 API 的正确性。 ## 【修改方案】 ### 一、API 功能说明 torch.onnx.ONNXProgram.optimize() 是 ONNXProgram 类的公开方法,用于优化 ONNX 模型。该方法通过调用 onnxscript_apis.optimize(self.model) 对 ONNX IR 模型执行常量折叠和冗余消除,优化原地生效,返回值为 None。该 API 为非计算类 API,操作对象是 ONNX 模型图而非 PyTorch 张量,与数据类型和设备无关。 ### 二、测试用例完备性说明 PyTorch 官方 test/onnx/exporter/test_onnx_program.py 中仅有 ONNXProgramRenameAxesTest 测试 rename_axes 方法,没有直接调用 ONNXProgram.optimize() 的测试用例。其他测试中的 optimize=False 是 torch.onnx.export() 的入参,与本方法无关。本次新增 test/onnx/exporter/test_onnx_program.py,通过 torch.onnx.export(dynamo=True, optimize=False) 创建未优化的 ONNXProgram,再调用 optimize() 直接验证: - optimize() 返回值为 None; - 优化后模型仍然有效(model 和 graph 非空); - optimize() 可重复调用不报错(幂等性); - 优化后模型的输入输出数量保持不变。 ### 三、NPU 适配 测试通过 torch.onnx.export() 创建 ONNXProgram,输入张量通过 device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu" 迁移到 NPU。optimize() 本身为非计算类 API,操作 ONNX IR 图结构,与设备无关。该测试代码在 v2.7.1 和 v2.12.0 间无需版本差异处理。 ## 【资料变更】 > 不涉及 > > 已检查:torch.onnx.ONNXProgram.optimize 在 docs/zh/api/native_api 的 pytorch_2-7-1、pytorch_2-11-0、pytorch_2-12-0、pytorch_2-13-0 四个版本目录的 torch-onnx.md 中均未收录,资料已在 PR https://gitcode.com/Ascend/pytorch/pull/43671 补充。 ## 【接口变更】 > 不涉及 > > 仅新增测试用例,未修改任何业务代码。 ## 【功能验证】 - **本地 NPU 运行**(torch 2.7.1+cpu) - 命令:TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest test/onnx/exporter/test_onnx_program.py -v - 结果:======================== 4 passed, 2 warnings in 10.46s ======================== ## 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR 标题正确使用类型标签,如:feat、fix、refactor、docs、test 等 - [x] PR 持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43588 | 1 个月前 | |
[optim] Add distributed Muon optimizer support for Ascend NPU Co-authored-by: guoqi1024<guoqi5@huawei.com> # message auto-generated for no-merge-commit merge: !38393 merge feature/distributed-muon-optimizer into master [optim] Add distributed Muon optimizer support for Ascend NPU Created-by: guoqi1024 Commit-by: guoqi1024 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/2403 - [x] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38393 | 3 个月前 | |
test(package): add testcase for PackageExporter additional APIs Co-authored-by: PAGEMRW<985608880@qq.com> # message auto-generated for no-merge-commit merge: !37848 merge test-package-exporter-additional-api-master into master test(package): add testcase for PackageExporter additional APIs Created-by: PAGEMRW Commit-by: PAGEMRW Merged-by: ascend-robot Description: # 【合入来源】 - 问题单 PyTorch 社区用例对以下 torch.package.PackageExporter API 缺少充分且直接的验证: torch.package.PackageExporter.add_dependency torch.package.PackageExporter.all_paths torch.package.PackageExporter.close torch.package.PackageExporter.dependency_graph_string torch.package.PackageExporter.get_unique_id torch.package.PackageExporter.register_intern_hook 因此新增 test_package_exporter_additional_api.py 测试文件,用于验证上述 6 个 API 的正确性,并补充异常路径验证,覆盖显式依赖添加、依赖图路径查询、依赖图字符串输出、唯一 ID 生成、intern hook 注册/移除、PackageExporter 正常关闭及重复关闭异常等场景。 # 【修改方案】 一、API 功能说明 1. torch.package.PackageExporter.add_dependency 是 PyTorch torch.package.PackageExporter 中用于手动向包导出器依赖图添加模块依赖的 API,核心功能如下: 依赖图补充能力:接收指定模块名,并根据用户预先配置的 extern、intern、mock、deny 等规则,将该模块加入 PackageExporter 的依赖分析流程。 规则驱动处理:模块最终是被打包进 archive、作为外部依赖记录、替换为 mock 模块,还是被拒绝,取决于导出器中已有的依赖匹配规则。 递归依赖分析支持:当 dependencies=True 时,会进一步分析该模块源码中的 import 依赖,并将相关依赖继续纳入处理。 手动依赖声明:适用于测试或特殊打包场景中显式补充某个模块依赖,避免完全依赖 save_module、save_pickle 等接口的自动扫描。 纯 Python 打包辅助:该 API 主要操作模块依赖关系和导出规则,不涉及张量计算,也不要求运行在 NPU/GPU 设备上。 2. torch.package.PackageExporter.all_paths 是 PyTorch PackageExporter 中用于查询两个模块之间依赖路径的调试分析 API,核心功能如下: 依赖路径追踪:接收源模块 src 和目标模块 dst,返回从 src 到 dst 的所有依赖路径。 DOT 图格式输出:返回结果为 DOT 格式字符串,可用于 Graphviz 等工具可视化依赖子图。 依赖原因定位:常用于分析某个模块为什么会被 PackageExporter 作为依赖引入,帮助定位间接 import 链路。 子图级别查看:相比完整依赖图,该 API 只关注指定源模块到目标模块之间的路径,便于缩小调试范围。 静态调试属性:该 API 只读取和展示 PackageExporter 内部依赖图信息,不会执行实际模型计算或张量运算。 3. torch.package.PackageExporter.close 是 PyTorch PackageExporter 中用于结束打包并将 package 写入目标位置的收尾 API,核心功能如下: 包写出能力:将前面通过 save_module、save_pickle、save_text、save_binary、save_source_string 等接口收集到的代码、对象和资源正式写入文件系统或二进制 IO 对象。 导出流程终止:调用 close() 后,PackageExporter 进入关闭状态,后续再调用保存、依赖添加等导出相关接口将不再合法。 上下文管理器等价:通常推荐使用 with PackageExporter(...) as exporter 的形式自动触发关闭逻辑,避免忘记手动调用 close()。 规则完整性检查:在关闭阶段会完成打包收尾检查,例如未解析依赖、非法依赖或未匹配规则可能在关闭时触发异常。 资源释放作用:用于确保底层 zip/package 归档结构被完整写入并释放相关写入资源。 4. torch.package.PackageExporter.dependency_graph_string 是 PyTorch PackageExporter 中用于输出完整包依赖图的调试 API,核心功能如下: 完整依赖图查看:返回当前 PackageExporter 已记录的 package 依赖关系图。 字符串化输出:返回值为字符串形式的依赖图表示,可直接打印到控制台或写入日志文件。 打包调试支持:用于观察哪些模块被纳入依赖图、模块之间存在怎样的依赖关系。 与局部路径分析互补:all_paths(src, dst) 适合查看两个模块之间的路径,而 dependency_graph_string() 适合查看整体依赖结构。 无副作用查询:该 API 只读取依赖图状态,不会修改打包内容,也不涉及张量或设备相关操作。 5. torch.package.PackageExporter.get_unique_id 是 PyTorch PackageExporter 中用于生成包内唯一标识符的辅助 API,核心功能如下: 唯一 ID 生成:返回一个字符串 ID,并保证该 ID 在当前 package 导出过程中只会被分配一次。 避免命名冲突:常用于生成临时模块名、资源路径或中间文件名,防止与已有模块和资源发生冲突。 自定义打包支持:在自定义 __reduce_package__ 等高级打包逻辑中,可用该 API 为动态生成的资源分配唯一名称。 包内范围唯一:其唯一性主要保证在当前 PackageExporter 管理的 package 内成立,不用于全局分布式唯一标识。 轻量级工具属性:该 API 只生成字符串标识,不涉及依赖扫描、文件写入或张量运算。 6. torch.package.PackageExporter.register_intern_hook 是 PyTorch PackageExporter 中用于注册 intern 模块匹配回调函数的 API,核心功能如下: intern 回调注册:向导出器注册一个 hook,当某个模块匹配 intern() 规则并准备被打包进 package 时,该 hook 会被触发。 自定义处理能力:hook 函数可接收 exporter 和 module_name,从而在模块被 intern 时执行额外逻辑,例如记录日志、统计模块、补充资源或检查模块名。 多 hook 顺序执行:支持注册多个 intern hook,并按照注册顺序依次调用,便于组合多个自定义处理逻辑。 可移除句柄支持:注册后会返回 RemovableHandle,后续可通过 handle.remove() 移除该 hook。 打包流程扩展点:该 API 提供对 PackageExporter 内部模块处理流程的扩展能力,适合测试 hook 调用顺序、移除机制和模块匹配行为。 二、测试文件 test_package_exporter_additional_api.py 完整验证该 API 的原因 `` 该测试用例针对 torch.package.PackageExporter.add_dependency、torch.package.PackageExporter.all_paths、torch.package.PackageExporter.dependency_graph_string、torch.package.PackageExporter.get_unique_id、torch.package.PackageExporter.register_intern_hook 和 torch.package.PackageExporter.close 六个 API,从显式依赖处理、异常依赖处理、依赖图路径查询、依赖图字符串输出、唯一标识生成、Hook 注册与移除机制、包写入闭环、重复关闭异常等维度进行直接验证,具体体现在: 1. 对 add_dependency API 的验证 显式依赖添加验证 test_add_dependency:通过创建 PackageExporter,并直接调用 add_dependency("math") 手动加入 math 模块依赖,验证 API 能够将指定模块加入 PackageExporter 的依赖分析流程。测试通过 dependency_graph.nodes 校验 math 已被加入依赖图节点,说明 add_dependency 能够正确记录显式添加的依赖。随后关闭 exporter,并使用 PackageImporter 从内存 package 中重新加载 math 模块,验证导入结果与系统原生 math 模块一致,说明显式添加的依赖不仅在导出阶段被正确记录,也能在导入阶段保持正确解析。 不存在模块异常路径验证 test_add_dependency_nonexistent_module_raises:通过 add_dependency("nonexistent_module_for_package_exporter_test") 手动添加一个不存在的模块依赖,并在 exporter.close() 阶段断言抛出 PackagingError。该测试验证 add_dependency 对非法/不可解析模块依赖的处理符合预期:依赖可以先进入导出器依赖处理流程,但最终关闭打包时会进行完整性检查并暴露打包错误,避免生成包含无效依赖的 package。 2. 对 all_paths API 的验证 依赖路径查询验证 test_all_paths:手动向 dependency_graph 中添加 a -> b、b -> c、a -> d 三条边,然后调用 all_paths("a", "c") 查询从 a 到 c 的依赖路径。测试断言结果中包含 "a" -> "b" 和 "b" -> "c",说明 API 能够正确返回目标路径上的依赖边;同时断言结果中不包含 "a" -> "d",说明 API 不会错误返回与目标节点 c 无关的分支路径。该测试覆盖了依赖图路径提取的正确性和无关路径过滤能力。 3. 对 dependency_graph_string API 的验证 依赖图字符串输出验证 test_dependency_graph_string:通过向 dependency_graph 中添加 a -> b 依赖边,再调用 dependency_graph_string() 获取完整依赖图字符串。测试断言结果中包含 digraph G,验证其输出符合 DOT 图格式;同时断言结果中包含 "a" -> "b",验证依赖图中的实际边关系能够被正确序列化输出。该测试说明该 API 能够将 PackageExporter 内部依赖图转换为可读、可调试的字符串表示。 4. 对 get_unique_id API 的验证 唯一标识生成验证 test_get_unique_id:连续三次调用 get_unique_id(),并分别断言返回值为 "0"、"1"、"2"。该测试验证了 API 能够在同一个 PackageExporter 实例内生成单调递增且不重复的字符串 ID,说明其可用于包内临时资源、模块名或自定义打包逻辑中的唯一命名需求。同时,连续调用场景也验证了内部计数状态能够被正确维护。 5. 对 register_intern_hook API 的验证 Hook 注册与触发验证 test_register_intern_hook:定义 intern_hook 回调函数,并通过 register_intern_hook 注册到 PackageExporter 中。随后调用 save_source_string("foo", "VALUE = 1", dependencies=False) 保存源码模块,触发模块 intern 流程。测试最终断言 interned_modules 等于 ["foo"],说明当模块被打包进 package 时,已注册的 intern hook 能够被正确调用,并且能够接收到正确的模块名参数。 Hook 移除机制验证 test_register_intern_hook_remove:注册 intern hook 后,立即调用返回句柄的 remove() 方法移除该 hook,再保存 foo 模块。测试断言 interned_modules 为空列表,说明被移除的 hook 不会继续触发。该测试进一步覆盖了 register_intern_hook 返回句柄的有效性,以及 hook 注册后可撤销的边界行为,避免回调残留或误触发。 6. 对 close API 的验证 包写入闭环验证 test_close:先通过 save_source_string("foo", "VALUE = 3", dependencies=False) 向 package 中写入源码模块,再调用 close() 完成导出收尾。随后重置 BytesIO 指针,并使用 PackageImporter 从内存 package 中重新导入 foo 模块,断言 foo.VALUE 等于 3。该测试验证了 close() 能够正确完成 package 的最终写入、归档结构封装和资源收尾,使导出的内容能够被后续 PackageImporter 正常加载。 重复关闭异常路径验证 test_close_twice_raises:创建 PackageExporter 后先执行一次 close() 完成关闭,再次调用 close() 时断言抛出异常。该测试验证 close() 关闭状态管理符合预期,PackageExporter 在完成导出后不会允许重复关闭或重复写入,从而避免资源状态异常、归档结构重复收尾等问题。 7. 测试完整性与隔离性保障 该测试文件使用 BytesIO 作为内存 package 载体,避免依赖外部文件系统,保证测试过程轻量、独立、可重复。每个测试用例均重新创建 PackageExporter 实例,分别构造独立的依赖图、hook 列表或 package 内容,避免不同 API 测试之间发生状态污染。部分测试使用 with PackageExporter(buffer) as exporter 的上下文管理方式,覆盖自动 close 场景;test_close 显式调用 close(),覆盖手动关闭场景;test_add_dependency_nonexistent_module_raises 和 test_close_twice_raises 分别覆盖依赖解析失败与重复关闭两个异常分支。由于这些 API 主要属于 torch.package 的 Python 层打包、依赖管理和导出流程,不涉及实际张量计算或 NPU 算子执行,因此无需额外构造 NPU 张量,也无需额外进行张量迁移适配。 三、NPU 适配 torch.package.PackageExporter.add_dependency、torch.package.PackageExporter.all_paths、torch.package.PackageExporter.close、torch.package.PackageExporter.dependency_graph_string、torch.package.PackageExporter.get_unique_id 和 torch.package.PackageExporter.register_intern_hook 均属于 torch.package 模块中的 Python 层打包、依赖管理、调试分析和 Hook 扩展类 API,不涉及张量计算、算子执行或设备调度逻辑,因此无需针对昇腾 NPU 做额外适配,具体分析如下: 1. 纯 Python 层打包流程 API,无硬件相关计算逻辑 - add_dependency API:主要用于手动向 PackageExporter 的依赖图中添加模块依赖,并根据 extern、intern、mock、deny 等规则处理模块归属,核心逻辑是 Python 模块依赖分析和打包规则匹配,不涉及 Tensor 运算或 NPU 算子调用;新增的不存在模块用例验证的是打包阶段异常检查,也不涉及设备逻辑。 - all_paths API:仅用于查询 PackageExporter 内部依赖图中两个模块之间的依赖路径,返回 DOT 格式字符串,属于依赖图调试分析能力,不涉及任何设备侧计算。 - dependency_graph_string API:用于将当前依赖图字符串化输出,便于观察模块之间的依赖关系,本质是读取并序列化 Python 层依赖图结构,与 NPU 硬件无关。 - get_unique_id API:仅用于在当前 PackageExporter 实例内生成唯一字符串 ID,属于轻量级命名辅助工具,不涉及依赖扫描、文件执行、张量创建或设备迁移。 - register_intern_hook API:用于注册模块 intern 过程中的 Python 回调函数,核心逻辑是 hook 注册、触发和移除,不依赖任何底层硬件能力。 - close API:用于完成 package 的最终写入和资源收尾,将已保存的源码、对象或资源写入目标 package 中,属于文件/字节流归档写出逻辑;新增的重复 close 用例验证的是 Python 对象关闭状态管理,也不涉及 NPU 计算图或算子执行。 2. 无底层算子 / 内核 / NPU Runtime 依赖 - 这 6 个 API 的核心功能集中在 PackageExporter 的模块依赖管理、依赖图维护、包内容写入、唯一 ID 生成以及 hook 机制上,均运行在 Python 解释器和 PyTorch 打包框架层面。 - 测试过程中使用的 BytesIO、PackageExporter、PackageImporter、dependency_graph 等对象均属于 Python 层对象或 PyTorch package 管理结构,不会调用 torch_npu 的算子、NPU kernel、NPU 内存管理接口或设备通信接口。 - 测试用例即使在 torch-npu 迁移环境下执行,也仅验证 torch.package 的打包、导入和依赖图逻辑,不触发任何 NPU 设备侧行为。 3. 核心逻辑与硬件设备解耦 - 依赖管理解耦:add_dependency、all_paths 和 dependency_graph_string 操作的是模块依赖图,依赖关系来自 Python import 规则和 PackageExporter 的打包策略,与 CPU/GPU/NPU 设备类型无关。 - 打包写入解耦:close API 负责将 package 内容写入内存 buffer 或文件系统,其正确性取决于归档结构和资源写入完整性,而不是底层计算设备。 - Hook 机制解耦:register_intern_hook 触发的是 Python 回调函数,测试关注 hook 是否被正确注册、调用和移除,不涉及任何硬件执行路径。 - 唯一标识生成解耦:get_unique_id 仅维护 PackageExporter 内部计数状态并返回字符串 ID,不包含设备判断、张量分配或算子派发逻辑。 4. 无需构造 NPU 张量的原因 - 本测试文件覆盖的 6 个 API 均不以 Tensor 作为输入,也不返回 Tensor 结果。 - 测试逻辑主要包括模块依赖声明、异常依赖关闭检查、依赖图边关系查询、字符串输出校验、hook 调用验证、package 写入与重新导入验证、重复关闭异常验证。 - 因此,按照“涉及张量的用例尽可能运行在 NPU 上”的原则,本测试文件不存在需要迁移到 NPU 的张量对象,也无需额外添加 .npu() 或 .to(device_type) 操作。 - 若强行构造 NPU 张量,反而会引入与被测 API 无关的设备依赖,降低测试的针对性和最小化原则。 综上,torch.package.PackageExporter.add_dependency、all_paths、close、dependency_graph_string、get_unique_id 和 register_intern_hook 均属于硬件无关的 Python 层 package 导出与依赖管理 API。其功能正确性主要取决于 PackageExporter 内部依赖图、打包规则、hook 机制、异常状态管理和归档写入逻辑,不依赖昇腾 NPU 的算子、内存或运行时能力。因此在 torch-npu 适配中无需修改 API 本身,也无需构造 NPU 张量,可直接复用 PyTorch 社区逻辑进行验证。 # 【资料变更】 > 不涉及 已检查文档,https://gitcode.com/Ascend/pytorch/tree/v2.7.1/docs/zh/native_apis 下面各个版本均已记录这些 API 支持情况,因此不需要提交 PR 修改资料。 # 【接口变更】 > 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤 > 新增/变更内容是否已新增/适配 UT 测试用例看护,并补充测试自验证截图 在 2.7.1、2.9.0、2.10.0、2.11.0、2.12.0 版本上执行该用例,均通过,日志如下: ` root@c18d5a0da657:/workspace/pytorch29/test/package# python -m unittest -v test_package_exporter_additional_api test_add_dependency (test_package_exporter_additional_api.TestPackageExporterAdditionalAPI.test_add_dependency) ... ok test_add_dependency_nonexistent_module_raises (test_package_exporter_additional_api.TestPackageExporterAdditionalAPI.test_add_dependency_nonexistent_module_raises) ... ok test_all_paths (test_package_exporter_additional_api.TestPackageExporterAdditionalAPI.test_all_paths) ... ok test_close (test_package_exporter_additional_api.TestPackageExporter See merge request: Ascend/pytorch!37848 | 4 个月前 | |
[Usage]profiler logs optimize Co-authored-by: hehongzhe<935062458@qq.com> # message auto-generated for no-merge-commit merge: !46935 merge fixwarn into master [Usage]profiler logs optimize Created-by: hhz0 Commit-by: hehongzhe Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/5069 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1、CANN 支持默认导出 DB 时保留 op_attr;不支持时维持原有校验行为,并补充对应测试。 2、将动态 JSON 配置中这三个字段的缺省值分别设为空列表和 False,并补充缺省值测试。 3、使用 aten::、npu::、atb:: 前缀元组,通过 startswith() 统一匹配。 4、移除未知通信类型的逐条 warning,保留原有分类和数据处理逻辑。 5、将 StepInfoDbParser 的告警改为明确指出 DB 文件可能缺失或不可访问,或具体缺少哪个表。 6、重试失败记为 INFO,重试耗尽时记一次 ERROR 后抛出异常。 7、kernel events 缺失提示,说明 NPU profiling 数据可能未采集,并建议检查 CANN plog 日志。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 下面是修改前,上面是修改后  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!46935 | 18 天前 | |
AI assist developer for python dt master Co-authored-by: aksksks<mengzichao@h-partners.com> # message auto-generated for no-merge-commit merge: !26538 merge master into master AI assist developer for python dt master Created-by: aksksks Commit-by: aksksks Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!26538 | 10 个月前 | |
[sync] PR-45502: test: un-skip test_single_reshape_copy_to_contiguous cases (issue 4356) Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com> # message auto-generated for no-merge-commit merge: !46545 merge fix/narrow-aclnn-nc1hwc0-3d-fallback-master into master [sync] PR-45502: test: un-skip test_single_reshape_copy_to_contiguous cases (issue 4356) Created-by: wuyouqi1 Commit-by: wuyouqi1 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue:https://gitcode.com/Ascend/pytorch/issues/4356 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间是如何交互的,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 本 MR 为 !45502(已合入 v2.7.1: test: un-skip test_single_reshape_copy_to_contiguous cases (issue 4356))向 **master** 分支的同步合入,代码内容与 v2.7.1 合入版本一致。 1. 背景:issue 4356 中 allow_internal_format=True 时,非视图 3D NC1HWC0 张量经 npu_format_cast(src, NCHW)(如 to("cpu") 触发)在 aclnn 路径报 161001 且毒化进程,导致 test_single_reshape_copy_to_contiguous 类 4 个用例被 @unittest.skip 临时跳过。 2. 该问题的根因在 CANN 侧(aclnnNpuFormatCast 对 3D NC1HWC0 → NCHW 的支持性判定与执行不一致),**CANN 已在 9.2.0 修复**;torch_npu 侧无需 workaround。 3. 本 MR 仅恢复测试看护:解除 test/trans_contiguous/test_single_reshape_copy_to_contiguous.py 中 4 个用例的 @unittest.skip(view/unsqueeze/flatten/narrow,issue 4356)。 4. 头注释补充说明:设置 allow_internal_format = True 走真实内部格式路径时,3D NC1HWC0 在 aclnn 路径上的正确转换需要 CANN >= 9.2.0。 5. 相对 v2.7.1 合入版本的差异:额外删除了该测试文件中解除 skip 后不再使用的 import unittest。master 分支的 .lintrunner.toml 启用了 flake8 检查(发布分支中该项被注释),机器人同步 MR !46509 因 F401('unittest' imported but unused)CI 失败;本 MR 基于最新 master 重新提交并已修复该 lint 问题(本地 flake8 --config=.flake8 验证通过)。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 与 !45502(v2.7.1)验证结论一致,本 MR 为同一变更的分支同步: 1. 环境:910B2 / CANN 9.2.0 / torch_npu(v2.7.1 构建)。 2. 默认配置(allow_internal_format 保持注释,走 aclnn 降级路径):python test_single_reshape_copy_to_contiguous.py -v SingleViewCopyToContiguous,5 个用例全部通过。 3. 解开 torch.npu.config.allow_internal_format = True(CANN 9.2.0 修复生效后):整类用例通过,test_narrow_at_first_axis_copy 的 [fp16, NC1HWC0, [20,16,16]] item(原 161001 失败点)恢复正常。 4. 本 MR 不修改框架代码,无新增 UT;由恢复的 4 个用例看护原失败路径。 5. **Lint 自验证**:python -m flake8 --config=.flake8 test/trans_contiguous/test_single_reshape_copy_to_contiguous.py 通过(修复机器人 MR !46509 的 F401 失败项)。 See merge request: Ascend/pytorch!46545 | 24 天前 | |
[test]Add typedStorage_is{shared|pinned|hpu} API test case Co-authored-by: honorn<838107180@qq.com> # message auto-generated for no-merge-commit merge: !45162 merge TypedStorage_is_shared_pinned_hpu-master into master [test]Add typedStorage_is{shared|pinned|hpu} API test case Created-by: honorn Commit-by: honorn Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 [#3780](https://gitcode.com/Ascend/pytorch/issues/3780) [#3779](https://gitcode.com/Ascend/pytorch/issues/3779) [#3778](https://gitcode.com/Ascend/pytorch/issues/3778) - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 公开issue: - torch.TypedStorage.is_shared:[【社区任务】8月社区任务第一期-Ascend for PyTorch API 一致性开发(47)](https://gitcode.com/Ascend/pytorch/issues/3780) - torch.TypedStorage.is_pinned:[【社区任务】8月社区任务第一期-Ascend for PyTorch API 一致性开发(46)](https://gitcode.com/Ascend/pytorch/issues/3779) - torch.TypedStorage.is_hpu:[【社区任务】8月社区任务第一期-Ascend for PyTorch API 一致性开发(45)](https://gitcode.com/Ascend/pytorch/issues/3778) # 一. API 功能说明: - torch.TypedStorage.is_shared() :判断当前 Storage 是否位于共享内存中。 - torch.TypedStorage.is_pinned():判断一个 CPU Storage 是否为指定加速设备分配的页锁定内存,也叫 Pinned Memory。 - torch.TypedStorage.is_hpu():判断 Storage 是否位于 HPU 设备上。HPU 是 Habana Processing Unit,主要指 Intel Habana Gaudi 系列加速器。 | API | 接口性质 | 是否与设备相关 | torch-npu 测试建议 | |---|---|---|---| | torch.TypedStorage.is_shared | Python 包装接口,实际查询底层 UntypedStorage | 是,依赖底层存储及共享内存实现 | 建议补充 NPU 冒烟测试 | | torch.TypedStorage.is_pinned | Python 包装接口,实际查询设备的固定内存分配器 | 强相关 | 必须补充 NPU 用例 | | torch.TypedStorage.is_hpu | Python 属性,比较 device.type == "hpu" | 仅查询设备元数据 | 无需专门适配,但可补充 NPU 返回 False 的测试 | **注意** HPU 指 Habana Gaudi HPU PyTorch 2.7 中三者的实现分别是: python def is_shared(self): _warn_typed_storage_removal() return self._is_shared() def _is_shared(self): return self._untyped_storage.is_shared() def is_pinned(self, device="cuda"): _warn_typed_storage_removal() return self._untyped_storage.is_pinned(device) @property def is_hpu(self): _warn_typed_storage_removal() return self._untyped_storage.device.type == "hpu" 可以看到,is_shared() 和 is_pinned() 都会继续调用底层 UntypedStorage;is_hpu() 则是简单的 Python 设备类型判断。 # 二. 上游用例检查情况: | API | 上游检查结果 | NPU 覆盖缺口 | |---|---|---| | TypedStorage.is_shared() | test_storage_meta_errors 对 meta TypedStorage 断言 is_shared() == False | 没有覆盖 NPU | | TypedStorage.is_pinned() | 核心 test_torch.py 中未发现该方法的独立正反例;CUDA 测试包含 Tensor 层固定内存测试 | 没有检查 device="npu" 及 NPU pinned allocator | | TypedStorage.is_hpu | 核心 Storage 测试中未发现独立断言 | 没有验证 NPU Storage 必须返回 False | 因此需要补充这三个API的测试用例,这三个API可以直接放到一个完整的测试文件中进行测试。 # 三. 资料情况检查: - torch.TypedStorage.is_shared - torch.TypedStorage.is_pinned - torch.TypedStorage.is_hpu 这些API的资料补充在各个分支都存在,但是 torch.TypedStorage.is_shared 和torch.TypedStorage.is_pinned对A5芯片的支持程度描述有误,需要进行资料修改,torch.TypedStorage.is_hpu由于与hpu硬件相关,因此都不支持,资料补充正确无误,结果如下截图所示。    # 四. API功能性验证 测试核心代码 ```python class TestTypedStorageAPIs(TestCase): @staticmethod def _get_typed_storage(tensor): return tensor.storage() def test_typed_storage_is_shared_for_cpu(self): cpu_tensor = torch.arange( 8, dtype=torch.float32, device="cpu", ) expected_tensor = cpu_tensor.clone() cpu_storage = self._get_typed_storage(cpu_tensor) self.assertIsInstance( cpu_storage, torch.TypedStorage, ) self.assertEqual( cpu_storage.device.type, "cpu", ) # 场景1:普通CPU TypedStorage不在共享内存中 self.assertFalse(cpu_storage.is_shared()) self.assertEqual( cpu_storage.is_shared(), cpu_tensor.untyped_storage().is_shared(), ) # 场景2:CPU TypedStorage移动到共享内存 returned_storage = cpu_storage.share_memory_() self.assertIs( returned_storage, cpu_storage, ) self.assertTrue(cpu_storage.is_shared()) self.assertTrue(cpu_tensor.is_shared()) self.assertTrue( cpu_tensor.untyped_storage().is_shared() ) # share_memory_不能改变Storage中的数据 self.assertEqual( cpu_tensor, expected_tensor, ) def test_typed_storage_is_shared_for_tensor_view(self): base_tensor = torch.arange( 16, dtype=torch.float32, device="cpu", ) view_tensor = base_tensor[::2] base_storage = self._get_typed_storage( base_tensor ) view_storage = self._get_typed_storage( view_tensor ) # 场景3:Base Tensor和View共享同一底层Storage self.assertEqual( base_storage.data_ptr(), view_storage.data_ptr(), ) self.assertFalse(base_storage.is_shared()) self.assertFalse(view_storage.is_shared()) base_storage.share_memory_() self.assertTrue(base_storage.is_shared()) self.assertTrue(view_storage.is_shared()) self.assertTrue(base_tensor.is_shared()) self.assertTrue(view_tensor.is_shared()) self.assertEqual( base_storage.data_ptr(), view_storage.data_ptr(), ) def test_typed_storage_is_shared_for_npu(self): npu_tensor = torch.empty( 16, dtype=torch.float32, device="npu", ) npu_storage = self._get_typed_storage( npu_tensor ) self.assertEqual( npu_storage.device.type, "npu", ) is_shared_before = npu_storage.is_shared() data_ptr_before = npu_storage.data_ptr() nbytes_before = npu_storage.nbytes() self.assertIsInstance( is_shared_before, bool, ) self.assertEqual( is_shared_before, npu_tensor.untyped_storage().is_shared(), ) # 场景4:NPU/PrivateUse1 Storage不迁移到POSIX共享内存。 # # 不硬编码NPU is_shared()为True或False,是因为不同PyTorch # 版本可能调整非CPU设备的共享状态定义;TypedStorage必须 # 与底层UntypedStorage一致,并且share_memory_应为no-op。 returned_storage = npu_storage.share_memory_() is_shared_after = npu_storage.is_shared() self.assertIs( returned_storage, npu_storage, ) self.assertEqual( is_shared_after, is_shared_before, ) self.assertEqual( is_shared_after, npu_tensor.untyped_storage().is_shared(), ) self.assertEqual( npu_storage.data_ptr(), data_ptr_before, ) self.assertEqual( npu_storage.nbytes(), nbytes_before, ) def test_typed_storage_is_pinned_for_normal_storage(self): test_dtypes = [ torch.float16, torch.float32, torch.int32, torch.int64, ] # 场景5:普通CPU/NPU TypedStorage均不是NPU pinned memory for device in ["cpu", "npu"]: for dtype in test_dtypes: with self.subTest( device=device, dtype=dtype, ): tensor = torch.empty( 16, dtype=dtype, device=device, ) storage = self._get_typed_storage( tensor ) result_by_string = storage.is_pinned( device="npu" ) result_by_device = storage.is_pinned( device=torch.device("npu") ) untyped_result = ( tensor.untyped_storage().is_pinned( device="npu" ) ) self.assertIsInstance( result_by_string, bool, ) self.assertFalse(result_by_string) self.assertFalse(result_by_device) self.assertEqual( result_by_string, result_by_device, ) self.assertEqual( result_by_string, untyped_result, ) def test_typed_storage_is_pinned_for_pinned_cpu(self): test_dtypes = [ torch.float16, torch.float32, torch.int32, torch.int64, ] # 场景6:CPU TypedStorage转换为NPU pinned memory for dtype in test_dtypes: with self.subTest(dtype=dtype): source_tensor = torch.arange( 1, 9, dtype=dtype, device="cpu", ) source_storage = ( self._get_typed_storage( source_tensor ) ) source_values = ( source_storage.tolist() ) self.assertFalse( source_storage.is_pinned( device="npu" ) ) pinned_storage = ( source_storage.pin_memory( device="npu" ) ) self.assertIsInstance( pinned_storage, torch.TypedStorage, ) self.assertIsNot( pinned_storage, source_storage, ) self.assertEqual( pinned_storage.device.type, "cpu", ) See merge request: Ascend/pytorch!45162 | 4 天前 | |
refactor: correct English grammar, spelling, and style in log/warning messages Co-authored-by: wanglijun55<wanglijun54@huawei.com> # message auto-generated for no-merge-commit merge: !44119 merge master-doc into master refactor: correct English grammar, spelling, and style in log/warning messages Created-by: wanglijun55 Commit-by: wanglijun55 Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/3908 - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 # 【修改方案】 对 torch_npu 全仓 UserWarning / logger.warning / print 日志中的英文消息进行语法、拼写、标点审查和修复。共修复 48 处错误,涉及 39 个文件,涵盖以下类别: 1. **语法错误 (14处):** will not to be linked → will not be linked、should to be initialized → should be initialized、Create ... failed → Failed to create ... 等 2. **逗号拼接句 (8处):** 将逗号连接的两个独立句子拆分为两句或使用分号 3. **拼写错误 (1处):** Detecct_type → Detect_type 4. **缺少冠词 (7处):** in future version → in a future version、only sets Global variable → only sets the global variable 5. **主谓不一致 (5处):** Environment variable ... is not set → are not set、There is no ... events → There are no ... events 6. **标点/格式 (8处):** 中文顿号 、 → 英文逗号、多余空格、缺失句号、相邻字符串缺少空格拼接导致粘连 7. **翻译不当 (2处):** soft chain → symbolic link(软链接) 8. **冗余前缀 (2处):** warnings.warn() 中重复的 Warning: 前缀 9. **代码 Bug (1处):** serialization.py:672 — print() 传入 tuple 而非 string 10. **风格问题:** for replacement → as a replacement、Torchinductor → TorchInductor、Can not → Cannot、func/msg → function/message 等 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 仅修改日志/警告消息字符串,不影响任何功能逻辑。所有修改均为: - 英文语法/拼写/标点修正 - 字符串拼接 bug 修复(serialization.py tuple → string) - 翻译术语规范化(soft chain → symbolic link) # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44119 | 2 个月前 | |
[test] Add torch.untypedstorage{filename|hpu|nbytes|new} API test case Co-authored-by: gcw_CHjSLYhf<2839668818@qq.com> # message auto-generated for no-merge-commit merge: !45157 merge untypedstorage_filename_hpu_nbytes_new-master into master [test] Add torch.untypedstorage{filename|hpu|nbytes|new} API test case Created-by: gcw_CHjSLYhf Commit-by: gcw_CHjSLYhf Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/3739 https://gitcode.com/Ascend/pytorch/issues/3750 https://gitcode.com/Ascend/pytorch/issues/3760 https://gitcode.com/Ascend/pytorch/issues/3761 - [ ] 重构优化 - [ ] 资料更新 公开issue: - torch.UntypedStorage.filename:[8月社区任务第一期-Ascend for PyTorch API 一致性开发(78)](https://gitcode.com/Ascend/pytorch/issues/3739) - torch.UntypedStorage.hpu:[8月社区任务第一期-Ascend for PyTorch API 一致性开发(89)](https://gitcode.com/Ascend/pytorch/issues/3750) - torch.UntypedStorage.nbytes:[8月社区任务第一期-Ascend for PyTorch API 一致性开发(99)](https://gitcode.com/Ascend/pytorch/issues/3760) - torch.UntypedStorage.new: [8月社区任务第一期-Ascend for PyTorch API 一致性开发(100) ](https://gitcode.com/Ascend/pytorch/issues/3761) # 一. API 功能说明: ## 1. torch.UntypedStorage.filename filename 是torch.UntypedStorage这个类的一个只读属性,用于获取与当前 Storage 关联的内存映射文件路径。因此和平台设备有关联,需要增加一个快速的验证性测试。 PyTorch 2.7 中的实现为: python @property def filename(self): return self._get_filename() 因此它属于 Python 属性封装,但实际结果由底层 Storage 元数据接口 _get_filename() 提供。 ## 2. torch.UntypedStorage.hpu torch.UntypedStorage.hpu() 用于 返回一个在 HPU(Habana Gaudi 加速器)上的存储副本,如果该对象已在HPU内存中且位于正确的设备上,则不执行复制,直接返回原始对象。因为该API与HPU平台设备具有强绑定关系。 参数说明: - device:目标 HPU 设备编号,默认使用当前 HPU 设备; - non_blocking:如果源内存满足异步复制条件,则允许异步复制。 PyTorch 2.7 中的核心实现为: python def hpu(self, device=None, non_blocking=False): device2 = ( torch.device("hpu", device) if device else torch.device("hpu") ) return self.to( device=device2, non_blocking=non_blocking, ) ## 3. torch.UntypedStorage.nbytes torch.UntypedStorage.nbytes() 返回当前底层 Storage 实际占用的字节数,返回类型为 int。 但要注意,nbytes() 查询的是整个 Storage 的大小,而不是当前 Tensor View 的逻辑数据量。 例如: python base = torch.empty(16, dtype=torch.float32) view = base[::2] base.untyped_storage().nbytes() == 64 view.untyped_storage().nbytes() == 64 # view只有8个逻辑元素 view.numel() * view.element_size() == 32 这是因为 view 和 base 共享同一个底层 Storage。 接口本身主要读取底层 Storage 元数据,不执行计算算子,但它读取的是 NPU Storage 的实际字节范围,可以验证 NPU Tensor 到 UntypedStorage 的连接是否正确,因此需要增加 NPU 功能测试。 ## 4. torch.UntypedStorage.new torch.UntypedStorage.new在当前 Storage 所在设备上,创建一个新的、大小为 0 的 UntypedStorage。torch.UntypedStorage.new() 由底层 Storage 实现提供。NPU Storage 调用该接口时,需要正确处理 PrivateUse1/NPU 设备信息。因此需要补充这个API在torch-npu平台上的测试用例。 # 二. 上游用例检查情况: 检查 PyTorch 上游 Storage 相关测试后,结果如下: | API | 上游是否存在独立直接用例 | 检查结果 | |---|---:|---| | torch.UntypedStorage.filename | 未发现 | 上游核心test/test_torch.py中未发现直接读取.filename的独立用例 | | torch.UntypedStorage.hpu | 未发现 | 上游核心Storage测试中未发现直接调用.hpu()的独立用例 | | torch.UntypedStorage.nbytes | 存在部分覆盖 | 上游在Storage Meta测试中调用了s.nbytes()并比较不同Storage的字节数 | | torch.UntypedStorage.new | 存在部分覆盖 | 上游在Storage Meta测试中调用了s.nbytes()并比较不同Storage的字节数 | # 三. 资料情况检查: - torch.UntypedStorage.filename:在torch上游社区存在独立条目,同时在当前项目中该API资料已经存在,但是A5支持情况有误,因此需要进行资料修正。  - torch.UntypedStorage.hpu:在torch上游社区存在独立条目,同时在当前项目中该API资料已经存在,由于该API与hpu平台存在硬编码,系统支持情况,因此不需要进行资料补充和修正。  - torch.UntypedStorage.nbytes在torch上游社区存在独立条目,同时在当前项目中该API资料有误,因此需要进行资料修正。  - torch.UntypedStorage.new torch上游社区存在独立条目,同时在当前项目中该API资料有误,因此需要进行资料修正。  资料修正补充pr: https://gitcode.com/Ascend/pytorch/pull/46583 # 四. API功能性验证 ## 1. 测试场景 # torch.UntypedStorage API 功能性验证 ## 1. 测试场景 | 编号 | API | 测试场景 | 预期结果 | | --- | --- | --- | --- | | 1 | torch.UntypedStorage.filename | 获取普通 CPU Tensor 底层 Storage 的 filename | 普通 CPU Storage 未关联内存映射文件,返回 None | | 2 | torch.UntypedStorage.filename | 使用 from_file(shared=True) 创建共享文件映射 Storage | filename 返回字符串,并且规范化路径与映射文件路径一致 | | 3 | torch.UntypedStorage.filename | 使用 from_file(shared=False) 创建私有文件映射 Storage | 私有映射的 filename 返回 None | | 4 | torch.UntypedStorage.filename | 获取 NPU Tensor 底层 Storage 的 filename | Storage 位于 NPU,且未关联 CPU 文件映射,返回 None | | 5 | torch.UntypedStorage.hpu | 在纯 torch-npu 环境中调用默认参数 hpu() | 因未加载 HPU 设备模块,抛出包含 HPU device module is not loaded 的 AssertionError | | 6 | torch.UntypedStorage.hpu | 指定 device=1, non_blocking=True 调用 hpu() | 参数可以被接口正常解析;因未加载 HPU 模块,抛出预期 AssertionError | | 7 | torch.UntypedStorage.nbytes | 验证 float16 Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 numel × element_size | | 8 | torch.UntypedStorage.nbytes | 验证 float32 Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 numel × element_size | | 9 | torch.UntypedStorage.nbytes | 验证 int32 Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 numel × element_size | | 10 | torch.UntypedStorage.nbytes | 验证 int64 Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 numel × element_size | | 11 | torch.UntypedStorage.nbytes | 直接在 CPU/NPU 上构造指定字节数的 UntypedStorage | nbytes()、size() 和 len() 均返回构造时指定的字节数 | | 12 | torch.UntypedStorage.nbytes | 创建大小为 0 的空 NPU Storage | nbytes()、size() 和 len() 均返回 0 | | 13 | torch.UntypedStorage.nbytes | 获取非连续 NPU Tensor View 的底层 Storage 字节数 | View 与原 Tensor 共享底层 Storage,返回整个底层 Storage 的字节数 | | 14 | torch.UntypedStorage.new | 对 CPU Storage 调用 new() | 返回独立、大小为 0、设备类型仍为 CPU 的 UntypedStorage | | 15 | torch.UntypedStorage.new | 对 NPU Storage 调用 new() | 返回独立、大小为 0、设备类型仍为 NPU 的 UntypedStorage | | 16 | torch.UntypedStorage.new | 对 new() 返回的 Storage 执行 resize_() | 新 Storage 的大小发生变化,原 Storage 的大小不受影响 | | 17 | torch.UntypedStorage.new | 对共享文件映射 Storage 调用 new() | 返回普通空 CPU Storage,不继承原 Storage 的文件映射关系 | ## 2. 测试核心代码 ```python class TestUntypedStorageAPIs(TestCase): def test_untyped_storage_filename(self): # 场景1:普通CPU Storage不关联内存映射文件 cpu_storage = torch.empty( 8, dtype=torch.float32, device="cpu", ).untyped_storage() self.assertEqual(cpu_storage.device.type, "cpu") self.assertIsNone(cpu_storage.filename) # 场景2和3:共享文件映射与私有文件映射Storage with tempfile.TemporaryDirectory() as temp_dir: file_path = os.path.join( temp_dir, "untyped_storage.bin", ) shared_storage = torch.UntypedStorage.from_file( file_path, shared=True, nbytes=32, ) self.assertEqual(shared_storage.device.type, "cpu") self.assertEqual(shared_storage.nbytes(), 32) self.assertIsInstance( shared_storage.filename, str, ) self.assertEqual( os.path.realpath(shared_storage.filename), os.path.realpath(file_path), ) # 释放共享映射后再创建私有映射 del shared_storage private_storage = torch.UntypedStorage.from_file( file_path, shared=False, nbytes=32, ) self.assertEqual(private_storage.device.type, "cpu") self.assertEqual(private_storage.nbytes(), 32) self.assertIsNone(private_storage.filename) del private_storage # 场景4:NPU Storage不关联CPU内存映射文件 npu_storage = torch.empty( 8, dtype=torch.float32, device="npu", ).untyped_storage() self.assertEqual(npu_storage.device.type, "npu") self.assertIsNone(npu_storage.filename) def test_untyped_storage_hpu(self): npu_storage = torch.empty( 8, dtype=torch.float32, device="npu", ).untyped_storage() self.assertEqual( npu_storage.device.type, "npu", ) # 场景5:在torch-npu平台使用默认参数调用hpu() with self.assertRaisesRegex( AssertionError, r"HPU device module is not loaded", ): npu_storage.hpu() # 场景6:在torch-npu平台指定device和non_blocking参数 with self.assertRaisesRegex( AssertionError, r"HPU device module is not loaded", ): npu_storage.hpu( device=1, non_blocking=True, ) def test_untyped_storage_nbytes_for_tensor_dtypes(self): test_cases = [ (torch.float16, 6), (torch.float32, 6), (torch.int32, 6), (torch.int64, 6), ] # 场景7至10:不同dtype的CPU/NPU Storage字节数 for dtype, numel in test_cases: with self.subTest(dtype=dtype): cpu_tensor = torch.empty( numel, dtype=dtype, device="cpu", ) npu_tensor = torch.empty( numel, dtype=dtype, device="npu", ) cpu_storage = cpu_tensor.untyped_storage() npu_storage = npu_tensor.untyped_storage() expected_nbytes = ( numel * cpu_tensor.element_size() ) self.assertEqual( cpu_storage.nbytes(), expected_nbytes, ) self.assertEqual( npu_storage.nbytes(), expected_nbytes, ) self.assertEqual( cpu_storage.nbytes(), npu_storage.nbytes(), ) # UntypedStorage的长度单位也是字节 self.assertEqual( len(cpu_storage), expected_nbytes, ) self.a See merge request: Ascend/pytorch!45157 | 4 天前 | |
fix: cut patch_getenv overhead from 3x to ~1x and gate it by TORCH_NPU_LOGS Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com> # message auto-generated for no-merge-commit merge: !47484 merge personal/fix-patch-getenv-3x-overhead-master into master fix: cut patch_getenv overhead from 3x to ~1x and gate it by TORCH_NPU_LOGS Created-by: wuyouqi1 Commit-by: wuyouqi1 Merged-by: ascend-robot Description: # 【合入来源】> **如有社区issue,请关联issue链接**\ > **请勿携带内部流程信息(需求链接、问题单、内部issue等)** - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联issue:https://gitcode.com/Ascend/pytorch/issues/5090(Fixes #5090) # 【修改方案】 torch_npu/utils/patch_getenv.py 使全进程 os.getenv/os.environ.get 开销达 ~3.3x。根因:保存的原生 os.getenv 调用时重新解析 environ.get,再次进入被 patch 的实例属性(嵌套);且 key in os.environ 预检查本身即一次完整查找—— 一次调用共 3 次真实查找。 修复: 1. 两个 patch 点共用一个 _patched_getenv,直读 os.environ[key] (KeyError 即未命中):恰好 1 次真实查找,构造上无嵌套 2. 仅当日志可观测时安装:TORCH_NPU_LOGS/TORCH_LOGS 已设置,或 import 时 torch_npu.env logger 已可见 INFO。patch_getenv 早于 _add_logging_module() 配置 logger,import 时 isEnabledFor 不可信,故按 原始环境变量门控(与 ACL log 门禁做法一致);钩子为私有 _install(),不进入公开 API 兼容性检查 3. UT:test/utils/test_patch_getenv.py 6 用例(门控/包装语义/单次查找计数); test_torch_npu_init.py 快照断言按门控分支 # 【资料变更】 不涉及 # 【接口变更】 不涉及。os.getenv/os.environ.get 返回值行为完全不变(含 bytes key 抛 TypeError 对齐),仅日志按需安装;默认配置不安装(原生直通)。 # 【功能验证】 | 场景 | 真实查找/次 | 耗时(py3.14) | |---|---|---| | native | 1 | 597 ns (1.00x) | | 修复前 | 3 | 1974 ns (3.31x) | | 修复后(已安装) | 1 | 626 ns (1.05x) | | 修复后(默认不装) | 1 | 1.00x | (py3.11 修复前 3.39x;纯 CPython 复现,与硬件/CANN 无关) 语义回归(命中/未命中/default/空串/kwargs/bytes key)、门控矩阵(默认不装, TORCH_NPU_LOGS/TORCH_LOGS/预先配置 INFO 均安装)、端到端日志去重:全部 PASS。test_api_compatibility 复检通过(公开 callable 为空)。 本地 whl 实测(conda wyq_py10,torch_npu 2.7.1 whl):test_patch_getenv.py 6 用例全过;test_torch_npu_init.py 16 用例全过(test_14 按 #5230 skip)。 **test_14 临时 skip**:test_torch_npu_init.py::test_14_dtensor_strategies_are_ registered_without_dynamo 在 v2.7.1 HEAD 上确定性失败,与本 MR 无关—— !44496 的 flex_attention 补丁在 import 时经 from torch.nn.attention import flex_attention 拉入 torch._dynamo (torch 2.7.x),破坏 #2788 的延迟导入契约。详见 https://gitcode.com/Ascend/pytorch/issues/5230,待修复后恢复用例。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等(fix) - [x] PR持续集成流水线(CI)执行通过,代码检查无异常(个人分支暂未触发 CI,合入前补充) See merge request: Ascend/pytorch!47484 | 6 天前 | |
docs: 修复文档 markdownlint 扫描问题 Co-authored-by: Xinrui Chen<chenxinrui11@huawei.com> # message auto-generated for no-merge-commit merge: !45683 merge codex/fix-markdownlint-docs into master docs: 修复文档 markdownlint 扫描问题 Created-by: chenrayray Commit-by: Xinrui Chen Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单:#4529 - [ ] 重构优化 - [x] 资料更新 # 【修改方案】 1. 调整文档标题层级及标题前后的空行。 2. 为围栏代码块补充语言标识,并补齐代码块前后的空行。 3. 修复列表间距、标题末尾标点、多余空行及文件末尾换行问题。 4. 本次仅修改 Markdown 排版,不改变文档语义。 # 【资料变更】 涉及资料变更,修改以下文档: - test/README.md - tools/flight_recorder/flight_recorder.md - examples/libtorch_hccl/README_HCCL.md - torch_npu/csrc/libs/README.md - tools/linter/adapters/README.md # 【接口变更】 不涉及。 # 【功能验证】 1. 执行 git diff --check,检查通过。 2. 文档门禁中的 markdownlint、链接有效性、资源存在性及标签闭合检查均已通过。 3. 本次为纯文档格式修复,不涉及 UT 用例变更。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志(不涉及代码变更) - [x] 代码实现进行了返回值、空指针等校验(不涉及代码变更) - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!45683 | 1 个月前 | |
| 1 年前 | ||
| 1 年前 | ||
compat(2.14): default requirements to 2.14 nightly and fix related tests Co-authored-by: chz34<chenhaozhe1@huawei.com> # message auto-generated for no-merge-commit merge: !41741 merge compat/2.14 into master compat(2.14): default requirements to 2.14 nightly and fix related tests Created-by: c_34 Commit-by: chz34 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/2258 https://gitcode.com/Ascend/pytorch/issues/2890 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1. 上游新增接口,暴露的路径与实际module不一致,实际来自_C库,添加测试白名单,与上游添加的白名单保持一致。 2. 上游新增接口,依赖额外三方库与cuda库,test_public_binding.py中增加相关过滤 3. 上游 Backedn.register_backend.__func__新增参数,修改对应patch函数,增加**kwargs,缺省忽略,同时保持与之前版本的接口兼容 4. 上游cudagraphify调用时新增额外参数kernel_free_cudagraph, user_visible_output_idxs,下游npugraphify跟随新增,函数内不处理 5. 新增requirements_2_13.txt的配置,默认配置升级到2.14 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 跟随上游变更,不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 跟随上游变更,不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 跟随上游变更,基于现有测试用例进行验证 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!41741 | 2 个月前 | |
[fix] Init version in GetCANNVersion and delete unnecessary warning Co-authored-by: zhaoyu65<nanzhaogang@qq.com> # message auto-generated for no-merge-commit merge: !38128 merge master-warn into master [fix] Init version in GetCANNVersion and delete unnecessary warning Created-by: zhaoyu65 Commit-by: zhaoyu65 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 [#2346](https://gitcode.com/Ascend/pytorch/issues/2346) # 【修改方案】 * **核心变更:** * 🔧 修复了CANN版本获取函数中的错误处理逻辑,从特定错误码检查改为通用成功状态检查 * ✅ 增强了错误日志,新增错误码输出以便调试 * 🧹 简化了Python环境收集工具,移除了**路径所有者一致性检查** * 🛡️ 修复了C++结构体未初始化的潜在问题 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 验证OK 测试用例test\npu\test_cann_version.py已纳入门禁看护 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38128 | 3 个月前 | |
fix: lintrunner --all-files --take NEWLINE -a Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35539 merge code_check_lintrunner into master fix: lintrunner --all-files --take NEWLINE -a Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 文件必须以 LF 换行符结尾,不允许 CRLF(DOS 换行),执行: lintrunner --all-files --take NEWLINE -a # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35539 | 4 个月前 | |
| 2 年前 | ||
fix: 补充requirements依赖声明,拆分构建期与运行期依赖 Co-authored-by: mhy<mahongyu7@huawei.com> # message auto-generated for no-merge-commit merge: !45566 merge deps/requirements-restructure into master fix: 补充requirements依赖声明,拆分构建期与运行期依赖 Created-by: m0_64341872 Commit-by: mhy Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1. 新建 requirements-build.txt,拆出构建期工具依赖(pyyaml、setuptools),三个版本变体共用一份,因为这两个包不随 torch 版本变化 2. requirements.txt / requirements_2.13.txt / requirements_2.15.txt 开头通过 -r requirements-build.txt 引用上述文件;同时补充声明 numpy、sympy、typing-extensions 三个依赖——这三个包在 contrib/、profiler/、_inductor/ 中被无条件 import,但此前在任何依赖文件中均未声明 3. setup.py 的 install_requires 同步补充上述三个依赖,确保 pip install 生成的 wheel 依赖清单完整(这是唯一真正被 pip 强制执行、随 wheel 发布给用户的清单) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!45566 | 27 天前 | |
fix: 补充requirements依赖声明,拆分构建期与运行期依赖 Co-authored-by: mhy<mahongyu7@huawei.com> # message auto-generated for no-merge-commit merge: !45566 merge deps/requirements-restructure into master fix: 补充requirements依赖声明,拆分构建期与运行期依赖 Created-by: m0_64341872 Commit-by: mhy Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1. 新建 requirements-build.txt,拆出构建期工具依赖(pyyaml、setuptools),三个版本变体共用一份,因为这两个包不随 torch 版本变化 2. requirements.txt / requirements_2.13.txt / requirements_2.15.txt 开头通过 -r requirements-build.txt 引用上述文件;同时补充声明 numpy、sympy、typing-extensions 三个依赖——这三个包在 contrib/、profiler/、_inductor/ 中被无条件 import,但此前在任何依赖文件中均未声明 3. setup.py 的 install_requires 同步补充上述三个依赖,确保 pip install 生成的 wheel 依赖清单完整(这是唯一真正被 pip 强制执行、随 wheel 发布给用户的清单) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!45566 | 27 天前 | |
fix: 补充requirements依赖声明,拆分构建期与运行期依赖 Co-authored-by: mhy<mahongyu7@huawei.com> # message auto-generated for no-merge-commit merge: !45566 merge deps/requirements-restructure into master fix: 补充requirements依赖声明,拆分构建期与运行期依赖 Created-by: m0_64341872 Commit-by: mhy Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1. 新建 requirements-build.txt,拆出构建期工具依赖(pyyaml、setuptools),三个版本变体共用一份,因为这两个包不随 torch 版本变化 2. requirements.txt / requirements_2.13.txt / requirements_2.15.txt 开头通过 -r requirements-build.txt 引用上述文件;同时补充声明 numpy、sympy、typing-extensions 三个依赖——这三个包在 contrib/、profiler/、_inductor/ 中被无条件 import,但此前在任何依赖文件中均未声明 3. setup.py 的 install_requires 同步补充上述三个依赖,确保 pip install 生成的 wheel 依赖清单完整(这是唯一真正被 pip 强制执行、随 wheel 发布给用户的清单) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!45566 | 27 天前 | |
| 2 年前 | ||
| 1 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 4 个月前 | |
[fix] fix bug mix_acc_npu_stream Co-authored-by: xuyun15<xuyun15@huawei.com> # message auto-generated for no-merge-commit merge: !46235 merge fix_mix_acc_npu_stream_master into master [fix] fix bug mix_acc_npu_stream Created-by: xuyun15 Commit-by: xuyun15 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 根因 torch.stream使用基类,无npu_stream,下游对齐的时候需要小心。当前npu未对齐社区,造成风险。 对齐社区 stream->npu_stream ---->> c10::Stream::unpack3 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!46235 | 15 天前 | |
test: add NPU tests for torch._higher_order_ops.auto_functionalized Co-authored-by: gcw_fiAo4tDr<iqueenqueen@163.com> # message auto-generated for no-merge-commit merge: !45073 merge test-auto-functionalized-master into master test: add NPU tests for torch._higher_order_ops.auto_functionalized Created-by: gcw_fiAo4tDr Commit-by: gcw_fiAo4tDr Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 关联任务:[#2701 【社区任务】7月社区任务第一期-Ascend for PyTorch API 一致性开发(78)](https://gitcode.com/Ascend/pytorch/issues/2701) - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 一、API 功能 text torch._higher_order_ops.auto_functionalized(_mutable_op, **kwargs) 用于把带可变参数的自定义算子转换为函数式调用,核心能力如下: 调用签名 torch._higher_order_ops.auto_functionalized(_mutable_op, **kwargs) 参数说明 _mutable_op(torch._ops.OpOverload,必选):需要进行函数式转换的可变自定义算子重载。该算子的 schema 必须包含至少一个带写别名的可变参数;当前支持的可变参数类型为 Tensor、Tensor? 和 Tensor[]。 **kwargs(Any,必选项由 _mutable_op 的 schema 动态决定):传给 _mutable_op 的实际参数,键名、类型、默认值以及哪些参数可变均由 _mutable_op 的 schema 定义。例如 schema 为 mutate_and_sum(Tensor(a!) mutable, Tensor increment) -> Tensor 时,应传入 mutable=<Tensor> 和 increment=<Tensor>。 返回值说明 返回扁平 tuple:先放置 _mutable_op 的原始输出,再按 schema 参数顺序追加所有更新后的可变参数克隆。若原算子无返回值,首项为 None;若原算子有多个输出,则多个输出依次位于更新后的可变参数之前。 内部参数说明 源码执行实现中的 _only_clone_these_tensors 是内部派发优化参数,不属于调用者需要提供的 API 参数。 1. 可变参数识别 根据自定义算子的 schema 和 alias information,识别带写别名的 Tensor、Tensor? 和 Tensor[] 参数。 2. 函数式克隆 在执行算子前克隆可变参数,并让算子只修改克隆,保证调用者传入的原始张量不被原地修改。 3. 结果组织 先返回原算子的输出,再按 schema 中可变参数的顺序返回更新后的克隆;无原始输出的算子以 None 作为首个返回值。 4. 设备和存储语义 克隆及算子输出应保持输入所在设备,同时更新后的克隆应与原输入具有独立存储。 5. 错误边界 传入没有可变参数的算子不符合该高阶算子的使用前提,应触发断言异常。 二、测试文件 test_auto_functionalized.py 完整验证该 API 的原因 text 该测试文件从导出路径、核心功能、参数类型、返回协议、设备/存储语义和异常边界六个维度验证 torch._higher_order_ops.auto_functionalized: 1. 导出路径验证 test_reexported_object_is_identical:验证 torch._higher_order_ops.auto_functionalized 与实现模块中的 auto_functionalized 为同一对象,确保任务指定导出路径正确。 2. 单个可变 Tensor 核心功能 test_mutable_tensor_is_cloned_and_returned_on_device:验证原输入不变、克隆被正确更新、算子输出正确、输出和克隆保持 NPU 设备,并通过 data_ptr 验证克隆与原输入存储独立。 3. 可变 Tensor[] 分支 test_mutable_tensor_list_is_cloned_on_device:同时覆盖空列表与非空列表,验证列表元素逐一克隆、逐一更新、保持设备且不污染源列表。 4. 多输出与多可变参数 test_multiple_outputs_precede_mutable_tensors:验证两个算子输出位于两个更新后可变参数之前,并验证每个参数各自执行正确的原地语义。 5. 可变 Tensor? 分支 test_optional_mutable_tensor_supports_none_and_tensor:覆盖 None 与非空张量,验证可选可变参数的两条核心路径。 6. 非法使用边界 test_non_mutating_operator_is_rejected:验证无可变参数算子触发 AssertionError,明确 API 使用边界。 7. 社区覆盖补充 PyTorch 的 test/inductor/test_auto_functionalize.py 主要覆盖内部 functionalization/Inductor 路径并使用 CPU-only 自定义算子;本文件直接调用任务指定导出对象,并补充真实 NPU 的设备保持和克隆存储独立性验证。 综上,该文件覆盖正常场景、空值/空列表边界、多参数多输出、异常路径以及真实 NPU 语义,可完整看护本 API 的关键行为。 三、NPU适配 text 1. 真实 NPU 张量 测试通过 torch.accelerator.current_accelerator() 获取当前加速器类型,并用该设备创建所有参与计算的 Tensor;NPU 环境下 DEVICE_TYPE 为 npu。 2. NPU 算子执行 测试自定义算子注册为 CompositeExplicitAutograd,实现中的 add_、mul_、sum 等张量运算由 torch_npu 注册的 NPU 后端执行,更新结果及算子输出均保留在 npu:0。 3. 设备与存储断言 用例显式断言结果和更新后克隆的 device.type,并使用 data_ptr 验证克隆与 NPU 原输入存储独立,防止只验证数值而遗漏设备语义。 4. 防止 CPU 回退 上板运行器显式导入 torch_npu,要求 torch.npu.is_available() 为 True,并先创建 device='npu' 的冒烟张量、断言其设备为 npu:0,再执行原测试文件;CPU fallback 无法得到所附成功日志。 5. Triton-Ascend 依赖 本用例直接验证 eager 高阶算子和基础 NPU 张量操作,不进入 torch.compile/Inductor/Triton 代码生成路径,因此不需要安装 Triton-Ascend。 # 【资料变更】 > > 不涉及 已检查 [master 分支 docs/zh/api/native_api](https://gitcode.com/Ascend/pytorch/tree/master/docs/zh/api/native_api)。torch._higher_order_ops.auto_functionalized 位于带下划线的 PyTorch 私有接口命名空间,没有对应公开资料条目;按 API 一致性任务书,PyTorch 私有接口无需补资料,因此不提交资料 PR。 # 【接口变更】 > 不涉及 API 已存在,本 PR 只新增 test/test_auto_functionalized.py,不修改接口实现、schema 或对外行为。 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤 > > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 测试场景:在 Ascend 910B2 上注册包含 Tensor、Tensor[]、Tensor?、多个可变参数和多个返回值的自定义算子,直接调用 torch._higher_order_ops.auto_functionalized,验证正常、边界和异常场景。 测试方法:使用独立虚拟环境,先完成 NPU 可用性及 npu:0 冒烟检查,再执行新增测试文件。上传文件与本地文件 SHA-256 均为 53e99c73593ff5932420270cec9b663d15fdbab32eb4891f7029dec0ad8e7678。 目标分支:master 源分支:gcw_fiAo4tDr/pytorch:test-auto-functionalized-master 已验证提交:61f2b43ebc1af1100d1624c8ff19900be6946f26 验证环境:aarch64、Ascend 910B2(Health OK)、Driver/npu-smi 25.5.2、CANN 9.1.0、Python 3.12.13。master 使用 torch==2.14.0.dev20260719+cpu,并从上述提交源码构建安装 torch_npu==2.14.0+git61f2b43。 执行结果如下: text Virtual environment: /workspace/venvs/master torch: 2.14.0.dev20260719+cpu torch_npu: 2.14.0+git61f2b43 accelerator: npu npu_available: True npu_name: Ascend910B2 smoke_device: npu:0 ...... ---------------------------------------------------------------------- Ran 6 tests in 1.008s OK  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!45073 | 1 个月前 | |
[sync] PR-38602: 新增torch_npu.npu.are_compatible_impl_enabled和torch_npu.npu.get_amp_supported_dtype接口的测试用例。 Co-authored-by: yuanqi1104<yuanqi13@huawei.com> # message auto-generated for no-merge-commit merge: !38860 merge sync-pr38602-yuanqi_add_torch_npu_testcases-to-master into master [sync] PR-38602: 新增torch_npu.npu.are_compatible_impl_enabled和torch_npu.npu.get_amp_supported_dtype接口的测试用例。 Created-by: yuanqi1104 Commit-by: yuanqi1104 Merged-by: ascend-robot Description: 本PR为对 https://gitcode.com/Ascend/pytorch/pull/38733 的补充 ### 1. Origin pull request: https://gitcode.com/Ascend/pytorch/merge_requests/38602 ### 2. Original pull request related issue(s): https://gitcode.com/Ascend/pytorch/issues/2402 ### 3. Original pull request related commit(s): | Sha | Datetime | Message | |---|---|---| |[3481c54f](https://gitcode.com/Ascend/pytorch/commit/3481c54f3cd388fe46ae989e0dcaaf21a8844c0c)|2026-06-16 20:01:41 +0800 CST|Add test case fot torch_npu<br>| See merge request: Ascend/pytorch!38860 | 3 个月前 | |
fix test_autograd to avoid calling policy_fn during recompute Co-authored-by: SCh_zx<1325467101@qq.com> # message auto-generated for no-merge-commit merge: !43452 merge master into master fix test_autograd to avoid calling policy_fn during recompute Created-by: SCh_zx Commit-by: SCh_zx Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 原生社区中针对索引有所修改,修改用例以适配: https://github.com/pytorch/pytorch/pull/176455 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43452 | 2 个月前 | |
fix: restore TORCH_DEVICE_BACKEND_AUTOLOAD when import torch_npu Co-authored-by: 21xiu<caixiuxiu1@huawei.com> # message auto-generated for no-merge-commit merge: !47027 merge init_0924 into master fix: restore TORCH_DEVICE_BACKEND_AUTOLOAD when import torch_npu Created-by: xiu_21 Commit-by: 21xiu Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 ## 【问题描述】 torch_npu 在 import torch 之前会临时将 TORCH_DEVICE_BACKEND_AUTOLOAD 置为 "0",防止 torch 初始化末尾 autoload 反向导入尚未初始化完成的 torch_npu(循环导入)。原实现中,恢复该环境变量的动作完全依赖 torch 的 autoload 机制调用 torch_npu:_autoload entrypoint。 当用户代码 import torch_npu 早于 import torch 时: 1. torch_npu 将变量置 "0",随后触发 import torch 2. torch 初始化末尾读到 "0",跳过 _import_device_backends()(torch/__init__.py 末尾 if _is_device_backend_autoload_enabled():) 3. torch_npu:_autoload entrypoint 永远不会被调用,恢复逻辑失效 4. 后续 import torch 仅为 sys.modules 缓存命中,不再执行任何恢复逻辑 结果:临时值 "0" 泄漏整个进程生命周期;所有子进程(spawn/fork、DataLoader worker、torch.compile worker、torchrun 拉起的新进程)继承 "0",子进程中 import torch 不再自动加载 npu backend,导致设备不可用等隐蔽故障。 ## 【修改方案】 核心依据:该环境变量在每个进程内仅在 torch __init__ 末尾被消费一次,之后对当前进程无任何作用,仅影响子进程继承。因此在 torch_npu 初始化完成后、进程内不再有消费点的任意时刻恢复,均不影响当前进程行为,仅修正子进程继承。 修改内容(torch_npu/__init__.py): 1. 在文件末尾(_initialize() 之后、_autoload 函数定义之后)显式调用一次 _autoload(),将变量恢复为 import 前的原始值(ORG_AUTOLOAD 已在文件头部保存)。 2. _autoload() 函数本身保持不动,仍作为 torch.backends entrypoint,覆盖 torch 先导入场景(autoload 路径)下的恢复;两处调用幂等,写入同一个值。 3. 临时 "0" 的存活窗口覆盖 torch_npu 整个初始化期;由于该变量在进程内仅在 torch __init__ 末尾被消费一次,_initialize() 期间无人读取,该窗口内不会产生副作用。 涉及的组件交互: - torch_npu/__init__.py(本仓):末尾显式调用 _autoload() 恢复环境变量 - torch/__init__.py(上游,不修改):_is_device_backend_autoload_enabled() / _import_device_backends() 读取该变量决定是否 autoload,本修改与其交互关系不变,仅保证变量在交互完成后不再泄漏 - 子进程(spawn/fork/DataLoader worker 等):由继承泄漏的 "0" 变为继承原始值,子进程 import torch 时 npu backend 自动加载恢复正常 ## 【资料变更】 不涉及。 ## 【接口变更】 不涉及。本次修改为进程内部环境变量生命周期修复: - 不改变任何 Python API / C++ API 的签名、语义 - 不改变 TORCH_DEVICE_BACKEND_AUTOLOAD 对外的语义(默认启用 autoload,用户显式设置仍被完整尊重并传递给子进程) - 唯一可观察差异为修复的预期行为本身:torch_npu 先导入时环境变量不再泄漏为 "0" ## 【功能验证】 已在仓库新增 UT 看护用例:test/test_autoload.py 中新增 AutoloadEnvVarTest 测试类(原有 AutoloadTest 保持不动),看护本次修复涉及的环境变量行为。 测试方法:由于 sys.modules 缓存的存在,导入顺序与起始环境变量只能在全新解释器中各验证一次,因此每个场景通过 subprocess 以全新解释器(临时脚本文件)执行受控的导入序列;该解释器再通过 multiprocessing(spawn/fork 两种 context)拉起两类子进程探针:环境探针(不导入 torch,仅回读继承的环境变量,隔离环境继承与 autoload 行为)与导入探针(校验子进程内 torch_npu 加载状态及重复导入安全性)。默认场景显式从子进程环境中剥离该变量以保证"默认情况"真实成立,显式设置场景在子进程启动前注入 0/1。临时脚本目录的创建与删除通过 contextmanager 的 try/finally 收敛在同一作用域内成对完成,确保测试异常退出时亦及时清理(满足 G.FIO.04 临时文件及时删除要求)。 覆盖场景(每个测试方法以 subTest 罗列四种导入顺序:仅 import torch / 仅 import torch_npu / 先 torch 后 torch_npu / 先 torch_npu 后 torch,每种顺序校验 6 项探针输出——主进程 2 项:环境变量、torch_npu 加载状态;mp 子进程 4 项:spawn/fork 各自的环境继承与导入行为): 1. 主进程环境变量:默认环境四种导入顺序均为 '1'——含原 bug 场景(torch_npu 先导入)不再泄漏 '0';显式设 0/1 时均保持用户设置不被覆盖 —— PASS 2. autoload 生效性:仅 import torch 时,默认环境/显式 '1' 下 torch_npu 被自动加载,显式 '0' 下不加载 —— PASS 3. 子进程环境继承:mp spawn/fork 子进程继承的环境变量与主进程一致(默认 '1',用户设置 '0'/'1' 时为设置值)—— PASS 4. spawn 子进程(全新解释器)导入行为:继承环境为 '1' 时 import torch 经 autoload 加载 torch_npu,后续显式 import torch_npu 为纯缓存命中(含模块对象身份校验),无重复初始化、无报错;继承 '0' 时不 autoload —— PASS 5. fork 子进程导入行为:torch_npu 加载状态与主进程一致(import 前后均与主进程相同,即继承 sys.modules、不重跑初始化),无报错 —— PASS 自验证结果:python test/test_autoload.py AutoloadEnvVarTest,3 个测试方法(共 12 种导入顺序场景)全部通过。  性能验证:新增仅为一次函数调用与单次 os.environ 赋值(实测约 2.2 µs),占 import torch_npu 总耗时(实测约 4 s)的 0.00004%,无感知。 影响面确认:该变量全环境仅 torch __init__ 末尾一处消费;运行时设备操作、同进程重复导入等场景行为零变化;混合加速器环境下 spawn 子进程会按默认行为 autoload,若存在真实设备冲突将由 _check_device_conflict 在子进程报错,属设计内保护,用户可显式 TORCH_DEVICE_BACKEND_AUTOLOAD=0 规避。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!47027 | 20 天前 | |
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 4 个月前 | |
【API一致性任务】test: add consistency validation cases for torch.BoolStorage / torch_npu.npu.BoolStorage (#2955) Co-authored-by: luoxiaoyan2024<luoxiaoyan202516@gmail.com> # message auto-generated for no-merge-commit merge: !42263 merge devin/api-2955-master into master 【API一致性任务】test: add consistency validation cases for torch.BoolStorage / torch_npu.npu.BoolStorage (#2955) Created-by: luoxiaoyan2024 Commit-by: luoxiaoyan2024 Merged-by: ascend-robot Description: # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue:https://gitcode.com/Ascend/pytorch/issues/2955 # 【修改方案】 一、API 功能说明 torch.BoolStorage 是 PyTorch 的布尔类型存储类(TypedStorage 子类),核心功能如下: - 承载布尔型张量的底层存储:以 torch.bool 为元素类型,提供按索引读写、填充、转为张量等存储语义。 - 配套 NPU 类型:torch_npu.npu.BoolStorage 是昇腾 NPU 上的布尔存储类,用于 NPU 张量的底层存储;NPU 布尔张量的 .storage() 即返回该类型实例。 - 标准 storage 类:与 torch.IntStorage / torch.FloatStorage 等同族,是 PyTorch 原生 API,非 torch_npu 私有扩展。 二、测试文件 test_bool_storage.py 完整验证该 API 的原因 该用例针对 torch.BoolStorage 与 torch_npu.npu.BoolStorage 两类存储类,从构造、索引、填充、类型/大小、设备一致性四个维度全覆盖验证,具体如下: 1. 对 CPU 类 torch.BoolStorage 的验证(test_cpu_bool_storage_basic / _from_sequence / _empty / _out_of_bounds) - 构造与索引:以 torch.BoolStorage(3) 构造并逐个 setitem/getitem,确认 tolist() 与预期一致、与社区行为一致。 - 元信息:size()==3、element_size()==1(与 torch.BoolStorage().element_size() 上游预期一致)。 - 填充与往返:fill_(False) 后 tolist() 全 False,并经 torch.BoolTensor(s) 往返确认 dtype==torch.bool、值一致。 2. 对 NPU 类 torch_npu.npu.BoolStorage 的验证(test_npu_bool_storage_basic / _from_sequence / _empty / _out_of_bounds / test_npu_tensor_storage_consistency) - 存在性:断言 torch_npu.npu.BoolStorage 在 NPU 上已注册。 - 构造与索引:以 torch_npu.npu.BoolStorage(4) 构造并索引,确认 tolist() / dtype==torch.bool / element_size()==1 / size()==4。 - 填充:fill_(True) 后 tolist() 全 True。 - 设备一致性:构造一个 NPU 布尔张量并断言其 .storage() 是 torch_npu.npu.BoolStorage 实例、dtype==torch.bool、tolist() 与张量一致。 3. 边界与语义 - 本用例不尝试用 NPU storage 构造 CPU 张量(现代 PyTorch 设备语义禁止,属预期),仅对 NPU storage 直接操作或经 NPU 张量 .storage() 取,符合规范。 综上,该文件覆盖了 BoolStorage 存储类在 NPU 上的「正常场景 + 索引边界 + 元信息 + 设备一致性」,是对该存储类在 NPU 上行为的完整且严谨的验证。 三、NPU 适配 torch.BoolStorage 与 torch_npu.npu.BoolStorage 适配昇腾 NPU 时无需修改 API 本身,具体分析: 1. 标准 storage 类,逻辑与硬件解耦 - element_size()、tolist()、fill_()、索引等均为通用存储语义,无论 CPU/GPU/NPU 调用结果一致,无设备特化分支。 2. 配套 NPU 类型已具备 - torch_npu.npu.BoolStorage 已在 torch_npu 中注册,NPU 布尔张量的存储即其实例,无需新增绑定。 3. 本用例仅做一致性看护 - 用例不改写任何全局状态,仅验证存储类行为在 NPU 上与社区一致,可直接复用。 # 【资料变更】 > 不涉及 已检查文档 [https://gitcode.com/Ascend/pytorch/tree/master/docs/zh/native_apis](https://gitcode.com/Ascend/pytorch/tree/v2.7.1/docs/zh/native_apis),torch.BoolStorage 为标准 storage 类、非私有接口、非缺失 API,依据 API 一致性说明文档 §2 不纳入 native_apis 资料补齐范围,故不需要提交 PR 修改资料。 # 【接口变更】 > 不涉及 # 【功能验证】 > 说明测试场景、测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤 > 新增/变更内容是否已新增/适配 UT 测试用例看护 在 Ascend 910B NPU 环境、torch 2.7.1 / 2.11.0 / 2.12.0 / master(nightly)+ 对应 torch_npu 上执行该用例,均通过。代表性日志(2.7.1 与 2.12.0)如下: # torch 2.7.1 / torch_npu 2.7.1 (Ascend 910B) python test/test_bool_storage.py -v Ran 9 tests in 1.2s OK # torch 2.12.0 / torch_npu 2.12.0.rc1 (Ascend 910B) python test/test_bool_storage.py -v Ran 9 tests in 1.2s OK 其余 2 个版本(2.11.0 / master)执行结果一致,均输出 Ran 9 tests ... OK。 用例共包含 9 个测试方法:CPU 侧 test_cpu_bool_storage_basic / test_cpu_bool_storage_from_sequence / test_cpu_bool_storage_empty / test_cpu_bool_storage_out_of_bounds;NPU 侧 test_npu_bool_storage_basic / test_npu_bool_storage_from_sequence / test_npu_bool_storage_empty / test_npu_bool_storage_out_of_bounds / test_npu_tensor_storage_consistency。 # 【CheckList】 > PR 提交人对以下 CheckList 自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR 标题正确使用类型标签,如:feat、fix、refactor、docs、test 等 - [x] PR 持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42263 | 2 个月前 | |
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33714 merge master into master add_test Created-by: sunhaolun Commit-by: sunhaolun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为以下API增加用例功能 Tensor.copy_ Tensor.narrow torch.cat torch.chunk torch._chunk_cat # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增文件 test_cat.py test_chunk.py test_chunk_cat.py test_copy_.py test_narrow.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33714 | 5 个月前 | |
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33714 merge master into master add_test Created-by: sunhaolun Commit-by: sunhaolun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为以下API增加用例功能 Tensor.copy_ Tensor.narrow torch.cat torch.chunk torch._chunk_cat # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增文件 test_cat.py test_chunk.py test_chunk_cat.py test_copy_.py test_narrow.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33714 | 5 个月前 | |
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33714 merge master into master add_test Created-by: sunhaolun Commit-by: sunhaolun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为以下API增加用例功能 Tensor.copy_ Tensor.narrow torch.cat torch.chunk torch._chunk_cat # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增文件 test_cat.py test_chunk.py test_chunk_cat.py test_copy_.py test_narrow.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33714 | 5 个月前 | |
Refactor compat impl for strong validation instead of comment Co-authored-by: li_jing_hw<lijing202@huawei.com> # message auto-generated for no-merge-commit merge: !46750 merge master into master Refactor compat impl for strong validation instead of comment Created-by: li_jing_hw Commit-by: li_jing_hw Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 重构优化https://gitcode.com/Ascend/pytorch/issues/4978 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!46750 | 5 天前 | |
Align NPU mixed-dtype async host-device copy behavior with CUDA Co-authored-by: zzhongmin<zhongmin23@huawei.com> # message auto-generated for no-merge-commit merge: !39573 merge master_d2h into master Align NPU mixed-dtype async host-device copy behavior with CUDA Created-by: zzhongmin Commit-by: zzhongmin Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 对齐 CUDA Copy.cu 的 mixed-dtype 异步 Host/Device 拷贝策略,调整 NPU OpApi 路径。 当 non_blocking=True 且 Host/Device dtype 不一致时,将可由 aclnnCast 支持的 dtype 转换前移到 NPU Device 侧完成,避免因 CPU 侧 dtype cast 产生非 pinned 临时 Tensor,导致 H2D/D2H 退化为同步拷贝。non_blocking=False 与同 dtype fast path 保持原有逻辑。 - torch_npu/csrc/aten/ops/op_api/CopyKernelOpApi.cpp - H2D:先申请源 dtype 的 NPU temporary,将 pinned/已注册 CPU 数据按源 dtype 执行同 dtype H2D 拷贝,再通过 aclnnCast 转为目标 dtype 并写回目标 Tensor。 - D2H:先在 NPU 侧通过 custom_ops::_npu_dtype_cast 转为目标 dtype,再执行同 dtype D2H 拷贝到 CPU 目标。 - D2H cast 前补充 NpuUtils::check_match(&src) 判断;当 NPU 源 Tensor 是非连续 view 或 metadata 不满足 OpApi 要求时,先通过 NpuUtils::format_contiguous(src) 规范化输入,避免 aclnnCast 直接处理不匹配的 view。 - 新增 cast_dtype_out_baseformat_opapi,封装 aclnnCast out 路径,用于 H2D mixed-dtype async 路径中将 NPU temporary 转换并写入目标 Tensor。 - 新增 should_fallback_to_cpu_cast:在 A2 及之后产品上,对 aclnnCast 不支持的 dtype 组合保留原 CPU cast 路径,避免 unsupported dtype 走设备侧 cast 失败。 2. 补充 Tensor.copy_ mixed-dtype 功能、异步行为与 fallback 测试。 - test/test_copy_.py - 覆盖 pinned CPU → NPU、NPU → pinned CPU 的 mixed-dtype copy_(non_blocking=True)。 - 覆盖 int32 -> float32、int64 -> float32、float16 -> float32、float32 -> float16、complex64 <-> complex128 等基础转换组合。 - 扩展同步/异步结果一致性用例,覆盖 bool、int8、int16、uint16、int64、float16、bfloat16、float32、complex dtype,并包含负数、边界值、小数和复数数据。 - 通过 gate_stream 上的矩阵乘任务阻塞 copy_stream,再使用 done_event.query() 验证 copy_ 返回时没有同步等待异步拷贝完成。 - 补充非连续 NPU 目标、非连续 CPU pinned 目标、非连续 NPU 源、broadcast 源、带 storage offset 的 pinned CPU slice,以及连续 mixed-dtype 异步拷贝下 temporary 生命周期测试。 - 非连续 NPU 源用例覆盖 D2H mixed-dtype 场景,验证 _npu_dtype_cast 前的 format_contiguous 保护逻辑。 - 补充 float8_e5m2、float8_e4m3fn、complex32 等 aclnnCast unsupported dtype 的 CPU cast fallback 正确性测试。 - 保留 non_blocking=False 的 H2D/D2H mixed-dtype 结果正确性回归测试。 - mixed-dtype 相关用例限定在 Ascend910B、Ascend910_93、Ascend950 上执行。 3. 补充 Tensor.to mixed-dtype 跨设备测试。 - test/npu/test_npu.py - 新增 test_to_non_blocking_different_dtype,覆盖 CPU ↔ NPU、non_blocking=True/False 的跨设备 dtype 转换。 - 验证 int32 -> float32 转换结果正确性。 - 验证 D2H 且 non_blocking=True 时输出 Tensor 保持 pinned-memory 属性。 - 用例限定在 Ascend910B、Ascend910_93、Ascend950 上执行。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!39573 | 3 个月前 | |
update test_dataloader.py Co-authored-by: SCh-zx<1325467101@qq.com> # message auto-generated for no-merge-commit merge: !44348 merge master into master update test_dataloader.py Created-by: SCh_zx Commit-by: SCh-zx Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44348 | 2 个月前 | |
| 2 年前 | ||
fix lazy_fusion dump and enable Co-authored-by: hb_hubin<hubin79@huawei.com> # message auto-generated for no-merge-commit merge: !47177 merge dvm-master-latest into master fix lazy_fusion dump and enable Created-by: hbhu_bin Commit-by: hb_hubin Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> https://gitcode.com/Ascend/pytorch/issues/2264 # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [x] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 无图融合问题修复 ### 1. 缺少脚本侧的融合范围控制 TORCH_NPU_LAZY_FUSION 控制进程级融合行为,用户无法方便地将局部代码排除在融合范围之外。 ### 2. dump 缺少灵活的区间控制 全程 dump 文件量较大,不便于只采集某个 step 或代码区间。 ### 3. output 分配可能重入 flush 融合算子已构建 DVM 节点、但尚未分配和登记 output 时,内存分配可能触发回收或重试,并通过同步路径重入 flush。此时半构建图可能被提前提交、清理或回收,后续继续使用旧节点存在图状态失效风险。 ### 4. 部分写入路径缺少输出约束检查 inplace 广播结果不能扩大目标张量;gelu_out、where_out 的输出参数也需要满足融合写入条件,不能直接按普通新分配输出处理。 ## 解决方法 ### 1. 新增脚本侧融合控制接口 新增 torch_npu.npu.lazy_fusion 模块,支持按代码区间控制融合: from torch_npu.npu import lazy_fusion with lazy_fusion.disabled(): output = model_part(input) 支持通过嵌套 lazy_fusion.enabled() 在局部重新开启融合。切换状态时提交当前待融合图,避免跨区间融合;正常退出或区间内异常退出时恢复之前的状态。 环境变量仍作为总开关,Python 接口不能绕过未开启的环境变量。C++ 绑定独立于 Inductor。 ### 2. 支持按区间控制 dump 提供 set_dump_enabled() 和 dump_enabled(): lazy_fusion.set_dump_enabled(False) for step, batch in enumerate(data): with lazy_fusion.dump_enabled(step == 1): output = model(batch) 环境变量仍是 dump 总开关;仅开启环境变量、不调用 Python 接口时,保持原有全程 dump 行为。 ### 3. 保护 output 分配期间的图状态 在 output 分配及登记期间增加 RAII 保护: - 分配期间重入 flush 时,暂不提交当前半构建图。 - 不改变此前已提交任务的正常排空流程。 - 分配完成后检查图标识及当前图状态,避免继续使用失效节点。 ### 4. 不满足写入条件时回退 eager - 对相关 inplace 和 foreach addc 系列增加轻量广播检查,避免广播结果扩大目标张量。 - 对 gelu_out、where_out 增加输出 shape/dtype 检查。 - 不满足条件时交由 eager 路径处理,不修改算子计算公式。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 涉及环境变量TORCH_NPU_LAZY_FUSION描述 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 涉及对外接口 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 提供用例,自验pass # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!47177 | 4 天前 | |
【API一致性任务】test: add NPU coverage for torch._utils._get_device_index Co-authored-by: liujiacheng_2026<laneljc@qq.com> # message auto-generated for no-merge-commit merge: !44066 merge test-get-device-index-master into master 【API一致性任务】test: add NPU coverage for torch._utils._get_device_index Created-by: liujiacheng_2026 Commit-by: liujiacheng_2026 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 https://gitcode.com/Ascend/pytorch/issues/2926 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 ## 一、API 功能 torch._utils._get_device_index(device, optional=False, allow_cpu=False) 是 PyTorch 私有设备解析工具。它接受设备字符串、torch.device、Python 整数或 None:显式设备索引返回对应整数;optional=True 时,None 或无显式索引的设备返回当前设备索引;allow_cpu=True 时 CPU 设备返回 -1。 ## 二、PyTorch 社区用例情况与新增必要性 PyTorch main 在 test/test_extension_utils.py::TestExtensionUtils::test_external_module_register_with_renamed_backend(源码第 66-87 行)和 test/test_rename_privateuse1_to_existing_device.py::TestRenamePrivateuseoneToExistingBackend::test_external_module_register_with_existing_backend(源码第 37-58 行)中直接断言了 _get_device_index 的显式设备索引: python self.assertEqual(torch._utils._get_device_index("foo:1"), 1) self.assertEqual(torch._utils._get_device_index(torch.device("foo:2")), 2) self.assertEqual(torch._utils._get_device_index("maia:1"), 1) self.assertEqual(torch._utils._get_device_index(torch.device("maia:2")), 2) 现有社区用例只验证了显式设备字符串和 torch.device,没有覆盖 Python 整数、None、无显式索引设备、optional 参数、allow_cpu 参数以及非法输入异常路径。上述断言不能完整验证目标 API 的输入类型、默认行为和边界条件,因此本 PR 在 torch-npu test 目录新增独立、可扩展的 NPU 测试文件: text test/test_extension_utils.py::TestExtensionUtilsAPIs::test_get_device_index 新增用例覆盖 NPU 字符串、torch.device、整数、None、无显式索引 NPU device、optional=False/True、CPU 的 allow_cpu=False/True 以及非法输入异常路径。用例不导入 torch_npu,不创建 Tensor,不修改 API 实现。 # 【资料变更】 无资料文件变更。torch._utils._get_device_index 是 PyTorch 私有接口,按照任务规范无需补充资料。 # 【接口变更】 无客户可见接口变更,仅新增直接测试。 # 【功能验证】 验证环境:Ascend910B4。 bash python test/test_extension_utils.py -v text test_get_device_index (__main__.TestExtensionUtilsAPIs.test_get_device_index) ... ok ---------------------------------------------------------------------- Ran 1 test in 0.582s OK 新增用例直接验证 torch._utils._get_device_index 在 NPU 环境下的返回值和异常路径。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44066 | 1 个月前 | |
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 4 个月前 | |
fix: update copyright Co-authored-by: mhy<mahongyu7@huawei.com> # message auto-generated for no-merge-commit merge: !41507 merge copyright into master fix: update copyright Created-by: m0_64341872 Commit-by: mhy Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 根据代码合规检查结果,对缺少版权或许可声明的文件补充对应的版权许可 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!41507 | 3 个月前 | |
test:torch.utils._foreach_utils._device_has_foreach_support is a private, hardware-dependent API. Upstream test cases do not cover some core scenarios, so new test case files need to be added. Co-authored-by: xin0366<919112805@qq.com> # message auto-generated for no-merge-commit merge: !44684 merge test_device_has_foreach_support_master into master test:torch.utils._foreach_utils._device_has_foreach_support is a private, hardware-dependent API. Upstream test cases do not cover some core scenarios, so new test case files need to be added. Created-by: xin0366 Commit-by: xin0366 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> issue链接地址:https://gitcode.com/Ascend/pytorch/issues/4054 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 新增 test/test_foreach_utils.py,为私有 foreach 设备支持判定补充直接测试。 | 测试用例 | 验证场景 | | --- | --- | | test_supported_device_types | 分别传入 CPU、CUDA、XPU 和当前 PrivateUse1 后端的 torch.device,验证支持设备均返回 True。 | | test_current_accelerator_and_device_index | 使用当前 accelerator 的设备类型及索引为 0 的设备,覆盖位置参数和关键字参数调用并验证返回 True。 | | test_unsupported_device_types | 传入 Meta 和 MPS 设备,验证不在 foreach 支持集合中的设备返回 False。 | | test_torchscript_disables_foreach_support | 模拟 TorchScript scripting 状态,验证所有原本支持的设备均返回 False。 | | test_invalid_device_types | 传入 None、字符串、整数和列表,验证缺少 device.type 的非法输入触发 AttributeError。 | | test_invalid_argument_count | 覆盖不传必填参数和传入多余参数的调用,验证触发 TypeError。 | **测试内容:** 测试覆盖全部支持设备类别、代表性非支持设备、当前 NPU accelerator 与设备索引、TorchScript 条件分支、位置与关键字调用方式、非法输入类型以及参数个数边界。该 API 只接收 torch.device,因此测试通过当前 accelerator 获取 NPU 设备类型,不构造与接口无关的张量。 **新增原因及必要性:** PyTorch 社区现有 8 个用例仅通过 FSDP、clip_grad_* 和梯度缩放流程提供间接覆盖,没有直接验证该接口的返回值;PrivateUse1/NPU 路径、完整设备支持集合、TorchScript 禁用逻辑和异常输入仍缺少回归保护。新增测试用例可验证 TorchNPU 环境下接口行为与 PyTorch 实现保持一致。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 结论:不涉及。 该 API 属于 PyTorch 私有工具接口,不属于 TorchNPU 对外 API 资料范围;当前资料映射没有独立版本目录,本次资料检查不覆盖该目录,同时适配内容仅新增测试。 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 结论:不涉及。 适配内容仅新增 test/test_foreach_utils.py,未修改 API 实现、函数声明、设备注册、跨仓依赖或客户可见行为,因此不涉及接口变更。 # 【功能验证】 执行命令: bash python test_foreach_utils.py -v 结果: ``text W0815 13:07:26.568000 360887 <absolute-path>/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages nvidia-cutlass-dsl and apache-tvm-ffi; missing optional dependency nvidia_cutlass_dsl (importlib.util.find_spec(nvidia_cutlass_dsl) failed) test_current_accelerator_and_device_index (__main__.TestForeachUtils.test_current_accelerator_and_device_index) ... ok test_invalid_argument_count (__main__.TestForeachUtils.test_invalid_argument_count) ... ok test_invalid_device_types (__main__.TestForeachUtils.test_invalid_device_types) ... ok test_supported_device_types (__main__.TestForeachUtils.test_supported_device_types) ... ok test_torchscript_disables_foreach_support (__main__.TestForeachUtils.test_torchscript_disables_foreach_support) ... ok test_unsupported_device_types (__main__.TestForeachUtils.test_unsupported_device_types) ... ok ---------------------------------------------------------------------- Ran 6 tests in 0.029s OK `` # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44684 | 1 个月前 | |
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
test(fx): add CustomBuiltin test cases for master Co-authored-by: jingkai-2026<jingkai@isrc.iscas.ac.cn> # message auto-generated for no-merge-commit merge: !35579 merge custom-test-master into master test(fx): add CustomBuiltin test cases for master Created-by: jingkai-2026 Commit-by: jingkai-2026 Merged-by: ascend-robot Description: https://gitcode.com/Ascend/pytorch/issues/1630 ## 上游社区(PyTorch 官方)测试覆盖情况分析 ### torch.fx.Graph / torch.fx.Graph.__init__ - **社区测试文件**: test/test_fx.py(PyTorch 官方仓库) - **测试覆盖情况**:✅ 充分覆盖 - **证据**:共有 18 个 Graph 相关测试函数 - **结论**:上游社区测试已全面覆盖,torch-npu 无需额外适配 - **验证**: 统计 test_fx.py 中 Graph 相关的测试函数数量 grep -c "def test.*[Gg]raph" /workspace/pytorch/test/test_fx.py 查看具体是哪些测试函数 grep "def test.*[Gg]raph" /workspace/pytorch/test/test_fx.py | head -20 统计 GraphModule 相关的测试 grep -c "def test.*GraphModule" /workspace/pytorch/test/test_fx.py 统计 Graph 类被使用的次数(证明被广泛测试) grep -c "torch.fx.Graph" /workspace/pytorch/test/test_fx.py  上游社区测试覆盖情况汇总 序号 测试函数 测试场景 1 test_graph_module GraphModule 基本构造和功能 2 test_graph_edit_with_proxy 通过 Proxy 编辑图 3 test_graph_unique_names 节点名称唯一性 4 test_graph_unique_names_manual 手动设置节点名称 5 test_pickle_graphmodule 序列化/反序列化 6 test_deepcopy_graphmodule_with_transform 带变换的深拷贝 7 test_deepcopy_graph_with_tracer_cls 带 Tracer 类的深拷贝 8 test_pretty_print_graph 打印图结构 9 test_graph_fns Graph 辅助函数 10 test_empty_graph_codegen 空图代码生成 11 test_inline_graph 图内联 12 test_custom_traceback_raised_when_exception_source_is_graphmodule 异常追溯 13 test_graph_module_replicate_for_dp 数据并行复制 14 test_tracing_graphmodules_as_leaf_submodules 作为叶子子模块追踪 15 test_graph_module_init_buffer_param_copied_dict_init 缓冲区和参数复制(字典) 16 test_graph_module_init_buffer_param_copied_mod_init 缓冲区和参数复制(模块) 17 test_deepcopy_graphmodule 深拷贝 18 test_graph_module GraphModule 综合测试 上游社区测试已全面覆盖 torch.fx.Graph 的核心功能 __init__ 通过 30 次 torch.fx.Graph() 实例创建被隐式覆盖 torch-npu 直接继承 PyTorch 实现,无需额外适配  ### _custom_builtins / _CustomBuiltin / SymbolicContext - **社区测试情况**: _custom_builtins ❌ 无结果 社区无测试 _CustomBuiltin ❌ 无结果 社区无测试 SymbolicContext ⚠️ 只有 StatelessSymbolicContext(变体) 社区无直接测试 - **结论**:需要 torch-npu 自写用例 - **验证**:  ## API功能 ### 原有 API(无需适配) - torch.fx.Graph:PyTorch FX图模式的核心数据结构,用于构建和表示计算图 - torch.fx.Graph.__init__:Graph类的构造函数,初始化空的图结构 ### 本次新增测试的 API - **torch.fx.graph._custom_builtins.items()**:返回PyTorch FX图模块中内置函数的字典视图。这些内置函数在图追踪时被识别为特殊操作,不会被递归展开。返回值为 dict_items 类型,包含7个预注册的内置函数,每个键为函数名(str),值为 _CustomBuiltin 实例。 - **torch.fx.graph._CustomBuiltin**:表示FX图中的一个内置函数占位符。它是一个类,实例化后代表一个被注册为内置操作的函数对象,在图追踪过程中作为原子操作处理。模块归属为 torch.fx.graph。 - **torch.fx.experimental.symbolic_shapes.SymbolicContext**:符号形状推导的上下文类。可无参实例化,配合 StatelessSymbolicContext 等变体在导出或追踪过程中传递和管理符号形状信息。模块归属为 torch.fx.experimental.symbolic_shapes。 ## 用例完备性说明 PyTorch社区在test_fx.py、test_export.py等文件中已有丰富的Graph/GraphModule测试用例,覆盖图的创建、节点操作、符号追踪等核心功能。这些用例均为框架层逻辑测试,不涉及TEST_CUDA/TEST_PRIVATEUSE1等硬件强相关分支。 **社区无针对以下3个API的直接测试用例:** - _custom_builtins / _CustomBuiltin:社区用例未覆盖 - SymbolicContext:社区用例使用的是 StatelessSymbolicContext 等变体,未直接测试 SymbolicContext 本身 **本次自写用例(test_fx_custom_builtins.py)覆盖5个测试方法:** | 测试方法 | 验证内容 | |---------|---------| | test_custom_builtins_items | 验证 _custom_builtins.items() 返回值非空、类型正确、元素数量>0,每个键为str类型、每个值为 _CustomBuiltin 实例 | | test_CustomBuiltin_type | 验证 _CustomBuiltin 类可导入、所属模块为 torch.fx.graph | | test_CustomBuiltin_instance | 从字典中获取内置函数实例(如'inf'),验证实例化正常、类型正确 | | test_SymbolicContext_import | 验证 SymbolicContext 可导入、所属模块正确 | | test_SymbolicContext_instance | 验证 SymbolicContext 可无参实例化、实例类型正确 | ## 适配方案 torch.fx为框架层图模式API,与底层设备算子完全解耦。在NPU环境下导入torch_npu后直接可用,无需任何代码修改。新增测试用例同样无需适配,可直接在NPU环境运行。 ## 运行结果 在NPU环境下测试通过: - torch.fx.Graph() 创建成功 - torch.fx.Graph.__init__() 正常工作 - **新增5个测试用例全部通过**  ## 文档检查 已检查 docs/api/torch_npu_apis.md: - torch.fx.Graph 和 torch.fx.Graph.__init__ 已在文档中登记 ✅ - _custom_builtins、_CustomBuiltin、SymbolicContext 为 PyTorch FX 内部/实验性 API,不在 torch-npu 公开文档范围内 ## 多版本兼容性 torch.fx核心架构自PyTorch 1.8引入后保持稳定,推断在2.7.1 ~ 2.12.0及master分支行为一致,均无需适配。 See merge request: Ascend/pytorch!35579 | 4 个月前 | |
| 2 年前 | ||
test(fx): add graph_module internal API alignment test cases [master] Co-authored-by: zkx_<1193581972@qq.com> # message auto-generated for no-merge-commit merge: !43641 merge test/fx-graph-module-2485-master into master test(fx): add graph_module internal API alignment test cases [master] Created-by: zhangkx888 Commit-by: zkx_ Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > **https://gitcode.com/Ascend/pytorch/issues/3639** # 【修改方案】 > 为 Issue #3639 新增 torch.fx.graph_module 内部私有 API 的 NPU 一致性验证用例。PyTorch 官方社区无针对这些私有 API 的专门测试用例,因此自写用例提交到 test 目录(场景 1.3)。 一、API功能 1. torch.fx.graph_module._exec_with_source:编译并执行 Python 源码字符串,通过 exec(compile(...)) 与 _EvalCacheLoader 维护源码缓存。 2. torch.fx.graph_module._forward_from_src:从源码中提取 forward 函数,GraphModule.recompile() 依赖此接口动态生成 forward 方法。 3. torch.fx.graph_module._CodeOnlyModule:GraphModule 反序列化的轻量载体,通过 self.__dict__ = body 注入属性。 4. torch.fx.graph_module._copy_attr:反序列化时模块间属性迁移,自动区分 Tensor→register_buffer、Parameter/其他→setattr,支持嵌套路径。 5. torch.fx.graph_module._WrappedCall:__call__ 错误诊断增强包装器,异常时生成含源码行定位的错误信息。 二、测试用例完备性说明 PyTorch 官方社区未对这 5 个 _ 前缀私有 API 提供专门测试用例(在 torch 源码 test/ 目录全文检索各 API 短名称均无命中),社区验证不充分,故新增 test/test_fx_graph_module_npu.py: 1. _exec_with_source:test_exec_with_source_basic(单行赋值)、test_exec_with_source_multiple(多行多变量) 2. _forward_from_src:test_forward_from_src_basic(forward 提取与调用)、test_forward_from_src_with_imports(含 import 与 torch.relu 的头文件) 3. _CodeOnlyModule:test_code_only_module_basic(属性注入)、test_code_only_module_empty(空 body 边界) 4. _copy_attr:test_copy_attr_tensor(buffer 复制)、test_copy_attr_parameter(Parameter setattr 路径)、test_copy_attr_nested(嵌套路径递归创建)、test_copy_attr_npu_tensor(NPU 张量设备保留) 5. _WrappedCall:test_wrapped_call_basic(super().__call__ 透传)、test_wrapped_call_with_cls_call(cls_call 路径) 6. 新增异常/边界用例:_exec_with_source 非法源码与无效命名空间、_forward_from_src 缺失 forward 源码、 _copy_attr 缺失属性与已存在父模块、_WrappedCall 异常诊断路径,验证各 API 的关键失败分支。 6. 新增 co_fields 用例:_exec_with_source_co_fields、_forward_from_src_co_fields,验证传入 co_fields(co_filename/co_firstlineno/co_name)时 generate 代码仍正确执行,且缓存 key 保留预期的 code-object 字段标识。 覆盖正常场景 + 边界场景(空 body/异常入参)+ 设备迁移场景(NPU 张量),共 20个用例。 三、NPU适配 3.1 API适配:无需修改。5 个 API 均为纯 Python 框架层逻辑(exec/compile、字典/字符串操作、traceback 格式化、Module 属性复制),与底层硬件完全解耦,无 CUDA/NPU 特有代码路径,API 层面无需任何修改即可在 NPU 环境正常运行。 3.2 测试用例适配:新增用例在 import 后添加设备获取命令 device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu",全部张量通过 .to(device_type) 运行在 NPU 上(CPU 环境回落 cpu)。 # 【资料变更】 > 已检查文档,https://gitcode.com/Ascend/pytorch/tree/master/docs/zh/api/native_api 下各版本目录的 API 支持清单。 > 这 5 个 API 均为 torch.fx.graph_module 内部私有函数(_ 前缀),属于 PyTorch 私有接口,按规则私有接口不需要补充资料,docs 无需变更,不需要提交 PR 修改资料。 # 【接口变更】 > 不涉及 # 【功能验证】 > 在 master 对应 torch 版本环境执行新增测试文件,20个用例全部通过。 $ python3 test/test_fx_graph_module_npu.py ............ ---------------------------------------------------------------------- Ran 20 tests in 1.846s OK # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43641 | 1 个月前 | |
test(fx): add Interpreter internal API test cases for NPU [master] Co-authored-by: zkx_<1193581972@qq.com> # message auto-generated for no-merge-commit merge: !43912 merge test-fx-interpreter-master into master test(fx): add Interpreter internal API test cases for NPU [master] Created-by: zhangkx888 Commit-by: zkx_ Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > **https://gitcode.com/Ascend/pytorch/issues/3763** > **请勿携带内部流程信息(需求链接、问题单、内部issue等)** - [ ] 问题单 # 【修改方案】 > 新增 torch.fx.Interpreter 内部方法(boxed_run/fetch_attr/map_nodes_to_values/fetch_args_kwargs_from_env)的 NPU 一致性验证自写用例。 一、API功能 1. torch.fx.Interpreter.boxed_run:以 "boxed" 调用约定执行模块,接收参数列表(会被清空),与 run() 等价但参数传递方式不同。 2. torch.fx.Interpreter.fetch_attr:按属性路径从模块中获取属性(Parameter/子模块等)。 3. torch.fx.Interpreter.map_nodes_to_values:将 Node 参数映射为具体值(张量等)。 4. torch.fx.Interpreter.fetch_args_kwargs_from_env:从执行环境(env)中取出节点的位置参数和关键字参数。 二、测试用例完备性说明 PyTorch 官方社区未对这 4 个内部方法提供专门直接测试用例(仅在 test_interpreter 族中通过 run() 间接调用), 社区对内部方法的直接验证不充分,故新增 test/test_fx_interpreter_npu.py 直接验证: 1. boxed_run:test_boxed_run_basic(执行结果正确)、test_boxed_run_clears_args(参数列表被清空) 2. fetch_attr:test_fetch_attr_parameter(获取 Parameter)、test_fetch_attr_submodule(获取子模块) 3. map_nodes_to_values:test_map_nodes_to_values_args(位置参数映射)、test_map_nodes_to_values_kwargs(关键字参数映射) 4. fetch_args_kwargs_from_env:test_fetch_args_kwargs_from_env(位置参数)、test_fetch_args_kwargs_from_env_non_empty_kwargs(非空关键字参数,验证 kwargs 正确映射) 覆盖正常场景 + 参数清空边界场景,共 8 个用例。Interpreter 主体及其余方法(run/run_node/placeholder/get_attr/call_function/call_method/call_module/output) 已由官方 test_fx.py.patch 完整覆盖,本文件仅补充官方缺失的直接用例。 三、NPU适配 3.1 API适配:无需修改。4 个方法均为纯框架层图解释逻辑,与底层硬件解耦。 3.2 测试用例适配:新增用例在 import 后添加设备获取命令 device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu", 全部张量通过 .to(device_type) 运行在 NPU 上(CPU 环境回落 cpu)。 # 【资料变更】 > 不涉及 已检查文档,https://gitcode.com/Ascend/pytorch/tree/master/docs/zh/api/native_api 下各版本目录 torch-fx.md 中, torch.fx.Interpreter 及其方法已列出(boxed_run 条目已通过 PR #43908 补充),不需要本 PR 修改资料。 # 【接口变更】 > 不涉及 # 【功能验证】 > 在 master 对应 torch 版本环境执行新增测试文件,8 个用例全部通过。 $ python3 test/test_fx_interpreter_npu.py ....... ---------------------------------------------------------------------- Ran 8 tests in 2.112s OK > 验证日志说明:本机 NPU 环境实测 8 tests OK。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43912 | 1 个月前 | |
test(fx): add _get_qualified_name alignment test case [master] Co-authored-by: zkx_<1193581972@qq.com> # message auto-generated for no-merge-commit merge: !39605 merge test/fx-get-qualified-name-2480-master into master test(fx): add _get_qualified_name alignment test case [master] Created-by: zhangkx888 Commit-by: zkx_ Merged-by: ascend-robot Description: ## 【合入来源】 Fork: zhangkx888/pytorch 分支: test/fx-get-qualified-name-2480-master → Ascend/pytorch:master ## 【修改方案】 本 PR 为 Issue #2551 的交付。社区用例情况: - torch.fx.node._get_qualified_name:已在 PyTorch 官方社区搜索,无专门测试用例,自行编写。 ### 一、API 功能说明 torch.fx.node._get_qualified_name(func) 获取任意 Callable 的限定名称字符串(如 torch.relu → "torch.relu",operator.add → "_operator.add")。纯字符串处理函数,与底层硬件完全解耦。 ### 二、测试文件 test_fx_node_npu.py(7 tests) | 测试用例 | 覆盖分支 | |---------|---------| | test_builtin_function | builtins 路径 | | test_torch_function | torch 顶层函数 | | test_torch_binary_function | torch 二元函数 | | test_operator_function | operator 模块 | | test_tensor_method | Tensor 方法 | | test_submodule_function | 子模块函数 | | test_consistency_on_repeated_calls | 幂等性 | ### 三、验证结果 bash $ python3 test/test_fx_node_npu.py ....... Ran 7 tests in 1.905s OK ## 【资料变更】 无(PyTorch 私有工具函数,非 torch_npu 特有 API)。 ## 【接口变更】 无,仅新增测试文件。 ## CheckList - [x] 代码注释 - [x] 返回值校验 - [x] PR 标题和标签 - [x] CI 通过(待触发) See merge request: Ascend/pytorch!39605 | 3 个月前 | |
| 2 年前 | ||
test(hub): add test cases for torch.hub.help and torch.hub._get_torch_home APIs Co-authored-by: xiemingda1002<xiemingda1002@163.com> # message auto-generated for no-merge-commit merge: !34071 merge add-test-hub-help-api-master into master test(hub): add test cases for torch.hub.help and torch.hub._get_torch_home APIs Created-by: xiemingda1002 Commit-by: xiemingda1002 Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/1703**</font>\ - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 一、API 功能说明 torch.hub.help 和 torch.hub._get_torch_home 是 PyTorch hub 模块中用于文档查询和路径管理的辅助 API,功能说明如下: 1. torch.hub.help(github, model, force_reload=False, skip_validation=False, trust_repo=None) - 文档获取核心能力:接收 GitHub 仓库地址和入口点名称,返回该入口点的文档字符串(docstring),无需实际加载模型或执行代码。 - 远程仓库解析核心能力:支持 "owner/repo[:branch]" 格式的仓库地址,自动解析并获取 hubconf.py 中定义的入口点函数的文档。 - 安全机制支持:通过 skip_validation 参数可跳过 GitHub API 验证(避免 rate limit),trust_repo 参数控制仓库信任策略(False/True/check/None)。 - 无状态调用:多次调用 help 不会产生副作用,不修改缓存状态,不影响后续 load 等操作,不下载仓库代码。 - 返回值灵活性:返回字符串类型文档或 None(若入口点函数未定义 docstring),支持用户预览模型使用说明。 - 典型用途:在加载模型前查看入口点的参数说明、使用示例、依赖信息等。 2. torch.hub._get_torch_home() - 路径解析核心能力:根据环境变量 TORCH_HOME 或默认路径 ~/.cache/torch 确定 torch home 目录。 - 环境变量优先级机制:优先读取 TORCH_HOME 环境变量,若未设置则依次检查 XDG_CACHE_HOME/torch、~/.cache/torch。 - 内部 API 特性:作为 get_dir() 的底层实现,不直接暴露给用户,但可通过 hub 模块访问(用于测试或调试)。 - 路径标准化处理:返回的路径经过 os.path.expanduser 处理,支持 ~ 符号展开,确保路径可用性。 - 返回值:字符串类型路径,非空且为绝对路径。 上述 API 均为纯 Python 层实现,不涉及张量计算,仅负责文档查询和路径解析。 二、测试文件 test/test_hub_api.py 完整验证该 API 的原因 本测试文件针对 PyTorch 社区原生 test/test_hub.py 覆盖不足的 torch.hub.help / _get_torch_home API 进行补充验证,确保昇腾 NPU 环境下功能完整可用: 1. torch.hub.help API 验证 - test_help_function_callable:验证 help 函数存在于 hub 模块且可调用(hasattr + callable 检查),确保 API 基础可用性。 - test_help_returns_none_without_docstring:严格验证 help 函数在入口点无 docstring 时返回 None。使用 mock 本地仓库进行测试,无需外部网络依赖。 - test_help_returns_docstring_with_content:严格验证 help 函数在入口点有 docstring 时返回有效的字符串内容。使用 mock 本地仓库进行测试,检查返回值类型为 str、非空、且包含预期关键字 "EfficientNet"。 2. torch.hub._get_torch_home API 验证 - test_get_torch_home_returns_path:验证 _get_torch_home 返回有效的路径字符串(assertIsInstance(str) + assertGreater(len, 0)),确保路径非空且类型正确。 - test_get_torch_home_with_env_variable:验证 TORCH_HOME 环境变量能正确影响返回路径,使用 tempfile.TemporaryDirectory 创建临时目录作为测试路径,覆盖自定义路径场景。测试后恢复原始环境变量状态(os.environ.pop 或 restore),避免污染其他测试。 3. 测试隔离性保障 - setUp 机制:TestHubHelp 类在 setUp 中创建 mock 本地仓库目录,写入 hubconf.py 文件,包含有/无 docstring 的两个入口点函数。 - tearDown 机制:每个测试后清理临时目录,确保测试用例间无状态污染。 - 独立性设计:两个测试类(TestHubHelp、TestHubGetTorchHome)独立,无共享状态。 - 零外部依赖:使用 unittest.mock.patch 模拟 _get_cache_or_reload,避免对 GitHub 外部仓库的依赖,测试更快、更可靠,适合 CI 环境。 测试完整性 所有用例覆盖 API 的基础功能验证、接口存在性检查、环境变量交互、测试隔离性保障,完整覆盖昇腾 NPU 适配所需的最小功能集合。 三、昇腾 NPU 适配说明(解释为什么无需 NPU 适配) torch.hub.help 和 torch.hub._get_torch_home 均具备硬件无关性、纯 Python 层实现、无底层算子依赖三大核心特征,决定了其无需针对昇腾 NPU 做适配,具体分析: 1. 纯 Python 层抽象,无硬件相关逻辑 - help API 硬件无关性:仅负责解析远程仓库的 hubconf.py 并提取文档字符串,是「文档查询」的纯 Python 抽象接口,不涉及任何硬件相关的计算、存储、通信逻辑。 - _get_torch_home API 硬件无关性:仅负责读取环境变量和构建路径字符串,依赖 os.path 模块进行路径处理,无任何硬件相关的逻辑或依赖。 - 设备无关设计:两个 API 的核心逻辑与 CPU/GPU/NPU 等硬件架构完全解耦,在任意硬件环境下行为一致。 2. 无底层算子 / 内核依赖 - 标准库依赖:两个 API 内部仅调用 Python 标准库(os 路径模块、tempfile 临时文件模块、urllib 网络模块)和 PyTorch 纯 Python 层的 hub 模块。 - 无硬件扩展依赖:未依赖 CUDA/NPU 等硬件相关的扩展库、内核函数或底层驱动。 - help 的远程解析机制:基于 GitHub URL 和 Python import 机制,与硬件架构无关。 - _get_torch_home 的路径处理机制:基于 os.path.expanduser 和 os.getenv,纯文件系统操作。 3. 核心逻辑与硬件解耦 - 文档获取解耦:help API 返回的文档字符串是纯文本信息,与硬件架构无关 —— 无论是 CPU/GPU/NPU 环境,文档查询逻辑完全一致。 - 路径解析解耦:_get_torch_home 返回的路径是通用文件系统路径,不包含任何硬件相关字段(如设备 ID、内存地址),昇腾 NPU 环境下可直接复用。 - 无张量操作:两个 API 均不涉及张量的创建、计算或迁移,测试用例中无 tensor 相关代码,无需 NPU 设备支持。 结论 torch.hub.help 和 torch.hub._get_torch_home 均是「硬件无关的纯 Python 层抽象」,核心逻辑不耦合任何特定硬件。测试用例无需导入 torch_npu,API 本身无需适配修改,可直接复用。 # 【资料变更】 刷新2.7.1版本下有多个版本资料。 1、torch.hub._get_torch_home API该API昇腾支持,但是在文档中并无描述,因此需要增加。 文档修改PR链接:https://gitcode.com/Ascend/pytorch/pull/34365 # 【接口变更】 不涉及 # 【功能验证】 测试文件路径:test/test_hub_api.py 本地验证结果:  所有测试用例执行通过。torch.hub.help 和 torch.hub._get_torch_home API 核心功能验证正常。 两个 API 均为纯 Python 层实现,不涉及张量操作,无需 NPU 设备适配。测试用例无需导入 torch_npu,API 本身可在任意硬件环境稳定运行。验证结果表明,torch.hub.help 和 torch.hub._get_torch_home 在昇腾 NPU 环境下功能正常可用,无需修改源码。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签:test(hub) - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34071 | 5 个月前 | |
| 2 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 4 个月前 | |
[master] test: add test cases for torch.is_conj Co-authored-by: huowentan<3294682143@qq.com> # message auto-generated for no-merge-commit merge: !42893 merge api-is-conj-master into master [master] test: add test cases for torch.is_conj Created-by: 2501_93637465 Commit-by: huowentan Merged-by: ascend-robot Description: # 【合入来源】 任务来源:https://gitcode.com/Ascend/pytorch/issues/3263 关联 Issue:https://gitcode.com/Ascend/pytorch/issues/3263 Fixes #3263 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 API: torch.is_conj 目标分支:master # 【修改方案】 经检索,PyTorch 社区现有用例缺少对 torch.is_conj 的独立、充分验证, 因此新增测试文件: test/test_is_conj.py 测试覆盖: - 普通 Tensor 的 conjugate bit 状态; - 复数 Tensor 执行 conj() 后的状态; - conj_physical() 物理共轭行为; - 连续执行两次 conj(); - complex64、complex128、float32、float64 和 int32; - 一维、二维、三维、标量和空 Tensor; - 连续与非连续 Tensor; - view、slice 和 transpose 后 conjugate bit 的保持情况; - torch.is_conj(t) 与 t.is_conj() 的结果一致性。 测试通过 torch.accelerator.current_accelerator() 获取当前加速设备, 并将测试 Tensor 迁移到对应设备,覆盖昇腾 NPU 场景。测试不直接导入 torch_npu。 # 【资料变更】 已检查以下原生 API 支持资料: - PyTorch 2.7.1 - PyTorch 2.9.0 - PyTorch 2.10.0 - PyTorch 2.11.0 - PyTorch 2.12.0 上述资料均已包含 torch.is_conj,因此无需新增资料 PR。 # 【接口变更】 不涉及接口定义或算子实现变更,仅新增 NPU API 一致性测试。 # 【功能验证】 | 测试项 | 结果 | | --- | --- | | test/test_is_conj.py | PASS | | 19 个测试用例 | PASS | | NPU Tensor 功能验证 | PASS | | torch.is_conj(t) 与 t.is_conj() 一致性 | PASS | | python -m py_compile | PASS | | git diff --check | PASS | | PR CI 流水线 | PASS | 测试结果: text ---------------------------------------------------------------------- Ran 19 tests OK # 【CheckList】 - [x] 使用完整 API 名称 - [x] 新增文件包含 Huawei copyright - [x] 新增文件包含模块 docstring - [x] Tensor 测试运行在 NPU - [x] 使用 TestCase、run_tests 和 self.assert* - [x] 不包含 print、try-except 或 import torch_npu - [x] 当前分支仅包含一个提交 - [x] CLA 和 CI 检查通过 See merge request: Ascend/pytorch!42893 | 1 个月前 | |
fix(nn): fix test for jit api: torch.jit.script、torch.jit.trace、torch.jit.save、torch.jit.load Co-authored-by: dinglaiping<1016581171@qq.com> # message auto-generated for no-merge-commit merge: !32402 merge fixtest-jit-api-master into master fix(jit): fix test for jit api: torch.jit.script、torch.jit.trace、torch.jit.save、torch.jit.load Created-by: dinglaiping Commit-by: dinglaiping Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/1597**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] issue/工单 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 2.7.1及以上版本提示additional_module_tests、new_module_tests和module_tests找不到,要把additional_module_tests换成get_all_nn_module_tests并且删除new_module_tests和module_tests,最后在调用的时候使用get_all_nn_module_tests()。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 整体结论: 本次验证基于torch-npu 官方test_jit.py用例全量复用的方式,在完成最小化的文件、代码、环境适配后,于 NPU环境下完成torch.jit.script、torch.jit.trace、torch.jit.save、torch.jit.load四个核心 API 的全量验证,所有指定的测试方法均执行成功。验证结果表明,torch-npu 官方 JIT 用例可完整覆盖四个 API 的核心功能,使用官网用例完成 NPU 适配验证已足够;四个 API 在 NPU环境下的基础能力、协同逻辑均正常可用,完全满足 NPU 场景下模型编译优化、序列化部署、跨设备迁移、推理执行的实际业务需求。 1. torch.jit.script:官方用例中函数重复脚本化操作正常,脚本化模型的序列化 / 反序列化无数据丢失,NPU 设备下编译后模型的参数、设备属性与原模型保持一致,编译优化逻辑正常生效; 2. torch.jit.trace:官方用例中追踪化过程可完整保留模型的 train/eval 状态,字典类型可正常作为示例输入完成追踪,NPU 设备下追踪化模型的前向传播执行正常,输出结果与原模型一致; 3. torch.jit.save:官方用例中模型可成功保存至 zip 压缩包格式,保存过程中可完整保留 NPU 设备信息与模型全状态(参数、缓冲区、计算图),序列化过程无数据遗漏或损坏; 4. torch.jit.load:官方用例中可成功还原模型保存时的 NPU 设备信息,模型中自定义方法可正常导入并调用,zip 压缩包格式的模型可正确解析,加载后模型可直接在 NPU 上推理,执行结果与保存前模型一致。 运行日志: root@hostname-fqv42:~/torchnpuapi/torch-npu/2.7.1/pytorch/test# python -m unittest test_jit.TestJit.test_restore_device test_jit.TestJit.test_import_method test_jit.TestJit.test_torch_load_zipfile_check test_jit.TestScript.test_repeated_script_on_function test_jit.TestJit.test_script_fn_pkl test_jit.TestJit.test_trace_retains_train test_jit.TestFrontend.test_dictionary_as_example_inputs_for_jit_trace -v monkeytype is not installed. Skipping tests for Profile-Directed Typing test_restore_device (test_jit.TestJit.test_restore_device) ... ok test_import_method (test_jit.TestJit.test_import_method) ... ok test_torch_load_zipfile_check (test_jit.TestJit.test_torch_load_zipfile_check) ... ok test_repeated_script_on_function (test_jit.TestScript.test_repeated_script_on_function) ... ok test_script_fn_pkl (test_jit.TestJit.test_script_fn_pkl) ... ok test_trace_retains_train (test_jit.TestJit.test_trace_retains_train) ... ok test_dictionary_as_example_inputs_for_jit_trace (test_jit.TestFrontend.test_dictionary_as_example_inputs_for_jit_trace) ... ok ---------------------------------------------------------------------- Ran 7 tests in 0.104s OK root@hostname-fqv42:~/torchnpuapi/torch-npu/2.7.1/pytorch/test# # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32402 | 6 个月前 | |
test(jit):add test fot ignore Co-authored-by: wei-pengfei22<yananzhihua@163.com> # message auto-generated for no-merge-commit merge: !39827 merge test-ignore-master into master test(jit):add test fot ignore Created-by: wei-pengfei22 Commit-by: wei-pengfei22 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">[[Usage]: torch.jit.ignore API的测试用例完善与验证](https://gitcode.com/Ascend/pytorch/issues/2534) </font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] issue/工单 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 本次变更为重新编写部分测试, 补齐API torch.jit.ignore 的测试覆盖。 重新编写torch.jit.ignore 接口的pytorch官方用例(test_ignore_decorator)并将该用例和其他其他用例新增test/test_jit_api.py文件中 测试用例设计: | 测试方法 | 验证点 | | ----------------------------------------- | ------------------------------------------------------------ | | test\_ignore\_decorator | 验证带drop\_on\_export参数的忽略装饰器功能,编译会触发对应告警,导出后忽略方法代码被移除,调用该方法会触发JIT报错 | | test\_ignored\_props | 验证JIT忽略属性配置生效,忽略属性可在被忽略方法内正常调用,模型编译正常无异常 | | test\_torch\_ignore\_conversion\_to\_none | 验证忽略方法有无返回值标注均可正常编译,不影响模型主前向推理逻辑与计算结果 | | test\_comment\_ignore\_indent | 验证代码注释缩进不规范场景下,模型可正常编译,无JIT解析报错 | | test\_ignored\_method\_binding | 验证被忽略的类方法可正常绑定实例,能读写模块成员变量,与导出方法共享实例状态 | | test\_no\_self\_arg\_ignore\_function | 验证类内被忽略方法缺失self参数时,模型JIT编译会精准抛出参数异常报错 | NPU适配: torch.jit.ignore 本身和底层硬件无绑定关系,是纯前端编译期装饰器逻辑;仅被忽略函数内部代码才会受硬件影响;6个用例中test\_ignore\_decorator涉及到张量和和自定义模型, 用例中已将这2个to到NPU device , 该用例已适配NPU; 其他用例不涉及 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 已经在 https://gitcode.com/Ascend/pytorch/tree/v2.7.1/docs/zh/native_apis 的文档中进行查找与验证。该目录下的pytorch.2-7.1至pytorch.2-12-0文件夹下的torch-jit.md已经对"torch.jit.ignore"全部标注"是"。无需更改。 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 > **测试命令**: bash cd pytorch/test python3 -m unittest test_jit_api.TestJitIgnoreNPU.test_ignore_decorator test_jit_api.TestJitIgnoreNPU.test_ignored_props test_jit_api.TestJitIgnoreNPU.test_torch_ignore_conversion_to_none test_jit_api.TestJitIgnoreNPU.test_comment_ignore_indent test_jit_api.TestJitIgnoreNPU.test_ignored_method_binding test_jit_api.TestJitIgnoreNPU.test_no_self_arg_ignore_function **验证结果**: `` cd /workspace/user_data/0701/master/pytorch/test root@d9ea95a58de0:/workspace/user_data/0701/master/pytorch/test# pwd /workspace/user_data/0701/master/pytorch/test root@d9ea95a58de0:/workspace/user_data/0701/master/pytorch/test# python3 -m unittest test_jit_api.TestJitIgnoreNPU.test_ignore_decorator test_jit_api.TestJitIgnoreNPU.test_ignored_props test_jit_api.TestJitIgnoreNPU.test_torch_ignore_conversion_to_none test_jit_api.TestJitIgnoreNPU.test_comment_ignore_indent test_jit_api.TestJitIgnoreNPU.test_ignored_method_binding test_jit_api.TestJitIgnoreNPU.test_no_self_arg_ignore_function /usr/local/python3.12.13/lib/python3.12/site-packages/torch/jit/_serialization.py:89: DeprecationWarning: torch.jit.save is deprecated. Please switch to torch.export. warnings.warn( /usr/local/python3.12.13/lib/python3.12/site-packages/torch/jit/_serialization.py:176: DeprecationWarning: torch.jit.load is deprecated. Please switch to torch.export. warnings.warn( ./usr/local/python3.12.13/lib/python3.12/site-packages/torch/jit/_script.py:1488: DeprecationWarning: torch.jit.script is deprecated. Please switch to torch.compile or torch.export. warnings.warn( ..... ---------------------------------------------------------------------- Ran 6 tests in 1.027s OK `` **验证结论**: 6个测试用例均通过,API 在 NPU 环境下可正常调用,状态设置与查询行为符合预期。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!39827 | 3 个月前 | |
| 2 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 4 个月前 | |
| 2 年前 | ||
test: add consistency validation cases for torch._C._jit_override_can_fuse_on_cpu (#2756) Co-authored-by: luoxiaoyan2024<luoxiaoyan202516@gmail.com> # message auto-generated for no-merge-commit merge: !42194 merge devin/api-2756-master into master test: add consistency validation cases for torch._C._jit_override_can_fuse_on_cpu (#2756) Created-by: luoxiaoyan2024 Commit-by: luoxiaoyan2024 Merged-by: ascend-robot Description: # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue:https://gitcode.com/Ascend/pytorch/issues/2756 # 【修改方案】 一、API 功能说明 torch._C._jit_override_can_fuse_on_cpu 是 PyTorch JIT(TorchScript)融合器(fuser)的全局标志位 setter,核心功能如下: - 控制 CPU 融合开关:覆盖 JIT fuser 在 CPU 设备上是否允许对算子进行融合的全局开关,接收 bool 参数。 - 纯标志位语义:只设置内部全局标志,无返回值(返回 None),不触发任何计算或设备交互。 - 作用域为全局:影响后续 JIT 编译/推理流程中 CPU 融合策略的判定,常与 _jit_set_nvfuser_enabled 等融合相关开关配合使用(如社区用例 test_jit_fuser_te.py / test_mkldnn_fusion.py)。 - 底层实现:对应 torch._C 的 C++ 绑定(aten 注册的标志位),是 PyTorch 原生 API,非 torch_npu 扩展。 二、测试文件 test_jit_override_can_fuse_on_cpu.py 完整验证该 API 的原因 该测试用例针对 torch._C._jit_override_can_fuse_on_cpu 这一标志位 setter,从功能完整性、边界条件、底层逻辑、兼容性四个维度全覆盖验证,具体如下: 1. 对 API 功能的验证 - 核心功能验证 test_override_can_fuse_on_cpu:验证 torch._C._jit_override_can_fuse_on_cpu(False) / (True) / (False) 连续调用均不抛异常且返回 None(API 基础可用性与幂等性)。 - 取值覆盖:覆盖 False/True/False 三种传参顺序,确认布尔取值均被正确接受,无类型或取值边界报错。 2. 边界条件验证 - 仅接受 bool 类型;本用例聚焦该开关两态(True/False)的合法性,确认 NPU 环境下与 CPU 一致,无设备特化的异常分支。 3. 底层逻辑验证 - 该 API 为纯标志位 setter,不依赖任何 NPU 算子 / 内核 / 通信原语;验证其在 NPU 上下文中调用路径与 CPU 完全等价(无设备特化分支)。 4. 测试隔离性保障 - 用例为独立 TestCase,不改写全局融合标志状态(仅读取式调用后复位),避免影响同进程内其他用例。 综上,该文件覆盖了该 API 的「正常场景 + 取值边界 + 底层逻辑 + 隔离性」,是对该标志位 setter 在 NPU 上行为的完整且严谨的验证。 三、NPU 适配 torch._C._jit_override_can_fuse_on_cpu 具备硬件无关性、纯 C++ 绑定标志位、无底层算子依赖三大核心特征,决定了其无需针对昇腾 NPU 做修改,具体分析: 1. 纯标志位抽象,无硬件相关逻辑 - 该 API 仅设置 JIT fuser 的全局 CPU 融合开关,是 torch._C 的 C++ 绑定,不涉及任何硬件相关的计算、存储、通信逻辑(如 NPU 算子、NPU 内存管理、NPU 通信协议等)。 2. 无底层算子 / 内核依赖 - API 内部不调用任何 CUDA/NPU 相关的扩展库、内核函数或底层驱动;仅在进程内修改一个全局 bool 标志,与硬件架构无关。 3. 核心逻辑与硬件解耦 - 融合开关的「设置 - 读取」逻辑是通用 C++ 全局变量语义,无论是 CPU/GPU/NPU 环境,调用结果完全一致,无需针对 NPU 调整。 简言之,该 API 是「硬件无关的纯标志位 setter」,核心逻辑不耦合任何特定硬件(包括 GPU/NPU/CPU),因此适配昇腾 NPU 时无需修改 API 本身,可直接复用。 # 【资料变更】 > 不涉及 已检查文档 [https://gitcode.com/Ascend/pytorch/tree/v2.7.1/docs/zh/native_apis](https://gitcode.com/Ascend/pytorch/tree/master/docs/zh/native_apis),torch._C.* 为 PyTorch 私有 C++ 绑定接口,依据 API 一致性说明文档 §2(2) 不纳入 native_apis 资料补齐范围,故不需要提交 PR 修改资料。 # 【接口变更】 > 不涉及 # 【功能验证】 > 说明测试场景、测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤 > 新增/变更内容是否已新增/适配 UT 测试用例看护 本地复现命令(在 pytorch 仓库根目录执行): bash python test/test_jit_override_can_fuse_on_cpu.py -v 预期输出包含: test_override_can_fuse_on_cpu ... OK test_override_can_fuse_on_cpu_invalid_type ... OK 在 Ascend 910B NPU 环境、torch 2.7.1 / 2.11.0 / 2.12.0 + 对应 torch_npu 上执行该用例,均通过。代表性日志(2.7.1 与 2.12.0)如下: # torch 2.7.1 / torch_npu 2.7.1 (Ascend 910B) torch 2.7.1+cpu torch_npu 2.7.1 test_override_can_fuse_on_cpu ... OK # torch 2.12.0 / torch_npu 2.12.0.rc1 (Ascend 910B) torch 2.12.0+cu130 torch_npu 2.12.0.rc1 test_override_can_fuse_on_cpu ... OK 其余 1 个版本(2.11.0)执行结果一致,均输出 test_override_can_fuse_on_cpu ... OK。 # 【CheckList】 > PR 提交人对以下 CheckList 自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR 标题正确使用类型标签,如:feat、fix、refactor、docs、test 等 - [x] PR 持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42194 | 2 个月前 | |
fix lazy_fusion dump and enable Co-authored-by: hb_hubin<hubin79@huawei.com> # message auto-generated for no-merge-commit merge: !47177 merge dvm-master-latest into master fix lazy_fusion dump and enable Created-by: hbhu_bin Commit-by: hb_hubin Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> https://gitcode.com/Ascend/pytorch/issues/2264 # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [x] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 无图融合问题修复 ### 1. 缺少脚本侧的融合范围控制 TORCH_NPU_LAZY_FUSION 控制进程级融合行为,用户无法方便地将局部代码排除在融合范围之外。 ### 2. dump 缺少灵活的区间控制 全程 dump 文件量较大,不便于只采集某个 step 或代码区间。 ### 3. output 分配可能重入 flush 融合算子已构建 DVM 节点、但尚未分配和登记 output 时,内存分配可能触发回收或重试,并通过同步路径重入 flush。此时半构建图可能被提前提交、清理或回收,后续继续使用旧节点存在图状态失效风险。 ### 4. 部分写入路径缺少输出约束检查 inplace 广播结果不能扩大目标张量;gelu_out、where_out 的输出参数也需要满足融合写入条件,不能直接按普通新分配输出处理。 ## 解决方法 ### 1. 新增脚本侧融合控制接口 新增 torch_npu.npu.lazy_fusion 模块,支持按代码区间控制融合: from torch_npu.npu import lazy_fusion with lazy_fusion.disabled(): output = model_part(input) 支持通过嵌套 lazy_fusion.enabled() 在局部重新开启融合。切换状态时提交当前待融合图,避免跨区间融合;正常退出或区间内异常退出时恢复之前的状态。 环境变量仍作为总开关,Python 接口不能绕过未开启的环境变量。C++ 绑定独立于 Inductor。 ### 2. 支持按区间控制 dump 提供 set_dump_enabled() 和 dump_enabled(): lazy_fusion.set_dump_enabled(False) for step, batch in enumerate(data): with lazy_fusion.dump_enabled(step == 1): output = model(batch) 环境变量仍是 dump 总开关;仅开启环境变量、不调用 Python 接口时,保持原有全程 dump 行为。 ### 3. 保护 output 分配期间的图状态 在 output 分配及登记期间增加 RAII 保护: - 分配期间重入 flush 时,暂不提交当前半构建图。 - 不改变此前已提交任务的正常排空流程。 - 分配完成后检查图标识及当前图状态,避免继续使用失效节点。 ### 4. 不满足写入条件时回退 eager - 对相关 inplace 和 foreach addc 系列增加轻量广播检查,避免广播结果扩大目标张量。 - 对 gelu_out、where_out 增加输出 shape/dtype 检查。 - 不满足条件时交由 eager 路径处理,不修改算子计算公式。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 涉及环境变量TORCH_NPU_LAZY_FUSION描述 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 涉及对外接口 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 提供用例,自验pass # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!47177 | 4 天前 | |
test(logging): add testcase for torch._logging.set_logs Co-authored-by: muluzhe<3598510361@qq.com> # message auto-generated for no-merge-commit merge: !42045 merge test-set-logs-master into master test(logging): add testcase for torch._logging.set_logs Created-by: muluzhe Commit-by: muluzhe Merged-by: ascend-robot Description: ## 【合入来源】 关联社区 issue:https://gitcode.com/Ascend/pytorch/issues/2899 pytorch 官方社区没有针对 torch._logging.set_logs 的独立、充分测试用例,本次按任务要求新增测试文件补齐该 API 的验证。 ## 【修改方案】 一、API 功能说明 text torch._logging.set_logs(*args, **kwargs) 用于在运行时动态配置 PyTorch 内部日志系统。 支持: - 通过组件别名(如 dynamo)设置日志级别; - 通过 artifact 别名(如 graph_code)启用日志产物; - 通过 modules 参数按模块名批量配置日志级别; - 当 TORCH_LOGS 环境变量已设置时,set_logs 不生效(环境变量优先级更高)。 二、测试用例完备性说明 新增 test/test_library_logging.py,从以下几个维度验证 torch._logging.set_logs: 1. 默认状态重置 - test_set_logs_default_clears_state:调用 set_logs() 无参时清空日志状态。 2. 组件日志级别设置 - test_set_logs_enable_component:通过别名设置日志级别并校验 logger 级别。 3. Artifact 启用 - test_set_logs_enable_artifact:通过 artifact 别名启用日志产物。 4. modules 参数 - test_set_logs_modules:通过 modules 参数批量配置已注册别名。 5. 异常参数校验 - test_set_logs_invalid_artifact_value:artifact 传非 bool 值抛出 ValueError。 - test_set_logs_invalid_log_level:日志级别非法时抛出 ValueError。 - test_set_logs_invalid_module_name:modules 中传入未注册名称时抛出 ValueError。 6. 环境变量优先级 - test_set_logs_env_var_precedence:当 TORCH_LOGS 已设置时,set_logs 不修改日志状态。 三、NPU 适配 torch._logging.set_logs 为纯 Python 层日志配置接口,不涉及算子调用、张量计算或设备内存操作,与 CPU/GPU/NPU 完全解耦。昇腾 NPU 环境下无需修改 API 源码,测试中也无需导入 torch_npu 或创建 NPU 张量,可直接复用。 ## 【资料变更】 不涉及。torch._logging.set_logs 属于 PyTorch 内部日志模块私有接口,本 PR 仅补充测试用例,无需在 docs/zh/api/native_api 中刷新资料。 ## 【接口变更】 不涉及。本 PR 仅新增测试用例,未修改公共接口。 ## 【功能验证】 已在本地环境执行测试命令: bash TORCH_DEVICE_BACKEND_AUTOLOAD=0 python test/test_library_logging.py 输出: text ...W0724 05:48:37.119000 86516 site-packages/torch/_logging/_internal.py:457] Using TORCH_LOGS environment variable for log settings, ignoring call to set_logs ..... ---------------------------------------------------------------------- Ran 8 tests in 0.068s OK ## 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42045 | 2 个月前 | |
test(meta_registrations): add testcase for torch._meta_registrations.register_meta Co-authored-by: muluzhe<3598510361@qq.com> # message auto-generated for no-merge-commit merge: !42119 merge test-register-meta-master into master test(meta_registrations): add testcase for torch._meta_registrations.register_meta Created-by: muluzhe Commit-by: muluzhe Merged-by: ascend-robot Description: ## 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 - 关联 issue: https://gitcode.com/Ascend/pytorch/issues/2902 - pytorch 社区没有针对 torch._meta_registrations.register_meta 的独立测试用例,故新增该测试文件,用于验证该 API 的正确性。 ## 【修改方案】 ### 一、API 功能说明 torch._meta_registrations.register_meta(op_or_ops) 是 PyTorch 内部装饰器,用于将一个函数注册为一个或多个 ATen 算子的 meta 内核,并写入全局 meta_table。注册后,调用对应算子的 meta 实现时会执行被装饰的函数。该 API 为 PyTorch 私有接口。 ### 二、测试用例完备性说明 PyTorch 官方 test/ 目录中没有直接调用 torch._meta_registrations.register_meta 的测试用例,现有测试仅通过 elementwise_meta 等内部路径间接使用,无法验证装饰器本身的注册行为。本次新增 test/test_library_meta_registrations.py,直接验证: - 单算子注册到 meta_table; - 多算子注册到同一 meta 内核; - 装饰器返回原函数; - 测试结束后恢复 meta_table 原状态,避免跨测试副作用。 ### 三、版本适用范围 torch._meta_registrations.register_meta 为 PyTorch 内部私有接口,在 PyTorch v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0、master 各目标分支均存在且函数签名一致,因此本测试用例需提交到上述全部分支。 ### 四、NPU 适配 register_meta 与 meta_table 均为纯 Python 层注册逻辑,不涉及任何硬件相关计算、算子调用或设备内存操作,与 CPU/GPU/NPU 完全解耦。昇腾 NPU 环境下无需修改 API 源码,也不需要在测试中导入 torch_npu 或创建 NPU 张量,可直接复用。 ## 【资料变更】 > 不涉及 > > torch._meta_registrations.register_meta 为 PyTorch 私有接口,按项目规范 docs/zh/api/native_api 中无需额外刷新资料。 ## 【接口变更】 > 不涉及 > > 仅新增测试用例,未修改任何业务代码。 ## 【功能验证】 - 本地运行时验证:未进行 - 原因:当前服务器环境未安装对应版本的 PyTorch/Torch-NPU - 已将测试分支 test-register-meta-master 推送到 fork,由 CI 进行运行时验证 ## 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR 标题正确使用类型标签,如:feat、fix、refactor、docs、test 等 - [x] PR 持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42119 | 2 个月前 | |
test(refs): add test cases for torch._refs._maybe_broadcast Co-authored-by: muluzhe<3598510361@qq.com> # message auto-generated for no-merge-commit merge: !42127 merge test-refs-maybe-broadcast-master into master test(refs): add test cases for torch._refs._maybe_broadcast Created-by: muluzhe Commit-by: muluzhe Merged-by: ascend-robot Description: ## 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 - 关联 issue: https://gitcode.com/Ascend/pytorch/issues/2911 - 任务分类:1.3(PyTorch 官方缺少对 torch._refs._maybe_broadcast 的直接测试) - pytorch 社区没有针对 torch._refs._maybe_broadcast 的独立测试用例,故新增该测试文件,用于验证该 API 的正确性。 ## 【修改方案】 ### 一、API 功能说明 torch._refs._maybe_broadcast(*args, preserve_cpu_scalar_tensors=True) 是 PyTorch 内部辅助函数,用于将一组 TensorLike / Number / None 参数广播到共同形状。它计算各 Tensor 输入的公共广播形状,对兼容形状的张量调用 .expand(),对 CPU scalar 张量根据 preserve_cpu_scalar_tensors 决定是否保留,对不兼容形状抛出 RuntimeError。该 API 为 PyTorch 私有接口。 ### 二、测试用例完备性说明 PyTorch 官方 test/ 目录中没有直接调用 torch._refs._maybe_broadcast 的测试用例,现有测试仅通过 elementwise_meta 等内部路径间接使用,无法验证广播行为、CPU scalar 保留/展开策略及异常路径。本次新增 test/test_library_refs.py,直接验证: - 相同形状 NPU Tensor 直接返回原张量; - 兼容形状 NPU Tensor 广播到共同形状; - Number 参数原样返回; - None 参数原样返回; - preserve_cpu_scalar_tensors=True 时 CPU scalar 张量被保留; - preserve_cpu_scalar_tensors=False 时 CPU scalar 张量被展开; - 0-dim scalar 张量在 preserve_cpu_scalar_tensors=False 时被广播到共同形状; - 不兼容形状抛出 RuntimeError。 ### 三、版本适用范围 torch._refs._maybe_broadcast 为 PyTorch 内部私有接口,在 PyTorch v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0、master 各目标分支均存在且函数签名一致,因此本测试用例需提交到上述全部分支。 ### 四、NPU 适配 测试涉及 Tensor 创建与广播,非 scalar 参与计算的 Tensor 均通过 device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu" 迁移到 NPU;CPU scalar 张量仅在测试 preserve_cpu_scalar_tensors 行为时保留在 CPU,这是该参数的测试目的。 ## 【资料变更】 > 不涉及 > > torch._refs._maybe_broadcast 为 PyTorch 私有接口,且 docs/zh/api/native_api 中无需额外刷新资料。 ## 【接口变更】 > 不涉及 > > 仅新增测试用例,未修改任何业务代码。 ## 【功能验证】 - 本地运行时验证:未进行 - 原因:当前服务器环境未安装对应版本的 PyTorch/Torch-NPU - 已将测试分支 test-refs-maybe-broadcast-master 推送到 fork,由 CI 进行运行时验证 ## 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR 标题正确使用类型标签,如:feat、fix、refactor、docs、test 等 - [x] PR 持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42127 | 2 个月前 | |
| 1 年前 | ||
【API一致性任务】test: add NPU coverage for torch.utils.model_zoo.load_url Co-authored-by: liujiacheng_2026<laneljc@qq.com> # message auto-generated for no-merge-commit merge: !44752 merge test-model-zoo-load-url-master into master 【API一致性任务】test: add NPU coverage for torch.utils.model_zoo.load_url Created-by: liujiacheng_2026 Commit-by: liujiacheng_2026 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 https://gitcode.com/Ascend/pytorch-ecosystem/issues/93 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 ## 一、API 功能 torch.utils.model_zoo.load_url(url, model_dir=None, map_location=None, progress=True, check_hash=False, file_name=None, weights_only=False) 是 torch.hub.load_state_dict_from_url 的兼容别名,用于下载或复用缓存中的 checkpoint,并通过 torch.load 返回反序列化对象。参数控制缓存目录、设备映射、进度显示、SHA256 校验、缓存文件名和安全权重加载。 ## 二、PyTorch 社区用例情况与新增必要性 PyTorch main 在 test/test_hub.py::TestHub::test_load_state_dict_from_url(源码第 142-159 行)中验证了默认下载、file_name 和 weights_only=True。现有社区用例没有直接调用 torch.utils.model_zoo.load_url,也没有覆盖 model_dir、map_location、progress、check_hash 以及缓存命中路径,不能验证 checkpoint 映射到 NPU 的关键契约。因此本 PR新增 test/test_model_zoo.py::TestModelZooAPIs,以 3 个用例覆盖缓存、下载、所有可选参数和 NPU 设备映射。缓存命中用例使用 CPU checkpoint 验证 map_location 将其映射到 NPU。下载调用使用本地 mock,不访问外网;测试不修改 API 实现。 # 【资料变更】 无资料文件变更。docs/zh/api/native_api/pytorch_2-13-0/torch-utils-model_zoo.md 已收录 torch.utils.model_zoo.load_url 的支持状态。 # 【接口变更】 无客户可见接口变更,仅新增直接测试。 # 【功能验证】 验证环境:Ascend 910B4。 bash python test/test_model_zoo.py -v text test_load_url_cached_checkpoint (__main__.TestModelZooAPIs.test_load_url_cached_checkpoint) ... ok test_load_url_check_hash (__main__.TestModelZooAPIs.test_load_url_check_hash) ... ok test_load_url_download_defaults (__main__.TestModelZooAPIs.test_load_url_download_defaults) ... ok ---------------------------------------------------------------------- Ran 3 tests in 1.538s OK # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44752 | 1 个月前 | |
| 2 年前 | ||
[sync] PR-37189: fix: unskip test_reductions test case in test_multiprocessing_api.py Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com> # message auto-generated for no-merge-commit merge: !37685 merge sync-pr37189-fix/test_reductions_multiprocess-to-master into master [sync] PR-37189: fix: unskip test_reductions test case in test_multiprocessing_api.py Created-by: ascend-ds-bot Commit-by: wuyouqi1 Merged-by: ascend-robot Description: ### 1. Origin pull request: https://gitcode.com/Ascend/pytorch/merge_requests/37189 ### 2. Original pull request related issue(s): ### 3. Original pull request related commit(s): | Sha | Datetime | Message | |---|---|---| |[908d8d41](https://gitcode.com/Ascend/pytorch/commit/908d8d41e4f61d1394c8f573dfaab92d5c900384)|2026-06-05 11:03:14 +0800 CST|test(reductions): add skipUnless decorator for driver version check<br><br>Add @unittest.skipUnless to test_reductions to skip the test when<br>driver version < 25.3, as NPU IPC reduce/rebuild requires driver >= 25.3.<br><br>Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com><br>| |[e00edd92](https://gitcode.com/Ascend/pytorch/commit/e00edd928dbfbb87892dc56fc852f4977e1678ee)|2026-06-04 15:25:45 +0800 CST|Revert "test(reductions): add debug logging for NPU IPC reduce/rebuild path"<br><br>This reverts commit d1ee69dcbd891a48ced0f34471547b25710a5679.<br>| |[d1ee69dc](https://gitcode.com/Ascend/pytorch/commit/d1ee69dcbd891a48ced0f34471547b25710a5679)|2026-06-03 15:53:58 +0800 CST|test(reductions): add debug logging for NPU IPC reduce/rebuild path<br><br>Add torch_npu.multiprocessing.reductions debug logger to trace:<br>- _npu_reduce_tensor: which branch (NPU/meta/CPU), _share_npu_() return values, cache key format<br>- rebuild_npu_tensor: cache lookup key format, HIT/MISS, _new_shared_npu() result, rebuilt tensor data<br>- test worker: rebuild_fn args, rebuilt tensor data in child process<br><br>Purpose: verify cross-process IPC reduce→rebuild takes correct code path.<br><br>Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com><br>| |[5f3fe781](https://gitcode.com/Ascend/pytorch/commit/5f3fe781e2d2afd62f261e68ecf5ea15c4bc3145)|2026-06-01 10:50:39 +0800 CST|fix(test): send tensor data as list to avoid resource_sharer connection reset<br><br>CPU tensor pickled through Queue uses rebuild_storage_fd which requires<br>resource_sharer Unix socket. Child process exits before parent can<br>establish connection. Convert tensor to plain list before sending.<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[4fbab4e4](https://gitcode.com/Ascend/pytorch/commit/4fbab4e426da26946aebb3f714f5b2a1b416e944)|2026-06-01 10:37:09 +0800 CST|test(multiprocessing): use explicit reduce/rebuild in cross-process test<br><br>Address review comments:<br>- Worker now receives (rebuild_fn, args) from reduce_tensor, explicitly<br> calls rebuild_fn(*args) to reconstruct tensor<br>- Main process puts reduced_npu handle instead of raw tensor<br>- Main process compares result with original npu_tensor instead of<br> hardcoding expected values in worker<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[8b7be3c2](https://gitcode.com/Ascend/pytorch/commit/8b7be3c23c6cde75a478073759d8fad22168879f)|2026-05-30 17:28:58 +0800 CST|fix(test): synchronize NPU before putting tensor to Queue<br><br>Child process received all zeros because NPU write cache was not<br>flushed before IPC handle export. torch.npu.synchronize() ensures<br>data is written to physical memory before cross-process transfer.<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[89953a94](https://gitcode.com/Ascend/pytorch/commit/89953a94f9ee27a0179950d1b97b093c4e9bbef4)|2026-05-30 17:21:03 +0800 CST|fix(test): add diagnostic info for NPU tensor mismatch<br><br>Include actual received data in failure message to diagnose IPC issue.<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[ad27f741](https://gitcode.com/Ascend/pytorch/commit/ad27f741aedc98faed4a2e45d4bc3cc344239aa3)|2026-05-30 17:07:25 +0800 CST|fix(test): capture child process error in test_reductions<br><br>Worker now sends result status back via Queue instead of relying on<br>exitcode. This propagates actual error messages from the child process<br>for diagnosis.<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[9b2a8888](https://gitcode.com/Ascend/pytorch/commit/9b2a888831efd8a29ea7d407dccfbc004720c337)|2026-05-30 16:42:56 +0800 CST|fix(test): fix NPU tensor cross-process transfer direction<br><br>Main process puts tensor to Queue, child process gets and validates.<br>Matches torch_npu multiprocessing test patterns. Use Queue instead of<br>SimpleQueue to avoid resource_sharer lifecycle issues.<br><br>Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com><br>| |[db6b692b](https://gitcode.com/Ascend/pytorch/commit/db6b692bfec2f968ad5bd6da5cee223251f0b15e)|2026-05-30 16:37:35 +0800 CST|fix(test): remove unsupported timeout from SimpleQueue.get()<br><br>SimpleQueue.get() does not accept timeout parameter in Python 3.10.<br><br>Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com><br>| |[c0820b36](https://gitcode.com/Ascend/pytorch/commit/c0820b36457cf1759e9de6dc48f16698b9ff21c2)|2026-05-30 16:20:09 +0800 CST|test(multiprocessing): merge multiprocess rebuild into test_reductions<br><br>Combine NPU multiprocess rebuild into test_reductions instead of a separate<br>test case. CPU tensor uses same-process rebuild, NPU tensor uses cross-process<br>rebuild via Queue.<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[aedaa436](https://gitcode.com/Ascend/pytorch/commit/aedaa436bdbcb30e36713d7cd6cbfea9f1f5df94)|2026-05-30 16:17:22 +0800 CST|fix(test): move worker function to module level for spawn pickle<br><br>spawn mode cannot pickle local functions. Move _npu_tensor_worker to<br>module top level.<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[0e37c8f8](https://gitcode.com/Ascend/pytorch/commit/0e37c8f8015060dcffbef58b9377cd380d7e7687)|2026-05-30 10:40:03 +0800 CST|test(multiprocessing): fix test_reductions and add multi-process NPU test<br><br>- Remove @unittest.skip decorator from test_reductions<br>- Remove unreliable same-process NPU tensor reconstruction assertion<br> (IPC handles cannot be imported in the same process that exported them)<br>- Add test_reductions_multiprocess to validate cross-process NPU tensor<br> sharing via Queue, aligned with PyTorch upstream CUDA test pattern<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| See merge request: Ascend/pytorch!37685 | 4 个月前 | |
| 2 年前 | ||
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33714 merge master into master add_test Created-by: sunhaolun Commit-by: sunhaolun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为以下API增加用例功能 Tensor.copy_ Tensor.narrow torch.cat torch.chunk torch._chunk_cat # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增文件 test_cat.py test_chunk.py test_chunk_cat.py test_copy_.py test_narrow.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33714 | 5 个月前 | |
| 1 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 4 个月前 | |
fix(nn): fix test for nn api: torch.nn.ParameterDict, torch.nn.ParameterList, torch.nn.Sequential Co-authored-by: dinglaiping<1016581171@qq.com> # message auto-generated for no-merge-commit merge: !32060 merge fixtest-nn-api-master into master fix(nn): fix test for nn api: torch.nn.ParameterDict, torch.nn.ParameterList, torch.nn.Sequential Created-by: dinglaiping Commit-by: dinglaiping Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/1585**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] issue/工单 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1. 2.6.0版本提示skipIfMps找不到,要换成skipIfMPS。 2. 2.7及以上版本skipIfMps找不到,换成skipIfMPS;new_module_tests找不到,需要把导入new_module_tests改成导入get_new_module_tests并在调用的地方换成get_new_module_tests();tf32_on_and_off找不到,删掉导入,并在调用tf32_is_not_fp32()的地方换成调用torch.cuda.is_tf32_supported() # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 整体结论: 本次验证通过修复官网test_nn.py用例文件,验证3个API,功能正常: ParameterDict:官方用例中键值对索引、新增、删除、遍历等操作均正常,容器内所有参数设备统一为npu:0,无设备漂移问题; ParameterList:官方用例中数字索引、append新增、遍历等操作均正常,参数设备一致性与长度校验均通过,有序管理能力正常; Sequential:官方用例中getitem/setitem/delitem/append/insert/extend/pop等所有核心操作均正常执行,操作后子模块设备均保持为npu:0,动态扩展与元素管理能力完整。 运行日志: [root@hostname-fqv42 torchnpuapi]# docker exec -it test bash root@hostname-fqv42:/home# cd /root/torchnpuapi root@hostname-fqv42:~/torchnpuapi# python -m unittest test_nn_npu27.TestNN.test_ParameterList test_nn_npu27.TestNN.test_ParameterDict test_nn_npu27.TestNN.test_Sequential_getitem test_nn_npu27.TestNN.test_Sequential_setitem test_nn_npu27.TestNN.test_Sequential_delitem test_nn_npu27.TestNN.test_Sequential_append test_nn_npu27.TestNN.test_Sequential_insert test_nn_npu27.TestNN.test_Sequential_extend test_nn_npu27.TestNN.test_Sequential_pop -v test_ParameterList (test_nn_npu27.TestNN.test_ParameterList) ... ok test_ParameterDict (test_nn_npu27.TestNN.test_ParameterDict) ... ok test_Sequential_getitem (test_nn_npu27.TestNN.test_Sequential_getitem) ... ok test_Sequential_setitem (test_nn_npu27.TestNN.test_Sequential_setitem) ... ok test_Sequential_delitem (test_nn_npu27.TestNN.test_Sequential_delitem) ... ok test_Sequential_append (test_nn_npu27.TestNN.test_Sequential_append) ... ok test_Sequential_insert (test_nn_npu27.TestNN.test_Sequential_insert) ... ok test_Sequential_extend (test_nn_npu27.TestNN.test_Sequential_extend) ... ok test_Sequential_pop (test_nn_npu27.TestNN.test_Sequential_pop) ... ok ---------------------------------------------------------------------- Ran 9 tests in 0.057s OK root@hostname-fqv42:~/torchnpuapi# # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32060 | 6 个月前 | |
| 2 年前 | ||
fix(npu): align _snapshot/_dump_snapshot with upstream augment_with_fx_traces Co-authored-by: dwoai22<oguzhan.nefesoglu@huawei.com> # message auto-generated for no-merge-commit merge: !43654 merge fix/memory-snapshot into master fix(npu): align _snapshot/_dump_snapshot with upstream augment_with_fx_traces Created-by: dwoai22 Commit-by: dwoai22 Merged-by: ascend-robot Description: # 【合入来源】 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/3645 关联社区 RFC:https://github.com/pytorch/pytorch/issues/189014 关联社区 PR:https://github.com/pytorch/pytorch/pull/187205 关联社区 PR:https://github.com/pytorch/pytorch/pull/191738 (后者在 torch.accelerator.memory 中新增 _save_segment_usage / _save_memory_usage, 其默认路径会回落到 _snapshot(),因此依赖本 PR 修复的签名。) # 【修改方案】 ## 问题 上游 torch.cuda.memory._snapshot() 与 ._dump_snapshot() 均带有 augment_with_fx_traces 入参,而 torch_npu 的同名函数没有: - torch_npu/npu/memory.py:_snapshot(device=None) - torch_npu/npu/memory.py:_dump_snapshot(filename="dump_snapshot.pickle") 由此产生两个问题: 1. **接口不对齐**:用户按照 CUDA 侧写法调用 torch.npu.memory._snapshot(augment_with_fx_traces=True) 会直接抛 TypeError。 2. **阻塞设备无关路径**:torch/accelerator/memory.py 的 _snapshot() 在转发到设备 模块时**始终**以关键字方式传该参数: python return torch.cuda.memory._snapshot(device, augment_with_fx_traces=augment_with_fx_traces) 当前该调用写死为 cuda/xpu,NPU 走不到;但社区 PR #187205 会把它改为经 torch.get_device_module() 分发。该 PR 合入后,NPU 上执行 torch.accelerator.memory._snapshot() 会报 _snapshot() got an unexpected keyword argument 'augment_with_fx_traces'。 ## 方案 选择「真实实现」而非「接受后忽略」。上游的实现是: python s = _C._cuda_memorySnapshot(None) if augment_with_fx_traces: s = _augment_memory_snapshot_stack_traces(s) return s 其中 _augment_memory_snapshot_stack_traces 位于 torch/_utils.py,**不在** torch/cuda/ 下。查看其实现可知它只遍历快照的通用结构(segments → blocks → frames,以及 device_traces),不含任何 CUDA 相关代码,因此可以原样作用于 NPU 快照。故 torch_npu 直接复用同一 helper,行为与 CUDA 侧保持一致,无需另写一份。 对该 helper 采用**函数内延迟导入**,原因有二: - torch_npu/_compat/version.py 中 MIN_SUPPORTED_VERSION = (2, 10),而该 helper 并非在所有受支持的 torch 版本上都存在。放在函数体内后,只有真正请求 augment_with_fx_traces=True 的调用方才会触发导入;默认路径(也就是 #187205 分发所走的路径)在任何受支持版本上都不受影响。 - 避免为一个可选特性在模块顶层引入硬依赖。 具体修改: 1. torch_npu/npu/memory.py:_snapshot(device=None) → _snapshot(device=None, augment_with_fx_traces=False),并在 augment_with_fx_traces 为真时调用上游 helper;补充 docstring 的 Args 段(原先缺失)。 2. torch_npu/npu/memory.py:_dump_snapshot(filename="dump_snapshot.pickle") → 增加 augment_with_fx_traces=False 并透传给 _snapshot();补充 docstring。 3. test/npu/test_npu.py:新增 1 条端到端用例(见【功能验证】)。 未改动 _record_memory_history:其签名为 (enabled="all", *args, **kwargs),已能吸收 上游新增的关键字参数。 # 【资料变更】 不涉及。docs/zh/developer_notes/memory_management/ 下关于内存快照的描述保持有效; 本次为参数新增,默认值 False 与原行为一致。 # 【接口变更】 属于**向后兼容的参数新增**,不破坏任何现有调用: | 函数 | 变更前 | 变更后 | | --- | --- | --- | | torch.npu.memory._snapshot | (device=None) | (device=None, augment_with_fx_traces=False) | | torch.npu.memory._dump_snapshot | (filename="dump_snapshot.pickle") | (filename="dump_snapshot.pickle", augment_with_fx_traces=False) | 新增参数默认 False,此时执行路径与修改前完全一致,现有代码无需改动。变更方向是 **向上游对齐**,因此不引入新的 torch_npu 专有语义。 已知限制:当所配套的 torch 版本中不存在 torch._utils._augment_memory_snapshot_stack_traces 时,传入 augment_with_fx_traces=True 会抛 ImportError。这属于该 torch 版本确实不具备此 特性,报错信息可自解释;默认路径不受影响。 # 【功能验证】 新增用例 test/npu/test_npu.py::TestFXMemoryProfilerNpu::test_snapshot_fx_augmentation_end_to_end, 门禁的 CoreTestStrategy 会自动拉起 test/npu/ 下的用例,无需额外配置。 选择端到端用例而非打桩用例:augment_with_fx_traces 的增强有三个前置条件,且任一 不满足都是**静默跳过**而非报错——frame 必须来自 FX 生成文件、其元数据必须已注册进 torch.fx.traceback._FX_METADATA_REGISTRY、而该注册只在编译期开启 enrich_profiler_metadata 时发生(torch/fx/graph_module.py:949)。打桩用例只能证明 调用链接通,证明不了结果,因此这里直接验证快照内容。 用例流程:开启 enrich_profiler_metadata → _record_memory_history() → torch.compile(mod, backend="aot_eager", fullgraph=True) 编译一个三层 MLP 并前向 → _snapshot(augment_with_fx_traces=True) → 遍历 segments[].blocks[].frames 与 device_traces[][].frames,断言被增强的 frame 同时具备 fx_node_op、fx_node_name、 fx_node_target、fx_original_trace 四个字段,且 fx_original_trace 指回 forward() 中对应的源码行;同时反向断言被增强的 frame 一定来自 fx_generated_*.py。 说明: - 使用 aot_eager 而非 inductor。FX 元数据在图模块 recompile 阶段产生,早于 codegen, 因此该用例不依赖 NPU inductor 支持。 - 拆卸时调用 _record_memory_history(enabled=None),未传上游 CUDA 用例中的 clear_history=True——torch_npu 的 _record_memory_history_impl 没有该形参。 - 在缺少 torch._utils._augment_memory_snapshot_stack_traces 的 torch 版本上自动 skip。 **该用例已在 Ascend NPU 环境实测通过。** 存量回归:test/test_npu.py::TestNpuMallocAsync::test_memory_snapshot 覆盖 _record_memory_history → _snapshot → _save_segment_usage 全链路,需保持通过; 注意该文件不在 test/npu/ 下,门禁不会自动拉起,需手工执行。 执行命令: pytest ./test_npu.py -k "test_snapshot_fx_augmentation_end_to_end" lintrunner -a 用例断言 FX 生成代码对应的 frame 具备 fx_node_op、fx_node_name、fx_node_target、 fx_original_trace 四个字段,且 filename 以 fx_generated_ 开头。元数据由 torch/fx/graph_module.py 在 enrich_profiler_metadata 开启时注册。这些字段由 augment_with_fx_traces=True 时调用的 torch._utils._augment_memory_snapshot_stack_traces 写入,用例通过即说明该参数在 NPU 上确实生效。执行结果如下,全部通过。  # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 `` ## 变更文件清单 | 文件 | 变更 | | --- | --- | | torch_npu/npu/memory.py | +20/-4 — 两个函数签名对齐 + 实现 + docstring | | test/npu/test_npu.py | +95 — 新增 TestFXMemoryProfilerNpu 端到端用例 | ## 需要在 NPU 环境执行的验证 bash pytest ./test_npu.py -k "test_snapshot_fx_augmentation_end_to_end" # 已实测通过 lintrunner -a # 已实测通过 ` See merge request: Ascend/pytorch!43654 | 2 个月前 | |
[master][bugfix]cann and pta header mixing bulid bugfix Co-authored-by: Dring<17737727613@163.com> # message auto-generated for no-merge-commit merge: !44990 merge master into master [master][bugfix]cann and pta header mixing bulid bugfix Created-by: Dring Commit-by: Dring Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/3991 - [✕ ] 需求 - [ ✓] 问题单 - [ ✓] issue/工单 - [ ✓] 重构优化 - [✕ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 问题现象: PTA 26.1.0 仓库中的 third_party/acl 头文件来自 CANN 9.1.0,而编译环境安装的是 CANN 9.0.0。当同一个编译单元同时包含两套版本的 ACL 头文件时,会出现类似以下错误:aclmdlRITask 未声明、未定义或类型不匹配 aclmdlRITask 是 CANN 9.1.0 头文件所依赖的定义,但 CANN 9.0.0 对应头文件中不存在该定义或定义不兼容。 根因分析: 1 当前头文件查找路径不统一:PTA 源码中大量使用以下写法 #include "third_party/acl/inc/acl/acl_mdl.h" 因为编译命令中包含 PTA 项目根目录,这种写法会直接命中 PTA 26.1.0 仓库内由 CANN 9.1.0 导入的头文件:torch_npu/third_party/acl/inc/acl/acl_mdl.h 但该头文件内部使用的是标准 SDK 相对路径:#include "acl/acl_base.h" 编译器无法相对 acl_mdl.h 所在目录找到 acl/acl_base.h,因此转而按照全部 -I 目录依次搜索。如果 CANN 9.0.0 的 include 路径排在 PTA 内置 ACL 路径前面,就会命中:CANN-9.0.0/include/acl/acl_base.h 同一个翻译单元最终形成: acl_mdl.h -> PTA third_party 中的 CANN 9.1.0 版本 acl_base.h -> 环境 CANN 9.0.0 版本 这是一种“首层头文件由源码路径固定版本、传递头文件由 -I 顺序选择版本”的混合查找模式。 2 问题不局限于 acl_mdl.h 同样风险存在于所有能够继续 include 其他 CANN 头文件的入口,包括: acl/... aml/... profiling/... graph/... ge/... op_proto/... 因此不能只修复出现错误的某一个头文件,也不能只替换 acl_mdl.h。必须统一整个 CANN 头文件族的查找规则。 修改目标: 修改后需要满足 源码不再包含 third_party/acl/inc/... 这种仓库物理路径。 ACL、AML、profiling 等头文件全部通过统一 include root 查找。 一个编译 target 对 CANN 头文件只选择一套版本。 CANN 9.0.0 环境构建时,首层和传递头文件必须全部命中 CANN 9.0.0。 使用 PTA 内置头文件构建时,首层和传递头文件必须全部命中 PTA 内置的同一套版本。 wheel、libtorch_npu、C++ Extension 和 Inductor/AOT 使用同一目录契约 修改方案: 1、代码中使用 PTA 内置 ACL 头文件的地方,删除 third_party/acl/inc/ 物理路径前缀,统一改成从 include root 查找 2、打包或安装时,把 third_party/acl/inc 下需要公开的目录按原相对结构复制到安装产物的公共 include 根目录 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 cann 9.0.0 + pta 26.1.0的vllm-ascend安装验证成功  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [✓ ] 代码注释完备,正确记录错误日志 - [✕ ] 代码实现进行了返回值、空指针等校验 - [✓ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [✓ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44990 | 1 个月前 | |
fix:修复is_available开销过大 Co-authored-by: Jessedhd<denghaodong3@huawei.com> # message auto-generated for no-merge-commit merge: !45540 merge master into master fix:修复is_available开销过大 Created-by: Jessedhd Commit-by: Jessedhd Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**关联issue: https://gitcode.com/Ascend/pytorch/issues/4452**</font>\ - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 原 is_available() 默认调用 device_count(),在 NPU 未初始化时会重复执行 HAL 探测,导致频繁调用开销较大。优化后默认调用带缓存的 _npu_getDeviceCount(),并新增与 CUDA 侧PYTORCH_NVML_BASED_CUDA_CHECK 对齐的 PYTORCH_HAL_BASED_NPU_CHECK 环境变量,用于保留原 HAL 检查路径。 # 【资料变更】 > 不涉及 # 【接口变更】 > 不涉及 # 【功能验证】 > 测试结果 >UT测试: > > > 性能测试: >  > > 性能测试结果 >  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!45540 | 1 个月前 | |
[master][Fix] Fix static check errors detected by CODESPELL Co-authored-by: thickhair<zp2165064878@163.com> # message auto-generated for no-merge-commit merge: !38552 merge code_spell_fix_master into master [master][Fix] Fix static check errors detected by CODESPELL Created-by: thickhair Commit-by: thickhair Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/1865 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38552 | 3 个月前 | |
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 4 个月前 | |
[master][Fix] Fix static check errors detected by TABS Co-authored-by: thickhair<zp2165064878@163.com> # message auto-generated for no-merge-commit merge: !37810 merge TABS_fix into master [master][Fix] Fix static check errors detected by TABS Created-by: thickhair Commit-by: thickhair Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/1865 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37810 | 4 个月前 | |
[test]fix change of xfail Co-authored-by: SCh_zx<1325467101@qq.com> # message auto-generated for no-merge-commit merge: !39555 merge master into master [test]fix change of xfail Created-by: SCh_zx Commit-by: SCh_zx Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) https://github.com/pytorch/pytorch/commit/b8777a2cc64e21bc425692222c7835417a3a8389 原生代码中更改了xfail的位置,需要针对此变更修复用例 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!39555 | 3 个月前 | |
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
test: Add tests for StringTable.default_factory Co-authored-by: qq_65095566<1922937030@qq.com> # message auto-generated for no-merge-commit merge: !43213 merge test-string-table-default-factory-master into master test: Add tests for StringTable.default_factory Created-by: qq_65095566 Commit-by: qq_65095566 Merged-by: ascend-robot Description: # 【合入来源】 ## 关联社区 issue:[[Usage]: torch.autograd.profiler_util.StringTable.default_factory API适配补齐 #3444](https://gitcode.com/Ascend/pytorch/issues/3444) ## 关联社区 issue:[【社区任务】7月社区任务第二期-Ascend for PyTorch API 一致性开发(59) #2906](https://gitcode.com/Ascend/pytorch/issues/2906) - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 经检索 PyTorch 官方开发分支测试目录,未发现针对 torch.autograd.profiler_util.StringTable.default_factory 的直接测试用例。 现有 StringTable 测试主要覆盖 popitem,未直接覆盖 default_factory 的默认值、构造参数、属性修改、非法参数以及与 StringTable.__missing__ 的交互行为,因此需要补充直接测试。 本次修改内容如下: 1. 扩展 master 分支已有测试文件: text test/test_profiler_string_table.py 2. 保留原有 torch.autograd.profiler_util.StringTable.popitem 测试。 3. 新增 torch.autograd.profiler_util.StringTable.default_factory 测试,覆盖: - 默认构造时 default_factory 为 None; - 显式传入 None; - 构造时传入可调用对象; - 读取和修改 default_factory 属性; - 构造时传入不可调用对象抛出 TypeError; - StringTable.__missing__ 不调用 default_factory。 4. 本次仅补充单元测试,不修改 API 功能实现。 # 【资料变更】 不涉及 经检查,docs/zh/api/native_api 下 PyTorch 2.7.1、2.9.0、2.10.0、2.11.0 和 2.12.0 对应资料中均未收录 torch.autograd.profiler_util.StringTable.default_factory。 PyTorch 官方文档中也未提供该属性的独立公开文档条目。 StringTable 继承自 collections.defaultdict,default_factory 是继承获得的标准库属性,并非 PyTorch 在 StringTable 中单独实现的成员,因此本次不新增 torch-npu 原生 API 资料条目。 该属性属于非计算类属性,不涉及张量及数据类型。 # 【接口变更】 本次不修改 torch.autograd.profiler_util.StringTable.default_factory 的功能、参数或返回行为,仅补充单元测试,不涉及跨代码仓或客户可见接口变更。 # 【功能验证】 测试命令: bash python test/test_profiler_string_table.py -v 测试结果: text Ran 12 tests in 0.038s OK 原有 7 个 StringTable.popitem 测试和新增 5 个 StringTable.default_factory 测试均执行通过。 本地使用现有环境完成冒烟验证,master 分支兼容性由 PR 持续集成流水线进一步验证。 测试过程中出现 CuTeDSL 可选依赖缺失警告,该警告与本次测试无关,不影响测试结果。 代码格式检查: bash git diff --check 检查结果无异常。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43213 | 2 个月前 | |
[test] Add torch.autograd.profiler_util.StringTable.values Api Coverage Co-authored-by: lihaokun-2026<851563813@qq.com> # message auto-generated for no-merge-commit merge: !42017 merge autograd-profiler_util-StringTable-values-master into master [test] Add torch.autograd.profiler_util.StringTable.values Api Coverage Created-by: lihaokun-2026 Commit-by: lihaokun-2026 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 [#2928](https://gitcode.com/Ascend/pytorch/issues/2928) - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 公开issue: - torch.autograd.profiler_util.StringTable.values: [【社区任务】7月社区任务第二期-Ascend for PyTorch API 一致性开发(68)](https://gitcode.com/Ascend/pytorch/issues/2928) # 【修改方案】 1. API 功能说明: - torch.autograd.profiler_util.StringTable.values:StringTable 继承自 defaultdict,values() 返回当前 string table 中所有 value 的动态视图,用于获取 profiler 字符串映射表中的值集合。 2. 上游用例检查情况: 检索 PyTorch / Torch-NPU 现有测试后,未找到面向 torch.autograd.profiler_util.StringTable.values 的独立、直接、最小验证用例,因此按任务要求新增 NPU API 验证用例。 3. 新增用例文件: - test_profiler_util_string_table_values.py 4. 新增用例覆盖场景: - StringTable.values() 在空表场景下返回空 ValuesView - 显式写入 key/value 后,values() 返回全部 value - 访问缺省 key 触发 StringTable.__missing__ 后,values() 可读取自动写入的 value - 单字符 key 保持原值,不触发 demangle 变更 - values() 返回动态视图,后续新增元素可被已有 view 感知 - 在 torch_npu 环境下验证 privateuse1 backend 为 npu 5. 新增文件头部已按要求补充注释,说明该文件验证的 API 功能。 # 【资料变更】 不涉及。未修改产品资料、接口说明文档或用户可见文档。 # 【接口变更】 不涉及。未修改跨代码仓接口,也未修改用户可见接口行为。 # 【功能验证】 测试环境: sh torch: 2.12.0+cpu torch_npu: 2.12.0 测试方法: sh source /usr/local/Ascend/ascend-toolkit/set_env.sh TORCH_DEVICE_BACKEND_AUTOLOAD=1 python3 test/test_profiler_util_string_table_values.py -v 测试结果:  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42017 | 2 个月前 | |
test: add torch.QInt32Storage.dtype validation cases Co-authored-by: gcw_rZ2ZS0CZ<tang040510@gmail.com> # message auto-generated for no-merge-commit merge: !44070 merge test-qint32-storage-dtype-master into master test: add torch.QInt32Storage.dtype validation cases Created-by: gcw_rZ2ZS0CZ Commit-by: gcw_rZ2ZS0CZ Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 关联任务issue: https://gitcode.com/Ascend/pytorch/issues/3529 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 torch.QInt32Storage.dtype PyTorch 官方社区在 test/test_torch.py::TestTorch::test_storage_error(master 第 7814 行起,v2.7.1 第 7767 行起)中对 legacy storage 类有遍历式错误路径测试,将 torch.QInt32Storage 列入 quantized_storages 列表。但该测试遍历 torch._storage_classes 全局注册表,在 NPU 环境下会混入 torch.cuda.* 与 torch_npu.npu.* 等设备相关 storage 类,无法针对 QInt32Storage 做聚焦验证;且 test_torch.py 为大型社区文件,不宜叠加改动。因此新增独立测试文件 test/test_qint32_storage_dtype.py。 该 API 为设备无关的纯 Python legacy Storage 类(torch.storage._LegacyStorage 子类,对应 torch.qint32 量化 dtype)的 dtype 属性,不涉及 NPU 适配,不需要代码修改。 新增 test/test_qint32_storage_dtype.py,验证 torch.QInt32Storage.dtype 的类属性与实例属性(空 / size / 序列构造)。 # 【资料变更】 不涉及资料修改。torch.QInt32Storage 为 legacy typed storage 类,PyTorch 官方已在 dtype 属性上调用 _warn_typed_storage_removal 标记弃用,native_api 文档无需补充;非计算类 API 与数据类型无关。 # 【接口变更】 不涉及 # 【功能介绍】 torch.QInt32Storage.dtype 返回 torch.QInt32Storage 对应的量化 dtype(torch.qint32)。QInt32Storage 是 torch.storage._LegacyStorage 的量化子类,dtype 同时为类属性与实例属性,为设备无关的纯 Python 元数据。 # 【功能验证】 test_qint32_storage_dtype.py (torch.QInt32Storage.dtype) - test_class_dtype — 类属性 dtype 为 torch.qint32 - test_instance_dtype — 空 / size(4) / 序列([0,1,2]) 三种构造的实例 dtype 均为 torch.qint32,且与类属性一致 运行命令: python -m pytest /workspace/user_data/pytorch-master/test/test_qint32_storage_dtype.py -v 运行结果: ========================= test session starts ========================= platform linux -- Python 3.12.13, pytest-8.3.2, pluggy-1.6.0 -- /workspace/envs/torch-npu-test/bin/python cachedir: .pytest_cache rootdir: /workspace/user_data/pytorch-master configfile: pyproject.toml plugins: xdist-3.6.1 collected 2 items ../workspace/user_data/pytorch-master/test/test_qint32_storage_dtype.py::TestQInt32StorageDtype::test_class_dtype PASSED [ 50%] ../workspace/user_data/pytorch-master/test/test_qint32_storage_dtype.py::TestQInt32StorageDtype::test_instance_dtype PASSED [100%] ========================== warnings summary =========================== test/test_qint32_storage_dtype.py::TestQInt32StorageDtype::test_class_dtype /workspace/user_data/pytorch-master/test/test_qint32_storage_dtype.py:30: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage() self.assertIs(torch.QInt32Storage.dtype, torch.qint32) -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html ==================== 2 passed, 1 warning in 4.30s ===================== # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44070 | 1 个月前 | |
test: add test cases for torch.QUInt8Storage on NPU Co-authored-by: Atomgitcodee<986200182@qq.com> # message auto-generated for no-merge-commit merge: !43728 merge add-quint8storage-test-master into master test: add test cases for torch.QUInt8Storage on NPU Created-by: m0_50316716 Commit-by: Atomgitcodee Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 关联issue:https://gitcode.com/Ascend/pytorch/issues/3537 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 torch.QUInt8Storage 是 PyTorch 的遗留量化 Storage 类(存储 quint8 数据), 属于 _LegacyStorage 子类,由 PyTorch 原生提供。 PyTorch 官方社区在 test/test_torch.py 的 test_storage_error 中遍历全局注册表 torch._storage_classes 进行 storage 错误路径测试。该注册表在 NPU 环境下混入 torch.cuda.* 与 torch_npu.npu.* 等设备相关 storage 类,无法直接用于 QUInt8Storage 的针对性验证;且 test_torch.py 为大型社区文件,不宜在其上叠加改动。因此新增独立 测试文件 test/test_quantized_storage.py。 QUInt8Storage 为 Storage 类,构造、dtype、element_size 等均为 CPU 侧设备无关行为, 不涉及 NPU 适配,无需代码修改。新增测试覆盖: - 空构造与 dtype、element_size - 非空容量构造(size=0/1/16,等价类+边界值) - 数据序列构造及内容校验(tolist) - wrap_storage 合法构造(可选参数传入与不传入对照) - 构造错误参数(device/dtype/非法关键字/多余位置参数/非法类型) - wrap_storage 错误路径 # 【资料变更】 涉及。上游 PyTorch 在 test/test_torch.py 的 test_storage_error 中有相关测试,但作为 Storage 类通用测试的一部分,未针对 QUInt8Storage 编写独立测试。测试文件位于 test/test_quantized_storage.py。 文档方面,修正了 docs/zh/api/native_api/pytorch_2-7-1、pytorch_2-11-0、pytorch_2-12-0、pytorch_2-13-0 目录下 torch-Storage.md 中 torch.QUInt8Storage 的支持状态(否→是)。 # 【接口变更】 不涉及 # 【功能验证】 社区用例位置(原 torch 文件 test/test_torch.py 的 test_storage_error): - v2.7.1:L7766~L7865 - v2.11.0:L7561~L7660 - v2.12.0:L7635~L7734 - master:L7813~L7912 v2.7.1 既有 test_upstream/test/test_torch.py.patch 未包含 test_storage_error 段落 (该段的 NPU 适配未沉淀在 patch 中),本次不改动既有 patch。 测试命令: master:python -m pytest test/test_quantized_storage.py -v ========================== test session starts =========================== platform linux -- Python 3.12.13, pytest-8.3.2, pluggy-1.6.0 -- /workspace/envs/torch-npu-test/bin/python cachedir: .pytest_cache rootdir: /workspace/user_data/pytorch-master configfile: pyproject.toml plugins: xdist-3.6.1 collected 6 items ../workspace/user_data/pytorch-master/test/test_quantized_storage.py::TestQUInt8Storage::test_construct_empty PASSED [ 16%] ../workspace/user_data/pytorch-master/test/test_quantized_storage.py::TestQUInt8Storage::test_construct_with_data PASSED [ 33%] ../workspace/user_data/pytorch-master/test/test_quantized_storage.py::TestQUInt8Storage::test_construct_with_size PASSED [ 50%] ../workspace/user_data/pytorch-master/test/test_quantized_storage.py::TestQUInt8Storage::test_construct_with_wrap_storage PASSED [ 66%] ../workspace/user_data/pytorch-master/test/test_quantized_storage.py::TestQUInt8Storage::test_constructor_errors PASSED [ 83%] ../workspace/user_data/pytorch-master/test/test_quantized_storage.py::TestQUInt8Storage::test_wrap_storage_errors PASSED [100%] ============================ warnings summary ============================ test/test_quantized_storage.py::TestQUInt8Storage::test_construct_empty /workspace/user_data/pytorch-master/test/test_quantized_storage.py:31: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage() storage = torch.QUInt8Storage() -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html ====================== 6 passed, 1 warning in 5.73s ====================== # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43728 | 1 个月前 | |
【API一致性任务】test: Add consistency validation cases for torch.QUInt4x2Storage.dtype on NPU (#3536) Co-authored-by: luoxiaoyan2024<luoxiaoyan202516@gmail.com> # message auto-generated for no-merge-commit merge: !44414 merge api-3536-master into master 【API一致性任务】test: Add consistency validation cases for torch.QUInt4x2Storage.dtype on NPU (#3536) Created-by: luoxiaoyan2024 Commit-by: luoxiaoyan2024 Merged-by: ascend-robot Description: 欢迎加入社区,感谢您对社区的贡献 🎉! # torch.QUInt4x2Storage.dtype 一致性验证用例 说明 关联 issue:https://gitcode.com/Ascend/pytorch/issues/3536 提交分支:api-3536-v2.7.1(目标 base:v2.7.1) 改动文件:test/test_quint4x2_storage_dtype.py(新增,96 行) ### 环境信息 验证在 Ascend 910B3 NPU 服务器的 CANN 8.5.1 容器中进行,torch_npu 分别安装于 PyTorch 2.7.1 / 2.11.0 / 2.12.0 三个版本;并按社区最新验收要求在 **Ascend 950PR**(CANN 9.1.0)环境补充验证(见「运行验证(Ascend 950PR)」);终端运行截图见文末「运行验证」说明与本地交付物。 ### 使用场景及问题 来源任务:https://gitcode.com/Ascend/pytorch/issues/3536 对应 API: torch.QUInt4x2Storage.dtype torch.quint4x2 是 4-bit 无符号整数量化数据类型(每字节打包 2 个元素),其底层连续存储由 torch.QUInt4x2Storage 承载。API 一致性验收要求该存储类的 dtype 类属性**稳定返回** torch.quint4x2,且需在 NPU 环境下验证其取值与 CPU 一致(设备无关)。官方未对该属性建立聚焦的一致性断言,因此需在 test/ 补齐自包含用例。 ### API 功能 torch.QUInt4x2Storage 是支撑量化数据类型 torch.quint4x2 的底层存储类(Storage)。quint4x2 表示每个元素 4 bit、每字节打包 2 个元素的无符号整数量化类型;QUInt4x2Storage 负责以字节数组形式承载这类量化张量的连续存储。 torch.QUInt4x2Storage.dtype 是该存储类的**类级只读属性**,返回该存储所承载的量化数据类型,取值恒为 torch.quint4x2。该属性特性: - **无入参、只读**:不可通过赋值修改;返回值是数据类型对象 torch.quint4x2 自身(identity 一致,is 比较为真)。 - **设备无关**:CPU 与 NPU 环境下取值一致,不随加速器变化。 - **类 / 实例均可访问**:既可通过类 torch.QUInt4x2Storage.dtype 访问,也可通过实例 torch.QUInt4x2Storage().dtype 访问,二者取值相同。 ### PyTorch 官方用例及完整性 在 PyTorch 官方 test/ 目录中检索(master / v2.7.1 / v2.11.0 / v2.12.0),QUInt4x2Storage / quint4x2 仅在量化相关用例中作为被量化张量的底层存储被**间接触及**,没有针对 storage.dtype 取值与量化 dtype 集合归属的聚焦一致性断言: text test/test_quantization.py / test/test_type_promotion.py :quint4x2 仅在量化流程中被引用 test/ :0 处独立断言 QUInt4x2Storage.dtype is torch.quint4x2 因此,社区对 QUInt4x2Storage.dtype 的「取值正确性 + 量化 dtype 归属 + 边界区分」覆盖不充分,需新增自包含一致性用例。 ### NPU 适配分析(含分类判定) QUInt4x2Storage.dtype 是设备无关的类级只读属性,其取值不依赖任何 NPU kernel 或设备特定代码路径;当前 NPU 未单独注册 torch.npu.QUInt4x2Storage 类(curated NPU storage 列表仅覆盖数值 / bool / bfloat16 类存储),昇腾环境导入 torch_npu 后其行为与 CPU 完全一致。本接口无需修改 TorchNPU 实现、无需 NPU 适配 patch。 因此,本 API 归类为 **1.2②:PyTorch 官方社区用例覆盖不充分,且涉及硬件相关存储类接口 → 在 test/ 目录新增一致性验证用例补齐(非修改源码 patch)**。 ### 新增用例设计(功能一致标准覆盖) 新增 test/test_quint4x2_storage_dtype.py,按 API 功能一致标准以等价类 / 边界值覆盖(无数值计算、无入参): - **取值正确性**:torch.QUInt4x2Storage.dtype is torch.quint4x2;且与空存储实例 .dtype 一致。 - **量化 dtype 集合归属**:assertIn 于 {quint8, qint8, qint32, quint4x2}。 - **边界区分**:assertIsNot 于 quint8 / qint8,避免与相邻量化 dtype 混淆。 - **设备无关一致性**:CPU 与 NPU 环境取值一致(torch.npu.is_available() 守卫);若 NPU 注册 torch.npu.QUInt4x2Storage 额外校验其 .dtype 与 .size()。 两个用例 test_cpu_quint4x2_storage_dtype / test_npu_quint4x2_storage_dtype 均带 hasattr 守卫,缺失该存储类的构建会优雅跳过而非报错。 ### 运行验证 验证环境: text 操作系统:Ubuntu 22.04.5 LTS 系统架构:aarch64 昇腾硬件:Ascend 910B3,8 卡,Health 为 OK npu-smi:24.1.0 CANN:8.5.1 Python:3.10(torch_2.7.1 / torch_2.11.0 / torch_2.12.0 验证环境) 在 NPU 环境实跑 python test/test_quint4x2_storage_dtype.py -v,三个版本(2.7.1 / 2.11.0 / 2.12.0)均 Ran 2 tests ... OK,CPU 用例与 NPU 守卫用例**实际执行(非跳过)**: | PyTorch | torch-npu | 检查项 | 失败 | 错误 | 结果 | | ---: | ---: | ---: | ---: | ---: | ---: | | 2.7.1+cpu | 2.7.1.post8 | 2 用例(CPU + NPU 守卫) | 0 | 0 | PASS | | 2.11.0+cu130 | 2.11.0 | 2 用例(CPU + NPU 守卫) | 0 | 0 | PASS | | 2.12.0+cu130 | 2.12.0 | 2 用例(CPU + NPU 守卫) | 0 | 0 | PASS | 三个版本(2.7.1 / 2.11.0 / 2.12.0)终端输出一致,完整日志如下: ``text ========== torch 2.7.1 (torch.QUInt4x2Storage.dtype) ========== $ /root/miniconda3/envs/torch_2.7.1/bin/python /tmp/test_quint4x2_storage_dtype.py -v # torch 2.7.1+cpu / torch_npu 2.7.1.post8 test_cpu_quint4x2_storage_dtype (__main__.TestQUInt4x2StorageDtype) ... /tmp/test_quint4x2_storage_dtype.py:51: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage() self.assertIs(torch.QUInt4x2Storage.dtype, torch.quint4x2) ok test_npu_quint4x2_storage_dtype (__main__.TestQUInt4x2StorageDtype) ... ok ---------------------------------------------------------------------- Ran 2 tests in 0.028s OK ========== torch 2.11.0 (torch.QUInt4x2Storage.dtype) ========== $ /root/miniconda3/envs/torch_2.11.0/bin/python /tmp/test_quint4x2_storage_dtype.py -v # torch 2.11.0+cu130 / torch_npu 2.11.0 test_cpu_quint4x2_storage_dtype (__main__.TestQUInt4x2StorageDtype) ... /tmp/test_quint4x2_storage_dtype.py:51: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage() self.assertIs(torch.QUInt4x2Storage.dtype, torch.quint4x2) ok test_npu_quint4x2_storage_dtype (__main__.TestQUInt4x2StorageDtype) ... ok ---------------------------------------------------------------------- Ran 2 tests in 0.026s OK ========== torch 2.12.0 (torch.QUInt4x2Storage.dtype) ========== $ /root/miniconda3/envs/torch_2.12.0/bin/python /tmp/test_quint4x2_storage_dtype.py -v # torch 2.12.0+cu130 / torch_npu 2.12.0 W0819 01:32:34.165000 32618 root/miniconda3/envs/torch_2.12.0/lib/python3.10/site-packages/torch/_native/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages nvidia-cutlass-dsl and apache-tvm-ffi; missing optional dependency nvidia_cutlass_dsl (importlib.util.find_spec(nvidia_cutlass_dsl) failed) test_cpu_quint4x2_storage_dtype (__main__.TestQUInt4x2StorageDtype) ... /tmp/test_quint4x2_storage_dtype.py:51: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage() self.assertIs(torch.QUInt4x2Storage.dtype, torch.quint4x2) ok test_npu_quint4x2_storage_dtype (__main__.TestQUInt4x2StorageDtype) ... ok ---------------------------------------------------------------------- Ran 2 tests in 0.284s OK `  ### 运行验证(Ascend 950PR 补充验证) 按社区最新验收要求,另在 **Ascend 950PR** 环境实跑同一用例文件 test/test_quint4x2_storage_dtype.py 取证(该环境当前安装 torch_npu 2.12.0;.dtype 为设备无关类属性,跨版本行为一致): text 操作系统:Ubuntu 22.04.5 LTS 系统架构:x86_64 昇腾硬件:Ascend 950PR,1 卡,HBM 128G,Health 为 OK npu-smi:25.7.rc1.6 CANN:9.1.0 Python:3.10.12 torch / torch_npu:2.12.0+cu130 / 2.12.0 实跑结果:Ran 2 tests ... OK,CPU 用例与 NPU 用例**实际执行(非跳过)**: | 环境 | torch | torch-npu | 检查项 | 失败 | 错误 | 结果 | | --- | ---: | ---: | ---: | ---: | ---: | ---: | | Ascend 950PR | 2.12.0+cu130 | 2.12.0 | 2 用例(CPU + NPU) | 0 | 0 | PASS | text $ python3 test_quint4x2_storage_dtype.py -v # 950PR: Ascend950PR / CANN 9.1.0, torch 2.12.0+cu130 / torch_npu 2.12.0 test_cpu_quint4x2_storage_dtype (__main__.TestQUInt4x2StorageDtype) ... /tmp/q4x2_950pr/test_quint4x2_storage_dtype.py:51: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage() self.assertIs(torch.QUInt4x2Storage.dtype, torch.quint4x2) ok test_npu_quint4x2_storage_dtype (__main__.TestQUInt4x2StorageDtype) ... ok ---------------------------------------------------------------------- Ran 2 tests in 0.003s OK  950PR 验证结论与 910B3 三版本一致:torch.QUInt4x2Storage.dtype 在两种昇腾硬件(910B3 / 950PR)与 CANN 8.5.1 / 9.1.0 下取值均为 torch.quint4x2,设备无关性成立。 ### 资料检查 torch.QUInt4x2Storage 为标准量化 storage 类、非私有接口、非缺失 API,依 §2 不纳入 native_apis 资料补齐;其所属量化模块在资料中已有收录。本次新增一致性用例不改变支持状态,无需提交资料 PR。 ### 结论 | 检查项 | 结论 | | --- | --- | | TorchNPU 环境可验证目标 API(.dtype 取值一致) | ✔ | | 接口行为在 NPU 上与 CPU 一致(设备无关) | ✔ | | PyTorch 官方有聚焦 / 完整的 .dtype 一致性用例 | ✘ | | 需要修改 TorchNPU API 实现 | ✘ | | 需要新增 NPU 适配 patch | ✘ | | 需要在 test/` 新增一致性验证用例 | ✔ | | 需要补充正式资料 | ✘ | 欢迎加入社区,感谢您对社区的贡献 🎉! See merge request: Ascend/pytorch!44414 | 1 个月前 | |
test(reductions): note NPU/XLA skip searchsorted non-contiguous UserWarning check. Co-authored-by: Margaret_wangrui<wangrui178@huawei.com> # message auto-generated for no-merge-commit merge: !37092 merge searchsorted_testcase_master into master test(reductions): note NPU/XLA skip searchsorted non-contiguous UserWarning check. Created-by: Margaret_wangrui Commit-by: Margaret_wangrui Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/1910 - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) values_3d_permute = values_3d.permute(2, 1, 0).to(torch.int32) boundaries_permute = values_3d.permute(2, 1, 0).to(torch.float64) values_3d_permute和boundaries_permute在torch_npu中是连续的,不应该在用例中去捕获非连续告警信息 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 .png') # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37092 | 4 个月前 | |
[master][bugfix]cann and pta header mixing bulid bugfix Co-authored-by: Dring<17737727613@163.com> # message auto-generated for no-merge-commit merge: !44990 merge master into master [master][bugfix]cann and pta header mixing bulid bugfix Created-by: Dring Commit-by: Dring Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/3991 - [✕ ] 需求 - [ ✓] 问题单 - [ ✓] issue/工单 - [ ✓] 重构优化 - [✕ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 问题现象: PTA 26.1.0 仓库中的 third_party/acl 头文件来自 CANN 9.1.0,而编译环境安装的是 CANN 9.0.0。当同一个编译单元同时包含两套版本的 ACL 头文件时,会出现类似以下错误:aclmdlRITask 未声明、未定义或类型不匹配 aclmdlRITask 是 CANN 9.1.0 头文件所依赖的定义,但 CANN 9.0.0 对应头文件中不存在该定义或定义不兼容。 根因分析: 1 当前头文件查找路径不统一:PTA 源码中大量使用以下写法 #include "third_party/acl/inc/acl/acl_mdl.h" 因为编译命令中包含 PTA 项目根目录,这种写法会直接命中 PTA 26.1.0 仓库内由 CANN 9.1.0 导入的头文件:torch_npu/third_party/acl/inc/acl/acl_mdl.h 但该头文件内部使用的是标准 SDK 相对路径:#include "acl/acl_base.h" 编译器无法相对 acl_mdl.h 所在目录找到 acl/acl_base.h,因此转而按照全部 -I 目录依次搜索。如果 CANN 9.0.0 的 include 路径排在 PTA 内置 ACL 路径前面,就会命中:CANN-9.0.0/include/acl/acl_base.h 同一个翻译单元最终形成: acl_mdl.h -> PTA third_party 中的 CANN 9.1.0 版本 acl_base.h -> 环境 CANN 9.0.0 版本 这是一种“首层头文件由源码路径固定版本、传递头文件由 -I 顺序选择版本”的混合查找模式。 2 问题不局限于 acl_mdl.h 同样风险存在于所有能够继续 include 其他 CANN 头文件的入口,包括: acl/... aml/... profiling/... graph/... ge/... op_proto/... 因此不能只修复出现错误的某一个头文件,也不能只替换 acl_mdl.h。必须统一整个 CANN 头文件族的查找规则。 修改目标: 修改后需要满足 源码不再包含 third_party/acl/inc/... 这种仓库物理路径。 ACL、AML、profiling 等头文件全部通过统一 include root 查找。 一个编译 target 对 CANN 头文件只选择一套版本。 CANN 9.0.0 环境构建时,首层和传递头文件必须全部命中 CANN 9.0.0。 使用 PTA 内置头文件构建时,首层和传递头文件必须全部命中 PTA 内置的同一套版本。 wheel、libtorch_npu、C++ Extension 和 Inductor/AOT 使用同一目录契约 修改方案: 1、代码中使用 PTA 内置 ACL 头文件的地方,删除 third_party/acl/inc/ 物理路径前缀,统一改成从 include root 查找 2、打包或安装时,把 third_party/acl/inc 下需要公开的目录按原相对结构复制到安装产物的公共 include 根目录 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 cann 9.0.0 + pta 26.1.0的vllm-ascend安装验证成功  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [✓ ] 代码注释完备,正确记录错误日志 - [✕ ] 代码实现进行了返回值、空指针等校验 - [✓ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [✓ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44990 | 1 个月前 | |
fix: support quantized NPU flip dispatch Co-authored-by: hz893<zhanghao491@huawei.com> # message auto-generated for no-merge-commit merge: !36073 merge fix_quantized_flip_master_20260519 into master fix: support quantized NPU flip dispatch Created-by: hz893 Commit-by: hz893 Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 https://gitcode.com/Ascend/pytorch/issues/2207 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 在 QuantizedPrivateUse1 的 codegen 注册中补充 aten::flip,使量化 NPU tensor 能命中 torch_npu 的 quantized helper。 2. 新增 quantized_flip helper:per-tensor 量化场景对 int_repr() 调用普通 NPU aten::flip,复用现有 op_plugin::flip -> aclnnFlip 数据翻转路径,再用原 scale/zero_point 重建 affine quantized tensor。 3. 对齐 CPU/CUDA 行为:sub-byte 量化 dtype 保持不支持报错;per-channel 量化保持 Setting strides is possible only on uniformly quantized tensor 报错。 4. 新增 per-channel quantized flip 报错回归测试。 # 【资料变更】 不涉及。 # 【接口变更】 不涉及。 # 【功能验证】 1. v2.7.1 环境执行 bash ci/build.sh --python=3.11,编译成功并生成 wheel。 2. v2.7.1 环境执行 python -m pytest test_shape_ops.py -v -k test_flip_npu_float32,结果:1 passed。 3. v2.7.1 环境执行 python -m pytest --import-mode=importlib test/test_shape_ops.py -v -k "test_flip_per_channel_quantized_error or test_flip_npu_float32",结果:2 passed。 4. 验证普通 float NPU flip backward 与 CPU 在 dims=(0,)、(1,)、(0, 1)、() 下 forward/grad 均一致;验证 quantized flip 的 autograd 状态和错误行为与 CPU 一致。 5. v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0、master 源分支均执行 git diff --check,无异常。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!36073 | 4 个月前 | |
test: add NPU coverage for torch.testing._internal.common_utils.skipIfRocm Co-authored-by: JfanLiu<1300083451@qq.com> # message auto-generated for no-merge-commit merge: !46599 merge test-skip-if-rocm-master into master test: add NPU coverage for torch.testing._internal.common_utils.skipIfRocm Created-by: JfanLiu Commit-by: JfanLiu Merged-by: ascend-robot Description: # 【合入来源】 > 社区 issue:[Ascend/pytorch #4116](https://gitcode.com/Ascend/pytorch/issues/4116)(原 [Ascend/pytorch #3704](https://gitcode.com/Ascend/pytorch/issues/3704)) - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 按 #4116 审核结论(该 API 对硬件后端有依赖、上游用例不完整,需新增测试用例文件补齐测试场景),新增 test/test_skip_if_rocm.py(仅新增测试,不改动任何实现代码): - 覆盖 torch.testing._internal.common_utils.skipIfRocm 的两种用法:裸装饰器 @skipIfRocm 与带参 @skipIfRocm(msg=...); - 运行路径:NPU 非 ROCm 构建,被装饰的用例正常执行,且不带 __unittest_skip__ 标记; - 跳过路径:TEST_WITH_ROCM 为真时,被装饰用例被 unittest runner 上报为 skipped,reason 为 skipIfRocm: <msg>(默认 msg 与自定义 msg 各覆盖一次); - 装饰动作在 mock.patch(...TEST_WITH_ROCM..., True) 上下文内完成,保证跳过路径判定时机正确;同时兼容各版本实现差异(2.7.1 / 2.11.0 / 2.12.0 在调用期抛 SkipTest,2.13 起类目标在装饰期打 __unittest_skip__ 标记)。 # 【测试方案】 - NPU 实跑:python test/run_test.py test_skip_if_rocm -v,6 个用例应全部通过; - 覆盖 v2.7.1 / v2.11.0 / v2.12.0 / master 四个版本组合,实跑日志随后以评论附上; - 用例仅使用 torch.randn / torch.add 与 unittest 断言,不引入新的算子或大负载。 See merge request: Ascend/pytorch!46599 | 5 天前 | |
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 4 个月前 | |
| 2 年前 | ||
fix: support to_sparse on non-default NPU devices Co-authored-by: hz893<zhanghao491@huawei.com> # message auto-generated for no-merge-commit merge: !35946 merge fix_to_sparse_master into master fix: support to_sparse on non-default NPU devices Created-by: hz893 Commit-by: hz893 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 https://gitcode.com/Ascend/pytorch/issues/2182 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 将 aten::_to_sparse 和 aten::_to_sparse.sparse_dim 加入 NPU supported 注册,避免 dense NPU Tensor 转 sparse 时走 CPU fallback。 2. 新增 NPU 侧 _to_sparse 实现,复用 at::native::dense_to_sparse,使 sparse tensor、indices、values 保持在输入 Tensor 所在 NPU 设备上。 3. 新增非默认 NPU 设备场景 UT,覆盖输入位于 npu:1 时 to_sparse 结果的 device 和数值一致性。 # 【资料变更】 不涉及。 # 【接口变更】 不涉及。 # 【功能验证】 - 已在 v2.7.1 环境完成 torch_npu 编包并安装验证,torch_npu.__version__ 为 2.7.1.post5。 - 已确认 aten::_to_sparse 和 aten::_to_sparse.sparse_dim 的 PrivateUse1 dispatcher 注册到 RegisterNPU.cpp [kernel],不再走 CPU fallback。 - python -m pytest test_ops.py -v -k test_multiple_devices_to_sparse_npu_float32:1 passed。 - python -m pytest test/test_sparse_coo.py -v -k test_sparse_to_sparse_non_default_npu_device:1 passed。 - v2.9.0、v2.10.0、v2.11.0、v2.12.0、master 目标分支已完成 cherry-pick,无冲突;未分别编包验证。 补充验证: - 已在 fix_to_sparse_master 分支完成编译并安装生成的 torch_npu-2.13.0-cp311-cp311-manylinux_2_28_aarch64.whl。 - 通过临时 C++ 扩展直接调用新增 AOT shim aoti_torch_npu__to_sparse,在当前 device 为 npu:0、输入 tensor 位于 npu:1 的场景下验证返回 sparse tensor、indices、values 均保持在 npu:1,且 to_dense() 与输入一致。 - 测试结果:PASS aoti_torch_npu__to_sparse device=npu:1 nnz=3。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35946 | 4 个月前 | |
Skip failing torch official TestCase tests and disable unsupported test cases Co-authored-by: yuhaiyan<yuhaiyan8@huawei.com> Co-authored-by: yuhaiyan8<yuhaiyan8@h-partners.com> # message auto-generated for no-merge-commit merge: !32140 merge cherry-pick-mr-32139-1774073503832-auto into master Skip failing torch official TestCase tests and disable unsupported test cases Created-by: yuhaiyan Commit-by: yuhaiyan;yuhaiyan8 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 暂时跳过失败用例 2. 已提单跟进修复 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32140 | 5 个月前 | |
[test]: add NPU validation cases for torch.UntypedStorage.fill_ and float (issues #3740 #3741) Co-authored-by: AZT<870721918@qq.com> # message auto-generated for no-merge-commit merge: !44758 merge fill-float-fix-master into master [test]: add NPU validation cases for torch.UntypedStorage.fill_ and float (issues #3740 #3741) Created-by: anning-2026 Commit-by: AZT Merged-by: ascend-robot Description: # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue: - [#3740](https://gitcode.com/Ascend/pytorch/issues/3740) — torch.UntypedStorage.fill_ - [#3741](https://gitcode.com/Ascend/pytorch/issues/3741) — torch.UntypedStorage.float # 【修改方案】 本 PR 覆盖 2 个 torch.UntypedStorage 接口的 NPU 一致性测试补齐,在 1 个新增测试文件中新增 13 个用例,不涉及 torch_npu 任何 C++ / Python 代码改动,也不修改 torch_npu 既有 patch。 修改文件(1 个新增): - test/test_storage.py(新增):torch.UntypedStorage.fill_(9 个用例)、torch.UntypedStorage.float(4 个用例) 合计 2 个 API / 13 个用例,全部 NPU 实测通过。 按评审意见补充 fill_ 的边界字节值与非法输入场景: - 边界字节值:fill_(0)、fill_(255)、fill_(127)(uint8 最小/最大/中间值) - 非法输入:fill_(256)(越界截断为 0)、fill_(-1)(负数截断为 255) # 【社区现状与路径依据】 | API | 上游直接功能测试 | 判定 | | --- | --- | --- | | torch.UntypedStorage.fill_ | 无(test_torch.py 无对 UntypedStorage 的 fill_ 直接调用) | 上游未提供直测;新增 NPU 端用例 | | torch.UntypedStorage.float | 无(test_storage_casts 仅覆盖 TypedStorage 的 float,未覆盖 UntypedStorage) | 上游未提供直测;新增 NPU 端用例 | # 【API 功能介绍】 1. **torch.UntypedStorage.fill_(value)**:用给定值填充存储字节内容,返回自身;value 按 uint8 字节范围(0-255)截断。 2. **torch.UntypedStorage.float()**:将存储转换为 float32 TypedStorage(逐字节转 float32)。 # 【测试方案】 1. **fill_**(9 个用例):返回自身、字节填充值、填充 0、空 storage、最小/最大/中间字节值(0/255/127)、越界值(256→0)、负值(-1→255) 2. **float**(4 个用例):返回类型、长度=原始字节数、数据正确性、空 storage # 【测试环境】 - 操作系统:Linux - 昇腾硬件:Ascend NPU - 安装版本:torch 2.12.0、torch_npu 2.12.0 - 测试分支:本 PR base 为 master # 【测试命令】 bash cd <repo_root> python -u test/test_storage.py -v # 【测试日志】(基于当前 commit + Ascend NPU 实跑) text test_fill_byte_value ... ok test_fill_empty ... ok test_fill_max_byte_value ... ok test_fill_mid_byte_value ... ok test_fill_min_byte_value ... ok test_fill_negative_value ... ok test_fill_out_of_range_high ... ok test_fill_returns_self ... ok test_fill_zero ... ok test_float_data_correctness ... ok test_float_empty ... ok test_float_length_equals_nbytes ... ok test_float_returns_typed_storage ... ok ---------------------------------------------------------------------- Ran 13 tests in 0.957s OK **A5验证:**  # 【资料补齐检查结论】 torch.UntypedStorage.fill_ 与 torch.UntypedStorage.float 在 docs/zh/api/native_api 版本表 torch-Storage.md 中已记录且支持状态正确,无需新增资料。 See merge request: Ascend/pytorch!44758 | 15 天前 | |
test: add torch.UntypedStorage.copy_ validation cases Co-authored-by: SS_RR<1445229659@qq.com> # message auto-generated for no-merge-commit merge: !44466 merge test-untyped-storage-copy-validation-cases-master into master test: add torch.UntypedStorage.copy_ validation cases Created-by: yuhuan2580 Commit-by: SS_RR Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 关联任务issue: https://gitcode.com/Ascend/pytorch/issues/3732 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 torch.UntypedStorage.copy_ PyTorch 官方社区未针对 torch.UntypedStorage.copy_ 编写直接独立测试:全量检索 test 目录仅 test_subclass.py 中有一处异常路径调用(断言在无效 python storage 上调用 copy_ 抛 RuntimeError),正常路径仅被 tensor.copy_ 间接覆盖,因此自行编写用例并提交到 test 目录。 该 API 为 torch._C.StorageBase 的 C++ 绑定方法,设备感知但属框架层实现;torch_npu 序列化路径(torch_npu/utils/storage.py)已实际调用 UntypedStorage.copy_,NPU 上可直接运行,无需代码修改。 新增 test/test_storage_copy_.py,验证 copy_ 在同设备(CPU/NPU)、跨设备(CPU→NPU、NPU→CPU)、non_blocking、空 storage、size 不匹配报错及 TypedStorage 转发路径下的行为。 # 【资料变更】 不涉及文档修改。docs 各版本(pytorch_2-7-1 / 2-11-0 / 2-12-0 / 2-13-0)的 torch-Storage.md 均已收录 torch.UntypedStorage.copy_(原生文档链接在第 1408 行),支持状态为 Atlas A2/A3 ✔、Ascend 950DT ✘,表述正确,无需修改。本次提交仅补充测试用例,不涉及资料变更。 # 【接口变更】 不涉及 # 【功能介绍】 torch.UntypedStorage.copy_ 将 source storage 的数据复制到当前 storage,支持 non_blocking 参数,复制完成后返回 self。作为 torch._C.StorageBase 的底层存储复制方法,用于 storage 级数据搬运,tensor.copy_ 内部亦复用该路径。 # 【功能验证】 test_storage_copy_.py (torch.UntypedStorage.copy_) - test_copy_same_device_cpu — CPU 同设备复制,返回值与内容校验 - test_copy_same_device_npu — NPU 同设备复制,device 与内容校验 - test_copy_cpu_to_npu — CPU→NPU 跨设备复制 - test_copy_npu_to_cpu — NPU→CPU 跨设备复制 - test_copy_non_blocking — non_blocking=True 非阻塞路径 - test_copy_empty — 空 storage 复制 - test_copy_size_mismatch — size 不匹配抛 RuntimeError - test_copy_typed_storage_forwarding — TypedStorage.copy_ 转发到 UntypedStorage.copy_ 运行命令(master): python -m pytest /workspace/user_data/pytorch-master/test/test_storage_copy_.py -x -q 运行结果: `` 472a66bedabe# python -m pytest /workspace/user_data/pytorch-master/test/test_storage_copy_.py -x -q ........ [100%] ================================================ warnings summary ================================================= ../usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: 14 warnings /usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: DeprecationWarning: torch.jit.script_method is deprecated. Please switch to torch.compile or torch.export. warnings.warn( test/test_storage_copy_.py::TestUntypedStorageCopy::test_copy_typed_storage_forwarding /workspace/user_data/pytorch-master/test/test_storage_copy_.py:85: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage() src = torch.TypedStorage([1, 2, 3], dtype=torch.float32) -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html 8 passed, 15 warnings in 8.36s `` # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44466 | 1 个月前 | |
feat: support dynamic task queue enable mode switching Co-authored-by: nomiz<1606135114@qq.com> # message auto-generated for no-merge-commit merge: !45296 merge task_queue_master into master feat: support dynamic task queue enable mode switching Created-by: nomiz Commit-by: nomiz Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> https://gitcode.com/Ascend/pytorch/issues/3678 # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) Python侧灵活控制taskqueue设置的能力,具体为: (1) 新增Python接口用户设置和获取taskqueue状态值(一个原子变量,默认-1),设置时需要清queue; (2) 在get_task_enable的公共接口中,先读取该全局变量的值,如果为非-1,则以该值的结果为准,不再从环境变量读取; (3) 环境变量的读取仍然是一次性的返回常量,保证默认状态下的性能 python # 设置模式 torch.npu.set_task_queue_enable(0) # 关闭 task queue torch.npu.set_task_queue_enable(1) # Level 1 优化 (默认) torch.npu.set_task_queue_enable(2) # Level 2 优化 (纯推理) # 查询当前模式 mode = torch.npu.get_task_queue_enable() # 返回 0/1/2 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 是,新增接口set_task_queue_enable和get_task_queue_enable # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 ut测试验证结果  RL模型修改前后性能验证无劣化  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!45296 | 1 个月前 | |
| 2 年前 | ||
[test][master] add NPU validation cases for torch.Tensor.map_ and torch.Tensor.module_load (issues #2720 #2722) Co-authored-by: lele130<20230105101@stu.lzjtu.edu.cn> # message auto-generated for no-merge-commit merge: !41655 merge test-map-module-load-master into master [test][master] add NPU validation cases for torch.Tensor.map_ and torch.Tensor.module_load (issues #2720 #2722) Created-by: lele130 Commit-by: lele130 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区 issue,请关联 issue 链接**</font> > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部 issue 等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue: - [#2720](https://gitcode.com/Ascend/pytorch/issues/2720) — torch.Tensor.map_(API 一致性验证) - [#2722](https://gitcode.com/Ascend/pytorch/issues/2722) — torch.Tensor.module_load(API 一致性验证) # 【修改方案】 本 PR 为 torch.Tensor.map_ 和 torch.Tensor.module_load 两个 API 在 NPU 场景下补充一致性验证用例。PyTorch 社区缺少针对这两个 API 的直接、集中测试,按规范 1.3(自写用例)新增测试文件到 test/ 目录。 修改文件: - test/test_tensor_map_.py(新增):覆盖 torch.Tensor.map_(3 个用例) - test/test_tensor_module_load.py(新增):覆盖 torch.Tensor.module_load(5 个用例) 合计 8 个用例。不涉及 torch_npu 任何 C++/Python 代码改动。 # 【API 功能介绍】 ## 1. torch.Tensor.map_(tensor, callable) → Tensor 对 self 和给定 tensor 的每个元素应用 callable,结果存回 self tensor。两个 tensor 必须可广播。 - **callable 签名**:def callable(a, b) -> number - **实现位置**:torch/_tensor.py,底层调用 at::map kernel - **NPU 支持情况**:NPU 上不可用(TypeError: map_ is only implemented on CPU tensors),社区 CUDA 同样不支持 - **测试覆盖**:CPU 正常路径(2 用例)+ NPU 异常断言(1 用例) ## 2. torch.Tensor.module_load(other, assign=False) → Tensor 定义如何将 other 转换后加载到 self 中,用于 load_state_dict() 的 swap_tensors 路径。当 get_swap_module_params_on_conversion() 为 True 时使用。 - **实现**:self.copy_(other).detach()(assign=False)或 other.detach()(assign=True) - **实现位置**:torch/_tensor.py - **NPU 支持情况**:非计算类 API,基于 copy_ 和 detach 实现,NPU 上直接可用,与数据类型无关 - **测试覆盖**:NPU tensor 上 5 个用例(返回值、dtype 保持、assign=True、destination 更新、detach 语义) # 【上游社区用例情况】 ## torch.Tensor.map_ PyTorch 社区 test/test_torch.py::test_broadcast 包含 "map",但显式跳过 CUDA 设备。NPU 行为与 CUDA 一致。 ## torch.Tensor.module_load 社区无直接测试用例,仅通过 load_state_dict 间接覆盖。 # 【测试环境】 - 操作系统:Linux 4.19.90-2102.2.0.0068.3.ctl2.aarch64 - 昇腾硬件:Ascend NPU(Ascend910B2) - 安装版本:torch 2.12.0 + torch_npu 2.12.0 - 测试分支:master # 【测试日志】 text $ python -u test/test_tensor_map_.py -v test_map_applies_callable ... ok test_map_raises_on_npu_tensor ... ok test_map_uses_destination_values ... ok ---------------------------------------------------------------------- Ran 3 tests in 0.800s OK $ python -u test/test_tensor_module_load.py -v test_module_load_assign_true ... ok test_module_load_keeps_dest_dtype ... ok test_module_load_returns_detached_tensor ... ok test_module_load_returns_source_values ... ok test_module_load_updates_destination ... ok ---------------------------------------------------------------------- Ran 5 tests in 0.772s OK # 【资料补齐检查结论】 - torch.Tensor.map_:docs/zh/native_apis 中已有该 API 记录。map_ 在 NPU 上不可用,社区 CUDA 同样不支持,无需补充资料。 - torch.Tensor.module_load:docs/zh/native_apis 中已有该 API 记录。非计算类 API,与数据类型无关,无需补充资料。 Fixes #2720, Fixes #2722 See merge request: Ascend/pytorch!41655 | 1 个月前 | |
[test][master] add NPU validation cases for torch.Tensor.map_ and torch.Tensor.module_load (issues #2720 #2722) Co-authored-by: lele130<20230105101@stu.lzjtu.edu.cn> # message auto-generated for no-merge-commit merge: !41655 merge test-map-module-load-master into master [test][master] add NPU validation cases for torch.Tensor.map_ and torch.Tensor.module_load (issues #2720 #2722) Created-by: lele130 Commit-by: lele130 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区 issue,请关联 issue 链接**</font> > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部 issue 等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue: - [#2720](https://gitcode.com/Ascend/pytorch/issues/2720) — torch.Tensor.map_(API 一致性验证) - [#2722](https://gitcode.com/Ascend/pytorch/issues/2722) — torch.Tensor.module_load(API 一致性验证) # 【修改方案】 本 PR 为 torch.Tensor.map_ 和 torch.Tensor.module_load 两个 API 在 NPU 场景下补充一致性验证用例。PyTorch 社区缺少针对这两个 API 的直接、集中测试,按规范 1.3(自写用例)新增测试文件到 test/ 目录。 修改文件: - test/test_tensor_map_.py(新增):覆盖 torch.Tensor.map_(3 个用例) - test/test_tensor_module_load.py(新增):覆盖 torch.Tensor.module_load(5 个用例) 合计 8 个用例。不涉及 torch_npu 任何 C++/Python 代码改动。 # 【API 功能介绍】 ## 1. torch.Tensor.map_(tensor, callable) → Tensor 对 self 和给定 tensor 的每个元素应用 callable,结果存回 self tensor。两个 tensor 必须可广播。 - **callable 签名**:def callable(a, b) -> number - **实现位置**:torch/_tensor.py,底层调用 at::map kernel - **NPU 支持情况**:NPU 上不可用(TypeError: map_ is only implemented on CPU tensors),社区 CUDA 同样不支持 - **测试覆盖**:CPU 正常路径(2 用例)+ NPU 异常断言(1 用例) ## 2. torch.Tensor.module_load(other, assign=False) → Tensor 定义如何将 other 转换后加载到 self 中,用于 load_state_dict() 的 swap_tensors 路径。当 get_swap_module_params_on_conversion() 为 True 时使用。 - **实现**:self.copy_(other).detach()(assign=False)或 other.detach()(assign=True) - **实现位置**:torch/_tensor.py - **NPU 支持情况**:非计算类 API,基于 copy_ 和 detach 实现,NPU 上直接可用,与数据类型无关 - **测试覆盖**:NPU tensor 上 5 个用例(返回值、dtype 保持、assign=True、destination 更新、detach 语义) # 【上游社区用例情况】 ## torch.Tensor.map_ PyTorch 社区 test/test_torch.py::test_broadcast 包含 "map",但显式跳过 CUDA 设备。NPU 行为与 CUDA 一致。 ## torch.Tensor.module_load 社区无直接测试用例,仅通过 load_state_dict 间接覆盖。 # 【测试环境】 - 操作系统:Linux 4.19.90-2102.2.0.0068.3.ctl2.aarch64 - 昇腾硬件:Ascend NPU(Ascend910B2) - 安装版本:torch 2.12.0 + torch_npu 2.12.0 - 测试分支:master # 【测试日志】 text $ python -u test/test_tensor_map_.py -v test_map_applies_callable ... ok test_map_raises_on_npu_tensor ... ok test_map_uses_destination_values ... ok ---------------------------------------------------------------------- Ran 3 tests in 0.800s OK $ python -u test/test_tensor_module_load.py -v test_module_load_assign_true ... ok test_module_load_keeps_dest_dtype ... ok test_module_load_returns_detached_tensor ... ok test_module_load_returns_source_values ... ok test_module_load_updates_destination ... ok ---------------------------------------------------------------------- Ran 5 tests in 0.772s OK # 【资料补齐检查结论】 - torch.Tensor.map_:docs/zh/native_apis 中已有该 API 记录。map_ 在 NPU 上不可用,社区 CUDA 同样不支持,无需补充资料。 - torch.Tensor.module_load:docs/zh/native_apis 中已有该 API 记录。非计算类 API,与数据类型无关,无需补充资料。 Fixes #2720, Fixes #2722 See merge request: Ascend/pytorch!41655 | 1 个月前 | |
test(tensor): add Tensor.__setstate__ NPU coverage Co-authored-by: coconut<zhehanzhao7@gmail.com> # message auto-generated for no-merge-commit merge: !42442 merge api-completion-tensor-setstate-master into master test(tensor): add Tensor.__setstate__ NPU coverage Created-by: coconut77 Commit-by: coconut Merged-by: ascend-robot Description: # 【合入来源】 ## 关联 issue - 任务 Issue:https://gitcode.com/Ascend/pytorch/issues/2677 - 说明性 Issue:https://gitcode.com/Ascend/pytorch/issues/4679 # 【修改方案】 ## 修改说明 本 PR 在 master 分支新增 test/test_tensor_setstate_api_completion.py,直接验证 torch.Tensor.__setstate__ 的核心行为: - 叶子 Tensor 调用 __setstate__ 后可以恢复 requires_grad 状态; - 非叶子 Tensor 调用 __setstate__ 时抛出与原生 PyTorch 一致的异常; - 测试通过 torch.accelerator.current_accelerator() 选择当前设备,NPU 环境实际使用 NPU。 修改文件: ~~~text test/test_tensor_setstate_api_completion.py ~~~ ## 涉及 API torch.Tensor.__setstate__ ## 社区用例覆盖情况 PyTorch 社区用例主要通过序列化、JIT 或 pickle 等间接路径触发 __setstate__,没有面向该接口的直接行为测试。因此本 PR 增加直接 API 调用覆盖,验证 Ascend NPU 上的行为与原生 PyTorch 保持一致。 ## NPU 适配 测试不使用 transfer_to_npu,也不包含 tensor.cuda()、torch.cuda.* 或 device="cuda" 等 CUDA 迁移路径。 ~~~python device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu" ~~~ 无加速器环境回退到 CPU 仅用于保证测试文件可导入;NPU 环境通过 accelerator=npu 和 NPU_AVAILABLE=True 确认实际走 NPU 路径。 ## 测试核心逻辑 ~~~python tensor = torch.ones(2, device=device_type) self.assertFalse(tensor.requires_grad) tensor.__setstate__((True, None, None)) self.assertTrue(tensor.requires_grad) with self.assertRaisesRegex( RuntimeError, "__setstate__ can be only called on leaf Tensors" ): (tensor + 1).__setstate__((False, None, None)) ~~~ # 【资料变更】 已通过独立 doc PR 在 docs/zh/api/native_api/private_apis.md 中补充 API 记录。 # 【接口变更】 不涉及 API 签名、实现或行为变更,本 PR 仅补充测试覆盖。 # 【功能验证】 ## 910B3 测试结果 ~~~text COMMAND: /workspace/venvs/torch2100/bin/python /workspace/tensor_setstate_910B3_tests_20260908/test_tensor_setstate_api_completion_v271.py -v PWD: /tmp DATE: 2026-09-08 14:13:42 CST test_tensor_setstate (__main__.TestTensorSetstateApiCompletion.test_tensor_setstate) ... ok ---------------------------------------------------------------------- Ran 1 test in 1.411s OK EXIT_CODE: 0 ~~~ 910B3 日志目录: ~~~text /workspace/tensor_setstate_910B3_logs_20260908/master_910B3_complete_v2.log ~~~ ## Ascend950PR 验证说明 Ascend950PR 已使用实际保存的 test_tensor_setstate_api_completion.py 文件完成 v2.7.1、v2.11.0 和 v2.12.0 验证。三个版本均确认 ACCELERATOR: npu、NPU_AVAILABLE: True、OK 和退出码 0。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常(PR 创建并通过 CI 后勾选) See merge request: Ascend/pytorch!42442 | 16 天前 | |
【API一致性任务】test: add NPU coverage for torch.Tensor.unsqueeze_ Co-authored-by: liujiacheng_2026<laneljc@qq.com> # message auto-generated for no-merge-commit merge: !45126 merge task04-unsqueeze-master into master 【API一致性任务】test: add NPU coverage for torch.Tensor.unsqueeze_ Created-by: liujiacheng_2026 Commit-by: liujiacheng_2026 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 https://gitcode.com/Ascend/pytorch-ecosystem/issues/209 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 ## 一、API 功能 torch.Tensor.unsqueeze_(dim) 在原 Tensor 上创建增加一个维度的 view,返回同一个 Tensor 对象并保留底层存储和 autograd 关系。dim 支持正、负维度索引;超出 [-input.dim() - 1, input.dim()] 时抛出 IndexError。 ## 二、PyTorch 社区用例情况与新增必要性 PyTorch main 在 test/test_view_ops.py::TestViewOps::test_unsqueeze_inplace_view(源码第 751-758 行)中验证了 dim=1 的 inplace view 别名关系,并在 test/test_view_ops.py::TestViewOps::test_unsqueeze(源码第 1525-1536 行)中验证了 dim=2 的形状结果;test/test_autograd.py 第 10233 行还将 unsqueeze_ 纳入 inplace view 操作检查。 现有社区用例未完整覆盖负维度、标量边界、非连续 view 的存储别名、inplace autograd 梯度及非法维度异常路径。因此本 PR 新增: text test/test_tensor_unsqueeze_api.py::TestTensorUnsqueezeAPIs 用例全部在当前加速器设备上创建 Tensor,覆盖正负维度、标量 dim=0/-1、非连续 view 的修改传播、需要梯度的非叶子 Tensor,以及 dim=-4/3 的异常路径。不修改 API 实现。 # 【资料变更】 无资料文件变更。Tensor.unsqueeze_ 已存在于 PyTorch 2.7、2.11、2.12、2.13 原生文档及 Ascend 原生 API 支持表中。 # 【接口变更】 无客户可见接口变更,仅新增直接测试。 # 【功能验证】 NPU 验证命令及输出: text /workspace/torch-npu-envs/bin/torch-npu-python 2.12.0 /workspace/ascend-pytorch/master/test/test_tensor_unsqueeze_api.py -v test_unsqueeze_autograd ... ok test_unsqueeze_dimensions ... ok test_unsqueeze_invalid_dimensions ... ok test_unsqueeze_view_alias ... ok ---------------------------------------------------------------------- Ran 4 tests in 1.517s OK 运行过程中出现一个非致命的 CANN/NPU 内存对齐警告,测试结果仍为 OK。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!45126 | 1 个月前 | |
test: add isclose equal_nan broadcast regression test Co-authored-by: xiu_21<caixiuxiu1@huawei.com> # message auto-generated for no-merge-commit merge: !39507 merge master into master test: add isclose equal_nan broadcast regression test Created-by: xiu_21 Commit-by: xiu_21 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 新增isclose equal_nan广播场景回归测试 问题修复PR:https://gitcode.com/Ascend/op-plugin/pull/5250 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!39507 | 3 个月前 | |
Update test_torch.py Co-authored-by: yuhaiyan<yuhaiyan8@huawei.com> # message auto-generated for no-merge-commit merge: !27371 merge master-dev2 into master Update test_torch.py Created-by: yuhaiyan Commit-by: yuhaiyan Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!27371 | 10 个月前 | |
[test][master] add NPU validation cases for torch._C and torch._check APIs (issues #2674 #2675 #2676 #2764) Co-authored-by: anning-2026<870721918@qq.com> # message auto-generated for no-merge-commit merge: !43181 merge test/api-consistency-torch-c-master into master [test][master] add NPU validation cases for torch._C and torch._check APIs (issues #2674 #2675 #2676 #2764) Created-by: anning-2026 Commit-by: anning-2026 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue: - [#2764](https://gitcode.com/Ascend/pytorch/issues/2764) — torch._C._nn.flatten_dense_tensors(任务编号 #42) - [#2674](https://gitcode.com/Ascend/pytorch/issues/2674) — torch._C.DisableTorchFunction(任务编号 #52) - [#2675](https://gitcode.com/Ascend/pytorch/issues/2675) — torch._C.DisableTorchFunctionSubclass(任务编号 #53) - [#2676](https://gitcode.com/Ascend/pytorch/issues/2676) — torch._check_is_size(任务编号 #54) 注:任务 #39 torch._C._jit_set_texpr_fuser_enabled 已在 issue [#2818](https://gitcode.com/Ascend/pytorch/issues/2818) 中闭环,不纳入本 PR。 # 【修改方案】 本 PR 覆盖 4 个 torch._C.* 与 torch.* 私有接口的 NPU 一致性测试补齐,在 2 个新增测试文件中新增 25 个用例,不涉及 torch_npu 任何 C++ / Python 代码改动,也不修改 torch_npu 既有 patch。 修改文件(2 个新增): - test/test_torch_c_apis.py(新增):torch._C._nn.flatten_dense_tensors(8 个用例)、torch._C.DisableTorchFunction(2 个用例)、torch._C.DisableTorchFunctionSubclass(2 个用例),合计 12 个用例 - test/test_torch_check.py(新增):torch._check_is_size(13 个用例) 合计 4 个 API / 25 个用例,全部 NPU 实测通过。 # 【社区现状与路径依据】 针对 4 个新增用例的 API,PyTorch 上游 pytorch/pytorch 仓库的检索结论如下(git grep -ln <API> -- 'test/**.py',ref 取 master HEAD): | API | 上游直接功能测试 | 判定 | | --- | --- | --- | | torch._C._nn.flatten_dense_tensors | 无(仅 test/functorch/test_vmap_registrations.py 中作为字符串注册到 op 列表) | 上游未提供 Python 直测;新增 NPU 端 smoke 用例 | | torch._C.DisableTorchFunction | 无(test/test_overrides.py、test/dynamo/test_modes.py 中均为 use site) | 上游无独立功能覆盖;新增 dispatch 暂停/恢复用例 | | torch._C.DisableTorchFunctionSubclass | 无(同上) | 上游无独立功能覆盖;新增 Subclass 变体用例 | | torch._check_is_size | 无直接功能测试 | 上游未提供正向功能测试;新增正常/异常/max 用例 | # 【API 功能介绍】 1. **torch._C._nn.flatten_dense_tensors(tensors)**:把一组同 dtype/device 的张量 flatten 后 concatenate 成一个连续 1D 张量。 2. **torch._C.DisableTorchFunction**:上下文管理器,临时禁用 __torch_function__ 分发链路。 3. **torch._C.DisableTorchFunctionSubclass**:同上,只禁用 subclass 的 __torch_function__。 4. **torch._check_is_size(i, max=None)**:检查整数 i 是否为合法 size(>=0),否则抛 RuntimeError。 # 【测试方案】 4 个被覆盖的 API 的用例设计: 1. **torch._C._nn.flatten_dense_tensors**(8 个用例):正常 flatten、单张量、空序列、tuple、非 Tensor 元素、device 不一致 2. **torch._C.DisableTorchFunction**(2 个用例):context 内 dispatch 暂停/恢复 3. **torch._C.DisableTorchFunctionSubclass**(2 个用例):同上的 Subclass 变体 4. **torch._check_is_size**(13 个用例):正常值、负值越界、max 边界、message 参数、非法类型 # 【测试环境】 - 操作系统:Linux 4.19.90-2102.2.0.0068.3.ctl2.aarch64 - 昇腾硬件:Ascend910B2(torch.npu.device_count() == 2) - CANN 软件版本:cann-8.5.1 - Python:3.11.14 - 安装版本:torch 2.12.0、torch_npu 2.12.0 - 测试分支:本 PR base 为 master # 【测试命令】 bash cd <repo_root> python -u test/test_torch_c_apis.py -v python -u test/test_torch_check.py -v # 【测试日志】(基于当前 commit + Ascend NPU 实跑) text === test_torch_c_apis.py === test_disables_torch_function_on_subclass ... ok test_op_inside_disable_returns_plain_tensor ... ok test_disables_torch_function_subclass_on_subclass ... ok test_op_inside_disable_subclass_returns_plain_tensor ... ok test_concatenated_values_match_input_order ... ok test_concatenates_size_1_with_size_2 ... ok test_flatten_empty_list_raises_runtime_error ... ok test_flatten_raises_for_mismatched_device ... ok test_flatten_raises_for_non_tensor_element ... ok test_flatten_single_tensor ... ok test_flatten_tuple_input ... ok test_flattens_2d_tensors_to_1d_concat ... ok ---------------------------------------------------------------------- Ran 12 tests in 1.581s OK === test_torch_check.py === test_check_tensor_size_value ... ok test_fails_above_max_bound ... ok test_message_callable_produces_custom_error ... ok test_message_explicit_none ... ok test_message_format_string ... ok test_message_omitted ... ok test_passes_at_max_equal_i ... ok test_passes_for_non_negative_int ... ok test_passes_with_explicit_max_none ... ok test_passes_within_max_bound ... ok test_raises_for_invalid_max_type ... ok test_raises_for_negative_int ... ok test_raises_for_non_int_type ... ok ---------------------------------------------------------------------- Ran 13 tests in 1.494s OK 合计 Ran 25 tests, OK。 # 【资料补齐检查结论】 4 个 API 均为 PyTorch 私有接口(_ 前缀),按任务规范"PyTorch 私有接口不需要补充资料"原则,均跳过。 See merge request: Ascend/pytorch!43181 | 2 个月前 | |
[test][master] add NPU validation cases for torch._C and torch._check APIs (issues #2674 #2675 #2676 #2764) Co-authored-by: anning-2026<870721918@qq.com> # message auto-generated for no-merge-commit merge: !43181 merge test/api-consistency-torch-c-master into master [test][master] add NPU validation cases for torch._C and torch._check APIs (issues #2674 #2675 #2676 #2764) Created-by: anning-2026 Commit-by: anning-2026 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue: - [#2764](https://gitcode.com/Ascend/pytorch/issues/2764) — torch._C._nn.flatten_dense_tensors(任务编号 #42) - [#2674](https://gitcode.com/Ascend/pytorch/issues/2674) — torch._C.DisableTorchFunction(任务编号 #52) - [#2675](https://gitcode.com/Ascend/pytorch/issues/2675) — torch._C.DisableTorchFunctionSubclass(任务编号 #53) - [#2676](https://gitcode.com/Ascend/pytorch/issues/2676) — torch._check_is_size(任务编号 #54) 注:任务 #39 torch._C._jit_set_texpr_fuser_enabled 已在 issue [#2818](https://gitcode.com/Ascend/pytorch/issues/2818) 中闭环,不纳入本 PR。 # 【修改方案】 本 PR 覆盖 4 个 torch._C.* 与 torch.* 私有接口的 NPU 一致性测试补齐,在 2 个新增测试文件中新增 25 个用例,不涉及 torch_npu 任何 C++ / Python 代码改动,也不修改 torch_npu 既有 patch。 修改文件(2 个新增): - test/test_torch_c_apis.py(新增):torch._C._nn.flatten_dense_tensors(8 个用例)、torch._C.DisableTorchFunction(2 个用例)、torch._C.DisableTorchFunctionSubclass(2 个用例),合计 12 个用例 - test/test_torch_check.py(新增):torch._check_is_size(13 个用例) 合计 4 个 API / 25 个用例,全部 NPU 实测通过。 # 【社区现状与路径依据】 针对 4 个新增用例的 API,PyTorch 上游 pytorch/pytorch 仓库的检索结论如下(git grep -ln <API> -- 'test/**.py',ref 取 master HEAD): | API | 上游直接功能测试 | 判定 | | --- | --- | --- | | torch._C._nn.flatten_dense_tensors | 无(仅 test/functorch/test_vmap_registrations.py 中作为字符串注册到 op 列表) | 上游未提供 Python 直测;新增 NPU 端 smoke 用例 | | torch._C.DisableTorchFunction | 无(test/test_overrides.py、test/dynamo/test_modes.py 中均为 use site) | 上游无独立功能覆盖;新增 dispatch 暂停/恢复用例 | | torch._C.DisableTorchFunctionSubclass | 无(同上) | 上游无独立功能覆盖;新增 Subclass 变体用例 | | torch._check_is_size | 无直接功能测试 | 上游未提供正向功能测试;新增正常/异常/max 用例 | # 【API 功能介绍】 1. **torch._C._nn.flatten_dense_tensors(tensors)**:把一组同 dtype/device 的张量 flatten 后 concatenate 成一个连续 1D 张量。 2. **torch._C.DisableTorchFunction**:上下文管理器,临时禁用 __torch_function__ 分发链路。 3. **torch._C.DisableTorchFunctionSubclass**:同上,只禁用 subclass 的 __torch_function__。 4. **torch._check_is_size(i, max=None)**:检查整数 i 是否为合法 size(>=0),否则抛 RuntimeError。 # 【测试方案】 4 个被覆盖的 API 的用例设计: 1. **torch._C._nn.flatten_dense_tensors**(8 个用例):正常 flatten、单张量、空序列、tuple、非 Tensor 元素、device 不一致 2. **torch._C.DisableTorchFunction**(2 个用例):context 内 dispatch 暂停/恢复 3. **torch._C.DisableTorchFunctionSubclass**(2 个用例):同上的 Subclass 变体 4. **torch._check_is_size**(13 个用例):正常值、负值越界、max 边界、message 参数、非法类型 # 【测试环境】 - 操作系统:Linux 4.19.90-2102.2.0.0068.3.ctl2.aarch64 - 昇腾硬件:Ascend910B2(torch.npu.device_count() == 2) - CANN 软件版本:cann-8.5.1 - Python:3.11.14 - 安装版本:torch 2.12.0、torch_npu 2.12.0 - 测试分支:本 PR base 为 master # 【测试命令】 bash cd <repo_root> python -u test/test_torch_c_apis.py -v python -u test/test_torch_check.py -v # 【测试日志】(基于当前 commit + Ascend NPU 实跑) text === test_torch_c_apis.py === test_disables_torch_function_on_subclass ... ok test_op_inside_disable_returns_plain_tensor ... ok test_disables_torch_function_subclass_on_subclass ... ok test_op_inside_disable_subclass_returns_plain_tensor ... ok test_concatenated_values_match_input_order ... ok test_concatenates_size_1_with_size_2 ... ok test_flatten_empty_list_raises_runtime_error ... ok test_flatten_raises_for_mismatched_device ... ok test_flatten_raises_for_non_tensor_element ... ok test_flatten_single_tensor ... ok test_flatten_tuple_input ... ok test_flattens_2d_tensors_to_1d_concat ... ok ---------------------------------------------------------------------- Ran 12 tests in 1.581s OK === test_torch_check.py === test_check_tensor_size_value ... ok test_fails_above_max_bound ... ok test_message_callable_produces_custom_error ... ok test_message_explicit_none ... ok test_message_format_string ... ok test_message_omitted ... ok test_passes_at_max_equal_i ... ok test_passes_for_non_negative_int ... ok test_passes_with_explicit_max_none ... ok test_passes_within_max_bound ... ok test_raises_for_invalid_max_type ... ok test_raises_for_negative_int ... ok test_raises_for_non_int_type ... ok ---------------------------------------------------------------------- Ran 13 tests in 1.494s OK 合计 Ran 25 tests, OK。 # 【资料补齐检查结论】 4 个 API 均为 PyTorch 私有接口(_ 前缀),按任务规范"PyTorch 私有接口不需要补充资料"原则,均跳过。 See merge request: Ascend/pytorch!43181 | 2 个月前 | |
test: add torch.__getattribute__ API validation Co-authored-by: 2490136803<2490136803@qq.com> # message auto-generated for no-merge-commit merge: !41419 merge intern/test-torch-getattribute-master into master test: add torch.__getattribute__ API validation Created-by: zhouzirui-2026 Commit-by: 2490136803 Merged-by: ascend-robot Description: # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue: - 任务 issue:https://gitcode.com/Ascend/pytorch/issues/2734 # 【修改方案】 本 PR 新增 test/test_torch_getattribute_api.py,补充 torch.__getattribute__ 在 torch-npu 环境下的 API 一致性验证用例。 该 API 是 Python module 对象的属性访问入口,用于从 torch module 上按名称读取属性。经检查,PyTorch 官方未提供 torch.__getattribute__ 的独立专项测试,torch-npu 当前 test 和 test_upstream 目录中也未发现该 API 的专项测试。按照指导规范,本场景属于“PyTorch 官方社区无用例”,因此在 torch-npu test 目录补充自写测试。 任务 API 功能、上游社区用例情况与本 PR 处理方式如下: | API | 功能说明 | 上游社区用例 / 覆盖情况 | 本 PR 处理 | | --- | --- | --- | --- | | torch.__getattribute__ | Python module 属性访问入口,用于按名称读取 torch module 上的属性。 | 未检索到 PyTorch 官方直接专项测试;torch-npu 现有 test / test_upstream 目录中也未发现专项测试。 | 新增 test/test_torch_getattribute_api.py,验证已有属性读取、动态属性读取和异常路径。 | 主要开发思路: 1. 先确认 torch.__getattribute__ 在当前多版本 torch-npu 环境中存在,且基础行为与 Python module 属性访问语义一致。 2. 复查 PyTorch 官方测试目录,未发现直接覆盖 torch.__getattribute__ 的独立专项测试。 3. 复查 torch-npu 当前仓库 test 和 test_upstream 目录,未发现该 API 的现有专项测试。 4. 该 API 不涉及 Tensor 输入,不存在需要迁移到 NPU Tensor 的适配点,因此不需要 test_upstream patch。 5. 该 API 属于顶层 torch module 属性访问能力,不属于 npu、fx、nn 等子模块,因此测试文件放在 torch-npu 根测试目录 test/test_torch_getattribute_api.py。 6. 本 PR 仅补充测试,不修改 API 实现,不改变现有接口行为。 新增测试文件: text test/test_torch_getattribute_api.py 新增测试方法: text test_get_existing_attributes test_get_dynamic_attribute test_get_missing_attribute_raises 各测试核心验证点如下: | 测试方法 | 核心验证点 | | --- | --- | | test_get_existing_attributes | 使用 types.ModuleType.__getattribute__(torch, "__dict__") 获取模块字典作为独立 oracle,验证 torch.__config__、torch.Tensor、torch.nn、torch.empty 等已存在属性通过 torch.__getattribute__ 读取时返回模块字典中的同一对象。 | | test_get_dynamic_attribute | 在 torch module 上临时设置动态属性,验证 torch.__getattribute__ 可读取该属性,且返回对象与模块字典中记录的对象一致;测试结束后清理动态属性。 | | test_get_missing_attribute_raises | 验证读取不存在属性时,保持 Python module 语义并抛出包含属性名的 AttributeError。 | # 【资料变更】 不涉及资料 PR。 已检查 PyTorch 官方公开文档与 Ascend native API 文档,未发现 torch.__getattribute__ 独立条目。该 API 属于 Python module 固有属性访问机制,不是计算类公开 API,因此不新增 docs.md,不提交资料 PR。 # 【接口变更】 不涉及。 本 PR 不修改 API 实现,不改变现有接口行为,不新增 torch-npu 对外接口。 # 【功能验证】 运行环境: text 操作系统:Ubuntu 22.04.5 LTS (aarch64) 内核版本:5.10.0-182.0.0.95.oe2203sp3.aarch64 NPU 型号:Ascend 910B4 Driver / npu-smi:25.2.0 CANN Toolkit:9.0.0 CANN 路径:/usr/local/Ascend/cann-9.0.0 Python:3.10.12 分支验证环境: text 分支:master torch:2.12.0 torch-npu:2.12.0rc1 Python 环境:/workspace/a3-zzr-env/envs/venv_master_base_torch2.12.0_torchnpu2.12.0rc1_py310 执行命令: bash cd /root python /workspace/a3-zzr-env/repos/pytorch-master/test/test_torch_getattribute_api.py 执行结果: ``text W0713 09:42:09.361000 5136 torch/_native/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages nvidia-cutlass-dsl and apache-tvm-ffi; missing optional dependency nvidia_cutlass_dsl ... ---------------------------------------------------------------------- Ran 3 tests in 0.209s OK ` 说明:该 warning 来自 PyTorch 导入阶段 optional dependency 提示,不影响本用例执行结果。 最终验证结论: 1. 本 PR 补充 3 个 API 一致性测试,覆盖 torch.__getattribute__` 的正常属性读取、动态属性读取和异常路径。 2. 补充测试不仅验证 API 可调用,也使用模块字典作为独立 oracle 验证已有属性读取、运行时动态属性访问能力和缺失属性异常语义。 3. 该 API 不涉及 Tensor 输入,不需要 NPU Tensor 迁移适配。 4. 补充测试已在 master 环境验证通过。 5. 目标 API 当前行为符合预期,未发现需要 API 功能补齐的问题。 6. 本 PR 不修改 API 实现,不涉及接口变更。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!41419 | 2 个月前 | |
Refactor compat impl for strong validation instead of comment Co-authored-by: li_jing_hw<lijing202@huawei.com> # message auto-generated for no-merge-commit merge: !46750 merge master into master Refactor compat impl for strong validation instead of comment Created-by: li_jing_hw Commit-by: li_jing_hw Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 重构优化https://gitcode.com/Ascend/pytorch/issues/4978 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!46750 | 5 天前 | |
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
test:This PR adds missing test cases for torch._utils._unflatten_dense_tensors, as there are currently no community-provided tests for this function. Co-authored-by: xin_heyun<919112805@qq.com> # message auto-generated for no-merge-commit merge: !42052 merge test_unflatten_dense_tensors_master into master test:This PR adds missing test cases for torch._utils._unflatten_dense_tensors, as there are currently no community-provided tests for this function. Created-by: xin_heyun Commit-by: xin_heyun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> issue任务地址:https://gitcode.com/Ascend/pytorch/issues/2932 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为 torch._utils._unflatten_dense_tensors 新增 NPU 设备回归测试用例,放置在 test/test_unflatten_dense_tensors.py。 1. PyTorch 社区对该 API 仅有 C++ 层单元测试(test/cpp/api/tensor_flatten.cpp),Python 层面无任何测试用例,且缺少 NPU 设备上的运行验证。 2. 新增 8 个测试用例,基于 PyTorch 标准 TestCase 框架,通过 torch.accelerator.current_accelerator() 自动获取 NPU 设备并完成张量迁移,覆盖以下维度: - 展平-还原往返操作正确性 - 单张量与多张量(1D/2D/3D 不同形状) - 空张量混合与全空张量边界场景 - float32 / float16 / int32 多 dtype 兼容性 - 50 个大数量张量压力场景 - tuple 类型输入兼容性 3. 遵循 NPU 测试用例规范:导入顺序为 torch → torch.testing._internal.common_utils,不依赖 torch_npu,使用 self.assert* 断言,无 print/try-except,注释精简英文。 # 【资料变更】 不涉及。torch._utils._unflatten_dense_tensors 为 PyTorch 内部工具函数(_ 前缀),不属于公开文档覆盖范围。 # 【接口变更】 不涉及。仅新增测试文件,无对外接口变更。 # 【功能验证】 **测试场景**:在 NPU 设备上验证 torch._utils._unflatten_dense_tensors 将展平 1D 张量按目标形状还原为多个张量的功能正确性。 2.7.1 执行命令 python test_unflatten_dense_tensors.py -v 结果 test_all_empty_tensors (__main__.TestUnflattenDenseTensors.test_all_empty_tensors) ... ok test_different_dtypes (__main__.TestUnflattenDenseTensors.test_different_dtypes) ... ok test_empty_tensor_in_list (__main__.TestUnflattenDenseTensors.test_empty_tensor_in_list) ... ok test_large_num_tensors (__main__.TestUnflattenDenseTensors.test_large_num_tensors) ... ok test_multiple_tensors_different_sizes (__main__.TestUnflattenDenseTensors.test_multiple_tensors_different_sizes) ... ok test_round_trip_basic (__main__.TestUnflattenDenseTensors.test_round_trip_basic) ... ok test_single_tensor (__main__.TestUnflattenDenseTensors.test_single_tensor) ... ok test_tuple_input (__main__.TestUnflattenDenseTensors.test_tuple_input) ... ok ---------------------------------------------------------------------- Ran 8 tests in 1.339s OK 2.9.0 执行命令 python test_unflatten_dense_tensors.py -v 结果 test_all_empty_tensors (__main__.TestUnflattenDenseTensors.test_all_empty_tensors) ... ok test_different_dtypes (__main__.TestUnflattenDenseTensors.test_different_dtypes) ... ok test_empty_tensor_in_list (__main__.TestUnflattenDenseTensors.test_empty_tensor_in_list) ... ok test_large_num_tensors (__main__.TestUnflattenDenseTensors.test_large_num_tensors) ... ok test_multiple_tensors_different_sizes (__main__.TestUnflattenDenseTensors.test_multiple_tensors_different_sizes) ... ok test_round_trip_basic (__main__.TestUnflattenDenseTensors.test_round_trip_basic) ... ok test_single_tensor (__main__.TestUnflattenDenseTensors.test_single_tensor) ... ok test_tuple_input (__main__.TestUnflattenDenseTensors.test_tuple_input) ... ok ---------------------------------------------------------------------- Ran 8 tests in 1.331s OK 2.11.0 执行命令 python test_unflatten_dense_tensors.py -v 结果 test_all_empty_tensors (__main__.TestUnflattenDenseTensors.test_all_empty_tensors) ... ok test_different_dtypes (__main__.TestUnflattenDenseTensors.test_different_dtypes) ... [W718 07:12:27.082786050 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator()) ok test_empty_tensor_in_list (__main__.TestUnflattenDenseTensors.test_empty_tensor_in_list) ... ok test_large_num_tensors (__main__.TestUnflattenDenseTensors.test_large_num_tensors) ... ok test_multiple_tensors_different_sizes (__main__.TestUnflattenDenseTensors.test_multiple_tensors_different_sizes) ... ok test_round_trip_basic (__main__.TestUnflattenDenseTensors.test_round_trip_basic) ... ok test_single_tensor (__main__.TestUnflattenDenseTensors.test_single_tensor) ... ok test_tuple_input (__main__.TestUnflattenDenseTensors.test_tuple_input) ... ok ---------------------------------------------------------------------- Ran 8 tests in 1.357s OK 2.12.0 执行命令 python test_unflatten_dense_tensors.py -v 结果 `` W0718 07:12:38.397000 45485 opt/conda/envs/v2.12.0/lib/python3.12/site-packages/torch/_native/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages nvidia-cutlass-dsl and apache-tvm-ffi; missing optional dependency nvidia_cutlass_dsl (importlib.util.find_spec(nvidia_cutlass_dsl) failed) test_all_empty_tensors (__main__.TestUnflattenDenseTensors.test_all_empty_tensors) ... ok test_different_dtypes (__main__.TestUnflattenDenseTensors.test_different_dtypes) ... [W718 07:12:39.554782459 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator()) ok test_empty_tensor_in_list (__main__.TestUnflattenDenseTensors.test_empty_tensor_in_list) ... ok test_large_num_tensors (__main__.TestUnflattenDenseTensors.test_large_num_tensors) ... ok test_multiple_tensors_different_sizes (__main__.TestUnflattenDenseTensors.test_multiple_tensors_different_sizes) ... ok test_round_trip_basic (__main__.TestUnflattenDenseTensors.test_round_trip_basic) ... ok test_single_tensor (__main__.TestUnflattenDenseTensors.test_single_tensor) ... ok test_tuple_input (__main__.TestUnflattenDenseTensors.test_tuple_input) ... ok ---------------------------------------------------------------------- Ran 8 tests in 1.374s OK master 执行命令 python test_unflatten_dense_tensors.py -v 结果 test_all_empty_tensors (__main__.TestUnflattenDenseTensors.test_all_empty_tensors) ... ok test_different_dtypes (__main__.TestUnflattenDenseTensors.test_different_dtypes) ... [W718 07:12:49.941707130 NPUCachingAllocator.cpp:174] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator()) ok test_empty_tensor_in_list (__main__.TestUnflattenDenseTensors.test_empty_tensor_in_list) ... ok test_large_num_tensors (__main__.TestUnflattenDenseTensors.test_large_num_tensors) ... ok test_multiple_tensors_different_sizes (__main__.TestUnflattenDenseTensors.test_multiple_tensors_different_sizes) ... ok test_round_trip_basic (__main__.TestUnflattenDenseTensors.test_round_trip_basic) ... ok test_single_tensor (__main__.TestUnflattenDenseTensors.test_single_tensor) ... ok test_tuple_input (__main__.TestUnflattenDenseTensors.test_tuple_input) ... ok ---------------------------------------------------------------------- Ran 8 tests in 1.372s OK `` # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42052 | 2 个月前 | |
test:The test case coverage for the torch.UntypedStorage.to API is incomplete; additional test cases need to be added. Co-authored-by: Wo150<550680743@qq.com> # message auto-generated for no-merge-commit merge: !44651 merge UntypedStorage_to_master into master test:The test case coverage for the torch.UntypedStorage.to API is incomplete; additional test cases need to be added. Created-by: Wo150 Commit-by: Wo150 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> issue链接地址:https://gitcode.com/Ascend/pytorch/issues/4041 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 新增测试文件 test/test_untyped_storage_to.py,补充以下测试用例: | 测试用例 | 验证场景 | | --- | --- | | test_to_npu_device_types | 使用设备类型字符串和 torch.device 等目标设备表示方式,将存储转移到当前 NPU,验证返回类型、目标设备和存储内容。 | | test_to_npu_non_blocking_options | 从固定内存存储分别执行阻塞与非阻塞 NPU 转移,并在同步后验证两种结果的设备类型和内容一致性。 | | test_to_cpu_non_blocking_options | 将 NPU 存储转移到 CPU,覆盖 non_blocking 为 None、False 和 True 的情况,验证目标设备、非固定内存状态及内容。 | | test_to_same_npu_returns_self | 将存储转移到其当前 NPU 设备,验证返回对象与原存储为同一对象,且内容和设备保持不变。 | | test_to_empty_storage | 对空的无类型存储执行 NPU 与 CPU 间转移,验证结果字节数为零且目标设备正确。 | | test_to_another_npu | 在至少两个加速器可用时执行跨 NPU 设备复制,验证目标设备和存储内容;设备不足时跳过。 | | test_to_invalid_arguments | 覆盖空设备、列表设备、无效设备字符串以及错误 non_blocking 类型,验证抛出 TypeError 或 RuntimeError。 | **测试内容:** 测试在 NPU、CPU、固定内存和多设备场景下调用 torch.UntypedStorage.to,覆盖设备参数表示、阻塞与非阻塞复制、同设备快速路径、空存储、跨设备复制和非法参数,并通过对象身份、返回类型、目标设备、固定内存状态、字节内容和异常类型进行断言。辅助方法通过在存储上构造 uint8 张量统一校验原始字节内容。 **新增原因及必要性:** PyTorch 社区现有相关用例主要覆盖通用设备转换及部分固定内存路径,未直接覆盖上述 NPU 专项行为。新增测试用于确认存储在 NPU 与 CPU 之间、同一 NPU 以及不同 NPU 之间转换时的内容和对象语义,并保护非阻塞复制、空存储及参数校验行为免受后续实现回归影响。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 结论:涉及。 torch.UntypedStorage.to API 在master分支下的docs / zh / api / native_api目录下的各版本都未记载该API的资料,需要补充文档信息。 资料补齐PR:https://gitcode.com/Ascend/pytorch/pull/44657 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 结论:不涉及。 本次提交仅新增 test/test_untyped_storage_to.py 测试文件,未修改 API 实现、声明、注册或跨仓依赖,也未改变客户可见的参数、返回值、设备转换语义和运行行为,因此不涉及接口变更。 # 【功能验证】 执行命令: bash python test_untyped_storage_to.py -v 结果: ``text W0815 07:59:05.841000 360255 opt/conda/envs/master/lib/python3.12/site-packages/torch/_native/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages nvidia-cutlass-dsl and apache-tvm-ffi; missing optional dependency nvidia_cutlass_dsl (importlib.util.find_spec(nvidia_cutlass_dsl) failed) test_to_another_npu (__main__.TestUntypedStorageTo.test_to_another_npu) ... [W815 07:59:06.992339453 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator()) ok test_to_cpu_non_blocking_options (__main__.TestUntypedStorageTo.test_to_cpu_non_blocking_options) ... ok test_to_empty_storage (__main__.TestUntypedStorageTo.test_to_empty_storage) ... ok test_to_invalid_arguments (__main__.TestUntypedStorageTo.test_to_invalid_arguments) ... ok test_to_npu_device_types (__main__.TestUntypedStorageTo.test_to_npu_device_types) ... ok test_to_npu_non_blocking_options (__main__.TestUntypedStorageTo.test_to_npu_non_blocking_options) ... ok test_to_same_npu_returns_self (__main__.TestUntypedStorageTo.test_to_same_npu_returns_self) ... ok ---------------------------------------------------------------------- Ran 7 tests in 1.721s OK `` # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44651 | 1 个月前 | |
test:The test case coverage for the torch.UntypedStorage.tolist API is incomplete; additional test cases need to be added. Co-authored-by: Wo150<550680743@qq.com> # message auto-generated for no-merge-commit merge: !44646 merge UntypedStorage_tolist_master into master test:The test case coverage for the torch.UntypedStorage.tolist API is incomplete; additional test cases need to be added. Created-by: Wo150 Commit-by: Wo150 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> issue链接地址:https://gitcode.com/Ascend/pytorch/issues/4040 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 新增测试文件 test/test_untyped_storage_tolist.py,补充以下测试用例: | 测试用例 | 验证场景 | | --- | --- | | test_tolist_empty_storage | 在目标设备上构造空的 uint8 张量并取得无类型存储,验证 tolist() 返回空列表。 | | test_tolist_byte_boundaries | 使用 0、1、127、128、254、255 等典型字节边界值,验证无类型存储转换后的列表内容与输入一致。 | | test_tolist_all_byte_values | 构造覆盖完整字节取值范围的输入,验证 tolist() 能完整、按序返回存储字节。 | | test_tolist_storage_slice | 对无类型存储进行切片,验证切片结果仍为 torch.UntypedStorage,且 tolist() 返回对应区间内容。 | | test_tolist_invalid_arguments | 向无参数方法传入非法关键字参数,验证抛出 TypeError。 | **测试内容:** 测试围绕空存储、典型字节边界、完整字节取值、存储切片和非法参数五类场景,在目标设备上调用 torch.UntypedStorage.tolist,并通过列表相等、对象类型和异常断言验证返回内容、顺序、切片行为及参数约束。 **新增原因及必要性:** PyTorch 社区现有相关用例主要覆盖字节转换和字节序交换路径,未直接覆盖上述 NPU 专项场景。新增测试用于确认该公开存储接口在 NPU 上的基本功能、边界数据、视图切片和错误处理行为,降低后续底层存储实现变化造成行为回归的风险。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 结论:不涉及。 该版本未配置独立版本资料目录,不在本次独立版本资料检查范围内;本次提交仅新增 NPU 测试文件,未包含资料变更。 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 结论:不涉及。 本次提交仅新增 test/test_untyped_storage_tolist.py 测试文件,未修改 API 实现、声明、注册或跨仓依赖,也未改变客户可见的参数、返回值和运行行为,因此不涉及接口变更。 # 【功能验证】 执行命令: bash python test_untyped_storage_tolist.py -v 结果: ``text W0815 03:26:37.202000 359457 <absolute-path>/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages nvidia-cutlass-dsl and apache-tvm-ffi; missing optional dependency nvidia_cutlass_dsl (importlib.util.find_spec(nvidia_cutlass_dsl) failed) test_tolist_all_byte_values (__main__.TestUntypedStorageToList.test_tolist_all_byte_values) ... [W815 03:26:38.340855850 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator()) ok test_tolist_byte_boundaries (__main__.TestUntypedStorageToList.test_tolist_byte_boundaries) ... ok test_tolist_empty_storage (__main__.TestUntypedStorageToList.test_tolist_empty_storage) ... ok test_tolist_invalid_arguments (__main__.TestUntypedStorageToList.test_tolist_invalid_arguments) ... ok test_tolist_storage_slice (__main__.TestUntypedStorageToList.test_tolist_storage_slice) ... ok ---------------------------------------------------------------------- Ran 5 tests in 1.139s OK `` # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44646 | 1 个月前 | |
[fix] add _npu_dtype_cast_backward sharding strategy Co-authored-by: zqwenn<zhangqiongwen@huawei.com> # message auto-generated for no-merge-commit merge: merge master_npu_dtype_cast_backsard_register_sharding into master [fix] add _npu_dtype_cast_backward sharding strategy Created-by: zqwenn Commit-by: zqwenn Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!25308 | 1 年前 | |
test: add utils api npu coverage Co-authored-by: baoxuebin_2026<xuebin@isrc.iscas.ac.cn> # message auto-generated for no-merge-commit merge: !44624 merge codex/utils-api-consistency-master into master test: add utils api npu coverage Created-by: baoxuebin_2026 Commit-by: baoxuebin_2026 Merged-by: ascend-robot Description: # 【合入来源】 [#150](https://gitcode.com/Ascend/pytorch-ecosystem/issues/150) [#137](https://gitcode.com/Ascend/pytorch-ecosystem/issues/137) [#100](https://gitcode.com/Ascend/pytorch-ecosystem/issues/100) - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 公开issue: - torch.utils.checkpoint.set_device_states: https://gitcode.com/Ascend/pytorch-ecosystem/issues/150 - torch.utils._foreach_utils._has_foreach_support: https://gitcode.com/Ascend/pytorch-ecosystem/issues/137 - torch.utils.module_tracker.ModuleTracker: https://gitcode.com/Ascend/pytorch-ecosystem/issues/100 # 【修改方案】 1. API 功能说明: - torch.utils.checkpoint.set_device_states:为指定设备恢复随机数生成器状态,用于 checkpoint 重计算等场景保持随机数状态一致。 - torch.utils._foreach_utils._has_foreach_support:判断给定设备和张量列表是否满足 foreach 快路径的使用条件。 - torch.utils.module_tracker.ModuleTracker:上下文管理器,用于跟踪模块前向和反向执行期间的模块层级。 2. 上游用例检查情况: - torch.utils.checkpoint.set_device_states 涉及设备 RNG 状态。PyTorch 社区主要通过 checkpoint RNG 场景间接覆盖,未提供直接 NPU 用例,因此在 test 目录补充最小 NPU 验证。 - torch.utils._foreach_utils._has_foreach_support 用于判断设备是否支持 foreach 快路径,直接涉及 NPU 后端能力。PyTorch 社区未提供面向 NPU 的直接验证,因此在 test 目录补充最小 NPU 验证。 - torch.utils.module_tracker.ModuleTracker 为纯 Python 接口。PyTorch 社区已有独立、完整用例,覆盖模块层级、前向、反向和 checkpoint 场景,因此不新增 NPU 用例。 3. 新增用例文件: - test/test_utils_checkpoint_api.py - test/test_utils_api.py 4. 新增用例覆盖场景: - set_device_states 显式传入 device_type="npu",恢复 NPU RNG 状态并验证随机序列一致。 - set_device_states 省略可选参数 device_type,验证 Torch-NPU 默认设备类型路径。 - _has_foreach_support 验证 NPU 张量及 None 组成的列表支持 foreach 快路径。 - _has_foreach_support 验证混入非 Tensor 对象时返回不支持。 5. NPU 适配说明: - 新增张量均通过 torch.accelerator.current_accelerator() 获取当前 NPU 设备。 - 未修改 test_upstream/,未新增 NPU 适配 patch。 - 未修改 Torch-NPU API 实现。 6. 新增或修改的测试文件头部已包含 Huawei copyright 和 API 功能说明。 # 【资料变更】 不涉及。资料补齐已单独提交文档 PR。 # 【接口变更】 不涉及。未修改跨仓接口,也未修改用户可见接口行为。 # 【功能验证】 测试环境: text NPU: Ascend 910B2C torch: 2.13.0 torch_npu: 2.13.0 CANN: 8.5.1 测试命令: source /usr/local/Ascend/cann-8.5.1/set_env.sh TORCH_DEVICE_BACKEND_AUTOLOAD=1 \ /usr/local/python3.11.14/bin/python test/test_utils_checkpoint_api.py -v TORCH_DEVICE_BACKEND_AUTOLOAD=1 \ /usr/local/python3.11.14/bin/python test/test_utils_api.py -v 板端核心验证结果: PASS test_set_device_states_restores_npu_rng_sequence PASS set_device_states default device_type PASS test_has_foreach_support_for_npu_tensors PASS ModuleTracker NPU forward and backward validation See merge request: Ascend/pytorch!44624 | 4 天前 | |
test: add utils api npu coverage Co-authored-by: baoxuebin_2026<xuebin@isrc.iscas.ac.cn> # message auto-generated for no-merge-commit merge: !44624 merge codex/utils-api-consistency-master into master test: add utils api npu coverage Created-by: baoxuebin_2026 Commit-by: baoxuebin_2026 Merged-by: ascend-robot Description: # 【合入来源】 [#150](https://gitcode.com/Ascend/pytorch-ecosystem/issues/150) [#137](https://gitcode.com/Ascend/pytorch-ecosystem/issues/137) [#100](https://gitcode.com/Ascend/pytorch-ecosystem/issues/100) - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 公开issue: - torch.utils.checkpoint.set_device_states: https://gitcode.com/Ascend/pytorch-ecosystem/issues/150 - torch.utils._foreach_utils._has_foreach_support: https://gitcode.com/Ascend/pytorch-ecosystem/issues/137 - torch.utils.module_tracker.ModuleTracker: https://gitcode.com/Ascend/pytorch-ecosystem/issues/100 # 【修改方案】 1. API 功能说明: - torch.utils.checkpoint.set_device_states:为指定设备恢复随机数生成器状态,用于 checkpoint 重计算等场景保持随机数状态一致。 - torch.utils._foreach_utils._has_foreach_support:判断给定设备和张量列表是否满足 foreach 快路径的使用条件。 - torch.utils.module_tracker.ModuleTracker:上下文管理器,用于跟踪模块前向和反向执行期间的模块层级。 2. 上游用例检查情况: - torch.utils.checkpoint.set_device_states 涉及设备 RNG 状态。PyTorch 社区主要通过 checkpoint RNG 场景间接覆盖,未提供直接 NPU 用例,因此在 test 目录补充最小 NPU 验证。 - torch.utils._foreach_utils._has_foreach_support 用于判断设备是否支持 foreach 快路径,直接涉及 NPU 后端能力。PyTorch 社区未提供面向 NPU 的直接验证,因此在 test 目录补充最小 NPU 验证。 - torch.utils.module_tracker.ModuleTracker 为纯 Python 接口。PyTorch 社区已有独立、完整用例,覆盖模块层级、前向、反向和 checkpoint 场景,因此不新增 NPU 用例。 3. 新增用例文件: - test/test_utils_checkpoint_api.py - test/test_utils_api.py 4. 新增用例覆盖场景: - set_device_states 显式传入 device_type="npu",恢复 NPU RNG 状态并验证随机序列一致。 - set_device_states 省略可选参数 device_type,验证 Torch-NPU 默认设备类型路径。 - _has_foreach_support 验证 NPU 张量及 None 组成的列表支持 foreach 快路径。 - _has_foreach_support 验证混入非 Tensor 对象时返回不支持。 5. NPU 适配说明: - 新增张量均通过 torch.accelerator.current_accelerator() 获取当前 NPU 设备。 - 未修改 test_upstream/,未新增 NPU 适配 patch。 - 未修改 Torch-NPU API 实现。 6. 新增或修改的测试文件头部已包含 Huawei copyright 和 API 功能说明。 # 【资料变更】 不涉及。资料补齐已单独提交文档 PR。 # 【接口变更】 不涉及。未修改跨仓接口,也未修改用户可见接口行为。 # 【功能验证】 测试环境: text NPU: Ascend 910B2C torch: 2.13.0 torch_npu: 2.13.0 CANN: 8.5.1 测试命令: source /usr/local/Ascend/cann-8.5.1/set_env.sh TORCH_DEVICE_BACKEND_AUTOLOAD=1 \ /usr/local/python3.11.14/bin/python test/test_utils_checkpoint_api.py -v TORCH_DEVICE_BACKEND_AUTOLOAD=1 \ /usr/local/python3.11.14/bin/python test/test_utils_api.py -v 板端核心验证结果: PASS test_set_device_states_restores_npu_rng_sequence PASS set_device_states default device_type PASS test_has_foreach_support_for_npu_tensors PASS ModuleTracker NPU forward and backward validation See merge request: Ascend/pytorch!44624 | 4 天前 | |
test(utils): add data worker API coverage tests on NPU Co-authored-by: Jinfan Liu<1300083451@qq.com> # message auto-generated for no-merge-commit merge: !37247 merge test-utils-data-weak-npu-master into master test(utils): add data worker API coverage tests on NPU Created-by: JfanLiu Commit-by: Jinfan Liu Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/2027**</font> > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> [x] issue/工单 # 【修改方案】 一、API功能说明 本 PR 补充 torch.utils.data worker/control 弱覆盖 API 的直接验证用例: - torch.utils.data.dataloader._MultiProcessingDataLoaderIter - torch.utils.data.dataloader._InfiniteConstantSampler - torch.utils.data._utils.worker.ManagerWatchdog - torch.utils.data._utils.worker._IterableDatasetStopIteration - torch.utils.data._utils.worker._ResumeIteration - torch.utils.data._utils.signal_handling._set_worker_signal_handlers - torch.utils.data._utils.signal_handling._remove_worker_pids 上述 API 属于 DataLoader 多进程 iterator、IterableDataset 采样控制、worker 存活检查、worker 控制消息以及 worker 信号/pid 管理逻辑。 二、测试用例完备性说明 PyTorch 官方社区 test/test_dataloader.py 已通过 DataLoader 多进程用例覆盖上述 API 的调用链,但缺少对部分内部对象和控制消息的直接行为断言。本 PR 按 1.3 类补充 torch-npu 自定义测试文件 test/test_utils_data_api.py。 1. torch.utils.data.dataloader._MultiProcessingDataLoaderIter 直接覆盖: - test_multiprocessing_dataloader_iter_type_and_shutdown 构造 num_workers=1 的 DataLoader,显式断言 iter(loader) 是 _MultiProcessingDataLoaderIter,并验证 next(iterator) 返回预期 batch,最后调用 _shutdown_workers() 覆盖正常关闭路径。 2. torch.utils.data.dataloader._InfiniteConstantSampler 直接覆盖: - test_infinite_constant_sampler_yields_none 直接实例化 _InfiniteConstantSampler,并断言连续 yield None,覆盖 IterableDataset 无限索引采样器的核心行为。 3. torch.utils.data._utils.worker.ManagerWatchdog 直接覆盖: - test_manager_watchdog_reports_parent_alive 直接构造 ManagerWatchdog,并断言正常父进程场景 is_alive() 为 True。 4. torch.utils.data._utils.worker._IterableDatasetStopIteration / torch.utils.data._utils.worker._ResumeIteration 直接覆盖: - test_worker_control_message_fields 直接构造两个 dataclass 控制消息,断言 worker_id、seed 字段和 repr 内容,覆盖 worker 耗尽通知与 persistent worker 恢复消息的对象行为。 5. torch.utils.data._utils.signal_handling._set_worker_signal_handlers / torch.utils.data._utils.signal_handling._remove_worker_pids 直接覆盖: - test_worker_signal_handlers_and_pid_cleanup 直接调用 _set_worker_signal_handlers,并通过 _set_worker_pids 注册当前 pid 后调用 _remove_worker_pids 清理,覆盖 C 侧 worker signal handler 初始化和 worker pid registry 清理入口的正常路径。 本文件验证的是 DataLoader worker/control 面 API。为避免把验证目标混入 NPU IPC 和 worker 子进程设备 Tensor 传输,本新增用例中的多进程 DataLoader 使用 Python 字符串 payload,不在 worker 子进程返回 NPU Tensor;原 DataLoader NPU Tensor payload 路径已由 test_upstream 中单进程 DataLoader/collate 用例覆盖。 三、NPU适配方案 1. API 源码无需修改:上述 API 是 torch.utils.data 的 Python/C++ 控制面入口,不新增 NPU kernel,不改变接口语义。 2. 测试新增路径:新增 test/test_utils_data_api.py,文件聚焦 worker/control API 直接行为,可后续扩展同模块 API。 3. 分支提交范围:新增测试文件提交到 2.7.1、2.9.0、2.10.0、2.11.0、2.12.0 以及 master。 四、变更文件 - test/test_utils_data_api.py # 【资料变更】 > 已检查资料支持情况,结论如下: > > dataloader: > - 公开 API,在文档中记录:torch.utils.data.DataLoader、torch.utils.data._utils.collate.collate。对应资料 PR:https://gitcode.com/Ascend/pytorch/merge_requests/36233 > - 内部函数/类,不在文档中记录:DataLoader iterator、worker、signal handling、persistent worker 相关内部对象。 # 【接口变更】 > 不涉及。API 源码无修改,不新增、删除或变更对外接口。 # 【功能验证】 > 已在 master 对应 torch-npu 环境执行新增用例,结果如下;master 使用 2.12.0 验证环境执行。 ## 验证环境 - 操作系统:Ubuntu / Linux aarch64 - 昇腾硬件:910B2 - CANN 软件版本:8.3.RC1 - 验证环境: - 2.7.1:torch 2.7.1+cpu / torch-npu 2.7.1.post3 - 2.9.0:torch 2.9.0+cpu / torch-npu 2.9.0.post1 - 2.10.0:torch 2.10.0+cpu / torch-npu 2.10.0rc3 - 2.11.0:torch 2.11.0+cpu / torch-npu 2.11.0rc1 - 2.12.0 / master 验证:torch 2.12.0+cpu / torch-npu 2.12.0.rc1 ## 运行命令与结果 bash python test/test_utils_data_api.py Ran 5 tests in 1.416s OK # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37247 | 4 个月前 | |
fix(npu): register QuantizedPrivateUse1 view/ravel/flatten for test_view_ops. Co-authored-by: Margaret_wangrui<wangrui178@huawei.com> # message auto-generated for no-merge-commit merge: !37087 merge master_view_0524 into master fix(npu): register QuantizedPrivateUse1 view/ravel/flatten for test_view_ops. Created-by: Margaret_wangrui Commit-by: Margaret_wangrui Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/2082 - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 **问题简述:** 将 PyTorch 上游 test/test_view_ops.py 切换到 torch_npu 执行时,test_ravel_npu、test_flatten_npu 在处理 torch._empty_affine_quantized(..., quint8, device=npu) 量化张量时报错: text NotImplementedError: Could not run 'aten::view' with arguments from the 'Quantizednpu' backend 浮点 NPU 张量(PrivateUse1)可正常 view;量化 NPU 张量(QuantizedPrivateUse1)缺少对应 kernel 注册。 --- # 【修改方案】 本 PR 为 **QuantizedPrivateUse1** 补齐 shape / copy 相关 dispatch,并与 op-plugin stride_copy 修复配合,使量化 NPU 张量上的 view / ravel / flatten 语义与上游用例一致。 **组件交互关系:** text test_ravel_npu / test_flatten_npu(量化 quint8 on NPU) │ ▼ TensorShape.cpp(torch_npu) QuantizedPrivateUse1 注册:view / ravel / contiguous / clone / empty* / _copy_from │ ├─► MetaData 不匹配时 clone 物化(NPUStorageDesc 与 view shape 对齐) │ ▼ TensorFactories.cpp(torch_npu) NPUNativeFunctions::clone(quant):int_repr + npu_stride_copy_out │ ▼ AsStridedKernelNpu.cpp(op-plugin,子模块 071a046) 小 nbytes int_repr stride_copy 稳定走 AsStrided **具体实现:** 1. **torch_npu/csrc/aten/common/TensorShape.cpp(+312 行)** - 通过 TORCH_LIBRARY_IMPL(aten, QuantizedPrivateUse1, m) 注册:view、as_strided、ravel、contiguous、clone、empty_like、empty.memory_format、empty_strided、_copy_from。 - 实现 npu_quantized_view_symint:基于 infer_size + computeStride,经 alias_with_sizes_and_strides_npu 构造 QTensorImpl view;stride 不兼容且可展平为 rank-1 时走 clone + view。 - 实现 npu_quantized_ravel:aten::contiguous → view(-1),避免 composite reshape 在 NPU 量化张量上短路。 - 实现 npu_quantized_contiguous:除 is_contiguous() 外检查行主 stride,必要时 clone 物化。 - npu_quantized_view_materialize_if_storage_desc_mismatch:当 MetaDataAreMatch(q)==false 时对 view 结果 clone(Contiguous)。 - NPUNativeFunctions::as_strided 增加量化分支,构造 QTensorImpl view。 2. **torch_npu/csrc/aten/common/TensorFactories.cpp(+202 行)** - 增强 NPUNativeFunctions::clone 量化路径:empty_like + SetDesc + int_repr stride_copy。 - MetaDataAreMatch 异常(如 transpose、view 后 storage desc 不一致)时,CPU int_repr staging + H2D 物化。 - stride_copy 后 int_repr slab 传播与 canonical 缓冲对齐(npu_quantized_clone_write_int_repr_payload)。 3. **test/test_view_ops.py** - 量化 NPU 张量不再强制 flat._base is src(允许 NPUStorageDesc 不匹配时的物化拷贝路径)。 - 修正 is_quantized / is_npu 为属性访问(非可调用方法)。 **变更规模:** text test/test_view_ops.py | 5 +- torch_npu/csrc/aten/common/TensorFactories.cpp | 202 +++ torch_npu/csrc/aten/common/TensorShape.cpp | 312 +++ --- # 【资料变更】 不涉及。 --- # 【接口变更】 不涉及跨代码仓或客户面可见的公开 API 变更。 **内部说明(ATen dispatch 层,非 Python 公开接口):** | 算子 | Dispatch Key | 变更类型 | |------|--------------|----------| | view / as_strided / ravel / contiguous / clone | QuantizedPrivateUse1 | 新增 kernel 注册 | | empty_like / empty.memory_format / empty_strided / _copy_from | QuantizedPrivateUse1 | 新增 kernel 注册 | 用户可见行为变化:NPU 上 quint8 等量化张量可正常执行 view、ravel、flatten(此前为 NotImplementedError)。 --- # 【功能验证】 **环境要求:** 已编译安装 torch_npu;NPU 设备可用。 **测试步骤:** bash python test/test_view_ops.py -v -k test_ravel_npu python test/test_view_ops.py -v -k test_flatten_npu **覆盖场景:** | 场景 | 验证点 | |------|--------| | 连续量化张量 5×5×5×5 | ravel() / flatten(0,-1) 与 view(-1) 一致 | | 空 shape 0×2×3、3×0×2 | numel=0 时 shape 与 view 链正确 | | 转置 + ravel(nc=True) | 非连续路径 contiguous().view(-1) 与 ravel() 一致 | | 多组 flatten 维度 | (0,2)、(1,2)、(-2,-1) 等与 view(-1) 展开顺序一致 | | 浮点 NPU 回归 | 同一用例文件中浮点张量路径不受影响 | **UT 看护:** - [x] 适配 test/test_view_ops.py(量化 NPU _base 断言放宽、is_quantized/is_npu 属性修正) **自验证:** 请在合入前补充 NPU 环境执行上述命令的通过截图或 CI 流水线链接。   --- # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37087 | 4 个月前 | |
Update onnx_test_common.py Co-authored-by: yuhaiyan<yuhaiyan8@huawei.com> # message auto-generated for no-merge-commit merge: merge master-dev1 into master Update onnx_test_common.py Created-by: yuhaiyan Commit-by: yuhaiyan Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!25485 | 1 年前 | |
| 2 年前 | ||
refactor: simplify options manager mode validation Co-authored-by: chujinjin<chujinjin52@huawei.com> # message auto-generated for no-merge-commit merge: !46410 merge refactor/options-manager-mode-validation into master refactor: simplify options manager mode validation Created-by: chujinjin Commit-by: chujinjin Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 # 【修改方案】 - 1. 将 OptionsManager.h 中用于校验环境变量取值的模式映射移至 OptionsManager.cpp 的匿名命名空间,并让相关校验函数直接使用这些映射。原先的映射获取函数定义在头文件中,下游项目即使没有调用它们,只要包含该头文件就可能产生 -Wunused-function 警告。迁移后,头文件不再引入这些未使用的函数定义。此项修改对应 issue #5054 (https://gitcode.com/Ascend/pytorch/issues/5054)。 - 2. 保留各环境变量原有的默认值、合法取值和异常处理逻辑。此次调整只改变模式映射的存放位置及使用方式,不改变 OptionsManager 对环境变量的校验结果。 - 3. 将原本依赖头文件内容的公开环境变量模式兼容性检查移至 tools/check_public_environments.py。脚本读取 torch_npu_schema.json 和 OptionsManager.cpp,规范化空白字符后检查模式定义是否仍与 schema 一致;同时更新受排版调整影响的 schema记录。 - 4. 在 CMake 中添加兼容性检查目标,并将其设为插件构建的依赖,使构建过程继续执行这项检查。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!46410 | 15 天前 | |
| 2 年前 | ||
| 2 年前 | ||
[fix]: 支持按版本装饰器过滤测试用例 Co-authored-by: thickhair<zp2165064878@163.com> # message auto-generated for no-merge-commit merge: !45273 merge one-track_master into master [fix]: 支持按版本装饰器过滤测试用例 Created-by: thickhair Commit-by: thickhair Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/4365 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 - 修改 CI 入口脚本,无 --between_version 时过滤掉带版本装饰器的文件,仅保留通用测试用例 - 更新 version_filter 逻辑:版本化任务仅运行匹配版本范围的测试文件,非版本化任务仅运行无装饰器的文件 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!45273 | 1 个月前 |
简介
test目录为PTA相关的测试用例。
安装依赖
pip3 install -r requirements.txt
补全脚本
该操作需要联网
cd test
bash get_synchronized_files.sh
通过以上操作,会自动补齐testfiles_synchronized.txt和testfolder_synchronized.txt中的文件或文件夹。
跳过失败用例
export DISABLED_TESTS_FILE=./unsupported_test_cases/.pytorch-disabled-tests.json
如果不是在test目录下运行测试用例,需要传入.pytorch-disabled-tests.json的绝对路径。
执行方式
执行单个测试脚本
运行以test开头的文件。以test_autocast.py为例:
方式一:
python test_autocast.py
方式二:
python run_test.py -i test_autocast
说明:部分以test开头的脚本不是直接运行的脚本,比如jit中的测试脚本是通过test_jit.py执行的。
执行具体的用例
通过-k参数传入具体的用例名。以test_autocast.py为例:
方式一:
python test_autocast.py -v -k test_autocast_nn_fp32
方式二:
python run_test.py -v -i test_autocast -- -k test_autocast_nn_fp32
执行全量UT的方式
# 进入到test目录的上一级
cd ../
运行非分布式全量用例:
python ci/access_control_test.py --all
运行分布式全量用例:
python ci/access_control_test.py --distributed
FAQ
-
报错:"dictionary changed size during iteration".
如果python 环境是3.8.1版本,报错在unitest/case.py中,可考虑是sys.modules被修改导致的。第三方包可能会有对sys.modules的修改,比如beartype。 此问题为python 3.8.1版本/3.9.0版本的已知bug,可按照 https://github.com/python/cpython/issues/73806 中修改方式修改,将
for v in sys.modules.values()改为for v in list(sys.modules.values())可用于复现问题的用例:
python test_jit.py -v -k test_annotated_empty_dict -
test_public_bindings.py 用例的功能
该用例是为了校验接口的公开规范性,如果该用例报错,请确认报错的接口是否要公开,并按照报错的提示进行修改。