Fix CUDA and cuDNN Library Load Errors in TensorFlow: A Diagnostic Guide
Every TensorFlow CUDA library error — libcublas, libcudart, libnvinfer, cuDNN — traced to one of four root causes, with the order to diagnose them.
TensorFlow, Keras, and CUDA/cuDNN setup, plus fixes for the runtime errors that block training.
21 articles
Every TensorFlow CUDA library error — libcublas, libcudart, libnvinfer, cuDNN — traced to one of four root causes, with the order to diagnose them.
model.fit failing under tf.distribute.MirroredStrategy is almost always: the model/optimizer built outside strategy.scope(), a global batch size that isn't scaled, or a non-replica-aware custom step. The correct pattern, explained.
This TensorFlow error doesn't mean bfloat16 is invalid — it means the specific op has no bfloat16 kernel. Cast to float32 for that op with tf.cast, or use mixed_bfloat16 precision so Keras places dtypes for you.
This internal TensorFlow crash means a GPU kernel was launched with zero or a negative number of elements — almost always an empty batch, a layer whose shape math collapsed to 0, or an int32 overflow on a huge tensor. Here's how to find which.
'InvalidArgumentError: Graph execution error' is a generic wrapper — the real cause is in the nested traceback. The three most common ones (shape mismatch, label out of range, dtype mismatch) and how to fix each.
These TensorFlow errors fire after the libraries load, so they're not path problems — usually GPU memory exhaustion (enable memory growth), a cuDNN/CUDA version mismatch, or the GPU being held by another process. How to diagnose and fix each.
This TensorFlow message about libnvinfer_plugin.so is almost always a harmless TensorRT warning, not an error — TF still runs on GPU. When it actually matters, and how to fix it if you need TensorRT.
Autocomplete fails for tf.keras because it's a lazily-loaded alias that static analyzers can't follow. Your code still runs — import from keras directly to give the IDE a real module to introspect.
How TF-Slim, the TF high-level API, and Keras relate: three abstraction layers over TensorFlow. TF-Slim is deprecated; use Keras in TensorFlow 2.x today.
This ImportError comes from a shadowed or half-installed package (classically TensorFlow) or a circular import — not from the abs builtin. Here's how to find which one and fix it.
Build a CNN for image classification with Swift for TensorFlow (S4TF). Note: S4TF was archived in 2021 — use Python TensorFlow/Keras or PyTorch instead.
This means the dynamic loader can't find the exact CUDA library your framework was built against. The '.9.0' suffix must match exactly — here's how to check whether it's a path problem or a missing CUDA toolkit, and fix each.
This TensorFlow message means it needs the CUDA 11.x runtime and can't find it. The '11.0' is a major-version SONAME — any CUDA 11.x provides it, CUDA 12 does not. Here's the triage and fix.
Set TensorFlow's default float type with tf.keras.backend.set_floatx, or use mixed_precision for float16/bfloat16. ConfigProto does not control dtypes.
TensorFlow returns an empty GPU list even though CUDA is installed via conda — almost always a CUDA/cuDNN version mismatch or a conda-vs-system conflict. Diagnose it and fix it with tensorflow[and-cuda] or a matched conda environment.
Optimize GPU utilization with TensorFlow's Go binding using GPUOptions. Control memory allocation, growth, and device selection for efficient computations.
Weighting Classes in Multiple Output Models with tf.keras - Custom Loss and Sample Weights Solution
EagerTensors from tf.constant are immutable, so slice assignment raises AttributeError. Use tf.Variable, or tf.tensor_scatter_nd_update for a modified copy.
The advantages of TensorFlow Lite's optimized model size, execution efficiency, and supported operations for mobile and embedded deployments.
Clear GPU memory in TensorFlow 2 by enabling memory growth or setting memory limits. Optimize performance with these simple techniques.
Load a full Keras model from HDF5 with load_model('model.h5') — it restores architecture, weights, and optimizer. Plus weights-only loading, custom_objects for custom layers, and why Keras 3 defaults to the newer .keras format.