{"record":{"id":"c912e70d5b4c2cec","repo":"Unity-Technologies/ml-agents","slug":"could-not-initialize-from-init-file-file-does-n","errorCode":null,"errorMessage":"Could not initialize from {init_file}. file does not exists or is not a `.pt` file","messagePattern":"Could not initialize from (.+?)\\. file does not exists or is not a `\\.pt` file","errorType":"exception","errorClass":"UnityTrainerException","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/directory_utils.py","lineNumber":75,"sourceCode":"    for behavior_name, ts in behaviors.items():\n        if ts.init_path is None:\n            # set default if None\n            ts.init_path = os.path.join(\n                init_dir, behavior_name, DEFAULT_CHECKPOINT_NAME\n            )\n        elif not os.path.dirname(ts.init_path):\n            # update to full path if just the file name\n            ts.init_path = os.path.join(init_dir, behavior_name, ts.init_path)\n        _validate_init_full_path(ts.init_path)\n\n\ndef _validate_init_full_path(init_file: str) -> None:\n    \"\"\"\n    Validate initialization path to be a .pt file\n    :param init_file: full path to initialization checkpoint file\n    \"\"\"\n    if not (os.path.isfile(init_file) and init_file.endswith(\".pt\")):\n        raise UnityTrainerException(\n            f\"Could not initialize from {init_file}. file does not exists or is not a `.pt` file\"\n        )\n","sourceCodeStart":57,"sourceCodeEnd":78,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/directory_utils.py#L57-L78","documentation":"UnityTrainerException thrown by _validate_init_full_path when the --init-file path passed to a trainer is either not an existing file or does not have a .pt extension. ML-Agents requires initialization from a previously saved PyTorch checkpoint, so the path must point to a real .pt model file. This is a startup-time configuration validation, raised before training begins.","triggerScenarios":"Calling setup_init_path with an init_file whose full path fails os.path.isfile() (file missing, typo, wrong working directory) or whose name does not end with '.pt' (e.g. a .ckpt, .pth, .onnx, or .nn file, or a directory path).","commonSituations":"Passing a TensorFlow-era .ckpt or an older .pth checkpoint to a newer mlagents-learn run; typos or relative paths resolved from the wrong CWD; pointing at a Model asset exported to .onnx instead of the trainer checkpoint .pt.","solutions":["Verify the file exists: run ls on the exact path you passed to --init-file (or Path(init_file).exists() in Python).","Confirm the file has a .pt extension; if you only have .onnx/.pth, re-save the model with torch.save as .pt or retrain to produce a checkpoint.","If the path is relative, either cd to the expected directory or pass an absolute path (os.path.abspath).","Point --init-file at the correct run's checkpoint, e.g. results/<run_id>/<behavior_name>/<behavior_name>-<steps>.pt."],"exampleFix":"// before\nmlagents-learn config.yaml --init-file=results/run1/3DBall/3DBall-50000.onnx\n// after\nmlagents-learn config.yaml --init-file=results/run1/3DBall/3DBall-50000.pt","handlingStrategy":"validation","validationCode":"import os\ninit_file = \"results/run1/3DBall/3DBall-50000.pt\"\nif not (os.path.isfile(init_file) and init_file.endswith(\".pt\")):\n    raise ValueError(f\"--init-file must be an existing .pt file, got: {init_file}\")","typeGuard":"def is_valid_checkpoint(path: str) -> bool:\n    return isinstance(path, str) and path.endswith(\".pt\") and os.path.isfile(path)","tryCatchPattern":"from mlagents.trainers.exception import UnityTrainerException\ntry:\n    trainer = setup_init_path(trainer, init_path)\nexcept UnityTrainerException:\n    logger.warning(\"Invalid init checkpoint, starting from scratch\")\n    init_path = None","preventionTips":["Always pass absolute paths to --init-file","Glob for results/<run>/**/*.pt before launching to confirm a checkpoint exists","Never point --init-file at .onnx/.pth/.ckpt artifacts"],"tags":["ml-agents","file-not-found","checkpoint-loading","configuration"],"backgroundTag":"checkpoint-file-not-found","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}