master
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
b651b67466 |
docs: add torch.nn.attention.flex_attention.or_masks support status
Co-authored-by: zhangjiahao-2026<2332445379@qq.com> # message auto-generated for no-merge-commit merge: !43375 merge issue-3293-or-masks-docs into master docs: add torch.nn.attention.flex_attention.or_masks support status Created-by: zhangjiahao-2026 Commit-by: zhangjiahao-2026 Merged-by: ascend-robot Description: # 【合入来源】 关联任务issue: https://gitcode.com/Ascend/pytorch/issues/3293 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [x] 资料更新 # 【修改方案】 在 master 资料中为公开非计算类 API `torch.nn.attention.flex_attention.or_masks` 补齐支持情况。 修改文件: - docs/zh/api/native_api/pytorch_2-7-1/torch-nn-attention.md - docs/zh/api/native_api/pytorch_2-11-0/torch-nn-attention.md - docs/zh/api/native_api/pytorch_2-12-0/torch-nn-attention.md - docs/zh/api/native_api/pytorch_2-13-0/torch-nn-attention.md 具体修改内容: 1. 在PyTorch 2.7.1、2.11.0、2.12.0和2.13.0资料中新增`torch.nn.attention.flex_attention.or_masks`条目; 2. 按照PyTorch官方资料的层级和顺序,将该API归入`BlockMask Utilities`,并放置在`BlockMask`之前; 3. Atlas A2训练系列产品、Atlas A3训练系列产品和Ascend 950DT均标记为支持; 4. 该API为非计算类纯Python接口,与具体数据类型无关,不填写数据类型限制。 本PR仅补充目标API的资料,不批量修改同一文件中其他历史API的资料格式。 # 【资料变更】 资料检查结果:此前 master 下的原生 API 资料未收录 `torch.nn.attention.flex_attention.or_masks`,因此需要补充。 本次在以下版本目录的 `torch-nn-attention.md` 中新增支持情况: - PyTorch 2.7.1 - PyTorch 2.11.0 - PyTorch 2.12.0 - PyTorch 2.13.0 该API为公开非计算类纯Python接口,与张量数据类型无关,不填写数据类型限制。文档条目按照PyTorch官方资料的层级和顺序归入`BlockMask Utilities`。 # 【接口变更】 不涉及 # 【功能验证】 `torch.nn.attention.flex_attention.or_masks(*mask_mods)`用于组合一个或多个 `mask_mod`,返回一个新的掩码函数,并对所有输入mask的返回结果执行逻辑或。 PyTorch官方社区在以下用例中已有`or_masks`基本逻辑或语义验证: ```text test/inductor/test_flex_attention.py::test_mask_mod_combiners ``` `or_masks`为纯Python组合接口,不包含NPU专属kernel或设备分支,不需要修改 Torch-NPU功能实现,也不需要新增测试文件或`test_upstream` patch。 API功能、社区用例情况、NPU适配分析和各版本验证结果见说明Issue: https://gitcode.com/Ascend/pytorch/issues/4082 A5硬件验证信息如下。 验证设备:  验证环境: ```text torch:2.12.0+cpu torch_npu:2.12.0 Python:3.12.13 ``` 验证命令: ```bash python /tmp/test_or_masks_a5.py ``` 验证场景: 1. 单个`mask_mod`返回True和False; 2. 多个`mask_mod`执行逻辑或; 3. 零个`mask_mod`返回位于NPU上的bool标量False; 4. 非callable输入触发预期`RuntimeError`; 5. 返回值dtype为`torch.bool`,设备类型为`npu`。 运行截图:  验证结论: `torch.nn.attention.flex_attention.or_masks`在上述A5环境中运行正常,单mask、 多mask、零mask和异常入参场景均验证通过,返回类型及返回设备符合PyTorch实现。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43375 |
||
|
|
c6a133ce28 |
docs: mark torch.layout as supported on Ascend 950DT
Co-authored-by: zhangjiahao-2026<2332445379@qq.com> # message auto-generated for no-merge-commit merge: !46016 merge docs-issue-3378-layout-950dt into master docs: mark torch.layout as supported on Ascend 950DT Created-by: zhangjiahao-2026 Commit-by: zhangjiahao-2026 Merged-by: ascend-robot Description: # 【合入来源】 关联任务issue: <https://gitcode.com/Ascend/pytorch/issues/3378> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [x] 资料更新 # 【修改方案】 在 master 资料中更新公开非计算类 API `torch.layout` 的 Ascend 950DT 支持情况。 修改文件: * docs/zh/api/native_api/pytorch_2-7-1/Tensor-Attributes.md * docs/zh/api/native_api/pytorch_2-11-0/Tensor-Attributes.md * docs/zh/api/native_api/pytorch_2-12-0/Tensor-Attributes.md * docs/zh/api/native_api/pytorch_2-13-0/Tensor-Attributes.md 具体修改内容: 1. 在 PyTorch 2.7.1、2.11.0、2.12.0 和 2.13.0 资料中,将 `torch.layout` 的 `Ascend 950DT` 由「不支持」改为「支持」; 2. Atlas A2 训练系列产品、Atlas A3 训练系列产品保持「支持」不变; 3. 该 API 为非计算类接口,与具体数据类型无关,不填写数据类型限制; 4. 不新增 A5 / 950PR 产品字段,资料产品维度仍为 A2 / A3 / 950DT。 本 PR 仅修改目标 API 的 950DT 支持标记,不批量修改同一文件中其他历史 API 的资料内容。 # 【资料变更】 资料检查结果:master 下的原生 API 资料已收录 `torch.layout`,Atlas A2、Atlas A3 标记为支持,Ascend 950DT 原标记为不支持。 本次已补充 A5(Ascend950PR)实机验证并通过,因此将以下版本目录 `Tensor-Attributes.md` 中 `torch.layout` 的 Ascend 950DT 更新为支持: * PyTorch 2.7.1 * PyTorch 2.11.0 * PyTorch 2.12.0 * PyTorch 2.13.0 该 API 为公开非计算类接口,与张量数据类型无关,不填写数据类型限制。 # 【接口变更】 不涉及 # 【功能验证】 `torch.layout` 是表示 `torch.Tensor` 内存布局的 PyTorch 原生类型。本任务验证现有社区用例覆盖的 `torch.zeros + torch.strided` 路径。 PyTorch 官方社区在以下用例中已有相关验证: ```text test/test_tensor_creation_ops.py::TestTensorCreation.test_zeros_dtype_layout_device_match ``` `torch.layout` 由 PyTorch 框架公共代码注册,不包含 NPU 专属 kernel 或设备分支,不需要修改 Torch-NPU 功能实现,也不需要新增测试文件或 `test_upstream` patch。 API 功能、社区用例情况、NPU 适配分析和各版本验证结果见说明 Issue: <https://gitcode.com/Ascend/pytorch/issues/3378> A5 硬件验证信息如下。 验证设备:  验证环境: ```text python: 3.10.12 torch: 2.12.0+cpu torch_npu: 2.12.0 npu_available: True device: Ascend950PR_9579 ``` 验证命令: ```bash python3 /tmp/test_layout_3378_a5.py ``` 验证场景:对齐社区用例 `test_zeros_dtype_layout_device_match`,在 NPU 上使用 `layout=torch.strided` 调用 `torch.zeros((2, 3), ...)`,覆盖以下 7 种 dtype: 1. `torch.bool` 2. `torch.uint8` 3. `torch.int16` 4. `torch.int64` 5. `torch.float16` 6. `torch.float32` 7. `torch.complex64` 每种 dtype 均校验返回 Tensor 的 `dtype`、`layout`、`device` 与入参一致。 运行截图:  验证结论: `torch.layout` 的 `torch.zeros + torch.strided` 路径在上述 A5(Ascend950PR)环境中 7 种 dtype 均验证通过。本结论不扩大为所有稀疏 layout 及其相关算子均已完成兼容性验证。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!46016 |
||
|
|
d8fa00afa6 |
docs: mark torch.ShortStorage as supported on Ascend 950DT
Co-authored-by: zhangjiahao-2026<2332445379@qq.com> # message auto-generated for no-merge-commit merge: !46018 merge docs-issue-3861-shortstorage-950dt into master docs: mark torch.ShortStorage as supported on Ascend 950DT Created-by: zhangjiahao-2026 Commit-by: zhangjiahao-2026 Merged-by: ascend-robot Description: # 【合入来源】 关联任务issue: <https://gitcode.com/Ascend/pytorch/issues/3861> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [x] 资料更新 # 【修改方案】 在 master 资料中更新公开非计算类 API `torch.ShortStorage` 的 Ascend 950DT 支持情况。 修改文件: * docs/zh/api/native_api/pytorch_2-7-1/torch-Storage.md * docs/zh/api/native_api/pytorch_2-9-0/torch-Storage.md * docs/zh/api/native_api/pytorch_2-10-0/torch-Storage.md * docs/zh/api/native_api/pytorch_2-11-0/torch-Storage.md * docs/zh/api/native_api/pytorch_2-12-0/torch-Storage.md * docs/zh/api/native_api/pytorch_2-13-0/torch-Storage.md * docs/zh/api/native_api/pytorch_2-14-0/torch-Storage.md 具体修改内容: 1. 在 PyTorch 2.7.1、2.9.0、2.10.0、2.11.0、2.12.0、2.13.0 和 2.14.0 资料中,将 torch.ShortStorage 在 Ascend 950DT 系列产品上的支持状态由“不支持”修改为“支持”。 2. Atlas A2 训练系列产品、Atlas A3 训练系列产品保持「支持」不变; 3. 该 API 为非计算类接口,与具体数据类型无关,不填写数据类型限制; 4. 不新增 A5 / 950PR 产品字段,资料产品维度仍为 A2 / A3 / 950DT; 本 PR 仅修改目标 API 的 950DT 支持标记,不批量修改同一文件中其他历史 API 的资料内容。 # 【资料变更】 资料检查结果:master 下的原生 API 资料已收录 `torch.ShortStorage`,Atlas A2、Atlas A3 标记为支持,Ascend 950DT 原标记为不支持。 本次已补充 A5(Ascend950PR)实机验证并通过,因此将以下版本目录 `torch-Storage.md` 中 `torch.ShortStorage` 的 Ascend 950DT 更新为支持: * PyTorch 2.7.1 * PyTorch 2.9.0 * PyTorch 2.10.0 * PyTorch 2.11.0 * PyTorch 2.12.0 * PyTorch 2.13.0 * PyTorch 2.14.0 该 API 为公开非计算类接口,与张量数据类型无关,不填写数据类型限制。 # 【接口变更】 不涉及 # 【功能验证】 `torch.ShortStorage` 是 PyTorch Legacy TypedStorage 类型之一,用于保存 16 位有符号整数数据,元素类型对应 `torch.int16`。 PyTorch 官方社区在以下用例中已有相关验证: ```text test/test_torch.py::test_storage_setitem test/test_torch.py::test_tensor_storage_type test/test_torch.py::test_element_size test/test_torch.py::test_from_buffer test/test_torch.py::test_storage_error test/test_torch.py::test_storage_casts ``` `torch.ShortStorage` 对应的 NPU Storage 类型为 `torch_npu.npu.ShortStorage`。现有 `test/test_torch.py` 已完成 NPU Storage 类型映射适配,不需要修改 Torch-NPU 功能实现,也不需要新增测试文件或 `test_upstream` patch。 API 功能、社区用例情况、NPU 适配分析和各版本验证结果见说明 Issue: <https://gitcode.com/Ascend/pytorch/issues/3861> A5 硬件验证信息如下。 验证设备:  验证环境: ```text python: 3.10.12 torch: 2.12.0+cpu torch_npu: 2.12.0 npu_available: True device: Ascend950PR_9579 ``` 验证命令: ```bash python3 /tmp/test_shortstorage_3861_a5.py ``` 验证场景: 1. 无参数创建及 `element_size` 2. 按元素数量、数据序列创建 3. CPU / NPU 元素及切片赋值 4. `from_buffer` 5. Storage 类型转换 6. NPU int16 Tensor 映射为 `torch_npu.npu.ShortStorage` 7. `torch.ShortStorage(wrap_storage=npu_storage)` 抛出 `must be cpu` 8. `torch_npu.npu.ShortStorage(wrap_storage=cpu_storage)` 抛出 `must be npu` 运行截图:  验证结论: `torch.ShortStorage` 在上述 A5(Ascend950PR)环境中上述场景均验证通过。TypedStorage deprecation warning 属于 PyTorch 上游预期告警,不影响结论。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!46018 |
||
|
|
9620f00b4c |
test: add NPU coverage for symbolic_shapes APIs (issue #1614)
Co-authored-by: zhangjiahao-2026<2332445379@qq.com> # message auto-generated for no-merge-commit merge: !38589 merge intern-1614-master into master test: add NPU coverage for symbolic_shapes APIs (issue #1614) Created-by: zhangjiahao-2026 Commit-by: zhangjiahao-2026 Merged-by: ascend-robot Description: # 【合入来源】 > **关联社区 issue:** https://gitcode.com/Ascend/pytorch/issues/1614 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 本次为 Torch-NPU API 一致性对齐任务(Issue #1614),针对 `torch.fx.experimental.symbolic_shapes` 下 5 个 API 补充/适配测试,**不涉及算子或 API 实现代码修改**(NPU 上与 PyTorch master 行为一致)。 ## API 功能说明 `torch.fx.experimental.symbolic_shapes` 是 PyTorch FX 动态 shape 推导体系中的符号形状模块,负责在编译/导出过程中管理 SymInt/SymBool 约束、guard 生成及 shape 相等关系。本次验证的 5 个 API 均为纯 Python 层面的符号 shape 工具,与底层计算硬件无关。 - `torch.fx.experimental.symbolic_shapes.DivideByKey`:整除键类,用于在符号 shape 表达中表示对某个常量做 floor division(整除)的运算模式,可通过构造参数指定除数。 - `torch.fx.experimental.symbolic_shapes.DivideByKey.get`:`DivideByKey` 实例方法,对给定数值执行 floor division,即 `value // divisor`,返回整除结果。 - `torch.fx.experimental.symbolic_shapes.EqualityConstraint`:符号 shape 约束类,用于在 FX 图导出/动态 shape 推导中表达多个 shape 源之间的相等关系,包含 `source_pairs`、`derived_equalities`、`phantom_symbols`、`relaxed_sources`、`warn_only` 等字段。 - `torch.fx.experimental.symbolic_shapes.has_free_symbols`:判断给定对象(通常为 sympy 表达式)是否包含未被绑定的自由符号,用于区分常量表达式与含符号变量的动态 shape 表达式。 - `torch.fx.experimental.symbolic_shapes.guard_size_oblivious`:符号 shape guard 生成过程中的辅助函数,对布尔条件做 size-oblivious 处理,使其与具体 tensor size 解耦(master 上该 API 已标记将废弃,功能仍可用)。 ## API 全名与测试覆盖场景 | 全名 API | 测试用例 | 覆盖场景 | |----------|----------|----------| | `torch.fx.experimental.symbolic_shapes.DivideByKey` | 自写 `TestDivideByKeyAndEqualityConstraint::test_divide_by_key` | 构造 `DivideByKey(4)`,验证 `str(key)` 为 `".__floordiv__(4)"` | | `torch.fx.experimental.symbolic_shapes.DivideByKey.get` | 自写 `TestDivideByKeyAndEqualityConstraint::test_divide_by_key_get` | 构造 `DivideByKey(4)`,调用 `.get(17)`,验证返回 `4` | | `torch.fx.experimental.symbolic_shapes.EqualityConstraint` | 自写 `TestDivideByKeyAndEqualityConstraint::test_equality_constraint_init` | 以空约束参数初始化(`source_pairs=[]`,`derived_equalities=[]`,`phantom_symbols=[]`,`relaxed_sources=set()`,`warn_only=False`),验证 `source_pairs`、`phantom_symbols` 为空且 `warn_only=False` | | `torch.fx.experimental.symbolic_shapes.has_free_symbols` | 官方 `test/test_dynamic_shapes.py::TestUnbacked::test_has_free_symbols`(本地验证) | master 无 `test_upstream` 机制,torch 2.13.0.dev 已通过 backend autoload 自动加载 torch_npu,本地运行官方用例验证 | | `torch.fx.experimental.symbolic_shapes.guard_size_oblivious` | 官方 `test/dynamo/test_misc.py`(本地验证) | master 无 `test_upstream` 机制,本地运行官方用例验证;该 API 在 2.13.0.dev 标记为将废弃(FutureWarning),功能仍可用 | ## 具体改动 1. 在 `test/fx/test_symbolic_shapes.py` 新增 `TestDivideByKeyAndEqualityConstraint` 类,补充 3 个自写用例 - 使用 `unittest` + `torch.testing._internal.common_utils.run_tests` - 覆盖 API:`DivideByKey`、`DivideByKey.get`、`EqualityConstraint` - 用例均带 `@unittest.skipUnless(torch.npu.is_available())` - 新增 `setUp()` 确保 `torch_npu` 扩展已加载 `has_free_symbols`、`guard_size_oblivious` 无 upstream patch(master 无 `test_upstream` 机制), 在 NPU 环境本地运行 PyTorch main 官方用例验证,验证截图见【功能验证】(3)(4)。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 环境: torch 2.13.0.dev20260416 + torch_npu 2.13.0+gitdede8a5(master 源码编译),`torch.npu.is_available()==True` ### (1)自写用例 ``` cd /tmp && python3 /data/pytorch/test/fx/test_symbolic_shapes.py \ TestDivideByKeyAndEqualityConstraint.test_divide_by_key \ TestDivideByKeyAndEqualityConstraint.test_divide_by_key_get \ TestDivideByKeyAndEqualityConstraint.test_equality_constraint_init \ 2>&1 | grep -vE "recording\.py|set_unbacked_var_to_val|E0626" | tail -10 ``` 结果:  覆盖 API:`DivideByKey`、`DivideByKey.get`、`EqualityConstraint` ### (2)5 个 API 快速验证 ``` cd /tmp python -c "import torch from torch.fx.experimental.symbolic_shapes import ( DivideByKey, EqualityConstraint, guard_size_oblivious, has_free_symbols, ) print('DivideByKey.get(17)=', DivideByKey(4).get(17)) print('guard_size_oblivious(True)=', guard_size_oblivious(True)) print('has_free_symbols(3)=', has_free_symbols(3)) print('EqualityConstraint OK') print('npu:', torch.npu.is_available())" ``` 结果:  ### (3)官方 has_free_symbols 用例 ``` cp /data/pytorch-upstream-main/test/test_dynamic_shapes.py /tmp/t_dyn.py cd /tmp && python t_dyn.py TestUnbacked.test_has_free_symbols -v ``` 结果:  ### (4)官方 guard_size_oblivious 用例 ``` cp /data/pytorch-upstream-main/test/dynamo/test_misc.py /tmp/t_misc.py cd /tmp && python t_misc.py -k guard_size_oblivious -v ``` 结果:  # 【CheckList】 - [x] 代码注释完备,正确记录错误日志(仅测试代码,无新增业务逻辑) - [x] 代码实现进行了返回值、空指针等校验(不涉及) - [x] PR标题正确使用类型标签(`test:`前缀) - [x] PR持续集成流水线(CI)执行通过(待评论 `compile` 触发 CI 通过后勾选) --- See merge request: Ascend/pytorch!38589 |