import numpy as np

def gelu(x):
    """Gaussian Error Linear Unit (approximation)."""
    return 0.5 * x * (1.0 + np.tanh(np.sqrt(2.0 / np.pi) * (x + 0.044715 * np.power(x, 3.0))))

def silu(x):
    """Sigmoid Linear Unit (SiLU), also known as Swish."""
    return x * (1.0 / (1.0 + np.exp(-x)))

def softmax(x, axis=-1):
    """Stable softmax implementation."""
    e_x = np.exp(x - np.max(x, axis=axis, keepdims=True))
    return e_x / e_x.sum(axis=axis, keepdims=True)

def rms_norm(x, weight, eps=1e-6):
    """Root Mean Square Layer Normalization."""
    norm = np.sqrt(np.mean(x**2, axis=-1, keepdims=True) + eps)
    return x / norm * weight
