Skip to content

vllm.ir

Modules:

Functions:

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_op(f: Callable[..., Any]) -> IrOp
register_op(
    *,
    name: str | None = None,
    activations: list[str] | None = None,
    allow_inplace: Literal[False] = False,
) -> Callable[[Callable[..., Any]], IrOp]
register_op(
    *,
    name: str | None = None,
    activations: list[str] | None = None,
    allow_inplace: Literal[True],
) -> Callable[[Callable[..., Any]], IrOpInplace]

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:

@vllm.ir.register_op
def my_add(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
    return x + y


@vllm.ir.register_op(name="custom_mul")
def multiply(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
    return x * y

set_default_torch_wrap(enable=True)

Permanently set the torch wrap flag.