{"record":{"id":"ac08a01aca7021b4","repo":"AUTOMATIC1111/stable-diffusion-webui","slug":"hypernetwork-uses-an-unsupported-activation-functi","errorCode":null,"errorMessage":"hypernetwork uses an unsupported activation function: {activation_func}","messagePattern":"hypernetwork uses an unsupported activation function: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"modules/hypernetworks/hypernetwork.py","lineNumber":59,"sourceCode":"        self.multiplier = 1.0\r\n\r\n        assert layer_structure is not None, \"layer_structure must not be None\"\r\n        assert layer_structure[0] == 1, \"Multiplier Sequence should start with size 1!\"\r\n        assert layer_structure[-1] == 1, \"Multiplier Sequence should end with size 1!\"\r\n\r\n        linears = []\r\n        for i in range(len(layer_structure) - 1):\r\n\r\n            # Add a fully-connected layer\r\n            linears.append(torch.nn.Linear(int(dim * layer_structure[i]), int(dim * layer_structure[i+1])))\r\n\r\n            # Add an activation func except last layer\r\n            if activation_func == \"linear\" or activation_func is None or (i >= len(layer_structure) - 2 and not activate_output):\r\n                pass\r\n            elif activation_func in self.activation_dict:\r\n                linears.append(self.activation_dict[activation_func]())\r\n            else:\r\n                raise RuntimeError(f'hypernetwork uses an unsupported activation function: {activation_func}')\r\n\r\n            # Add layer normalization\r\n            if add_layer_norm:\r\n                linears.append(torch.nn.LayerNorm(int(dim * layer_structure[i+1])))\r\n\r\n            # Everything should be now parsed into dropout structure, and applied here.\r\n            # Since we only have dropouts after layers, dropout structure should start with 0 and end with 0.\r\n            if dropout_structure is not None and dropout_structure[i+1] > 0:\r\n                assert 0 < dropout_structure[i+1] < 1, \"Dropout probability should be 0 or float between 0 and 1!\"\r\n                linears.append(torch.nn.Dropout(p=dropout_structure[i+1]))\r\n            # 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].\r\n\r\n        self.linear = torch.nn.Sequential(*linears)\r\n\r\n        if state_dict is not None:\r\n            self.fix_old_state_dict(state_dict)\r\n            self.load_state_dict(state_dict)\r\n        else:\r","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/hypernetworks/hypernetwork.py#L41-L77","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","solutions":["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.","Check exact casing: names are lowercase keys like 'relu', 'leakyrelu', 'gelu', 'swish'.","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."],"exampleFix":"# before\nhypernetwork.activation_func = 'GELU'  # RuntimeError: unsupported\n\n# after\nhypernetwork.activation_func = 'gelu'  # must be a key of activation_dict","handlingStrategy":"validation","validationCode":"from modules.hypernetworks.hypernetwork import HypernetworkModule\n\ndef valid_activation(name):\n    return name in HypernetworkModule.activation_dict or name in (None, 'linear')\n\nassert valid_activation(requested_activation), \\\n    f'activation must be one of {list(HypernetworkModule.activation_dict)} or \"linear\"'","typeGuard":"def is_supported_activation(name: str) -> bool:\n    return name is None or name == 'linear' or name in HypernetworkModule.activation_dict","tryCatchPattern":"try:\n    hn = HypernetworkModule(..., activation_func=name)\nexcept RuntimeError as e:\n    if 'unsupported activation' in str(e):\n        name = 'linear'  # or prompt user to re-pick\n        hn = HypernetworkModule(..., activation_func=name)\n    else:\n        raise","preventionTips":["Build UI dropdowns/API schemas from activation_dict keys instead of free-text.","Validate activation_func and weight_init together when parsing hypernetwork templates."],"tags":["hypernetwork","activation-function","validation","stable-diffusion"],"backgroundTag":null,"analyzedSha":"82a973c04367123ae98bd9abdf80d9eda9b910e2","analyzedAt":"2026-08-14T16:46:43.225Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}