sgl-project/sglang · error · ValueError

Activation function {act_fn_name!r} is not supported.

Error message

Activation function {act_fn_name!r} is not supported.

What it means

get_act_fn looks up activation functions by lowercased name in the module's _ACTIVATION_REGISTRY. Unknown names raise ValueError, so any model config whose activation string is not registered (gelu, silu, relu, etc. — whatever the registry contains) fails at layer construction time.

Source

Thrown at python/sglang/multimodal_gen/runtime/layers/activation.py:160

        """PyTorch-native implementation equivalent to forward()."""
        return x * torch.sigmoid(1.702 * x)


_ACTIVATION_REGISTRY = {
    "gelu": nn.GELU,
    "gelu_new": NewGELU,
    "gelu_pytorch_tanh": lambda: nn.GELU(approximate="tanh"),
    "relu": nn.ReLU,
    "silu": nn.SiLU,
    "quick_gelu": QuickGELU,
}


def get_act_fn(act_fn_name: str) -> nn.Module:
    """Get an activation function by name."""
    act_fn_name = act_fn_name.lower()
    if act_fn_name not in _ACTIVATION_REGISTRY:
        raise ValueError(f"Activation function {act_fn_name!r} is not supported.")

    return _ACTIVATION_REGISTRY[act_fn_name]()

View on GitHub (pinned to 0132848349)

Solutions

  1. Inspect _ACTIVATION_REGISTRY in the same module to see supported names and use one of them.
  2. Add the missing name/alias to the registry (e.g. map 'swish' → the silu module) at module scope.
  3. Fix the model config's hidden_act/activation string to a canonical name.

Example fix

# before
act = get_act_fn('swish')  # ValueError
# after
# register alias near the registry definition
_ACTIVATION_REGISTRY['swish'] = _ACTIVATION_REGISTRY['silu']
act = get_act_fn('swish')
Defensive patterns

Strategy: validation

Validate before calling

from sglang.multimodal_gen.runtime.layers.activation import _ACTIVATION_REGISTRY
name = cfg.hidden_act.lower()
if name not in _ACTIVATION_REGISTRY:
    raise SystemExit(f"unsupported activation {name}; supported: {sorted(_ACTIVATION_REGISTRY)}")

Type guard

def is_supported_act(name: str) -> bool:
    from ...activation import _ACTIVATION_REGISTRY
    return name.lower() in _ACTIVATION_REGISTRY

Prevention

When it happens

Trigger: Calling get_act_fn('swish') or any name not present in _ACTIVATION_REGISTRY — usually because a new model config uses an activation alias (e.g. 'gelu_new', 'quick_gelu', 'silu2') that this build hasn't registered.

Common situations: Adding support for a new architecture whose config uses an unregistered activation string; typo in config; aliases not normalized (case is handled via .lower(), but underscores/aliases are not).

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/7970324c73fcf199. Report an issue: GitHub.