Skip to content
Merged
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
21 changes: 21 additions & 0 deletions .github/actions/install-artifact/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Install artifact with pip"
description: "Install artifact with pip"
inputs:
artifact:
description: "The distribution artifact name"
type: string
required: true

# TODO: https://github.com/actions/runner/issues/3620
runs:
using: "composite"
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact }}

- name: Install artifact
shell: bash
run: |
pip install ${{ inputs.artifact }}
63 changes: 50 additions & 13 deletions .github/workflows/_ascend_npu_benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ on:
required: true
type: string
description: 'The device selected to run on'
artifact_name:
torch-artifact:
required: false
type: string
description: 'The distribution artifact name of torch'
torch-npu-artifact:
required: true
type: string
description: 'The torch_npu distribution artifact name'
description: 'The distribution artifact name of torch_npu'
secrets:
pr-token:
description: 'A token used to create a pull request'
Expand Down Expand Up @@ -87,29 +91,61 @@ jobs:
repository: pytorch/benchmark
path: benchmark

- name: Download ${{ inputs.artifact_name }}
# TODO
# - name: Install torch
# id: install-torch
# uses: ./.github/actions/install-artifact
# with:
# artifact: ${{ inputs.torch-artifact }}

- name: Download torch artifact
if: ${{ inputs.torch-artifact }}
uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact_name }}
path: ascend_npu
name: ${{ inputs.torch-artifact }}

- name: Install torch_npu
working-directory: ascend_npu
- name: Install torch
if: ${{ inputs.torch-artifact }}
run: |
pip install ${{ inputs.artifact_name }}
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@v4
with:
name: ${{ inputs.torch-npu-artifact }}
path: ascend_npu

- name: Install torch_npu
working-directory: ascend_npu
run: |
curl -fsSL -O https://raw.githubusercontent.com/Ascend/pytorch/refs/heads/master/requirements.txt
pip install -r requirements.txt
pip install ${{ inputs.torch-npu-artifact }}

# TODO: We must use numpy 1.x
- name: Install benchmark dependencies
run: |
pip install -r benchmark/requirements.txt --constraint ascend_npu/requirements.txt "numpy==1.*"
pip install -r benchmark/requirements.txt \
torch==${{ steps.list-torch-version.outputs.torch-version }} \
numpy==1.*

- name: Install dependencies for all the models
run: |
python benchmark/install.py --userbenchmark test_bench --continue_on_fail

- name: Install nightly torchvision and torchaudio
run: |
pip install --pre torchvision torchaudio --no-deps --index-url https://download.pytorch.org/whl/nightly/cpu

- name: Install project dependencies
run: |
pip install -r requirements.txt
Expand All @@ -128,14 +164,15 @@ jobs:
python run_benchmark.py test_bench --accuracy --device npu --test eval \
--output ascend_npu_benchmark.json

- name: Upload the output file
- name: Upload the benchmark report file
id: upload-output
uses: actions/upload-artifact@v4
with:
name: ascend_npu_benchmark.json
path: benchmark/ascend_npu_benchmark.json
if-no-files-found: error
retention-days: 1
overwrite: true

- name: Write to workflow job summary
run: |
Expand Down
109 changes: 109 additions & 0 deletions .github/workflows/_ascend_npu_build_torch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: '_ascend_npu_build_torch'

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 used to build'
ref:
required: false
type: string
default: 'refs/heads/main'
description: 'The branch, tag or SHA to checkout'
outputs:
torch-artifact:
description: 'The distribution artifact name of torch'
value: ${{ jobs.build.outputs.dist-name }}

# Bash shells do not use ~/.profile or ~/.bashrc so these shells need to be explicitly
# declared as "shell: bash -el {0}" on steps that need to be properly activated.
# It's used to activate ascend-toolkit environment variables.
defaults:
run:
shell: bash -el {0}

jobs:
build:
name: build torch
runs-on: ${{ inputs.runner }}
container:
image: ${{ inputs.image }}
options: >-
--network host
env:
HTTP_PROXY: http://127.0.0.1:10809
HTTPS_PROXY: http://127.0.0.1:10809
ALL_PROXY: socks5://127.0.0.1:10808
SOCKS_PROXY: socks5://127.0.0.1:10808
outputs:
dist-name: ${{ steps.list-dist.outputs.dist-name }}
steps:
- 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

# See: https://github.com/actions/checkout/issues/363#issuecomment-1915075699
- name: Config git
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"

- name: Checkout PyTorch
uses: actions/checkout@v4
with:
repository: pytorch/pytorch
ref: ${{ inputs.ref }}
submodules: recursive
path: pytorch

- name: View commit history
working-directory: pytorch
run: |
git log -n 10 --graph | cat

- name: Install torch dependencies
working-directory: pytorch
run: |
pip install -r requirements.txt

- name: Build torch
working-directory: pytorch
run: |
python setup.py build bdist_wheel

- name: List distribution package
id: list-dist
working-directory: pytorch/dist
run: |
dist_name=$(ls torch*.whl)
dist_path=$(pwd)/${dist_name}
echo "dist-name=${dist_name}" >> $GITHUB_OUTPUT
echo "dist-path=${dist_path}" >> $GITHUB_OUTPUT

- name: Upload distribution artifact
id: upload-dist
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: ${{ steps.list-dist.outputs.dist-name }}
path: ${{ steps.list-dist.outputs.dist-path }}
if-no-files-found: error
retention-days: 1
overwrite: true

- name: Write to workflow job summary
if: ${{ steps.upload-dist.outputs.artifact-url }}
run: |
echo "## torch built successfully! :rocket:" >> $GITHUB_STEP_SUMMARY
echo "You can download the distribution package [here](${{ steps.upload-dist.outputs.artifact-url }})." >> $GITHUB_STEP_SUMMARY
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ on:
required: true
type: string
description: 'The docker image which will be used to build'
torch-artifact:
required: false
type: string
description: 'The distribution artifact name of torch'
outputs:
artifact_name:
description: 'The torch_npu distribution artifact name'
value: ${{ jobs.build.outputs.dist_name }}
torch-npu-artifact:
description: 'The distribution artifact name of torch_npu'
value: ${{ jobs.build.outputs.dist-name }}

# Bash shells do not use ~/.profile or ~/.bashrc so these shells need to be explicitly
# declared as "shell: bash -el {0}" on steps that need to be properly activated.
Expand All @@ -37,14 +41,13 @@ jobs:
ALL_PROXY: socks5://127.0.0.1:10808
SOCKS_PROXY: socks5://127.0.0.1:10808
outputs:
dist_name: ${{ steps.list-dist.outputs.dist_name }}
dist-name: ${{ steps.list-dist.outputs.dist-name }}
steps:
- 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

# TODO(shink): Should we add these dependencies to the image?
- name: Install system dependencies
run: |
apt-get update
Expand All @@ -69,40 +72,58 @@ jobs:
submodules: recursive
path: torch_npu

- name: Install pip dependencies
- name: Install torch_npu dependencies
working-directory: torch_npu
run: |
pip install wheel
pip install -r requirements.txt

# TODO
# - name: Install torch
# id: install-torch
# uses: ./.github/actions/install-artifact
# with:
# artifact: ${{ inputs.torch-artifact }}

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

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

- name: List Python version
id: list-py-version
working-directory: torch_npu
run: |
py_version=$(python --version | awk '{print $2}' | cut -d '.' -f 1,2)
echo "py_version=${py_version}" >> $GITHUB_OUTPUT
echo "py-version=${py_version}" >> $GITHUB_OUTPUT

- name: Build torch_npu
working-directory: torch_npu
run: |
bash ci/build.sh --python=${{ steps.list-py-version.outputs.py_version }}
bash ci/build.sh --python=${{ steps.list-py-version.outputs.py-version }}

- name: List distribution package
id: list-dist
working-directory: torch_npu/dist
run: |
dist_name=$(ls torch_npu*.whl)
dist_path=$(pwd)/${dist_name}
echo "dist_name=${dist_name}" >> $GITHUB_OUTPUT
echo "dist_path=${dist_path}" >> $GITHUB_OUTPUT
echo "dist-name=${dist_name}" >> $GITHUB_OUTPUT
echo "dist-path=${dist_path}" >> $GITHUB_OUTPUT

- name: Upload distribution artifact
id: upload-dist
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: ${{ steps.list-dist.outputs.dist_name }}
path: ${{ steps.list-dist.outputs.dist_path }}
name: ${{ steps.list-dist.outputs.dist-name }}
path: ${{ steps.list-dist.outputs.dist-path }}
if-no-files-found: error
retention-days: 1
overwrite: true
Expand Down
Loading
Loading