Unity-Technologies/ml-agents · error · TrainerConfigError

Invalid trainer type {val} was found

Error message

Invalid trainer type {val} was found

What it means

Thrown while structuring the trainer config dictionary in settings.py: the 'trainer_type' string parsed from the YAML config does not match any registered trainer settings class (it is not a key of the all_trainer_settings registry mapping trainer types like 'ppo' or 'sac' to their TrainerSettings subclasses). It fires at config-load time, before any training starts, and means the typo or unsupported trainer type prevents the behavior's settings from being built.

Source

Thrown at ml-agents/mlagents/trainers/settings.py:722

                        val, d_copy["trainer_type"]
                    )
                    try:
                        d_copy[key] = strict_to_cls(
                            d_copy[key], all_trainer_settings[d_copy["trainer_type"]]
                        )
                    except KeyError:
                        raise TrainerConfigError(
                            f"Settings for trainer type {d_copy['trainer_type']} were not found"
                        )
            elif key == "max_steps":
                d_copy[key] = int(float(val))
                # In some legacy configs, max steps was specified as a float
            # elif key == "even_checkpoints":
            #     if val:
            #         d_copy["checkpoint_interval"] = int(d_copy["max_steps"] / d_copy["keep_checkpoints"])
            elif key == "trainer_type":
                if val not in all_trainer_types.keys():
                    raise TrainerConfigError(f"Invalid trainer type {val} was found")
            else:
                d_copy[key] = check_and_structure(key, val, t)
        return t(**d_copy)

    class DefaultTrainerDict(collections.defaultdict):
        def __init__(self, *args):
            # Depending on how this is called, args may have the defaultdict
            # callable at the start of the list or not. In particular, unpickling
            # will pass [TrainerSettings].
            if args and args[0] == TrainerSettings:
                super().__init__(*args)
            else:
                super().__init__(TrainerSettings, *args)
            self._config_specified = True

        def set_config_specified(self, require_config_specified: bool) -> None:
            self._config_specified = require_config_specified

View on GitHub (pinned to 3ecb446f75)

Solutions

  1. Use one of the supported values: ppo, sac, poca.
  2. Normalize casing (lowercase) and strip whitespace.
  3. Consult the ML-Agents docs for the version you use to confirm valid trainer types.

Example fix

// before
trainer_type: PPO
// after
trainer_type: ppo
Defensive patterns

Strategy: validation

Validate before calling

tt = cfg.get('trainer_type')
if tt not in ('ppo', 'sac', 'poca'):
    raise ValueError(f'Invalid trainer_type: {tt!r}')

Type guard

from typing import Literal
def is_valid_trainer_type(v) -> 'Literal["ppo","sac","poca"]':
    return v in ('ppo', 'sac', 'poca')

Try / catch

from mlagents.trainers.exception import TrainerConfigError
try:
    load_config(path)
except TrainerConfigError as e:
    if 'Invalid trainer type' in str(e):
        logger.error('%s - use ppo, sac or poca', e)

Prevention

When it happens

Trigger: trainer_type set to a misspelled, mis-cased, or nonexistent value such as 'PPO', 'ppo2', 'imitation', or with trailing whitespace.

Common situations: Copying configs from other frameworks or old ML-Agents versions (pre-1.0 used different naming); hand-editing typos; IDE autocomplete inserting wrong values.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02). Data as JSON: /api/errors/1654f7585164873e. Report an issue: GitHub.