{"record":{"id":"493009ceb9c005bf","repo":"facebookresearch/detectron2","slug":"config-file-filename-has-to-be-a-python-or-yaml","errorCode":null,"errorMessage":"Config file {filename} has to be a python or yaml file.","messagePattern":"Config file (.+?) has to be a python or yaml file\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"detectron2/config/lazy.py","lineNumber":209,"sourceCode":"        assert caller_fname != \"<string>\", \"load_rel Unable to find caller\"\n        caller_dir = os.path.dirname(caller_fname)\n        filename = os.path.join(caller_dir, filename)\n        return LazyConfig.load(filename, keys)\n\n    @staticmethod\n    def load(filename: str, keys: Union[None, str, Tuple[str, ...]] = None):\n        \"\"\"\n        Load a config file.\n\n        Args:\n            filename: absolute path or relative path w.r.t. the current working directory\n            keys: keys to load and return. If not given, return all keys\n                (whose values are config objects) in a dict.\n        \"\"\"\n        has_keys = keys is not None\n        filename = filename.replace(\"/./\", \"/\")  # redundant\n        if os.path.splitext(filename)[1] not in [\".py\", \".yaml\", \".yml\"]:\n            raise ValueError(f\"Config file {filename} has to be a python or yaml file.\")\n        if filename.endswith(\".py\"):\n            _validate_py_syntax(filename)\n\n            with _patch_import():\n                # Record the filename\n                module_namespace = {\n                    \"__file__\": filename,\n                    \"__package__\": _random_package_name(filename),\n                }\n                with PathManager.open(filename) as f:\n                    content = f.read()\n                # Compile first with filename to:\n                # 1. make filename appears in stacktrace\n                # 2. make load_rel able to find its parent's (possibly remote) location\n                exec(compile(content, filename, \"exec\"), module_namespace)\n\n            ret = module_namespace\n        else:","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/facebookresearch/detectron2/blob/a2f4a8771ab77e8411c26b27f24f9489a28a2453/detectron2/config/lazy.py#L191-L227","documentation":"LazyConfig.load only accepts files with a .py, .yaml, or .yml extension; the extension is checked with os.path.splitext before anything is read. Any other extension (or none) is rejected immediately.","triggerScenarios":"LazyConfig.load('config.json'), load('cfg.txt'), or a path whose extension is .pth/.pkl; also paths where '/./' normalization leaves a doubled extension.","commonSituations":"Feeding a YAML dump or JSON config from another tool into LazyConfig; scripts that glob config paths and accidentally pick up non-config files.","solutions":["Convert the file to .yaml/.yml or .py format and use that extension","If it's JSON, rename/save as .yaml (JSON is valid YAML) and load again","Filter file globs to *.py/*.yaml/*.yml before calling load"],"exampleFix":"# before\ncfg = LazyConfig.load(\"configs/exp1.json\")\n# after\nimport json, yaml\ndata = json.load(open(\"configs/exp1.json\"))\nyaml.safe_dump(data, open(\"configs/exp1.yaml\", \"w\"))\ncfg = LazyConfig.load(\"configs/exp1.yaml\")","handlingStrategy":"type-guard","validationCode":"assert os.path.splitext(path)[1] in {'.py','.yaml','.yml'}, f\"not a LazyConfig file: {path}\"","typeGuard":"def is_lazyconfig_file(path: str) -> bool:\n    return os.path.splitext(path)[1] in {\".py\", \".yaml\", \".yml\"}","tryCatchPattern":null,"preventionTips":["Standardize experiment configs on .py or .yaml","Convert JSON to YAML before loading","Filter glob results by extension in launcher scripts"],"tags":["config-file","file-extension","lazy-config"],"backgroundTag":"unsupported-config-format","analyzedSha":"a2f4a8771ab77e8411c26b27f24f9489a28a2453","analyzedAt":"2026-08-27T12:08:21.260Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}