vllm.model_executor.custom_op
¶
Classes:
-
CustomOp–Base class for custom ops.
-
PluggableLayer–Base class for pluggable layers.
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 of the forward method.
-
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 of the forward method. This method is optional. If implemented, it can be used with compilers such as torch.compile or PyTorch XLA. Also, it can be used for testing purposes.
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.