vllm_gaudi.v1.kv_offload.worker.cpu_hpu
¶
Transfer
dataclass
¶
Source code in vllm_gaudi/v1/kv_offload/worker/cpu_hpu.py
CpuGpuOffloadingHandlers_init_
¶
CpuGpuOffloadingHandlers_init_(
self,
kv_caches: CanonicalKVCaches,
block_size_factor: int,
num_cpu_blocks: int,
)
Source code in vllm_gaudi/v1/kv_offload/worker/cpu_hpu.py
SingleDirectionOffloadingHandler_init_
¶
SingleDirectionOffloadingHandler_init_(
self,
gpu_tensors: list[Tensor],
cpu_tensors: list[Tensor],
block_size_factor: int,
kv_cache_groups_data_refs: list[
list[CanonicalKVCacheRef]
],
gpu_to_cpu: bool,
)
Initialize a SingleDirectionOffloadingHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gpu_tensors
|
list[Tensor]
|
list of GPU KV cache tensors. Each of shape (num_gpu_blocks, gpu_page_size_bytes) with dtype int8. |
required |
cpu_tensors
|
list[Tensor]
|
list of CPU KV cache tensors. Each of shape (num_cpu_blocks, cpu_page_size_bytes) with dtype int8. Order should match gpu_tensors. |
required |
block_size_factor
|
int
|
The ratio of cpu_page_size to gpu_page_size. |
required |
kv_cache_groups_data_refs
|
list[list[CanonicalKVCacheRef]]
|
list of CanonicalKVCacheRef per group. |
required |
gpu_to_cpu
|
bool
|
if True, transfer from GPU to CPU; otherwise CPU to GPU. |
required |
Source code in vllm_gaudi/v1/kv_offload/worker/cpu_hpu.py
expand_block_ids
¶
expand_block_ids(
block_ids: ndarray,
block_size_factor: int,
output: ndarray,
skip_count: int = 0,
)
Convert a list of block IDs to a list of matching block ids, assuming each block is composed of actual block_size_factor blocks. Outputs to output tensor. The first skip_count blocks will be skipped. Note that skip_count must be less than block_size_factor.
For example, if block_ids = [0, 1, 3] and block_size_factor = 4, then it yields [0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15] since 0 maps to [0, 1, 2, 3] 1 maps to [4, 5, 6, 7] and 3 maps to [12, 13, 14, 15]
Source code in vllm_gaudi/v1/kv_offload/worker/cpu_hpu.py
get_handlers
¶
get_handlers(
self, kv_caches: CanonicalKVCaches
) -> Iterator[
tuple[
type[LoadStoreSpec],
type[LoadStoreSpec],
OffloadingHandler,
]
]
Source code in vllm_gaudi/v1/kv_offload/worker/cpu_hpu.py
register_kv_caches
¶
HPU-specific register_kv_caches.
On HPU, get_kv_caches_4D() may return a TensorTuple (K, V pair) instead of a single torch.Tensor for attention layers. This override handles that by treating each element of the tuple as a separate canonical tensor (similar to the FlashAttention unbind case).
Source code in vllm_gaudi/v1/kv_offload/worker/cpu_hpu.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |