AUTOMATIC1111/stable-diffusion-webui · error · RuntimeError

hypernetwork uses an unsupported activation function: {activ

Error message

hypernetwork uses an unsupported activation function: {activation_func}

What it means

Hypernetwork module construction walks layer_structure building nn.Linear + activation layers; activation_func is looked up in self.activation_dict (torch activations like relu, leakrelu, gelu, swish...). 'linear'/None mean no activation; anything else that is not a key of activation_dict raises this RuntimeError, aborting hypernetwork creation/training.

Source

Thrown at modules/hypernetworks/hypernetwork.py:59

        self.multiplier = 1.0

        assert layer_structure is not None, "layer_structure must not be None"
        assert layer_structure[0] == 1, "Multiplier Sequence should start with size 1!"
        assert layer_structure[-1] == 1, "Multiplier Sequence should end with size 1!"

        linears = []
        for i in range(len(layer_structure) - 1):

            # Add a fully-connected layer
            linears.append(torch.nn.Linear(int(dim * layer_structure[i]), int(dim * layer_structure[i+1])))

            # Add an activation func except last layer
            if activation_func == "linear" or activation_func is None or (i >= len(layer_structure) - 2 and not activate_output):
                pass
            elif activation_func in self.activation_dict:
                linears.append(self.activation_dict[activation_func]())
            else:
                raise RuntimeError(f'hypernetwork uses an unsupported activation function: {activation_func}')

            # Add layer normalization
            if add_layer_norm:
                linears.append(torch.nn.LayerNorm(int(dim * layer_structure[i+1])))

            # Everything should be now parsed into dropout structure, and applied here.
            # Since we only have dropouts after layers, dropout structure should start with 0 and end with 0.
            if dropout_structure is not None and dropout_structure[i+1] > 0:
                assert 0 < dropout_structure[i+1] < 1, "Dropout probability should be 0 or float between 0 and 1!"
                linears.append(torch.nn.Dropout(p=dropout_structure[i+1]))
            # Code explanation : [1, 2, 1] -> dropout is missing when last_layer_dropout is false. [1, 2, 2, 1] -> [0, 0.3, 0, 0], when its True, [0, 0.3, 0.3, 0].

        self.linear = torch.nn.Sequential(*linears)

        if state_dict is not None:
            self.fix_old_state_dict(state_dict)
            self.load_state_dict(state_dict)
        else:

View on GitHub (pinned to 82a973c043)

Solutions

  1. Set activation_func to one of the keys of modules.hypernetworks.hypernetwork.HypernetworkModule.activation_dict (inspect it in a Python shell), or leave it as 'linear'/None for no activation.
  2. Check exact casing: names are lowercase keys like 'relu', 'leakyrelu', 'gelu', 'swish'.
  3. If loading an existing .pt hypernetwork, edit its activation string in the file or re-create the hypernetwork with a supported name and re-train.

Example fix

# before
hypernetwork.activation_func = 'GELU'  # RuntimeError: unsupported

# after
hypernetwork.activation_func = 'gelu'  # must be a key of activation_dict
Defensive patterns

Strategy: validation

Validate before calling

from modules.hypernetworks.hypernetwork import HypernetworkModule

def valid_activation(name):
    return name in HypernetworkModule.activation_dict or name in (None, 'linear')

assert valid_activation(requested_activation), \
    f'activation must be one of {list(HypernetworkModule.activation_dict)} or "linear"'

Type guard

def is_supported_activation(name: str) -> bool:
    return name is None or name == 'linear' or name in HypernetworkModule.activation_dict

Try / catch

try:
    hn = HypernetworkModule(..., activation_func=name)
except RuntimeError as e:
    if 'unsupported activation' in str(e):
        name = 'linear'  # or prompt user to re-pick
        hn = HypernetworkModule(..., activation_func=name)
    else:
        raise

Prevention

When it happens

Trigger: Creating or training a hypernetwork with AddHypernetworkActivationFunc / activation_func parameter set to a string not present in hypernetwork.activation_dict — e.g. 'GELU' (wrong case), 'tanh' if unsupported by the build's dict, or a typo like 're lu'.

Common situations: Typo or wrong casing in the activation function name in the UI dropdown or API payload; upgrading to a webui version whose activation_dict lost/renamed an alias; loading a hypernetwork template string that embeds an old activation name.

Related errors


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