Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 194 additions & 0 deletions .github/workflows/nightly-build-arm.yml
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading