|
| 1 | +name: '_ascend_npu_benchmark' |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + runner: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + description: 'The runner selected to run on' |
| 10 | + image: |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + description: 'The docker image which will be loaded' |
| 14 | + device: |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + description: 'The device selected to run on' |
| 18 | + torch-artifact: |
| 19 | + required: false |
| 20 | + type: string |
| 21 | + description: 'The distribution artifact name of torch' |
| 22 | + torch-npu-artifact: |
| 23 | + required: true |
| 24 | + type: string |
| 25 | + description: 'The distribution artifact name of torch_npu' |
| 26 | + secrets: |
| 27 | + pr-token: |
| 28 | + description: 'A token used to create a pull request' |
| 29 | + required: true |
| 30 | + |
| 31 | +# Bash shells do not use ~/.profile or ~/.bashrc so these shells need to be explicitly |
| 32 | +# declared as "shell: bash -el {0}" on steps that need to be properly activated. |
| 33 | +# It's used to activate ascend-toolkit environment variables. |
| 34 | +defaults: |
| 35 | + run: |
| 36 | + shell: bash -el {0} |
| 37 | + |
| 38 | +jobs: |
| 39 | + test: |
| 40 | + name: run benchmarks for torch_npu |
| 41 | + runs-on: ${{ inputs.runner }} |
| 42 | + container: |
| 43 | + image: ${{ inputs.image }} |
| 44 | + env: |
| 45 | + HF_ENDPOINT: https://hf-mirror.com |
| 46 | + steps: |
| 47 | + - name: Show NPU info |
| 48 | + run: | |
| 49 | + npu-smi info |
| 50 | +
|
| 51 | + - name: Config mirrors |
| 52 | + run: | |
| 53 | + sed -i 's|ports.ubuntu.com|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list |
| 54 | + pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple |
| 55 | +
|
| 56 | + - name: Install system dependencies |
| 57 | + run: | |
| 58 | + apt-get update |
| 59 | + apt-get install -y \ |
| 60 | + git gcc g++ make cmake ninja-build curl \ |
| 61 | + libgl1 libglib2.0-0 libsndfile1 |
| 62 | +
|
| 63 | + # See: https://github.com/actions/checkout/issues/363#issuecomment-1915075699 |
| 64 | + # See: https://github.com/hunshcn/gh-proxy/issues/28#issuecomment-773769630 |
| 65 | + - name: Config git |
| 66 | + run: | |
| 67 | + git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 68 | + git config --global url."https://gh-proxy.test.osinfra.cn/https://github.com/".insteadOf https://github.com/ |
| 69 | +
|
| 70 | + - name: Checkout |
| 71 | + uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - name: Checkout benchmark |
| 74 | + uses: actions/checkout@v4 |
| 75 | + with: |
| 76 | + repository: pytorch/benchmark |
| 77 | + path: benchmark |
| 78 | + |
| 79 | + # TODO |
| 80 | + # - name: Install torch |
| 81 | + # id: install-torch |
| 82 | + # uses: ./.github/actions/install-artifact |
| 83 | + # with: |
| 84 | + # artifact: ${{ inputs.torch-artifact }} |
| 85 | + |
| 86 | + - name: Download torch artifact |
| 87 | + if: ${{ inputs.torch-artifact }} |
| 88 | + uses: actions/download-artifact@v4 |
| 89 | + with: |
| 90 | + name: ${{ inputs.torch-artifact }} |
| 91 | + |
| 92 | + - name: Install torch |
| 93 | + if: ${{ inputs.torch-artifact }} |
| 94 | + run: | |
| 95 | + pip install ${{ inputs.torch-artifact }} |
| 96 | +
|
| 97 | + - name: Install torch_npu dependencies |
| 98 | + if: ${{ !inputs.torch-artifact }} |
| 99 | + run: | |
| 100 | + pip install -r https://raw.githubusercontent.com/Ascend/pytorch/refs/heads/master/requirements.txt |
| 101 | +
|
| 102 | + - name: List torch version |
| 103 | + id: list-torch-version |
| 104 | + shell: bash |
| 105 | + run: | |
| 106 | + torch_version=$(python -c "import torch; print(torch.__version__)") |
| 107 | + echo "torch-version=${torch_version}" >> $GITHUB_OUTPUT |
| 108 | +
|
| 109 | + - name: Download torch_npu artifact |
| 110 | + uses: actions/download-artifact@v4 |
| 111 | + with: |
| 112 | + name: ${{ inputs.torch-npu-artifact }} |
| 113 | + path: ascend_npu |
| 114 | + |
| 115 | + - name: Install torch_npu |
| 116 | + working-directory: ascend_npu |
| 117 | + run: | |
| 118 | + pip install ${{ inputs.torch-npu-artifact }} |
| 119 | +
|
| 120 | + - name: Install benchmark dependencies |
| 121 | + run: | |
| 122 | + pip install -r benchmark/requirements.txt \ |
| 123 | + torch==${{ steps.list-torch-version.outputs.torch-version }} \ |
| 124 | + numpy==1.* |
| 125 | +
|
| 126 | + - name: Install dependencies for all the models |
| 127 | + run: | |
| 128 | + python benchmark/install.py --userbenchmark test_bench --continue_on_fail |
| 129 | +
|
| 130 | + - name: Install nightly torchvision and torchaudio |
| 131 | + run: | |
| 132 | + pip install --pre torchvision torchaudio --no-deps --index-url https://download.pytorch.org/whl/nightly/cpu |
| 133 | +
|
| 134 | + - name: Install project dependencies |
| 135 | + run: | |
| 136 | + pip install -r requirements.txt |
| 137 | +
|
| 138 | + - name: Show environment info |
| 139 | + run: | |
| 140 | + npu_is_available=$(python -c "import torch; print(torch.npu.is_available())") |
| 141 | + npu_count=$(python -c "import torch; print(torch.npu.device_count())") |
| 142 | + echo "NPU is available: ${npu_is_available}" |
| 143 | + echo "NPU count: ${npu_count}" |
| 144 | + pip list | grep -E 'torch|numpy' |
| 145 | +
|
| 146 | + - name: Run benchmarks |
| 147 | + working-directory: benchmark |
| 148 | + run: | |
| 149 | + python run_benchmark.py test_bench --accuracy --device npu --test eval \ |
| 150 | + --output ascend_npu_benchmark.json |
| 151 | +
|
| 152 | + - name: Upload the benchmark report file |
| 153 | + id: upload-report |
| 154 | + uses: actions/upload-artifact@v4 |
| 155 | + with: |
| 156 | + name: ascend_npu_benchmark.json |
| 157 | + path: benchmark/ascend_npu_benchmark.json |
| 158 | + if-no-files-found: error |
| 159 | + retention-days: 1 |
| 160 | + overwrite: true |
| 161 | + |
| 162 | + - name: Write to workflow job summary |
| 163 | + run: | |
| 164 | + python .ci/benchmark.py --write-gh-job-summary --path benchmark/ascend_npu_benchmark.json |
| 165 | +
|
| 166 | + - name: Update README.md |
| 167 | + if: ${{ contains(fromJSON('["push", "schedule", "workflow_dispatch"]'), github.event_name) }} |
| 168 | + id: update-readme |
| 169 | + run: | |
| 170 | + python .ci/benchmark.py --update-readme --path benchmark/ascend_npu_benchmark.json |
| 171 | + if git diff --quiet README.md; then |
| 172 | + echo "README.md not changed" |
| 173 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 174 | + else |
| 175 | + echo "README.md changed" |
| 176 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 177 | + fi |
| 178 | +
|
| 179 | + # See: https://github.com/peter-evans/create-pull-request |
| 180 | + - name: Create a pull request for changes to README.md |
| 181 | + if: ${{ steps.update-readme.outputs.changed == 'true' }} |
| 182 | + uses: peter-evans/create-pull-request@v7 |
| 183 | + with: |
| 184 | + token: ${{ secrets.pr-token }} |
| 185 | + base: ${{ github.head_ref }} |
| 186 | + committer: 'cosdt-bot <[email protected]>' |
| 187 | + author: 'cosdt-bot <[email protected]>' |
| 188 | + commit-message: 'Update torchbenchmark report in README.md' |
| 189 | + add-paths: README.md |
| 190 | + branch: ascend-npu/benchmark |
| 191 | + title: '[Ascend NPU] Update torchbenchmark report in README.md' |
| 192 | + body: | |
| 193 | + The torchbenchmark results running on Ascend NPU have changed, I'm updating the report in README.md. |
| 194 | +
|
| 195 | + Please check out the following resources for more information: |
| 196 | +
|
| 197 | + - [Workflow run][1] |
| 198 | + - [Torchbenchmark report][2] (click to download) |
| 199 | +
|
| 200 | + [1]: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 201 | + [2]: ${{ steps.upload-report.outputs.artifact-url }} |
| 202 | +
|
| 203 | + cc: @Yikun @hipudding @FFFrog @Zhenbin-8 @zeshengzong @wjunLu @MengqingCao @shink |
| 204 | + reviewers: shink |
0 commit comments