{"record":{"id":"a4d663809ca8e0d2","repo":"Unity-Technologies/ml-agents","slug":"hyperparameters-were-specified-but-no-trainer-type","errorCode":null,"errorMessage":"Hyperparameters were specified but no trainer_type was given.","messagePattern":"Hyperparameters were specified but no trainer_type was given\\.","errorType":"validation","errorClass":"TrainerConfigError","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/settings.py","lineNumber":699,"sourceCode":"\n        # Check if a default_settings was specified. If so, used those as the default\n        # rather than an empty dict.\n        if TrainerSettings.default_override is not None:\n            d_copy.update(cattr.unstructure(TrainerSettings.default_override))\n\n        deep_update_dict(d_copy, d)\n\n        if \"framework\" in d_copy:\n            logger.warning(\"Framework option was deprecated but was specified\")\n            d_copy.pop(\"framework\", None)\n\n        for key, val in d_copy.items():\n            if attr.has(type(val)):\n                # Don't convert already-converted attrs classes.\n                continue\n            if key == \"hyperparameters\":\n                if \"trainer_type\" not in d_copy:\n                    raise TrainerConfigError(\n                        \"Hyperparameters were specified but no trainer_type was given.\"\n                    )\n                else:\n                    d_copy[key] = check_hyperparam_schedules(\n                        val, d_copy[\"trainer_type\"]\n                    )\n                    try:\n                        d_copy[key] = strict_to_cls(\n                            d_copy[key], all_trainer_settings[d_copy[\"trainer_type\"]]\n                        )\n                    except KeyError:\n                        raise TrainerConfigError(\n                            f\"Settings for trainer type {d_copy['trainer_type']} were not found\"\n                        )\n            elif key == \"max_steps\":\n                d_copy[key] = int(float(val))\n                # In some legacy configs, max steps was specified as a float\n            # elif key == \"even_checkpoints\":","sourceCodeStart":681,"sourceCodeEnd":717,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/settings.py#L681-L717","documentation":"When the 'hyperparameters' key is present in a trainer config, the trainer_type must also be specified, since hyperparameter classes differ per trainer (PPO/SAC/POCA). mlagents raises TrainerConfigError when hyperparameters are given without trainer_type.","triggerScenarios":"A behavior config includes hyperparameters but omits trainer_type, or default_settings provides hyperparameters while the behavior-level dict lacks trainer_type.","commonSituations":"Trimming configs and accidentally deleting trainer_type; relying on default_settings that include hyperparameters for a behavior that has no trainer_type; migrating legacy configs.","solutions":["Add trainer_type: ppo|sac|poca at the same level as hyperparameters.","Remove hyperparameters from default_settings if they shouldn't apply universally, or add trainer_type to default_settings.","Verify per-behavior configs for behaviors inheriting default hyperparameters."],"exampleFix":"// before\nMyBehavior:\n  hyperparameters:\n    batch_size: 64\n// after\nMyBehavior:\n  trainer_type: ppo\n  hyperparameters:\n    batch_size: 64","handlingStrategy":"validation","validationCode":"if 'hyperparameters' in cfg and 'trainer_type' not in cfg:\n    raise ValueError('hyperparameters given without trainer_type')","typeGuard":"def has_trainer_type(cfg):\n    return isinstance(cfg, dict) and isinstance(cfg.get('trainer_type'), str) and cfg['trainer_type']","tryCatchPattern":"from mlagents.trainers.exception import TrainerConfigError\ntry:\n    load_config(path)\nexcept TrainerConfigError as e:\n    if 'no trainer_type' in str(e):\n        cfg.setdefault('trainer_type', 'ppo')\n    else:\n        raise","preventionTips":["Always pair hyperparameters with an explicit trainer_type","Don't put hyperparameters in default_settings without a default trainer_type","Check per-behavior configs when using defaults"],"tags":["config","ml-agents"],"backgroundTag":"missing-required-config-field","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}