Skip to content

vllm.model_executor.layers.activation

Custom activation functions.

Classes:

Functions:

FastGELU

Bases: CustomOp

Methods:

  • forward_native –

    PyTorch-native implementation equivalent to forward().

forward_native(x)

PyTorch-native implementation equivalent to forward().

FatreluAndMul

Bases: CustomOp

An activation function for FATReLU.

The function computes x -> FATReLU(x[:d]) * x[d:] where d = x.shape[-1] // 2. This is used in openbmb/MiniCPM-S-1B-sft.

Shapes

x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d) return: (num_tokens, d) or (batch_size, seq_len, d)

GeluAndMul

Bases: CustomOp

An activation function for GeGLU.

The function computes x -> GELU(x[:d]) * x[d:] where d = x.shape[-1] // 2.

Shapes

x: (batch_size, seq_len, 2 * d) or (num_tokens, 2 * d) return: (batch_size, seq_len, d) or (num_tokens, d)

Methods:

  • forward_native –

    PyTorch-native implementation equivalent to forward().

forward_native(x)

PyTorch-native implementation equivalent to forward().

GeluAndMulSparse

Bases: CustomOp

An activation function for GeluAndMulSparse. This activation function is used in Gemma3n. It computes: up_proj = self.up_proj(x) gate_proj = self.gate_proj(x) gate_proj = self._gaussian_topk(gate_proj) # sparsity activations = self.act_fn(gate_proj) # gelu down_proj = self.down_proj(activations * up_proj) Shapes: x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d) return: (num_tokens, d) or (batch_size, seq_len, d)

Methods:

  • forward_native –

    PyTorch-native implementation equivalent to forward().

forward_native(x)

PyTorch-native implementation equivalent to forward().

MulAndSilu

Bases: CustomOp

An activation function for SwiGLU.

The function computes x -> x[:d] * silu(x[d:]) where d = x.shape[-1] // 2.

Shapes

x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d) return: (num_tokens, d) or (batch_size, seq_len, d)

Methods:

  • forward_native –

    PyTorch-native implementation equivalent to forward().

forward_native(x)

PyTorch-native implementation equivalent to forward().

NewGELU

Bases: CustomOp

Methods:

  • forward_native –

    PyTorch-native implementation equivalent to forward().

forward_native(x)

PyTorch-native implementation equivalent to forward().

QuickGELU

Bases: CustomOp

Methods:

  • forward_native –

    PyTorch-native implementation equivalent to forward().

forward_native(x)

PyTorch-native implementation equivalent to forward().

ReLUSquaredActivation

Bases: CustomOp

Applies the relu^2 activation introduced in https://arxiv.org/abs/2109.08668v2.

Methods:

  • forward_native –

    PyTorch-native implementation equivalent to forward().

forward_native(x)

PyTorch-native implementation equivalent to forward().

SiluAndMul

Bases: CustomOp

An activation function for SwiGLU.

The function computes x -> silu(x[:d]) * x[d:] where d = x.shape[-1] // 2.

Shapes

x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d) return: (num_tokens, d) or (batch_size, seq_len, d)

Methods:

  • forward_native –

    PyTorch-native implementation equivalent to forward().

forward_native(x) staticmethod

PyTorch-native implementation equivalent to forward().

SiluAndMulWithClamp

Bases: CustomOp

SwiGLU activation with input clamping (used by some MoE shared experts).

Computes

gate = clamp(x[..., :d], max=swiglu_limit) up = clamp(x[..., d:], min=-swiglu_limit, max=swiglu_limit) out = gate * sigmoid(alpha * gate) * (up + beta)

where d = x.shape[-1] // 2. The defaults alpha=1.0, beta=0.0 reduce this to silu(gate) * up; SwiGLU-OAI style models pass alpha (sigmoid scale) and beta=1.0 (up bias).

Shapes

x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d) return: (num_tokens, d) or (batch_size, seq_len, d)

SituAndMul

Bases: CustomOp

SituGLU activation used by Kimi models.

Computes beta * tanh(gate / beta) * sigmoid(gate) * up. When linear_beta is set, the up projection is also softly clipped with linear_beta * tanh(up / linear_beta).

SwigluOAIAndMul

Bases: CustomOp

Methods:

  • forward_native –

    PyTorch-native implementation equivalent to forward().

forward_native(x)

PyTorch-native implementation equivalent to forward().

SwigluStepAndMul

Bases: CustomOp

An activation function for SwiGLU with clamping.

Computes x -> silu(x[:d]).clamp(max=limit) * x[d:].clamp(-limit, limit) where d = x.shape[-1] // 2.

Shapes

x: (num_tokens, 2 * d) or (batch_size, seq_len, 2 * d) return: (num_tokens, d) or (batch_size, seq_len, d)

Methods:

  • forward_native –

    PyTorch-native implementation equivalent to forward().

forward_native(x)

PyTorch-native implementation equivalent to forward().

XIELU

Bases: CustomOp

Applies the xIELU activation function introduced in https://arxiv.org/abs/2411.13010 If the user has installed the nickjbrowning/XIELU, we import xIELU CUDA Otherwise, we emit a single warning and use xIELU Python

_xielu_cuda(x)

Firewall function to prevent torch.compile from seeing .item().

_get_gelu_pytorch_tanh()

Get PyTorch GELU with tanh approximation, with ROCm fallback and fast GELU for ARM.

get_act_and_mul_fn(act_fn_name, *, compile_native=True)

Get an activation-and-mul (i.e. SiluAndMul) function by name.

get_act_fn(act_fn_name)

Get an activation function by name.