vllm.distributed.kv_transfer.kv_connector.v1.hf3fs.utils.gather_scatter_helper ¶
Classes:
-
CopyBufferAllocator–Memory pool for tensor buffers to avoid frequent allocation/deallocation.
Functions:
-
gather_kv_caches–Gather KV cache data from KV cache storage to destination tensor.
-
scatter_kv_caches–Scatter KV cache data from source tensor to KV cache storage.
CopyBufferAllocator ¶
Memory pool for tensor buffers to avoid frequent allocation/deallocation.
Methods:
-
alloc_buffer–Allocate buffers from the pool.
-
free_buffer–Return buffers to the pool.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/hf3fs/utils/gather_scatter_helper.py
gather_kv_caches(kv_caches_ptrs, total_token_in_kvcache, dst_tensor, token_indices, tokens_per_block, num_heads, content_size, kv_cache_strides) ¶
Gather KV cache data from KV cache storage to destination tensor.
Parameters:
-
(kv_caches_ptrs¶Tensor) –Tensor of KV cache pointers (one per layer)
-
(total_token_in_kvcache¶int) –Total number of tokens in KV cache
-
(dst_tensor¶Tensor) –Destination
[L, H, N, C]tensor -
(token_indices¶list[int]) –List of token positions to gather
-
(tokens_per_block¶int) –Number of stored states in each cache block
-
(num_heads¶int) –Size of the H axis
-
(content_size¶int) –Size of the C axis
-
(kv_cache_strides¶tuple[int, ...]) –Element strides of each
[B, H, N, C]layer view
Source code in vllm/distributed/kv_transfer/kv_connector/v1/hf3fs/utils/gather_scatter_helper.py
scatter_kv_caches(kv_caches_ptrs, total_token_in_kvcache, src_tensor, token_indices, tokens_per_block, num_heads, content_size, kv_cache_strides) ¶
Scatter KV cache data from source tensor to KV cache storage.
Parameters:
-
(kv_caches_ptrs¶Tensor) –Tensor of KV cache pointers (one per layer)
-
(total_token_in_kvcache¶int) –Total number of tokens in KV cache
-
(src_tensor¶Tensor) –Source
[L, H, N, C]tensor containing data to scatter -
(token_indices¶list[int]) –List of token positions to update
-
(tokens_per_block¶int) –Number of stored states in each cache block
-
(num_heads¶int) –Size of the H axis
-
(content_size¶int) –Size of the C axis
-
(kv_cache_strides¶tuple[int, ...]) –Element strides of each
[B, H, N, C]layer view