TensorFlow
CPU
multi-core processing
deep learning
machine learning

Can TensorFlow run with multiple CPUs no GPUs?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Yes. TensorFlow runs perfectly well on machines that have multiple CPU cores and no GPUs at all. CPU execution is the normal fallback when no GPU is visible, and many TensorFlow operations can use several CPU threads in parallel.

TensorFlow Uses CPU Automatically

If TensorFlow does not detect a GPU, it places supported operations on the CPU. You do not need a special "CPU mode" API for basic use.

python
1import tensorflow as tf
2
3print("GPUs:", tf.config.list_physical_devices("GPU"))
4print("CPUs:", tf.config.list_physical_devices("CPU"))

If the GPU list is empty, TensorFlow will still run. That makes development, testing, and even a lot of production inference possible on ordinary servers and laptops.

Multiple CPUs Usually Means Multiple Threads

TensorFlow does not usually present every CPU core as a separate device in the same way it presents multiple GPUs. Instead, it uses thread pools so operations can run in parallel across available CPU resources.

Two settings are especially important:

  • 'intra_op_parallelism_threads controls parallelism inside one operation'
  • 'inter_op_parallelism_threads controls parallelism across independent operations'
python
1import tensorflow as tf
2
3tf.config.threading.set_intra_op_parallelism_threads(4)
4tf.config.threading.set_inter_op_parallelism_threads(2)
5
6print("Thread settings applied")

These values are workload-dependent. More threads do not always mean better performance, because too many threads can create contention and scheduling overhead.

Train a Small Model on CPU-Only Hardware

Here is a small TensorFlow model that runs fine with no GPU:

python
1import numpy as np
2import tensorflow as tf
3
4x = np.random.rand(1024, 20).astype("float32")
5y = np.random.randint(0, 2, size=(1024, 1)).astype("float32")
6
7model = tf.keras.Sequential(
8    [
9        tf.keras.layers.Input(shape=(20,)),
10        tf.keras.layers.Dense(64, activation="relu"),
11        tf.keras.layers.Dense(1, activation="sigmoid"),
12    ]
13)
14
15model.compile(
16    optimizer="adam",
17    loss="binary_crossentropy",
18    metrics=["accuracy"],
19)
20
21model.fit(x, y, epochs=3, batch_size=32)

This is fully valid TensorFlow. It may train more slowly than a good GPU on very large workloads, but the framework itself is not limited to GPU machines.

When CPU-Only TensorFlow Is a Good Fit

CPU-only execution is a practical choice when:

  • the model is small or moderate
  • you are prototyping or debugging
  • deployment targets are plain servers or containers
  • inference throughput requirements are modest

It is also common in CI pipelines and local development environments where installing GPU drivers would add complexity without enough benefit.

Understand the Performance Tradeoff

Running on multiple CPU cores is not the same as using GPU acceleration. Deep learning workloads with large dense matrix operations often train much faster on GPUs.

But CPU-only TensorFlow is still useful for:

  • unit tests around model code
  • data preprocessing with TensorFlow ops
  • lightweight inference services
  • tabular or smaller dense models

The right question is not whether TensorFlow can run without GPUs. It can. The real question is whether CPU performance is enough for your training or inference target.

Common Pitfalls

  • Assuming TensorFlow requires a GPU in order to run at all.
  • Expecting each CPU core to appear as a separate TensorFlow device.
  • Setting thread counts too high and making performance worse through contention.
  • Comparing CPU-only results with GPU results without considering model size and batch size.
  • Debugging device placement before first confirming the runtime sees the available CPU resources correctly.

Summary

  • TensorFlow runs correctly on machines with multiple CPUs and no GPUs.
  • Multi-core CPU use is handled mainly through threading rather than GPU-style device placement.
  • You can tune intra-op and inter-op thread counts for CPU workloads.
  • CPU-only TensorFlow is common for development, testing, and many inference scenarios.
  • The main limitation is performance relative to workload size, not framework compatibility.

Course illustration
Course illustration

All Rights Reserved.