{"id":4276,"library":"tensorflow-cpu","title":"TensorFlow CPU","description":"TensorFlow-cpu is the CPU-optimized variant of TensorFlow, an open-source machine learning framework developed by Google. It is designed for high-performance numerical computation, suitable for training and deploying machine learning models without GPU acceleration. The current version is 2.21.0, and it follows a frequent release cadence, typically aligning with the main TensorFlow project's minor and patch updates every few months.","status":"active","version":"2.21.0","language":"en","source_language":"en","source_url":"https://github.com/tensorflow/tensorflow","tags":["machine learning","deep learning","cpu","tensor","google"],"install":[{"cmd":"pip install tensorflow-cpu","lang":"bash","label":"Install CPU-only TensorFlow"}],"dependencies":[{"reason":"Required Python interpreter version","package":"python","optional":false}],"imports":[{"symbol":"tensorflow","correct":"import tensorflow as tf"}],"quickstart":{"code":"import tensorflow as tf\n\n# Verify TensorFlow version\nprint(f\"TensorFlow Version: {tf.__version__}\")\n\n# Verify CPU device is recognized\ncpu_devices = tf.config.list_physical_devices('CPU')\nprint(f\"CPU Devices: {cpu_devices}\")\n\nif cpu_devices:\n    print(f\"TensorFlow is configured to use CPU: {cpu_devices[0].name}\")\n    # Perform a simple operation to confirm functionality\n    a = tf.constant([[1.0, 2.0], [3.0, 4.0]])\n    b = tf.constant([[1.0, 1.0], [1.0, 1.0]])\n    print(f\"Result of a + b:\\n{a + b}\")\nelse:\n    print(\"No CPU devices found by TensorFlow. Check installation.\")","lang":"python","description":"This quickstart code verifies the installed TensorFlow version, checks if CPU devices are recognized, and performs a basic tensor operation to confirm that TensorFlow is functioning correctly on the CPU."},"warnings":[{"fix":"Upgrade to Python 3.10 or newer. The `tensorflow-cpu` package generally requires Python >=3.10.","message":"Support for Python 3.9 has been removed starting with TensorFlow 2.21.","severity":"breaking","affected_versions":">=2.21.0"},{"fix":"Update your code to be compatible with Keras 3. To continue using Keras 2 (tf-keras), install `tf-keras` via `pip install tf-keras~=2.16` and set the environment variable `TF_USE_LEGACY_KERAS=1` before importing TensorFlow.","message":"Keras 3 became the default Keras version starting with TensorFlow 2.16. This may introduce breaking changes if your code relies on Keras 2 APIs.","severity":"breaking","affected_versions":">=2.16.0"},{"fix":"Migrate your code away from `tf.estimator`. If you must use this API, you will need to use TensorFlow 2.15 or an earlier version.","message":"The `tf.estimator` API has been removed.","severity":"breaking","affected_versions":">=2.16.0"},{"fix":"To explicitly restrict TensorFlow to CPU, add `tf.config.set_visible_devices([], 'GPU')` at the beginning of your script, before any other TensorFlow operations.","message":"If a GPU is present on your system, TensorFlow might prioritize it even if you've installed `tensorflow-cpu`. This can lead to unexpected GPU utilization.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consider adjusting `tf.config.threading.set_intra_op_parallelism_threads()` and `tf.config.threading.set_inter_op_parallelism_threads()`. For Intel CPUs, setting the environment variable `TF_ENABLE_ONEDNN_OPTS=1` can enable oneDNN optimizations (default on Windows x64 & x86 since TF 2.15).","message":"Optimizing TensorFlow performance on CPU often requires tuning specific runtime options and environment variables.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}