{"record":{"id":"22b10a72fb2f86eb","repo":"invoke-ai/InvokeAI","slug":"missing-lora-layer-src-key","errorCode":null,"errorMessage":"Missing LoRA layer: '{src_key}'.","messagePattern":"Missing LoRA layer: '(.+?)'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/patches/lora_conversions/flux_diffusers_lora_conversion_utils.py","lineNumber":172,"sourceCode":"        # If none of the keys are present, return early.\n        keys_present = [key in grouped_state_dict for key in src_keys]\n        if not any(keys_present):\n            return\n\n        dim_0_offset = 0\n        sub_layers: list[BaseLayerPatch] = []\n        sub_layer_ranges: list[Range] = []\n        for src_key, src_weight_shape in zip(src_keys, src_weight_shapes, strict=True):\n            src_layer_dict = grouped_state_dict.pop(src_key, None)\n            if src_layer_dict is not None:\n                values = get_lora_layer_values(src_layer_dict)\n                # assert values[\"lora_down.weight\"].shape[1] == src_weight_shape[1]\n                # assert values[\"lora_up.weight\"].shape[0] == src_weight_shape[0]\n                sub_layers.append(any_lora_layer_from_state_dict(values))\n                sub_layer_ranges.append(Range(dim_0_offset, dim_0_offset + src_weight_shape[0]))\n            else:\n                if not allow_missing_keys:\n                    raise ValueError(f\"Missing LoRA layer: '{src_key}'.\")\n\n            dim_0_offset += src_weight_shape[0]\n\n        layers[dst_qkv_key] = MergedLayerPatch(sub_layers, sub_layer_ranges)\n\n    # time_text_embed.timestep_embedder -> time_in.\n    add_lora_layer_if_present(\"time_text_embed.timestep_embedder.linear_1\", \"time_in.in_layer\")\n    add_lora_layer_if_present(\"time_text_embed.timestep_embedder.linear_2\", \"time_in.out_layer\")\n\n    # time_text_embed.text_embedder -> vector_in.\n    add_lora_layer_if_present(\"time_text_embed.text_embedder.linear_1\", \"vector_in.in_layer\")\n    add_lora_layer_if_present(\"time_text_embed.text_embedder.linear_2\", \"vector_in.out_layer\")\n\n    # time_text_embed.guidance_embedder -> guidance_in.\n    add_lora_layer_if_present(\"time_text_embed.guidance_embedder.linear_1\", \"guidance_in\")\n    add_lora_layer_if_present(\"time_text_embed.guidance_embedder.linear_2\", \"guidance_in\")\n\n    # context_embedder -> txt_in.","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/patches/lora_conversions/flux_diffusers_lora_conversion_utils.py#L154-L190","documentation":"add_qkv_lora_layer_if_present merges per-layer LoRA sub-layers into a single MergedLayerPatch targeting the model's fused qkv weight. When a sub-layer's source key (src_key) cannot be found in the transformer state dict, the function raises ValueError('Missing LoRA layer: ...') unless allow_missing_keys is True. It guards against LoRAs written against a model whose qkv layout/shapes don't match the target model.","triggerScenarios":"Calling lora_layers_from_flux_diffusers_grouped_state_dict with allow_missing_keys=False (the default) and a grouped diffusers FLUX LoRA whose qkv sub-layer keys don't align with the model's qkv rows (e.g. LoRA trained on a differently-shaped/text-encoder-augmented FLUX variant).","commonSituations":"Mixing FLUX.1-dev LoRAs with FLUX.1-schnell or Flux variant models; LoRAs exported with extra or renamed attention projections; passing the wrong model path so source weight shapes differ.","solutions":["Pass allow_missing_keys=True to skip non-matching qkv sub-layers if partial application is acceptable.","Verify the LoRA and base checkpoint are the same FLUX variant; use a LoRA made for your exact model.","Inspect src_key and pre-check the model's state dict for it; drop or remap keys that don't exist before conversion."],"exampleFix":"// before\nlayers = lora_layers_from_flux_diffusers_grouped_state_dict(sd)\n// after\nlayers = lora_layers_from_flux_diffusers_grouped_state_dict(sd, allow_missing_keys=True)","handlingStrategy":"validation","validationCode":"model_keys = set(model_sd.keys())\nmissing = [k for k in lora_src_keys if k not in model_keys]\nassert not missing, f\"LoRA targets missing model keys: {missing}\"","typeGuard":null,"tryCatchPattern":"try:\n    layers = lora_layers_from_flux_diffusers_grouped_state_dict(sd, model_sd)\nexcept ValueError as e:\n    logger.warning(\"Missing qkv LoRA layer, retrying with allow_missing_keys: %s\", e)\n    layers = lora_layers_from_flux_diffusers_grouped_state_dict(sd, model_sd, allow_missing_keys=True)","preventionTips":["Match LoRA variant to the exact base checkpoint (dev vs schnell vs other FLUX).","Pre-check that LoRA source keys exist in the model state dict.","Use allow_missing_keys=True when partial application is acceptable."],"tags":["lora","flux","diffusers","missing-key"],"backgroundTag":"missing-lora-layer-key","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}