{"record":{"id":"1d5ac0244b9e0de3","repo":"deepfakes/faceswap","slug":"you-do-not-have-enough-gpu-memory-available-to-run","errorCode":null,"errorMessage":"You do not have enough GPU memory available to run detection at the selected batch size. Youcan try a number of things:\n1) Close any other application that is using your GPU (web browsers are particularly bad for this).\n2) Try again. Sometimes this can be a transient issue when you are close to VRAM capacity.\n3) Lower the batch size (the amount of images fed into the model) by editing the plugin settings (GUI: Settings > Configure extract settings, CLI: Edit the file faceswap/config/extract.ini).\n4) Use lighter weight plugins.\n5) Enable fewer plugins.","messagePattern":"You do not have enough GPU memory available to run detection at the selected batch size\\. Youcan try a number of things:\n1\\) Close any other application that is using your GPU \\(web browsers are particularly bad for this\\)\\.\n2\\) Try again\\. Sometimes this can be a transient issue when you are close to VRAM capacity\\.\n3\\) Lower the batch size \\(the amount of images fed into the model\\) by editing the plugin settings \\(GUI: Settings > Configure extract settings, CLI: Edit the file faceswap/config/extract\\.ini\\)\\.\n4\\) Use lighter weight plugins\\.\n5\\) Enable fewer plugins\\.","errorType":"exception","errorClass":"FaceswapError","httpStatus":null,"severity":"error","filePath":"lib/infer/handler.py","lineNumber":180,"sourceCode":"        The prediction from the model\n\n        Raises\n        ------\n        FaceswapError\n            If an OOM occurs\n        \"\"\"\n        feed_size = feed.shape[0]\n        is_padded = self.do_compile and feed_size < self.plugin.batch_size\n        batch_feed = feed\n        if is_padded:  # Prevent model re-compile on undersized batch\n            batch_feed = np.empty((self.plugin.batch_size, *feed.shape[1:]), dtype=feed.dtype)\n            logger.debug(\"[%s.process] Padding undersized batch of shape %s to %s\",\n                         self.plugin.name, feed.shape, batch_feed.shape)\n            batch_feed[:feed_size] = feed\n        try:\n            retval = self.plugin.process(batch_feed)\n        except OutOfMemoryError as err:\n            raise FaceswapError(OOM_MESSAGE) from err\n        if is_padded and retval.dtype == \"object\":\n            out = np.empty(retval.shape, dtype=\"object\")\n            out[:] = [x[:feed_size] for x in retval]\n            retval = out\n        elif is_padded:\n            retval = retval[:feed_size]\n        return retval\n\n    def _format_images(self, images: npt.NDArray[np.uint8]) -> np.ndarray:\n        \"\"\"Format the incoming UINT8 0-255 images to the format specified by the plugin\n\n        Parameters\n        ----------\n        images\n            The batch of UINT8 images to format\n\n        Returns\n        -------","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/lib/infer/handler.py#L162-L198","documentation":"FaceswapError wrapping a framework OutOfMemoryError raised inside plugin.process during detection/inference. The handler pads undersized batches to the plugin's configured batch size before predicting, so VRAM consumption tracks the configured batch size; when it exceeds available GPU memory this user-facing OOM_MESSAGE is raised with remediation steps.","triggerScenarios":"Running detect/extract plugins with a batch size too large for the GPU; another process (browser, another training job) occupying VRAM; VRAM fragmentation when close to capacity.","commonSituations":"New users defaulting to high batch sizes on small GPUs (2-4GB); running extraction while a model trains; driver/browser compositing eating several hundred MB.","solutions":["Lower the batch size in plugin settings (GUI: Settings > Configure extract settings; CLI: edit faceswap/config/extract.ini).","Close other GPU consumers (browsers, other ML jobs) and retry — transient when near capacity.","Switch to lighter-weight or fewer plugins.","If persistent, use a smaller model or a GPU with more VRAM."],"exampleFix":"# faceswap/config/extract.ini\n# before\ndetect.batch_size = 64\n# after\ndetect.batch_size = 8","handlingStrategy":"fallback","validationCode":"# Before a long run, verify free VRAM vs batch size heuristic\nimport subprocess\nfree_mib = int(subprocess.run(\n    ['nvidia-smi', '--query-gpu=memory.free', '--format=csv,noheader,nounits'],\n    capture_output=True, text=True).stdout.split()[0])\nbatches_per_gpu = max(1, min(configured_batch, free_mib // 150))  # ~150MB/batch-item heuristic","typeGuard":null,"tryCatchPattern":"try:\n    detect(batch=batch_size)\nexcept FaceswapError as err:\n    if 'GPU memory' in str(err):\n        batch_size //= 2\n        detect(batch=batch_size)\n    else:\n        raise","preventionTips":["Start with batch_size 4-8 and increase after observing VRAM headroom.","Close browsers and other GPU apps before extraction/training.","Monitor with nvidia-smi during the first minutes of a run."],"tags":["gpu","out-of-memory","batch-size","inference"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}