{"record":{"id":"5cacd1ddaca9509d","repo":"invoke-ai/InvokeAI","slug":"krea-2-requires-a-qwen3-vl-4b-checkpoint-containin","errorCode":null,"errorMessage":"Krea-2 requires a Qwen3-VL 4B checkpoint containing language-model layer 35","messagePattern":"Krea-2 requires a Qwen3-VL 4B checkpoint containing language-model layer 35","errorType":"validation","errorClass":"NotAMatchError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_manager/configs/qwen3_vl_encoder.py","lineNumber":84,"sourceCode":"\n\ndef _validate_krea2_qwen3_vl_checkpoint_shape(state_dict: dict[str | int, Any]) -> None:\n    embed_keys = (\n        \"model.embed_tokens.weight\",\n        \"model.language_model.embed_tokens.weight\",\n        \"language_model.embed_tokens.weight\",\n        \"embed_tokens.weight\",\n    )\n    embed = next((state_dict[key] for key in embed_keys if key in state_dict), None)\n    shape = getattr(embed, \"shape\", ())\n    if len(shape) < 2 or shape[1] != _KREA2_QWEN3_VL_HIDDEN_SIZE:\n        hidden_size = shape[1] if len(shape) >= 2 else None\n        raise NotAMatchError(\n            f\"Krea-2 requires a Qwen3-VL 4B checkpoint with hidden size \"\n            f\"{_KREA2_QWEN3_VL_HIDDEN_SIZE}, got {hidden_size}\"\n        )\n    if not any(isinstance(key, str) and \".layers.35.\" in key for key in state_dict):\n        raise NotAMatchError(\"Krea-2 requires a Qwen3-VL 4B checkpoint containing language-model layer 35\")\n\n\nclass Qwen3VLEncoder_Qwen3VLEncoder_Config(Config_Base):\n    \"\"\"Configuration for standalone Qwen3-VL text encoder models (diffusers-like directory format).\n\n    Used by Krea-2, whose text conditioning comes from a Qwen3-VL model (``Qwen3VLModel``). The model\n    weights are expected either in a ``text_encoder`` subfolder of the model directory or directly at the\n    root (standalone download). This is distinct from the text-only ``Qwen3Encoder`` (Z-Image / FLUX.2\n    Klein) and the Qwen2.5-VL ``QwenVLEncoder`` (Qwen Image).\n    \"\"\"\n\n    base: Literal[BaseModelType.Any] = Field(default=BaseModelType.Any)\n    type: Literal[ModelType.Qwen3VLEncoder] = Field(default=ModelType.Qwen3VLEncoder)\n    format: Literal[ModelFormat.Qwen3VLEncoder] = Field(default=ModelFormat.Qwen3VLEncoder)\n    cpu_only: bool | None = Field(default=None, description=\"Whether this model should run on CPU only\")\n\n    @classmethod\n    def from_model_on_disk(cls, mod: ModelOnDisk, override_fields: dict[str, Any]) -> Self:","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/qwen3_vl_encoder.py#L66-L102","documentation":"After checking hidden size, the same validator requires the state dict to contain a language-model layer with index 35 (\".layers.35.\"), which only exists in the full 36-layer Qwen3-VL 4B decoder. This NotAMatchError is thrown when layer 35 is missing, indicating the checkpoint is a smaller/trimmed Qwen3-VL model or a truncated weight file rather than the required 4B checkpoint.","triggerScenarios":"Qwen3VLEncoder_Checkpoint_Config.from_model_on_disk loads a .safetensors state dict that has an embed token and a visual tower, but no key matching \".layers.35.\" (0-indexed layer 35 of 36), then calls _validate_krea2_qwen3_vl_checkpoint_shape.","commonSituations":"Using a smaller Qwen3-VL variant (fewer layers, e.g. 2B with ~28 layers), a pruned or layer-dropped distillation, a sharded download where the shard containing the final layers was not fully downloaded/converted, or hand-built state dicts that omit trailing layers.","solutions":["Obtain the complete Qwen3-VL 4B checkpoint (36 layers) referenced by Krea-2 and re-import it.","List the state-dict keys (e.g. with safetensors.safe_open) and confirm keys like model.language_model.layers.35.* exist; if not, re-download missing shards.","If the model is sharded, ensure all shards and the index file are present and fully downloaded before scanning the folder.","If you intentionally use a trimmed model, register it under a different model type; InvokeAI will not accept it as the Krea-2 encoder."],"exampleFix":"// before: trimmed checkpoint keys end at layer 27\nmodel.layers.27.self_attn.q_proj.weight\n// after: full 4B checkpoint contains layers 0..35\nmodel.layers.35.mlp.down_proj.weight  # required by validator","handlingStrategy":"validation","validationCode":"from safetensors import safe_open\n\ndef has_all_36_layers(path: str) -> bool:\n    with safe_open(path, framework=\"pt\") as f:\n        keys = f.keys()\n        return any(\".layers.35.\" in k for k in keys)","typeGuard":"def is_full_depth_qwen3vl(sd: dict) -> bool:\n    return any(isinstance(k, str) and \".layers.35.\" in k for k in sd)","tryCatchPattern":"try:\n    cfg = Qwen3VLEncoder_Checkpoint_Config.from_model_on_disk(mod, {})\nexcept NotAMatchError:\n    logger.warning(\"Checkpoint %s lacks layer 35; expected the full 36-layer Qwen3-VL 4B model\", mod.path)","preventionTips":["Confirm the model card states 36 layers (num_hidden_layers=36) before downloading a Qwen3-VL encoder for Krea-2.","For sharded downloads, ensure every shard finished downloading before importing.","Avoid pruned/layer-dropped community reuploads of Qwen3-VL.","Inspect state-dict key ranges (layers.0 ... layers.35) before adding a checkpoint to the models folder."],"tags":["model-loading","checkpoint-validation","invokeai","krea-2","qwen3-vl"],"backgroundTag":"model-checkpoint-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}