Skip to content

vllm.model_executor.hw_agnostic.custom_op

Classes:

CustomOp

Bases: Module

Base class for custom ops. Dispatches the forward method to the appropriate backend.

Methods:

  • default_on –

    Behavior controlled by CompilationConfig.custom_ops: On by default if

  • forward_native –

    PyTorch-native implementation; OOT plugins override via

  • maybe_compile –

    Compile fn if compilation enabled.

default_on() staticmethod

Behavior controlled by CompilationConfig.custom_ops: On by default if 'all', off by default if 'none'. When PyTorch Inductor is used, 'none' is the default value, otherwise 'all'.

forward_native(*args, **kwargs)

PyTorch-native implementation; OOT plugins override via forward_oot.

maybe_compile(fn, *, enable=True)

Compile fn if compilation enabled. Useful for CustomOp instances called from within a torch custom op, meaning the forward call is hidden from the model-level torch.compile.

NOTE: this does not enable fusion across ops, so opaque custom ops should still be unwrapped wherever possible.

PluggableLayer

Bases: Module

Base class for pluggable layers.

A PluggableLayer is a module-composing abstraction: it may instantiate other torch.nn.Module objects as sub-layers, and its functionality depends on these sub-layers following a generalized invocation sequence. Also, it is stateful and may hold parameters or buffers.

Unlike CustomOp, PluggableLayer does NOT provide per-platform forward_* dispatch. Instead, it supports out-of-tree (OOT) replacement of the entire layer class at instantiation time, allowing customized initialization and submodule composition.

_class_to_instantiate(cls, name)

The out-of-tree override registered for cls as name, else cls.

The in-tree and the hw-agnostic path keep separate registries, both keyed on the bare class name, so a class can be registered in the hw-agnostic path but not in the in-tree one, and vice versa. This catches the two cases where an override written against the in-tree class would go unnoticed:

  • Registered in the hw-agnostic path, but not derived from cls: Python would skip its __init__, so this raises.
  • Registered in the in-tree path, but not in the hw-agnostic one: it would never be used, so this warns.