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

  1. Verify the LoRA was trained against the same base model architecture you currently have loaded
  2. 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
  3. Inspect the offending network_key with a .safetensors key viewer; delete non-LoRA keys or re-export the LoRA
  4. 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

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


AI-assisted analysis of AUTOMATIC1111/stable-diffusion-webui@82a973c043 (2026-08-14). Data as JSON: /api/errors/16897aef4573cffc. Report an issue: GitHub.