Does TensorFlow by default use all available GPUs in the machine?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
TensorFlow usually detects all visible GPUs by default, but that does not mean your model automatically runs across all of them efficiently. Detection, memory allocation, and multi-GPU execution are related topics, and they are often confused.
The practical answer is: TensorFlow can see all available GPUs unless you hide some of them, but using them all for one training job normally requires an explicit distribution strategy.
What TensorFlow Does Automatically
When GPU-enabled TensorFlow starts, it typically enumerates visible GPU devices.
If multiple GPUs are installed and visible through CUDA, TensorFlow will usually list them all.
Historically, TensorFlow would also try to allocate a large amount of memory on visible GPUs unless configured otherwise. That behavior is about memory management, not about automatic data-parallel training.
Does One Model Automatically Use All GPUs
Not by default in the sense most people mean.
A normal model script like this:
does not automatically become a correct multi-GPU training setup just because several GPUs exist.
To train across multiple GPUs intentionally, use a distribution strategy such as MirroredStrategy.
This is the explicit step that tells TensorFlow to replicate the model and coordinate work across GPUs.
Controlling Which GPUs Are Visible
You can restrict TensorFlow to selected GPUs.
Or at the environment level:
This is useful for debugging, shared machines, and avoiding accidental contention with other jobs.
Memory Growth and Allocation
Even when TensorFlow is not actively training on all GPUs, it may still reserve GPU memory in ways that surprise users.
To make allocation more incremental, enable memory growth.
This is often a good default on development machines where multiple processes may share the same hardware.
What Often Causes Confusion
People often observe this sequence:
- TensorFlow lists multiple GPUs
- GPU memory appears to be touched
- training still is not actually scaling across all devices
That happens because visibility and memory management are not the same thing as coordinated multi-device execution.
TensorFlow can know about many GPUs without automatically parallelizing your training in the way you expect.
Quick Diagnostic Pattern
A practical debugging pattern is to print visible GPUs, enable memory growth if needed, and then watch actual device utilization while running a small training step. That separates device discovery from real workload placement.
On many machines, this makes it obvious whether the issue is visibility, memory configuration, or missing distribution strategy.
Common Pitfalls
The biggest mistake is assuming that detected GPUs automatically imply multi-GPU training. Usually they do not.
Another common issue is confusing memory allocation behavior with actual compute utilization.
People also forget to use a distribution strategy and then wonder why only one GPU seems busy during training.
Finally, if a machine has many GPUs but you want deterministic debugging, limit visible devices explicitly instead of trusting defaults.
Summary
- TensorFlow usually detects all visible GPUs by default.
- Detection is not the same thing as automatically using all GPUs for one training job.
- Multi-GPU training typically requires a strategy such as
MirroredStrategy. - GPU visibility can be restricted with TensorFlow APIs or
CUDA_VISIBLE_DEVICES. - Memory allocation behavior can be tuned with memory growth settings.
- Separate the questions of device discovery, memory use, and actual parallel execution.
Related reading
- Does TensorFlow have cross validation implemented?
- Does TensorFlow have cross validation implemented?
- Does TensorFlow job use multiple cores by default?
- Does tensorflow map_fn support taking more than one tensor?
- Does Tensorflow normalize input data by default?
- Does tensorflow or python have memory cleanup issues when using multiple models in loop?
- Does TensorFlow view all CPUs of one machine as ONE device?
- Does the C volatile keyword introduce a memory fence?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.