Skip to content

vllm.kernels.oink_ops

oink_rms_supported module-attribute

oink_rms_supported = (
    lambda x, weight, epsilon, variance_size=None: (
        variance_size is None
        and weight is not None
        and dim() >= 2
        and dtype == dtype
        and is_contiguous()
        and _can_view_as_2d(x)
        and _is_oink_stride_compatible_2d(
            view(-1, shape[-1])
        )
    )
)

Oink rms only supports 2d-like inputs with contiguous weight and no variance_size override.

_can_view_as_2d

_can_view_as_2d(x: Tensor) -> bool

Return True if x.view(-1, x.shape[-1]) is viewable (no copy).

Source code in vllm/kernels/oink_ops.py
def _can_view_as_2d(x: torch.Tensor) -> bool:
    """Return True if x.view(-1, x.shape[-1]) is viewable (no copy)."""
    if x.dim() < 2:
        return False
    if x.dim() == 2:
        return True
    # For a view(-1, N) to be valid, all leading dims must be contiguous with
    # respect to each other (size-1 dims are ignored).
    for dim in range(x.dim() - 1):
        # Strides for size-1 dims are irrelevant and can be arbitrary.
        if x.size(dim + 1) != 1 and x.stride(dim) != x.stride(dim + 1) * x.size(
            dim + 1
        ):
            return False
    return True

_is_oink_stride_compatible_2d

_is_oink_stride_compatible_2d(x_2d: Tensor) -> bool

Return True if x_2d meets Oink's pointer-path stride constraints.

Source code in vllm/kernels/oink_ops.py
def _is_oink_stride_compatible_2d(x_2d: torch.Tensor) -> bool:
    """Return True if x_2d meets Oink's pointer-path stride constraints."""
    if x_2d.dim() != 2:
        return False
    if x_2d.stride(1) != 1:
        return False
    # Match Oink's vectorization constraint: stride(0) divisible by 256b.
    if x_2d.dtype in (torch.float16, torch.bfloat16):
        divby = 16
    elif x_2d.dtype == torch.float32:
        divby = 8
    else:
        return False
    return (x_2d.stride(0) % divby) == 0

has_oink_op

has_oink_op(name: str) -> bool

Check if a specific oink op is registered.

Source code in vllm/kernels/oink_ops.py
def has_oink_op(name: str) -> bool:
    """Check if a specific oink op is registered."""
    return OINK_AVAILABLE and hasattr(torch.ops.oink, name)