Skip to content

vllm.v1.hisparse.backend

Device operations used by the common HiSparse runtime and connector.

Classes:

HiSparseBackend

Methods:

Source code in vllm/v1/hisparse/backend.py
class HiSparseBackend:
    supports_shared_host_pool = False
    stats_dtype = torch.uint64

    def check_available(self) -> None:
        raise NotImplementedError

    def pin_tensor(self, tensor: torch.Tensor) -> None:
        raise NotImplementedError

    def unpin_tensor(self, tensor: torch.Tensor) -> None:
        raise NotImplementedError

    def create_cache_ops(self, runtime: HiSparseRuntime) -> Any:
        raise NotImplementedError

    def validate_kv_cache_config(self, kv_cache_config: KVCacheConfig) -> None:
        """Validate device cache formats before allocating or pinning storage."""

    def prepare_kv_cache_views(
        self,
        kv_cache_config: KVCacheConfig,
        kv_caches: dict[str, Any],
        forward_context: dict[str, Any],
    ) -> None:
        """Adapt device views before runtime binding; retain allocation ownership.

        Called once per cache initialization, inside the common rollback scope.
        Backends must not put per-step metadata or transfers in this hook.
        """

    def create_ipc_event(self) -> Any:
        """Create an event that can be exported to another process."""
        raise NotImplementedError

    def export_event(self, event: Any) -> Any:
        raise NotImplementedError

    def import_event(self, device: torch.device, handle: Any) -> Any:
        raise NotImplementedError

    def gather_resident_rows(
        self, source: torch.Tensor, destination: torch.Tensor, row_ids: torch.Tensor
    ) -> None:
        """Copy resident rows into staging without changing their payload format."""
        rows = row_ids.to(torch.long).clamp_min(0)
        block_size = source.shape[1]
        payload = source[rows // block_size, rows % block_size]
        if payload.dtype != destination.dtype:
            payload = payload.contiguous().view(destination.dtype)
        destination.copy_(payload)

    def is_current_stream_capturing(self) -> bool:
        raise NotImplementedError

    def swap_blocks_batch(
        self, src: torch.Tensor, dst: torch.Tensor, sizes: torch.Tensor
    ) -> None:
        """Enqueue device-to-host copies on the current stream."""
        raise NotImplementedError

create_ipc_event()

Create an event that can be exported to another process.

Source code in vllm/v1/hisparse/backend.py
def create_ipc_event(self) -> Any:
    """Create an event that can be exported to another process."""
    raise NotImplementedError

gather_resident_rows(source, destination, row_ids)

Copy resident rows into staging without changing their payload format.

Source code in vllm/v1/hisparse/backend.py
def gather_resident_rows(
    self, source: torch.Tensor, destination: torch.Tensor, row_ids: torch.Tensor
) -> None:
    """Copy resident rows into staging without changing their payload format."""
    rows = row_ids.to(torch.long).clamp_min(0)
    block_size = source.shape[1]
    payload = source[rows // block_size, rows % block_size]
    if payload.dtype != destination.dtype:
        payload = payload.contiguous().view(destination.dtype)
    destination.copy_(payload)

prepare_kv_cache_views(kv_cache_config, kv_caches, forward_context)

Adapt device views before runtime binding; retain allocation ownership.

Called once per cache initialization, inside the common rollback scope. Backends must not put per-step metadata or transfers in this hook.

Source code in vllm/v1/hisparse/backend.py
def prepare_kv_cache_views(
    self,
    kv_cache_config: KVCacheConfig,
    kv_caches: dict[str, Any],
    forward_context: dict[str, Any],
) -> None:
    """Adapt device views before runtime binding; retain allocation ownership.

    Called once per cache initialization, inside the common rollback scope.
    Backends must not put per-step metadata or transfers in this hook.
    """

swap_blocks_batch(src, dst, sizes)

Enqueue device-to-host copies on the current stream.

Source code in vllm/v1/hisparse/backend.py
def swap_blocks_batch(
    self, src: torch.Tensor, dst: torch.Tensor, sizes: torch.Tensor
) -> None:
    """Enqueue device-to-host copies on the current stream."""
    raise NotImplementedError

validate_kv_cache_config(kv_cache_config)

Validate device cache formats before allocating or pinning storage.

Source code in vllm/v1/hisparse/backend.py
def validate_kv_cache_config(self, kv_cache_config: KVCacheConfig) -> None:
    """Validate device cache formats before allocating or pinning storage."""