diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml index 55a0b52dcf..10e989aa77 100644 --- a/.github/workflows/_build.yml +++ b/.github/workflows/_build.yml @@ -1,106 +1,360 @@ -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: required: true type: string - description: The downstream repository full name (owner/repo) + 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' + 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' + # 缓存目录(container 中 HOME 为 /root) + PIP_CACHE_DIR: '/root/.cache/pip' + CCACHE_DIR: '/root/.cache/ccache' 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: ${{ inputs.docker_image }} + 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: | + echo "docker-image=${{ inputs.docker_image }}" >> $GITHUB_OUTPUT + echo "Using Docker image: ${{ inputs.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: ${{ env.PIP_CACHE_DIR }} + 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 "${{ env.PIP_CACHE_DIR }}" + # 升级 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: ${{ env.CCACHE_DIR }} + 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 配置目录 + mkdir -p "${{ env.CCACHE_DIR }}" + + # 直接写入配置文件 + cat > "${{ env.CCACHE_DIR }}/ccache.conf" << EOF + max_size = 20G + cache_dir = ${{ env.CCACHE_DIR }} + 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 + 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 --show-config + + echo "" + echo "=== Config File Contents ===" + cat "${{ env.CCACHE_DIR }}/ccache.conf" + + echo "" + echo "=== Cache Directory ===" + ls -la "${{ env.CCACHE_DIR }}/" + + echo "" + echo "=== Symbolic Links ===" + ls -la /usr/local/bin/gcc /usr/local/bin/g++ + + echo "" + echo "=== ccache Statistics (before build) ===" + 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="${{ env.CCACHE_DIR }}" + + # 清除 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="${{ env.CCACHE_DIR }}" 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="${{ env.CCACHE_DIR }}" + + # 禁用 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: ${{ env.PIP_CACHE_DIR }} + key: ${{ steps.pip_key.outputs.cache_key }} + + - name: Save ccache + if: always() + uses: actions/cache/save@v4 + with: + path: ${{ env.CCACHE_DIR }} + 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 "${{ 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 "${{ env.CCACHE_DIR }}" 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..aa2370420b --- /dev/null +++ b/.github/workflows/_test.yml @@ -0,0 +1,172 @@ +name: Test torch_npu wheels + +on: + workflow_call: + inputs: + python_version: + required: true + type: string + default: '3.11' + docker_image: + required: true + type: string + 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)' + 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: ${{ inputs.docker_image }} + 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 + + 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 }} + + 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..5d1e95be2f --- /dev/null +++ b/.github/workflows/nightly.yml @@ -0,0 +1,85 @@ +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' + 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.10' + - '3.11' + - '3.12' + - '3.13' + 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' + +jobs: + # ==================== 编译阶段 ==================== + build: + name: Build PyTorch and torch_npu + uses: ./.github/workflows/_build.yml + with: + 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' }} + + # ==================== 测试阶段 ==================== + test: + name: Test torch_npu wheels + needs: build + uses: ./.github/workflows/_test.yml + with: + python_version: ${{ inputs.python_version || '3.11' }} + docker_image: ${{ inputs.docker_image || 'quay.io/kerer/pytorch:manylinux-cann9.0.0-beta.2-20260428' }} + + # ==================== 报告阶段 ==================== + 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: ${DOCKER_IMAGE}" >> $GITHUB_STEP_SUMMARY + echo "- Trigger: ${TRIGGER_TYPE}" >> $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 }} \ No newline at end of file diff --git a/torch_npu/csrc/aten/VariableFallbackKernel.cpp b/torch_npu/csrc/aten/VariableFallbackKernel.cpp index 25d96107e4..13f95c0a30 100644 --- a/torch_npu/csrc/aten/VariableFallbackKernel.cpp +++ b/torch_npu/csrc/aten/VariableFallbackKernel.cpp @@ -132,7 +132,7 @@ static void npuBasicAutogradNotImplementedFallbackImpl( // by putting it after the requires_grad checks. any_input_requires_grad = any_input_requires_grad && at::GradMode::is_enabled(); - std::shared_ptr grad_fn; + c10::intrusive_ptr grad_fn; if (any_input_requires_grad) { // NB: It is standard to collect edges from all tensors // (see generated/VariableTypeEverything.cpp for examples) @@ -144,9 +144,7 @@ static void npuBasicAutogradNotImplementedFallbackImpl( stack, stack_start, num_arguments); - grad_fn = std::shared_ptr( - new WarnNotImplemented(op_name, all_tensors_on_stack.size()), - torch::autograd::deleteNode); + grad_fn = c10::make_intrusive(op_name, all_tensors_on_stack.size()); grad_fn->set_next_edges(torch::autograd::collect_next_edges(all_tensors_on_stack)); } diff --git a/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());