{"record":{"id":"2b89cb3f0bcbfda9","repo":"PaddlePaddle/PaddleOCR","slug":"key-global-not-found-in-config-file-all-confi","errorCode":null,"errorMessage":"Key 'Global' not found in config file. \n{all_config}","messagePattern":"Key 'Global' not found in config file\\. \n(.+?)","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"deploy/slim/auto_compression/run.py","lineNumber":130,"sourceCode":"    elif model_type == \"rec\":\n        return metric[\"acc\"]\n    return metric\n\n\ndef main():\n    rank_id = paddle.distributed.get_rank()\n    if args.devices == \"gpu\":\n        place = paddle.CUDAPlace(rank_id)\n        paddle.set_device(\"gpu\")\n    else:\n        place = paddle.CPUPlace()\n        paddle.set_device(\"cpu\")\n\n    global all_config, global_config\n    all_config = load_slim_config(args.config_path)\n\n    if \"Global\" not in all_config:\n        raise KeyError(f\"Key 'Global' not found in config file. \\n{all_config}\")\n    global_config = all_config[\"Global\"]\n\n    gpu_num = paddle.distributed.get_world_size()\n\n    train_dataloader = build_dataloader(all_config, \"Train\", args.devices, logger)\n\n    global val_loader\n    val_loader = build_dataloader(all_config, \"Eval\", args.devices, logger)\n\n    if (\n        isinstance(all_config[\"TrainConfig\"][\"learning_rate\"], dict)\n        and all_config[\"TrainConfig\"][\"learning_rate\"][\"type\"] == \"CosineAnnealingDecay\"\n    ):\n        steps = len(train_dataloader) * all_config[\"TrainConfig\"][\"epochs\"]\n        all_config[\"TrainConfig\"][\"learning_rate\"][\"T_max\"] = steps\n        print(\"total training steps:\", steps)\n\n    global_config[\"input_name\"] = get_feed_vars(","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/deploy/slim/auto_compression/run.py#L112-L148","documentation":"KeyError raised by deploy/slim/auto_compression/run.py when the loaded slim configuration (YAML) has no top-level `Global` key. The auto-compression entrypoint requires all_config['Global'] to exist before building dataloaders and training config; its absence means the config file is malformed or the wrong file was passed.","triggerScenarios":"Passing --config_path pointing to a training YAML that lacks a Global section; a YAML with typo'd top-level key (e.g. `global:` lowercase) or wrong indentation so Global nests under another key; passing an empty or non-YAML file that parsed to {}.","commonSituations":"Reusing a PaddleOCR training config for slim auto-compression without the required structure; hand-editing configs and breaking indentation so top-level keys collapse into a parent.","solutions":["Open the config and confirm a top-level `Global:` block exists with correct spelling and zero indentation.","Compare against a known-good slim config shipped in deploy/slim/auto_compression and copy its skeleton.","Print the parsed config (the error message includes all_config) to see what keys were actually read.","Verify --config_path points to the intended file and that it is valid YAML (yaml.safe_load returns a dict, not None/str)."],"exampleFix":"// before (broken)\nTrain:\n  dataset:\n    ...\nGlobal:\n  epochs: 20\n\n// after\nGlobal:\n  epochs: 20\nTrain:\n  dataset:\n    ...","handlingStrategy":"validation","validationCode":"import yaml\n\ndef slim_config_valid(path: str) -> bool:\n    data = yaml.safe_load(open(path, encoding=\"utf-8\"))\n    return isinstance(data, dict) and \"Global\" in data and isinstance(data[\"Global\"], dict)","typeGuard":"def has_global_section(cfg: object) -> bool:\n    return isinstance(cfg, dict) and \"Global\" in cfg","tryCatchPattern":"try:\n    main(config_path)\nexcept KeyError as e:\n    if \"Global\" in str(e):\n        log.error(\"slim config %s missing top-level Global section\", config_path)\n    raise","preventionTips":["Validate slim configs with a yaml lint/structure check before launching distributed jobs.","Start from a shipped example config and edit values, never retype top-level keys.","Use consistent indentation (spaces) — one wrong tab can nest Global under a sibling."],"tags":["python","config","yaml","paddleslim","auto-compression"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}