sgl-project/sglang · error · RuntimeError
Cannot load PE model: 'model_max_length' not found in {os.pa
Error message
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. What it means
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.
Source
Thrown at python/sglang/multimodal_gen/runtime/loader/component_loaders/pe_loader.py:153
pe_tokenizer_dir = os.path.join(
os.path.dirname(component_model_path), "pe_tokenizer"
)
if not os.path.exists(
os.path.join(component_model_path, "tokenizer_config.json")
) and os.path.exists(os.path.join(pe_tokenizer_dir, "tokenizer_config.json")):
tokenizer_path = pe_tokenizer_dir
logger.info(
"PE tokenizer files not found in %s, using %s",
component_model_path,
tokenizer_path,
)
else:
tokenizer_path = component_model_path
model_max_length = _read_model_max_length(tokenizer_path)
if model_max_length is None:
raise RuntimeError(
f"Cannot load PE model: 'model_max_length' not found in "
f"{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."
)
logger.info(
"PE model_max_length=%d (from tokenizer_config.json)", model_max_length
)
tokenizer = AutoTokenizer.from_pretrained(
tokenizer_path,
trust_remote_code=server_args.trust_remote_code,
)
if tokenizer.pad_token_id is None:
tokenizer.pad_token_id = tokenizer.eos_token_id
model = Ministral3ForCausalLM.from_pretrained(View on GitHub (pinned to 0132848349)
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)
Example fix
// before: tokenizer_config.json has no model_max_length
// after: tokenizer_config.json
{ "model_max_length": 32768, "...": "..." } Defensive patterns
Strategy: validation
Validate before calling
import json, os
def find_model_max_length(pe_path):
for cand in (pe_path, os.path.join(os.path.dirname(pe_path.rstrip('/')), 'pe_tokenizer')):
p = os.path.join(cand, 'tokenizer_config.json')
if os.path.exists(p):
mml = json.load(open(p)).get('model_max_length')
if mml:
return mml
return None
assert find_model_max_length(pe_path), "missing model_max_length" Prevention
- Ship tokenizer files with the PE component or a pe_tokenizer/ sibling
- Verify tokenizer_config.json contains model_max_length after any export
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Model config does not contain a _class_name attribute. Only
- Model config does not contain a _class_name attribute. Only
- f"Cannot parse checkpoint quantization for {component_name!r
- f"Transformers-managed {component_name!r} quantization requi
- {component_name!r} does not support an explicit quantization
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/7d9766ab69cbf955.
Report an issue: GitHub.