Skip to content

vllm.models.nemotron_shortcut.nvidia.mlp

Nemotron Shortcut dense MLP with the soft-clamped squared-ReLU activation.

Shared by the dense MLP blocks and by the MoE's shared experts, so it lives apart from both the model and the MoE package.

Classes:

NemotronShortcutClampedActivation

Bases: Module

Soft-clamps the pre-activation to activation_clamp_value before relu2.

Source code in vllm/models/nemotron_shortcut/nvidia/mlp.py
class NemotronShortcutClampedActivation(nn.Module):
    """Soft-clamps the pre-activation to `activation_clamp_value` before relu2."""

    def __init__(self, config: PreTrainedConfig) -> None:
        super().__init__()
        self.clamp_value = config.activation_clamp_value
        self.act_fn = get_act_fn(config.mlp_hidden_act)

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        if self.clamp_value is not None:
            x = (self.clamp_value * torch.tanh(x.float() / self.clamp_value)).to(
                x.dtype
            )
        return self.act_fn(x)