Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .github/workflows/torch_c_dlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ jobs:
with:
name: pypi-wheels-linux-${{ matrix.arch }}-${{ matrix.python-version }}
path: ./wheelhouse/*.whl
build_wheels_macos:
strategy:
fail-fast: false
matrix:
arch: ["arm64"]
python-version: ["cp39", "cp310", "cp311", "cp312", "cp313", "cp314"]
runs-on: macos-14
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
- name: build torch libs and wheels
working-directory: ./tvm-ffi
run: |
bash ./addons/torch_c_dlpack_ext/build_aot_wheels.sh ${{ matrix.arch }} ${{ matrix.python-version }}
- uses: actions/upload-artifact@v4
with:
name: pypi-wheels-macos-${{ matrix.arch }}-${{ matrix.python-version }}
path: ./tvm-ffi/addons/torch_c_dlpack_ext/wheelhouse/*.whl
build_source:
runs-on: ubuntu-latest
steps:
Expand All @@ -90,7 +114,7 @@ jobs:
name: pypi-source
path: ./tvm-ffi/addons/torch_c_dlpack_ext/dist/*tar.gz
upload_pypi:
needs: [build_wheels_linux, build_source]
needs: [build_wheels_linux, build_wheels_macos, build_source]
runs-on: ubuntu-latest
environment: pypi
permissions:
Expand Down
44 changes: 35 additions & 9 deletions addons/torch_c_dlpack_ext/build_aot_wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ set -eux
arch=$1
python_version=$2

os=$(uname -s)

case "$os" in
"Linux" | "Darwin")
;;
*)
echo "Unknown OS: $os"
return 1
;;
esac

tvm_ffi="$PWD"
torch_c_dlpack_ext="$tvm_ffi"/addons/torch_c_dlpack_ext

Expand Down Expand Up @@ -54,7 +65,10 @@ function check_availability() {
"2.4")
! [[ "$arch" == "aarch64" || "$python_version" == "cp313" || "$python_version" == "cp314" ]]
;;
"2.5" | "2.6")
"2.5")
! [[ ("$os" == "Linux" && ("$arch" == "aarch64" || "$python_version" == "cp314")) || ("$os" == "Darwin" && ("$python_version" == "cp313" || "$python_version" == "cp314")) ]]
;;
"2.6")
! [[ "$arch" == "aarch64" || "$python_version" == "cp314" ]]
;;
"2.7" | "2.8")
Expand All @@ -74,15 +88,19 @@ function check_availability() {
function build_libs() {
local torch_version=$1
if check_availability "$torch_version"; then
mkdir "$tvm_ffi"/.venv -p
uv venv "$tvm_ffi"/.venv/torch"$torch_version" --python "$python_version"
source "$tvm_ffi"/.venv/torch"$torch_version"/bin/activate
uv pip install setuptools ninja
uv pip install torch=="$torch_version" --index-url "$(get_torch_url "$torch_version")"
if [[ "$os" == "Linux" ]]; then
uv pip install torch=="$torch_version" --index-url "$(get_torch_url "$torch_version")"
else
uv pip install torch=="$torch_version"
fi
uv pip install -v .
mkdir "$tvm_ffi"/lib -p
python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir "$tvm_ffi"/lib
python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir "$tvm_ffi"/lib --build-with-cuda
if [[ "$os" == "Linux" ]]; then
python -m tvm_ffi.utils._build_optional_torch_c_dlpack --output-dir "$tvm_ffi"/lib --build-with-cuda
fi
ls "$tvm_ffi"/lib
deactivate
rm -rf "$tvm_ffi"/.venv/torch"$torch_version"
Expand All @@ -91,6 +109,8 @@ function build_libs() {
fi
}

mkdir -p "$tvm_ffi"/.venv
mkdir -p "$tvm_ffi"/lib
torch_versions=("2.4" "2.5" "2.6" "2.7" "2.8" "2.9")
for version in "${torch_versions[@]}"; do
build_libs "$version"
Expand All @@ -99,11 +119,17 @@ done
cp "$tvm_ffi"/lib/*.so "$torch_c_dlpack_ext"/torch_c_dlpack_ext
uv venv "$tvm_ffi"/.venv/build --python "$python_version"
source "$tvm_ffi"/.venv/build/bin/activate
uv pip install build wheel auditwheel
uv pip install build wheel
cd "$torch_c_dlpack_ext"
python -m build -w
ls dist
python -m wheel tags dist/*.whl --python-tag="$python_version" --abi-tag="$python_version" --remove
ls dist
auditwheel repair --exclude libtorch.so --exclude libtorch_cpu.so --exclude libc10.so --exclude libtorch_python.so dist/*.whl -w wheelhouse
if [[ "$os" == "Linux" ]]; then
python -m wheel tags dist/*.whl --python-tag="$python_version" --abi-tag="$python_version" --remove
uv pip install auditwheel
auditwheel repair --exclude libtorch.so --exclude libtorch_cpu.so --exclude libc10.so --exclude libtorch_python.so --exclude libtorch_cuda.so --exclude libc10_cuda.so dist/*.whl -w wheelhouse
else
python -m wheel tags dist/*.whl --python-tag="$python_version" --abi-tag="$python_version" --platform-tag=macosx_11_0_arm64 --remove
uv pip install delocate
delocate-wheel -v --ignore-missing-dependencies --exclude libtorch.dylib,libtorch_cpu.dylib,libc10.dylib,libtorch_python.dylib dist/*.whl -w wheelhouse

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--exclude might be redundant here, as the building venv does not contain torch related lib. and delocate-wheel will still ask for these libs. actually --ignore-missing-dependencies depresses the such missing libs.

fi
ls wheelhouse
2 changes: 0 additions & 2 deletions addons/torch_c_dlpack_ext/build_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
def _is_lib_prebuilt() -> bool:
if sys.platform.startswith("win32"):
extension = "dll"
elif sys.platform.startswith("darwin"):
extension = "dylib"
else:
extension = "so"
return next(_package_path.rglob(f"*.{extension}"), None) is not None
Expand Down