{"record":{"id":"974c0b02c6ff7a31","repo":"hiyouga/LlamaFactory","slug":"extra-config-file-not-found-self-extra-config","errorCode":null,"errorMessage":"`extra_config` file not found: {self.extra_config}","messagePattern":"`extra_config` file not found: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/hparams/megatron_bridge_args.py","lineNumber":191,"sourceCode":"            \"alltoall\",\n            \"flex\",\n        ):\n            raise ValueError(\"`moe_token_dispatcher_type` must be 'allgather', 'alltoall', or 'flex'.\")\n\n        if isinstance(self.extra_config, str):\n            config_str = self.extra_config.strip()\n            if config_str.startswith(\"{\"):\n                self.extra_config = _convert_str_dict(json.loads(config_str))\n            else:\n                self.extra_config = config_str\n\n    def load_extra_config(self) -> dict:\n        if self.extra_config is None:\n            return {}\n        if isinstance(self.extra_config, dict):\n            return self.extra_config\n        if not os.path.isfile(self.extra_config):\n            raise ValueError(f\"`extra_config` file not found: {self.extra_config}\")\n        with open(self.extra_config, encoding=\"utf-8\") as f:\n            return json.load(f)\n","sourceCodeStart":173,"sourceCodeEnd":194,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/hparams/megatron_bridge_args.py#L173-L194","documentation":"Raised by MegatronBridgeArguments.load_extra_config (megatron_bridge_args.py:191) when extra_config is a string that is neither inline JSON nor an existing file path. __post_init__ first tries to parse the string as JSON if it starts with '{'; otherwise the raw string is treated as a file path, and load_extra_config raises when os.path.isfile fails. This runs at training launch, when the bridge arguments are constructed and extra config is loaded.","triggerScenarios":"Passing extra_config: /path/that/does/not/exist.json; a relative path evaluated from a different working directory than expected; a typo'd path; passing plain key=value text that neither starts with '{' nor names a file.","commonSituations":"Running llamafactory-cli train from a different cwd so relative paths break; file created after config written but deleted/renamed; typos in long absolute paths; permission issues that make isfile return False in unusual container mounts.","solutions":["Verify the path exists and is readable from the directory you launch the CLI from; prefer absolute paths","If you meant inline settings, pass a JSON object string starting with '{' (e.g. extra_config: '{\"foo\": 1}') or a YAML mapping that becomes a dict","Check for typos and stray whitespace in the path"],"exampleFix":"# before\nextra_config: config/megatron_extra.json   # missing or wrong cwd\n\n# after\nextra_config: /abs/path/config/megatron_extra.json\n# or inline:\nextra_config: '{\"optimizer\": {\"bar\": 1}}'","handlingStrategy":"validation","validationCode":"import os\nec = cfg.get('extra_config')\nif isinstance(ec, str) and not ec.strip().startswith('{'):\n    ec = os.path.abspath(ec)\n    assert os.path.isfile(ec), f'extra_config file missing: {ec}'\n    cfg['extra_config'] = ec","typeGuard":"def extra_config_resolvable(v: str | dict | None) -> bool:\n    if v is None or isinstance(v, dict):\n        return True\n    return v.strip().startswith('{') or os.path.isfile(v)","tryCatchPattern":"try:\n    extra = bridge_args.load_extra_config()\nexcept ValueError as e:\n    if 'file not found' in str(e):\n        cfg['extra_config'] = inline_json_dict  # fall back to inline config\n        bridge_args = MegatronBridgeArguments(**cfg)\n    else:\n        raise","preventionTips":["Use absolute paths for extra_config files","Launch the CLI from the repo root or record the intended cwd in run scripts"],"tags":["megatron","file-not-found","config-validation"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}