4
4
workflow_call :
5
5
inputs :
6
6
pytorch :
7
- required : false
7
+ required : true
8
8
type : string
9
9
default : ' main'
10
10
description : Pytorch branch/commit
13
13
type : string
14
14
default : ' false'
15
15
description : Keep torch-xpu-ops pin. `true` means use pined commit
16
+ driver :
17
+ required : false
18
+ type : string
19
+ default : ' lts'
20
+ description : Driver lts/rolling
16
21
python :
17
22
required : false
18
23
type : string
23
28
type : string
24
29
default : ' linux.idc.xpu'
25
30
description : Runner label
26
- driver :
27
- required : false
28
- type : string
29
- default : ' lts'
30
- description : Driver lts/rolling
31
31
update_lkg :
32
32
required : false
33
33
type : string
@@ -44,68 +44,85 @@ permissions:
44
44
jobs :
45
45
build :
46
46
runs-on : ${{ inputs.runner }}
47
+ container :
48
+ image : ' pytorch/manylinux2_28-builder:xpu-main'
49
+ volumes :
50
+ - ${{ github.workspace }}:${{ github.workspace }}
51
+ env :
52
+ PATH : /opt/xpu-build/bin:/usr/share/Modules/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
53
+ commit_issue : 1280
54
+ GH_TOKEN : ${{ github.token }}
55
+ NEOReadDebugKeys : ${{ inputs.driver == 'rolling' && '1' || '0' }}
56
+ DisableScratchPages : ${{ inputs.driver == 'rolling' && '1' || '0' }}
47
57
outputs :
48
58
TORCH_COMMIT_ID : ${{ steps.build_version.outputs.TORCH_COMMIT_ID }}
49
59
timeout-minutes : 900
50
- env :
51
- commit_issue : 1280
52
- GH_TOKEN : ${{ github.token }}
53
- NEOReadDebugKeys : ${{ inputs.driver == 'rolling' && '1' || '0' }}
54
- DisableScratchPages : ${{ inputs.driver == 'rolling' && '1' || '0' }}
55
60
steps :
61
+ - name : Setup based env
62
+ run : |
63
+ # Cleanup workspace
64
+ rm -rf ${{ github.workspace }}/*
65
+ # Install gh
66
+ dnf install 'dnf-command(config-manager)'
67
+ dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
68
+ dnf autoremove -y git236* && dnf install -y git
69
+ dnf install gh --repo gh-cli -y
70
+ # Setup python
71
+ local_python=$(echo ${{ inputs.python }} |awk -F. '{printf("cp%s%s-cp%s%s", $1, $2, $1, $2)}')
72
+ /opt/python/${local_python}/bin/python -m venv /opt/xpu-build
73
+ which python && python -V && pip list
74
+ pip install -U pip wheel setuptools
56
75
- name : Checkout torch-xpu-ops
57
76
uses : actions/checkout@v4
58
- - name : Prepare Stock Pytorch
59
- run : |
60
- pwd
61
- which conda && conda clean -ay
62
- conda remove --all -y -n xpu_build || \
63
- rm -rf $(dirname ${CONDA_EXE})/../envs/xpu_build
64
- conda create -n xpu_build python=${{ inputs.python }} cmake=3.28 ninja -y
65
- source activate xpu_build
66
- cd ../ && rm -rf pytorch
67
- pip install requests
68
- git clone https://github.com/pytorch/pytorch pytorch
69
- cd pytorch && git checkout $(echo ${{ inputs.pytorch }})
70
- # apply PRs for stock pytorch
71
- python ../torch-xpu-ops/.github/scripts/apply_torch_pr.py
72
- git status && git show -s
73
- git submodule sync && git submodule update --init --recursive
74
- if [[ ${{ inputs.keep_torch_xpu_ops }} == 'true' ]]; then
75
- echo "Don't replace torch-xpu-ops!"
76
- else
77
- rm -rf third_party/torch-xpu-ops && cp -r ../torch-xpu-ops third_party/
78
- # Workaround for torch-xpu-ops ci test
79
- sed -i "s/checkout --quiet \${TORCH_XPU_OPS_COMMIT}/log -n 1/g" caffe2/CMakeLists.txt
80
- fi
77
+ with :
78
+ path : torch-xpu-ops
81
79
- name : Build Pytorch XPU
82
80
run : |
83
81
set -xe
84
- source activate xpu_build
85
- source .github/scripts/env.sh ${{ inputs.pytorch }}
86
- export USE_ONEMKL=1
87
- export USE_XCCL=1
88
- if [[ ${{ inputs.driver }} == 'lts' ]]; then
89
- export TORCH_XPU_ARCH_LIST='pvc'
82
+ if [ "${{ inputs.driver }}" == "lts" ]; then
83
+ export TORCH_XPU_ARCH_LIST='pvc'
84
+ fi
85
+ if [[ "${{ inputs.pytorch }}" == *"https://"* ]];then
86
+ PYTORCH_REPO="$(echo ${{ inputs.pytorch }} |sed 's/@.*//')"
87
+ PYTORCH_VERSION="$(echo ${{ inputs.pytorch }} |sed 's/.*@//')"
88
+ else
89
+ PYTORCH_REPO="https://github.com/pytorch/pytorch.git"
90
+ PYTORCH_VERSION="${{ inputs.pytorch }}"
91
+ fi
92
+ if [[ "${{ inputs.keep_torch_xpu_ops }}" == *"https://"* ]];then
93
+ TORCH_XPU_OPS_REPO="$(echo ${{ inputs.keep_torch_xpu_ops }} |sed 's/@.*//')"
94
+ TORCH_XPU_OPS_VERSION="$(echo ${{ inputs.keep_torch_xpu_ops }} |sed 's/.*@//')"
95
+ elif [ "${{ inputs.keep_torch_xpu_ops }}" == "true" ];then
96
+ TORCH_XPU_OPS_VERSION="pinned"
97
+ else
98
+ TORCH_XPU_OPS_VERSION="cicd"
90
99
fi
91
- pip install mkl-static==2025.0.1 mkl-include==2025.0.1
100
+ # oneAPI DLE
101
+ source ${{ github.workspace }}/torch-xpu-ops/.github/scripts/env.sh
102
+ icpx --version
103
+ # gcc 11
104
+ source /opt/rh/gcc-toolset-11/enable
105
+ build_status="$(
106
+ ${{ github.workspace }}/torch-xpu-ops/.github/scripts/build.sh \
107
+ --WORKSPACE="${{ github.workspace }}" \
108
+ --PYTORCH_REPO="${PYTORCH_REPO}" \
109
+ --PYTORCH_VERSION="${PYTORCH_VERSION}" \
110
+ --TORCH_XPU_OPS_REPO="${TORCH_XPU_OPS_REPO}" \
111
+ --TORCH_XPU_OPS_VERSION="${TORCH_XPU_OPS_VERSION}" \
112
+ > ${{ github.workspace }}/pytorch_build_${PYTORCH_VERSION//\//-}.log 2>&1 && echo $? || echo $?
113
+ )"
114
+ tail -n 100 ${{ github.workspace }}/pytorch_build_${PYTORCH_VERSION//\//-}.log
92
115
build_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
93
116
repo="${{ github.repository }}"
94
117
last_commit=$(gh --repo $repo issue view $commit_issue --json body -q .body | grep ${{ inputs.pytorch }} | cut -d'[' -f 2 | cut -d']' -f 1)
95
- cd ../pytorch
96
- current_commit=$(git rev-parse HEAD)
118
+ current_commit=$(cat ${{ github.workspace }}/pytorch.commit)
97
119
is_fork_pr=false
98
120
if [ -n "${{ github.event.pull_request }}" ] && [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
99
121
is_fork_pr=true
100
122
fi
101
123
echo ">>>>>>>>>>>>Fork PR: ${is_fork_pr}, pytorch branch: ${{ inputs.pytorch }}, last commit: ${last_commit}, current commit: ${current_commit}"
102
-
103
- export CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}:${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
104
- pip install -r requirements.txt
105
- WERROR=1 python setup.py bdist_wheel 2>&1 | tee pytorch_${current_commit}_build.log
106
-
107
124
if [[ "${is_fork_pr}" == "false" ]]; then
108
- if [ -f dist/torch*.whl ] && \
125
+ if [ "${build_status}" == "0" ] && \
109
126
[ "${{ inputs.update_lkg }}" == "true" ] && \
110
127
[ "${last_commit}" != "${current_commit}" ] && \
111
128
[[ "${{ inputs.pytorch }}" == "main" || "${{ inputs.pytorch }}" == "release/"* ]]; then
@@ -114,55 +131,34 @@ jobs:
114
131
gh --repo $repo issue edit $commit_issue --body-file new_body.txt
115
132
gh --repo $repo issue comment $commit_issue -b "Update LKG torch, refer ${build_url}"
116
133
fi
117
- if [ ! -f dist /torch*.whl ]; then
134
+ if [ ! -f ${{ github.workspace }} /torch*.whl ] && [ "${TORCH_XPU_OPS_VERSION}" == "cicd" ]; then
118
135
echo "Wheel build failed, use last commit in the issue https://github.com/intel/torch-xpu-ops/issues/1280"
119
136
gh --repo $repo issue comment $commit_issue -b "Wheel build failed with commit [${current_commit}](https://github.com/pytorch/pytorch/tree/${current_commit}), refer ${build_url}. CC @intel/torch-xpu-ops-maintain @EikanWang @riverliuintel @fengyuan14 @xytintel @etaf @chuanqi129 @mengfei25"
120
- python setup.py clean
121
- git clean -df .
122
- git reset --hard
123
- git checkout $last_commit
124
- # apply PRs for stock pytorch
125
- python ../torch-xpu-ops/.github/scripts/apply_torch_pr.py
126
- git status && git show -s
127
- git submodule sync && git submodule update --init --recursive
128
- if [[ ${{ inputs.keep_torch_xpu_ops }} == 'true' ]]; then
129
- echo "Don't replace torch-xpu-ops!"
130
- else
131
- rm -rf third_party/torch-xpu-ops && cp -r ../torch-xpu-ops third_party/
132
- # Workaround for torch-xpu-ops ci test
133
- sed -i "s/checkout --quiet \${TORCH_XPU_OPS_COMMIT}/log -n 1/g" caffe2/CMakeLists.txt
134
- fi
135
- WERROR=1 python setup.py bdist_wheel
137
+ build_status="$(
138
+ ${{ github.workspace }}/torch-xpu-ops/.github/scripts/build.sh \
139
+ --WORKSPACE="${{ github.workspace }}" \
140
+ --PYTORCH_REPO="https://github.com/pytorch/pytorch.git" \
141
+ --PYTORCH_VERSION="${last_commit}" \
142
+ --TORCH_XPU_OPS_REPO="${TORCH_XPU_OPS_REPO}" \
143
+ --TORCH_XPU_OPS_VERSION="${TORCH_XPU_OPS_VERSION}" \
144
+ >> ${{ github.workspace }}/pytorch_build_${last_commit}.log 2>&1 && echo $? || echo $?
145
+ )"
146
+ tail -n 100 ${{ github.workspace }}/pytorch_build_${last_commit}.log
136
147
fi
137
148
else
138
149
echo "Forked PR, don't update the issue"
139
150
fi
140
- pip install --force-reinstall dist/*.whl
141
- cp dist/*.whl ${{ github.workspace }}/
142
- cp pytorch_${current_commit}_build.log ${{ github.workspace }}/
151
+ exit ${build_status}
143
152
- name : Torch Config
144
153
run : |
145
- source activate xpu_build
146
- source .github/scripts/env.sh ${{ inputs.pytorch }}
147
154
python -c "import torch; print(torch.__config__.show())"
148
155
python -c "import torch; print(torch.__config__.parallel_info())"
149
156
python -c "import torch; print(torch.__config__.torch.xpu.device_count())"
150
- cd ..
151
157
python pytorch/torch/utils/collect_env.py
152
158
- name : Identify Build version
153
159
id : build_version
154
160
run : |
155
- source .github/scripts/env.sh
156
- cd ../pytorch
157
- echo "TORCH_BRANCH_ID=$(git rev-parse --abbrev-ref HEAD)" |tee -a "${GITHUB_OUTPUT}" >> "${GITHUB_ENV}"
158
- echo "TORCH_COMMIT_ID=$(git rev-parse HEAD)" |tee -a "${GITHUB_OUTPUT}" >> "${GITHUB_ENV}"
159
- echo "DRIVER_VERSION=$(sycl-ls |grep 'opencl:gpu' |awk '{print $NF}' |sort |uniq -c |sed 's/ //g;s/\[/*[/')" |tee -a "${GITHUB_OUTPUT}" >> "${GITHUB_ENV}"
160
- echo "KERNEL_VERSION=$(uname -rv 2>&1)" |tee -a "${GITHUB_OUTPUT}" >> "${GITHUB_ENV}"
161
- echo "BUNDLE_VERSION=$(icpx --version 2>&1 |grep 'DPC++/C++' |sed 's/.*(//;s/).*//')" |tee -a "${GITHUB_OUTPUT}" >> "${GITHUB_ENV}"
162
- . /etc/os-release
163
- echo "OS_PRETTY_NAME=${PRETTY_NAME}" |tee -a "${GITHUB_OUTPUT}" >> "${GITHUB_ENV}"
164
- echo "GCC_VERSION=$(gcc -dumpversion)" |tee -a "${GITHUB_OUTPUT}" >> "${GITHUB_ENV}"
165
- echo ${GITHUB_ENV}
161
+ echo "TORCH_COMMIT_ID=$(python -c 'import torch; print(torch.version.git_version)')" |tee -a "${GITHUB_OUTPUT}"
166
162
- name : Upload Torch XPU Wheel
167
163
if : ${{ ! cancelled() }}
168
164
uses : actions/upload-artifact@v4
@@ -175,3 +171,8 @@ jobs:
175
171
with :
176
172
name : Torch-XPU-Build-Log-${{ github.event.pull_request.number || github.sha }}
177
173
path : ${{ github.workspace }}/pytorch_*.log
174
+ - name : Cleanup
175
+ if : always()
176
+ run : |
177
+ chmod 777 . -R
178
+ rm -rf pytorch torch-xpu-ops pytorch_*.log torch*.whl
0 commit comments