Unity-Technologies/ml-agents · error · UnityTrainerException

Previous data from this run ID was found. Either specify a n

Error message

Previous data from this run ID was found. Either specify a new run ID, use --resume to resume this run, or use the --force parameter to overwrite existing data.

What it means

validate_existing_directories checks whether the run's output directory already exists. If it does and neither --resume nor --force was passed, ML-Agents raises UnityTrainerException to prevent silently overwriting previous training artifacts (models, summaries, checkpoints) for the same run ID.

Source

Thrown at ml-agents/mlagents/trainers/directory_utils.py:26

def validate_existing_directories(
    output_path: str, resume: bool, force: bool, init_path: Optional[str] = None
) -> None:
    """
    Validates that if the run_id model exists, we do not overwrite it unless --force is specified.
    Throws an exception if resume isn't specified and run_id exists. Throws an exception
    if --resume is specified and run-id was not found.
    :param model_path: The model path specified.
    :param summary_path: The summary path to be used.
    :param resume: Whether or not the --resume flag was passed.
    :param force: Whether or not the --force flag was passed.
    :param init_path: Path to run-id dir to initialize from
    """

    output_path_exists = os.path.isdir(output_path)

    if output_path_exists:
        if not resume and not force:
            raise UnityTrainerException(
                "Previous data from this run ID was found. "
                "Either specify a new run ID, use --resume to resume this run, "
                "or use the --force parameter to overwrite existing data."
            )
    else:
        if resume:
            raise UnityTrainerException(
                "Previous data from this run ID was not found. "
                "Train a new run by removing the --resume flag."
            )

    # Verify init path if specified.
    if init_path is not None:
        if not os.path.isdir(init_path):
            raise UnityTrainerException(
                "Could not initialize from {}. "
                "Make sure models have already been saved with that run ID.".format(
                    init_path

View on GitHub (pinned to 3ecb446f75)

Solutions

  1. Pass --resume to continue the existing run, or --force to delete/overwrite previous data.
  2. Choose a new --run-id to start a fresh training run in a new directory.
  3. Manually move or delete the existing results/<run_id> directory if the old data is no longer needed.

Example fix

// before
mlagents-learn config.yaml --run-id=ppo1
// after (overwrite previous data)
mlagents-learn config.yaml --run-id=ppo1 --force
Defensive patterns

Strategy: validation

Validate before calling

import os
run_id, results_dir = "ppo1", "results"
exists = os.path.isdir(os.path.join(results_dir, run_id))
if exists and not (resume or force):
    # decide: resume, force, or new run-id before launching
    pass

Type guard

def launch_is_safe(run_id: str, results_dir: str, resume: bool, force: bool) -> bool:
    import os
    return (not os.path.isdir(os.path.join(results_dir, run_id))) or resume or force

Try / catch

try:
    validate_existing_directories(model_path, summary_path, run_id, resume, force, init_path)
except UnityTrainerException as e:
    if "Previous data from this run ID was found" in str(e):
        logger.info("Existing run found; rerun with --resume or --force")
        raise SystemExit(1)
    raise

Prevention

When it happens

Trigger: Running mlagents-learn with a run_id whose results/<run_id> directory already exists, without --resume or --force — e.g. re-running the same command after a previous training session.

Common situations: Re-running an interrupted training without deciding whether to resume or start fresh; two team members using the default run_id; automated scripts re-invoking training with a fixed run_id.

Related errors


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