TensorFlow for AArch64
TensorFlow for AArch64 is an open-source machine learning framework providing a flexible architecture for high-performance numerical computation on ARM 64-bit systems. Since TensorFlow 2.10, official Linux CPU builds for AArch64/ARM64 processors are built, maintained, tested, and released by a third-party collaboration including AWS, ARM, and Linaro. The current version is 2.16.1. It follows the main TensorFlow release cadence.
Common errors
-
ImportError: /usr/lib/aarch64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.22' not found
cause The installed `libstdc++` library is older than what TensorFlow requires, often seen on older Linux distributions.fixUpgrade your `libstdc++6` package. For Ubuntu/Debian, this might involve adding a newer toolchain repository and upgrading: `sudo add-apt-repository ppa:ubuntu-toolchain-r/test && sudo apt update && sudo apt install --only-upgrade libstdc++6`. -
ERROR: Could not find a version that satisfies the requirement tensorflow-aarch64 (from versions: none)
cause This typically means your Python version is incompatible with the available `tensorflow-aarch64` wheels on PyPI, or your `pip` is outdated, or you are on an unsupported AArch64 variant.fix1. Ensure you have a 64-bit Python (`python3 -c 'import sys; print(sys.maxsize > 2**32)'` should output `True`). 2. Check your Python version against TensorFlow's requirements (e.g., TF 2.16.1 requires >=3.9). 3. Upgrade pip: `python3 -m pip install --upgrade pip`. -
failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
cause TensorFlow cannot detect an NVIDIA GPU, often due to incompatible CUDA Toolkit/cuDNN versions, missing NVIDIA drivers, or incorrect environment setup (e.g., `LD_LIBRARY_PATH`).fix1. Verify NVIDIA drivers are installed and up-to-date (`nvidia-smi`). 2. Ensure your CUDA Toolkit and cuDNN versions are compatible with your TensorFlow version (check official TensorFlow GPU installation guide). 3. Set necessary environment variables, especially `LD_LIBRARY_PATH` to include CUDA library paths. You might also need to downgrade TensorFlow or CUDA if versions are incompatible. -
ERROR: Failed building wheel for h5py
cause During `pip install`, `h5py` (a common dependency) fails to build from source because necessary HDF5 development libraries are missing on the system.fixInstall the HDF5 development libraries: `sudo apt-get install libhdf5-dev` (for Debian/Ubuntu) or equivalent for your distribution. Then retry the `pip install` command.
Warnings
- breaking Starting with TensorFlow 2.10, Linux CPU-builds for Aarch64/ARM64 processors are built, maintained, and released by a third party (AWS). This change might affect users who relied on previous community-built `tensorflow-aarch64` packages.
- breaking TensorFlow has specific Python version requirements. TensorFlow 2.16.1 requires Python >=3.9. Future versions (e.g., TF 2.21) will remove support for Python 3.9.
- gotcha The default Keras version in TensorFlow 2.16 and later is Keras 3.0. If your existing code relies on Keras 2.0 specific behaviors or APIs, it might break.
- gotcha When checking the type of a TensorFlow tensor, relying on exact type checking (e.g., `type(t) == tf.Tensor`) might fail due to changes in class hierarchy (explicit `EagerTensor` and `SymbolicTensor` classes).
- gotcha Some AArch64 systems may encounter `cannot allocate memory in static TLS block` errors related to `libgomp` when running TensorFlow.
Install
-
pip install tensorflow-aarch64 -
pip install tensorflow-aarch64 tensorflow_io
Imports
- tensorflow
import tensorflow as tf
Quickstart
import tensorflow as tf
print("TensorFlow version:", tf.__version__)
# Check for GPU devices (will be empty if only CPU is available)
gpus = tf.config.list_physical_devices('GPU')
if gpus:
print(f"Detected GPUs: {gpus}")
else:
print("No GPU devices found.")
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10)
])
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
model.compile(optimizer='adam', loss=loss_fn, metrics=['accuracy'])
print("\nTraining model...")
model.fit(x_train, y_train, epochs=1)
print("\nEvaluating model...")
model.evaluate(x_test, y_test, verbose=2)