Mixed Precision, GPUs and Faster Training

Deep Learning with Keras and TensorFlow 9 min min read Updated: Nov 16, 2026 Advanced
Mixed Precision, GPUs and Faster Training
Advanced Topic 6 of 7

Why is Training Slow?

Deep learning does a huge number of calculations. Training time depends on the hardware, the model size, the data pipeline and how you configure things. Here are the easy wins.

1. Use a GPU or TPU

python import tensorflow as tf print(tf.config.list_physical_devices("GPU"))

If the list is empty, you are on a CPU. In Google Colab, choose a GPU runtime. TensorFlow uses an available GPU automatically.

2. Fix the Input Pipeline

  • Use tf.data with cache() and prefetch(tf.data.AUTOTUNE)
  • Use num_parallel_calls=tf.data.AUTOTUNE in map()
  • Read data from a fast disk, and avoid decoding images again and again

3. Larger Batch Size

A bigger batch uses the GPU better. Increase it until you run out of memory, and consider raising the learning rate a little.

4. Mixed Precision

Modern GPUs calculate much faster with 16-bit numbers. Mixed precision uses 16-bit for most operations and keeps 32-bit where needed for stability, giving large speedups on supported GPUs with little accuracy loss.

python import keras keras.mixed_precision.set_global_policy("mixed_float16") # Build the model as usual. # Make the last layer output float32 for numerical stability: outputs = layers.Dense(10, activation="softmax", dtype="float32")(x)
Check your hardware: Mixed precision helps most on GPUs with Tensor Cores (modern NVIDIA cards). On a CPU it may not help, or may even be slower.

5. Multiple GPUs

python strategy = tf.distribute.MirroredStrategy() print("Devices:", strategy.num_replicas_in_sync) with strategy.scope(): model = build_model() model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"]) model.fit(train_ds, epochs=5) # batches are split across the GPUs

6. Other Tips

TipEffect
Smaller input imagesBig speedup, small accuracy cost
Transfer learningFar fewer weights to train
EarlyStoppingAvoid useless epochs
Lighter model (MobileNet)Faster training and inference
Train on a sample firstDebug your code in seconds

Find the Bottleneck with the Profiler

python tb = keras.callbacks.TensorBoard(log_dir="logs", profile_batch=(10, 20)) model.fit(train_ds, epochs=2, callbacks=[tb])

Open TensorBoard and look at the Profile tab to see if the GPU is waiting for data.

Golden rule: Always get your code working on a small subset of the data first. Then scale up to the full data and the full model.

Conclusion

Fast training comes from good hardware use, an efficient data pipeline and techniques such as mixed precision.

Quick Summary: Use a GPU, tf.data with prefetch, larger batches and mixed precision. Scale to multiple GPUs with MirroredStrategy.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators