{"record":{"id":"ba133d247c368cf7","repo":"invoke-ai/InvokeAI","slug":"qwen3-encoder-variant-mismatch-flux-2-klein-main","errorCode":null,"errorMessage":"Qwen3 encoder variant mismatch: FLUX.2 Klein {main_config.variant.value} requires a {required_qwen3.value} encoder, but the {model_name} pipeline '{config.name}' ({source_variant.value}) carries {source_qwen3.value}. Select a Klein pipeline from the same family - 4B pairs with 4B, 9B with 9B.","messagePattern":"Qwen3 encoder variant mismatch: FLUX\\.2 Klein (.+?) requires a (.+?) encoder, but the (.+?) pipeline '(.+?)' \\((.+?)\\) carries (.+?)\\. Select a Klein pipeline from the same family - 4B pairs with 4B, 9B with 9B\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/flux2_klein_model_loader.py","lineNumber":250,"sourceCode":"        \"\"\"\n        config = self._validate_diffusers_format(context, model, model_name)\n        source_variant = getattr(config, \"variant\", None)\n        source_qwen3 = _KLEIN_TO_QWEN3_VARIANT.get(source_variant)\n\n        # An allowlist, not \"reject [dev]\": a future third FLUX.2 variant has to fail closed here\n        # the way the [dev] loader's guard already makes it, rather than being silently accepted.\n        if source_qwen3 is None:\n            described = f\"variant '{source_variant.value}'\" if source_variant is not None else \"not a Klein pipeline\"\n            raise ValueError(\n                f\"The {model_name} model must be a FLUX.2 Klein pipeline, \"\n                f\"but the selected model '{config.name}' is {described}. \"\n                \"Its text encoder is incompatible with the Klein transformer. \"\n                \"(Its VAE is compatible - this only blocks encoder extraction.)\"\n            )\n\n        required_qwen3 = _KLEIN_TO_QWEN3_VARIANT.get(getattr(main_config, \"variant\", None))\n        if required_qwen3 is not None and source_qwen3 != required_qwen3:\n            raise ValueError(\n                f\"Qwen3 encoder variant mismatch: FLUX.2 Klein {main_config.variant.value} requires a \"\n                f\"{required_qwen3.value} encoder, but the {model_name} pipeline '{config.name}' \"\n                f\"({source_variant.value}) carries {source_qwen3.value}. \"\n                \"Select a Klein pipeline from the same family - 4B pairs with 4B, 9B with 9B.\"\n            )\n\n    def _validate_qwen3_encoder_variant(self, context: InvocationContext, main_config: AnyModelConfig) -> None:\n        \"\"\"Validate that the standalone Qwen3 encoder variant matches the FLUX.2 Klein variant.\n\n        - FLUX.2 Klein 4B (and 4B Base) require the Qwen3 4B encoder\n        - FLUX.2 Klein 9B (and 9B Base) require the Qwen3 8B encoder\n        \"\"\"\n        if self.qwen3_encoder_model is None:\n            return\n\n        # `getattr(..., None)` rather than `hasattr`: the field can exist and still be None, and\n        # comparing None against the expected variant would then raise `AttributeError` on\n        # `.value` in the error path instead of the intended `ValueError`.","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/flux2_klein_model_loader.py#L232-L268","documentation":"_validate_encoder_source raised ValueError because the Qwen3 encoder carried by the source pipeline does not match the size required by the main Klein model's variant (e.g. a 9B encoder on a 4B Klein transformer). The loader enforces same-family pairing: Klein 4B pairs with Qwen3 4B, Klein 9B with Qwen3 8B.","triggerScenarios":"invoke() -> _validate_encoder_source where required_qwen3 = _KLEIN_TO_QWEN3_VARIANT[main_config.variant] exists but source_qwen3 (from the source pipeline's variant) differs from it.","commonSituations":"Mixing Klein 4B main model with a Klein 9B pipeline as encoder source (or vice versa); the model manager's variant tags mislabeled after manual import; grabbing whichever Klein pipeline is downloaded first.","solutions":["Select a source Klein pipeline from the same family as the main model (4B pipeline for 4B model, 9B for 9B)","Correct variant metadata on either model if the sizes actually match but tags differ","Instead supply a standalone matching Qwen3 encoder via 'Qwen3 Encoder'","Catch ValueError, read required vs source variants from both configs, and warn/redirect before invoke()"],"exampleFix":"// before\nmain = klein_4b_model; loader.qwen3_source_model = klein_9b_pipeline  # mismatch\n// after\nmain_cfg = context.models.get_config(main)\nsrc_cfg = context.models.get_config(source_pipeline)\nassert _KLEIN_TO_QWEN3_VARIANT[main_cfg.variant] == _KLEIN_TO_QWEN3_VARIANT[src_cfg.variant]\nloader.qwen3_source_model = klein_4b_pipeline","handlingStrategy":"validation","validationCode":"main_cfg = context.models.get_config(main_model)\nsrc_cfg = context.models.get_config(source_pipeline)\nreq = _KLEIN_TO_QWEN3_VARIANT.get(getattr(main_cfg, 'variant', None))\nsrc = _KLEIN_TO_QWEN3_VARIANT.get(getattr(src_cfg, 'variant', None))\nif req is not None and src != req:\n    raise ValueError(f\"encoder family mismatch: need {req}, source carries {src}\")","typeGuard":"def encoder_family_matches(main_cfg, source_cfg) -> bool:\n    return _KLEIN_TO_QWEN3_VARIANT.get(getattr(main_cfg, 'variant', None)) \\\n        == _KLEIN_TO_QWEN3_VARIANT.get(getattr(source_cfg, 'variant', None))","tryCatchPattern":"try:\n    output = loader.invoke(context)\nexcept ValueError as e:\n    if 'Qwen3 encoder variant mismatch' in str(e) and 'carries' in str(e):\n        loader.qwen3_source_model = select_same_family_pipeline(loader.model, context)\n        output = loader.invoke(context)\n    else:\n        raise","preventionTips":["Match Klein pipeline sizes explicitly (4B with 4B, 9B with 9B) when wiring sources","Fix variant metadata after manual model imports","Name/tag models by size family to avoid mix-ups"],"tags":["variant-mismatch","qwen3","model-size","invokeai"],"backgroundTag":"encoder-variant-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}