deepfakes/faceswap · error · FaceswapError
There was an error reading from the Nvidia Machine Learning
Error message
There was an error reading from the Nvidia Machine Learning Library. The most likely cause is incorrectly installed drivers. If this is the case, Please remove and reinstall your Nvidia drivers before reporting. Original Error: {str(err)} What it means
Fallback except in the same PyNVML init path: any exception other than the three known NVML errors (e.g. NVML_UnknownError, version-glyph errors like NVML_ERROR_FUNCTION_NOT_FOUND after nvmlInit succeeded partially, or OS-level errors) is re-raised as FaceswapError with the original message preserved.
Source
Thrown at lib/gpu_stats/nvidia.py:55
Raises
------
FaceswapError
If the NVML library could not be successfully loaded
"""
if self._is_initialized:
return
try:
self._log("debug", "Initializing PyNVML for Nvidia GPU.")
pynvml.nvmlInit()
except (pynvml.NVMLError_LibraryNotFound, # pylint:disable=no-member
pynvml.NVMLError_DriverNotLoaded, # pylint:disable=no-member
pynvml.NVMLError_NoPermission) as err: # pylint:disable=no-member
msg = ("There was an error reading from the Nvidia Machine Learning Library. The most "
"likely cause is incorrectly installed drivers. If this is the case, Please "
"remove and reinstall your Nvidia drivers before reporting. Original "
f"Error: {str(err)}")
raise FaceswapError(msg) from err
except Exception as err: # pylint:disable=broad-except
msg = ("An unhandled exception occurred reading from the Nvidia Machine Learning "
f"Library. Original error: {str(err)}")
raise FaceswapError(msg) from err
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
super()._initialize()
def _shutdown(self) -> None:
"""Cleanly close access to NVML and set :attr:`_is_initialized` back to ``False``. """
self._log("debug", "Shutting down NVML")
pynvml.nvmlShutdown()
super()._shutdown()
def _get_device_count(self) -> int:
"""Detect the number of GPUs attached to the system.
ReturnsView on GitHub (pinned to f530cb7508)
Solutions
- Read the appended 'Original error' to identify the NVML code (e.g. NVML_ERROR_FUNCTION_NOT_FOUND) and match driver vs pynvml versions
- Clean-reinstall the NVIDIA driver AND update the nvidia-ml-py/pynvml package so both come from the same driver generation
- Verify `nvidia-smi` works; if not, reload the kernel modules (sudo rmmod nvidia_uvm && sudo modprobe nvidia_uvm) or reboot
- Bypass with --cpu while the GPU stack is repaired
Example fix
# before python faceswap.py --nvidia ... # An unhandled exception occurred reading from the Nvidia ML Library # after pip install -U nvidia-ml-py # match pynvml to driver sudo apt install --reinstall nvidia-driver-XXX nvidia-smi # verify python faceswap.py --nvidia ...
Defensive patterns
Strategy: validation
Validate before calling
import shutil, subprocess
def nvidia_driver_ok():
return shutil.which("nvidia-smi") is not None \
and subprocess.run(["nvidia-smi"], capture_output=True).returncode == 0
assert nvidia_driver_ok(), "fix NVIDIA driver before --nvidia" Type guard
def nvml_reachable() -> bool:
"""True when NVML initializes cleanly (driver loaded & permitted)."""
try:
import pynvml
pynvml.nvmlInit()
pynvml.nvmlShutdown()
return True
except Exception:
return False Try / catch
from lib.utils import FaceswapError
try:
gpu_stats = NvidiaStats(log="debug")
except FaceswapError as err:
if "Nvidia Machine Learning Library" in str(err):
log_driver_fix_instructions(); use_cpu()
else:
raise Prevention
- Run nvidia-smi as the first GPU sanity check in any session
- Use --gpus all / nvidia-container-toolkit for containers
- Reboot after driver upgrades so kernel modules reload
When it happens
Trigger: `faceswap.py --nvidia ...` where nvmlInit() raises something unexpected: driver/library version skew (newer driver userspace, older libnvidia-ml), NVML functions missing in the installed driver version, driver lost GPU access mid-boot, or exotic virtualization (vGPU/legacy passthrough) errors.
Common situations: Mixed-version installs (libnvidia-ml from one release, kernel module from another); VMs with GPU passthrough; driver crashes that leave NVML in a bad state; pynvml package version newer than the driver's NVML API.
Related errors
- An unhandled exception occurred initializing the device via
- Hex color codes should start with a '#' and be 6 characters
- You do not have enough GPU memory available to train the sel
- Landmark based masks cannot be created for {self._landmark_t
- There is a mismatch between the number of frames found in th
AI-assisted analysis of deepfakes/faceswap@f530cb7508 (2026-08-15).
Data as JSON: /api/errors/133145adf1f96299.
Report an issue: GitHub.