{"record":{"id":"65595245a8542a7c","repo":"deepfakes/faceswap","slug":"you-do-not-have-enough-gpu-memory-available-to-tra","errorCode":null,"errorMessage":"You do not have enough GPU memory available to train the selected model at the selected settings. You can try a number of things:\\n1) Close any other application that is using your GPU (web browsers are particularly bad for this).\\n2) Lower the batchsize (the amount of images fed into the model each iteration).\\n3) Try enabling 'Mixed Precision' training.\\n4) Use a more lightweight model, or select the model's 'LowMem' option (in config) if it has one.","messagePattern":"You do not have enough GPU memory available to train the selected model at the selected settings\\. You can try a number of things:\\\\n1\\) Close any other application that is using your GPU \\(web browsers are particularly bad for this\\)\\.\\\\n2\\) Lower the batchsize \\(the amount of images fed into the model each iteration\\)\\.\\\\n3\\) Try enabling 'Mixed Precision' training\\.\\\\n4\\) Use a more lightweight model, or select the model's 'LowMem' option \\(in config\\) if it has one\\.","errorType":"exception","errorClass":"FaceswapError","httpStatus":null,"severity":"error","filePath":"lib/training/train.py","lineNumber":312,"sourceCode":"        \"\"\"\n        try:\n            inputs, targets, meta = next(self._train_loader)\n            loss = self._plugin.train_batch([i.to(self._device) for i in inputs],\n                                            [t.to(self._device) for t in targets],\n                                            self._optimizer,\n                                            meta.to(self._device))\n            retval = [x.to_cpu() for x in loss]\n        except OutOfMemoryError as err:\n            msg = (\"You do not have enough GPU memory available to train the selected model at \"\n                   \"the selected settings. You can try a number of things:\"\n                   \"\\n1) Close any other application that is using your GPU (web browsers are \"\n                   \"particularly bad for this).\"\n                   \"\\n2) Lower the batchsize (the amount of images fed into the model each \"\n                   \"iteration).\"\n                   \"\\n3) Try enabling 'Mixed Precision' training.\"\n                   \"\\n4) Use a more lightweight model, or select the model's 'LowMem' option \"\n                   \"(in config) if it has one.\")\n            raise FaceswapError(msg) from err\n        return retval\n\n    def _log_tensorboard(self, loss: list[BatchLoss]) -> None:\n        \"\"\"Log current loss to Tensorboard log files\n\n        Parameters\n        ----------\n        loss\n            The loss scalars for the batch detached and moved to cpu in order (A, B, ...)\n        \"\"\"\n        if not self._tensorboard:\n            return\n        logger.trace(\"[Trainer] Updating TensorBoard log: %s\", loss)  # type: ignore\n        logs: dict[str, float | dict[str, float]] = {\n            \"total\": T.cast(torch.Tensor, sum(x.total for x in loss)).item()}\n        for i, out in enumerate(loss):\n            lbl = get_label(i, len(loss))\n            for idx, (w, u) in enumerate(zip(out.weighted, out.unweighted)):","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/lib/training/train.py#L294-L330","documentation":"Faceswap catches torch's OutOfMemoryError during the training forward/backward pass and re-raises it as a FaceswapError with actionable guidance. It means the GPU ran out of VRAM for the current model + batch size + precision combination; it is an environment/capacity problem, not corrupted data.","triggerScenarios":"Calling the training loop with a batch size, input size, or model variant whose activations exceed free VRAM; also triggered when another process (browser with hardware acceleration, another training job, compositing desktop) already occupies VRAM, or when running on a GPU with little memory.","commonSituations":"Raising batch size on a consumer GPU; switching to a heavier model (e.g. Dfaker/RealFace) or larger input dimensions; first training on a new machine with the desktop/browser consuming VRAM; switching from a GPU with more VRAM to one with less.","solutions":["Lower the batch size in the train arguments (e.g. faceswap train ... -bs 8 -> -bs 4).","Enable mixed precision training in the training settings to reduce VRAM usage.","Close other applications using the GPU (browsers, other ML jobs) and verify with nvidia-smi.","Switch to a more lightweight model plugin, or enable the model's 'LowMem' option in the model config if available."],"exampleFix":"# before\nfaceswap train -A facesA -B facesB -m model -bs 16\n\n# after\nfaceswap train -A facesA -B facesB -m model -bs 4\n# plus enable mixed precision in train settings: settings.mixed_precision = true","handlingStrategy":"fallback","validationCode":"import torch\nfree, total = torch.cuda.mem_get_info()\nneeded_estimate = batch_size * bytes_per_sample  # from a dry run or prior runs\nassert free > needed_estimate, f\"only {free/1e9:.1f}GB free; lower batch size\"","typeGuard":null,"tryCatchPattern":"try:\n    trainer.train(...)\nexcept FaceswapError as err:\n    if \"not enough GPU memory\" in str(err):\n        # retry once with halved batch size\n        trainer.batch_size //= 2\n        trainer.train(...)\n    else:\n        raise","preventionTips":["Check free VRAM with nvidia-smi before launching training and budget the batch size accordingly.","Keep mixed precision enabled on GPUs < 11-12GB for large models.","Close browsers and other GPU apps before training; pin a conservative default batch size and step it up rather than starting high."],"tags":["faceswap","training","gpu","out-of-memory","cuda"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}