{"record":{"id":"16897aef4573cffc","repo":"AUTOMATIC1111/stable-diffusion-webui","slug":"lora-layer-self-network-key-matched-a-layer-with","errorCode":null,"errorMessage":"Lora layer {self.network_key} matched a layer with unsupported type: {type(self.sd_module).__name__}","messagePattern":"Lora layer (.+?) matched a layer with unsupported type: (.+?)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"extensions-builtin/Lora/network_lora.py","lineNumber":59,"sourceCode":"        is_conv = type(self.sd_module) in [torch.nn.Conv2d]\r\n\r\n        if is_linear:\r\n            weight = weight.reshape(weight.shape[0], -1)\r\n            module = torch.nn.Linear(weight.shape[1], weight.shape[0], bias=False)\r\n        elif is_conv and key == \"lora_down.weight\" or key == \"dyn_up\":\r\n            if len(weight.shape) == 2:\r\n                weight = weight.reshape(weight.shape[0], -1, 1, 1)\r\n\r\n            if weight.shape[2] != 1 or weight.shape[3] != 1:\r\n                module = torch.nn.Conv2d(weight.shape[1], weight.shape[0], self.sd_module.kernel_size, self.sd_module.stride, self.sd_module.padding, bias=False)\r\n            else:\r\n                module = torch.nn.Conv2d(weight.shape[1], weight.shape[0], (1, 1), bias=False)\r\n        elif is_conv and key == \"lora_mid.weight\":\r\n            module = torch.nn.Conv2d(weight.shape[1], weight.shape[0], self.sd_module.kernel_size, self.sd_module.stride, self.sd_module.padding, bias=False)\r\n        elif is_conv and key == \"lora_up.weight\" or key == \"dyn_down\":\r\n            module = torch.nn.Conv2d(weight.shape[1], weight.shape[0], (1, 1), bias=False)\r\n        else:\r\n            raise AssertionError(f'Lora layer {self.network_key} matched a layer with unsupported type: {type(self.sd_module).__name__}')\r\n\r\n        with torch.no_grad():\r\n            if weight.shape != module.weight.shape:\r\n                weight = weight.reshape(module.weight.shape)\r\n            module.weight.copy_(weight)\r\n\r\n        module.to(device=devices.cpu, dtype=devices.dtype)\r\n        module.weight.requires_grad_(False)\r\n\r\n        return module\r\n\r\n    def calc_updown(self, orig_weight):\r\n        up = self.up_model.weight.to(orig_weight.device)\r\n        down = self.down_model.weight.to(orig_weight.device)\r\n\r\n        output_shape = [up.size(0), down.size(1)]\r\n        if self.mid_model is not None:\r\n            # cp-decomposition\r","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/extensions-builtin/Lora/network_lora.py#L41-L77","documentation":"Raised by LoraModule.create_module in the built-in Lora extension when a LoRA weight key maps to a target module (sd_module) whose PyTorch type is neither a Linear-like layer (torch.nn.Linear, NonDynamicallyQuantizableLinear, MultiheadAttention, sd3 QkvLinear) nor torch.nn.Conv2d. The LoRA loader can only synthesize matching up/down/mid adapter modules for those layer types, so any other module type is a hard error during network creation.","triggerScenarios":"Loading a .safetensors/.pt LoRA whose keys match a layer such as Conv1d, Conv3d, LayerNorm, GroupNorm, or a custom/renamed module class (e.g. from a new architecture like SD3/Flux variants where a linear-ish class was not added to the is_linear list). Also triggered when key naming is unexpected so none of the key branches (lora_down/lora_up/lora_mid/dyn_up/dyn_down) match even for a supported module.","commonSituations":"Using a LoRA trained for a different base model architecture (e.g. a Flux or SD3 LoRA on an older webui build, or vice versa); new attention implementations (xFormers/QkvLinear variants) not covered by the type list; community LoRAs containing training-artifact keys that matched an unrelated layer; version drift after a webui upgrade that changed module classes.","solutions":["Verify the LoRA was trained against the same base model architecture you currently have loaded","Update the webui to the latest version so newly supported module types (e.g. QkvLinear for SD3) are in the is_linear/is_conv lists","Inspect the offending network_key with a .safetensors key viewer; delete non-LoRA keys or re-export the LoRA","If the module genuinely is linear-shaped, add its class to the is_linear list in extensions-builtin/Lora/network_lora.py:40 and rebuild"],"exampleFix":"# before: class missing from supported list\nis_linear = type(self.sd_module) in [torch.nn.Linear, torch.nn.modules.linear.NonDynamicallyQuantizableLinear, torch.nn.MultiheadAttention]\n\n# after: include the custom linear class\nis_linear = type(self.sd_module) in [torch.nn.Linear, torch.nn.modules.linear.NonDynamicallyQuantizableLinear, torch.nn.MultiheadAttention, modules.models.sd3.mmdit.QkvLinear, MyCustomLinear]","handlingStrategy":"try-catch","validationCode":"# before calling networks.load_networks / applying a LoRA\nimport torch\nSUPPORTED = (torch.nn.Linear, torch.nn.modules.linear.NonDynamicallyQuantizableLinear, torch.nn.MultiheadAttention, torch.nn.Conv2d)\ndef lora_targets_supported(pairs):\n    # pairs: [(network_key, sd_module), ...]\n    bad = [k for k, m in pairs if not isinstance(m, SUPPORTED)]\n    return not bad, bad","typeGuard":"def is_supported_lora_target(module) -> bool:\n    return isinstance(module, (torch.nn.Linear, torch.nn.modules.linear.NonDynamicallyQuantizableLinear, torch.nn.MultiheadAttention, torch.nn.Conv2d))","tryCatchPattern":"try:\n    networks.load_networks(shared.sd_model, [network_on_disk])\nexcept AssertionError as e:\n    if 'unsupported type' in str(e):\n        shared.log.warning(f'skipping incompatible LoRA: {e}')\n        # remove it from the request's extra_networks and continue\n    else:\n        raise","preventionTips":["Only use LoRAs trained for the base architecture currently loaded","Keep webui updated so new module types are supported","Preview safetensors keys before importing community LoRAs"],"tags":["lora","pytorch","model-loading","stable-diffusion-webui"],"backgroundTag":null,"analyzedSha":"82a973c04367123ae98bd9abdf80d9eda9b910e2","analyzedAt":"2026-08-14T16:46:43.225Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}