deepfakes/faceswap · error · FaceswapError

You do not have enough GPU memory available to train the sel

Error message

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.

What it means

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.

Source

Thrown at lib/training/train.py:312

        """
        try:
            inputs, targets, meta = next(self._train_loader)
            loss = self._plugin.train_batch([i.to(self._device) for i in inputs],
                                            [t.to(self._device) for t in targets],
                                            self._optimizer,
                                            meta.to(self._device))
            retval = [x.to_cpu() for x in loss]
        except OutOfMemoryError as err:
            msg = ("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.")
            raise FaceswapError(msg) from err
        return retval

    def _log_tensorboard(self, loss: list[BatchLoss]) -> None:
        """Log current loss to Tensorboard log files

        Parameters
        ----------
        loss
            The loss scalars for the batch detached and moved to cpu in order (A, B, ...)
        """
        if not self._tensorboard:
            return
        logger.trace("[Trainer] Updating TensorBoard log: %s", loss)  # type: ignore
        logs: dict[str, float | dict[str, float]] = {
            "total": T.cast(torch.Tensor, sum(x.total for x in loss)).item()}
        for i, out in enumerate(loss):
            lbl = get_label(i, len(loss))
            for idx, (w, u) in enumerate(zip(out.weighted, out.unweighted)):

View on GitHub (pinned to f530cb7508)

Solutions

  1. Lower the batch size in the train arguments (e.g. faceswap train ... -bs 8 -> -bs 4).
  2. Enable mixed precision training in the training settings to reduce VRAM usage.
  3. Close other applications using the GPU (browsers, other ML jobs) and verify with nvidia-smi.
  4. Switch to a more lightweight model plugin, or enable the model's 'LowMem' option in the model config if available.

Example fix

# before
faceswap train -A facesA -B facesB -m model -bs 16

# after
faceswap train -A facesA -B facesB -m model -bs 4
# plus enable mixed precision in train settings: settings.mixed_precision = true
Defensive patterns

Strategy: fallback

Validate before calling

import torch
free, total = torch.cuda.mem_get_info()
needed_estimate = batch_size * bytes_per_sample  # from a dry run or prior runs
assert free > needed_estimate, f"only {free/1e9:.1f}GB free; lower batch size"

Try / catch

try:
    trainer.train(...)
except FaceswapError as err:
    if "not enough GPU memory" in str(err):
        # retry once with halved batch size
        trainer.batch_size //= 2
        trainer.train(...)
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of deepfakes/faceswap@f530cb7508 (2026-08-15). Data as JSON: /api/errors/65595245a8542a7c. Report an issue: GitHub.