Files
vllm/vllm/block.py

42 lines
1.1 KiB
Python
Raw Normal View History

"""Token blocks."""
from typing import List
2023-02-09 11:26:21 +00:00
2023-06-17 03:07:40 -07:00
from vllm.utils import Device
2023-02-09 11:26:21 +00:00
DEFAULT_LAST_ACCESSED_TIME = -1
2023-02-09 11:26:21 +00:00
class PhysicalTokenBlock:
"""Represents the state of a block in the KV cache."""
2023-02-09 11:26:21 +00:00
def __init__(
self,
device: Device,
block_number: int,
block_size: int,
block_hash: int,
num_hashed_tokens: int,
2023-02-09 11:26:21 +00:00
) -> None:
self.device = device
self.block_number = block_number
self.block_size = block_size
self.block_hash = block_hash
self.num_hashed_tokens = num_hashed_tokens
2023-02-09 11:26:21 +00:00
self.ref_count = 0
self.last_accessed = DEFAULT_LAST_ACCESSED_TIME
self.computed = False
2023-02-14 09:34:07 +00:00
def __repr__(self) -> str:
return (f'PhysicalTokenBlock(device={self.device}, '
f'block_number={self.block_number}, '
f'num_hashed_tokens={self.num_hashed_tokens}, '
f'ref_count={self.ref_count}, '
f'last_accessed={self.last_accessed}, '
f'computed={self.computed})')
# Mapping: logical block number -> physical block.
BlockTable = List[PhysicalTokenBlock]