{"record":{"id":"7d9766ab69cbf955","repo":"sgl-project/sglang","slug":"cannot-load-pe-model-model-max-length-not-found","errorCode":null,"errorMessage":"Cannot load PE model: 'model_max_length' not found in {os.path.join(tokenizer_path, 'tokenizer_config.json')}. Please ensure the PE component directory (or its sibling pe_tokenizer/ directory) contains a valid tokenizer_config.json with a 'model_max_length' field.","messagePattern":"Cannot load PE model: 'model_max_length' not found in (.+?)\\. Please ensure the PE component directory \\(or its sibling pe_tokenizer/ directory\\) contains a valid tokenizer_config\\.json with a 'model_max_length' field\\.","errorType":"error_code","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/loader/component_loaders/pe_loader.py","lineNumber":153,"sourceCode":"\n        pe_tokenizer_dir = os.path.join(\n            os.path.dirname(component_model_path), \"pe_tokenizer\"\n        )\n        if not os.path.exists(\n            os.path.join(component_model_path, \"tokenizer_config.json\")\n        ) and os.path.exists(os.path.join(pe_tokenizer_dir, \"tokenizer_config.json\")):\n            tokenizer_path = pe_tokenizer_dir\n            logger.info(\n                \"PE tokenizer files not found in %s, using %s\",\n                component_model_path,\n                tokenizer_path,\n            )\n        else:\n            tokenizer_path = component_model_path\n\n        model_max_length = _read_model_max_length(tokenizer_path)\n        if model_max_length is None:\n            raise RuntimeError(\n                f\"Cannot load PE model: 'model_max_length' not found in \"\n                f\"{os.path.join(tokenizer_path, 'tokenizer_config.json')}. \"\n                \"Please ensure the PE component directory (or its sibling \"\n                \"pe_tokenizer/ directory) contains a valid tokenizer_config.json \"\n                \"with a 'model_max_length' field.\"\n            )\n        logger.info(\n            \"PE model_max_length=%d (from tokenizer_config.json)\", model_max_length\n        )\n\n        tokenizer = AutoTokenizer.from_pretrained(\n            tokenizer_path,\n            trust_remote_code=server_args.trust_remote_code,\n        )\n        if tokenizer.pad_token_id is None:\n            tokenizer.pad_token_id = tokenizer.eos_token_id\n\n        model = Ministral3ForCausalLM.from_pretrained(","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/loader/component_loaders/pe_loader.py#L135-L171","documentation":"The PE (perception/embedding) loader needs model_max_length from tokenizer_config.json — either in the component directory or its sibling pe_tokenizer/ directory — to size sequence handling. If _read_model_max_length returns None, this RuntimeError explains both locations that were checked.","triggerScenarios":"Loading a PE component where tokenizer_config.json is missing, unreadable, or lacks a 'model_max_length' field in both the component dir and the sibling pe_tokenizer/ dir.","commonSituations":"Checkpoint downloaded without tokenizer files; the tokenizer was shipped only in the main repo and pe_tokenizer/ was never created; tokenizer_config.json from a minimal export omitting model_max_length.","solutions":["Ensure tokenizer_config.json containing \"model_max_length\" exists in the PE component dir or a sibling pe_tokenizer/ dir","Copy the tokenizer files from the main model repo into pe_tokenizer/","If the field is genuinely absent, add \"model_max_length\": <int> to tokenizer_config.json (match the model's context length)"],"exampleFix":"// before: tokenizer_config.json has no model_max_length\n// after: tokenizer_config.json\n{ \"model_max_length\": 32768, \"...\": \"...\" }","handlingStrategy":"validation","validationCode":"import json, os\n\ndef find_model_max_length(pe_path):\n    for cand in (pe_path, os.path.join(os.path.dirname(pe_path.rstrip('/')), 'pe_tokenizer')):\n        p = os.path.join(cand, 'tokenizer_config.json')\n        if os.path.exists(p):\n            mml = json.load(open(p)).get('model_max_length')\n            if mml:\n                return mml\n    return None\n\nassert find_model_max_length(pe_path), \"missing model_max_length\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ship tokenizer files with the PE component or a pe_tokenizer/ sibling","Verify tokenizer_config.json contains model_max_length after any export"],"tags":["model-loading","tokenizer","missing-file","config"],"backgroundTag":"missing-tokenizer-config","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}