Using YDF on ARM64 Linux
Because prebuilt YDF packages do not support ARM64 Linux, YDF must be built and installed from source.
sudo apt install -y build-essential git python3-dev
Install the Bazel build tool (via Bazelisk):
mkdir -p ~/bin
curl -L -o ~/bin/bazel https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-arm64
chmod +x ~/bin/bazel; export PATH=~/bin:$PATH
cd ~/works
git clone --depth 1 https://github.com/google/yggdrasil-decision-forests.git
cd yggdrasil-decision-forests/yggdrasil_decision_forests/port/python
Update yggdrasil_decision_forests/port/python/tools/BUILD and dev_requirements.txt to add ARM64 Linux support:
$ git diff tools/BUILD
diff --git a/yggdrasil_decision_forests/port/python/tools/BUILD b/yggdrasil_decision_forests/port/python/tools/BUILD
index 0abd338..4c7403a 100644
--- a/yggdrasil_decision_forests/port/python/tools/BUILD
+++ b/yggdrasil_decision_forests/port/python/tools/BUILD
@@ -35,6 +35,16 @@ config_setting(
],
)
+# Added :Linux ARM64
+config_setting(
+ name = "linux_aarch64",
+ constraint_values = [
+ "@platforms//os:linux",
+ "@platforms//cpu:aarch64",
+ ],
+)
+
+
config_setting(
name = "macos_arm64",
constraint_values = [
@@ -43,6 +53,7 @@ config_setting(
],
)
+
# Python and ABI tag of the wheel, e.g. "cp312" (see PYTHON_VERSIONS in
# MODULE.bazel).
PYTHON_TAG = select(
@@ -89,8 +100,9 @@ py_wheel(
license = "Apache 2.0",
platform = select(
{
- ":linux_x86_64": "manylinux_2_27_x86_64",
- ":macos_arm64": "macosx_12_0_arm64",
+ ":linux_x86_64": "manylinux_2_27_x86_64",
+ ":linux_aarch64": "manylinux_2_27_aarch64",
+ ":macos_arm64": "macosx_12_0_arm64",
},
no_match_error = "Unsupported platform for the YDF wheel.",
),
$ git diff dev_requirements.txt
diff --git a/yggdrasil_decision_forests/port/python/dev_requirements.txt b/yggdrasil_decision_forests/port/python/dev_requirements.txt
index cf16a7f..0c83c11 100644
--- a/yggdrasil_decision_forests/port/python/dev_requirements.txt
+++ b/yggdrasil_decision_forests/port/python/dev_requirements.txt
@@ -6,11 +6,11 @@ urllib3
tensorflow; platform_machine != 'aarch64' and python_version >= '3.9' and python_version < '3.13'
portpicker
scikit-learn
-jax; platform_system != 'Windows' and (platform_machine != 'aarch64' or platform_system == 'Darwin')
-jaxlib; platform_system != 'Windows' and (platform_machine != 'aarch64' or platform_system == 'Darwin')
+jax; platform_system != 'Windows'
+jaxlib; platform_system != 'Windows'
jaxtyping
-optax; platform_system != 'Windows' and (platform_machine != 'aarch64' or platform_system == 'Darwin')
-flax; platform_system != 'Windows' and (platform_machine != 'aarch64' or platform_system == 'Darwin')
+optax; platform_system != 'Windows'
+flax; platform_system != 'Windows'
flatbuffers; platform_machine != 'aarch64' and platform_system != 'Windows' and python_version >= '3.12'
tensorflow-datasets; platform_machine != 'aarch64' and platform_system != 'Windows' and python_version >= '3.9'
grain; platform_machine != 'aarch64' and platform_system == 'Linux' and python_version >= '3.10' and python_version < '3.13'
Update the requirements as follows:
bazel run //:requirements.update
Build the wheel package:
bazel build --config=local_cc --jobs=2 \
--@rules_python//python/config_settings:python_version=3.12 \
//tools:wheel
Once the build completes, verify the installation in a temporary virtual environment:
python -m venv ~/venvs/ydf-arm64
source ~/venvs/ydf-arm64/bin/activate
python -m pip install --upgrade pip
python -m pip install \
~/works/yggdrasil-decision-forests/yggdrasil_decision_forests/port/python/bazel-bin/tools/ydf-0.17.0-cp312-cp312-manylinux_2_27_aarch64.whl
After installation, run the following command to test the import:
python -c "import ydf; print('YDF import successful')"
The installation is successful if the following output appears:
$ python -c "import ydf; print('YDF import successful')"
YDF import successful