TensorFlow CPU (AWS ARM64 optimized)
TensorFlow is an open-source machine learning framework. The `tensorflow-cpu-aws` package is a distribution of TensorFlow specifically optimized for CPU (ARM64/Aarch64) architectures, built and maintained by AWS. It is typically installed automatically as a dependency when the generic `tensorflow` package is installed on an ARM-based system. The current version is 2.15.1, and its release cadence generally aligns with the main TensorFlow releases.
Common errors
-
ERROR: Could not find a version that satisfies the requirement tensorflow-cpu-aws (from versions: none)
cause Attempting to install `tensorflow-cpu-aws` directly on an x86_64 system where only ARM64/Aarch64 wheels are available.fixOn x86_64, use `pip install tensorflow` or `pip install tensorflow-cpu`. If on an ARM64/Aarch64 system, this error can also occur if the specific version requested is not yet available, or if Python version compatibility is an issue. Ensure your Python version (>=3.9) is supported. -
tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape [...] and type float on /job:localhost/replica:0/task:0/device:CPU:0 by allocator cpu
cause The TensorFlow operation attempted to allocate more memory than available on the CPU, common in under-provisioned environments like smaller AWS EC2 instances.fixIncrease the memory and CPU resources of your AWS EC2 instance. Review your model architecture and batch sizes; reduce them if possible. Ensure your dataset fits into memory. -
Killed
cause The `pip install` process was terminated by the operating system, typically due to running out of memory (OOM killer) or other resource constraints on the host machine (e.g., an AWS EC2 instance).fixUse an AWS EC2 instance with more memory. Consider using `pip install --no-cache-dir tensorflow-cpu-aws` to reduce temporary disk usage during installation.
Warnings
- breaking For TensorFlow versions 2.16 and later, the `tensorflow` package's metadata has sometimes incorrectly specified a tight dependency on a `tensorflow-cpu-aws` version (e.g., `tensorflow-cpu-aws==2.16.1`) that might not yet be released. This can lead to dependency resolution failures during installation on ARM64/Aarch64 machines.
- gotcha The `tensorflow-cpu-aws` package is specifically compiled for ARM64/Aarch64 processors. Attempting to install this package directly on an x86_64 architecture will result in a 'No matching distribution found' error, as compatible wheels are not available for that platform.
- gotcha Running TensorFlow on under-provisioned AWS EC2 instances (e.g., free-tier `t2.micro`) can lead to `ResourceExhaustedError: OOM when allocating tensor` or the `pip install` process being 'killed' due to insufficient RAM or CPU.
- gotcha TensorFlow may not fully utilize all available CPU cores on multi-core instances by default, potentially leading to lower-than-expected performance.
Install
-
pip install tensorflow-cpu-aws -
pip install tensorflow
Imports
- tensorflow
import tensorflow as tf
- keras
from tensorflow import keras
Quickstart
import tensorflow as tf
# Verify TensorFlow installation and basic operation
print("TensorFlow version:", tf.__version__)
print("Is GPU available:", tf.config.list_physical_devices('GPU'))
# Create a simple constant tensor
hello = tf.constant('Hello from TensorFlow-CPU-AWS!')
print(hello.numpy().decode('utf-8'))
# Perform a basic operation
a = tf.constant(10)
b = tf.constant(32)
print("a + b =", tf.add(a, b).numpy())
# Example with Keras (MNIST dataset)
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)
])
predictions = model(x_train[:1]).numpy()
print("Sample predictions shape:", predictions.shape)