{"record":{"id":"12eb17c08c446a9a","repo":"invoke-ai/InvokeAI","slug":"krea-2-requires-a-qwen3-vl-4b-checkpoint-with-hidd","errorCode":null,"errorMessage":"Krea-2 requires a Qwen3-VL 4B checkpoint with hidden size {_KREA2_QWEN3_VL_HIDDEN_SIZE}, got {hidden_size}","messagePattern":"Krea-2 requires a Qwen3-VL 4B checkpoint with hidden size (.+?), got (.+?)","errorType":"exception","errorClass":"NotAMatchError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_manager/configs/qwen3_vl_encoder.py","lineNumber":79,"sourceCode":"            if not candidate.is_relative_to(root):\n                return False\n            referenced_files.add(candidate)\n        return bool(referenced_files) and all(path.is_file() for path in referenced_files)\n    return False\n\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)","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/qwen3_vl_encoder.py#L61-L97","documentation":"InvokeAI's Qwen3-VL encoder config (used by Krea-2) inspects the embedding weight tensor of a single-file .safetensors checkpoint and requires its second dimension (hidden size) to be exactly 2560 (the Qwen3-VL 4B architecture). This NotAMatchError is thrown when the embedding tensor is missing, malformed, or has a different hidden size, meaning the checkpoint is not a Qwen3-VL 4B model. It is a model-identification guard so incompatible weights are not silently registered as a Krea-2 text encoder.","triggerScenarios":"Calling Qwen3VLEncoder_Checkpoint_Config.from_model_on_disk on a .safetensors file whose state dict passed the visual-tower heuristic but whose embed tensor (model.embed_tokens.weight and siblings) has shape[1] != 2560, is 1-dimensional, or is absent.","commonSituations":"Pointing InvokeAI at a Qwen3-VL model in a different size (e.g. 2B or 8B variant with hidden_size 2048/4096), a text-only Qwen3 encoder file mislabeled with a visual tower, a truncated or partially downloaded safetensors file, or a quantized/repacked checkpoint with renamed or reshaped embedding tensors.","solutions":["Download the correct Qwen3-VL 4B checkpoint (e.g. Qwen/Qwen3-VL-4B-Instruct or the Krea-2-specified encoder) whose hidden_size is 2560.","Verify the checkpoint is complete: re-download the .safetensors file and compare its size/hash against the source.","Open the safetensors header and confirm model.embed_tokens.weight has shape [vocab_size, 2560]; if you converted the model yourself, redo the conversion without reshaping the embedding.","If the file is genuinely a different architecture, do not register it as a Qwen3VLEncoder; import it under its proper model type instead."],"exampleFix":"// before: wrong-size variant downloaded\nmodels/qwen3vl/qwen_3vl_2b.safetensors   # hidden_size 2048 -> NotAMatchError\n// after: Krea-2 requires the 4B checkpoint\nmodels/qwen3vl/qwen_3vl_4b_instruct.safetensors  # embed_tokens.weight: [151936, 2560]","handlingStrategy":"validation","validationCode":"from safetensors import safe_open\n\ndef validate_qwen3vl_4b_checkpoint(path: str) -> bool:\n    with safe_open(path, framework=\"pt\") as f:\n        for key in (\"model.embed_tokens.weight\", \"model.language_model.embed_tokens.weight\",\n                    \"language_model.embed_tokens.weight\", \"embed_tokens.weight\"):\n            if key in f.keys():\n                return f.get_slice(key).get_shape()[1] == 2560\n        return False","typeGuard":"def is_qwen3vl_4b_state_dict(sd: dict) -> bool:\n    embed = next((sd[k] for k in (\"model.embed_tokens.weight\", \"embed_tokens.weight\") if k in sd), None)\n    shape = getattr(embed, \"shape\", ())\n    return len(shape) >= 2 and shape[1] == 2560 and any(\".layers.35.\" in k for k in sd)","tryCatchPattern":"from invokeai.backend.model_manager.configs.identification_utils import NotAMatchError\n\ntry:\n    config = Qwen3VLEncoder_Checkpoint_Config.from_model_on_disk(mod, {})\nexcept NotAMatchError:\n    logger.warning(\"%s is not a Qwen3-VL 4B checkpoint (hidden_size must be 2560)\", mod.path)","preventionTips":["Always download the exact checkpoint variant Krea-2 documents (Qwen3-VL 4B, hidden_size 2560).","Check the safetensors header shapes before importing a converted or quantized checkpoint.","Verify file size/hash after downloading large model files.","Keep conversions faithful: never reshape or rename embedding tensors when repacking checkpoints."],"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"}