|
| 1 | +name: '_ascend_npu_build' |
| 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 used to build' |
| 14 | + outputs: |
| 15 | + artifact_name: |
| 16 | + description: 'The torch_npu distribution artifact name' |
| 17 | + value: ${{ jobs.build.outputs.dist_name }} |
| 18 | + |
| 19 | +# Bash shells do not use ~/.profile or ~/.bashrc so these shells need to be explicitly |
| 20 | +# declared as "shell: bash -el {0}" on steps that need to be properly activated. |
| 21 | +# It's used to activate ascend-toolkit environment variables. |
| 22 | +defaults: |
| 23 | + run: |
| 24 | + shell: bash -el {0} |
| 25 | + |
| 26 | +jobs: |
| 27 | + build: |
| 28 | + name: build torch_npu |
| 29 | + runs-on: ${{ inputs.runner }} |
| 30 | + container: |
| 31 | + image: ${{ inputs.image }} |
| 32 | + outputs: |
| 33 | + dist_name: ${{ steps.list-dist.outputs.dist_name }} |
| 34 | + steps: |
| 35 | + # TODO(shink): Should we add these dependencies to the image? |
| 36 | + - name: Install system dependencies |
| 37 | + run: | |
| 38 | + sed -i 's|ports.ubuntu.com|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list |
| 39 | + apt update |
| 40 | + apt install --no-install-recommends -y git gcc g++ make cmake ninja-build |
| 41 | +
|
| 42 | + - name: Checkout |
| 43 | + uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Checkout torch_npu |
| 46 | + uses: actions/checkout@v4 |
| 47 | + with: |
| 48 | + # TODO(shink): Use Ascend/pytorch once this pr merged: |
| 49 | + # https://gitee.com/ascend/pytorch/pulls/12854 |
| 50 | + # repository: Ascend/pytorch |
| 51 | + repository: shink/torchnpu |
| 52 | + ref: feat/autoload |
| 53 | + submodules: recursive |
| 54 | + path: torch_npu |
| 55 | + |
| 56 | + - name: Install pip dependencies |
| 57 | + working-directory: torch_npu |
| 58 | + run: | |
| 59 | + pip install wheel |
| 60 | + pip install -r requirements.txt |
| 61 | +
|
| 62 | + - name: List Python version |
| 63 | + id: list-py-version |
| 64 | + working-directory: torch_npu |
| 65 | + run: | |
| 66 | + py_version=$(python --version | awk '{print $2}' | cut -d '.' -f 1,2) |
| 67 | + echo "py_version=${py_version}" >> $GITHUB_OUTPUT |
| 68 | +
|
| 69 | + - name: Build torch_npu |
| 70 | + working-directory: torch_npu |
| 71 | + run: | |
| 72 | + bash ci/build.sh --python=${{ steps.list-py-version.outputs.py_version }} |
| 73 | +
|
| 74 | + - name: List distribution package |
| 75 | + id: list-dist |
| 76 | + working-directory: torch_npu/dist |
| 77 | + run: | |
| 78 | + dist_name=$(ls torch_npu*.whl) |
| 79 | + dist_path=$(pwd)/${dist_name} |
| 80 | + echo "dist_name=${dist_name}" >> $GITHUB_OUTPUT |
| 81 | + echo "dist_path=${dist_path}" >> $GITHUB_OUTPUT |
| 82 | +
|
| 83 | + - name: Upload distribution artifact |
| 84 | + id: upload-dist |
| 85 | + continue-on-error: true |
| 86 | + uses: actions/upload-artifact@v4 |
| 87 | + with: |
| 88 | + name: ${{ steps.list-dist.outputs.dist_name }} |
| 89 | + path: ${{ steps.list-dist.outputs.dist_path }} |
| 90 | + if-no-files-found: error |
| 91 | + retention-days: 1 |
| 92 | + overwrite: true |
| 93 | + |
| 94 | + - name: Write to workflow job summary |
| 95 | + if: ${{ steps.upload-dist.outputs.artifact-url }} |
| 96 | + run: | |
| 97 | + echo "## torch_npu built successfully! :rocket:" >> $GITHUB_STEP_SUMMARY |
| 98 | + echo "You can download the distribution package [here](${{ steps.upload-dist.outputs.artifact-url }})." >> $GITHUB_STEP_SUMMARY |
0 commit comments