{"record":{"id":"133145adf1f96299","repo":"deepfakes/faceswap","slug":"there-was-an-error-reading-from-the-nvidia-machine","errorCode":null,"errorMessage":"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)}","messagePattern":"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: (.+?)","errorType":"exception","errorClass":"FaceswapError","httpStatus":null,"severity":"error","filePath":"lib/gpu_stats/nvidia.py","lineNumber":55,"sourceCode":"\n        Raises\n        ------\n        FaceswapError\n            If the NVML library could not be successfully loaded\n        \"\"\"\n        if self._is_initialized:\n            return\n        try:\n            self._log(\"debug\", \"Initializing PyNVML for Nvidia GPU.\")\n            pynvml.nvmlInit()\n        except (pynvml.NVMLError_LibraryNotFound,  # pylint:disable=no-member\n                pynvml.NVMLError_DriverNotLoaded,  # pylint:disable=no-member\n                pynvml.NVMLError_NoPermission) as err:  # pylint:disable=no-member\n            msg = (\"There was an error reading from the Nvidia Machine Learning Library. The most \"\n                   \"likely cause is incorrectly installed drivers. If this is the case, Please \"\n                   \"remove and reinstall your Nvidia drivers before reporting. Original \"\n                   f\"Error: {str(err)}\")\n            raise FaceswapError(msg) from err\n        except Exception as err:  # pylint:disable=broad-except\n            msg = (\"An unhandled exception occurred reading from the Nvidia Machine Learning \"\n                   f\"Library. Original error: {str(err)}\")\n            raise FaceswapError(msg) from err\n\n        os.environ[\"CUDA_DEVICE_ORDER\"] = \"PCI_BUS_ID\"\n        super()._initialize()\n\n    def _shutdown(self) -> None:\n        \"\"\"Cleanly close access to NVML and set :attr:`_is_initialized` back to ``False``. \"\"\"\n        self._log(\"debug\", \"Shutting down NVML\")\n        pynvml.nvmlShutdown()\n        super()._shutdown()\n\n    def _get_device_count(self) -> int:\n        \"\"\"Detect the number of GPUs attached to the system.\n\n        Returns","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/lib/gpu_stats/nvidia.py#L37-L73","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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"],"exampleFix":"# before\npython faceswap.py --nvidia ...  # An unhandled exception occurred reading from the Nvidia ML Library\n\n# after\npip install -U nvidia-ml-py          # match pynvml to driver\nsudo apt install --reinstall nvidia-driver-XXX\nnvidia-smi                           # verify\npython faceswap.py --nvidia ...","handlingStrategy":"validation","validationCode":"import shutil, subprocess\n\ndef nvidia_driver_ok():\n    return shutil.which(\"nvidia-smi\") is not None \\\n        and subprocess.run([\"nvidia-smi\"], capture_output=True).returncode == 0\n\nassert nvidia_driver_ok(), \"fix NVIDIA driver before --nvidia\"","typeGuard":"def nvml_reachable() -> bool:\n    \"\"\"True when NVML initializes cleanly (driver loaded & permitted).\"\"\"\n    try:\n        import pynvml\n        pynvml.nvmlInit()\n        pynvml.nvmlShutdown()\n        return True\n    except Exception:\n        return False","tryCatchPattern":"from lib.utils import FaceswapError\ntry:\n    gpu_stats = NvidiaStats(log=\"debug\")\nexcept FaceswapError as err:\n    if \"Nvidia Machine Learning Library\" in str(err):\n        log_driver_fix_instructions(); use_cpu()\n    else:\n        raise","preventionTips":["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"],"tags":["faceswap","nvidia","nvml","driver","gpu","version-skew"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}