Skip to content

vllm.multimodal.base

_T module-attribute

_T = TypeVar('_T')

MediaIO

Bases: ABC, Generic[_T]

Source code in vllm/multimodal/base.py
class MediaIO(ABC, Generic[_T]):
    @abstractmethod
    def load_bytes(self, data: bytes) -> _T:
        raise NotImplementedError

    @abstractmethod
    def load_base64(self, media_type: str, data: str) -> _T:
        """
        List of media types:
        https://www.iana.org/assignments/media-types/media-types.xhtml
        """
        raise NotImplementedError

    @abstractmethod
    def load_file(self, filepath: Path) -> _T:
        raise NotImplementedError

load_base64 abstractmethod

load_base64(media_type: str, data: str) -> _T

List of media types: https://www.iana.org/assignments/media-types/media-types.xhtml

Source code in vllm/multimodal/base.py
@abstractmethod
def load_base64(self, media_type: str, data: str) -> _T:
    """
    List of media types:
    https://www.iana.org/assignments/media-types/media-types.xhtml
    """
    raise NotImplementedError

load_bytes abstractmethod

load_bytes(data: bytes) -> _T
Source code in vllm/multimodal/base.py
@abstractmethod
def load_bytes(self, data: bytes) -> _T:
    raise NotImplementedError

load_file abstractmethod

load_file(filepath: Path) -> _T
Source code in vllm/multimodal/base.py
@abstractmethod
def load_file(self, filepath: Path) -> _T:
    raise NotImplementedError

MediaWithBytes dataclass

Bases: Generic[_T]

Wrapper that couples a media object with its original encoded bytes.

This ensures the raw bytes and media object remain synchronized, preventing cache corruption from in-place modifications.

The wrapper delegates attribute access to the underlying media object, making it behave transparently like the wrapped type (e.g., PIL.Image).

NOTE: Currently, this wrapper is used only for the image modality.

Source code in vllm/multimodal/base.py
@dataclass
class MediaWithBytes(Generic[_T]):
    """
    Wrapper that couples a media object with its original encoded bytes.

    This ensures the raw bytes and media object remain synchronized,
    preventing cache corruption from in-place modifications.

    The wrapper delegates attribute access to the underlying media object,
    making it behave transparently like the wrapped type (e.g., PIL.Image).

    NOTE: Currently, this wrapper is used only for the image modality.
    """

    media: _T
    original_bytes: bytes

    def __array__(self, *args, **kwargs) -> np.ndarray:
        """Allow np.array(obj) to return np.array(obj.media)."""
        return np.array(self.media, *args, **kwargs)

    def __getattr__(self, name: str):
        """Delegate attribute access to the underlying media object."""
        # This is only called when the attribute is not found on self
        return getattr(self.media, name)

media instance-attribute

media: _T

original_bytes instance-attribute

original_bytes: bytes

__array__

__array__(*args, **kwargs) -> ndarray

Allow np.array(obj) to return np.array(obj.media).

Source code in vllm/multimodal/base.py
def __array__(self, *args, **kwargs) -> np.ndarray:
    """Allow np.array(obj) to return np.array(obj.media)."""
    return np.array(self.media, *args, **kwargs)

__getattr__

__getattr__(name: str)

Delegate attribute access to the underlying media object.

Source code in vllm/multimodal/base.py
def __getattr__(self, name: str):
    """Delegate attribute access to the underlying media object."""
    # This is only called when the attribute is not found on self
    return getattr(self.media, name)

__init__

__init__(media: _T, original_bytes: bytes) -> None