vllm.ir.op
¶
Classes:
-
IrOp– -
IrOpImpl– -
IrOpInplace–IR op with inplace support via maybe_inplace.
Functions:
-
enable_torch_wrap–Context manager to enable/disable torch custom op wrapping for vLLM IR ops.
-
register_op–Register a new vLLM IR op.
-
set_default_torch_wrap–Permanently set the torch wrap flag.
Attributes:
-
RESERVED_PROVIDERS–Providers that are reserved and cannot be used for custom implementations.
RESERVED_PROVIDERS = ['native', 'unfused']
module-attribute
¶
Providers that are reserved and cannot be used for custom implementations.
_ENABLE_TORCH_WRAP = True
module-attribute
¶
Global override flag to control torch op layer wrapping.
IrOp
¶
Methods:
-
__repr__–Return unambiguous string representation.
-
__str__–Return human-readable string representation using docstring.
-
apply_arg_defaults–Return args with default values applied.
-
dispatch–Dispatch to the appropriate implementation based on current priority
-
get_priority–Get the current dispatch priority for implementations for this op.
-
register_fake–Register a fake impl for the torch custom op. If this method is not called,
-
register_impl–Register an implementation for this custom op.
-
set_default–Permanently set the dispatch priority for this op. Use this for
-
set_priority–Context manager setting the dispatch priority for this op's impls.
__repr__()
¶
Return unambiguous string representation.
__str__()
¶
Return human-readable string representation using docstring.
_fake_call(*args, **kwargs)
¶
Call to the fake implementation of the op. We use indirection because we want users to be able to register fake later but also want it to fall back to native directly by default, instead of going through the dispatching mechanism.
_inner_call(*args, **kwargs)
¶
Eager call to torch op lands here. When torch wrapping is disabled, call routes straight here instead of going through torch op dispatching.
apply_arg_defaults(args)
¶
Return args with default values applied. Defaults are taken from the native implementation signature.
SHOULD NOT BE USED IN THE DISPATCH PATH (SLOW). Only for Inductor lowering.
dispatch(*args, **kwargs)
¶
Dispatch to the appropriate implementation based on current priority and argument support checks. Returns the selected IrOpImpl.
THIS FUNCTION IS ON THE HOT PATH (OP DISPATCH), MUST BE FAST.
get_priority()
¶
Get the current dispatch priority for implementations for this op.
register_fake(fn)
¶
Register a fake impl for the torch custom op. If this method is not called, the native implementation is used directly for the fake implementation.
register_impl(provider, *, supported=True, supports_args=None, inplace=False, functional_impl=None)
¶
Register an implementation for this custom op.
Parameters:
-
(provider¶str) –The name of the provider, must be unique.
-
(supported¶bool, default:True) –Static support check, use this to check platform support.
-
(supports_args¶Callable[..., bool] | None, default:None) –Dynamic arg support check, used for types and shapes.
-
(inplace¶bool, default:False) –Does this op reuse activation input memory for outputs
-
(functional_impl¶Callable[..., Any] | None, default:None) –Optional out-of-place variant of an inplace impl. Used for the functional overload (e.g. Inductor lowering) instead of cloning activations before the inplace impl.
Returns:
The decorated function must have the same semantics and signature as the native implementation.
The provider name must be unique and not one of the RESERVED_PROVIDERS. The supported and supports_args parameters should not be used to implement custom enablement logic based on global state (e.g. environment variables). Instead, supported param should only be used to check for platform support (e.g. whether a specific hardware or library is available). supports_args should be used to check whether the provided arguments are compatible with the implementation. For custom enablement logic, set op impl priority.
Example:
set_default(priority)
¶
Permanently set the dispatch priority for this op. Use this for
process-lifetime setup (e.g., worker startup). For scoped overrides,
use set_priority instead.
set_priority(priority)
¶
Context manager setting the dispatch priority for this op's impls.
IrOpImpl
¶
Methods:
-
func_impl_fn–Copy any inputs in activations if this is an inplace impl,
-
uuid–Compile-time hash to uniquely determine whether the implementation has
Attributes:
-
supports_all_args(bool) –Check if this implementation supports all args unconditionally.
supports_all_args
property
¶
Check if this implementation supports all args unconditionally.
func_impl_fn(*args, **kwargs)
¶
Copy any inputs in activations if this is an inplace impl, to ensure functional semantics.
uuid()
¶
Compile-time hash to uniquely determine whether the implementation has changed. Used by vllm-compile hash mechanism and torch.compile lowering pass uuid to control the vLLM compile cache and AOTAutograd/Inductor caches respectively.
Source file contents do not change so we cache uuid. TODO(luka): Cache the file hash as multiple impls are likely in the same file.
_torch_ops_subtree(lib)
¶
torch.ops subtree for lib.ns; fall back if doc mocks replace ns.
_validate_name(name, entity_type)
¶
Validate that a name matches the required pattern [a-z_][a-z_0-9]*.
enable_torch_wrap(enable=True)
¶
Context manager to enable/disable torch custom op wrapping for vLLM IR ops. When torch wrapping is disabled, the torch custom op layer is skipped and IR ops dispatch directly to the implementation. Helpful for avoiding torch dispatch overhead in eager mode and avoiding the need for lowering for platforms not using Inductor.
register_op(f=None, *, name=None, activations=None, allow_inplace=False)
¶
Register a new vLLM IR op.
Parameters:
-
(f¶Callable | None, default:None) –the native implementation of the op
-
(name¶str | None, default:None) –the name of the op, defaults to the function name
-
(activations¶list[str] | None, default:None) –list of activation params, defaults to params starting with 'x'
-
(allow_inplace¶bool, default:False) –add a maybe_inplace overload that allows inplace impls
Returns:
Example usage:
set_default_torch_wrap(enable=True)
¶
Permanently set the torch wrap flag.