| 
 | 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 | +      artifact_name:  | 
 | 19 | +        required: true  | 
 | 20 | +        type: string  | 
 | 21 | +        description: 'The torch_npu distribution artifact name'  | 
 | 22 | + | 
 | 23 | +# Bash shells do not use ~/.profile or ~/.bashrc so these shells need to be explicitly  | 
 | 24 | +# declared as "shell: bash -el {0}" on steps that need to be properly activated.  | 
 | 25 | +# It's used to activate ascend-toolkit environment variables.  | 
 | 26 | +defaults:  | 
 | 27 | +  run:  | 
 | 28 | +    shell: bash -el {0}  | 
 | 29 | + | 
 | 30 | +jobs:  | 
 | 31 | +  test:  | 
 | 32 | +    name: run benchmarks for torch_npu  | 
 | 33 | +    runs-on: ${{ inputs.runner }}  | 
 | 34 | +    container:  | 
 | 35 | +      image: ${{ inputs.image }}  | 
 | 36 | +      volumes:  | 
 | 37 | +        - /usr/local/dcmi:/usr/local/dcmi  | 
 | 38 | +        - /usr/local/bin/npu-smi:/usr/local/bin/npu-smi  | 
 | 39 | +        - /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/  | 
 | 40 | +        - /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info  | 
 | 41 | +        - /etc/ascend_install.info:/etc/ascend_install.info  | 
 | 42 | +      options: >-  | 
 | 43 | +        --network host  | 
 | 44 | +        --device ${{ inputs.device }}  | 
 | 45 | +        --device /dev/davinci_manager  | 
 | 46 | +        --device /dev/devmm_svm  | 
 | 47 | +        --device /dev/hisi_hdc  | 
 | 48 | +      env:  | 
 | 49 | +        HTTP_PROXY: http://127.0.0.1:10809  | 
 | 50 | +        HTTPS_PROXY: http://127.0.0.1:10809  | 
 | 51 | +        ALL_PROXY: socks5://127.0.0.1:10808  | 
 | 52 | +        SOCKS_PROXY: socks5://127.0.0.1:10808  | 
 | 53 | +    steps:  | 
 | 54 | +      - name: Show NPU info  | 
 | 55 | +        run: |  | 
 | 56 | +          npu-smi info  | 
 | 57 | +
  | 
 | 58 | +      - name: Config mirrors  | 
 | 59 | +        run: |  | 
 | 60 | +          sed -i 's|ports.ubuntu.com|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list  | 
 | 61 | +          pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple  | 
 | 62 | +
  | 
 | 63 | +      - name: Install system dependencies  | 
 | 64 | +        run: |  | 
 | 65 | +          apt update  | 
 | 66 | +          apt install --no-install-recommends -y \  | 
 | 67 | +              git gcc g++ make cmake ninja-build curl \  | 
 | 68 | +              libgl1 libglib2.0-0 libsndfile1  | 
 | 69 | +
  | 
 | 70 | +      - name: Checkout  | 
 | 71 | +        uses: actions/checkout@v4  | 
 | 72 | + | 
 | 73 | +      # TODO(shink): Update once PR merged  | 
 | 74 | +      # https://github.com/pytorch/benchmark/pull/2550  | 
 | 75 | +      - name: Checkout benchmark  | 
 | 76 | +        uses: actions/checkout@v4  | 
 | 77 | +        with:  | 
 | 78 | +          repository: shink/benchmark  | 
 | 79 | +          ref: feat/test_bench/continue_on_error  | 
 | 80 | +          path: benchmark  | 
 | 81 | + | 
 | 82 | +      - name: Download ${{ inputs.artifact_name }}  | 
 | 83 | +        uses: actions/download-artifact@v4  | 
 | 84 | +        with:  | 
 | 85 | +          name: ${{ inputs.artifact_name }}  | 
 | 86 | +          path: ascend_npu  | 
 | 87 | + | 
 | 88 | +      - name: Install torch_npu  | 
 | 89 | +        working-directory: ascend_npu  | 
 | 90 | +        run: |  | 
 | 91 | +          pip install ${{ inputs.artifact_name }}  | 
 | 92 | +
  | 
 | 93 | +      - name: Install torch_npu dependencies  | 
 | 94 | +        working-directory: ascend_npu  | 
 | 95 | +        run: |  | 
 | 96 | +          curl -fsSL -O https://raw.githubusercontent.com/Ascend/pytorch/refs/heads/master/requirements.txt  | 
 | 97 | +          pip install -r requirements.txt  | 
 | 98 | +
  | 
 | 99 | +      - name: Install benchmark dependencies  | 
 | 100 | +        run: |  | 
 | 101 | +          pip install -r benchmark/requirements.txt --constraint ascend_npu/requirements.txt "numpy==1.*"  | 
 | 102 | +          python benchmark/install.py --userbenchmark test_bench --continue_on_fail  | 
 | 103 | +
  | 
 | 104 | +      - name: Install project dependencies  | 
 | 105 | +        run: |  | 
 | 106 | +          pip install -r requirements.txt  | 
 | 107 | +
  | 
 | 108 | +      - name: Show environment info  | 
 | 109 | +        run: |  | 
 | 110 | +          npu_is_available=$(python -c "import torch; print(torch.npu.is_available())")  | 
 | 111 | +          npu_count=$(python -c "import torch; print(torch.npu.device_count())")  | 
 | 112 | +          echo "NPU is available: ${npu_is_available}"  | 
 | 113 | +          echo "NPU count: ${npu_count}"  | 
 | 114 | +          pip list | grep -E 'torch|numpy'  | 
 | 115 | +
  | 
 | 116 | +      - name: Run benchmarks  | 
 | 117 | +        working-directory: benchmark  | 
 | 118 | +        run: |  | 
 | 119 | +          python run_benchmark.py test_bench --accuracy --device npu --test eval \  | 
 | 120 | +              --output ascend_npu_benchmark.json  | 
 | 121 | +
  | 
 | 122 | +      - name: Upload the output file  | 
 | 123 | +        id: upload-output  | 
 | 124 | +        uses: actions/upload-artifact@v4  | 
 | 125 | +        with:  | 
 | 126 | +          name: ascend_npu_benchmark.json  | 
 | 127 | +          path: benchmark/ascend_npu_benchmark.json  | 
 | 128 | +          if-no-files-found: error  | 
 | 129 | +          retention-days: 1  | 
 | 130 | +          overwrite: true  | 
 | 131 | + | 
 | 132 | +      - name: Write to workflow job summary  | 
 | 133 | +        id: report  | 
 | 134 | +        run: |  | 
 | 135 | +          set -x  | 
 | 136 | +          realpath benchmark/ascend_npu_benchmark.json  | 
 | 137 | +          ls benchmark  | 
 | 138 | +          cat benchmark/ascend_npu_benchmark.json  | 
 | 139 | +
  | 
 | 140 | +          output_path=$(realpath benchmark/ascend_npu_benchmark.json)  | 
 | 141 | +          python .ci/benchmark.py ${output_path}  | 
 | 142 | +
  | 
 | 143 | +      # TODO(shink)  | 
 | 144 | +      - name: Update README.md  | 
 | 145 | +        if: ${{ github.event_name == 'push' }}  | 
 | 146 | +        run: |  | 
 | 147 | +          echo "${{ github.event_name }}"  | 
 | 148 | +          echo "${{ github.event_name == 'push' }}"  | 
0 commit comments