TensorFlow-Intel
TensorFlow-Intel is an optimized distribution of the open-source machine learning framework TensorFlow, specifically tailored for Intel CPUs. It leverages Intel's oneAPI Deep Neural Network Library (oneDNN) primitives to enhance performance for deep learning workloads. This package is compatible with existing TensorFlow code and is maintained by Intel in collaboration with Google, aiming to provide maximal performance on Intel architectures. It is actively developed with regular updates to support newer TensorFlow versions and Intel hardware.
Common errors
-
Could not find CUDA drivers on your machine, GPU will not be used.
cause This message is often benign when running `tensorflow-intel` on a CPU-only system or an Intel GPU system without NVIDIA CUDA. TensorFlow attempts to detect CUDA devices by default.fixIf you intend to use only the CPU or an Intel GPU (and have `Intel® Extension for TensorFlow*` installed and configured correctly), this message can usually be ignored. If you have an NVIDIA GPU, ensure CUDA and cuDNN are correctly installed and configured for TensorFlow. -
ModuleNotFoundError: No module named 'tensorflow' (or 'keras', 'absl-py')
cause The package or one of its core dependencies is not installed, or the Python environment is not correctly activated.fixEnsure you have activated the correct virtual environment and run `pip install tensorflow-intel`. If `absl-py` is specifically mentioned, `pip install absl-py` might be needed, though it's typically a transitive dependency. -
Could not find a version that satisfies the requirement tensorflow-intel==X.Y.Z
cause The specified version of `tensorflow-intel` is not available for your Python version, operating system, or architecture.fixCheck the available versions on PyPI for your specific Python version and OS (e.g., `pip install 'tensorflow-intel<2.11'` for older Windows GPU versions, or simply `pip install tensorflow-intel` for the latest compatible version). Consider upgrading your Python interpreter if needed, as `tensorflow-intel` requires Python >=3.9.
Warnings
- deprecated The separate `Intel® Optimization for TensorFlow*` package (`intel-tensorflow`) has been discontinued as of Q1 2024. Users should transition to `tensorflow-intel` or stock TensorFlow with `Intel® Extension for TensorFlow*` for Intel CPU optimizations.
- gotcha Installing `tensorflow` or `tensorflow-cpu` on Windows might automatically install `tensorflow-intel` to provide Intel optimizations. While generally beneficial, this can be unexpected for some users.
- gotcha Enabling oneAPI Deep Neural Network Library (oneDNN) optimizations required setting the environment variable `TF_ENABLE_ONEDNN_OPTS=1` for TensorFlow versions 2.5 through 2.8. Starting with TensorFlow v2.9 (and thus in `tensorflow-intel`), these optimizations are enabled by default.
- gotcha Attempting to install both `tensorflow-intel` and `intel-extension-for-tensorflow` in the same Python environment, or mixing `tensorflow-intel` with the old `intel-tensorflow` (Intel® Optimization for TensorFlow*), can lead to conflicts and undefined behavior.
Install
-
pip install tensorflow-intel
Imports
- tensorflow
import tensorflow as tf
- tensorflow.keras
from tensorflow import keras
Quickstart
import tensorflow as tf
# Verify TensorFlow installation and CPU setup
print(tf.reduce_sum(tf.random.normal([1000, 1000])))
# Basic Keras example
model = tf.keras.Sequential([
tf.keras.layers.Dense(10, activation='relu', input_shape=(784,)),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.summary()