Co-authored-by: Xinrui Chen<chenxinrui11@huawei.com> # message auto-generated for no-merge-commit merge: !47559 merge codex/fix-native-api-npu-tags-master into master docs: [master] 补齐原生 API 硬件说明的 NPU 标签 Created-by: chenrayray Commit-by: Xinrui Chen Merged-by: ascend-robot Description: # 【合入来源】 - [x] issue/工单 - [x] 资料更新 关联 Issue:https://gitcode.com/Ascend/pytorch/issues/5276 # 【修改方案】 补齐 `master` 原生 API 文档中 152 行硬件专属说明的 NPU 标签,并将确定性计算文档的两个标签范围扩展至完整硬件专属 API 表格,确保按硬件筛选时说明随对应产品显示。 1. 为遗漏的 A2、A3、950DT 产品支持条目分别补充 `910b`、`A3`、`950` 标签,新增 ID 避开文档已有 ID。 2. 为所有版本目录中的 MemPool 950DT 分配器限制补充 `950` 标签;将 Adam 的限制改为“<term>Atlas A2训练系列产品</term>和<term>Atlas A3训练系列产品</term>暂不支持将`fused`设置为`True`。”,使用 `910b,A3` 标签,使 A2/A3 筛选时显示不支持提示,950DT(A5)筛选时不显示此提示。 3. 将 private_apis.md 的全部表格转换为 37 个独立 API 条目,按原生 API 文档形式展示产品支持情况、限制与说明及 NPU 形式名称。分别以独立行标签包裹 A2、A3、950DT 支持条目,保留原表中 18 个 API 暂不支持 950DT 的信息;全部 NPU 起止标签独占一行。 4. 将确定性计算文档的结束标签移动至对应表格之后,覆盖表题、表头及全部 API 行。 # 【资料变更】 修改 `docs/zh/api/native_api/` 下 37 个 Markdown 文件,补齐硬件条件注释并将私有 API 表格转换为逐项文档形式,沿用目标分支现有硬件标识。 # 【接口变更】 不涉及。 # 【功能验证】 - 全量扫描 468 个文档,显式硬件说明未覆盖数为 0。 - 标签起止配对、文档内 ID 唯一性检查通过。 - 私有 API 文档的 37 个条目与基线表格逐项比对,API 名称、NPU 形式名称、产品支持情况、数据类型及版本限制均保留;除 Adam fused 限制按硬件筛选语境改写外,其他修改文件去除 NPU 注释后原文保持一致。 - 全量检查所有 NPU 起止标签均独占一行,配对完整、ID 唯一,硬件说明均被标签覆盖;私有 API 文档无残留表格或行内标签,确定性计算标签覆盖完整对应表格。 - 两个分支各 7 个 PyTorch 版本目录的 Adam fused 提示经筛选验证:910b、A3 可见,950 不可见。 - `git diff --check` 通过。 - 文档变更未运行 NPU UT 或完整文档站点构建;远端 CI 待运行确认。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志(不涉及运行时代码) - [x] 代码实现进行了返回值、空指针等校验(不涉及运行时代码) - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常(待CI) See merge request: Ascend/pytorch!47559
4.6 KiB
4.6 KiB
确定性计算API清单
简介
在使用PyTorch框架进行训练时,部分算子在计算时可能存在随机性,若需要输出结果排除随机性,则需要设置确定性计算开关。在开启确定性计算时,当使用相同的输入在相同的硬件和软件上执行相同的操作,输出的结果每次都是相同的。
Note
- 确定性计算设置方法都必须与待设置的网络、算子等在同一个主进程,部分模型脚本中main()与训练网络并不在一个进程中。
- 当前同一线程中只能设置一次确定性状态,多次设置以第一次有效设置为准,后续设置不会生效。
有效设置:在设置确定性状态后,必须实际执行至少一次算子,使其任务下发。仅仅设置而未执行任何算子,只会开启确定性标志,但不会真正影响算子行为。
解决方案:
- 暂不推荐在同一线程中多次设置确定性。
- 该问题在开启和关闭确定性开关的情况下均存在,在后续版本中会解决该问题。
使用方法
确定性计算的用法和效果具体可参考相应官方文档torch.use_deterministic_algorithms,本小节仅介绍开启确定性计算的方法。
Caution
开启确定性开关可能会导致性能下降。
-
开启确定性计算开关:
torch.use_deterministic_algorithms(True) -
验证设置是否成功。
-
执行如下命令查询接口设置:
torch.are_deterministic_algorithms_enabled() -
回显示例如下:
print(torch.are_deterministic_algorithms_enabled())
执行训练时,当接口返回值为True时,表示当前已开启确定性计算开关,返回值为False则表示未开启。
-
API清单
当使用Atlas A2系列产品或Atlas A3系列产品时,表1所示API计算存在随机性,开启确定性计算开关可以保持计算结果的确定性。
| API |
|---|
torch.nn.functional.batch_norm |
torch.nn.functional.binary_cross_entropy |
torch.nn.functional.ctc_loss |
torch.cumsum |
torch.dot |
torch.matmul |
torch.nn.functional.embedding |
torch.nn.functional.nll_loss |
torch.nn.functional.prelu |
torch.mean |
torch.nn.functional.adaptive_avg_pool2d |
torch.nn.functional.avg_pool2d |
torch.nn.functional.binary_cross_entropy_with_logits |
torch.nn.functional.mse_loss |
torch.addbmm |
torch.Tensor.addbmm_ |
torch.addmv |
torch.Tensor.addmv_ |
torch.nn.functional.l1_loss |
torch.nn.functional.smooth_l1_loss |
torch.addmm |
torch.Tensor.addmm |
torch.mm |
torch.bmm |
torch.nn.functional.layer_norm |
Tensor.put_ |
torch.Tensor.index_put |
torch.Tensor.index_put_ |
torch.ops.aten.convolution_backward |
torch.nn.NLLLoss2d |
torch.nn.functional.fold |
torch.nn.functional.unfold |
torch.nn.functional.kl_div |
torch.nn.functional.multilabel_margin_loss |
torch.std_mean |
torch.std |
torch.var_mean |
torch.var |
torch.sum |
torch.nn.functional.interpolate |
torch.nn.functional.soft_margin_loss |
torch.trace |
torch.mv |
当使用Ascend 950DT系列产品时,表2所示API计算存在随机性,开启确定性计算开关可以保持计算结果的确定性。
| API |
|---|
torch.Tensor.put_ |
torch.max_unpool2d |
torch.max_unpool3d |
torch._unique |
torch._unique2 |
torch.scatter_add |
torch.Tensor.scatter_add_ |
torch.scatter |
torch.Tensor.scatter_ |
torch.index_add |
torch.bincount |
torch.index_copy |
torch.index_copy_ |
torch.Tensor.index_put_ |
torch.linalg.vector_norm |
torch.ops.aten.upsample_bicubic2d 反向 |
torch.ops.aten.upsample_bilinear2d 反向 |
torch.ops.aten.upsample_linear1d 反向 |
torch.ops.aten._upsample_bilinear2d_aa 反向 |
torch.ops.aten._upsample_bicubic2d_aa 反向 |
torch.nn.functional.adaptive_max_pool3d 反向 |
torch.nn.functional.batch_norm |
torch.Tensor.coalesce |
torch.grid_sampler_2d 反向 |
torch.grid_sampler_3d 反向 |