-
Notifications
You must be signed in to change notification settings - Fork 90
218 lines (215 loc) · 9.76 KB
/
Copy pathtorch_c_dlpack.yml
File metadata and controls
218 lines (215 loc) · 9.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: torch c dlpack
on:
workflow_dispatch:
inputs:
branch:
description: "Branch or tag to publish (manual run)"
required: true
jobs:
build_libs:
strategy:
fail-fast: false
matrix:
arch: ["x86_64", "aarch64"]
python-version: ["cp39", "cp310", "cp311", "cp312", "cp313"]
runs-on: ${{ matrix.arch == 'aarch64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
steps:
- uses: jlumbroso/free-disk-space@main
if: ${{ matrix.arch == 'x86_64'}}
- uses: actions/checkout@v5
with:
repository: apache/tvm-ffi
ref: main
fetch-depth: 0
submodules: recursive
path: tvm-ffi
- name: prepare docker environment
run: |
docker pull quay.io/pypa/manylinux_2_28_${{ matrix.arch }}:latest
docker run --name build_lib -d quay.io/pypa/manylinux_2_28_${{ matrix.arch }}:latest tail -f /dev/null
docker cp tvm-ffi build_lib:/tvm-ffi
wget https://developer.download.nvidia.com/compute/cuda/13.0.2/local_installers/cuda-repo-rhel8-13-0-local-13.0.2_580.95.05-1.${{ matrix.arch }}.rpm > /dev/null 2>&1
docker cp cuda-repo-rhel8-13-0-local-13.0.2_580.95.05-1.${{ matrix.arch }}.rpm build_lib:/
rm cuda-repo-rhel8-13-0-local-13.0.2_580.95.05-1.${{ matrix.arch }}.rpm
docker exec build_lib bash -c "rpm -i /cuda-repo-rhel8-13-0-local-13.0.2_580.95.05-1.${{ matrix.arch }}.rpm \
&& dnf clean all \
&& dnf -y install cuda-toolkit-13-0 \
&& rm /cuda-repo-rhel8-13-0-local-13.0.2_580.95.05-1.${{ matrix.arch }}.rpm \
&& dnf clean all \
&& mkdir /libs"
- name: build torch 2.4 lib
if: ${{ matrix.python-version != 'cp313' && matrix.python-version != 'cp314' && matrix.arch != 'aarch64' }}
run: |
docker exec build_lib bash -c "uv venv /torch2.4 --python ${{ matrix.python-version }} \
&& source /torch2.4/bin/activate \
&& uv pip install setuptools ninja \
&& uv pip install torch==2.4 --index-url https://download.pytorch.org/whl/cu124 \
&& cd /tvm-ffi \
&& uv pip install -v . \
&& python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir /libs \
&& python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir /libs --build-with-cuda \
&& rm -rf /torch2.4"
- name: build torch 2.5 lib
if: ${{ matrix.python-version != 'cp314' && matrix.arch != 'aarch64' }}
run: |
docker exec build_lib bash -c "uv venv /torch2.5 --python ${{ matrix.python-version }} \
&& source /torch2.5/bin/activate \
&& uv pip install setuptools ninja \
&& uv pip install torch==2.5 --index-url https://download.pytorch.org/whl/cu124 \
&& cd /tvm-ffi \
&& uv pip install -v . \
&& python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir /libs \
&& python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir /libs --build-with-cuda \
&& rm -rf /torch2.5"
- name: build torch 2.6 lib
if: ${{ matrix.python-version != 'cp314' && matrix.arch != 'aarch64' }}
run: |
docker exec build_lib bash -c "uv venv /torch2.6 --python ${{ matrix.python-version }} \
&& source /torch2.6/bin/activate \
&& uv pip install setuptools ninja \
&& uv pip install torch==2.6 --index-url https://download.pytorch.org/whl/cu126 \
&& cd /tvm-ffi \
&& uv pip install -v . \
&& python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir /libs \
&& python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir /libs --build-with-cuda \
&& rm -rf /torch2.6"
- name: build torch 2.7 lib
if: ${{ matrix.python-version != 'cp314' }}
run: |
docker exec build_lib bash -c "uv venv /torch2.7 --python ${{ matrix.python-version }} \
&& source /torch2.7/bin/activate \
&& uv pip install setuptools ninja \
&& uv pip install torch==2.7 --index-url https://download.pytorch.org/whl/cu128 \
&& cd /tvm-ffi \
&& uv pip install -v . \
&& python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir /libs \
&& python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir /libs --build-with-cuda \
&& rm -rf /torch2.7"
- name: build torch 2.8 lib
if: ${{ matrix.python-version != 'cp314' }}
run: |
docker exec build_lib bash -c "uv venv /torch2.8 --python ${{ matrix.python-version }} \
&& source /torch2.8/bin/activate \
&& uv pip install setuptools ninja \
&& uv pip install torch==2.8 --index-url https://download.pytorch.org/whl/cu129 \
&& cd /tvm-ffi \
&& uv pip install -v . \
&& python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir /libs \
&& python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir /libs --build-with-cuda \
&& rm -rf /torch2.8"
- name: build torch 2.9 lib
if: ${{ matrix.python-version != 'cp39' }}
run: |
docker exec build_lib bash -c "uv venv /torch2.9 --python ${{ matrix.python-version }} \
&& source /torch2.9/bin/activate \
&& uv pip install setuptools ninja \
&& uv pip install torch==2.9 --index-url https://download.pytorch.org/whl/cu129 \
&& cd /tvm-ffi \
&& uv pip install -v . \
&& python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir /libs \
&& python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir /libs --build-with-cuda \
&& rm -rf /torch2.9"
- name: collect built libs
run: |
mkdir libs
docker cp build_lib:/libs .
- uses: actions/upload-artifact@v4
with:
name: libs-${{ matrix.arch }}-${{ matrix.python-version }}
path: ./libs/*.so
build_wheels:
needs: build_libs
strategy:
matrix:
arch: ["x86_64", "aarch64"]
python-version: ["cp39", "cp310", "cp311", "cp312", "cp313"]
runs-on: ${{ matrix.arch == 'aarch64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
container: quay.io/pypa/manylinux_2_28_${{ matrix.arch }}
steps:
- uses: actions/checkout@v5
with:
repository: apache/tvm-ffi
ref: main
fetch-depth: 0
submodules: recursive
path: tvm-ffi
- uses: actions/download-artifact@v4
with:
pattern: libs-${{ matrix.arch }}-${{ matrix.python-version }}
path: ./tvm-ffi/addons/torch_c_dlpack_ext/torch_c_dlpack_ext
merge-multiple: true
- name: build wheels
run: |
/opt/python/${{ matrix.python-version }}-${{ matrix.python-version }}/bin/pip3 install build wheel auditwheel
cd ./tvm-ffi/addons/torch_c_dlpack_ext
/opt/python/${{ matrix.python-version }}-${{ matrix.python-version }}/bin/python -m build -w
/opt/python/${{ matrix.python-version }}-${{ matrix.python-version }}/bin/python -m wheel tags dist/*.whl --python-tag=${{ matrix.python-version }} --abi-tag=${{ matrix.python-version }} --remove
auditwheel repair --exclude libtorch.so --exclude libtorch_cpu.so --exclude libc10.so --exclude libtorch_python.so dist/*.whl -w wheelhouse
- uses: actions/upload-artifact@v4
with:
name: pypi-wheels-${{ matrix.arch }}-${{ matrix.python-version }}
path: ./tvm-ffi/addons/torch_c_dlpack_ext/wheelhouse/*.whl
build_source:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
repository: apache/tvm-ffi
ref: main
fetch-depth: 0
submodules: recursive
path: tvm-ffi
- uses: astral-sh/setup-uv@v7
with:
python-version: "3.12"
activate-environment: true
- name: build source
run: |
uv pip install build
cd ./tvm-ffi/addons/torch_c_dlpack_ext
python -m build -s
- uses: actions/upload-artifact@v4
with:
name: pypi-source
path: ./tvm-ffi/addons/torch_c_dlpack_ext/dist/*tar.gz
upload_pypi:
needs: [build_wheels, build_source]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
attestations: write
# if: github.event_name == 'workflow_dispatch' # <-- publish only on manual trigger
steps:
- uses: actions/download-artifact@v4
with:
pattern: pypi-*
path: dist
merge-multiple: true
- name: Generate artifact attestation for sdist and wheels
uses: actions/attest-build-provenance@v1
with:
subject-path: dist/*
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
attestations: true
verbose: true
# testing publish url
# repository-url: https://test.pypi.org/legacy/