AUTOMATIC1111/stable-diffusion-webui · error · AssertionError
Lora layer {self.network_key} matched a layer with unsupport
Error message
Lora layer {self.network_key} matched a layer with unsupported type: {type(self.sd_module).__name__} What it means
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.
Source
Thrown at extensions-builtin/Lora/network_lora.py:59
is_conv = type(self.sd_module) in [torch.nn.Conv2d]
if is_linear:
weight = weight.reshape(weight.shape[0], -1)
module = torch.nn.Linear(weight.shape[1], weight.shape[0], bias=False)
elif is_conv and key == "lora_down.weight" or key == "dyn_up":
if len(weight.shape) == 2:
weight = weight.reshape(weight.shape[0], -1, 1, 1)
if weight.shape[2] != 1 or weight.shape[3] != 1:
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)
else:
module = torch.nn.Conv2d(weight.shape[1], weight.shape[0], (1, 1), bias=False)
elif is_conv and key == "lora_mid.weight":
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)
elif is_conv and key == "lora_up.weight" or key == "dyn_down":
module = torch.nn.Conv2d(weight.shape[1], weight.shape[0], (1, 1), bias=False)
else:
raise AssertionError(f'Lora layer {self.network_key} matched a layer with unsupported type: {type(self.sd_module).__name__}')
with torch.no_grad():
if weight.shape != module.weight.shape:
weight = weight.reshape(module.weight.shape)
module.weight.copy_(weight)
module.to(device=devices.cpu, dtype=devices.dtype)
module.weight.requires_grad_(False)
return module
def calc_updown(self, orig_weight):
up = self.up_model.weight.to(orig_weight.device)
down = self.down_model.weight.to(orig_weight.device)
output_shape = [up.size(0), down.size(1)]
if self.mid_model is not None:
# cp-decomposition
View on GitHub (pinned to 82a973c043)
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
Example fix
# before: class missing from supported list is_linear = type(self.sd_module) in [torch.nn.Linear, torch.nn.modules.linear.NonDynamicallyQuantizableLinear, torch.nn.MultiheadAttention] # after: include the custom linear class is_linear = type(self.sd_module) in [torch.nn.Linear, torch.nn.modules.linear.NonDynamicallyQuantizableLinear, torch.nn.MultiheadAttention, modules.models.sd3.mmdit.QkvLinear, MyCustomLinear]
Defensive patterns
Strategy: try-catch
Validate before calling
# before calling networks.load_networks / applying a LoRA
import torch
SUPPORTED = (torch.nn.Linear, torch.nn.modules.linear.NonDynamicallyQuantizableLinear, torch.nn.MultiheadAttention, torch.nn.Conv2d)
def lora_targets_supported(pairs):
# pairs: [(network_key, sd_module), ...]
bad = [k for k, m in pairs if not isinstance(m, SUPPORTED)]
return not bad, bad Type guard
def is_supported_lora_target(module) -> bool:
return isinstance(module, (torch.nn.Linear, torch.nn.modules.linear.NonDynamicallyQuantizableLinear, torch.nn.MultiheadAttention, torch.nn.Conv2d)) Try / catch
try:
networks.load_networks(shared.sd_model, [network_on_disk])
except AssertionError as e:
if 'unsupported type' in str(e):
shared.log.warning(f'skipping incompatible LoRA: {e}')
# remove it from the request's extra_networks and continue
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not find a module type (out of {', '.join([x.__class__
- Unable to find model info: {path}
- A tensor with NaNs was produced. Use --disable-nan-check com
- Multiple data.pkl found in {filename}
- Unknown checkpoint: {x}
AI-assisted analysis of AUTOMATIC1111/stable-diffusion-webui@82a973c043 (2026-08-14).
Data as JSON: /api/errors/16897aef4573cffc.
Report an issue: GitHub.