Adds ALL files needed for Dockerfile build:
- qwen3_6_scripts/ (baseline patches + our optimizations)
- vllm/ (full vllm package)
- paged_attention_v2_pytorch.py (V2 with single-bmm optimization)
- Dockerfile + computility-run.yaml
Our optimizations vs baseline:
1. paged_attn.py: pre-gathered context KV (eliminates 194 gather calls),
Triton try/fallback, V2 heuristic, threshold 32K→64K
2. paged_attention_v2_pytorch.py: fills NotImplementedError,
single-bmm Phase 1 (195 launches → 3)
3. patch_enable_triton.py: HAS_TRITON=True with safety fallback
4. patch_triton_tuning.py: BLOCK=64, NUM_WARPS=4 for BI-V100
5. computility-run.yaml: gpu-memory-utilization 0.9→0.95,
max-num-batched-tokens 8192→16384
This repo can now be submitted to dev.modelhub.org.cn as-is.
89 lines
2.5 KiB
Python
89 lines
2.5 KiB
Python
"""Token blocks."""
|
|
from typing import TYPE_CHECKING, Iterator, List, Optional
|
|
|
|
from vllm.utils import Device
|
|
|
|
DEFAULT_LAST_ACCESSED_TIME: float = -1
|
|
|
|
|
|
class PhysicalTokenBlock:
|
|
"""Represents the state of a block in the KV cache."""
|
|
|
|
def __init__(
|
|
self,
|
|
device: Device,
|
|
block_number: int,
|
|
block_size: int,
|
|
block_hash: int,
|
|
num_hashed_tokens: int,
|
|
) -> 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
|
|
|
|
self.ref_count = 0
|
|
self.last_accessed = DEFAULT_LAST_ACCESSED_TIME
|
|
|
|
self.computed = False
|
|
|
|
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})')
|
|
|
|
|
|
class BlockTable:
|
|
"""Holds a list of blocks with caching of their associated block_ids
|
|
"""
|
|
|
|
def __init__(self, blocks: Optional[List[PhysicalTokenBlock]] = None):
|
|
self._blocks: List[PhysicalTokenBlock] = []
|
|
self._block_ids: List[int] = []
|
|
|
|
if blocks is not None:
|
|
for block in blocks:
|
|
self.append(block)
|
|
|
|
def append(self, block: PhysicalTokenBlock):
|
|
self._blocks.append(block)
|
|
self._block_ids.append(block.block_number)
|
|
|
|
def __len__(self) -> int:
|
|
return len(self._blocks)
|
|
|
|
def __getitem__(self, key):
|
|
return self._blocks[key]
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
def __iter__(self) -> Iterator[PhysicalTokenBlock]:
|
|
raise RuntimeError("Method should be automatically generated")
|
|
|
|
def __setitem__(self, key, value):
|
|
if isinstance(key, slice):
|
|
blocks = value
|
|
self._blocks[key] = blocks
|
|
self._block_ids[key] = [b.block_number for b in blocks]
|
|
else:
|
|
block = value
|
|
self._blocks[key] = block
|
|
self._block_ids[key] = block.block_number
|
|
|
|
def reset(self):
|
|
self._blocks = []
|
|
self._block_ids = []
|
|
|
|
def copy(self) -> "BlockTable":
|
|
return BlockTable(self._blocks)
|
|
|
|
def list(self) -> List[PhysicalTokenBlock]:
|
|
return self._blocks
|
|
|
|
def ids(self) -> List[int]:
|
|
return self._block_ids
|