Skip to content
Draft
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
191 changes: 191 additions & 0 deletions .github/workflows/_ascend_pytorch_label_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
name: PyTorch Label Check

on:
workflow_call:
inputs:
runner:
required: true
type: string
description: "The runner selected to run on"
image:
required: true
type: string
description: "The docker image which will be loaded"
torch-artifact:
required: false
type: string
description: "The distribution artifact name of torch"
torch-npu-artifact:
required: true
type: string
description: "The distribution artifact name of torch_npu"
secrets:
hf-token:
required: true
description: "The Hugging Face token for downloading models"

jobs:
prepare:
runs-on: ubuntu-latest
environment: Ascend
outputs:
pr_numbers: ${{ steps.set_matrix.outputs.pr_numbers }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get open PRs from B repo
id: get_prs
run: |
prs=$(curl -s -H "Authorization: token ${{ secrets.COSDT_BOT_TOKEN }}" \
"https://api.github.com/search/issues?q=is:pr+is:open+repo:pytorch/pytorch+label:\"module:%20PrivateUse1\"")
echo "$prs" > matched.json
cat matched.json

count=$(jq 'length' matched.json)
echo "found=$count" >> $GITHUB_OUTPUT

- name: Show matched PRs
if: steps.get_prs.outputs.found != '0'
run: cat matched.json

- name: Set matrix for parallel PR checkout
id: set_matrix
run: |
matrix_prs=$(jq -r '.items[].number' matched.json | jq -s -c '.')
echo "matrix_prs=$matrix_prs" >> $GITHUB_ENV
echo "pr_numbers=$matrix_prs" >> $GITHUB_OUTPUT

- name: Upload matched.json
uses: actions/upload-artifact@v4
with:
name: matched
path: matched.json


# Define a separate job for each PR number
check_pr:
needs: prepare
environment: Ascend
runs-on: ${{ inputs.runner }}
container:
image: ${{ inputs.image }}
env:
HF_ENDPOINT: https://hf-mirror.com
strategy:
matrix:
pr_number: ${{ fromJson(needs.prepare.outputs.pr_numbers) }}
steps:
- name: Checkout code for PR
uses: actions/checkout@v4

- name: Download matched.json
uses: actions/download-artifact@v4
with:
name: matched

- name: Checkout PR branch
run: |
# Get the PR details
pr_number=${{ matrix.pr_number }}
head_repo=$(jq -r ".[] | select(.number==$pr_number) | .head.repo.full_name" matched.json)
head_ref=$(jq -r ".[] | select(.number==$pr_number) | .head.ref" matched.json)

echo "Checking out PR #$pr_number from $head_repo ($head_ref)"

# Clone the PR's branch
git clone --depth=1 --branch "$head_ref" \
"https://github.com/$head_repo.git" pr-code-$pr_number
ls -al pr-code-$pr_number

- name: Show NPU info
run: |
npu-smi info

- name: Config mirrors
run: |
sed -i 's|ports.ubuntu.com|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

- name: Install system dependencies
run: |
apt-get update
apt-get install -y \
git gcc g++ make cmake ninja-build curl \
libgl1 libglib2.0-0 libsndfile1

# See: https://github.com/actions/checkout/issues/363#issuecomment-1915075699
# See: https://github.com/hunshcn/gh-proxy/issues/28#issuecomment-773769630
- name: Config git
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config --global url."https://gh-proxy.test.osinfra.cn/https://github.com/".insteadOf https://github.com/

- name: Checkout
uses: actions/checkout@v4

- name: Checkout torchtune
uses: actions/checkout@v4
with:
repository: pytorch/torchtune
path: torchtune

- name: Download torch artifact
if: ${{ inputs.torch-artifact }}
uses: actions/download-artifact@v5
with:
name: ${{ inputs.torch-artifact }}

- name: Install torch
if: ${{ inputs.torch-artifact }}
run: |
pip install ${{ inputs.torch-artifact }}

- name: Install torch_npu dependencies
if: ${{ !inputs.torch-artifact }}
run: |
pip install -r https://raw.githubusercontent.com/Ascend/pytorch/refs/heads/master/requirements.txt

- name: List torch version
id: list-torch-version
shell: bash
run: |
torch_version=$(python -c "import torch; print(torch.__version__)")
echo "torch-version=${torch_version}" >> $GITHUB_OUTPUT

- name: Download torch_npu artifact
uses: actions/download-artifact@v5
with:
name: ${{ inputs.torch-npu-artifact }}
path: ascend_npu

- name: Install torch_npu
working-directory: ascend_npu
run: |
pip install ${{ inputs.torch-npu-artifact }} torchtune torchao torchvision --extra-index-url https://download.pytorch.org/whl/nightly/cpu

- name: Show environment info
run: |
pip list

- name: Run tests
id: build
working-directory: pr-code-${{ matrix.pr_number }}
run: |
python test/run_test.py --verbose --exclude-jit-executor
continue-on-error: true

- name: Create GitHub Issue on Failure
if: steps.build.outcome == 'failure'
uses: JasonEtco/create-an-issue@v2
with:
token: ${{ secrets.COSDT_BOT_TOKEN }}
title: Build Failed in Workflow ${{ github.workflow }}
body: |
The build failed. Please investigate.

- **Workflow**: `${{ github.workflow }}`
- **Job**: `${{ github.job }}`
- **Commit**: `${{ github.sha }}`
- **Triggered by**: `${{ github.actor }}`
- **Logs**: [Click here to see the logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})