deepfakes/faceswap · error · ValueError

' ' is not a valid optimizer. Select from

Error message

'{name}' is not a valid optimizer. Select from {list(_OPTIMIZERS)}

What it means

Raised when building the training optimizer if config.optimizer() does not match any key in the _OPTIMIZERS registry in lib/training/optimizer.py. The optimizer name is read straight from the user's training configuration, so any unrecognised string aborts training at startup with this ValueError.

Solutions

  1. Set the optimizer in the training config to one of the names printed in the error (the keys of _OPTIMIZERS).
  2. Pick the value via the GUI Train > Configure dialog so only valid names are offered.
  3. Delete/regenerate the stale training config after upgrading Faceswap so it is rewritten with the currently valid options.

Example fix

# before
[optimizer.optimizer] = adamax

# after
[optimizer.optimizer] = adam
Defensive patterns

Strategy: validation

Validate before calling

from lib.training.optimizer import _OPTIMIZERS  # module-level registry
assert config_optimizer_name in _OPTIMIZERS, f"pick from {list(_OPTIMIZERS)}"

Type guard

def is_valid_optimizer(name: str, registry: dict) -> bool:
    return name in registry

Prevention

When it happens

Trigger: Training is launched with an optimizer name in the training config that is not registered (typos like 'ADAM', 'adamw' when unsupported, or names removed after a Faceswap upgrade, e.g. the Keras-to-PyTorch backend migration).

Common situations: Hand-edited config files; configs carried across versions where the optimizer list changed; copying a config from a tutorial/forum listing optimizers this build does not include.

Related errors


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

Appendix: source

Thrown at lib/training/optimizer.py:224

        return retval

    def _get_optimizer(self, model: K_Model, config: type[OptConfig]) -> torch.optim.Optimizer:
        """Obtain the configured optimizer the given configuration file options

        Parameters
        ----------
        model
            The keras model that is to be trained
        config
            The optimizer user configuration options

        Returns
        -------
        The requested configured optimizer
        """
        name = config.optimizer()
        if name not in _OPTIMIZERS:
            raise ValueError(f"'{name}' is not a valid optimizer. Select from {list(_OPTIMIZERS)}")
        optimizer = _OPTIMIZERS[name]

        retval = optimizer(self._get_parameter_groups(model, config.weight_decay()),
                           lr=config.learning_rate(),
                           **self._get_optimizer_kwargs(config))
        logger.debug("[Optimizer] Got optimizer '%s': %s", name, retval)
        return retval

    def _get_parameter_groups(self, model: K_Model, weight_decay: float
                              ) -> tuple[dict[T.Literal["params", "weight_decay"],
                                              list[nn.Parameter] | float],
                                         dict[T.Literal["params", "weight_decay"],
                                              list[nn.Parameter] | float]]:
        """Obtain the parameter groups from within the keras model

        Parameters
        ----------
        model

View on GitHub (pinned to f530cb7508)