File size: 1,530 Bytes
fac4d07 | 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 | #!/usr/bin/env bash
# Provision the native libraries required by tch 0.22 on Apple Silicon.
# The official PyTorch wheel is only an archive source: no Python is installed
# or executed, and only C++ headers and shared libraries are extracted.
set -euo pipefail
# Resolve paths against the checkout, independent of the caller's directory.
project_root="$(cd "$(dirname "$0")/.." && pwd)"
# Keep the downloaded archive and extracted libraries outside published files.
native_root="${project_root}/.libtorch/2.9.0"
native_archive="${native_root}/torch-native.whl"
# Pin the official PyPI artifact and its independently published SHA-256.
native_url='https://files.pythonhosted.org/packages/b3/b7/205ef3e94de636feffd64b28bb59a0dfac0771221201b9871acf9236f5ca/torch-2.9.0-cp311-none-macosx_11_0_arm64.whl'
native_sha='614a185e4986326d526a91210c8fc1397e76e8cfafa78baf6296a790e53a9eec'
if [[ "$(uname -s)" != Darwin || "$(uname -m)" != arm64 ]]; then
printf '%s\n' 'This provisioning script targets macOS arm64. On other platforms, install LibTorch 2.9.0 and set LIBTORCH to its root.' >&2
exit 1
fi
mkdir -p "${native_root}"
if [[ ! -f "${native_archive}" ]]; then
curl --fail --location --retry 3 "${native_url}" --output "${native_archive}.partial"
mv "${native_archive}.partial" "${native_archive}"
fi
printf '%s %s\n' "${native_sha}" "${native_archive}" | shasum -a 256 -c -
unzip -q -o "${native_archive}" 'torch/include/*' 'torch/lib/*' -d "${native_root}"
printf 'export LIBTORCH="%s/torch"\n' "${native_root}"
|