diff --git a/.ci/docker/README.md b/.ci/docker/README.md new file mode 100644 index 0000000000..0f8388e268 --- /dev/null +++ b/.ci/docker/README.md @@ -0,0 +1,49 @@ +# torch-npu CI Docker Images + +本目录管理 torch-npu 项目的测试镜像 (test),当前仅支持 aarch64 架构。 + +## 镜像类型 + +| 类型 | 基座 | 用途 | +|------|------|------| +| **test** | ubuntu:22.04 | CI 单元测试运行环境,包含 PyTorch nightly、CANN runtime、triton-ascend 和测试框架 | + +## 目录结构 + +``` +.ci/docker/ +├── README.md +├── requirements-test.txt # Test 镜像 pip 依赖 +├── docker_build.sh # 构建入口脚本 +├── common/ # 共享安装脚本 +│ ├── install_cann.sh # 安装 CANN toolkit (支持 A2/A3) +│ ├── install_triton.sh # 安装 triton-ascend +│ └── install_obs.sh # 安装华为 OBS util +└── test/ + └── Dockerfile.aarch64 +``` + +## 快速构建 + +```bash +./docker_build.sh torch-npu-test-aarch64-cann-a2-py3.10-torch-nightly +./docker_build.sh torch-npu-test-aarch64-cann-a3-py3.10-torch-nightly +``` + +## Tag 命名规范 + +``` +torch-npu-test-aarch64-cann-py-torch-nightly +``` + +| 字段 | 可选值 | +|------|--------| +| CHIP | A2 (Ascend 910b), A3 | +| PYTHON_VERSION | 3.10 | + +## CANN 芯片映射 + +| CANN_CHIP | 芯片 | CANN 版本 | +|-----------|------|----------| +| A2 | Ascend 910b | 9.1.0-beta.1 | +| A3 | Ascend A3 | 9.0.0-beta.2 | diff --git a/.ci/docker/common/install_cann.sh b/.ci/docker/common/install_cann.sh new file mode 100755 index 0000000000..4af49bbb89 --- /dev/null +++ b/.ci/docker/common/install_cann.sh @@ -0,0 +1,109 @@ +#!/usr/bin/bash +# Install CANN toolkit for Ascend NPU. +# Usage: CANN_CHIP=A1 ./install_cann.sh +# CANN_CHIP: A1 (Ascend 910), A2 (Ascend 910b), A3 (Ascend A3) +# Automatically detects architecture (x86_64 / aarch64). + +set -e + +CANN_CHIP="${CANN_CHIP:-A1}" +ARCH=$(uname -m) + +BASE_URL="https://pytorch-package.obs.cn-north-4.myhuaweicloud.com/pta/cann-package" +CANN_BASE_URL="https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/CANN/CANN%209.1.T1" + +case "${ARCH}_${CANN_CHIP}" in + # x86_64 + x86_64_A1) + TOOLKIT_URL="${BASE_URL}/20260513/Ascend-cann-toolkit_9.1.0_linux-x86_64.run" + OPS_URL="${BASE_URL}/20260513/Ascend-cann-910-ops_9.1.0_linux-x86_64.run" + NNAL_URL="${BASE_URL}/20260513/Ascend-cann-nnal_9.1.0_linux-x86_64.run" + OPS_GLOB="Ascend-cann-910*" + SET_ENV_PATH="/usr/local/Ascend/cann/set_env.sh" + ;; + x86_64_A2) + TOOLKIT_URL="${CANN_BASE_URL}/Ascend-cann-toolkit_9.1.0-beta.1_linux-x86_64.run" + OPS_URL="${CANN_BASE_URL}/Ascend-cann-910b-ops_9.1.0-beta.1_linux-x86_64.run" + NNAL_URL="${CANN_BASE_URL}/Ascend-cann-nnal_9.1.0-beta.1_linux-x86_64.run" + OPS_GLOB="Ascend-cann-910b-ops*" + SET_ENV_PATH="/usr/local/Ascend/cann/set_env.sh" + ;; + x86_64_A3) + TOOLKIT_URL="${CANN_BASE_URL}/Ascend-cann-toolkit_9.1.0-beta.1_linux-x86_64.run" + OPS_URL="${CANN_BASE_URL}/Ascend-cann-A3-ops_9.1.0-beta.1_linux-x86_64.run" + NNAL_URL="${CANN_BASE_URL}/Ascend-cann-nnal_9.1.0-beta.1_linux-x86_64.run" + OPS_GLOB="Ascend-cann-A3-ops*" + SET_ENV_PATH="/usr/local/Ascend/cann/set_env.sh" + ;; + # aarch64 + aarch64_A1) + TOOLKIT_URL="${BASE_URL}/20260302/Ascend-cann-toolkit_9.0.0-beta.1_linux-aarch64.run" + OPS_URL="${BASE_URL}/20260302/Ascend-cann-910b-ops_9.0.0-beta.1_linux-aarch64.run" + NNAL_URL="${BASE_URL}/20260302/Ascend-cann-nnal_9.0.0-beta.1_linux-aarch64.run" + OPS_GLOB="Ascend-cann-910b*" + SET_ENV_PATH="/usr/local/Ascend/cann/set_env.sh" + ;; + aarch64_A2) + TOOLKIT_URL="${CANN_BASE_URL}/Ascend-cann-toolkit_9.1.0-beta.1_linux-aarch64.run" + OPS_URL="${CANN_BASE_URL}/Ascend-cann-910b-ops_9.1.0-beta.1_linux-aarch64.run" + NNAL_URL="${CANN_BASE_URL}/Ascend-cann-nnal_9.1.0-beta.1_linux-aarch64.run" + OPS_GLOB="Ascend-cann-910b-ops*" + SET_ENV_PATH="/usr/local/Ascend/cann/set_env.sh" + ;; + aarch64_A3) + TOOLKIT_URL="${CANN_BASE_URL}/Ascend-cann-toolkit_9.1.0-beta.1_linux-aarch64.run" + OPS_URL="${CANN_BASE_URL}/Ascend-cann-A3-ops_9.1.0-beta.1_linux-aarch64.run" + NNAL_URL="${CANN_BASE_URL}/Ascend-cann-nnal_9.1.0-beta.1_linux-aarch64.run" + OPS_GLOB="Ascend-cann-A3-ops*" + SET_ENV_PATH="/usr/local/Ascend/cann/set_env.sh" + ;; + *) + echo "Unsupported combination: ${ARCH} + ${CANN_CHIP}" + exit 1 + ;; +esac + +echo "Installing CANN ${CANN_CHIP} for ${ARCH}..." + +echo "=== Creating HwHiAiUser user and group ===" +groupadd -f HwHiAiUser +id -u HwHiAiUser >/dev/null 2>&1 || useradd -g HwHiAiUser -d /home/HwHiAiUser -m HwHiAiUser -s /bin/bash + +rm -rf cann +mkdir -p cann && cd cann + +echo "=== Downloading CANN packages ===" +curl -O "${TOOLKIT_URL}" +curl -O "${OPS_URL}" +curl -O "${NNAL_URL}" +echo "Download complete." + +chmod +x Ascend-cann*.run + +echo "=== Installing CANN toolkit ===" +./Ascend-cann-toolkit*.run --full --quiet --install-path=/usr/local/Ascend +source "${SET_ENV_PATH}" +echo "toolkit install success" + +echo "=== Installing CANN ops ===" +./${OPS_GLOB}.run --install --quiet --install-path=/usr/local/Ascend +echo "ops install success" + +echo "=== Installing CANN nnal ===" +./Ascend-cann-nnal*.run --install --quiet --install-path=/usr/local/Ascend +source /usr/local/Ascend/nnal/atb/set_env.sh +echo "nnal install success" + +# Some CANN versions install to versioned paths (e.g. cann-9.0.0-beta.2) +# instead of /usr/local/Ascend/cann/. Fix broken symlinks so runtime +# sourcing of set_env.sh works. +if [ ! -f /usr/local/Ascend/cann/set_env.sh ]; then + CANN_REAL_DIR=$(ls -d /usr/local/Ascend/cann-* 2>/dev/null | head -1) + if [ -n "${CANN_REAL_DIR}" ]; then + ln -sf "${CANN_REAL_DIR}" /usr/local/Ascend/cann + echo "Fixed: linked ${CANN_REAL_DIR} -> /usr/local/Ascend/cann" + fi +fi + +rm -rf * +echo "CANN ${CANN_CHIP} installation complete." \ No newline at end of file diff --git a/.ci/docker/common/install_obs.sh b/.ci/docker/common/install_obs.sh new file mode 100755 index 0000000000..1acea84f2b --- /dev/null +++ b/.ci/docker/common/install_obs.sh @@ -0,0 +1,21 @@ +#!/usr/bin/bash +# Install Huawei OBS util for object storage access. + +set -e + +ARCH=$(uname -m) +case "${ARCH}" in + x86_64) OBS_ARCH="amd64" ;; + aarch64) OBS_ARCH="arm64" ;; + *) echo "Unsupported architecture: ${ARCH}"; exit 1 ;; +esac + +OBS_URL="https://obs-community.obs.cn-north-1.myhuaweicloud.com/obsutil/current/obsutil_linux_${OBS_ARCH}.tar.gz" + +wget -q "${OBS_URL}" +mkdir -p /usr/local/obsutil +tar -zxf "obsutil_linux_${OBS_ARCH}.tar.gz" -C /usr/local/obsutil/ +rm -f "obsutil_linux_${OBS_ARCH}.tar.gz" +ln -sf /usr/local/obsutil/obsutil_linux_${OBS_ARCH}_*/obsutil /usr/local/bin/obsutil + +echo "OBS util installed." diff --git a/.ci/docker/common/install_triton.sh b/.ci/docker/common/install_triton.sh new file mode 100755 index 0000000000..ed76bca16d --- /dev/null +++ b/.ci/docker/common/install_triton.sh @@ -0,0 +1,19 @@ +#!/usr/bin/bash +# Install triton-ascend for NPU. +# Usage: ./install_triton.sh +# PYTHON_VERSION: e.g. 3.10, 3.11, 3.12, 3.13 + +set -e + +TRITON_VERSION="${TRITON_VERSION:-3.2.1}" +PYTHON_VERSION="${1:?Usage: $0 (e.g. 3.10)}" + +ARCH=$(uname -m) +PY_SHORT=$(echo "${PYTHON_VERSION}" | tr -d '.') + +TRITON_WHL="triton_ascend-${TRITON_VERSION}-cp${PY_SHORT}-cp${PY_SHORT}-manylinux_2_27_${ARCH}.manylinux_2_28_${ARCH}.whl" +TRITON_URL="https://gitcode.com/Ascend/triton-ascend/releases/download/v${TRITON_VERSION}/${TRITON_WHL}" + +echo "Installing triton-ascend ${TRITON_VERSION} for Python ${PYTHON_VERSION} (${ARCH})..." +pip3 install --no-cache-dir "${TRITON_URL}" +echo "triton-ascend installed." diff --git a/.ci/docker/docker_build.sh b/.ci/docker/docker_build.sh new file mode 100755 index 0000000000..b32b0d40f7 --- /dev/null +++ b/.ci/docker/docker_build.sh @@ -0,0 +1,56 @@ +#!/usr/bin/bash +# Docker image build script for torch-npu CI test images (aarch64 only). +# +# Usage: +# ./docker_build.sh +# +# Examples: +# ./docker_build.sh torch-npu-test-aarch64-cann-a2-py3.10-torch-nightly +# ./docker_build.sh torch-npu-test-aarch64-cann-a3-py3.10-torch-nightly + +set -euo pipefail + +BASE_TAG="${1:?Usage: $0 }" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BUILD_CONTEXT="${SCRIPT_DIR}" + +case "$BASE_TAG" in + torch-npu-test-aarch64-cann-a2-py3.10-torch-nightly) + CANN_CHIP=A2 + PYTHON_VERSION=3.10 + ;; + torch-npu-test-aarch64-cann-a3-py3.10-torch-nightly) + CANN_CHIP=A3 + PYTHON_VERSION=3.10 + ;; + *) + echo "ERROR: Unknown image tag: $BASE_TAG" + echo "" + echo "Supported tags:" + echo " torch-npu-test-aarch64-cann-a2-py3.10-torch-nightly" + echo " torch-npu-test-aarch64-cann-a3-py3.10-torch-nightly" + exit 1 + ;; +esac + +TIMESTAMP="$(date +%Y%m%d%H%M)" +TAG="${BASE_TAG}-${TIMESTAMP}" + +DOCKERFILE="${SCRIPT_DIR}/test/Dockerfile.aarch64" + +echo "=== Image Configuration ===" +echo " Architecture: aarch64" +echo " CANN Chip: ${CANN_CHIP}" +echo " Python: ${PYTHON_VERSION}" +echo " PyTorch: nightly" +echo " Full Tag: ${TAG}" + +echo "=== Building test image: ${TAG} ===" +docker build \ + --build-arg CANN_CHIP="${CANN_CHIP}" \ + --build-arg PYTHON_VERSION="${PYTHON_VERSION}" \ + --tag "${TAG}" \ + --file "${DOCKERFILE}" \ + "${BUILD_CONTEXT}" + +echo "=== Image built successfully: ${TAG} ===" diff --git a/.ci/docker/requirements-post.txt b/.ci/docker/requirements-post.txt new file mode 100644 index 0000000000..779d6634e0 --- /dev/null +++ b/.ci/docker/requirements-post.txt @@ -0,0 +1,11 @@ +# Python dependencies that require PyTorch to be pre-installed. +# Install AFTER PyTorch is built, before running tests. +# Uses PyTorch nightly index to resolve torch-dependent packages. + +--index-url https://download.pytorch.org/whl/nightly/cpu +--extra-index-url https://pypi.org/simple +-f https://data.pyg.org/whl/torch-2.13.0+cpu.html + +torchvision +torch_geometric==2.5.3 +torch-scatter==2.1.2 diff --git a/.ci/docker/requirements-test-annotated.md b/.ci/docker/requirements-test-annotated.md new file mode 100644 index 0000000000..596d7aa8b1 --- /dev/null +++ b/.ci/docker/requirements-test-annotated.md @@ -0,0 +1,181 @@ +# requirements-test.txt 依赖说明文档 + +> **用途**: 安装在 torch-npu CI Docker 测试镜像中,用于构建和运行上游 PyTorch 测试用例。 +> +> **对齐基准**: 上游 PyTorch `.ci/docker/requirements-ci.txt` (py3.10 / jammy profile) +> +> **安装位置**: `.ci/docker/test/Dockerfile.aarch64:78` +> ```dockerfile +> RUN conda run -n py_${PYTHON_VERSION} pip install --no-cache-dir -r /opt/buildtools/requirements-test.txt +> ``` + +--- + +## 目录 + +- [Core test frameworks](#core-test-frameworks) +- [Type checking](#type-checking) +- [Core scientific](#core-scientific) +- [Data & serialization](#data--serialization) +- [ONNX](#onnx) +- [ML / data processing](#ml--data-processing) +- [Image / audio / ML](#image--audio--ml) +- [Utilities](#utilities) +- [Build tools](#build-tools) +- [Solver / optimization](#solver--optimization) +- [Test utilities](#test-utilities) +- [Infrastructure](#infrastructure) + +--- + +## Core test frameworks + +| 包名 | 版本 | 上游对应 | 引用位置 | 说明 | +|------|------|---------|---------|------| +| `pytest` | `7.3.2` | ✅ 一致 | 全部 `test/*.py` | 测试框架主体,`test/run_test.py` 核心调度 | +| `pytest-xdist` | `3.3.1` | ✅ 一致 | `test/conftest.py:142`, `test/run_test.py:1361` | 并行测试执行,`-n` 参数 | +| `pytest-flakefinder` | `1.1.0` | ✅ 一致 | `test/run_test.py:547,2289` | 重跑测试以发现 flaky tests | +| `pytest-rerunfailures` | `>=10.3` | ✅ 一致 | `test/conftest.py:42` | 失败用例自动重试 | +| `pytest-subtests` | `0.13.1` | ✅ 一致 | `test/distributed/_composable/test_replicate_mixed_precision.py:73` | 子测试支持 | +| `pytest-cpp` | `2.3.0` | ✅ 一致 | `test/run_test.py:548` | pytest 调用 C++ 测试 | +| `xdoctest` | `1.3.0` | ✅ 一致 | `test/run_test.py:1162-1265` | 运行 docstring 中的 doctest | +| `hypothesis` | `6.56.4` | ✅ 一致 | `test/quantization/fx/test_quantize_fx.py:157`, `test/nn/test_nn.py` 等 | 基于属性的测试生成 | +| `expecttest` | `0.3.0` | ✅ 一致 | `test/test_tensorboard.py:11`, `test/inductor/test_cutedsl_template.py:5`, `test/benchmark_utils/test_benchmark_utils.py:12` 等 | 期望值自动填充测试 | +| `parameterized` | `0.8.1` | ✅ 一致 | `test/onnx/torchlib/test_ops.py:38`, `test/higher_order_ops/test_invoke_subgraph.py:12`, `test/onnx/test_models_onnxruntime.py:9` 等 | 参数化测试 | +| `unittest-xml-reporting` | `<=3.2.0,>=2.0.0` | ✅ 一致 | CI 测试结果 XML 输出 | `lxml` 是其依赖 | + +## Type checking + +| 包名 | 版本 | 上游对应 | 引用位置 | 说明 | +|------|------|---------|---------|------| +| `mypy` | `1.16.0` | ✅ 一致 | `test/test_type_hints.py:22` `import mypy.api`, `test/test_typing.py:22` `from mypy import api` | 类型检查测试 | + +## Core scientific + +| 包名 | 版本 | 上游对应 | 引用位置 | 说明 | +|------|------|---------|---------|------| +| `numpy` | `1.23.2` | ✅ 一致 (py3.10) | `test/` 下 277 个文件 import | 核心数值计算库 | +| `scipy` | `1.10.1` | ✅ 一致 (py<=3.11) | `test/` 下 41 个文件 import | 科学计算,`test_linalg.py`, `test_binary_ufuncs.py` 等 | +| `opt-einsum` | `3.3` | ✅ 一致 | `test/test_linalg.py` (einsum 优化) | 张量缩并顺序优化 | +| `sympy` | `1.13.3` | ✅ 一致 | `test/` 下 69 个文件引用 | 符号计算,形状推断、guard 条件 | +| `networkx` | `2.8.8` | ✅ 一致 | `test/functorch/test_aotdispatch.py:134,7088` | 复杂网络库,AOT dispatch 测试 | + +## Data & serialization + +| 包名 | 版本 | 上游对应 | 引用位置 | 说明 | +|------|------|---------|---------|------| +| `pillow` | `12.3.0` | ✅ 一致 | `test/test_tensorboard.py:118` `from PIL import Image`, `test/onnx/test_models_onnxruntime.py:10` | 图像处理 | +| `protobuf` | `6.33.5` | ✅ 一致 | `test/test_tensorboard.py:117` `from google.protobuf import text_format`, `test/onnx/torchlib/error_reproduction.py:28` | 序列化协议 | +| `dill` | `0.3.7` | ✅ 一致 | `test/test_datapipe.py:593` `@skipIfNoDill` | 序列化库,DataLoader 测试 | +| `flatbuffers` | `24.12.23` | ✅ 一致 | `test/onnx/` 目录 (ONNX 序列化) | 跨平台序列化 | +| `lxml` | `5.3.0` | ✅ 一致 (py<3.14) | `unittest-xml-reporting` 的依赖 | XML 处理,测试报告 | + +## ONNX + +| 包名 | 版本 | 上游对应 | 引用位置 | 说明 | +|------|------|---------|---------|------| +| `onnx` | `1.21.0` | ✅ 一致 | `test/` 下 57 个文件 import | ONNX 模型格式 | +| `onnx-ir` | `0.1.16` | ✅ 一致 | `onnxscript` 的依赖 | ONNX 内存 IR | +| `onnxruntime` | `1.23.1` | 上游注释掉,通过 `install_onnx.sh` 安装 | **torch-npu**: `test/onnx/test_pytorch_onnx_onnxruntime_npu.py:7`, `test/onnx/dynamo/test_dynamo_with_onnxruntime_backend.py:12`, `test/onnx/onnx_test_common.py:16`, `test/onnx/test_pytorch_jit_onnx.py:2`; **上游**: `test/onnx/` 7 个文件 | ONNX 推理引擎,ONNX 测试必需 | +| `onnxscript` | `0.6.2` | ✅ 一致 | `test/onnx/exporter/test_tensors.py:6`, `test/onnx/exporter/test_api.py:10`, `test/onnx/test_onnxscript_runtime.py:8` | ONNX Script 语言 | + +## ML / data processing + +| 包名 | 版本 | 上游对应 | 引用位置 | 说明 | +|------|------|---------|---------|------| +| `jinja2` | `3.1.6` | ✅ 一致 | `torch/_inductor/codegen/common.py:2619,2652`, `torch/_inductor/select_algorithm.py:2506`, `torch/distributed/debug/_frontend.py:15` | 模板引擎,Inductor 代码生成 | +| `filelock` | `3.20.3` | ✅ 一致 | `test/inductor/test_caching.py:18`, `torch/_inductor/debug.py:482`, `torch/_inductor/runtime/caching/locks.py:18` | 文件锁,Inductor 缓存 | +| `optree` | `0.13.0` | ✅ 一致 (py<3.14) | `test/` 下 4 个文件 import | 树结构操作,pytree | +| `ml-dtypes` | `0.5.1` | 上游不存在 | **torch-npu**: `test/custom_ops/test_npu_anti_quant.py:3` `from ml_dtypes import int4`; **上游**: `test/onnx/exporter/test_core.py:10` | 机器学习数据类型,NPU 量化算子测试 | +| `transformers` | `4.36.2` | 上游通过 `install_onnx.sh` 安装 `4.36.2` | **torch-npu**: `test/dynamo/test_model_output.py:13-16`, `test/onnx/dynamo/test_dynamo_with_onnxruntime_backend.py:398-399`; **上游**: `test/dynamo/test_model_output.py`, `test/inductor/test_padding.py`, `test/onnx/exporter/test_small_models_e2e.py` | HuggingFace Transformers,模型导出测试 | + +## Image / audio / ML + +| 包名 | 版本 | 上游对应 | 引用位置 | 说明 | +|------|------|---------|---------|------| +| `scikit-image` | `0.22.0` | ✅ 一致 | `test/test_nn.py` (图像处理) | 图像处理库 | +| `librosa` | `>=0.6.2` | ✅ 一致 (py3.10 不 pin) | `test/test_spectral_ops.py` | 音频分析 | +| `numba` | `0.57.1` | ✅ 一致 (py3.10) | `test/test_numba_integration.py:19` `import numba.cuda` | JIT 编译 | +| `tensorboard` | `2.13.0` | ✅ 一致 (py<3.13) | `test/test_tensorboard.py:17-18,119-122` | 可视化工具 | +| `pywavelets` | `1.4.1` | ✅ 一致 (py<3.12) | `scikit-image` 的依赖 | 小波变换 | + +## Utilities + +| 包名 | 版本 | 上游对应 | 引用位置 | 说明 | +|------|------|---------|---------|------| +| `tabulate` | `0.9.0` | ✅ 一致 | `test/test_compile_benchmark_util.py:16`, `torch/fx/graph.py:2595`, `torch/ao/quantization/fx/_model_report/model_report_visualizer.py:11` | 表格格式化输出 | +| `psutil` | 无pin | ✅ 一致 | `test/test_cuda.py:26`, `test/distributed/checkpoint/test_state_dict_stager.py:9`, `test/test_dataloader.py:69`, `test/profiler/test_profiler.py:119` | 系统资源监控 | +| `fsspec` | `>=0.8.5` | 上游在 `requirements.txt` 中 | `test/distributed/checkpoint/test_fsspec.py:10-11`, `torch/distributed/checkpoint/_fsspec_filesystem.py:11,23` | 文件系统抽象 | +| `packaging` | `24.2` | ✅ 一致 | `test/` 下 7 个文件 | 包版本管理 | +| `pyyaml` | `6.0.3` | ✅ 一致 | `test/` 下 9 个文件 | YAML 解析 | +| `typing-extensions` | `4.12.2` | ✅ 一致 (py<3.14) | `test/` + `torch/` 下 307 处引用 | 类型提示扩展 | +| `requests` | `2.32.0` | 上游注释掉 | `test/distributed/test_debug.py:13-14`, `test/distributed/test_c10d_fr_hook.py:431,700`, `test/distributed/elastic/test_control_plane.py:194` | HTTP 客户端 | +| `pybind11` | `3.0.1` | 上游通过 `install_triton.sh` 安装 | **torch-npu C++源码**: `torch_npu/csrc/npu/Graph.cpp:716`, `Stream.cpp:1`, `Event.cpp:3`, `Graph.h:4` 等 56 处 `#include `; `CMakeLists.txt:304` | C++/Python 绑定,torch_npu 编译必需 | +| `tqdm` | `>=4.66.0` | ✅ 一致 | `test/profiler/test_profiler.py:112`, `test/scripts/run_cuda_memcheck.py:23`, `benchmarks/dynamo/*` | 进度条 | +| `click` | 无pin | ✅ 一致 | `test/cpp/aoti_inference/generate_lowered_cpu.py:3`, `torch/csrc/jit/tensorexpr/scripts/bisect.py:68` | CLI 框架 | +| `pygments` | `2.20.0` | ✅ 一致 | doctest 语法高亮 | 代码高亮 | + +## Build tools + +| 包名 | 版本 | 上游对应 | 引用位置 | 说明 | +|------|------|---------|---------|------| +| `cmake` | `3.31.6` | ✅ 一致 | `ci/build.sh`, C++ 扩展测试构建 | 构建系统 | +| `ninja` | `1.13.0` | ✅ 一致 | `test/run_test.py`, `test_cpp_extensions_aot.py`, `test_determination.py` | 构建加速 | +| `build` | `1.3.0` | ✅ 一致 | `ci/build.sh` `python -m build --wheel --no-isolation` | Python 构建前端 | +| `pip` | `26.1.2` | ✅ 一致 | 包安装工具 | pip 自身 | +| `setuptools` | `78.1.1` | ✅ 一致 | `ci/build.sh` `python setup.py build bdist_wheel` | 构建系统 | +| `pyzstd` | 无pin | ✅ 一致 | Zstandard 压缩(间接依赖) | 压缩库 | +| `six` | 无pin | ✅ 一致 | `torch/` 间接依赖 (NNPACK -> PeachPy -> six) | Python 2/3 兼容 | +| `wheel` | 无pin | 上游在 `requirements.txt` 中 | **torch-npu**: `setup.py:26` `from wheel.bdist_wheel import bdist_wheel`, `setup.py:610,626,631,677` | Wheel 打包,torch_npu `bdist_wheel` 构建必需 | + +## Solver / optimization + +| 包名 | 版本 | 上游对应 | 引用位置 | 说明 | +|------|------|---------|---------|------| +| `z3-solver` | `4.15.1.0` | ✅ 一致 (非 s390x) | `test/dynamo/test_exc.py:397`, `test/fx/test_z3_gradual_types.py:35`, `test/test_sympy_utils.py:1048`, `test/test_fx_experimental.py:2295` | Z3 定理证明器 | +| `pulp` | `2.9.0` | ✅ 一致 | `test/distributed/_tools/test_sac_ilp.py` | ILP 求解器 | + +## Test utilities + +| 包名 | 版本 | 上游对应 | 引用位置 | 说明 | +|------|------|---------|---------|------| +| `coverage` | 无pin | 上游不存在 | `test/run_test.py:2418` `from coverage import Coverage`, `test/run_test.py:506` `["coverage", "run", "--parallel-mode", "--source=torch"]` | 代码覆盖率,`--coverage` 选项 | +| `junitparser` | `2.1.1` | ✅ 一致 | CI 报告解析 JUnit XML | 测试结果解析 | +| `lark` | `0.12.0` | ✅ 一致 | `test/` (解析器) | 解析器库 | +| `pytest-timeout` | `2.3.1` | 上游不存在 | **torch-npu CI**: `run_npu_test_shard.py:1256` `pytest_args.append(f"--timeout={timeout}")`, `run_npu_test_file.py:268` `f"--timeout={case_timeout}"`, `test-npu.sh:55` `PYTEST_ADDOPTS="... -p timeout --timeout=600"`, `npu_poisoning_plugin.py:77` | pytest 超时控制,nightly CI 必需 | +| `tlparse` | `0.4.0` | ✅ 一致 | CI 日志解析 | 日志解析工具 | + +## Infrastructure + +| 包名 | 版本 | 上游对应 | 引用位置 | 说明 | +|------|------|---------|---------|------| +| `boto3` | `1.35.42` | ✅ 一致 | CI 基础设施(OBS/S3 上传) | AWS SDK | +| `PyGithub` | `2.3.0` | ✅ 一致 | CI 状态上报 | GitHub API | +| `redis` | `>=4.0.0` | ✅ 一致 | `test/distributed/tensor/` (OSS 缓存测试), `inductor/test_codecache.py`, `inductor/test_max_autotune.py` | Redis 缓存测试 | +| `aiohttp` | `3.14.3` | ✅ 一致 | `test/distributed/test_debug.py:34` `import aiohttp`, `torch/distributed/debug/_frontend.py:105` | 异步 HTTP | +| `dataclasses_json` | `0.6.7` | ✅ 一致 | `tools/stats/` (数据管道) | dataclass JSON 序列化 | + +--- + +## 已删除的包 + +以下包在本次对齐中从 `requirements-test.txt` 中删除,因为在 torch-npu 仓库、上游 PyTorch 仓库、nightly CI 流程中均无引用: + +| 包名 | 原版本 | 删除原因 | +|------|--------|---------| +| `beartype` | `0.17.0` | 整个仓库(含 torch-npu 和上游 pytorch)无任何 `import beartype` 或 `@beartype` | +| `attrs` | 无pin | 无 `import attrs` 或 `from attrs`,是其他包的间接依赖,pip 自动处理 | +| `decorator` | 无pin | 无 `import decorator` 或 `from decorator`,`test_decorators.py` 是测试 Python decorator 语法而非 `decorator` 包 | +| `importlib_metadata` | 无pin | 测试使用 stdlib `importlib.metadata`(`torch_npu/contrib/transfer_to_npu.py:5`),非 backport 包 | +| `zstandard` | `0.25.0` | 整个仓库(含 torch-npu 和上游 pytorch)无任何 `import zstandard`;注意 `pyzstd` 是不同的包 | + +## 版本对齐修改 + +| 包名 | 修改前 | 修改后 | 原因 | +|------|--------|--------|------| +| `pillow` | `12.2.0` | `12.3.0` | 与上游 `requirements-ci.txt:172` 对齐 | +| `pip` | `26.0.1` | `26.1.2` | 与上游 `requirements-ci.txt:379` 对齐 | +| `aiohttp` | `3.13.4` | `3.14.3` | 与上游 `requirements-ci.txt:429` 对齐 | +| `typing-extensions` | `4.15.0` | `4.12.2` | 与上游 `requirements-ci.txt:273` 对齐 (py<3.14) | +| `librosa` | `0.10.2` | `>=0.6.2` | 与上游 `requirements-ci.txt:71` 对齐 (py3.10 不 pin) | +| `transformers` | `4.40.0` | `4.36.2` | 与上游 `install_onnx.sh:17` 对齐 | diff --git a/.ci/docker/requirements-test.txt b/.ci/docker/requirements-test.txt new file mode 100644 index 0000000000..1f3e09ef23 --- /dev/null +++ b/.ci/docker/requirements-test.txt @@ -0,0 +1,95 @@ +# Python dependencies required for CI unit tests +# Aligned with PyTorch upstream .ci/docker/requirements-ci.txt (CUDA 13.0 / py3.10 / jammy) +# Note: torch-dependent packages (torchvision, torch_geometric, torch-scatter) +# are in requirements-post.txt, installed after PyTorch is built. + +# Core test frameworks +pytest==7.3.2 +pytest-xdist==3.3.1 +pytest-flakefinder==1.1.0 +pytest-rerunfailures>=10.3 +pytest-subtests==0.13.1 +pytest-cpp==2.3.0 +xdoctest==1.3.0 +hypothesis==6.56.4 +expecttest==0.3.0 +parameterized==0.8.1 +unittest-xml-reporting<=3.2.0,>=2.0.0 + +# Type checking +mypy==1.16.0 + +# Core scientific +numpy==1.23.2 +scipy==1.10.1 +opt-einsum==3.3 +sympy==1.13.3 +networkx==2.8.8 + +# Data & serialization +pillow==12.3.0 +protobuf==6.33.5 +dill==0.3.7 +flatbuffers==24.12.23 +lxml==5.3.0 + +# ONNX +onnx==1.21.0 +onnx-ir==0.1.16 +onnxruntime==1.23.1 +onnxscript==0.6.2 + +# ML / data processing +jinja2==3.1.6 +filelock==3.20.3 +optree==0.13.0 +ml-dtypes==0.5.1 +transformers==4.36.2 + +# Image / audio / ML +scikit-image==0.22.0 +librosa>=0.6.2 +numba==0.57.1 +tensorboard==2.13.0 +pywavelets==1.4.1 + +# Utilities +tabulate==0.9.0 +psutil +fsspec>=0.8.5 +packaging==24.2 +pyyaml==6.0.3 +typing-extensions==4.12.2 +requests==2.32.0 +pybind11==3.0.1 +tqdm>=4.66.0 +click +pygments==2.20.0 + +# Build tools (for C++ extension tests) +cmake==3.31.6 +ninja==1.13.0 +build==1.3.0 +pip==26.1.2 +setuptools==78.1.1 +pyzstd +six +wheel + +# Solver / optimization +z3-solver==4.15.1.0 +pulp==2.9.0 + +# Test utilities +coverage +junitparser==2.1.1 +lark==0.12.0 +pytest-timeout==2.3.1 +tlparse==0.4.0 + +# Infrastructure +boto3==1.35.42 +PyGithub==2.3.0 +redis>=4.0.0 +aiohttp==3.14.3 +dataclasses_json==0.6.7 diff --git a/.ci/docker/test/Dockerfile.aarch64 b/.ci/docker/test/Dockerfile.aarch64 new file mode 100644 index 0000000000..e99bf34918 --- /dev/null +++ b/.ci/docker/test/Dockerfile.aarch64 @@ -0,0 +1,81 @@ +FROM ubuntu:22.04 + +ARG CANN_CHIP=A2 +ARG PYTHON_VERSION=3.10 + +ENV DEBIAN_FRONTEND=noninteractive +ENV TZ=Asia/Shanghai +ENV PATH=/usr/local/bin:$PATH +ENV CANN_CHIP=${CANN_CHIP} + +# Conda environment (aligned with upstream install_conda.sh) +ENV ANACONDA_PYTHON_VERSION=${PYTHON_VERSION} +ENV PATH=/opt/conda/envs/py_${PYTHON_VERSION}/bin:/opt/conda/bin:$PATH + +COPY common/ /opt/buildtools/ +COPY requirements-test.txt /opt/buildtools/ + +# System dependencies (aligned with upstream install_base.sh for jammy) +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + autoconf \ + automake \ + build-essential \ + ca-certificates \ + cmake=3.22* \ + curl \ + dos2unix \ + gcc \ + g++ \ + gdb \ + gfortran \ + git \ + jq \ + libasound2-dev \ + libffi-dev \ + libbz2-dev \ + libgl1 \ + libjemalloc2 \ + libjpeg-dev \ + libreadline-dev \ + libsndfile-dev \ + libsqlite3-dev \ + libssl-dev \ + libtool \ + libyaml-dev \ + libz-dev \ + ccache \ + make \ + sudo \ + tar \ + tzdata \ + unzip \ + valgrind \ + vim \ + wget \ + zip \ + && rm -rf /var/lib/apt/lists/* + +# Install Miniforge3 and create conda env (aligned with upstream install_conda.sh) +RUN curl -fsSL https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-$(uname -m).sh -o /tmp/miniforge.sh \ + && bash /tmp/miniforge.sh -b -p /opt/conda \ + && rm /tmp/miniforge.sh \ + && conda create -n py_${PYTHON_VERSION} -y \ + python=${PYTHON_VERSION} \ + pip \ + cmake=3.31.6 \ + && conda clean -ya + +# Install CANN and OBS +RUN chmod -R 755 /opt/buildtools/* \ + && dos2unix /opt/buildtools/* \ + && /opt/buildtools/install_cann.sh \ + && /opt/buildtools/install_obs.sh + +# Install triton-ascend +RUN /opt/buildtools/install_triton.sh ${PYTHON_VERSION} + +# Install base test requirements (no PyTorch-dependent packages; torch is built separately) +RUN conda run -n py_${PYTHON_VERSION} pip install --no-cache-dir -r /opt/buildtools/requirements-test.txt + +WORKDIR /home diff --git a/.ci/pytorch/build.sh b/.ci/pytorch/build.sh new file mode 100755 index 0000000000..9ce6b2d6a5 --- /dev/null +++ b/.ci/pytorch/build.sh @@ -0,0 +1,76 @@ +#!/usr/bin/bash +# Main CI build entry point for torch-npu. +# Modeled after PyTorch upstream .ci/pytorch/build.sh +# +# Orchestrates: +# 1. PyTorch build (from source or pre-built wheel) +# 2. torch_npu build +# 3. Integration verification +# +# Environment variables: +# PYTORCH_SRC - Path to PyTorch source (default: ../pytorch) +# TORCH_NPU_SRC - Path to torch_npu source (default: repo root) +# BUILD_MODE - "develop" (PR) or "wheel" (nightly) +# PYTORCH_BUILD_MODE - "source" (build from source) or "wheel" (install pre-built) +# PYTORCH_WHEEL_URL - URL/path to pre-built PyTorch wheel (when PYTORCH_BUILD_MODE=wheel) +# PYTORCH_VERSION - PyTorch version for pre-built wheel (default: 2.7.1) + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/common.sh" + +PYTORCH_SRC="${PYTORCH_SRC:-${REPO_ROOT}/../pytorch}" +TORCH_NPU_SRC="${TORCH_NPU_SRC:-${REPO_ROOT}}" +BUILD_MODE="${BUILD_MODE:-develop}" +PYTORCH_BUILD_MODE="${PYTORCH_BUILD_MODE:-source}" +PYTORCH_VERSION="${PYTORCH_VERSION:-2.7.1}" +PYTORCH_INDEX_URL="${PYTORCH_INDEX_URL:-https://download.pytorch.org/whl/cpu}" + +echo "============================================" +echo " torch-npu CI Build" +echo "============================================" +echo " Build mode: ${BUILD_MODE}" +echo " PyTorch mode: ${PYTORCH_BUILD_MODE}" +echo " PyTorch src: ${PYTORCH_SRC}" +echo " torch_npu src: ${TORCH_NPU_SRC}" +echo "============================================" + +# Step 1: Install or build PyTorch +case "${PYTORCH_BUILD_MODE}" in + source) + echo ">>> Step 1/3: Building PyTorch from source..." + PYTORCH_SRC="${PYTORCH_SRC}" BUILD_MODE="${BUILD_MODE}" bash "${SCRIPT_DIR}/build_pytorch.sh" + ;; + wheel) + echo ">>> Step 1/3: Installing pre-built PyTorch ${PYTORCH_VERSION}..." + pip_install --index-url "${PYTORCH_INDEX_URL}" "torch==${PYTORCH_VERSION}" + conda_run python -c "import torch; print(f'PyTorch {torch.__version__} installed')" + ;; + *) + echo "ERROR: Unknown PYTORCH_BUILD_MODE: ${PYTORCH_BUILD_MODE}" + exit 1 + ;; +esac + +# Step 2: Build torch_npu +echo ">>> Step 2/4: Building torch_npu..." +TORCH_NPU_SRC="${TORCH_NPU_SRC}" BUILD_MODE="${BUILD_MODE}" bash "${SCRIPT_DIR}/build_torch_npu.sh" + +# Step 3: Install post-build dependencies (packages that require PyTorch) +echo ">>> Step 3/4: Installing post-build dependencies..." +REQUIREMENTS_POST="${TORCH_NPU_SRC}/.ci/docker/requirements-post.txt" +if [ -f "${REQUIREMENTS_POST}" ]; then + pip_install -r "${REQUIREMENTS_POST}" + echo "Post-build dependencies installed." +else + echo "WARNING: requirements-post.txt not found at ${REQUIREMENTS_POST}, skipping." +fi + +# Step 4: Integration verification +echo ">>> Step 4/4: Verifying integration..." +bash "${SCRIPT_DIR}/integration_verify.sh" + +echo "============================================" +echo " Build Summary: SUCCESS" +echo "============================================" diff --git a/.ci/pytorch/build_pytorch.sh b/.ci/pytorch/build_pytorch.sh new file mode 100755 index 0000000000..f4c054d2c2 --- /dev/null +++ b/.ci/pytorch/build_pytorch.sh @@ -0,0 +1,63 @@ +#!/usr/bin/bash +# Build PyTorch from source for NPU CI. +# Modeled after PyTorch upstream .ci/pytorch/build.sh +# +# This mirrors the upstream CPU-only build path: +# USE_CUDA=0 USE_XNNPACK=0 WERROR=1 python -m build --wheel --no-isolation +# +# For CI PR verification, we use setup.py develop (faster, no packaging). +# For nightly/release, we use python -m build --wheel (full verification). + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/common.sh" + +PYTORCH_SRC="${PYTORCH_SRC:-${REPO_ROOT}/../pytorch}" +BUILD_MODE="${BUILD_MODE:-develop}" # "develop" for PR, "wheel" for nightly + +setup_build_env + +echo "=== Building PyTorch from source ===" +echo " Source dir: ${PYTORCH_SRC}" +echo " Build mode: ${BUILD_MODE}" + +cd "${PYTORCH_SRC}" + +# Install PyTorch build requirements +echo "=== Installing PyTorch build requirements ===" +pip_install -r requirements.txt + +# Install numpy for build compatibility +pip_install "numpy>=1.23,<3.0" + +case "${BUILD_MODE}" in + develop) + echo "=== Building PyTorch (develop mode) ===" + conda_run python setup.py clean + conda_run python setup.py develop + echo "=== PyTorch develop install complete ===" + ;; + wheel) + echo "=== Building PyTorch (wheel mode) ===" + conda_run python setup.py clean + conda_run python -m build --wheel --no-isolation + pip_install_whl "$(echo dist/*.whl)" + echo "=== PyTorch wheel build and install complete ===" + ;; + *) + echo "ERROR: Unknown build mode: ${BUILD_MODE}" + exit 1 + ;; +esac + +# Verify PyTorch installation +echo "=== Verifying PyTorch installation ===" +conda_run python -c " +import torch +print(f'PyTorch version: {torch.__version__}') +print(f'CUDA available: {torch.cuda.is_available()}') +print(f'Build passed: OK') +" + +echo "=== PyTorch build successful ===" diff --git a/.ci/pytorch/build_torch_npu.sh b/.ci/pytorch/build_torch_npu.sh new file mode 100755 index 0000000000..e2e8cc6bfb --- /dev/null +++ b/.ci/pytorch/build_torch_npu.sh @@ -0,0 +1,57 @@ +#!/usr/bin/bash +# Build torch_npu from source for NPU CI. +# Must be run AFTER PyTorch is installed (via build_pytorch.sh or pre-built wheel). +# +# Usage: +# ./build_torch_npu.sh [--python=3.10] [--mode=develop|wheel] + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/common.sh" + +TORCH_NPU_SRC="${TORCH_NPU_SRC:-${REPO_ROOT}}" +PYTHON_VERSION="${ANACONDA_PYTHON_VERSION:-3.10}" +BUILD_MODE="${BUILD_MODE:-wheel}" + +setup_build_env + +echo "=== Building torch_npu from source ===" +echo " Source dir: ${TORCH_NPU_SRC}" +echo " Python version: ${PYTHON_VERSION}" +echo " Build mode: ${BUILD_MODE}" + +cd "${TORCH_NPU_SRC}" + +# Install torch_npu build requirements +if [[ -f requirements.txt ]]; then + echo "=== Installing torch_npu build requirements ===" + pip_install -r requirements.txt +fi + +# Verify PyTorch is installed before building torch_npu +echo "=== Checking PyTorch installation ===" +if ! conda_run python -c "import torch; print(torch.__version__)" 2>/dev/null; then + echo "ERROR: PyTorch is not installed. Please run build_pytorch.sh first." + exit 1 +fi + +case "${BUILD_MODE}" in + develop) + echo "=== Building torch_npu (develop mode) ===" + conda_run python setup.py develop + echo "=== torch_npu develop install complete ===" + ;; + wheel) + echo "=== Building torch_npu (wheel mode) ===" + bash ci/build.sh --python="${PYTHON_VERSION}" + pip_install_whl "$(echo dist/torch_npu*.whl)" + echo "=== torch_npu wheel build and install complete ===" + ;; + *) + echo "ERROR: Unknown build mode: ${BUILD_MODE}" + exit 1 + ;; +esac + +echo "=== torch_npu build successful ===" diff --git a/.ci/pytorch/common.sh b/.ci/pytorch/common.sh new file mode 100755 index 0000000000..bf82721289 --- /dev/null +++ b/.ci/pytorch/common.sh @@ -0,0 +1,67 @@ +#!/usr/bin/bash +# Shared utilities for torch-npu CI build scripts. +# Modeled after PyTorch upstream .ci/pytorch/common.sh and common-build.sh. + +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" + +# --- Conda helpers (aligned with upstream common_utils.sh) --- + +conda_run() { + conda run -n "py_${ANACONDA_PYTHON_VERSION:-3.10}" --no-capture-output "$@" +} + +pip_install() { + conda_run pip install --progress-bar off "$@" +} + +pip_install_whl() { + conda_run pip install --progress-bar off "$@" +} + +# --- Build environment setup --- + +setup_build_env() { + # Default Python version if not set + export ANACONDA_PYTHON_VERSION="${ANACONDA_PYTHON_VERSION:-3.10}" + + # NPU build: no CUDA, no XNNPACK (aligned with upstream CPU-only builds) + export USE_CUDA=0 + export USE_XNNPACK=0 + + # Use C++11 ABI (required for torch_npu compatibility) + export _GLIBCXX_USE_CXX11_ABI="${_GLIBCXX_USE_CXX11_ABI:-1}" + + # Set MAX_JOBS to avoid OOM + if [[ -z "${MAX_JOBS:-}" ]]; then + export MAX_JOBS=$(($(nproc) - 2)) + # Use at least 1 job + if [[ "$MAX_JOBS" -lt 1 ]]; then + export MAX_JOBS=1 + fi + fi + + echo "=== Build Environment ===" + echo " ANACONDA_PYTHON_VERSION: ${ANACONDA_PYTHON_VERSION}" + echo " USE_CUDA: ${USE_CUDA}" + echo " USE_XNNPACK: ${USE_XNNPACK}" + echo " _GLIBCXX_USE_CXX11_ABI: ${_GLIBCXX_USE_CXX11_ABI}" + echo " MAX_JOBS: ${MAX_JOBS}" + echo " Python: $(conda_run python --version 2>&1)" + echo " Python path: $(conda_run which python)" +} + +# --- Error handling --- + +trap_add() { + local trap_add_cmd="$1" + shift || true + local trap_add_signal="$*" + + if [[ -z "$(trap -p "${trap_add_signal}")" ]]; then + trap "${trap_add_cmd}" "${trap_add_signal}" + else + trap "${trap_add_cmd};$(trap -p "${trap_add_signal}" | sed "s/^trap -- '\(.*\)' \([A-Z0-9 ]*\)$/\1/")" "${trap_add_signal}" + fi +} diff --git a/.ci/pytorch/integration_verify.sh b/.ci/pytorch/integration_verify.sh new file mode 100755 index 0000000000..823024f85f --- /dev/null +++ b/.ci/pytorch/integration_verify.sh @@ -0,0 +1,88 @@ +#!/usr/bin/bash +# Integration verification: confirms PyTorch + torch_npu work together. +# Tests basic import, device detection, and tensor operations. + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/common.sh" + +echo "=== Integration Verification ===" + +# Test 1: Basic imports +echo "--- Test 1: Basic imports ---" +conda_run python -c " +import torch +import torch_npu +print(f'PyTorch: {torch.__version__}') +print(f'torch_npu: {torch_npu.__version__}') +print('Import OK') +" + +# Test 2: NPU device detection +echo "--- Test 2: NPU device detection ---" +conda_run python -c " +import torch +import torch_npu +count = torch.npu.device_count() +print(f'NPU device count: {count}') +print(f'NPU available: {torch.npu.is_available()}') +if count > 0: + print(f'Device name: {torch.npu.get_device_name(0)}') +print('Device detection OK') +" + +# Test 3: Basic tensor operations on NPU +echo "--- Test 3: Basic tensor operations ---" +conda_run python -c " +import torch +import torch_npu + +if torch.npu.is_available(): + # Create tensor on NPU + x = torch.randn(3, 3).npu() + y = torch.randn(3, 3).npu() + z = x + y + print(f'Tensor addition: {z.mean().item():.4f}') + + # Matmul + z = torch.mm(x, y.t()) + print(f'Matmul shape: {z.shape}') + + # Move back to CPU + z_cpu = z.cpu() + print(f'CPU tensor: {z_cpu}') +else: + # NPU not available, test CPU fallback + x = torch.randn(3, 3) + y = torch.randn(3, 3) + z = x + y + print(f'CPU fallback: {z.mean().item():.4f}') + print('(NPU not available, running CPU-only verification)') + +print('Tensor operations OK') +" + +# Test 4: Check torch_npu compile status +echo "--- Test 4: Compilation status ---" +conda_run python -c " +import torch +import torch_npu + +# Check that key modules are available +modules_to_check = [ + 'torch_npu.npu', + 'torch_npu.optim', + 'torch_npu.profiler', +] +for mod_name in modules_to_check: + try: + __import__(mod_name) + print(f' {mod_name}: OK') + except ImportError: + print(f' {mod_name}: NOT FOUND (may be expected)') + +print('Module check complete') +" + +echo "=== Integration verification: ALL PASSED ===" diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml index 55a0b52dcf..a1fec81053 100644 --- a/.github/workflows/_build.yml +++ b/.github/workflows/_build.yml @@ -20,23 +20,52 @@ on: required: true type: string description: The downstream repository full name (owner/repo) + downstream_ref: + required: false + type: string + default: 'master' + description: The downstream repository branch, tag, or SHA to build jobs: build: - runs-on: ubuntu-latest + runs-on: linux-aarch64-a3-16 + defaults: + run: + shell: bash + container: + image: quay.io/kerer/pytorch:torch-npu-test-aarch64-cann-a3-py3.10-torch-nightly + options: --network host + env: + MAX_JOBS: 128 + USE_CUDA: 0 + USE_XNNPACK: 0 + _GLIBCXX_USE_CXX11_ABI: 1 + BUILD_IGNORE_SVE_UNAVAILABLE: 1 + BUILD_WITHOUT_SHA: 1 + PIP_INDEX_URL: https://mirrors.huaweicloud.com/repository/pypi/simple steps: - # Step 1: Checkout upstream PyTorch PR code - # Use fork repo if available (PR from fork), otherwise use upstream repo (push or PR from same repo) + # Step 1: Checkout upstream PyTorch PR code (shallow) + # fetch-depth: 1 = single commit only, no branches/tags/history. + # PyTorch repo has thousands of branches; full clone takes ~3min. + # Submodules init deferred to separate step with --depth=1. - name: Checkout upstream PyTorch PR uses: actions/checkout@v6 with: repository: ${{ inputs.upstream_fork_repo != '' && inputs.upstream_fork_repo || inputs.upstream_repo }} ref: ${{ inputs.upstream_sha }} - submodules: recursive + fetch-depth: 1 + submodules: false path: pytorch - # Step 2: Build PyTorch - - name: Build PyTorch + - name: Init submodules (shallow) + working-directory: pytorch + run: | + git submodule update --init --recursive --depth=1 --jobs=$(nproc) + + # Step 2: Build and install PyTorch + - name: Build and install PyTorch + id: build_pytorch + working-directory: pytorch run: | echo "============================================" echo "Building PyTorch from upstream PR..." @@ -46,61 +75,186 @@ jobs: echo "Repository: ${{ inputs.upstream_repo }}" fi echo "Commit SHA: ${{ inputs.upstream_sha }}" + echo "MAX_JOBS: ${MAX_JOBS}" echo "============================================" - # TODO: Add actual PyTorch build commands - # Example: - # cd pytorch - # pip install -r requirements.txt - # python setup.py develop - echo "[SIMULATED] PyTorch build completed successfully!" - - # Step 3: Install PyTorch wheel - - name: Install PyTorch wheel - run: | - echo "============================================" - echo "Installing PyTorch wheel..." - echo "============================================" - # TODO: Add actual install commands - # Example: - # pip install pytorch/dist/torch*.whl - echo "[SIMULATED] PyTorch wheel installed successfully!" - # Step 4: Checkout downstream repo (torch_npu) master + pip install -r requirements.txt + + # Build wheel first, then install from it. + # This produces an artifact we can upload for downstream use. + mkdir -p /tmp/wheels + python -m pip wheel --no-build-isolation -w /tmp/wheels/ . 2>&1 | tee /tmp/build-pytorch.log + BUILD_STATUS=${PIPESTATUS[0]} + + if [ ${BUILD_STATUS} -ne 0 ]; then + echo "PyTorch build failed!" + exit ${BUILD_STATUS} + fi + + pip install /tmp/wheels/torch*.whl + + # Must NOT run from pytorch/ source dir: Python would find + # the local torch/ source tree instead of the installed package. + cd /tmp + python -c "import torch; print(f'PyTorch version: {torch.__version__}')" + cd "${GITHUB_WORKSPACE}" + + # Step 3: Checkout downstream torch_npu - name: Checkout downstream repo (torch_npu) uses: actions/checkout@v6 with: repository: ${{ inputs.downstream_repo }} - ref: master - submodules: recursive + ref: ${{ inputs.downstream_ref }} + fetch-depth: 1 + submodules: false path: torch_npu - # Step 5: Build torch_npu - - name: Build torch_npu + - name: Init submodules (shallow) + working-directory: torch_npu + run: | + git submodule update --init --recursive --depth=1 --jobs=$(nproc) + + # Step 3.5: Diagnose installed PyTorch for Dimname references + - name: "[Diagnostic] Check installed torchgen for Dimname" + working-directory: /tmp + run: | + echo "=== Checking installed torchgen for Dimname ===" + python -c " + import torchgen, os, sys + d = os.path.dirname(torchgen.__file__) + yaml_path = os.path.join(d, 'packaged/ATen/native/native_functions.yaml') + print(f'Checking: {yaml_path}') + if not os.path.exists(yaml_path): + print('ERROR: native_functions.yaml not found!') + sys.exit(1) + with open(yaml_path) as f: + c = f.read() + cnt = c.count('Dimname') + print(f'native_functions.yaml: {cnt} Dimname reference(s)') + if cnt > 0: + for i, l in enumerate(c.split('\n')): + if 'Dimname' in l: + print(f' line {i}: {l.strip()[:150]}') + print('FATAL: Stale native_functions.yaml with Dimname detected!') + sys.exit(1) + else: + print('OK: native_functions.yaml is clean') + " + + echo "" + echo "=== Checking model.py BaseTy ===" + python -c " + import torchgen.model as m + has = 'Dimname' in [e.name for e in m.BaseTy] + print(f'model.py BaseTy has Dimname member: {has}') + import sys + if has: + print('FATAL: model.py still has Dimname in BaseTy!') + sys.exit(1) + else: + print('OK: model.py BaseTy is clean') + " + + echo "" + echo "=== Checking tags.yaml ===" + python -c " + import torchgen, os + d = os.path.dirname(torchgen.__file__) + tags_path = os.path.join(d, 'packaged/ATen/native/tags.yaml') + print(f'Checking: {tags_path}') + with open(tags_path) as f: + c = f.read() + cnt = c.count('Dimname') + print(f'tags.yaml: {cnt} Dimname reference(s)') + if cnt > 0: + print('WARNING: tags.yaml has Dimname refs!') + else: + print('OK: tags.yaml is clean') + " + + # Step 4: Build and install torch_npu + # NOTE: Intentionally do NOT use 'pip install -r requirements.txt' from torch_npu, + # because that file pins a specific torch version which would overwrite the + # source-built PyTorch from the upstream PR. + - name: Build and install torch_npu + id: build_torchnpu + working-directory: torch_npu run: | echo "============================================" - echo "Building torch_npu from downstream master..." + echo "Building torch_npu..." echo "Repository: ${{ inputs.downstream_repo }}" - echo "Branch: master" + echo "Ref: ${{ inputs.downstream_ref }}" echo "============================================" - # TODO: Add actual torch_npu build commands - # Example: - # cd torch_npu - # pip install -r requirements.txt - # bash ci/build.sh - echo "[SIMULATED] torch_npu build completed successfully!" + bash ci/build.sh --python=3.10 --disable_torchair --disable_rpc 2>&1 | tee /tmp/build-torchnpu.log + BUILD_STATUS=${PIPESTATUS[0]} + + if [ ${BUILD_STATUS} -ne 0 ]; then + echo "torch_npu build failed!" + exit ${BUILD_STATUS} + fi + + pip install dist/torch_npu*.whl + cp dist/torch_npu*.whl /tmp/wheels/ + + # Step 5: Upload wheel artifacts + - name: Upload wheel artifacts + if: success() + uses: actions/upload-artifact@v4 + with: + name: wheels-${{ github.run_number }} + path: /tmp/wheels/*.whl + retention-days: 7 + + # Step 6: Verify NPU environment and imports + - name: Verify NPU device + run: | + source /usr/local/Ascend/cann/set_env.sh 2>/dev/null || true + source /usr/local/Ascend/nnal/atb/set_env.sh 2>/dev/null || true + + echo "=== NPU Device Information ===" + npu-smi info + echo "=== End of NPU Device Information ===" + + - name: Verify NPU availability + run: | + source /usr/local/Ascend/cann/set_env.sh 2>/dev/null || true + source /usr/local/Ascend/nnal/atb/set_env.sh 2>/dev/null || true + + python -c " + import torch + print(f'torch: {torch.__version__}') + import torch_npu + print(f'torch_npu: {torch_npu.__version__}') + print(f'NPU available: {torch.npu.is_available()}') + print(f'NPU count: {torch.npu.device_count()}') + " + + # Step 7: Upload build artifacts (always, for debugging failures) + - name: Upload build artifacts + if: always() + uses: actions/upload-artifact@v4 + with: + name: build-artifacts-${{ github.run_number }} + path: | + /tmp/build-pytorch.log + /tmp/build-torchnpu.log + torch_npu/torch_npu/csrc/inductor/aoti_torch/generated/c_shim_npu.h + if-no-files-found: warn + + # Step 8: Summary - name: Summary + if: always() run: | echo "============================================" - echo "Build Summary" + echo " Build Summary" echo "============================================" if [ -n "${{ inputs.upstream_fork_repo }}" ]; then - echo "1. PyTorch fork PR: ${{ inputs.upstream_fork_repo }}@${{ inputs.upstream_sha }}" + echo "PyTorch fork PR : ${{ inputs.upstream_fork_repo }}" else - echo "1. PyTorch upstream: ${{ inputs.upstream_repo }}@${{ inputs.upstream_sha }}" + echo "PyTorch upstream: ${{ inputs.upstream_repo }}" fi - echo "2. PyTorch build: SUCCESS (simulated)" - echo "3. PyTorch install: SUCCESS (simulated)" - echo "4. torch_npu master: ${{ inputs.downstream_repo }}" - echo "5. torch_npu build: SUCCESS (simulated)" - echo "============================================" \ No newline at end of file + echo "PyTorch commit : ${{ inputs.upstream_sha }}" + echo "torch_npu repo : ${{ inputs.downstream_repo }}" + echo "Max jobs : ${MAX_JOBS}" + echo "============================================" diff --git a/.github/workflows/build-docker-images.yml b/.github/workflows/build-docker-images.yml new file mode 100644 index 0000000000..e92a7bdc5b --- /dev/null +++ b/.github/workflows/build-docker-images.yml @@ -0,0 +1,160 @@ +name: Build Docker Images + +on: + push: + paths: + - '.ci/docker/**' + - '.github/workflows/build-docker-images.yml' + workflow_dispatch: + inputs: + images: + description: 'Images to build (comma-separated: test-aarch64-a2, test-aarch64-a3)' + required: false + type: string + default: 'test-aarch64-a2' + push: + description: 'Push images to registry' + required: false + type: boolean + default: false + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + REGISTRY: quay.io + QUAY_ORG: kerer + IMAGE_NAME: pytorch + +jobs: + matrix-prep: + runs-on: ubuntu-latest + outputs: + images: ${{ steps.select.outputs.images }} + do_push: ${{ steps.select.outputs.do_push }} + steps: + - name: Select images to build + id: select + run: | + ALL_IMAGES='["test-aarch64-a2","test-aarch64-a3"]' + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + INPUT="${{ github.event.inputs.images }}" + JSON=$(echo "${INPUT}" | sed 's/ *, */","/g' | sed 's/^/["/' | sed 's/$/"]/') + echo "images=${JSON}" >> "$GITHUB_OUTPUT" + echo "do_push=${{ github.event.inputs.push }}" >> "$GITHUB_OUTPUT" + else + echo "images=${ALL_IMAGES}" >> "$GITHUB_OUTPUT" + echo "do_push=true" >> "$GITHUB_OUTPUT" + fi + + build: + needs: matrix-prep + environment: QUAY_USERNAME + runs-on: ubuntu-24.04-arm + strategy: + fail-fast: false + matrix: + image: ${{ fromJSON(needs.matrix-prep.outputs.images) }} + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Log in to Quay.io + if: needs.matrix-prep.outputs.do_push == 'true' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_PASSWORD }} + + - name: Build and push image + run: | + case "${{ matrix.image }}" in + test-aarch64-a2) + BASE_TAG="torch-npu-test-aarch64-cann-a2-py3.10-torch-nightly" + ;; + test-aarch64-a3) + BASE_TAG="torch-npu-test-aarch64-cann-a3-py3.10-torch-nightly" + ;; + *) + echo "ERROR: Unknown image: ${{ matrix.image }}" + exit 1 + ;; + esac + + chmod +x .ci/docker/docker_build.sh + + echo "=== Building: ${BASE_TAG} ===" + bash .ci/docker/docker_build.sh "${BASE_TAG}" + + # docker_build.sh appends a timestamp suffix (YYYYMMDDHHMM) to the + # tag. Docker treats the full string as the repository name with tag + # "latest", so we match on repository name. + BUILT_REPO="$(docker images --format '{{.Repository}}' \ + | grep -E "^${BASE_TAG}-[0-9]{12}$" \ + | sort -r | head -1)" + + if [ -z "${BUILT_REPO}" ]; then + echo "ERROR: Could not find built image for ${BASE_TAG}" + docker images | grep "${BASE_TAG}" + exit 1 + fi + + TAG="${BUILT_REPO}:latest" + + echo "=== Built: ${TAG} ===" + docker image inspect "${TAG}" --format ' Size: {{ .Size }}' + + # Remote tag = the timestamped repository name (without :latest) + REMOTE_IMAGE="${REGISTRY}/${QUAY_ORG}/${IMAGE_NAME}:${BUILT_REPO}" + + if [ "${{ needs.matrix-prep.outputs.do_push }}" = "true" ]; then + docker tag "${TAG}" "${REMOTE_IMAGE}" + docker push "${REMOTE_IMAGE}" + echo "=== Pushed: ${REMOTE_IMAGE} ===" + fi + + mkdir -p /tmp/result + echo "${REMOTE_IMAGE}" > "/tmp/result/${BUILT_REPO}.txt" + + - name: Upload result + if: always() + uses: actions/upload-artifact@v4 + with: + name: result-${{ matrix.image }} + path: /tmp/result/*.txt + retention-days: 1 + + summary: + needs: [matrix-prep, build] + runs-on: ubuntu-latest + if: always() + steps: + - name: Download results + uses: actions/download-artifact@v4 + with: + pattern: result-* + path: /tmp/results + merge-multiple: true + + - name: Generate summary + run: | + echo "## Docker Image Build Summary" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "| # | Image | Pull Command |" >> $GITHUB_STEP_SUMMARY + echo "|---|-------|-------------|" >> $GITHUB_STEP_SUMMARY + + if [ -d /tmp/results ] && [ "$(ls -A /tmp/results 2>/dev/null)" ]; then + COUNT=1 + for f in /tmp/results/*.txt; do + IMAGE=$(cat "$f") + echo "| ${COUNT} | \`${IMAGE##*:}\` | \`docker pull ${IMAGE}\` |" >> $GITHUB_STEP_SUMMARY + COUNT=$((COUNT + 1)) + done + else + echo "| - | No images built | - |" >> $GITHUB_STEP_SUMMARY + fi + + echo "" >> $GITHUB_STEP_SUMMARY + echo "**Registry:** \`${REGISTRY}/${QUAY_ORG}/${IMAGE_NAME}\`" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/test-build-trigger.yml b/.github/workflows/test-build-trigger.yml new file mode 100644 index 0000000000..2a13780151 --- /dev/null +++ b/.github/workflows/test-build-trigger.yml @@ -0,0 +1,29 @@ +name: Test Build Trigger + +on: + pull_request: + branches: + - master + +jobs: + resolve: + runs-on: ubuntu-latest + outputs: + sha: ${{ steps.resolve.outputs.sha }} + steps: + - name: Resolve upstream PyTorch main HEAD + id: resolve + run: | + SHA=$(git ls-remote https://github.com/pytorch/pytorch.git refs/heads/main | awk '{print $1}') + echo "Upstream PyTorch main HEAD: ${SHA}" + echo "sha=${SHA}" >> "$GITHUB_OUTPUT" + + build: + needs: resolve + uses: ./.github/workflows/_build.yml + with: + upstream_repo: pytorch/pytorch + upstream_sha: ${{ needs.resolve.outputs.sha }} + upstream_fork_repo: '' + downstream_repo: ${{ github.event.pull_request.head.repo.full_name }} + downstream_ref: ${{ github.head_ref }} diff --git a/ci/build.sh b/ci/build.sh index 5a855130fe..54422c64aa 100644 --- a/ci/build.sh +++ b/ci/build.sh @@ -43,6 +43,11 @@ function parse_script_args() { args_num=$((args_num-1)) shift ;; + --update_aoti_c_shim) + export UPDATE_AOTI_C_SHIM="--update_aoti_c_shim" + args_num=$((args_num-1)) + shift + ;; --enable_lto) export ENABLE_LTO=TRUE args_num=$((args_num-1)) diff --git a/generate_code.sh b/generate_code.sh index 946d44d49e..0c19b8cb75 100644 --- a/generate_code.sh +++ b/generate_code.sh @@ -8,6 +8,7 @@ cd $CDIR python_execute="$1" pytorch_version="$2" +update_aoti_c_shim="${3:-${UPDATE_AOTI_C_SHIM:-}}" IFS='.' read -ra version_parts <<< "$pytorch_version" @@ -57,12 +58,22 @@ testing_source_yaml="$CDIR/test/ops_unsupport_list.yaml" op_plugin_functions_yaml_path="$op_plugin_config_path/npu_native_functions.yaml" -${python_execute} -m torchnpugen.gen_backend_stubs \ - --output_dir="torch_npu/csrc/aten" \ - --source_yaml="$source_yaml" \ - --impl_path="$CDIR/torch_npu/csrc/aten" \ - --op_plugin_impl_path="$CDIR/third_party/op-plugin/op_plugin/ops" \ - --op_plugin_yaml_path="$op_plugin_config_path/op_plugin_functions.yaml" +if [ "${update_aoti_c_shim}" = "--update_aoti_c_shim" ]; then + ${python_execute} -m torchnpugen.gen_backend_stubs \ + --output_dir="torch_npu/csrc/aten" \ + --source_yaml="$source_yaml" \ + --impl_path="$CDIR/torch_npu/csrc/aten" \ + --op_plugin_impl_path="$CDIR/third_party/op-plugin/op_plugin/ops" \ + --op_plugin_yaml_path="$op_plugin_config_path/op_plugin_functions.yaml" \ + --update_aoti_c_shim +else + ${python_execute} -m torchnpugen.gen_backend_stubs \ + --output_dir="torch_npu/csrc/aten" \ + --source_yaml="$source_yaml" \ + --impl_path="$CDIR/torch_npu/csrc/aten" \ + --op_plugin_impl_path="$CDIR/third_party/op-plugin/op_plugin/ops" \ + --op_plugin_yaml_path="$op_plugin_config_path/op_plugin_functions.yaml" +fi ${python_execute} -m torchnpugen.autograd.gen_autograd \ --out_dir="$CDIR/torch_npu/csrc/aten" \ diff --git a/torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py b/torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py index 2842ae9ba2..c9f0c1fa9c 100644 --- a/torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py +++ b/torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py @@ -3068,9 +3068,6 @@ def is_aligned(x): make_fallback(aten.to_sparse) make_fallback(aten._to_sparse) -# Needs dimname support -make_fallback(aten.zeros.names) - # 6) Pattern-matched make_fallback( aten._scaled_dot_product_efficient_attention.default, diff --git a/torch_npu/csrc/aten/AutoCastOps.cpp b/torch_npu/csrc/aten/AutoCastOps.cpp index 85c75bcb9c..8f9dd136ff 100644 --- a/torch_npu/csrc/aten/AutoCastOps.cpp +++ b/torch_npu/csrc/aten/AutoCastOps.cpp @@ -108,11 +108,8 @@ TORCH_LIBRARY_IMPL(aten, AutocastPrivateUse1, m) { // fp32_set_opt_dtype KERNEL_PRIVATEUSEONE(prod, fp32_set_opt_dtype) KERNEL_PRIVATEUSEONE(prod, dim_int, fp32_set_opt_dtype) - KERNEL_PRIVATEUSEONE(prod, dim_Dimname, fp32_set_opt_dtype) KERNEL_PRIVATEUSEONE(softmax, int, fp32_set_opt_dtype) - KERNEL_PRIVATEUSEONE(softmax, Dimname, fp32_set_opt_dtype) KERNEL_PRIVATEUSEONE(log_softmax, int, fp32_set_opt_dtype) - KERNEL_PRIVATEUSEONE(log_softmax, Dimname, fp32_set_opt_dtype) KERNEL_PRIVATEUSEONE(cumprod, fp32_set_opt_dtype) KERNEL_PRIVATEUSEONE(cumprod, dimname, fp32_set_opt_dtype) KERNEL_PRIVATEUSEONE(cumsum, fp32_set_opt_dtype) @@ -124,7 +121,6 @@ TORCH_LIBRARY_IMPL(aten, AutocastPrivateUse1, m) { // when autocasting. KERNEL_PRIVATEUSEONE(sum, fp32_set_opt_dtype) KERNEL_PRIVATEUSEONE(sum, dim_IntList, fp32_set_opt_dtype) - KERNEL_PRIVATEUSEONE(sum, dim_DimnameList, fp32_set_opt_dtype) // fp32_append_dtype // The fp32_append_dtype wrapper overrides implicit promotion behavior. // norm does not implicitly promote, but be aware when adding new ops to this policy. @@ -136,10 +132,6 @@ TORCH_LIBRARY_IMPL(aten, AutocastPrivateUse1, m) { at::Tensor (const at::Tensor &, const c10::optional&, at::IntArrayRef, bool), at::Tensor (const at::Tensor &, const c10::optional&, at::IntArrayRef, bool, at::ScalarType), fp32_append_dtype) - KERNEL_DIFFERENT_REDISPATCH_SIGNATURE_PRIVATEUSEONE(ADD_NS(norm), "norm.names_ScalarOpt_dim", - at::Tensor (const at::Tensor &, const c10::optional&, at::DimnameList, bool), - at::Tensor (const at::Tensor &, const c10::optional&, at::DimnameList, bool, at::ScalarType), - fp32_append_dtype) // promote KERNEL_PRIVATEUSEONE(addcdiv, promote) KERNEL_PRIVATEUSEONE(addcmul, promote) diff --git a/torch_npu/csrc/aten/VariableFallbackKernel.cpp b/torch_npu/csrc/aten/VariableFallbackKernel.cpp index 25d96107e4..13f95c0a30 100644 --- a/torch_npu/csrc/aten/VariableFallbackKernel.cpp +++ b/torch_npu/csrc/aten/VariableFallbackKernel.cpp @@ -132,7 +132,7 @@ static void npuBasicAutogradNotImplementedFallbackImpl( // by putting it after the requires_grad checks. any_input_requires_grad = any_input_requires_grad && at::GradMode::is_enabled(); - std::shared_ptr grad_fn; + c10::intrusive_ptr grad_fn; if (any_input_requires_grad) { // NB: It is standard to collect edges from all tensors // (see generated/VariableTypeEverything.cpp for examples) @@ -144,9 +144,7 @@ static void npuBasicAutogradNotImplementedFallbackImpl( stack, stack_start, num_arguments); - grad_fn = std::shared_ptr( - new WarnNotImplemented(op_name, all_tensors_on_stack.size()), - torch::autograd::deleteNode); + grad_fn = c10::make_intrusive(op_name, all_tensors_on_stack.size()); grad_fn->set_next_edges(torch::autograd::collect_next_edges(all_tensors_on_stack)); } diff --git a/torch_npu/csrc/aten/common/CopyKernel.cpp b/torch_npu/csrc/aten/common/CopyKernel.cpp index 6f3e239fa4..8d47115180 100644 --- a/torch_npu/csrc/aten/common/CopyKernel.cpp +++ b/torch_npu/csrc/aten/common/CopyKernel.cpp @@ -439,12 +439,6 @@ at::Tensor& NPUNativeFunctions::copy_(at::Tensor& self, const at::Tensor& src, b if (src._is_zerotensor()) { return self.zero_(); } - // save tensor dim name - c10::optional names = src.opt_names(); - if (names.has_value()) { - internal_set_names_inplace(self, names); - } - if (torch_npu::utils::is_npu(self)) { if (torch_npu::utils::is_npu(src)) { copy_d2d(self, src, non_blocking); diff --git a/torch_npu/csrc/aten/common/ResizeNpu.cpp b/torch_npu/csrc/aten/common/ResizeNpu.cpp index a9bfc5e601..a27c98772b 100644 --- a/torch_npu/csrc/aten/common/ResizeNpu.cpp +++ b/torch_npu/csrc/aten/common/ResizeNpu.cpp @@ -1,5 +1,4 @@ #include -#include #include "torch_npu/csrc/framework/FormatHelper.h" #include "torch_npu/csrc/aten/NPUNativeFunctions.h" @@ -8,40 +7,11 @@ namespace at_npu { namespace native { -inline const at::Tensor& resize_named_tensor_( - const at::Tensor& self, - c10::IntArrayRef size, - c10::optional format) -{ - TORCH_INTERNAL_ASSERT(self.has_names()); - TORCH_CHECK( - self.sizes() == size, - "Cannot resize named tensor with resize_ or resize_as_ (tried to resize " - "Tensor", - self.names(), - " with size ", - self.sizes(), - " to ", - size, - "). This may be caused by passing a named tensor ", - "as an `out=` argument; please ensure that the sizes are the same. ", - OPS_ERROR(ErrCode::VALUE)); - TORCH_CHECK( - !format.has_value(), - "Unsupported memory format for named tensor resize ", - format.value(), - OPS_ERROR(ErrCode::NOT_SUPPORT)); - return self; -} - const at::Tensor& NPUNativeFunctions::resize_( const at::Tensor& self, c10::IntArrayRef size, c10::optional format) { - if (self.has_names()) { - return resize_named_tensor_(self, size, format); - } // because of resize _impl_npu_ only support at base format, so // no need to reflush NpuStorageDesc here. auto ks = self.key_set(); @@ -76,7 +46,6 @@ const at::Tensor& NPUNativeFunctions::resize_as_( } const at::Tensor& result = self.resize_(the_template.sizes()); - at::namedinference::propagate_names(result, the_template); return result; } diff --git a/torch_npu/csrc/aten/common/TensorFactories.cpp b/torch_npu/csrc/aten/common/TensorFactories.cpp index 1a327c97e1..558f5789da 100644 --- a/torch_npu/csrc/aten/common/TensorFactories.cpp +++ b/torch_npu/csrc/aten/common/TensorFactories.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -325,10 +324,6 @@ at::Tensor empty_like_npu( } } - if (self.opt_names()) { - at::namedinference::propagate_names(result, self.names()); - } - return result; } @@ -427,43 +422,6 @@ at::Tensor NPUNativeFunctions::unsafe_empty_with_format( return NPUNativeFunctions::empty_with_format(size, dtype_opt, layout_opt, device_opt, pin_memory_opt, dst_format, c10::nullopt); } -at::Tensor NPUNativeFunctions::empty_with_format( - c10::IntArrayRef size, - c10::optional names, - c10::optional dtype_opt, - c10::optional layout_opt, - c10::optional device_opt, - c10::optional pin_memory_opt, - int64_t dst_format) -{ - torch_npu::utils::torch_check_npu(c10::device_or_default(device_opt)); - caffe2::TypeMeta dtype = c10::scalarTypeToTypeMeta(dtype_or_default(dtype_opt)); - c10::TensorOptions options = c10::TensorOptions().dtype(dtype_opt) - .device(device_opt) - .layout(layout_opt) - .pinned_memory(pin_memory_opt); - at::Tensor result = OpPreparation::ApplyTensorWithFormat(size, options, dst_format); - if (names.has_value()) { - internal_set_names_inplace(result, names); - } - - return result; -} - -at::Tensor empty_with_format_name_npu( - c10::IntArrayRef size, - c10::optional names, - const c10::TensorOptions &options, - int64_t dst_format) -{ - at::Tensor result = OpPreparation::ApplyTensorWithFormat(size, options, dst_format); - if (names.has_value()) { - internal_set_names_inplace(result, names); - } - - return result; -} - at::Tensor NPUNativeFunctions::empty_strided( c10::IntArrayRef size, c10::IntArrayRef stride, diff --git a/torch_npu/csrc/aten/common/TensorShape.cpp b/torch_npu/csrc/aten/common/TensorShape.cpp index 26053b37d0..f15cb4abf4 100644 --- a/torch_npu/csrc/aten/common/TensorShape.cpp +++ b/torch_npu/csrc/aten/common/TensorShape.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -105,7 +104,6 @@ at::Tensor alias_with_sizes_and_strides_npu( self_tmp_->set_storage_offset(self.storage_offset()); self_tmp_->set_sizes_and_strides(sizes, strides); } - at::namedinference::propagate_names(self_, self); return self_; } @@ -193,8 +191,6 @@ at::Tensor NPUNativeFunctions::squeeze(const at::Tensor& self) { auto g = inferSqueezeGeometry(self); at::Tensor result = self.as_strided(std::get<0>(g), std::get<1>(g)); - auto maybe_outnames = at::namedinference::compute_squeeze_outnames(self); - at::namedinference::propagate_names_if_nonempty(result, maybe_outnames); return result; } @@ -207,7 +203,6 @@ at::Tensor NPUNativeFunctions::squeeze(const at::Tensor& self, int64_t dim) } auto g = inferSqueezeGeometry(self, dim); auto result = self.as_strided(std::get<0>(g), std::get<1>(g)); - at::namedinference::propagate_names_except(result, self, {dim}); return result; } diff --git a/torch_npu/csrc/aten/npu_native_functions.yaml b/torch_npu/csrc/aten/npu_native_functions.yaml index 839f98d15c..8b72b2c1a8 100644 --- a/torch_npu/csrc/aten/npu_native_functions.yaml +++ b/torch_npu/csrc/aten/npu_native_functions.yaml @@ -21,9 +21,7 @@ supported: - empty_like - empty_strided - empty_with_format - - empty_with_format.names - full - - full.names - full.out - hamming_window - hamming_window.periodic @@ -76,9 +74,6 @@ custom: - func: unsafe_empty_with_format(int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, int acl_format=2, bool keep_format=False) -> Tensor dispatch: CompositeExplicitAutograd: empty_with_format - - func: empty_with_format.names(int[] size, Dimname[]? names, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, int acl_format=2) -> Tensor - dispatch: - CompositeExplicitAutograd: empty_with_format - func: copy_memory_(Tensor(a!) self, Tensor src, bool non_blocking=False) -> Tensor(a!) device_check: NoCheck - func: get_storage_size(Tensor self) -> int diff --git a/torch_npu/csrc/aten/ops/FullKernelNpu.cpp b/torch_npu/csrc/aten/ops/FullKernelNpu.cpp index 43682288ba..01cbc40417 100644 --- a/torch_npu/csrc/aten/ops/FullKernelNpu.cpp +++ b/torch_npu/csrc/aten/ops/FullKernelNpu.cpp @@ -1,5 +1,3 @@ -#include - #include "torch_npu/csrc/framework/utils/OpAdapter.h" #include "torch_npu/csrc/framework/utils/CalcuOpUtil.h" #include "torch_npu/csrc/aten/NPUNativeFunctions.h" @@ -18,35 +16,5 @@ at::Tensor& NPUNativeFunctions::full_out(at::IntArrayRef size, const at::Scalar& return out; } -at::Tensor NPUNativeFunctions::full( - at::IntArrayRef size, - const at::Scalar& fill_value, - c10::optional names, - c10::optional dtype_opt, - c10::optional layout_opt, - c10::optional device_opt, - c10::optional pin_memory_opt) -{ - c10::TensorOptions option = c10::TensorOptions().dtype(dtype_opt) - .device(device_opt) - .layout(layout_opt) - .pinned_memory(pin_memory_opt); - at::Tensor result = OpPreparation::ApplyTensorWithSizes(size, option); - - if (!dtype_opt.has_value()) { - if (fill_value.isBoolean()) { - option = option.dtype(at::kBool); - } else if (fill_value.isIntegral(false)) { - option = option.dtype(at::kLong); - } else { - option = option.dtype(c10::get_default_dtype()); - } - } - - auto maybe_name = names.value_or(at::ArrayRef{}); - at::namedinference::propagate_names_if_nonempty(result, maybe_name); - return result.fill_(fill_value); -} - } } diff --git a/torch_npu/csrc/aten/ops/op_api/CloneKernelOpApi.cpp b/torch_npu/csrc/aten/ops/op_api/CloneKernelOpApi.cpp index d73815eb1f..50a3ffeaeb 100644 --- a/torch_npu/csrc/aten/ops/op_api/CloneKernelOpApi.cpp +++ b/torch_npu/csrc/aten/ops/op_api/CloneKernelOpApi.cpp @@ -39,7 +39,6 @@ at::Tensor NPUNativeOpApiFunctions::clone(const at::Tensor &src, c10::optional expect_sparse_gradients_; - std::vector> + std::vector> grad_accumulators_; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) std::unordered_map gradAccToVariableMap_; - std::vector>> + std::vector>> hooks_; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) diff --git a/torch_npu/csrc/framework/autograd/VariableTypeManual.cpp b/torch_npu/csrc/framework/autograd/VariableTypeManual.cpp index 7ef8237d0f..f463f44524 100644 --- a/torch_npu/csrc/framework/autograd/VariableTypeManual.cpp +++ b/torch_npu/csrc/framework/autograd/VariableTypeManual.cpp @@ -98,9 +98,9 @@ namespace { Tensor _fw_primal(c10::DispatchKeySet ks, const Tensor& self, int64_t level) { auto& self_ = unpack(self, "self", 0); - std::shared_ptr grad_fn; + c10::intrusive_ptr grad_fn; if (compute_requires_grad(self)) { - grad_fn = std::make_shared(); + grad_fn = c10::make_intrusive(); grad_fn->set_next_edges(collect_next_edges(self)); } diff --git a/torch_npu/csrc/framework/contiguous/ContiguousOpt.cpp b/torch_npu/csrc/framework/contiguous/ContiguousOpt.cpp index 9ca6676477..1b45b1ab45 100644 --- a/torch_npu/csrc/framework/contiguous/ContiguousOpt.cpp +++ b/torch_npu/csrc/framework/contiguous/ContiguousOpt.cpp @@ -227,7 +227,6 @@ at::Tensor TransContiguous::view_tensor(const at::Tensor& self, auto* self_tmp_ = self_.unsafeGetTensorImpl(); self_tmp_->set_storage_offset(offset); self_tmp_->set_sizes_and_strides(sizes, strides); - at::namedinference::propagate_names(self_, self); return self_; } diff --git a/torch_npu/csrc/framework/contiguous/combined_opt.cpp b/torch_npu/csrc/framework/contiguous/combined_opt.cpp index d95fd051db..2665f90d50 100644 --- a/torch_npu/csrc/framework/contiguous/combined_opt.cpp +++ b/torch_npu/csrc/framework/contiguous/combined_opt.cpp @@ -1,4 +1,3 @@ -#include #include #include diff --git a/torch_npu/csrc/framework/utils/CalcuOpUtil.h b/torch_npu/csrc/framework/utils/CalcuOpUtil.h index 9f0cb38e10..a44fe6310a 100644 --- a/torch_npu/csrc/framework/utils/CalcuOpUtil.h +++ b/torch_npu/csrc/framework/utils/CalcuOpUtil.h @@ -6,7 +6,6 @@ #include #include -#include #include "torch_npu/csrc/core/npu/NPUException.h" #include "torch_npu/csrc/core/npu/DeviceUtils.h" diff --git a/torch_npu/csrc/inductor/aoti_torch/generated/c_shim_npu.h b/torch_npu/csrc/inductor/aoti_torch/generated/c_shim_npu.h index 104337efc4..c97c4861bf 100644 --- a/torch_npu/csrc/inductor/aoti_torch/generated/c_shim_npu.h +++ b/torch_npu/csrc/inductor/aoti_torch/generated/c_shim_npu.h @@ -24,7 +24,9 @@ AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu__fft_c2c(AtenTensorHandle self, AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu__fft_r2c(AtenTensorHandle self, const int64_t* dim, int64_t dim_len_, int64_t normalization, int32_t onesided, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu__fused_moving_avg_obs_fq_helper_functional(AtenTensorHandle self, AtenTensorHandle observer_on, AtenTensorHandle fake_quant_on, AtenTensorHandle running_min, AtenTensorHandle running_max, AtenTensorHandle scale, AtenTensorHandle zero_point, double averaging_const, int64_t quant_min, int64_t quant_max, int64_t ch_axis, int32_t per_row_fake_quant, int32_t symmetric_quant, AtenTensorHandle* ret0, AtenTensorHandle* ret1, AtenTensorHandle* ret2, AtenTensorHandle* ret3, AtenTensorHandle* ret4, AtenTensorHandle* ret5); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu__fused_rms_norm(AtenTensorHandle input, const int64_t* normalized_shape, int64_t normalized_shape_len_, AtenTensorHandle* weight, double* eps, AtenTensorHandle* ret0, AtenTensorHandle* ret1); +#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu__grouped_mm(AtenTensorHandle self, AtenTensorHandle mat2, AtenTensorHandle* offs, AtenTensorHandle* bias, int32_t* out_dtype, AtenTensorHandle* ret0); +#endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu__pdist_forward(AtenTensorHandle self, double p, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu__thnn_fused_lstm_cell(AtenTensorHandle input_gates, AtenTensorHandle hidden_gates, AtenTensorHandle cx, AtenTensorHandle* input_bias, AtenTensorHandle* hidden_bias, AtenTensorHandle* ret0, AtenTensorHandle* ret1, AtenTensorHandle* ret2); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu__to_sparse(AtenTensorHandle self, int32_t* layout, const int64_t** blocksize, int64_t blocksize_len_, int64_t* dense_dim, AtenTensorHandle* ret0); @@ -59,6 +61,12 @@ AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_cumsum(AtenTensorHandle self, in AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_exponential(AtenTensorHandle self, double lambd, AtenGeneratorHandle* generator, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_fill__Scalar(AtenTensorHandle self, double value); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_grid_sampler_2d_backward(AtenTensorHandle grad_output, AtenTensorHandle input, AtenTensorHandle grid, int64_t interpolation_mode, int64_t padding_mode, int32_t align_corners, const int32_t* output_mask, int64_t output_mask_len_, AtenTensorHandle* ret0, AtenTensorHandle* ret1); +#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_13_0 +AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_grid_sampler_3d(AtenTensorHandle input, AtenTensorHandle grid, int64_t interpolation_mode, int64_t padding_mode, int32_t align_corners, AtenTensorHandle* ret0); +#endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_13_0 +#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_13_0 +AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_grid_sampler_3d_backward(AtenTensorHandle grad_output, AtenTensorHandle input, AtenTensorHandle grid, int64_t interpolation_mode, int64_t padding_mode, int32_t align_corners, const int32_t* output_mask, int64_t output_mask_len_, AtenTensorHandle* ret0, AtenTensorHandle* ret1); +#endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_13_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_hann_window(int64_t window_length, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_histc(AtenTensorHandle self, int64_t bins, double min, double max, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_index_Tensor(AtenTensorHandle self, const AtenTensorHandle** indices, int64_t indices_len_, AtenTensorHandle* ret0); @@ -75,7 +83,9 @@ AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_max_pool3d_with_indices_backward AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_max_unpool2d(AtenTensorHandle self, AtenTensorHandle indices, const int64_t* output_size, int64_t output_size_len_, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_max_unpool3d(AtenTensorHandle self, AtenTensorHandle indices, const int64_t* output_size, int64_t output_size_len_, const int64_t* stride, int64_t stride_len_, const int64_t* padding, int64_t padding_len_, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_median(AtenTensorHandle self, AtenTensorHandle* ret0); +#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_mm_dtype_out(AtenTensorHandle out, AtenTensorHandle self, AtenTensorHandle mat2, int32_t out_dtype); +#endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_11_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_mm_out(AtenTensorHandle out, AtenTensorHandle self, AtenTensorHandle mat2); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_mul_Scalar(AtenTensorHandle self, double other, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_mul_Tensor(AtenTensorHandle self, AtenTensorHandle other, AtenTensorHandle* ret0); @@ -92,18 +102,30 @@ AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_pow_Tensor_Scalar(AtenTensorHand AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_pow_Tensor_Tensor(AtenTensorHandle self, AtenTensorHandle exponent, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_rand(const int64_t* size, int64_t size_len_, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_rand_generator(const int64_t* size, int64_t size_len_, AtenGeneratorHandle* generator, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, AtenTensorHandle* ret0); +#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_rand_like(AtenTensorHandle self, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, int32_t* memory_format, AtenTensorHandle* ret0); +#endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 +#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_rand_like_generator(AtenTensorHandle self, AtenGeneratorHandle* generator, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, int32_t* memory_format, AtenTensorHandle* ret0); +#endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_randint(int64_t high, const int64_t* size, int64_t size_len_, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_randint_generator(int64_t high, const int64_t* size, int64_t size_len_, AtenGeneratorHandle* generator, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_randint_low(int64_t low, int64_t high, const int64_t* size, int64_t size_len_, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_randint_low_out(AtenTensorHandle out, int64_t low, int64_t high, const int64_t* size, int64_t size_len_); +#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_randint_like(AtenTensorHandle self, int64_t high, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, int32_t* memory_format, AtenTensorHandle* ret0); +#endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 +#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_randint_like_low_dtype(AtenTensorHandle self, int64_t low, int64_t high, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, int32_t* memory_format, AtenTensorHandle* ret0); +#endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_randn(const int64_t* size, int64_t size_len_, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_randn_generator(const int64_t* size, int64_t size_len_, AtenGeneratorHandle* generator, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, AtenTensorHandle* ret0); +#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_randn_like(AtenTensorHandle self, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, int32_t* memory_format, AtenTensorHandle* ret0); +#endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 +#if TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_randn_like_generator(AtenTensorHandle self, AtenGeneratorHandle* generator, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, int32_t* memory_format, AtenTensorHandle* ret0); +#endif // TORCH_FEATURE_VERSION >= TORCH_VERSION_2_12_0 AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_randperm(int64_t n, int32_t* dtype, int32_t* layout, int32_t* device, int32_t device_index_, int32_t* pin_memory, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_replication_pad1d_backward(AtenTensorHandle grad_output, AtenTensorHandle self, const int64_t* padding, int64_t padding_len_, AtenTensorHandle* ret0); AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_replication_pad2d_backward(AtenTensorHandle grad_output, AtenTensorHandle self, const int64_t* padding, int64_t padding_len_, AtenTensorHandle* ret0); diff --git a/torchnpugen/autograd/templates/Functions.h b/torchnpugen/autograd/templates/Functions.h index bb822779e6..fc1e0ed24b 100644 --- a/torchnpugen/autograd/templates/Functions.h +++ b/torchnpugen/autograd/templates/Functions.h @@ -27,7 +27,7 @@ using at::ScalarType; using c10::optional; using c10::fmap; -inline std::vector unpack_list(at::ArrayRef xs, std::shared_ptr saved_for = nullptr) +inline std::vector unpack_list(at::ArrayRef xs, c10::intrusive_ptr saved_for = nullptr) { // NB: we must explicitly do the conversion in the lambda, otherwise template // deduction will give a Tensor of Variable which is not convertible @@ -36,7 +36,7 @@ inline std::vector unpack_list(at::ArrayRef xs, std::shar }); } -inline c10::List> unpack_opt_list(at::ArrayRef xs, std::shared_ptr saved_for = nullptr) +inline c10::List> unpack_opt_list(at::ArrayRef xs, c10::intrusive_ptr saved_for = nullptr) { torch::List> result; result.reserve(xs.size()); diff --git a/torchnpugen/autograd/templates/VariableType.h b/torchnpugen/autograd/templates/VariableType.h index ec552d867b..3c0e896dca 100644 --- a/torchnpugen/autograd/templates/VariableType.h +++ b/torchnpugen/autograd/templates/VariableType.h @@ -25,8 +25,6 @@ namespace at_npu { namespace autograd { using Variable = at::Tensor; using at::Context; using at::Device; -using at::Dimname; -using at::DimnameList; using at::Generator; using at::IntArrayRef; using at::MemoryFormat; diff --git a/torchnpugen/templates/CustomRegisterSchema.cpp b/torchnpugen/templates/CustomRegisterSchema.cpp index 15bd3fa4aa..e62224039f 100644 --- a/torchnpugen/templates/CustomRegisterSchema.cpp +++ b/torchnpugen/templates/CustomRegisterSchema.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include