Skip to content

vllm.utils.registry

Classes:

ExtensionManager

A registry for managing pluggable extension classes.

This class provides a simple mechanism to register and instantiate extension classes by name. It is commonly used to implement plugin systems where different implementations can be swapped at runtime.

Examples:

Basic usage with a registry instance:

>>> FOO_REGISTRY = ExtensionManager()
>>> @FOO_REGISTRY.register("my_foo_impl")
... class MyFooImpl(Foo):
...     def __init__(self, value):
...         self.value = value
>>> foo_impl = FOO_REGISTRY.load("my_foo_impl", value=123)

Methods:

  • __init__ –

    Initialize an empty extension registry.

  • load –

    Instantiate and return a registered extension class by name.

  • register –

    Decorator to register a class with the given name.

Source code in vllm/utils/registry.py
class ExtensionManager:
    """A registry for managing pluggable extension classes.

    This class provides a simple mechanism to register and instantiate
    extension classes by name. It is commonly used to implement plugin
    systems where different implementations can be swapped at runtime.

    Examples:
        Basic usage with a registry instance:

        >>> FOO_REGISTRY = ExtensionManager()
        >>> @FOO_REGISTRY.register("my_foo_impl")
        ... class MyFooImpl(Foo):
        ...     def __init__(self, value):
        ...         self.value = value
        >>> foo_impl = FOO_REGISTRY.load("my_foo_impl", value=123)

    """

    def __init__(self) -> None:
        """Initialize an empty extension registry."""
        self.name2class: dict[str, type] = {}

    def register(self, name: str):
        """Decorator to register a class with the given name."""

        def wrap(cls_to_register: _T) -> _T:
            self.name2class[name] = cls_to_register
            return cls_to_register

        return wrap

    def load(self, cls_name: str, *args, **kwargs) -> Any:
        """Instantiate and return a registered extension class by name."""
        cls = self.name2class.get(cls_name)
        assert cls is not None, f"Extension class {cls_name} not found"
        return cls(*args, **kwargs)

__init__()

Initialize an empty extension registry.

Source code in vllm/utils/registry.py
def __init__(self) -> None:
    """Initialize an empty extension registry."""
    self.name2class: dict[str, type] = {}

load(cls_name, *args, **kwargs)

Instantiate and return a registered extension class by name.

Source code in vllm/utils/registry.py
def load(self, cls_name: str, *args, **kwargs) -> Any:
    """Instantiate and return a registered extension class by name."""
    cls = self.name2class.get(cls_name)
    assert cls is not None, f"Extension class {cls_name} not found"
    return cls(*args, **kwargs)

register(name)

Decorator to register a class with the given name.

Source code in vllm/utils/registry.py
def register(self, name: str):
    """Decorator to register a class with the given name."""

    def wrap(cls_to_register: _T) -> _T:
        self.name2class[name] = cls_to_register
        return cls_to_register

    return wrap