Created
June 20, 2026 20:05
-
-
Save yohanesnuwara/9a22505f619087917c3dac5ca2791b65 to your computer and use it in GitHub Desktop.
Solving Incompatibility Issue of Tensorflow 2.21.0 and Newest CUDA 13 (Blackwell GPU)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Install TensorFlow + CUDA runtime wheels | |
| uv add "tensorflow[and-cuda]==2.21.0" | |
| # Set up Tensorflow | |
| import os | |
| import site | |
| import ctypes | |
| from pathlib import Path | |
| # Optional: reduce TensorFlow startup logs | |
| os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" | |
| # Add NVIDIA wheel library folders to LD_LIBRARY_PATH | |
| site_packages = next(p for p in site.getsitepackages() if p.endswith("site-packages")) | |
| nvidia_root = Path(site_packages) / "nvidia" | |
| lib_dirs = sorted( | |
| {str(p.parent) for p in nvidia_root.rglob("*.so*") if p.parent.name == "lib"} | |
| ) | |
| if lib_dirs: | |
| old = os.environ.get("LD_LIBRARY_PATH", "") | |
| os.environ["LD_LIBRARY_PATH"] = ":".join(lib_dirs + ([old] if old else [])) | |
| # Preload common CUDA libs in this process so TensorFlow can resolve symbols | |
| preload = [ | |
| "cudart/lib/libcudart.so*", | |
| "cublas/lib/libcublas.so*", | |
| "cublas/lib/libcublasLt.so*", | |
| "cudnn/lib/libcudnn.so*", | |
| "cufft/lib/libcufft.so*", | |
| "curand/lib/libcurand.so*", | |
| "cusolver/lib/libcusolver.so*", | |
| "cusparse/lib/libcusparse.so*", | |
| "nccl/lib/libnccl.so*", | |
| "nvjitlink/lib/libnvJitLink.so*", | |
| "cuda_nvrtc/lib/libnvrtc.so*", | |
| "cuda_cupti/lib/libcupti.so*", | |
| ] | |
| for pattern in preload: | |
| matches = sorted(nvidia_root.glob(pattern)) | |
| if matches: | |
| ctypes.CDLL(str(matches[-1]), mode=ctypes.RTLD_GLOBAL) | |
| # Verify installation | |
| import tensorflow as tf | |
| print("TF version:", tf.__version__) | |
| print("CUDA build:", tf.sysconfig.get_build_info().get("cuda_version")) | |
| print("cuDNN:", tf.sysconfig.get_build_info().get("cudnn_version")) | |
| print("GPUs:", tf.config.list_physical_devices("GPU")) | |
| # OUTPUT: | |
| # TF version: 2.21.0 | |
| # CUDA build: 12.5.1 | |
| # cuDNN: 9 | |
| # GPUs: [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')] |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some relevant discussions from tensorflow/tensorflow#106653. This gist at least worked in my NVIDIA RTX Pro 500 Blackwell with CUDA 13.2 driver.