{"record":{"id":"05fa142792f124d6","repo":"hiyouga/LlamaFactory","slug":"invalid-length","errorCode":null,"errorMessage":"Invalid length","messagePattern":"Invalid length","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"src/llamafactory/api/chat.py","lineNumber":87,"sourceCode":"    Role.TOOL: DataRole.OBSERVATION.value,\n}\n\n\ndef _process_request(\n    request: \"ChatCompletionRequest\",\n) -> tuple[\n    list[dict[str, str]],\n    Optional[str],\n    Optional[str],\n    Optional[list[\"ImageInput\"]],\n    Optional[list[\"VideoInput\"]],\n    Optional[list[\"AudioInput\"]],\n]:\n    if is_env_enabled(\"API_VERBOSE\", \"1\"):\n        logger.info_rank0(f\"==== request ====\\n{json.dumps(dictify(request), indent=2, ensure_ascii=False)}\")\n\n    if len(request.messages) == 0:\n        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=\"Invalid length\")\n\n    if request.messages[0].role == Role.SYSTEM:\n        content = request.messages.pop(0).content\n        if isinstance(content, list):\n            system = content[0].text if content else \"\"\n        else:\n            system = content\n    else:\n        system = None\n\n    if len(request.messages) % 2 == 0:\n        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=\"Only supports u/a/u/a/u...\")\n\n    input_messages = []\n    images, videos, audios = [], [], []\n    for i, message in enumerate(request.messages):\n        if i % 2 == 0 and message.role not in [Role.USER, Role.TOOL]:\n            raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=\"Invalid role\")","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/api/chat.py#L69-L105","documentation":"The Megatron Bridge PT/SFT path (gpt_step) only supports text LLMs listed in MEGATRON_BRIDGE_SUPPORTED_MODELS (constants.py:78: deepseek_v3, deepseek_v4, llama, mistral, qwen2, qwen3, qwen3_5, qwen3_5_moe, qwen3_5_moe_text, qwen3_5_text, qwen3_moe, qwen3_next). _check_model_support loads the HF config and raises ValueError for any other model_type, explicitly noting multimodal/audio/omni models are not enabled in v0.","triggerScenarios":"Running the megatron_bridge workflow with model_name_or_path whose AutoConfig.model_type is outside the set — e.g. qwen2_5_vl, qwen3_omni_moe, gemma3, internvl — during _check_model_support before dataset export/training.","commonSituations":"Assuming the Megatron path handles VL/omni models because the MCA path does; using a text model with an exotic model_type; model_type naming changes after a transformers upgrade.","solutions":["Use a supported text model type (see MEGATRON_BRIDGE_SUPPORTED_MODELS in src/llamafactory/extras/constants.py)","For multimodal models, switch off the Megatron Bridge backend to the standard HF trainer path or the MCA path which supports qwen*_vl","For a text backbone inside a multimodal release, point at the text-only checkpoint variant (e.g. qwen3_5_text)"],"exampleFix":"# before\nmodel_name_or_path: Qwen/Qwen2.5-VL-7B  # model_type qwen2_5_vl\n# megatron bridge path -> ValueError\n\n# after\nmodel_name_or_path: Qwen/Qwen2.5-7B  # qwen2 supported (or drop megatron bridge)","handlingStrategy":"validation","validationCode":"from transformers import AutoConfig\nfrom llamafactory.extras.constants import MEGATRON_BRIDGE_SUPPORTED_MODELS\nmodel_type = AutoConfig.from_pretrained(model_path).model_type\nassert model_type in MEGATRON_BRIDGE_SUPPORTED_MODELS, (\n    f'{model_type} unsupported by Megatron Bridge; supported: {sorted(MEGATRON_BRIDGE_SUPPORTED_MODELS)}'\n)","typeGuard":"def megatron_bridge_supports(model_name_or_path: str, trust_remote_code: bool = False) -> bool:\n    from transformers import AutoConfig\n    from llamafactory.extras.constants import MEGATRON_BRIDGE_SUPPORTED_MODELS\n    return AutoConfig.from_pretrained(model_name_or_path, trust_remote_code=trust_remote_code).model_type in MEGATRON_BRIDGE_SUPPORTED_MODELS","tryCatchPattern":"try:\n    run_exp()\nexcept ValueError as e:\n    if 'Megatron Bridge' in str(e):\n        raise SystemExit('Use a supported text model type or switch off the megatron_bridge backend') from e\n    raise","preventionTips":["Reserve the Megatron Bridge path for text-only LLMs; route multimodal runs to the standard trainer","Query MEGATRON_BRIDGE_SUPPORTED_MODELS in job validation before scheduling"],"tags":["megatron-bridge","model-support","multimodal","config"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}