From 69426a9d690ae9b095a4671a57c83a9355d9d586 Mon Sep 17 00:00:00 2001 From: wangsike Date: Wed, 6 May 2026 22:16:16 +0800 Subject: [PATCH 01/10] [ci] add nightly build workflow and refactor build/test separation - Refactor _build.yml: fix git proxy redundancy, remove duplicate pip upgrades, add warning for CANN env failures, use $HOME instead of hardcoded paths - Add _test.yml: reusable test workflow with NPU verification and smoke test - Add nightly.yml: main workflow with schedule, PR trigger, and manual dispatch Co-Authored-By: Claude Opus 4.6 --- .github/workflows/_build.yml | 412 +++++++++++++++++++++++++++------- .github/workflows/_test.yml | 167 ++++++++++++++ .github/workflows/nightly.yml | 125 +++++++++++ 3 files changed, 624 insertions(+), 80 deletions(-) create mode 100644 .github/workflows/_test.yml create mode 100644 .github/workflows/nightly.yml diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml index 55a0b52dcf..72bdb40397 100644 --- a/.github/workflows/_build.yml +++ b/.github/workflows/_build.yml @@ -1,106 +1,358 @@ -name: Build PyTorch and torch_npu +name: Build PyTorch and torch_npu (with cache) on: workflow_call: inputs: - upstream_repo: + pytorch_branch: required: true type: string - description: The upstream repository full name (owner/repo) - upstream_sha: + default: 'main' + python_version: required: true type: string - description: The upstream commit SHA to build - upstream_fork_repo: - required: false - type: string - default: '' - description: The fork repository full name for PR from fork (owner/repo) - downstream_repo: + default: '3.11' + docker_image_tag: required: true type: string - description: The downstream repository full name (owner/repo) + description: 'Docker image tag with timestamp' + outputs: + docker-image: + description: 'Full Docker image URL' + value: ${{ jobs.build.outputs.docker-image }} + torch-wheel: + description: 'PyTorch wheel artifact name' + value: 'torch-wheel-main' + torch-npu-wheel: + description: 'torch_npu wheel artifact name' + value: 'torch-npu-wheel-main' + test-src: + description: 'Test source artifact name' + value: 'test-src-main' + +env: + # 缓存版本号,当需要强制刷新缓存时修改此值 + CACHE_VERSION: 'v2' + # GitHub 代理 URL(用于加速 git clone,留空则不使用代理) + GH_PROXY_URL: 'https://gh-proxy.test.osinfra.cn' + # PyPI 缓存 URL(用于加速 pip 下载) + PYPI_CACHE_URL: 'http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple' jobs: build: - runs-on: ubuntu-latest + runs-on: linux-aarch64-a3-16 + timeout-minutes: 240 + outputs: + docker-image: ${{ steps.set_image.outputs.docker-image }} + + container: + image: quay.io/kerer/pytorch:${{ inputs.docker_image_tag }} + options: --user root + 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) - - 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 - path: pytorch + - name: Set Docker image URL + id: set_image + run: | + DOCKER_IMAGE="quay.io/kerer/pytorch:${{ inputs.docker_image_tag }}" + echo "docker-image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT + echo "Using Docker image: ${DOCKER_IMAGE}" + + - name: Setup CANN environment + run: | + if ! source /usr/local/Ascend/cann/set_env.sh 2>/dev/null; then + echo "::warning::Failed to source CANN environment script" + fi + if ! source /usr/local/Ascend/nnal/atb/set_env.sh 2>/dev/null; then + echo "::warning::Failed to source ATB environment script" + fi - # Step 2: Build PyTorch - - name: Build PyTorch + - name: Configure git proxy for faster clone run: | - echo "============================================" - echo "Building PyTorch from upstream PR..." - if [ -n "${{ inputs.upstream_fork_repo }}" ]; then - echo "Fork Repository: ${{ inputs.upstream_fork_repo }}" + # 配置 git URL rewrite 来使用代理(加速 clone 和 submodules) + if [ -n "${{ env.GH_PROXY_URL }}" ]; then + git config --global url."${{ env.GH_PROXY_URL }}/https://github.com/".insteadOf "https://github.com/" + git config --global url."${{ env.GH_PROXY_URL }}/https://gitlab.com/".insteadOf "https://gitlab.com/" + echo "Git proxy configured:" + git config --global --list | grep url else - echo "Repository: ${{ inputs.upstream_repo }}" + echo "No proxy configured, using direct connection" fi - echo "Commit SHA: ${{ inputs.upstream_sha }}" - 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 + + - name: Clone upstream PyTorch with submodules + id: clone_pytorch 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 - - name: Checkout downstream repo (torch_npu) - uses: actions/checkout@v6 + # --recurse-submodules 同时下载所有 submodules(使用已配置的 git proxy) + git clone --depth=1 --recurse-submodules --branch ${{ inputs.pytorch_branch }} \ + "https://github.com/pytorch/pytorch.git" pytorch-src + PYTORCH_SHA=$(cd pytorch-src && git rev-parse HEAD) + echo "pytorch_sha=${PYTORCH_SHA}" >> $GITHUB_OUTPUT + echo "Cloned PyTorch commit: ${PYTORCH_SHA}" + echo "Submodules downloaded:" + ls -la pytorch-src/third_party/ | head -20 + + - name: Checkout torch_npu + uses: actions/checkout@v4 with: - repository: ${{ inputs.downstream_repo }} - ref: master + path: torch_npu-src submodules: recursive - path: torch_npu - # Step 5: Build torch_npu - - name: Build torch_npu + # ==================== pip 缓存配置 ==================== + # pip 缓存加速依赖下载,不影响构建结果 + # 缓存键基于 requirements-build.txt hash(依赖变化频率低) + - name: Get pip cache key + id: pip_key + run: | + REQUIREMENTS_HASH=$(cd pytorch-src && sha256sum requirements-build.txt | cut -d' ' -f1) + echo "cache_key=${{ env.CACHE_VERSION }}-pip-${{ inputs.python_version }}-${REQUIREMENTS_HASH}" >> $GITHUB_OUTPUT + + - name: Restore pip cache + uses: actions/cache/restore@v4 + with: + path: $HOME/.cache/pip + key: ${{ steps.pip_key.outputs.cache_key }} + restore-keys: | + ${{ env.CACHE_VERSION }}-pip-${{ inputs.python_version }}- + ${{ env.CACHE_VERSION }}-pip- + + - name: Setup pip cache directory and upgrade pip run: | - echo "============================================" - echo "Building torch_npu from downstream master..." - echo "Repository: ${{ inputs.downstream_repo }}" - echo "Branch: master" - 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!" - - - name: Summary + mkdir -p "$HOME/.cache/pip" + # 升级 pip 和 setuptools,避免旧版包兼容性问题 + pip${{ inputs.python_version }} install --upgrade pip setuptools wheel + + - name: Configure pip index URL run: | - echo "============================================" - echo "Build Summary" - echo "============================================" - if [ -n "${{ inputs.upstream_fork_repo }}" ]; then - echo "1. PyTorch fork PR: ${{ inputs.upstream_fork_repo }}@${{ inputs.upstream_sha }}" + # 配置 pip 使用 PyPI 缓存加速下载 + if [ -n "${{ env.PYPI_CACHE_URL }}" ]; then + pip${{ inputs.python_version }} config set global.index-url ${{ env.PYPI_CACHE_URL }} + pip${{ inputs.python_version }} config set global.trusted-host "cache-service.nginx-pypi-cache.svc.cluster.local" + echo "pip index-url configured: ${{ env.PYPI_CACHE_URL }}" else - echo "1. PyTorch upstream: ${{ inputs.upstream_repo }}@${{ inputs.upstream_sha }}" + echo "No PyPI cache URL configured, using default" + fi + + # ==================== ccache 缓存配置 ==================== + # ccache 是真正加速编译的关键(可节省 30-60 分钟) + # 我们依赖 torch_npu SHA 和 requirements-build.txt hash 作为缓存键 + - name: Get ccache key + id: ccache_key + run: | + # ccache 缓存键:torch_npu SHA + requirements hash + # PyTorch SHA 每次都变化(--depth=1 clone 最新),所以不包含在缓存键中 + TORCH_NPU_SHA=$(cd torch_npu-src && git rev-parse HEAD) + REQUIREMENTS_HASH=$(cd pytorch-src && sha256sum requirements-build.txt | cut -d' ' -f1) + echo "cache_key=${{ env.CACHE_VERSION }}-ccache-${REQUIREMENTS_HASH}-${TORCH_NPU_SHA}" >> $GITHUB_OUTPUT + # partial_key 用于恢复同版本 requirements 的缓存(不同 torch_npu 版本) + echo "partial_key=${{ env.CACHE_VERSION }}-ccache-${REQUIREMENTS_HASH}-" >> $GITHUB_OUTPUT + # base_key 用于恢复同 CACHE_VERSION 的所有缓存 + echo "base_key=${{ env.CACHE_VERSION }}-ccache-" >> $GITHUB_OUTPUT + + - name: Restore ccache + uses: actions/cache/restore@v4 + with: + path: $HOME/.cache/ccache + key: ${{ steps.ccache_key.outputs.cache_key }} + restore-keys: | + ${{ steps.ccache_key.outputs.partial_key }} + ${{ steps.ccache_key.outputs.base_key }} + + - name: Setup ccache + run: | + # 安装 ccache(manylinux 镜像没有预装) + yum install -y ccache + + # 创建 ccache 配置目录(使用 $HOME 变量) + CCACHE_DIR_PATH="$HOME/.cache/ccache" + mkdir -p "$CCACHE_DIR_PATH" + + # 直接写入配置文件(使用 $HOME 变量) + cat > "$CCACHE_DIR_PATH/ccache.conf" << EOF + max_size = 20G + cache_dir = $HOME/.cache/ccache + compression = true + compression_level = 6 + EOF + + # 使用符号链接方式让 ccache 模拟 gcc/g++ + mkdir -p /usr/local/bin + ln -sf /usr/bin/ccache /usr/local/bin/gcc + ln -sf /usr/bin/ccache /usr/local/bin/g++ + ln -sf /usr/bin/ccache /usr/local/bin/cc + ln -sf /usr/bin/ccache /usr/local/bin/c++ + + # 设置 PATH 优先使用符号链接 + echo "PATH=/usr/local/bin:$PATH" >> $GITHUB_ENV + + # 设置 CCACHE_DIR(使用 $HOME 变量) + echo "CCACHE_DIR=$CCACHE_DIR_PATH" >> $GITHUB_ENV + + # 设置编译器环境变量,确保 CMake/Ninja 使用 ccache + echo "CC=/usr/local/bin/gcc" >> $GITHUB_ENV + echo "CXX=/usr/local/bin/g++" >> $GITHUB_ENV + + echo "=== ccache Configuration ===" + CCACHE_DIR="$CCACHE_DIR_PATH" ccache --show-config + + echo "" + echo "=== Config File Contents ===" + cat "$CCACHE_DIR_PATH/ccache.conf" + + echo "" + echo "=== Cache Directory ===" + ls -la "$CCACHE_DIR_PATH/" + + echo "" + echo "=== Symbolic Links ===" + ls -la /usr/local/bin/gcc /usr/local/bin/g++ + + echo "" + echo "=== ccache Statistics (before build) ===" + CCACHE_DIR="$CCACHE_DIR_PATH" ccache --show-stats + + # ==================== 构建 PyTorch ==================== + - name: Build PyTorch wheel + run: | + if ! source /usr/local/Ascend/cann/set_env.sh 2>/dev/null; then + echo "::warning::Failed to source CANN environment script" 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 + + cd pytorch-src + + # 安装构建依赖(pip 缓存已恢复,加速下载) + pip${{ inputs.python_version }} install -r requirements-build.txt + + # 设置构建环境变量 + export MAX_JOBS=128 + export USE_CUDA=0 + export USE_CUDNN=0 + export USE_DISTRIBUTED=1 + export CMAKE_BUILD_TYPE=Release + export USE_OPENMP=1 + export USE_MKLDNN=0 + + # 确保使用 ccache(CMake 会检测 CC/CXX 环境变量) + export CC=/usr/local/bin/gcc + export CXX=/usr/local/bin/g++ + export CCACHE_DIR="$HOME/.cache/ccache" + + # 清除 ccache 统计(开始新的构建) + ccache --zero-stats + + python${{ inputs.python_version }} setup.py build bdist_wheel + + echo "PyTorch wheel built:" + ls -la dist/ + + echo "" + echo "=== ccache Statistics (after PyTorch build) ===" + ccache --show-stats + + # ==================== 构建 torch_npu ==================== + - name: Install PyTorch wheel and build dependencies + run: | + if ! source /usr/local/Ascend/cann/set_env.sh 2>/dev/null; then + echo "::warning::Failed to source CANN environment script" + fi + if ! source /usr/local/Ascend/nnal/atb/set_env.sh 2>/dev/null; then + echo "::warning::Failed to source ATB environment script" + fi + + echo "=== Installing built PyTorch wheel ===" + pip${{ inputs.python_version }} install pytorch-src/dist/*.whl + + echo "" + echo "=== Verifying PyTorch installation ===" + python${{ inputs.python_version }} -c "import torch; print(f'torch version: {torch.__version__}')" + + echo "" + echo "=== Installing torch_npu build dependencies ===" + pip${{ inputs.python_version }} install cmake ninja numpy packaging pyyaml requests six typing-extensions + + cd torch_npu-src + + # 显示 ccache 统计(依赖安装阶段) + echo "" + echo "=== ccache Statistics (before torch_npu build) ===" + CCACHE_DIR="$HOME/.cache/ccache" ccache --show-stats + + - name: Build torch_npu wheel + run: | + if ! source /usr/local/Ascend/cann/set_env.sh 2>/dev/null; then + echo "::warning::Failed to source CANN environment script" + fi + if ! source /usr/local/Ascend/nnal/atb/set_env.sh 2>/dev/null; then + echo "::warning::Failed to source ATB environment script" + fi + + cd torch_npu-src + + export MAX_JOBS=128 + + # 确保使用 ccache + export CC=/usr/local/bin/gcc + export CXX=/usr/local/bin/g++ + export CCACHE_DIR="$HOME/.cache/ccache" + + # 禁用 torchair 构建(上游 PyTorch main API 变化导致兼容性问题) + bash ci/build.sh --python=${{ inputs.python_version }} --disable_torchair + + echo "torch_npu wheel built:" + ls -la dist/ + + echo "" + echo "=== ccache Statistics (after torch_npu build) ===" + ccache --show-stats + + # ==================== 保存缓存 ==================== + - name: Save pip cache + if: always() + uses: actions/cache/save@v4 + with: + path: $HOME/.cache/pip + key: ${{ steps.pip_key.outputs.cache_key }} + + - name: Save ccache + if: always() + uses: actions/cache/save@v4 + with: + path: $HOME/.cache/ccache + key: ${{ steps.ccache_key.outputs.cache_key }} + + - name: Display cache save status + if: always() + run: | + echo "=== Cache Saved ===" + echo "pip cache key: ${{ steps.pip_key.outputs.cache_key }}" + PIP_CACHE_SIZE=$(du -sh "$HOME/.cache/pip" 2>/dev/null | cut -f1) + echo "pip cache size: ${PIP_CACHE_SIZE}" + echo "" + echo "ccache key: ${{ steps.ccache_key.outputs.cache_key }}" + CCACHE_SIZE=$(du -sh "$HOME/.cache/ccache" 2>/dev/null | cut -f1) + echo "ccache size: ${CCACHE_SIZE}" + + # ==================== 打包和上传 ==================== + - name: Package test source + run: | + # 只打包测试目录,不需要整个 PyTorch 源码 + tar -czf test-src.tar.gz pytorch-src/test + ls -la test-src.tar.gz + + - name: Upload PyTorch wheel + uses: actions/upload-artifact@v4 + with: + name: torch-wheel-main + path: pytorch-src/dist/*.whl + retention-days: 7 + + - name: Upload torch_npu wheel + uses: actions/upload-artifact@v4 + with: + name: torch-npu-wheel-main + path: torch_npu-src/dist/*.whl + retention-days: 7 + + - name: Upload test source + uses: actions/upload-artifact@v4 + with: + name: test-src-main + path: test-src.tar.gz + retention-days: 7 \ No newline at end of file diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml new file mode 100644 index 0000000000..996695bd18 --- /dev/null +++ b/.github/workflows/_test.yml @@ -0,0 +1,167 @@ +name: Test torch_npu wheels + +on: + workflow_call: + inputs: + python_version: + required: true + type: string + default: '3.11' + docker_image_tag: + required: true + type: string + description: 'Docker image tag (same as build)' + outputs: + test-result: + description: 'Test result (success/failure)' + value: ${{ jobs.test.outputs.result }} + +env: + PYTHON_VERSION: ${{ inputs.python_version }} + +jobs: + test: + runs-on: linux-aarch64-a3-16 + timeout-minutes: 30 + outputs: + result: ${{ steps.final_status.outputs.result }} + + container: + image: quay.io/kerer/pytorch:${{ inputs.docker_image_tag }} + options: --user root + + steps: + - name: Download PyTorch wheel + uses: actions/download-artifact@v4 + with: + name: torch-wheel-main + path: wheels/ + + - name: Download torch_npu wheel + uses: actions/download-artifact@v4 + with: + name: torch-npu-wheel-main + path: wheels/ + + - name: Display downloaded wheels + run: | + echo "=== Downloaded wheels ===" + ls -la wheels/ + + - name: Install built wheels + run: | + PYTHON=python${{ env.PYTHON_VERSION }} + + echo "=== Installing PyTorch wheel ===" + pip${{ env.PYTHON_VERSION }} install wheels/torch-*.whl --force-reinstall + + echo "" + echo "=== Installing torch_npu wheel ===" + pip${{ env.PYTHON_VERSION }} install wheels/torch_npu-*.whl --force-reinstall + + echo "" + echo "=== Installed packages ===" + pip${{ env.PYTHON_VERSION }} list | grep -E "torch|torch_npu" + + - name: Verify NPU availability + continue-on-error: true + run: | + # 切换到 /tmp 目录,避免源码目录干扰 torch 导入 + cd /tmp + + echo "=== CANN Directory Contents ===" + ls -la /usr/local/Ascend/ || echo "Ascend directory not found" + echo "" + echo "=== CANN Version Info ===" + if [ -d /usr/local/Ascend/cann ]; then + ls -la /usr/local/Ascend/cann/ + echo "" + echo "=== CANN Version File ===" + cat /usr/local/Ascend/cann/version.info 2>/dev/null || echo "version.info not found" + else + echo "CANN directory not found" + fi + echo "" + echo "=== NNAL Directory Contents ===" + if [ -d /usr/local/Ascend/nnal ]; then + ls -la /usr/local/Ascend/nnal/ + else + echo "NNAL directory not found" + fi + + 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 "" + echo "=== NPU-SMI Info ===" + npu-smi info || echo "npu-smi not available" + + PYTHON=python${{ env.PYTHON_VERSION }} + echo "" + echo "=== PyTorch and NPU Info ===" + $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()}') + if torch.npu.is_available(): + print(f'NPU name: {torch.npu.get_device_name(0)}') + print(f'NPU capability: {torch.npu.get_device_capability(0)}') + " 2>&1 || echo "torch/torch_npu import failed - this is expected if torch and torch_npu versions are mismatched" + + - name: Run basic smoke test + id: smoke_test + run: | + cd /tmp + + 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 "=== Running smoke test ===" + $PYTHON << 'EOF' + import torch + import torch_npu + + print(f"torch version: {torch.__version__}") + print(f"torch_npu version: {torch_npu.__version__}") + + # Basic tensor operations + x = torch.randn(2, 3) + print(f"Tensor created on CPU: {x.device}") + + # Move to NPU if available + if torch.npu.is_available(): + try: + x_npu = x.npu() + print(f"Tensor moved to NPU: {x_npu.device}") + y = torch.randn(2, 3).npu() + z = x_npu + y + print(f"Addition result shape: {z.shape}") + print(f"Result device: {z.device}") + print("Smoke test PASSED") + except Exception as e: + print(f"NPU operation failed: {e}") + print("Smoke test FAILED") + exit(1) + else: + print("NPU not available, smoke test SKIPPED (CPU only)") + EOF + + echo "smoke_result=passed" >> $GITHUB_OUTPUT + + - name: Set final status + id: final_status + if: always() + run: | + if [ "${{ steps.smoke_test.outputs.smoke_result }}" == "passed" ]; then + echo "result=success" >> $GITHUB_OUTPUT + echo "::notice::All tests passed" + else + echo "result=failure" >> $GITHUB_OUTPUT + echo "::error::Tests failed" + exit 1 + fi \ No newline at end of file diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 0000000000..54a102ec4f --- /dev/null +++ b/.github/workflows/nightly.yml @@ -0,0 +1,125 @@ +name: Nightly Build Integration + +on: + schedule: + # 每天凌晨 2:00 UTC+8 运行 (UTC 18:00) + - cron: '0 18 * * *' + pull_request: + branches: + - master + - master_nightly_build + paths: + - '.github/workflows/_build.yml' + - '.github/workflows/_test.yml' + - '.github/workflows/nightly.yml' + - 'ci/build.sh' + workflow_dispatch: + inputs: + pytorch_branch: + description: 'PyTorch branch to build' + required: true + type: string + default: 'main' + python_version: + description: 'Python version' + required: true + type: choice + options: + - '3.11' + - '3.10' + - '3.9' + - '3.8' + default: '3.11' + skip_build: + description: 'Skip build (use cached artifacts)' + required: false + type: boolean + default: false + +env: + # Docker 镜像仓库 + DOCKER_REGISTRY: 'quay.io/kerer/pytorch' + +jobs: + # ==================== 编译阶段 ==================== + build: + name: Build PyTorch and torch_npu + if: ${{ inputs.skip_build != true }} + uses: ./.github/workflows/_build.yml + with: + pytorch_branch: ${{ inputs.pytorch_branch || 'main' }} + python_version: ${{ inputs.python_version || '3.11' }} + docker_image_tag: ${{ github.event_name == 'schedule' && 'nightly-latest' || format('nightly-{0}', github.run_number) }} + + # ==================== 测试阶段 ==================== + test: + name: Test torch_npu wheels + needs: build + if: always() && needs.build.result == 'success' + uses: ./.github/workflows/_test.yml + with: + python_version: ${{ inputs.python_version || '3.11' }} + docker_image_tag: ${{ github.event_name == 'schedule' && 'nightly-latest' || format('nightly-{0}', github.run_number) }} + + # ==================== 报告阶段 ==================== + report: + name: Build Report + needs: [build, test] + if: always() + runs-on: ubuntu-latest + + steps: + - name: Generate build report + run: | + echo "## Nightly Build Report" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "| Item | Status |" >> $GITHUB_STEP_SUMMARY + echo "|------|--------|" >> $GITHUB_STEP_SUMMARY + echo "| Build | ${BUILD_STATUS} |" >> $GITHUB_STEP_SUMMARY + echo "| Test | ${TEST_STATUS} |" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "**Configuration:**" >> $GITHUB_STEP_SUMMARY + echo "- PyTorch branch: ${PYTORCH_BRANCH}" >> $GITHUB_STEP_SUMMARY + echo "- Python version: ${PYTHON_VERSION}" >> $GITHUB_STEP_SUMMARY + echo "- Docker image tag: ${DOCKER_TAG}" >> $GITHUB_STEP_SUMMARY + echo "- Trigger: ${TRIGGER_TYPE}" >> $GITHUB_STEP_SUMMARY + echo "- Run number: ${RUN_NUMBER}" >> $GITHUB_STEP_SUMMARY + env: + BUILD_STATUS: ${{ needs.build.result == 'success' && '✅ Success' || needs.build.result == 'skipped' && '⏭️ Skipped' || '❌ Failed' }} + TEST_STATUS: ${{ needs.test.result == 'success' && '✅ Success' || needs.test.result == 'skipped' && '⏭️ Skipped' || '❌ Failed' }} + PYTORCH_BRANCH: ${{ inputs.pytorch_branch || 'main' }} + PYTHON_VERSION: ${{ inputs.python_version || '3.11' }} + DOCKER_TAG: ${{ github.event_name == 'schedule' && 'nightly-latest' || format('nightly-{0}', github.run_number) }} + TRIGGER_TYPE: ${{ github.event_name }} + RUN_NUMBER: ${{ github.run_number }} + + - name: Check overall status + run: | + BUILD_RESULT="${{ needs.build.result }}" + TEST_RESULT="${{ needs.test.result }}" + + # Build skipped is OK when skip_build is true + BUILD_OK=false + if [[ "$BUILD_RESULT" == "skipped" && "${{ inputs.skip_build }}" == "true" ]]; then + BUILD_OK=true + elif [[ "$BUILD_RESULT" == "success" ]]; then + BUILD_OK=true + fi + + # Test must succeed (or be skipped when build was skipped) + TEST_OK=false + if [[ "$TEST_RESULT" == "success" ]]; then + TEST_OK=true + elif [[ "$BUILD_RESULT" == "skipped" && "$TEST_RESULT" == "skipped" ]]; then + TEST_OK=true + fi + + if [[ "$BUILD_OK" == true && "$TEST_OK" == true ]]; then + echo "Overall status: PASSED ✅" + exit 0 + else + echo "Overall status: FAILED ❌" + echo "Build result: $BUILD_RESULT" + echo "Test result: $TEST_RESULT" + exit 1 + fi \ No newline at end of file From e089d6cb1be80762bf3cf7bdcab9c6def9dc4eb7 Mon Sep 17 00:00:00 2001 From: wangsike Date: Wed, 6 May 2026 22:23:33 +0800 Subject: [PATCH 02/10] [ci] fix cache path variable resolution - Add PIP_CACHE_DIR and CCACHE_DIR env variables - Replace $HOME references with ${{ env.* }} for proper variable expansion - actions/cache does not expand shell variables in 'with' parameters Co-Authored-By: Claude Opus 4.6 --- .github/workflows/_build.yml | 46 +++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml index 72bdb40397..2fa8326180 100644 --- a/.github/workflows/_build.yml +++ b/.github/workflows/_build.yml @@ -36,6 +36,9 @@ env: GH_PROXY_URL: 'https://gh-proxy.test.osinfra.cn' # PyPI 缓存 URL(用于加速 pip 下载) PYPI_CACHE_URL: 'http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple' + # 缓存目录(container 中 HOME 为 /root) + PIP_CACHE_DIR: '/root/.cache/pip' + CCACHE_DIR: '/root/.cache/ccache' jobs: build: @@ -107,7 +110,7 @@ jobs: - name: Restore pip cache uses: actions/cache/restore@v4 with: - path: $HOME/.cache/pip + path: ${{ env.PIP_CACHE_DIR }} key: ${{ steps.pip_key.outputs.cache_key }} restore-keys: | ${{ env.CACHE_VERSION }}-pip-${{ inputs.python_version }}- @@ -115,7 +118,7 @@ jobs: - name: Setup pip cache directory and upgrade pip run: | - mkdir -p "$HOME/.cache/pip" + mkdir -p "${{ env.PIP_CACHE_DIR }}" # 升级 pip 和 setuptools,避免旧版包兼容性问题 pip${{ inputs.python_version }} install --upgrade pip setuptools wheel @@ -149,7 +152,7 @@ jobs: - name: Restore ccache uses: actions/cache/restore@v4 with: - path: $HOME/.cache/ccache + path: ${{ env.CCACHE_DIR }} key: ${{ steps.ccache_key.outputs.cache_key }} restore-keys: | ${{ steps.ccache_key.outputs.partial_key }} @@ -160,14 +163,13 @@ jobs: # 安装 ccache(manylinux 镜像没有预装) yum install -y ccache - # 创建 ccache 配置目录(使用 $HOME 变量) - CCACHE_DIR_PATH="$HOME/.cache/ccache" - mkdir -p "$CCACHE_DIR_PATH" + # 创建 ccache 配置目录 + mkdir -p "${{ env.CCACHE_DIR }}" - # 直接写入配置文件(使用 $HOME 变量) - cat > "$CCACHE_DIR_PATH/ccache.conf" << EOF + # 直接写入配置文件 + cat > "${{ env.CCACHE_DIR }}/ccache.conf" << EOF max_size = 20G - cache_dir = $HOME/.cache/ccache + cache_dir = ${{ env.CCACHE_DIR }} compression = true compression_level = 6 EOF @@ -182,23 +184,23 @@ jobs: # 设置 PATH 优先使用符号链接 echo "PATH=/usr/local/bin:$PATH" >> $GITHUB_ENV - # 设置 CCACHE_DIR(使用 $HOME 变量) - echo "CCACHE_DIR=$CCACHE_DIR_PATH" >> $GITHUB_ENV + # 设置 CCACHE_DIR + echo "CCACHE_DIR=${{ env.CCACHE_DIR }}" >> $GITHUB_ENV # 设置编译器环境变量,确保 CMake/Ninja 使用 ccache echo "CC=/usr/local/bin/gcc" >> $GITHUB_ENV echo "CXX=/usr/local/bin/g++" >> $GITHUB_ENV echo "=== ccache Configuration ===" - CCACHE_DIR="$CCACHE_DIR_PATH" ccache --show-config + ccache --show-config echo "" echo "=== Config File Contents ===" - cat "$CCACHE_DIR_PATH/ccache.conf" + cat "${{ env.CCACHE_DIR }}/ccache.conf" echo "" echo "=== Cache Directory ===" - ls -la "$CCACHE_DIR_PATH/" + ls -la "${{ env.CCACHE_DIR }}/" echo "" echo "=== Symbolic Links ===" @@ -206,7 +208,7 @@ jobs: echo "" echo "=== ccache Statistics (before build) ===" - CCACHE_DIR="$CCACHE_DIR_PATH" ccache --show-stats + ccache --show-stats # ==================== 构建 PyTorch ==================== - name: Build PyTorch wheel @@ -232,7 +234,7 @@ jobs: # 确保使用 ccache(CMake 会检测 CC/CXX 环境变量) export CC=/usr/local/bin/gcc export CXX=/usr/local/bin/g++ - export CCACHE_DIR="$HOME/.cache/ccache" + export CCACHE_DIR="${{ env.CCACHE_DIR }}" # 清除 ccache 统计(开始新的构建) ccache --zero-stats @@ -272,7 +274,7 @@ jobs: # 显示 ccache 统计(依赖安装阶段) echo "" echo "=== ccache Statistics (before torch_npu build) ===" - CCACHE_DIR="$HOME/.cache/ccache" ccache --show-stats + CCACHE_DIR="${{ env.CCACHE_DIR }}" ccache --show-stats - name: Build torch_npu wheel run: | @@ -290,7 +292,7 @@ jobs: # 确保使用 ccache export CC=/usr/local/bin/gcc export CXX=/usr/local/bin/g++ - export CCACHE_DIR="$HOME/.cache/ccache" + export CCACHE_DIR="${{ env.CCACHE_DIR }}" # 禁用 torchair 构建(上游 PyTorch main API 变化导致兼容性问题) bash ci/build.sh --python=${{ inputs.python_version }} --disable_torchair @@ -307,14 +309,14 @@ jobs: if: always() uses: actions/cache/save@v4 with: - path: $HOME/.cache/pip + path: ${{ env.PIP_CACHE_DIR }} key: ${{ steps.pip_key.outputs.cache_key }} - name: Save ccache if: always() uses: actions/cache/save@v4 with: - path: $HOME/.cache/ccache + path: ${{ env.CCACHE_DIR }} key: ${{ steps.ccache_key.outputs.cache_key }} - name: Display cache save status @@ -322,11 +324,11 @@ jobs: run: | echo "=== Cache Saved ===" echo "pip cache key: ${{ steps.pip_key.outputs.cache_key }}" - PIP_CACHE_SIZE=$(du -sh "$HOME/.cache/pip" 2>/dev/null | cut -f1) + PIP_CACHE_SIZE=$(du -sh "${{ env.PIP_CACHE_DIR }}" 2>/dev/null | cut -f1) echo "pip cache size: ${PIP_CACHE_SIZE}" echo "" echo "ccache key: ${{ steps.ccache_key.outputs.cache_key }}" - CCACHE_SIZE=$(du -sh "$HOME/.cache/ccache" 2>/dev/null | cut -f1) + CCACHE_SIZE=$(du -sh "${{ env.CCACHE_DIR }}" 2>/dev/null | cut -f1) echo "ccache size: ${CCACHE_SIZE}" # ==================== 打包和上传 ==================== From 9aa7cbbe21404b869f92997d272fbddec656e685 Mon Sep 17 00:00:00 2001 From: wangsike Date: Wed, 6 May 2026 22:33:00 +0800 Subject: [PATCH 03/10] [ci] unify docker image configuration and fix PR review issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes: - Rename docker_image_tag to docker_image, accept full URL instead of tag - Set default image: quay.io/kerer/pytorch:manylinux-cann9.0.0-beta.2-20260428 - Remove docker image拼接 in _build.yml and _test.yml - Unify error handling in _test.yml (use ::warning:: instead of || true) - Remove unused DOCKER_REGISTRY env in nightly.yml Co-Authored-By: Claude Opus 4.6 --- .github/workflows/_build.yml | 12 ++++++------ .github/workflows/_test.yml | 15 ++++++++++----- .github/workflows/nightly.yml | 17 +++++++++-------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml index 2fa8326180..10e989aa77 100644 --- a/.github/workflows/_build.yml +++ b/.github/workflows/_build.yml @@ -11,10 +11,11 @@ on: required: true type: string default: '3.11' - docker_image_tag: + docker_image: required: true type: string - description: 'Docker image tag with timestamp' + description: 'Full Docker image URL (e.g., quay.io/kerer/pytorch:tag)' + default: 'quay.io/kerer/pytorch:manylinux-cann9.0.0-beta.2-20260428' outputs: docker-image: description: 'Full Docker image URL' @@ -48,16 +49,15 @@ jobs: docker-image: ${{ steps.set_image.outputs.docker-image }} container: - image: quay.io/kerer/pytorch:${{ inputs.docker_image_tag }} + image: ${{ inputs.docker_image }} options: --user root steps: - name: Set Docker image URL id: set_image run: | - DOCKER_IMAGE="quay.io/kerer/pytorch:${{ inputs.docker_image_tag }}" - echo "docker-image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT - echo "Using Docker image: ${DOCKER_IMAGE}" + echo "docker-image=${{ inputs.docker_image }}" >> $GITHUB_OUTPUT + echo "Using Docker image: ${{ inputs.docker_image }}" - name: Setup CANN environment run: | diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 996695bd18..aa2370420b 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -7,10 +7,11 @@ on: required: true type: string default: '3.11' - docker_image_tag: + docker_image: required: true type: string - description: 'Docker image tag (same as build)' + description: 'Full Docker image URL (same as build)' + default: 'quay.io/kerer/pytorch:manylinux-cann9.0.0-beta.2-20260428' outputs: test-result: description: 'Test result (success/failure)' @@ -27,7 +28,7 @@ jobs: result: ${{ steps.final_status.outputs.result }} container: - image: quay.io/kerer/pytorch:${{ inputs.docker_image_tag }} + image: ${{ inputs.docker_image }} options: --user root steps: @@ -116,8 +117,12 @@ jobs: run: | cd /tmp - 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 + if ! source /usr/local/Ascend/cann/set_env.sh 2>/dev/null; then + echo "::warning::Failed to source CANN environment script" + fi + if ! source /usr/local/Ascend/nnal/atb/set_env.sh 2>/dev/null; then + echo "::warning::Failed to source ATB environment script" + fi PYTHON=python${{ env.PYTHON_VERSION }} diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 54a102ec4f..a26f860c1a 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -30,16 +30,17 @@ on: - '3.9' - '3.8' default: '3.11' + docker_image: + description: 'Docker image for build and test' + required: true + type: string + default: 'quay.io/kerer/pytorch:manylinux-cann9.0.0-beta.2-20260428' skip_build: description: 'Skip build (use cached artifacts)' required: false type: boolean default: false -env: - # Docker 镜像仓库 - DOCKER_REGISTRY: 'quay.io/kerer/pytorch' - jobs: # ==================== 编译阶段 ==================== build: @@ -49,7 +50,7 @@ jobs: with: pytorch_branch: ${{ inputs.pytorch_branch || 'main' }} python_version: ${{ inputs.python_version || '3.11' }} - docker_image_tag: ${{ github.event_name == 'schedule' && 'nightly-latest' || format('nightly-{0}', github.run_number) }} + docker_image: ${{ inputs.docker_image || 'quay.io/kerer/pytorch:manylinux-cann9.0.0-beta.2-20260428' }} # ==================== 测试阶段 ==================== test: @@ -59,7 +60,7 @@ jobs: uses: ./.github/workflows/_test.yml with: python_version: ${{ inputs.python_version || '3.11' }} - docker_image_tag: ${{ github.event_name == 'schedule' && 'nightly-latest' || format('nightly-{0}', github.run_number) }} + docker_image: ${{ inputs.docker_image || 'quay.io/kerer/pytorch:manylinux-cann9.0.0-beta.2-20260428' }} # ==================== 报告阶段 ==================== report: @@ -81,7 +82,7 @@ jobs: echo "**Configuration:**" >> $GITHUB_STEP_SUMMARY echo "- PyTorch branch: ${PYTORCH_BRANCH}" >> $GITHUB_STEP_SUMMARY echo "- Python version: ${PYTHON_VERSION}" >> $GITHUB_STEP_SUMMARY - echo "- Docker image tag: ${DOCKER_TAG}" >> $GITHUB_STEP_SUMMARY + echo "- Docker image: ${DOCKER_IMAGE}" >> $GITHUB_STEP_SUMMARY echo "- Trigger: ${TRIGGER_TYPE}" >> $GITHUB_STEP_SUMMARY echo "- Run number: ${RUN_NUMBER}" >> $GITHUB_STEP_SUMMARY env: @@ -89,7 +90,7 @@ jobs: TEST_STATUS: ${{ needs.test.result == 'success' && '✅ Success' || needs.test.result == 'skipped' && '⏭️ Skipped' || '❌ Failed' }} PYTORCH_BRANCH: ${{ inputs.pytorch_branch || 'main' }} PYTHON_VERSION: ${{ inputs.python_version || '3.11' }} - DOCKER_TAG: ${{ github.event_name == 'schedule' && 'nightly-latest' || format('nightly-{0}', github.run_number) }} + DOCKER_IMAGE: ${{ inputs.docker_image || 'quay.io/kerer/pytorch:manylinux-cann9.0.0-beta.2-20260428' }} TRIGGER_TYPE: ${{ github.event_name }} RUN_NUMBER: ${{ github.run_number }} From ea98dd1352937f5693d27c9a0524a72a44591398 Mon Sep 17 00:00:00 2001 From: wangsike Date: Wed, 6 May 2026 22:33:50 +0800 Subject: [PATCH 04/10] [ci] update python version options to 3.10-3.13 Co-Authored-By: Claude Opus 4.6 --- .github/workflows/nightly.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index a26f860c1a..cb132bc2d1 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -25,10 +25,10 @@ on: required: true type: choice options: - - '3.11' - '3.10' - - '3.9' - - '3.8' + - '3.11' + - '3.12' + - '3.13' default: '3.11' docker_image: description: 'Docker image for build and test' From 1667b2722cef022ec71fd559ba049c34ca71f6e0 Mon Sep 17 00:00:00 2001 From: wangsike Date: Wed, 6 May 2026 22:39:18 +0800 Subject: [PATCH 05/10] [ci] remove ci/build.sh from PR trigger paths Co-Authored-By: Claude Opus 4.6 --- .github/workflows/nightly.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index cb132bc2d1..276550da4c 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -12,7 +12,6 @@ on: - '.github/workflows/_build.yml' - '.github/workflows/_test.yml' - '.github/workflows/nightly.yml' - - 'ci/build.sh' workflow_dispatch: inputs: pytorch_branch: From 8b432daedc7f55758a1ba9ef910d2a275910a72d Mon Sep 17 00:00:00 2001 From: wangsike Date: Thu, 7 May 2026 09:02:08 +0800 Subject: [PATCH 06/10] [ci] simplify report job by removing redundant status check - Change if: always() to if: success() or skipped with skip_build - Remove Check overall status step (GitHub handles failure status automatically) Co-Authored-By: Claude Opus 4.6 --- .github/workflows/nightly.yml | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 276550da4c..a7c3a69876 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -65,7 +65,7 @@ jobs: report: name: Build Report needs: [build, test] - if: always() + if: success() || (needs.build.result == 'skipped' && inputs.skip_build == true) runs-on: ubuntu-latest steps: @@ -91,35 +91,4 @@ jobs: PYTHON_VERSION: ${{ inputs.python_version || '3.11' }} DOCKER_IMAGE: ${{ inputs.docker_image || 'quay.io/kerer/pytorch:manylinux-cann9.0.0-beta.2-20260428' }} TRIGGER_TYPE: ${{ github.event_name }} - RUN_NUMBER: ${{ github.run_number }} - - - name: Check overall status - run: | - BUILD_RESULT="${{ needs.build.result }}" - TEST_RESULT="${{ needs.test.result }}" - - # Build skipped is OK when skip_build is true - BUILD_OK=false - if [[ "$BUILD_RESULT" == "skipped" && "${{ inputs.skip_build }}" == "true" ]]; then - BUILD_OK=true - elif [[ "$BUILD_RESULT" == "success" ]]; then - BUILD_OK=true - fi - - # Test must succeed (or be skipped when build was skipped) - TEST_OK=false - if [[ "$TEST_RESULT" == "success" ]]; then - TEST_OK=true - elif [[ "$BUILD_RESULT" == "skipped" && "$TEST_RESULT" == "skipped" ]]; then - TEST_OK=true - fi - - if [[ "$BUILD_OK" == true && "$TEST_OK" == true ]]; then - echo "Overall status: PASSED ✅" - exit 0 - else - echo "Overall status: FAILED ❌" - echo "Build result: $BUILD_RESULT" - echo "Test result: $TEST_RESULT" - exit 1 - fi \ No newline at end of file + RUN_NUMBER: ${{ github.run_number }} \ No newline at end of file From 1b4fcd31db25b5d126093e89c80ed38d4eb096c6 Mon Sep 17 00:00:00 2001 From: wangsike Date: Thu, 7 May 2026 09:09:04 +0800 Subject: [PATCH 07/10] [ci] remove unused RUN_NUMBER from build report Co-Authored-By: Claude Opus 4.6 --- .github/workflows/nightly.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index a7c3a69876..7ea7f9f15c 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -83,12 +83,10 @@ jobs: echo "- Python version: ${PYTHON_VERSION}" >> $GITHUB_STEP_SUMMARY echo "- Docker image: ${DOCKER_IMAGE}" >> $GITHUB_STEP_SUMMARY echo "- Trigger: ${TRIGGER_TYPE}" >> $GITHUB_STEP_SUMMARY - echo "- Run number: ${RUN_NUMBER}" >> $GITHUB_STEP_SUMMARY env: BUILD_STATUS: ${{ needs.build.result == 'success' && '✅ Success' || needs.build.result == 'skipped' && '⏭️ Skipped' || '❌ Failed' }} TEST_STATUS: ${{ needs.test.result == 'success' && '✅ Success' || needs.test.result == 'skipped' && '⏭️ Skipped' || '❌ Failed' }} PYTORCH_BRANCH: ${{ inputs.pytorch_branch || 'main' }} PYTHON_VERSION: ${{ inputs.python_version || '3.11' }} DOCKER_IMAGE: ${{ inputs.docker_image || 'quay.io/kerer/pytorch:manylinux-cann9.0.0-beta.2-20260428' }} - TRIGGER_TYPE: ${{ github.event_name }} - RUN_NUMBER: ${{ github.run_number }} \ No newline at end of file + TRIGGER_TYPE: ${{ github.event_name }} \ No newline at end of file From c8d3eb04b7cf1d1925581d1385bf8a005bf1de13 Mon Sep 17 00:00:00 2001 From: wangsike Date: Thu, 7 May 2026 09:16:03 +0800 Subject: [PATCH 08/10] [autograd] fix SavedVariable::unpack parameter type mismatch Changed std::shared_ptr to c10::intrusive_ptr in unpack_list and unpack_opt_list functions to match PyTorch's new autograd API. Co-Authored-By: Claude Opus 4.6 --- torchnpugen/autograd/templates/Functions.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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()); From 98794569f78b5de3a75af728924ee713f2eb1693 Mon Sep 17 00:00:00 2001 From: wangsike Date: Thu, 7 May 2026 10:36:49 +0800 Subject: [PATCH 09/10] [autograd] replace std::shared_ptr with c10::intrusive_ptr in VariableFallbackKernel Changed WarnNotImplemented from std::shared_ptr to c10::intrusive_ptr to match PyTorch's autograd API changes: - Use c10::make_intrusive instead of new with deleteNode - Remove deprecated torch::autograd::deleteNode usage Co-Authored-By: Claude Opus 4.6 --- torch_npu/csrc/aten/VariableFallbackKernel.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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)); } From 4a87a304e5384282104bdf42b867ae154ab0d4f7 Mon Sep 17 00:00:00 2001 From: wangsike Date: Thu, 7 May 2026 15:44:05 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/nightly.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 7ea7f9f15c..5d1e95be2f 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -34,17 +34,11 @@ on: required: true type: string default: 'quay.io/kerer/pytorch:manylinux-cann9.0.0-beta.2-20260428' - skip_build: - description: 'Skip build (use cached artifacts)' - required: false - type: boolean - default: false jobs: # ==================== 编译阶段 ==================== build: name: Build PyTorch and torch_npu - if: ${{ inputs.skip_build != true }} uses: ./.github/workflows/_build.yml with: pytorch_branch: ${{ inputs.pytorch_branch || 'main' }} @@ -55,7 +49,6 @@ jobs: test: name: Test torch_npu wheels needs: build - if: always() && needs.build.result == 'success' uses: ./.github/workflows/_test.yml with: python_version: ${{ inputs.python_version || '3.11' }} @@ -65,7 +58,7 @@ jobs: report: name: Build Report needs: [build, test] - if: success() || (needs.build.result == 'skipped' && inputs.skip_build == true) + if: always() runs-on: ubuntu-latest steps: