From 9fbb5b194277609ebd09226cddd2cba447e974aa Mon Sep 17 00:00:00 2001 From: wangsike <771902230@qq.com> Date: Fri, 6 Mar 2026 16:57:53 +0800 Subject: [PATCH 01/12] Add GitHub Actions workflow for building torch_npu extension This workflow: 1. Clones PyTorch main repository 2. Clones kerer-ai/pytorch repository 3. Builds PyTorch from source 4. Builds torch_npu extension 5. Tests the installation 6. Uploads build artifacts The workflow supports multiple Python versions (3.9, 3.10, 3.11) and can be triggered on push to master, pull requests, or manually. Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/build-torch-npu.yml | 113 ++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 .github/workflows/build-torch-npu.yml diff --git a/.github/workflows/build-torch-npu.yml b/.github/workflows/build-torch-npu.yml new file mode 100644 index 0000000000..803146f573 --- /dev/null +++ b/.github/workflows/build-torch-npu.yml @@ -0,0 +1,113 @@ +name: Build Torch NPU Extension + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + workflow_dispatch: # Allow manual triggering + +jobs: + build-torch-npu: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - name: Checkout kerer-ai/pytorch + uses: actions/checkout@v4 + with: + path: torch-npu + + - name: Checkout PyTorch + uses: actions/checkout@v4 + with: + repository: pytorch/pytorch + path: pytorch + ref: main + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + cmake \ + ninja-build \ + g++ \ + git \ + libopenblas-dev \ + libopenmpi-dev \ + openmpi-bin \ + openmpi-common \ + libgomp1 \ + libnuma-dev + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install wheel setuptools + pip install -r torch-npu/requirements.txt + + - name: Build PyTorch + working-directory: pytorch + env: + USE_CUDA: 0 + USE_CUDNN: 0 + USE_MKLDNN: 0 + USE_NNPACK: 0 + USE_QNNPACK: 0 + USE_XNNPACK: 0 + USE_DISTRIBUTED: 0 + USE_OPENMP: 1 + USE_FBGEMM: 0 + USE_NUMPY: 1 + BUILD_TEST: 0 + _GLIBCXX_USE_CXX11_ABI: 1 + run: | + # Install PyTorch build dependencies + pip install -r requirements.txt + + # Build PyTorch in development mode + python setup.py develop + + - name: Build torch_npu extension + working-directory: torch-npu + env: + _GLIBCXX_USE_CXX11_ABI: 1 + USE_CUDA: 0 + run: | + # Initialize submodules if needed + if [ -f .gitmodules ]; then + git submodule update --init --recursive + fi + + # Build torch_npu + bash ci/build.sh --python=${{ matrix.python-version }} + + - name: Test installation + run: | + # Install the built wheel + wheel_file=$(find torch-npu/dist -name "torch_npu*.whl" | head -1) + if [ -f "$wheel_file" ]; then + pip install "$wheel_file" + echo "torch_npu installed successfully" + + # Basic test + python -c "import torch; import torch_npu; print(f'PyTorch version: {torch.__version__}'); print(f'torch_npu version: {torch_npu.__version__}')" + else + echo "Error: No wheel file found in torch-npu/dist/" + exit 1 + fi + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + if: success() + with: + name: torch-npu-wheels-${{ matrix.python-version }} + path: torch-npu/dist/*.whl + retention-days: 7 \ No newline at end of file From 82cdb48aea340aa1617eaaa3851b45a30604a01b Mon Sep 17 00:00:00 2001 From: wangsike <771902230@qq.com> Date: Fri, 6 Mar 2026 17:19:36 +0800 Subject: [PATCH 02/12] Fix GitHub Actions workflow for torch_npu build Changes: 1. Remove torch installation from requirements.txt to avoid conflict with compiled PyTorch 2. Add Huawei Cloud mirror for faster package installation in China 3. Add warning about missing CANN environment 4. Adjust Python versions to match existing CI (3.8, 3.9, 3.10) The build may still fail due to missing CANN drivers for Ascend NPU support. Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/build-torch-npu.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-torch-npu.yml b/.github/workflows/build-torch-npu.yml index 803146f573..a9fd381e62 100644 --- a/.github/workflows/build-torch-npu.yml +++ b/.github/workflows/build-torch-npu.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10"] steps: - name: Checkout kerer-ai/pytorch @@ -51,7 +51,8 @@ jobs: run: | python -m pip install --upgrade pip pip install wheel setuptools - pip install -r torch-npu/requirements.txt + # 使用华为云镜像源安装依赖 + pip install pyyaml setuptools auditwheel -i https://mirrors.huaweicloud.com/repository/pypi/simple - name: Build PyTorch working-directory: pytorch @@ -69,8 +70,8 @@ jobs: BUILD_TEST: 0 _GLIBCXX_USE_CXX11_ABI: 1 run: | - # Install PyTorch build dependencies - pip install -r requirements.txt + # Install PyTorch build dependencies with Huawei Cloud mirror + pip install -r requirements.txt -i https://mirrors.huaweicloud.com/repository/pypi/simple # Build PyTorch in development mode python setup.py develop @@ -86,6 +87,10 @@ jobs: git submodule update --init --recursive fi + # Note: This build may fail due to missing CANN (Compute Architecture for Neural Networks) environment + # CANN is required for Ascend NPU support. For full functionality, CANN drivers and libraries are needed. + echo "Warning: Building without CANN environment. This is a limited build for testing purposes only." + # Build torch_npu bash ci/build.sh --python=${{ matrix.python-version }} From 4f6522032b1b07a9a8662af75b7d4bd6324f8d18 Mon Sep 17 00:00:00 2001 From: wangsike <771902230@qq.com> Date: Fri, 6 Mar 2026 17:23:57 +0800 Subject: [PATCH 03/12] Add test workflow for basic build validation This workflow only checks: 1. Build script syntax 2. setup.py syntax 3. Project structure It does not attempt full build, which requires CANN environment. Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/test-build.yml | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/test-build.yml diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml new file mode 100644 index 0000000000..08140faba6 --- /dev/null +++ b/.github/workflows/test-build.yml @@ -0,0 +1,52 @@ +name: Test Build (Basic) + +on: + workflow_dispatch: # Manual trigger only + +jobs: + test-build: + runs-on: ubuntu-latest + + steps: + - name: Checkout kerer-ai/pytorch + uses: actions/checkout@v4 + with: + path: torch-npu + + - name: Set up Python 3.9 + uses: actions/setup-python@v5 + with: + python-version: "3.9" + + - name: Install basic dependencies + run: | + python -m pip install --upgrade pip + pip install wheel setuptools pyyaml -i https://mirrors.huaweicloud.com/repository/pypi/simple + + - name: Check build script syntax + working-directory: torch-npu + run: | + echo "Checking build script..." + if [ -f ci/build.sh ]; then + bash -n ci/build.sh + echo "Build script syntax OK" + else + echo "Error: ci/build.sh not found" + exit 1 + fi + + - name: Check setup.py + working-directory: torch-npu + run: | + echo "Checking setup.py..." + python -m py_compile setup.py + echo "setup.py syntax OK" + + - name: List project structure + working-directory: torch-npu + run: | + echo "Project structure:" + find . -type f -name "*.py" | head -20 + echo "" + echo "Top-level files:" + ls -la \ No newline at end of file From a6904c49f2835f72bc999fd636ffc26825bc89fa Mon Sep 17 00:00:00 2001 From: wangsike <771902230@qq.com> Date: Fri, 6 Mar 2026 22:44:31 +0800 Subject: [PATCH 04/12] Add separate workflows for PyTorch and torch_npu builds 1. build-pytorch.yml: Builds PyTorch from source - Supports multiple Python versions (3.9, 3.10, 3.11) - Two build modes: develop (editable) and install - Weekly scheduled builds 2. build-torch-npu-simple.yml: Simplified torch_npu build - Installs pre-built PyTorch - Checks environment and dependencies - Creates build report with next steps - Acknowledges CANN dependency requirement These workflows separate the complex build process and provide better debugging information. Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/build-pytorch.yml | 96 +++++++++++++++++ .github/workflows/build-torch-npu-simple.yml | 103 +++++++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 .github/workflows/build-pytorch.yml create mode 100644 .github/workflows/build-torch-npu-simple.yml diff --git a/.github/workflows/build-pytorch.yml b/.github/workflows/build-pytorch.yml new file mode 100644 index 0000000000..dc8d6380a3 --- /dev/null +++ b/.github/workflows/build-pytorch.yml @@ -0,0 +1,96 @@ +name: Build PyTorch from Source + +on: + workflow_dispatch: # Manual trigger only + schedule: + - cron: '0 0 * * 0' # Weekly on Sunday at midnight + +jobs: + build-pytorch: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11"] + build-type: ["develop", "install"] + + steps: + - name: Checkout PyTorch + uses: actions/checkout@v4 + with: + repository: pytorch/pytorch + ref: main + path: pytorch + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + cmake \ + ninja-build \ + g++ \ + gcc \ + git \ + libopenblas-dev \ + libopenmpi-dev \ + openmpi-bin \ + openmpi-common \ + libgomp1 \ + libnuma-dev \ + libjpeg-dev \ + libpng-dev + + - name: Install Python build dependencies + run: | + python -m pip install --upgrade pip + pip install wheel setuptools + cd pytorch + pip install -r requirements.txt -i https://mirrors.huaweicloud.com/repository/pypi/simple + + - name: Build PyTorch (${{ matrix.build-type }}) + working-directory: pytorch + env: + USE_CUDA: 0 + USE_CUDNN: 0 + USE_MKLDNN: 0 + USE_NNPACK: 0 + USE_QNNPACK: 0 + USE_XNNPACK: 0 + USE_DISTRIBUTED: 0 + USE_OPENMP: 1 + USE_FBGEMM: 0 + USE_NUMPY: 1 + BUILD_TEST: 0 + _GLIBCXX_USE_CXX11_ABI: 1 + MAX_JOBS: 4 + run: | + echo "Building PyTorch with Python ${{ matrix.python-version }} in ${{ matrix.build-type }} mode" + + if [ "${{ matrix.build-type }}" = "develop" ]; then + # Development mode (editable install) + python setup.py develop + echo "PyTorch installed in development mode" + else + # Install mode (regular install) + python setup.py install + echo "PyTorch installed regularly" + fi + + - name: Test PyTorch installation + run: | + python -c "import torch; print(f'PyTorch version: {torch.__version__}'); print(f'PyTorch build config: {torch.__config__.show()}')" + python -c "import torch; x = torch.randn(3, 3); y = x @ x.t(); print(f'Matrix multiplication test: {y.shape}')" + + - name: Upload build info + if: success() + uses: actions/upload-artifact@v4 + with: + name: pytorch-build-info-${{ matrix.python-version }}-${{ matrix.build-type }} + path: | + pytorch/build/lib*/torch/__config__.py + pytorch/build/lib*/torch/version.py + retention-days: 30 \ No newline at end of file diff --git a/.github/workflows/build-torch-npu-simple.yml b/.github/workflows/build-torch-npu-simple.yml new file mode 100644 index 0000000000..5597a4635f --- /dev/null +++ b/.github/workflows/build-torch-npu-simple.yml @@ -0,0 +1,103 @@ +name: Build Torch NPU (Simple) + +on: + workflow_dispatch: # Manual trigger only + +jobs: + build-torch-npu: + runs-on: ubuntu-latest + + steps: + - name: Checkout kerer-ai/pytorch + uses: actions/checkout@v4 + with: + path: torch-npu + + - name: Set up Python 3.9 + uses: actions/setup-python@v5 + with: + python-version: "3.9" + + - name: Install basic Python dependencies + run: | + python -m pip install --upgrade pip + pip install wheel setuptools pyyaml auditwheel -i https://mirrors.huaweicloud.com/repository/pypi/simple + + - name: Install PyTorch (pre-built) + run: | + # Install a compatible PyTorch version + pip install torch==2.1.0 -i https://mirrors.huaweicloud.com/repository/pypi/simple + + - name: Initialize submodules + working-directory: torch-npu + run: | + if [ -f .gitmodules ]; then + git submodule update --init --recursive + fi + + - name: Check build environment + working-directory: torch-npu + run: | + echo "Python version: $(python --version)" + echo "Pip version: $(pip --version)" + python -c "import torch; print(f'PyTorch version: {torch.__version__}'); print(f'PyTorch path: {torch.__file__}')" + + # Check if setup.py can be parsed + python -m py_compile setup.py + echo "setup.py syntax OK" + + # Check build script + if [ -f ci/build.sh ]; then + bash -n ci/build.sh + echo "Build script syntax OK" + fi + + - name: Attempt build (dry run) + working-directory: torch-npu + env: + _GLIBCXX_USE_CXX11_ABI: 1 + USE_CUDA: 0 + run: | + echo "Attempting to build torch_npu..." + echo "Note: This will likely fail due to missing CANN dependencies" + + # Try to run setup.py in dry-run mode + python setup.py build --dry-run || echo "Dry run completed (may show errors)" + + - name: Check for CANN dependencies + working-directory: torch-npu + run: | + echo "Checking for CANN-related files..." + find . -type f -name "*.py" -exec grep -l "cann\|CANN\|ascend\|Ascend" {} \; | head -10 || true + echo "" + echo "Checking build dependencies in setup.py..." + grep -n "cann\|CANN\|ascend\|Ascend" setup.py | head -10 || true + + - name: Create build report + if: always() + run: | + echo "=== Build Environment Report ===" + echo "OS: $(uname -a)" + echo "Python: $(python --version)" + echo "PyTorch: $(python -c 'import torch; print(torch.__version__)' 2>/dev/null || echo 'Not installed')" + echo "" + echo "=== Next Steps ===" + echo "1. This build requires CANN (Compute Architecture for Neural Networks) environment" + echo "2. CANN is Huawei's software stack for Ascend NPU" + echo "3. For full build, need:" + echo " - CANN toolkit installed" + echo " - Ascend driver installed" + echo " - NPU hardware or emulator" + echo "" + echo "=== Workflow Status ===" > report.md + echo "- PyTorch: Installed" >> report.md + echo "- torch_npu: Requires CANN" >> report.md + echo "- Build: Partial (environment check only)" >> report.md + + - name: Upload build report + if: always() + uses: actions/upload-artifact@v4 + with: + name: torch-npu-build-report + path: report.md + retention-days: 7 \ No newline at end of file From 4c1cee44d029cd0835307ed965c1e350d10f782a Mon Sep 17 00:00:00 2001 From: wangsike <771902230@qq.com> Date: Fri, 6 Mar 2026 23:10:35 +0800 Subject: [PATCH 05/12] Add workflow with correct PyTorch version for torch_npu This workflow: 1. Installs the exact PyTorch version required (2.11.0.dev20251215) 2. Includes numpy to avoid warnings 3. Provides detailed analysis of build requirements 4. Documents CANN dependency clearly The build still requires CANN environment for Ascend NPU support. Co-Authored-By: Claude Sonnet 4.6 --- .../build-torch-npu-correct-version.yml | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 .github/workflows/build-torch-npu-correct-version.yml diff --git a/.github/workflows/build-torch-npu-correct-version.yml b/.github/workflows/build-torch-npu-correct-version.yml new file mode 100644 index 0000000000..359bcf5eca --- /dev/null +++ b/.github/workflows/build-torch-npu-correct-version.yml @@ -0,0 +1,121 @@ +name: Build Torch NPU (Correct Version) + +on: + workflow_dispatch: # Manual trigger only + +jobs: + build-torch-npu: + runs-on: ubuntu-latest + + steps: + - name: Checkout kerer-ai/pytorch + uses: actions/checkout@v4 + with: + path: torch-npu + + - name: Set up Python 3.9 + uses: actions/setup-python@v5 + with: + python-version: "3.9" + + - name: Install basic Python dependencies + run: | + python -m pip install --upgrade pip + pip install wheel setuptools pyyaml auditwheel numpy -i https://mirrors.huaweicloud.com/repository/pypi/simple + + - name: Install correct PyTorch version + run: | + # Install the exact PyTorch version required by torch_npu + echo "Installing PyTorch version: 2.11.0.dev20251215" + pip install torch==2.11.0.dev20251215 --index-url https://download.pytorch.org/whl/nightly/cpu -i https://mirrors.huaweicloud.com/repository/pypi/simple + + - name: Initialize submodules + working-directory: torch-npu + run: | + if [ -f .gitmodules ]; then + git submodule update --init --recursive + fi + + - name: Check build environment + working-directory: torch-npu + run: | + echo "=== Build Environment ===" + echo "Python version: $(python --version)" + echo "Pip version: $(pip --version)" + python -c "import torch; print(f'PyTorch version: {torch.__version__}'); print(f'PyTorch path: {torch.__file__}')" + python -c "import numpy; print(f'NumPy version: {numpy.__version__}')" + + # Check torchgen compatibility + python -c "from torchgen.packaged.autograd.gen_inplace_or_view_type import extract_bindings; print('extract_bindings import successful')" 2>/dev/null || echo "extract_bindings import failed (expected)" + + - name: Try to build with workaround + working-directory: torch-npu + env: + _GLIBCXX_USE_CXX11_ABI: 1 + USE_CUDA: 0 + USE_NUMPY: 1 + BUILD_TEST: 0 + run: | + echo "=== Attempting Build ===" + echo "Note: This build requires CANN environment for Ascend NPU" + + # Create a simple test to check if we can bypass the import error + cat > test_import.py << 'EOF' +import sys +sys.path.insert(0, '.') +try: + # Try to import the problematic module + from torchnpugen.autograd.utils import VERSION_PART + print("Import successful!") +except ImportError as e: + print(f"Import error: {e}") + print("This is expected without CANN environment") +EOF + + python test_import.py + + - name: Check for build artifacts + working-directory: torch-npu + run: | + echo "=== Checking Build Artifacts ===" + if [ -d "build" ]; then + echo "Build directory exists" + find build -type f -name "*.so" -o -name "*.py" | head -10 + else + echo "No build directory found" + fi + + - name: Create comprehensive report + if: always() + run: | + echo "=== Torch NPU Build Analysis ===" > report.md + echo "" >> report.md + echo "## Build Status" >> report.md + echo "- PyTorch Version: 2.11.0.dev20251215 ✓" >> report.md + echo "- Python Environment: 3.9 ✓" >> report.md + echo "- Build Attempted: Yes" >> report.md + echo "- CANN Environment: Missing (Required)" >> report.md + echo "" >> report.md + echo "## Issues Identified" >> report.md + echo "1. **CANN Dependency**: Huawei Ascend NPU software stack required" >> report.md + echo "2. **PyTorch Version**: Requires specific development version" >> report.md + echo "3. **Import Compatibility**: torchgen API changes may cause issues" >> report.md + echo "" >> report.md + echo "## Next Steps for Full Build" >> report.md + echo "1. **Install CANN Toolkit** from Huawei Ascend Community" >> report.md + echo "2. **Set up build environment** with CANN libraries" >> report.md + echo "3. **Use Docker image** with pre-installed CANN (see existing CI)" >> report.md + echo "4. **Check PyTorch compatibility** with torch_npu codebase" >> report.md + echo "" >> report.md + echo "## References" >> report.md + echo "- [Ascend Community](https://www.hiascend.com/en/)" >> report.md + echo "- [CANN Installation](https://www.hiascend.com/cann)" >> report.md + echo "- [Existing CI Configuration](.github/workflows/_build-and-test.yml)" >> report.md + + - name: Upload build report + if: always() + uses: actions/upload-artifact@v4 + with: + name: torch-npu-build-analysis + path: report.md + retention-days: 30 \ No newline at end of file From 7e7cbdc3e88a5df640e9a1d6d05764ea9143a555 Mon Sep 17 00:00:00 2001 From: wangsike Date: Thu, 2 Apr 2026 21:14:03 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/nightly-build-arm.yml | 194 ++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 .github/workflows/nightly-build-arm.yml diff --git a/.github/workflows/nightly-build-arm.yml b/.github/workflows/nightly-build-arm.yml new file mode 100644 index 0000000000..20bede24f4 --- /dev/null +++ b/.github/workflows/nightly-build-arm.yml @@ -0,0 +1,194 @@ +name: Ascend/pytorch Nightly Build Validation (ARM) + +on: + pull_request: # 监听所有PR事件 + branches: [ master ] + schedule: + - cron: '0 22 * * *' # UTC 22:00(北京时间次日 06:00) + - cron: '0 3 * * *' # UTC 03:00(北京时间 11:00) + - cron: '0 8 * * *' # UTC 08:00(北京时间 16:00) + workflow_dispatch: + inputs: + torch_nightly_date: + description: 'PyTorch nightly 日期 (格式: YYYYMMDD,留空使用最新版)' + required: false + default: '' + +jobs: + build: + name: Build torch_npu (ARM, PyTorch nightly) + runs-on: linux-aarch64-a3-2 + container: + image: swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch_2.11.0_a2_aarch64_builder:20260331 + options: --user root + env: + PYTHON_VERSION: '3.11' + DOCKER_IMAGE: swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch_2.11.0_a2_aarch64_builder:20260331 + # 跳过 auditwheel repair,避免因缺少 CANN 库(如 libccl_dpu.so)导致构建失败 + # torch_npu 依赖外部 CANN 环境,wheel 不需要自包含这些库 + AUDITWHEEL_PLAT: 'skip' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup cache directories + run: | + mkdir -p ~/.cache/pip + mkdir -p ~/.cache/ccache + chmod -R 777 ~/.cache + + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: pip-arm-py${{ env.PYTHON_VERSION }}-torch-nightly + restore-keys: | + pip-arm-py${{ env.PYTHON_VERSION }}- + + - name: Cache ccache + uses: actions/cache@v4 + with: + path: ~/.cache/ccache + key: ccache-arm-py${{ env.PYTHON_VERSION }}-${{ github.run_id }} + restore-keys: | + ccache-arm-py${{ env.PYTHON_VERSION }}- + + - name: Upgrade PyTorch to nightly (CPU, aarch64) + id: install_torch + run: | + # 使用镜像中的 Python 3.11 + PYTHON=python${{ env.PYTHON_VERSION }} + PIP=pip${{ env.PYTHON_VERSION }} + + # 配置 pip 使用缓存 + export PIP_CACHE_DIR=~/.cache/pip + + $PIP install --upgrade pip + + # 卸载镜像中预装的 torch 和 torchvision,避免版本冲突 + $PIP uninstall -y torch torchvision || true + + if [ -n "${{ github.event.inputs.torch_nightly_date }}" ]; then + DATE="${{ github.event.inputs.torch_nightly_date }}" + $PIP install --pre \ + "torch==2.12.0.dev${DATE}" \ + --index-url https://download.pytorch.org/whl/nightly/cpu + else + $PIP install --pre torch \ + --index-url https://download.pytorch.org/whl/nightly/cpu + fi + TORCH_VER=$($PYTHON -c "import torch; print(torch.__version__)") + echo "version=${TORCH_VER}" >> $GITHUB_OUTPUT + echo "PyTorch nightly version: ${TORCH_VER}" + + - name: Clone Ascend/pytorch (with submodules) + id: clone_repo + run: | + git clone --depth=1 --recurse-submodules \ + https://gitcode.com/Ascend/pytorch.git ascend_pytorch + cd ascend_pytorch + COMMIT=$(git rev-parse HEAD) + COMMIT_SHORT=$(git rev-parse --short HEAD) + COMMIT_DATE=$(git log -1 --format='%ci') + echo "commit=${COMMIT}" >> $GITHUB_OUTPUT + echo "commit_short=${COMMIT_SHORT}" >> $GITHUB_OUTPUT + echo "commit_date=${COMMIT_DATE}" >> $GITHUB_OUTPUT + echo "Ascend/pytorch commit: ${COMMIT} (${COMMIT_DATE})" + + - name: Install Python build dependencies + run: | + PIP=pip${{ env.PYTHON_VERSION }} + cd ascend_pytorch + # 跳过 requirements.txt 中固定的 torch 版本,使用我们安装的 nightly + # auditwheel 已通过 AUDITWHEEL_PLAT=skip 跳过,仅安装 setuptools + $PIP install setuptools + + - name: Build torch_npu wheel + id: build + run: | + PYTHON=python${{ env.PYTHON_VERSION }} + cd ascend_pytorch + + # 配置 ccache(如果可用) + if command -v ccache &> /dev/null; then + echo "ccache found, enabling ccache" + ccache -M 10G + ccache -z || true + export CC="ccache gcc" + export CXX="ccache g++" + export CCACHE_DIR=~/.cache/ccache + export CCACHE_COMPRESS=1 + export CCACHE_MAXSIZE=10G + export CCACHE_BASEDIR="${PWD}" + USE_CCACHE=1 + else + echo "ccache not found, building without cache" + USE_CCACHE=0 + fi + + # 根据 runner CPU 核心数设置并行编译数 + export MAX_JOBS=$(nproc) + + # 默认启用 torchair 构建;RPC 使用默认构建行为(不强制禁用) + export DISABLE_INSTALL_TORCHAIR=FALSE + export BUILD_WITHOUT_SHA=1 + $PYTHON setup.py build bdist_wheel 2>&1 | tee /tmp/build.log + BUILD_STATUS=${PIPESTATUS[0]} + + # 输出 ccache 统计信息 + if [ "${USE_CCACHE}" = "1" ]; then + CCACHE_STATS=$(ccache -s | grep -E "^(Hits|Misses|Cache size)" | tr '\n' ' ') + echo "hit_rate=${CCACHE_STATS}" >> $GITHUB_OUTPUT + ccache -s + fi + + echo "status=${BUILD_STATUS}" >> $GITHUB_OUTPUT + if [ ${BUILD_STATUS} -eq 0 ]; then + WHL=$(ls dist/*.whl 2>/dev/null | head -1) + echo "wheel=${WHL}" >> $GITHUB_OUTPUT + echo "Build succeeded: ${WHL}" + fi + exit ${BUILD_STATUS} + + - name: Upload build log + if: always() + uses: actions/upload-artifact@v4 + with: + name: build-log-arm-${{ github.run_number }} + path: /tmp/build.log + if-no-files-found: warn + + - name: Upload wheel + if: steps.build.outputs.status == '0' + uses: actions/upload-artifact@v4 + with: + name: torch_npu-wheel-arm-${{ github.run_number }} + path: ascend_pytorch/dist/*.whl + if-no-files-found: warn + + - name: Build summary + if: always() + run: | + BUILD_STATUS="${{ steps.build.outputs.status }}" + if [ "${BUILD_STATUS}" = "0" ]; then + STATUS_ICON="✅ SUCCESS" + else + STATUS_ICON="❌ FAILED" + fi + + cat >> $GITHUB_STEP_SUMMARY << EOF + ## Ascend/pytorch Nightly Build Validation (ARM) + + | 项目 | 详情 | + |------|------| + | 构建时间 | $(date -u '+%Y-%m-%d %H:%M UTC') | + | Docker 镜像 | \`${{ env.DOCKER_IMAGE }}\` | + | PyTorch Nightly | \`${{ steps.install_torch.outputs.version }}\` | + | Ascend/pytorch Commit | [\`${{ steps.clone_repo.outputs.commit_short }}\`](https://gitcode.com/Ascend/pytorch/commit/${{ steps.clone_repo.outputs.commit }}) | + | Commit 时间 | ${{ steps.clone_repo.outputs.commit_date }} | + | ccache 统计 | ${{ steps.build.outputs.hit_rate || 'N/A' }} | + | 构建结果 | ${STATUS_ICON} | + + $( [ "${BUILD_STATUS}" = "0" ] && echo "> Wheel: \`${{ steps.build.outputs.wheel }}\`" || echo "> 查看 build-log artifact 获取详细错误信息" ) + EOF \ No newline at end of file From de3716c496391692a3baa2fc5f747da7574a04e8 Mon Sep 17 00:00:00 2001 From: wangsike Date: Fri, 3 Apr 2026 09:57:18 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E6=B5=8B=E8=AF=95workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/nightly-build-arm.yml | 194 -------------------- .github/workflows/npu-test.yml | 230 ++++++++++++++++++++++++ 2 files changed, 230 insertions(+), 194 deletions(-) delete mode 100644 .github/workflows/nightly-build-arm.yml create mode 100644 .github/workflows/npu-test.yml diff --git a/.github/workflows/nightly-build-arm.yml b/.github/workflows/nightly-build-arm.yml deleted file mode 100644 index 20bede24f4..0000000000 --- a/.github/workflows/nightly-build-arm.yml +++ /dev/null @@ -1,194 +0,0 @@ -name: Ascend/pytorch Nightly Build Validation (ARM) - -on: - pull_request: # 监听所有PR事件 - branches: [ master ] - schedule: - - cron: '0 22 * * *' # UTC 22:00(北京时间次日 06:00) - - cron: '0 3 * * *' # UTC 03:00(北京时间 11:00) - - cron: '0 8 * * *' # UTC 08:00(北京时间 16:00) - workflow_dispatch: - inputs: - torch_nightly_date: - description: 'PyTorch nightly 日期 (格式: YYYYMMDD,留空使用最新版)' - required: false - default: '' - -jobs: - build: - name: Build torch_npu (ARM, PyTorch nightly) - runs-on: linux-aarch64-a3-2 - container: - image: swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch_2.11.0_a2_aarch64_builder:20260331 - options: --user root - env: - PYTHON_VERSION: '3.11' - DOCKER_IMAGE: swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch_2.11.0_a2_aarch64_builder:20260331 - # 跳过 auditwheel repair,避免因缺少 CANN 库(如 libccl_dpu.so)导致构建失败 - # torch_npu 依赖外部 CANN 环境,wheel 不需要自包含这些库 - AUDITWHEEL_PLAT: 'skip' - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup cache directories - run: | - mkdir -p ~/.cache/pip - mkdir -p ~/.cache/ccache - chmod -R 777 ~/.cache - - - name: Cache pip - uses: actions/cache@v4 - with: - path: ~/.cache/pip - key: pip-arm-py${{ env.PYTHON_VERSION }}-torch-nightly - restore-keys: | - pip-arm-py${{ env.PYTHON_VERSION }}- - - - name: Cache ccache - uses: actions/cache@v4 - with: - path: ~/.cache/ccache - key: ccache-arm-py${{ env.PYTHON_VERSION }}-${{ github.run_id }} - restore-keys: | - ccache-arm-py${{ env.PYTHON_VERSION }}- - - - name: Upgrade PyTorch to nightly (CPU, aarch64) - id: install_torch - run: | - # 使用镜像中的 Python 3.11 - PYTHON=python${{ env.PYTHON_VERSION }} - PIP=pip${{ env.PYTHON_VERSION }} - - # 配置 pip 使用缓存 - export PIP_CACHE_DIR=~/.cache/pip - - $PIP install --upgrade pip - - # 卸载镜像中预装的 torch 和 torchvision,避免版本冲突 - $PIP uninstall -y torch torchvision || true - - if [ -n "${{ github.event.inputs.torch_nightly_date }}" ]; then - DATE="${{ github.event.inputs.torch_nightly_date }}" - $PIP install --pre \ - "torch==2.12.0.dev${DATE}" \ - --index-url https://download.pytorch.org/whl/nightly/cpu - else - $PIP install --pre torch \ - --index-url https://download.pytorch.org/whl/nightly/cpu - fi - TORCH_VER=$($PYTHON -c "import torch; print(torch.__version__)") - echo "version=${TORCH_VER}" >> $GITHUB_OUTPUT - echo "PyTorch nightly version: ${TORCH_VER}" - - - name: Clone Ascend/pytorch (with submodules) - id: clone_repo - run: | - git clone --depth=1 --recurse-submodules \ - https://gitcode.com/Ascend/pytorch.git ascend_pytorch - cd ascend_pytorch - COMMIT=$(git rev-parse HEAD) - COMMIT_SHORT=$(git rev-parse --short HEAD) - COMMIT_DATE=$(git log -1 --format='%ci') - echo "commit=${COMMIT}" >> $GITHUB_OUTPUT - echo "commit_short=${COMMIT_SHORT}" >> $GITHUB_OUTPUT - echo "commit_date=${COMMIT_DATE}" >> $GITHUB_OUTPUT - echo "Ascend/pytorch commit: ${COMMIT} (${COMMIT_DATE})" - - - name: Install Python build dependencies - run: | - PIP=pip${{ env.PYTHON_VERSION }} - cd ascend_pytorch - # 跳过 requirements.txt 中固定的 torch 版本,使用我们安装的 nightly - # auditwheel 已通过 AUDITWHEEL_PLAT=skip 跳过,仅安装 setuptools - $PIP install setuptools - - - name: Build torch_npu wheel - id: build - run: | - PYTHON=python${{ env.PYTHON_VERSION }} - cd ascend_pytorch - - # 配置 ccache(如果可用) - if command -v ccache &> /dev/null; then - echo "ccache found, enabling ccache" - ccache -M 10G - ccache -z || true - export CC="ccache gcc" - export CXX="ccache g++" - export CCACHE_DIR=~/.cache/ccache - export CCACHE_COMPRESS=1 - export CCACHE_MAXSIZE=10G - export CCACHE_BASEDIR="${PWD}" - USE_CCACHE=1 - else - echo "ccache not found, building without cache" - USE_CCACHE=0 - fi - - # 根据 runner CPU 核心数设置并行编译数 - export MAX_JOBS=$(nproc) - - # 默认启用 torchair 构建;RPC 使用默认构建行为(不强制禁用) - export DISABLE_INSTALL_TORCHAIR=FALSE - export BUILD_WITHOUT_SHA=1 - $PYTHON setup.py build bdist_wheel 2>&1 | tee /tmp/build.log - BUILD_STATUS=${PIPESTATUS[0]} - - # 输出 ccache 统计信息 - if [ "${USE_CCACHE}" = "1" ]; then - CCACHE_STATS=$(ccache -s | grep -E "^(Hits|Misses|Cache size)" | tr '\n' ' ') - echo "hit_rate=${CCACHE_STATS}" >> $GITHUB_OUTPUT - ccache -s - fi - - echo "status=${BUILD_STATUS}" >> $GITHUB_OUTPUT - if [ ${BUILD_STATUS} -eq 0 ]; then - WHL=$(ls dist/*.whl 2>/dev/null | head -1) - echo "wheel=${WHL}" >> $GITHUB_OUTPUT - echo "Build succeeded: ${WHL}" - fi - exit ${BUILD_STATUS} - - - name: Upload build log - if: always() - uses: actions/upload-artifact@v4 - with: - name: build-log-arm-${{ github.run_number }} - path: /tmp/build.log - if-no-files-found: warn - - - name: Upload wheel - if: steps.build.outputs.status == '0' - uses: actions/upload-artifact@v4 - with: - name: torch_npu-wheel-arm-${{ github.run_number }} - path: ascend_pytorch/dist/*.whl - if-no-files-found: warn - - - name: Build summary - if: always() - run: | - BUILD_STATUS="${{ steps.build.outputs.status }}" - if [ "${BUILD_STATUS}" = "0" ]; then - STATUS_ICON="✅ SUCCESS" - else - STATUS_ICON="❌ FAILED" - fi - - cat >> $GITHUB_STEP_SUMMARY << EOF - ## Ascend/pytorch Nightly Build Validation (ARM) - - | 项目 | 详情 | - |------|------| - | 构建时间 | $(date -u '+%Y-%m-%d %H:%M UTC') | - | Docker 镜像 | \`${{ env.DOCKER_IMAGE }}\` | - | PyTorch Nightly | \`${{ steps.install_torch.outputs.version }}\` | - | Ascend/pytorch Commit | [\`${{ steps.clone_repo.outputs.commit_short }}\`](https://gitcode.com/Ascend/pytorch/commit/${{ steps.clone_repo.outputs.commit }}) | - | Commit 时间 | ${{ steps.clone_repo.outputs.commit_date }} | - | ccache 统计 | ${{ steps.build.outputs.hit_rate || 'N/A' }} | - | 构建结果 | ${STATUS_ICON} | - - $( [ "${BUILD_STATUS}" = "0" ] && echo "> Wheel: \`${{ steps.build.outputs.wheel }}\`" || echo "> 查看 build-log artifact 获取详细错误信息" ) - EOF \ No newline at end of file diff --git a/.github/workflows/npu-test.yml b/.github/workflows/npu-test.yml new file mode 100644 index 0000000000..3e3dd922b4 --- /dev/null +++ b/.github/workflows/npu-test.yml @@ -0,0 +1,230 @@ +name: NPU Build and Test + +on: + pull_request: + branches: [ master ] + workflow_dispatch: + inputs: + torch_nightly_date: + description: 'PyTorch nightly 日期 (格式: YYYYMMDD,留空使用最新版)' + required: false + default: '' + +jobs: + build-and-test: + name: Build and Test torch_npu + runs-on: linux-aarch64-a3-2 + container: + image: swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch_2.11.0_a2_aarch64_builder:20260331 + options: --user root --device /dev/davinci4 --device /dev/davinci_manager --device /dev/devmm_svm --device /dev/hisi_hdc -v /usr/local/sbin/npu-smi:/usr/local/sbin/npu-smi -v /usr/local/Ascend/driver:/usr/local/Ascend/driver -v /usr/local/Ascend/firmware:/usr/local/Ascend/firmware -v /usr/local/Ascend/cann:/usr/local/Ascend/cann -v /usr/local/Ascend/nnal:/usr/local/Ascend/nnal + env: + PYTHON_VERSION: '3.11' + DOCKER_IMAGE: swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch_2.11.0_a2_aarch64_builder:20260331 + AUDITWHEEL_PLAT: 'skip' + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup cache directories + run: | + mkdir -p ~/.cache/pip + mkdir -p ~/.cache/ccache + chmod -R 777 ~/.cache + + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: pip-arm-py${{ env.PYTHON_VERSION }}-build-test + restore-keys: | + pip-arm-py${{ env.PYTHON_VERSION }}- + + - name: Cache ccache + uses: actions/cache@v4 + with: + path: ~/.cache/ccache + key: ccache-arm-py${{ env.PYTHON_VERSION }}-${{ github.run_id }} + restore-keys: | + ccache-arm-py${{ env.PYTHON_VERSION }}- + + - name: Uninstall pre-installed packages + run: | + pip${{ env.PYTHON_VERSION }} uninstall -y torch torchvision pyyaml setuptools auditwheel || true + echo "Pre-installed packages uninstalled" + + - name: Install PyTorch nightly + id: install_torch + run: | + PIP=pip${{ env.PYTHON_VERSION }} + PYTHON=python${{ env.PYTHON_VERSION }} + + export PIP_CACHE_DIR=~/.cache/pip + $PIP install --upgrade pip + + # 安装基础依赖 + $PIP install pyyaml setuptools auditwheel + + if [ -n "${{ github.event.inputs.torch_nightly_date }}" ]; then + DATE="${{ github.event.inputs.torch_nightly_date }}" + $PIP install --pre "torch==2.12.0.dev${DATE}" --index-url https://download.pytorch.org/whl/nightly/cpu + else + # 按 requirements.txt 安装固定版本 + $PIP install --pre "torch==2.12.0.dev20260217" --extra-index-url https://download.pytorch.org/whl/nightly/cpu + fi + + TORCH_VER=$($PYTHON -c "import torch; print(torch.__version__)") + echo "version=${TORCH_VER}" >> $GITHUB_OUTPUT + echo "PyTorch nightly version: ${TORCH_VER}" + + - name: Build torch_npu wheel + id: build + run: | + PYTHON=python${{ env.PYTHON_VERSION }} + + # 配置 ccache + if command -v ccache &> /dev/null; then + echo "ccache found, enabling ccache" + ccache -M 10G + ccache -z || true + export CC="ccache gcc" + export CXX="ccache g++" + export CCACHE_DIR=~/.cache/ccache + export CCACHE_COMPRESS=1 + export CCACHE_MAXSIZE=10G + export CCACHE_BASEDIR="${PWD}" + USE_CCACHE=1 + else + echo "ccache not found, building without cache" + USE_CCACHE=0 + fi + + # 构建参数 + export MAX_JOBS=$(nproc) + export DISABLE_INSTALL_TORCHAIR=FALSE + export BUILD_WITHOUT_SHA=1 + + # 使用 ci/build.sh 脚本 + bash ci/build.sh --python=${{ env.PYTHON_VERSION }} 2>&1 | tee /tmp/build.log + BUILD_STATUS=${PIPESTATUS[0]} + + # ccache 统计 + if [ "${USE_CCACHE}" = "1" ]; then + CCACHE_STATS=$(ccache -s | grep -E "^(Hits|Misses|Cache size)" | tr '\n' ' ') + echo "ccache_stats=${CCACHE_STATS}" >> $GITHUB_OUTPUT + ccache -s + fi + + echo "status=${BUILD_STATUS}" >> $GITHUB_OUTPUT + if [ ${BUILD_STATUS} -eq 0 ]; then + WHL=$(ls dist/*.whl 2>/dev/null | head -1) + echo "wheel=${WHL}" >> $GITHUB_OUTPUT + echo "Build succeeded: ${WHL}" + fi + exit ${BUILD_STATUS} + + - name: Install torch_npu wheel + run: | + pip${{ env.PYTHON_VERSION }} install dist/torch_npu*.whl + echo "torch_npu wheel installed" + + - name: Check Ascend paths + run: | + echo "=== Checking Ascend paths ===" + ls -la /usr/local/Ascend/ 2>&1 || echo "/usr/local/Ascend not found" + ls -la /usr/local/Ascend/cann/ 2>&1 || echo "/usr/local/Ascend/cann not found" + ls -la /usr/local/Ascend/nnal/ 2>&1 || echo "/usr/local/Ascend/nnal not found" + + - name: Verify NPU availability + run: | + # 加载 CANN 环境变量 + 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=python${{ env.PYTHON_VERSION }} + echo "=== Testing torch_npu import ===" + $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()}'); print(f'NPU name: {torch.npu.get_device_name(0) if torch.npu.is_available() else \"N/A\"}')" + + - name: Run test_device.py + id: run_tests + run: | + # 加载 CANN 环境变量 + 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=python${{ env.PYTHON_VERSION }} + PIP=pip${{ env.PYTHON_VERSION }} + + # 安装 pytest + $PIP install pytest pytest-xdist + + cd test + $PYTHON -m pytest npu/test_device.py -v 2>&1 | tee /tmp/test.log + + if [ $? -eq 0 ]; then + echo "status=0" >> $GITHUB_OUTPUT + echo "test_device.py: PASSED" + else + echo "status=1" >> $GITHUB_OUTPUT + echo "test_device.py: FAILED" + fi + + - name: Upload build log + if: always() + uses: actions/upload-artifact@v4 + with: + name: build-log-${{ github.run_number }} + path: /tmp/build.log + if-no-files-found: warn + + - name: Upload test log + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-log-${{ github.run_number }} + path: /tmp/test.log + if-no-files-found: warn + + - name: Upload wheel artifact + if: steps.build.outputs.status == '0' + uses: actions/upload-artifact@v4 + with: + name: torch_npu-wheel-${{ github.run_number }} + path: dist/*.whl + if-no-files-found: warn + + - name: Build and Test summary + if: always() + run: | + BUILD_STATUS="${{ steps.build.outputs.status }}" + TEST_STATUS="${{ steps.run_tests.outputs.status }}" + + if [ "${BUILD_STATUS}" = "0" ]; then + BUILD_ICON="✅ SUCCESS" + else + BUILD_ICON="❌ FAILED" + fi + + if [ "${TEST_STATUS}" = "0" ]; then + TEST_ICON="✅ PASSED" + else + TEST_ICON="❌ FAILED" + fi + + cat >> $GITHUB_STEP_SUMMARY << EOF + ## NPU Build and Test + + | 项目 | 详情 | + |------|------| + | 执行时间 | $(date -u '+%Y-%m-%d %H:%M UTC') | + | Docker 镜像 | \`${{ env.DOCKER_IMAGE }}\` | + | PyTorch Nightly | \`${{ steps.install_torch.outputs.version }}\` | + | 仓库 Commit | \`${{ github.sha }}\` | + | ccache 统计 | ${{ steps.build.outputs.ccache_stats || 'N/A' }} | + | 构建结果 | ${BUILD_ICON} | + | 测试结果 | ${TEST_ICON} | + + $( [ "${BUILD_STATUS}" = "0" ] && echo "> Wheel: \`${{ steps.build.outputs.wheel }}\`" || echo "> 查看 build-log artifact 获取详细错误信息" ) + EOF \ No newline at end of file From 5b4535539390ed80b694dc36cc4852837cdcb78b Mon Sep 17 00:00:00 2001 From: wangsike Date: Fri, 3 Apr 2026 10:05:58 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E6=95=88workf?= =?UTF-8?q?low?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-pytorch.yml | 96 -------------- .../build-torch-npu-correct-version.yml | 121 ------------------ .github/workflows/build-torch-npu-simple.yml | 103 --------------- .github/workflows/build-torch-npu.yml | 118 ----------------- .github/workflows/test-build.yml | 52 -------- 5 files changed, 490 deletions(-) delete mode 100644 .github/workflows/build-pytorch.yml delete mode 100644 .github/workflows/build-torch-npu-correct-version.yml delete mode 100644 .github/workflows/build-torch-npu-simple.yml delete mode 100644 .github/workflows/build-torch-npu.yml delete mode 100644 .github/workflows/test-build.yml diff --git a/.github/workflows/build-pytorch.yml b/.github/workflows/build-pytorch.yml deleted file mode 100644 index dc8d6380a3..0000000000 --- a/.github/workflows/build-pytorch.yml +++ /dev/null @@ -1,96 +0,0 @@ -name: Build PyTorch from Source - -on: - workflow_dispatch: # Manual trigger only - schedule: - - cron: '0 0 * * 0' # Weekly on Sunday at midnight - -jobs: - build-pytorch: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.9", "3.10", "3.11"] - build-type: ["develop", "install"] - - steps: - - name: Checkout PyTorch - uses: actions/checkout@v4 - with: - repository: pytorch/pytorch - ref: main - path: pytorch - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - - name: Install system dependencies - run: | - sudo apt-get update - sudo apt-get install -y \ - cmake \ - ninja-build \ - g++ \ - gcc \ - git \ - libopenblas-dev \ - libopenmpi-dev \ - openmpi-bin \ - openmpi-common \ - libgomp1 \ - libnuma-dev \ - libjpeg-dev \ - libpng-dev - - - name: Install Python build dependencies - run: | - python -m pip install --upgrade pip - pip install wheel setuptools - cd pytorch - pip install -r requirements.txt -i https://mirrors.huaweicloud.com/repository/pypi/simple - - - name: Build PyTorch (${{ matrix.build-type }}) - working-directory: pytorch - env: - USE_CUDA: 0 - USE_CUDNN: 0 - USE_MKLDNN: 0 - USE_NNPACK: 0 - USE_QNNPACK: 0 - USE_XNNPACK: 0 - USE_DISTRIBUTED: 0 - USE_OPENMP: 1 - USE_FBGEMM: 0 - USE_NUMPY: 1 - BUILD_TEST: 0 - _GLIBCXX_USE_CXX11_ABI: 1 - MAX_JOBS: 4 - run: | - echo "Building PyTorch with Python ${{ matrix.python-version }} in ${{ matrix.build-type }} mode" - - if [ "${{ matrix.build-type }}" = "develop" ]; then - # Development mode (editable install) - python setup.py develop - echo "PyTorch installed in development mode" - else - # Install mode (regular install) - python setup.py install - echo "PyTorch installed regularly" - fi - - - name: Test PyTorch installation - run: | - python -c "import torch; print(f'PyTorch version: {torch.__version__}'); print(f'PyTorch build config: {torch.__config__.show()}')" - python -c "import torch; x = torch.randn(3, 3); y = x @ x.t(); print(f'Matrix multiplication test: {y.shape}')" - - - name: Upload build info - if: success() - uses: actions/upload-artifact@v4 - with: - name: pytorch-build-info-${{ matrix.python-version }}-${{ matrix.build-type }} - path: | - pytorch/build/lib*/torch/__config__.py - pytorch/build/lib*/torch/version.py - retention-days: 30 \ No newline at end of file diff --git a/.github/workflows/build-torch-npu-correct-version.yml b/.github/workflows/build-torch-npu-correct-version.yml deleted file mode 100644 index 359bcf5eca..0000000000 --- a/.github/workflows/build-torch-npu-correct-version.yml +++ /dev/null @@ -1,121 +0,0 @@ -name: Build Torch NPU (Correct Version) - -on: - workflow_dispatch: # Manual trigger only - -jobs: - build-torch-npu: - runs-on: ubuntu-latest - - steps: - - name: Checkout kerer-ai/pytorch - uses: actions/checkout@v4 - with: - path: torch-npu - - - name: Set up Python 3.9 - uses: actions/setup-python@v5 - with: - python-version: "3.9" - - - name: Install basic Python dependencies - run: | - python -m pip install --upgrade pip - pip install wheel setuptools pyyaml auditwheel numpy -i https://mirrors.huaweicloud.com/repository/pypi/simple - - - name: Install correct PyTorch version - run: | - # Install the exact PyTorch version required by torch_npu - echo "Installing PyTorch version: 2.11.0.dev20251215" - pip install torch==2.11.0.dev20251215 --index-url https://download.pytorch.org/whl/nightly/cpu -i https://mirrors.huaweicloud.com/repository/pypi/simple - - - name: Initialize submodules - working-directory: torch-npu - run: | - if [ -f .gitmodules ]; then - git submodule update --init --recursive - fi - - - name: Check build environment - working-directory: torch-npu - run: | - echo "=== Build Environment ===" - echo "Python version: $(python --version)" - echo "Pip version: $(pip --version)" - python -c "import torch; print(f'PyTorch version: {torch.__version__}'); print(f'PyTorch path: {torch.__file__}')" - python -c "import numpy; print(f'NumPy version: {numpy.__version__}')" - - # Check torchgen compatibility - python -c "from torchgen.packaged.autograd.gen_inplace_or_view_type import extract_bindings; print('extract_bindings import successful')" 2>/dev/null || echo "extract_bindings import failed (expected)" - - - name: Try to build with workaround - working-directory: torch-npu - env: - _GLIBCXX_USE_CXX11_ABI: 1 - USE_CUDA: 0 - USE_NUMPY: 1 - BUILD_TEST: 0 - run: | - echo "=== Attempting Build ===" - echo "Note: This build requires CANN environment for Ascend NPU" - - # Create a simple test to check if we can bypass the import error - cat > test_import.py << 'EOF' -import sys -sys.path.insert(0, '.') -try: - # Try to import the problematic module - from torchnpugen.autograd.utils import VERSION_PART - print("Import successful!") -except ImportError as e: - print(f"Import error: {e}") - print("This is expected without CANN environment") -EOF - - python test_import.py - - - name: Check for build artifacts - working-directory: torch-npu - run: | - echo "=== Checking Build Artifacts ===" - if [ -d "build" ]; then - echo "Build directory exists" - find build -type f -name "*.so" -o -name "*.py" | head -10 - else - echo "No build directory found" - fi - - - name: Create comprehensive report - if: always() - run: | - echo "=== Torch NPU Build Analysis ===" > report.md - echo "" >> report.md - echo "## Build Status" >> report.md - echo "- PyTorch Version: 2.11.0.dev20251215 ✓" >> report.md - echo "- Python Environment: 3.9 ✓" >> report.md - echo "- Build Attempted: Yes" >> report.md - echo "- CANN Environment: Missing (Required)" >> report.md - echo "" >> report.md - echo "## Issues Identified" >> report.md - echo "1. **CANN Dependency**: Huawei Ascend NPU software stack required" >> report.md - echo "2. **PyTorch Version**: Requires specific development version" >> report.md - echo "3. **Import Compatibility**: torchgen API changes may cause issues" >> report.md - echo "" >> report.md - echo "## Next Steps for Full Build" >> report.md - echo "1. **Install CANN Toolkit** from Huawei Ascend Community" >> report.md - echo "2. **Set up build environment** with CANN libraries" >> report.md - echo "3. **Use Docker image** with pre-installed CANN (see existing CI)" >> report.md - echo "4. **Check PyTorch compatibility** with torch_npu codebase" >> report.md - echo "" >> report.md - echo "## References" >> report.md - echo "- [Ascend Community](https://www.hiascend.com/en/)" >> report.md - echo "- [CANN Installation](https://www.hiascend.com/cann)" >> report.md - echo "- [Existing CI Configuration](.github/workflows/_build-and-test.yml)" >> report.md - - - name: Upload build report - if: always() - uses: actions/upload-artifact@v4 - with: - name: torch-npu-build-analysis - path: report.md - retention-days: 30 \ No newline at end of file diff --git a/.github/workflows/build-torch-npu-simple.yml b/.github/workflows/build-torch-npu-simple.yml deleted file mode 100644 index 5597a4635f..0000000000 --- a/.github/workflows/build-torch-npu-simple.yml +++ /dev/null @@ -1,103 +0,0 @@ -name: Build Torch NPU (Simple) - -on: - workflow_dispatch: # Manual trigger only - -jobs: - build-torch-npu: - runs-on: ubuntu-latest - - steps: - - name: Checkout kerer-ai/pytorch - uses: actions/checkout@v4 - with: - path: torch-npu - - - name: Set up Python 3.9 - uses: actions/setup-python@v5 - with: - python-version: "3.9" - - - name: Install basic Python dependencies - run: | - python -m pip install --upgrade pip - pip install wheel setuptools pyyaml auditwheel -i https://mirrors.huaweicloud.com/repository/pypi/simple - - - name: Install PyTorch (pre-built) - run: | - # Install a compatible PyTorch version - pip install torch==2.1.0 -i https://mirrors.huaweicloud.com/repository/pypi/simple - - - name: Initialize submodules - working-directory: torch-npu - run: | - if [ -f .gitmodules ]; then - git submodule update --init --recursive - fi - - - name: Check build environment - working-directory: torch-npu - run: | - echo "Python version: $(python --version)" - echo "Pip version: $(pip --version)" - python -c "import torch; print(f'PyTorch version: {torch.__version__}'); print(f'PyTorch path: {torch.__file__}')" - - # Check if setup.py can be parsed - python -m py_compile setup.py - echo "setup.py syntax OK" - - # Check build script - if [ -f ci/build.sh ]; then - bash -n ci/build.sh - echo "Build script syntax OK" - fi - - - name: Attempt build (dry run) - working-directory: torch-npu - env: - _GLIBCXX_USE_CXX11_ABI: 1 - USE_CUDA: 0 - run: | - echo "Attempting to build torch_npu..." - echo "Note: This will likely fail due to missing CANN dependencies" - - # Try to run setup.py in dry-run mode - python setup.py build --dry-run || echo "Dry run completed (may show errors)" - - - name: Check for CANN dependencies - working-directory: torch-npu - run: | - echo "Checking for CANN-related files..." - find . -type f -name "*.py" -exec grep -l "cann\|CANN\|ascend\|Ascend" {} \; | head -10 || true - echo "" - echo "Checking build dependencies in setup.py..." - grep -n "cann\|CANN\|ascend\|Ascend" setup.py | head -10 || true - - - name: Create build report - if: always() - run: | - echo "=== Build Environment Report ===" - echo "OS: $(uname -a)" - echo "Python: $(python --version)" - echo "PyTorch: $(python -c 'import torch; print(torch.__version__)' 2>/dev/null || echo 'Not installed')" - echo "" - echo "=== Next Steps ===" - echo "1. This build requires CANN (Compute Architecture for Neural Networks) environment" - echo "2. CANN is Huawei's software stack for Ascend NPU" - echo "3. For full build, need:" - echo " - CANN toolkit installed" - echo " - Ascend driver installed" - echo " - NPU hardware or emulator" - echo "" - echo "=== Workflow Status ===" > report.md - echo "- PyTorch: Installed" >> report.md - echo "- torch_npu: Requires CANN" >> report.md - echo "- Build: Partial (environment check only)" >> report.md - - - name: Upload build report - if: always() - uses: actions/upload-artifact@v4 - with: - name: torch-npu-build-report - path: report.md - retention-days: 7 \ No newline at end of file diff --git a/.github/workflows/build-torch-npu.yml b/.github/workflows/build-torch-npu.yml deleted file mode 100644 index a9fd381e62..0000000000 --- a/.github/workflows/build-torch-npu.yml +++ /dev/null @@ -1,118 +0,0 @@ -name: Build Torch NPU Extension - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - workflow_dispatch: # Allow manual triggering - -jobs: - build-torch-npu: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.8", "3.9", "3.10"] - - steps: - - name: Checkout kerer-ai/pytorch - uses: actions/checkout@v4 - with: - path: torch-npu - - - name: Checkout PyTorch - uses: actions/checkout@v4 - with: - repository: pytorch/pytorch - path: pytorch - ref: main - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - - name: Install system dependencies - run: | - sudo apt-get update - sudo apt-get install -y \ - cmake \ - ninja-build \ - g++ \ - git \ - libopenblas-dev \ - libopenmpi-dev \ - openmpi-bin \ - openmpi-common \ - libgomp1 \ - libnuma-dev - - - name: Install Python dependencies - run: | - python -m pip install --upgrade pip - pip install wheel setuptools - # 使用华为云镜像源安装依赖 - pip install pyyaml setuptools auditwheel -i https://mirrors.huaweicloud.com/repository/pypi/simple - - - name: Build PyTorch - working-directory: pytorch - env: - USE_CUDA: 0 - USE_CUDNN: 0 - USE_MKLDNN: 0 - USE_NNPACK: 0 - USE_QNNPACK: 0 - USE_XNNPACK: 0 - USE_DISTRIBUTED: 0 - USE_OPENMP: 1 - USE_FBGEMM: 0 - USE_NUMPY: 1 - BUILD_TEST: 0 - _GLIBCXX_USE_CXX11_ABI: 1 - run: | - # Install PyTorch build dependencies with Huawei Cloud mirror - pip install -r requirements.txt -i https://mirrors.huaweicloud.com/repository/pypi/simple - - # Build PyTorch in development mode - python setup.py develop - - - name: Build torch_npu extension - working-directory: torch-npu - env: - _GLIBCXX_USE_CXX11_ABI: 1 - USE_CUDA: 0 - run: | - # Initialize submodules if needed - if [ -f .gitmodules ]; then - git submodule update --init --recursive - fi - - # Note: This build may fail due to missing CANN (Compute Architecture for Neural Networks) environment - # CANN is required for Ascend NPU support. For full functionality, CANN drivers and libraries are needed. - echo "Warning: Building without CANN environment. This is a limited build for testing purposes only." - - # Build torch_npu - bash ci/build.sh --python=${{ matrix.python-version }} - - - name: Test installation - run: | - # Install the built wheel - wheel_file=$(find torch-npu/dist -name "torch_npu*.whl" | head -1) - if [ -f "$wheel_file" ]; then - pip install "$wheel_file" - echo "torch_npu installed successfully" - - # Basic test - python -c "import torch; import torch_npu; print(f'PyTorch version: {torch.__version__}'); print(f'torch_npu version: {torch_npu.__version__}')" - else - echo "Error: No wheel file found in torch-npu/dist/" - exit 1 - fi - - - name: Upload build artifacts - uses: actions/upload-artifact@v4 - if: success() - with: - name: torch-npu-wheels-${{ matrix.python-version }} - path: torch-npu/dist/*.whl - retention-days: 7 \ No newline at end of file diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml deleted file mode 100644 index 08140faba6..0000000000 --- a/.github/workflows/test-build.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Test Build (Basic) - -on: - workflow_dispatch: # Manual trigger only - -jobs: - test-build: - runs-on: ubuntu-latest - - steps: - - name: Checkout kerer-ai/pytorch - uses: actions/checkout@v4 - with: - path: torch-npu - - - name: Set up Python 3.9 - uses: actions/setup-python@v5 - with: - python-version: "3.9" - - - name: Install basic dependencies - run: | - python -m pip install --upgrade pip - pip install wheel setuptools pyyaml -i https://mirrors.huaweicloud.com/repository/pypi/simple - - - name: Check build script syntax - working-directory: torch-npu - run: | - echo "Checking build script..." - if [ -f ci/build.sh ]; then - bash -n ci/build.sh - echo "Build script syntax OK" - else - echo "Error: ci/build.sh not found" - exit 1 - fi - - - name: Check setup.py - working-directory: torch-npu - run: | - echo "Checking setup.py..." - python -m py_compile setup.py - echo "setup.py syntax OK" - - - name: List project structure - working-directory: torch-npu - run: | - echo "Project structure:" - find . -type f -name "*.py" | head -20 - echo "" - echo "Top-level files:" - ls -la \ No newline at end of file From 73954ee1934e4f409cd215a6e2e7c2a9a1c72015 Mon Sep 17 00:00:00 2001 From: wangsike Date: Fri, 3 Apr 2026 10:12:22 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/npu-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/npu-test.yml b/.github/workflows/npu-test.yml index 3e3dd922b4..632ec343ec 100644 --- a/.github/workflows/npu-test.yml +++ b/.github/workflows/npu-test.yml @@ -16,7 +16,7 @@ jobs: runs-on: linux-aarch64-a3-2 container: image: swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch_2.11.0_a2_aarch64_builder:20260331 - options: --user root --device /dev/davinci4 --device /dev/davinci_manager --device /dev/devmm_svm --device /dev/hisi_hdc -v /usr/local/sbin/npu-smi:/usr/local/sbin/npu-smi -v /usr/local/Ascend/driver:/usr/local/Ascend/driver -v /usr/local/Ascend/firmware:/usr/local/Ascend/firmware -v /usr/local/Ascend/cann:/usr/local/Ascend/cann -v /usr/local/Ascend/nnal:/usr/local/Ascend/nnal + options: --user root -v /usr/local/sbin/npu-smi:/usr/local/sbin/npu-smi env: PYTHON_VERSION: '3.11' DOCKER_IMAGE: swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch_2.11.0_a2_aarch64_builder:20260331 From bf080f70e94ca9e8140d69e193385e5dad62803d Mon Sep 17 00:00:00 2001 From: wangsike Date: Fri, 3 Apr 2026 16:00:19 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/npu-test.yml | 48 +++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/.github/workflows/npu-test.yml b/.github/workflows/npu-test.yml index 632ec343ec..68847ca28d 100644 --- a/.github/workflows/npu-test.yml +++ b/.github/workflows/npu-test.yml @@ -1,8 +1,12 @@ name: NPU Build and Test on: + push: + paths: + - '.github/workflows/npu-test.yml' pull_request: - branches: [ master ] + paths: + - '.github/workflows/npu-test.yml' workflow_dispatch: inputs: torch_nightly_date: @@ -16,7 +20,7 @@ jobs: runs-on: linux-aarch64-a3-2 container: image: swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch_2.11.0_a2_aarch64_builder:20260331 - options: --user root -v /usr/local/sbin/npu-smi:/usr/local/sbin/npu-smi + options: --user root env: PYTHON_VERSION: '3.11' DOCKER_IMAGE: swr.cn-north-4.myhuaweicloud.com/frameworkptadapter/pytorch_2.11.0_a2_aarch64_builder:20260331 @@ -30,26 +34,23 @@ jobs: - name: Setup cache directories run: | - mkdir -p ~/.cache/pip - mkdir -p ~/.cache/ccache - chmod -R 777 ~/.cache + mkdir -p /github/home/.cache/pip + mkdir -p /github/home/.cache/ccache + chmod -R 777 /github/home/.cache + + - name: Install ccache + run: | + yum install -y ccache + ccache --version - name: Cache pip uses: actions/cache@v4 with: - path: ~/.cache/pip + path: /github/home/.cache/pip key: pip-arm-py${{ env.PYTHON_VERSION }}-build-test restore-keys: | pip-arm-py${{ env.PYTHON_VERSION }}- - - name: Cache ccache - uses: actions/cache@v4 - with: - path: ~/.cache/ccache - key: ccache-arm-py${{ env.PYTHON_VERSION }}-${{ github.run_id }} - restore-keys: | - ccache-arm-py${{ env.PYTHON_VERSION }}- - - name: Uninstall pre-installed packages run: | pip${{ env.PYTHON_VERSION }} uninstall -y torch torchvision pyyaml setuptools auditwheel || true @@ -61,7 +62,7 @@ jobs: PIP=pip${{ env.PYTHON_VERSION }} PYTHON=python${{ env.PYTHON_VERSION }} - export PIP_CACHE_DIR=~/.cache/pip + export PIP_CACHE_DIR=/github/home/.cache/pip $PIP install --upgrade pip # 安装基础依赖 @@ -79,6 +80,14 @@ jobs: echo "version=${TORCH_VER}" >> $GITHUB_OUTPUT echo "PyTorch nightly version: ${TORCH_VER}" + - name: Cache ccache + uses: actions/cache@v4 + with: + path: /github/home/.cache/ccache + key: ccache-arm-py${{ env.PYTHON_VERSION }}-torch${{ steps.install_torch.outputs.version }}-${{ github.sha }} + restore-keys: | + ccache-arm-py${{ env.PYTHON_VERSION }}-torch${{ steps.install_torch.outputs.version }}- + - name: Build torch_npu wheel id: build run: | @@ -91,7 +100,7 @@ jobs: ccache -z || true export CC="ccache gcc" export CXX="ccache g++" - export CCACHE_DIR=~/.cache/ccache + export CCACHE_DIR=/github/home/.cache/ccache export CCACHE_COMPRESS=1 export CCACHE_MAXSIZE=10G export CCACHE_BASEDIR="${PWD}" @@ -110,9 +119,9 @@ jobs: bash ci/build.sh --python=${{ env.PYTHON_VERSION }} 2>&1 | tee /tmp/build.log BUILD_STATUS=${PIPESTATUS[0]} - # ccache 统计 + # ccache 统计(兼容 ccache 3.x/4.x 格式) if [ "${USE_CCACHE}" = "1" ]; then - CCACHE_STATS=$(ccache -s | grep -E "^(Hits|Misses|Cache size)" | tr '\n' ' ') + CCACHE_STATS=$(ccache -s | grep -E "cache hit|cache miss|cache size|hit rate" | tr '\n' ' ') echo "ccache_stats=${CCACHE_STATS}" >> $GITHUB_OUTPUT ccache -s fi @@ -157,9 +166,6 @@ jobs: PYTHON=python${{ env.PYTHON_VERSION }} PIP=pip${{ env.PYTHON_VERSION }} - # 安装 pytest - $PIP install pytest pytest-xdist - cd test $PYTHON -m pytest npu/test_device.py -v 2>&1 | tee /tmp/test.log From 068a8a753a1f7821b0cc8abafc9e109f6d68067c Mon Sep 17 00:00:00 2001 From: wangsike Date: Fri, 3 Apr 2026 16:38:09 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9CPU=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/npu-test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/npu-test.yml b/.github/workflows/npu-test.yml index 68847ca28d..7aa0ada41b 100644 --- a/.github/workflows/npu-test.yml +++ b/.github/workflows/npu-test.yml @@ -111,7 +111,9 @@ jobs: fi # 构建参数 - export MAX_JOBS=$(nproc) + echo "nproc value: $(nproc)" + echo "MAX_JOBS: 40" + export MAX_JOBS=40 export DISABLE_INSTALL_TORCHAIR=FALSE export BUILD_WITHOUT_SHA=1 From 7b8154dd06cc2ea160f0b3085da7a02540f70571 Mon Sep 17 00:00:00 2001 From: wangsike Date: Fri, 3 Apr 2026 18:04:04 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=AF=BC=E8=87=B4=E7=9A=84=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/npu-test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/npu-test.yml b/.github/workflows/npu-test.yml index 7aa0ada41b..ffb91aa604 100644 --- a/.github/workflows/npu-test.yml +++ b/.github/workflows/npu-test.yml @@ -155,6 +155,8 @@ jobs: source /usr/local/Ascend/nnal/atb/set_env.sh 2>/dev/null || true PYTHON=python${{ env.PYTHON_VERSION }} + # 切换到项目根目录的上一级,避免从源码目录加载 torch_npu + cd .. echo "=== Testing torch_npu import ===" $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()}'); print(f'NPU name: {torch.npu.get_device_name(0) if torch.npu.is_available() else \"N/A\"}')" @@ -168,6 +170,7 @@ jobs: PYTHON=python${{ env.PYTHON_VERSION }} PIP=pip${{ env.PYTHON_VERSION }} + # 步骤开始时自动回到项目根目录,进入 test 目录执行测试 cd test $PYTHON -m pytest npu/test_device.py -v 2>&1 | tee /tmp/test.log