{"record":{"id":"8952b247fbd8d8c4","repo":"invoke-ai/InvokeAI","slug":"only-gemma2encoder-gemma2encoder-config-models-are","errorCode":null,"errorMessage":"Only Gemma2Encoder_Gemma2Encoder_Config models are supported here.","messagePattern":"Only Gemma2Encoder_Gemma2Encoder_Config models are supported here\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_manager/load/model_loaders/gemma2_encoder.py","lineNumber":84,"sourceCode":"            out[\"embed_tokens.weight\"] = value\n        elif key == \"output_norm.weight\":\n            out[\"norm.weight\"] = value\n        else:\n            raise ValueError(f\"Unmapped Gemma-2 GGUF tensor key '{key}'\")\n    return out\n\n\n@ModelLoaderRegistry.register(base=BaseModelType.Any, type=ModelType.Gemma2Encoder, format=ModelFormat.Gemma2Encoder)\nclass Gemma2EncoderLoader(ModelLoader):\n    \"\"\"Loads a Gemma-2 causal LM directory and exposes its decoder + tokenizer.\"\"\"\n\n    def _load_model(\n        self,\n        config: AnyModelConfig,\n        submodel_type: Optional[SubModelType] = None,\n    ) -> AnyModel:\n        if not isinstance(config, Gemma2Encoder_Gemma2Encoder_Config):\n            raise ValueError(\"Only Gemma2Encoder_Gemma2Encoder_Config models are supported here.\")\n\n        model_path = Path(config.path)\n\n        match submodel_type:\n            case SubModelType.Tokenizer:\n                return AutoTokenizer.from_pretrained(model_path, local_files_only=True)\n            case SubModelType.TextEncoder:\n                target_device = TorchDevice.choose_torch_device()\n                model_dtype = TorchDevice.choose_bfloat16_safe_dtype(target_device)\n                causal_lm = AutoModelForCausalLM.from_pretrained(\n                    model_path,\n                    torch_dtype=model_dtype,\n                    low_cpu_mem_usage=True,\n                    local_files_only=True,\n                )\n                # PiD only ever uses the decoder block — the transformer stack\n                # without the LM head. Upstream calls `.get_decoder()`, but\n                # transformers 4.56 returns None for Gemma2, so we reach for","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/load/model_loaders/gemma2_encoder.py#L66-L102","documentation":"Gemma2EncoderLoader._load_model is registered only for Gemma2Encoder models and accepts a single config type: Gemma2Encoder_Gemma2Encoder_Config. If the model manager dispatches a config of any other class to this loader (a routing/registration bug or wrong model record), it refuses with this ValueError rather than loading the wrong model.","triggerScenarios":"A model record whose config class is not Gemma2Encoder_Gemma2Encoder_Config is routed to the Gemma2Encoder loader — e.g. a GGUF record handed to the non-GGUF loader because ModelFormat was recorded as Gemma2Encoder instead of GGUFQuantized, or a stale/incorrect models.yaml/DB entry.","commonSituations":"Model installed with the wrong format metadata so the registry picks the wrong loader; code calling Gemma2EncoderLoader._load_model directly with a foreign config object; refactors renaming the config class without updating model records.","solutions":["Ensure the model's format is GGUFQuantized so the Gemma2EncoderGGUFLoader handles it instead","Reinstall/re-convert the model so its config is Gemma2Encoder_Gemma2Encoder_Config","Check the registry registration format tags so dispatch selects the correct loader"],"exampleFix":"# before\nconfig = Gemma2Encoder_GGUF_Config(...)  # routed to Gemma2EncoderLoader\n# after\nmodel_format = ModelFormat.GGUFQuantized  # dispatched to Gemma2EncoderGGUFLoader","handlingStrategy":"type-guard","validationCode":"from invokeai.backend.model_manager.config import Gemma2Encoder_Gemma2Encoder_Config\ndef can_load_with_gemma2_encoder_loader(config):\n    return isinstance(config, Gemma2Encoder_Gemma2Encoder_Config)","typeGuard":"def is_gemma2_encoder_config(config) -> bool:\n    return isinstance(config, Gemma2Encoder_Gemma2Encoder_Config)","tryCatchPattern":"try:\n    model = loader._load_model(config, submodel_type)\nexcept ValueError as e:\n    if \"Only Gemma2Encoder_Gemma2Encoder_Config\" in str(e):\n        print(f\"Wrong loader for model {config.path}; check its recorded format\")\n    else:\n        raise","preventionTips":["Ensure model records store the correct ModelFormat so registry dispatch picks the right loader","Never call _load_model directly with configs of a different class","Re-convert models rather than hand-editing config/format metadata"],"tags":["model-loader","config-mismatch","gemma2"],"backgroundTag":"unsupported-model-config","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}