已合并
ttfhw-解决关联issue #3483
关龙锋创建于 7月31日
ttfhw-解决关联issue #3483
已合并
共 6 个文件变更+66-38
| @@ -6,7 +6,7 @@ | |||
| 6 | "target": "dev", | 6 | "target": "dev", |
| 7 | "args": { | 7 | "args": { |
| 8 | "PY_VERSION": "3.10", | 8 | "PY_VERSION": "3.10", |
| 9 | - "TORCH_VERSION": "2.13.0", | 9 | + "TORCH_VERSION": "2.12.0", |
| 10 | "CANN_VERSION": "9.1.0_beta.1", | 10 | "CANN_VERSION": "9.1.0_beta.1", |
| 11 | "CANN_PRODUCT": "910b" | 11 | "CANN_PRODUCT": "910b" |
| 12 | } | 12 | } |
| @@ -95,7 +95,7 @@ pip3 uninstall torchair | |||
| 95 | 95 | ||
| 96 | # 快速上手 | 96 | # 快速上手 |
| 97 | 97 | ||
| 98 | -本的调试(CPU调试): | 98 | +本的调试(最小CPU调试): |
| 99 | 99 | ||
| 100 | 1、在执行./configure设置ASCEND_SDK_PATH如(ASCEND_SDK_PATH=xx/Ascend/ascend-toolkit/latest/)。 | 100 | 1、在执行./configure设置ASCEND_SDK_PATH如(ASCEND_SDK_PATH=xx/Ascend/ascend-toolkit/latest/)。 |
| 101 | 101 | ||
| @@ -105,6 +105,34 @@ pip3 uninstall torchair | |||
| 105 | source tools/env.sh | 105 | source tools/env.sh |
| 106 | ``` | 106 | ``` |
| 107 | 107 | ||
| 108 | +npu设备调试: | ||
| 109 | + | ||
| 110 | +## 1、安装torch_npu | ||
| 111 | + | ||
| 112 | +torch_npu版本可以根据环境要求安装,请参照[版本配套表]。 | ||
| 113 | + | ||
| 114 | +```bash | ||
| 115 | +pip3 install numpy | ||
| 116 | +pip3 install pyyaml | ||
| 117 | +pip3 install setuptools | ||
| 118 | +pip3 install torch_npu==2.12 # 通过pip安装torch_npu时会自动安装依赖的torch版本 | ||
🟡 Medium Priority 第 117 行(本 diff 新增)的安装指令 建议:确认 torch_npu 实际可用的精确版本号(如 ![]() ![]() | |||
| 119 | +``` | ||
| 120 | + | ||
| 121 | +如果安装了真实torch_npu,需要把torch_npu的stubs模块链接环境去除,否则无法正常使用。 | ||
| 122 | +如LD_LIBRARY_PATH中去除/workspace/build/stubs设置,如果没有设置请忽略。 | ||
| 123 | + | ||
| 124 | +## 2、安装CANN主线版本 | ||
| 125 | + | ||
| 126 | +npu调试依赖CANN主线版本。如果您是外部用户,可以联系对应的支撑团队获取安装包。 | ||
| 127 | + | ||
| 128 | +执行前,需要执行 CANN 安装目录下的 set_env.sh 设置 CANN 相关环境变量 | ||
| 129 | + | ||
| 130 | +> 例如CANN安装路径为 `/usr/local/Ascend/cann`,则执行: | ||
| 131 | + | ||
| 132 | +```bash | ||
| 133 | +source /usr/local/Ascend/cann/set_env.sh | ||
| 134 | +``` | ||
| 135 | + | ||
| 108 | 执行以下python脚本快速验证TorchAir基本功能 | 136 | 执行以下python脚本快速验证TorchAir基本功能 |
| 109 | 137 | ||
| 110 | ```python | 138 | ```python |
| @@ -128,10 +156,6 @@ y = torch.randn(2, 2) | |||
| 128 | model(x, y) | 156 | model(x, y) |
| 129 | ``` | 157 | ``` |
| 130 | 158 | ||
| 131 | -# 开发者自测UT | ||
| 132 | - | ||
| 133 | -参考[docs](CONTRIBUTING.md)设置执行 | ||
| 134 | - | ||
| 135 | # 特性介绍 | 159 | # 特性介绍 |
| 136 | 160 | ||
| 137 | TorchAir常用特性如下,全量特性介绍请访问[docs](docs/zh/_menu_torchair.md)获取详细教程。 | 161 | TorchAir常用特性如下,全量特性介绍请访问[docs](docs/zh/_menu_torchair.md)获取详细教程。 |
| @@ -169,13 +193,11 @@ TorchAir常用特性如下,全量特性介绍请访问[docs](docs/zh/_menu_tor | |||
| 169 | 193 | ||
| 170 | <a id="hardware_support"></a> | 194 | <a id="hardware_support"></a> |
| 171 | 195 | ||
| 172 | -1、torch_npu的版本选择请参照[版本配套表],下载地址:[TorchNPUReleases](https://gitcode.com/Ascend/pytorch/releases)。 | 196 | +torch_npu的版本选择请参照[版本配套表],下载地址:[TorchNPUReleases](https://gitcode.com/Ascend/pytorch/releases)。 |
| 173 | 197 | ||
| 174 | 示例: | 198 | 示例: |
| 175 | https://gitcode.com/Ascend/pytorch/releases/download/v26.1.0-pytorch2.10.0/torch_npu-2.10.0.post4-cp310-cp310-manylinux_2_28_x86_64.whl | 199 | https://gitcode.com/Ascend/pytorch/releases/download/v26.1.0-pytorch2.10.0/torch_npu-2.10.0.post4-cp310-cp310-manylinux_2_28_x86_64.whl |
| 176 | 200 | ||
| 177 | -2、你还可以自己下载torch_npu源码根据readme提示自己编译安装[Torch_npu](https://gitcode.com/Ascend/pytorch) | ||
| 178 | - | ||
| 179 | # 支持的型号 | 201 | # 支持的型号 |
| 180 | 202 | ||
| 181 | - Ascend 950PR/Ascend 950DT | 203 | - Ascend 950PR/Ascend 950DT |
| @@ -46,7 +46,7 @@ FROM base AS builder | |||
| 46 | 46 | ||
| 47 | ARG PY_VERSION | 47 | ARG PY_VERSION |
| 48 | ARG DEVTOOLSET_VERSION=13 | 48 | ARG DEVTOOLSET_VERSION=13 |
| 49 | -ARG TORCH_VERSION=2.13.0 | 49 | +ARG TORCH_VERSION=2.12.0 |
| 50 | ARG TARGETARCH | 50 | ARG TARGETARCH |
| 51 | 51 | ||
| 52 | RUN yum install -y \ | 52 | RUN yum install -y \ |
| @@ -91,7 +91,8 @@ RUN case "${PY_VERSION}" in \ | |||
| 91 | *.dev*) pip${PY_VERSION} install torch==${TORCH_VERSION} --index-url https://download.pytorch.org/whl/nightly/cpu ;; \ | 91 | *.dev*) pip${PY_VERSION} install torch==${TORCH_VERSION} --index-url https://download.pytorch.org/whl/nightly/cpu ;; \ |
| 92 | *) pip${PY_VERSION} install torch==${TORCH_VERSION} --index-url https://download.pytorch.org/whl/cpu ;; \ | 92 | *) pip${PY_VERSION} install torch==${TORCH_VERSION} --index-url https://download.pytorch.org/whl/cpu ;; \ |
| 93 | esac && \ | 93 | esac && \ |
| 94 | - pip${PY_VERSION} install numpy==${NUMPY_VER} | 94 | + pip${PY_VERSION} install numpy==${NUMPY_VER} && \ |
| 95 | + pip${PY_VERSION} install torch_npu | ||
| 95 | 96 | ||
| 96 | FROM builder AS dev | 97 | FROM builder AS dev |
| 97 | 98 | ||
| @@ -17,7 +17,7 @@ base manylinux + Python 软链接 + pip 源 + 基础系统包(curl/wget | |||
| 17 | 17 | ||
| 18 | > Dockerfile会自动根据当前架构(ARM/X86)拉取对应镜像。 | 18 | > Dockerfile会自动根据当前架构(ARM/X86)拉取对应镜像。 |
| 19 | > Driver 不包含在镜像中,用户需在宿主机自行安装。镜像仅提供 CANN 编译环境,运行时需宿主机已安装匹配的 NPU 驱动。 | 19 | > Driver 不包含在镜像中,用户需在宿主机自行安装。镜像仅提供 CANN 编译环境,运行时需宿主机已安装匹配的 NPU 驱动。 |
| 20 | -> 镜像中预装的 PyTorch CPU 版本默认为 v2.13.0 分支对应的版本(`torch==2.13.0`)。可通过构建参数 `TORCH_VERSION` 指定稳定版本(如 `2.7.1`),详见 [构建参数参考](#构建参数参考)。 | 20 | +> 镜像中预装的 PyTorch CPU 版本默认为 v2.12.0 分支对应的版本(`torch==2.12.0`)。可通过构建参数 `TORCH_VERSION` 指定稳定版本(如 `2.7.1`),详见 [构建参数参考](#构建参数参考)。 |
| 21 | 21 | ||
| 22 | ## 2 镜像构建 | 22 | ## 2 镜像构建 |
| 23 | 23 | ||
| @@ -30,15 +30,15 @@ export DOCKER_BUILDKIT=1 | |||
| 30 | 30 | ||
| 31 | #### 构建参数参考 | 31 | #### 构建参数参考 |
| 32 | 32 | ||
| 33 | -| ARG | 默认值 | 说明 | 适用阶段 | | 33 | +| ARG | 默认值 | 说明 | 适用阶段 | |
| 34 | -|-----|--------|------|---------| | 34 | +|-----|----------------|---------------------------------------------------------------------------------------|---------| |
| 35 | -| `PY_VERSION` | `3.10` | Python 版本,仅安装对应版本依赖 | all | | 35 | +| `PY_VERSION` | `3.10` | Python 版本,仅安装对应版本依赖 | all | |
| 36 | -| `TORCH_VERSION` | `2.13.0` | PyTorch 版本,格式 `x.x.x`(如 `2.13.0`)或 dev 版本(如 `2.13.0.dev20260610`);dev 版本从 nightly 源安装 | all | | 36 | +| `TORCH_VERSION` | `2.12.0` | PyTorch 版本,格式 `x.x.x`(如 `2.12.0`)或 dev 版本(如 `2.13.0.dev20260610`);dev 版本从 nightly 源安装 | all | |
| 37 | -| `DEVTOOLSET_VERSION` | `13` | GCC toolset 版本 | builder | | 37 | +| `DEVTOOLSET_VERSION` | `13` | GCC toolset 版本 | builder | |
| 38 | -| `CANN_VERSION` | `9.1.0_beta.1` | CANN 版本号 | dev | | 38 | +| `CANN_VERSION` | `9.1.0_beta.1` | CANN 版本号 | dev | |
| 39 | -| `CANN_PRODUCT` | `910b` | CANN 算子包产品类型 | dev | | 39 | +| `CANN_PRODUCT` | `910b` | CANN 算子包产品类型 | dev | |
| 40 | -| `INSTALL_NNAL` | `0` | 是否安装 NNAL 神经网络加速库 | dev | | 40 | +| `INSTALL_NNAL` | `0` | 是否安装 NNAL 神经网络加速库 | dev | |
| 41 | -| `CANN_RELEASE_TRAIN` | - | CANN 发布版本号,仅当`CANN_VERSION`与默认值不同时需手动指定 | dev | | 41 | +| `CANN_RELEASE_TRAIN` | - | CANN 发布版本号,仅当`CANN_VERSION`与默认值不同时需手动指定 | dev | |
| 42 | 42 | ||
| 43 | #### 使用示例 | 43 | #### 使用示例 |
| 44 | 44 | ||
| @@ -15,7 +15,7 @@ INSTALL_NNAL=0 | |||
| 15 | NO_CACHE=0 | 15 | NO_CACHE=0 |
| 16 | CANN_RELEASE_TRAIN="" | 16 | CANN_RELEASE_TRAIN="" |
| 17 | IMAGE_TARGET="builder" | 17 | IMAGE_TARGET="builder" |
| 18 | -TORCH_VERSION="2.13.0" | 18 | +TORCH_VERSION="2.12.0" |
| 19 | 19 | ||
| 20 | function usage() { | 20 | function usage() { |
| 21 | cat <<EOF | 21 | cat <<EOF |
| @@ -23,7 +23,7 @@ Usage: $0 [OPTIONS] | |||
| 23 | 23 | ||
| 24 | Options: | 24 | Options: |
| 25 | -p, --python VERSION Python version: 3.10 3.11 3.12 3.13 3.14 (default: 3.10) | 25 | -p, --python VERSION Python version: 3.10 3.11 3.12 3.13 3.14 (default: 3.10) |
| 26 | - --torch-version VER PyTorch version: x.x.x (e.g. 2.7.1, 2.12.0) or dev version (e.g. 2.13.0.dev20260610) (default: 2.13.0) | 26 | + --torch-version VER PyTorch version: x.x.x (e.g. 2.7.1, 2.12.0) |
| 27 | --no-cache Build docker image without cache | 27 | --no-cache Build docker image without cache |
| 28 | -h, --help Show this help message | 28 | -h, --help Show this help message |
| 29 | 29 | ||
| @@ -3,6 +3,7 @@ import os | |||
| 3 | import shutil | 3 | import shutil |
| 4 | import sys | 4 | import sys |
| 5 | import contextlib | 5 | import contextlib |
| 6 | +import re | ||
| 6 | 7 | ||
| 7 | import torch | 8 | import torch |
| 8 | import unittest | 9 | import unittest |
| @@ -2203,9 +2204,9 @@ class TorchairSt(unittest.TestCase): | |||
| 2203 | content = dump_file.readlines() | 2204 | content = dump_file.readlines() |
| 2204 | dump_line = [line for line in content if line.startswith("## FX Code")][0] | 2205 | dump_line = [line for line in content if line.startswith("## FX Code")][0] |
| 2205 | 2206 | ||
| 2206 | - self.assertTrue("add: torch.float32[s0, s0]cpu" in dump_line) | 2207 | + self.assertRegex(dump_line, r"add: torch\.float32\[s\d+, s\d+\]cpu") |
| 2207 | - self.assertTrue("arg1_1: torch.float32[s0, s0]cpu" in dump_line) | 2208 | + self.assertRegex(dump_line, r"arg1_1: torch\.float32\[s\d+, s\d+\]cpu") |
| 2208 | - self.assertTrue("arg2_1: torch.float32[s0, s0]cpu" in dump_line) | 2209 | + self.assertRegex(dump_line, r"arg2_1: torch\.float32\[s\d+, s\d+\]cpu") |
| 2209 | 2210 | ||
| 2210 | def test_output_always_with_correct_dtype(self): | 2211 | def test_output_always_with_correct_dtype(self): |
| 2211 | m = torch.library.Library("test", "DEF") | 2212 | m = torch.library.Library("test", "DEF") |
| @@ -2571,19 +2572,23 @@ class TorchairSt(unittest.TestCase): | |||
| 2571 | for op in geGraph.op: | 2572 | for op in geGraph.op: |
| 2572 | if op.name == "MyOpInfer": | 2573 | if op.name == "MyOpInfer": |
| 2573 | inference_rule = json.loads(op.attr["_inference_rule"].s) | 2574 | inference_rule = json.loads(op.attr["_inference_rule"].s) |
| 2574 | - self.assertEqual(inference_rule["shape"]["inputs"][0][0], "s0") | 2575 | + input0_shape = inference_rule["shape"]["inputs"][0] |
| 2575 | - self.assertEqual(inference_rule["shape"]["inputs"][0][1], "s1") | 2576 | + input1_shape = inference_rule["shape"]["inputs"][1] |
| 2576 | - self.assertEqual(inference_rule["shape"]["inputs"][1][0], "s2") | 2577 | + self.assertRegex(input0_shape[0], r"s\d+") |
| 2577 | - self.assertEqual(inference_rule["shape"]["inputs"][1][1], "s3") | 2578 | + self.assertRegex(input0_shape[1], r"s\d+") |
| 2579 | + self.assertRegex(input1_shape[0], r"s\d+") | ||
| 2580 | + self.assertRegex(input1_shape[1], r"s\d+") | ||
| 2578 | 2581 | ||
| 2579 | - is_high_python_version = hasattr(ast, 'unparse') | 2582 | + output0_shape = inference_rule["shape"]["outputs"][0] |
| 2580 | - s0_out = "s0 + 2" if is_high_python_version else "(s0+2)" | 2583 | + output1_shape = inference_rule["shape"]["outputs"][1] |
| 2581 | - self.assertEqual(inference_rule["shape"]["outputs"][0][0], s0_out) | 2584 | + plus_pattern = rf"\(?{re.escape(input0_shape[0])}\s*\+\s*2\)?" |
| 2582 | - s1_out = "s1 - 2" if is_high_python_version else "(s1-2)" | 2585 | + minus_pattern = rf"\(?{re.escape(input0_shape[1])}\s*-\s*2\)?" |
| 2583 | - self.assertEqual(inference_rule["shape"]["outputs"][0][1], s1_out) | 2586 | + mul_pattern = rf"\(?2\s*\*\s*{re.escape(input1_shape[0])}\)?" |
| 2584 | - s2_out = "2 * s2" if is_high_python_version else "(2*s2)" | 2587 | + floor_div_pattern = rf"Floor\(Div\({re.escape(input1_shape[1])},\s*2\)\)" |
| 2585 | - self.assertEqual(inference_rule["shape"]["outputs"][1][0], s2_out) | 2588 | + self.assertRegex(output0_shape[0], plus_pattern) |
| 2586 | - self.assertEqual(inference_rule["shape"]["outputs"][1][1], "Floor(Div(s3, 2))") | 2589 | + self.assertRegex(output0_shape[1], minus_pattern) |
| 2590 | + self.assertRegex(output1_shape[0], mul_pattern) | ||
| 2591 | + self.assertRegex(output1_shape[1], floor_div_pattern) | ||
| 2587 | 2592 | ||
| 2588 | self.assertEqual(inference_rule["dtype"][0], 3) | 2593 | self.assertEqual(inference_rule["dtype"][0], 3) |
| 2589 | self.assertEqual(inference_rule["dtype"][1], 0) | 2594 | self.assertEqual(inference_rule["dtype"][1], 0) |


🟡 Medium Priority
第 111 行(本 diff 新增)使用了 Markdown 快捷引用链接语法
[版本配套表],但文档中不存在对应的链接定义[版本配套表]: <url>。在 GitCode/GitHub 等标准 Markdown 渲染器下,该文本将原样显示为带方括号的[版本配套表]而非可点击的超链接。同一文档第 15 行的正确写法是[版本配套表](#version_match)(内联链接,指向<a id="version_match"></a>锚点),第 111 行应保持一致。建议:将
[版本配套表]改为[版本配套表](#version_match),与文档第 15 行保持一致。