PushKvBlocks
Applicability
Product |
Supported (Yes/No) |
|---|---|
Atlas 350 Accelerator Card |
No |
Yes |
|
Yes |
|
No |
|
No |
|
No |
Note: For the
Function Description
Pushes the cache from the local node to the remote node by configuring a block list. This API can be called only when the role is Prompt.
Prototype
1 2 3 4 5 | Status PushKvBlocks(const Cache &src_cache, const CacheIndex &dst_cache_index, const std::vector<uint64_t> &src_blocks, const std::vector<uint64_t> &dst_blocks, const KvCacheExtParam &ext_param = {}); |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
src_cache |
Input |
Local source cache. |
dst_cache_index |
Input |
Index of the remote destination cache. |
src_blocks |
Input |
Block index list of the source cache. |
dst_blocks |
Input |
Block index list of the destination cache. |
ext_param |
Input |
The difference between second and first in src_layer_range must equal that in dst_layer_range. The default values of first and second in both src_layer_range and dst_layer_range are -1, indicating all layers. The valid range for each index is [0, maximum available layer index], and first must be less than or equal to second. The maximum available layer index is calculated as follows: (CacheDesc::num_tensors / KvCacheExtParam::tensor_num_per_layer) - 1 tensor_num_per_layer can range from 1 to the total number of tensors in the cache, with a default value of 2. When src_layer_range or dst_layer_range uses non-default values, tensor_num_per_layer can either remain at its default value or be set to another value, which must be divisible by the total number of tensors in the cache. |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | CacheDesc kv_desc{}; kv_desc.data_type = llm_datadist::DT_INT32; kv_desc.shape = {4, 16}; kv_desc.num_tensors = 4; Cache cache{}; llm_datadist.AllocateCache(kv_desc, cache); CacheIndex dst_cache_key{0, 1}; KvCacheExtParam ext_param{}; ext_param.src_layer_range = std::pair<int32_t, int32_t>(3, 3); ext_param.dst_layer_range = std::pair<int32_t, int32_t>(3, 3); ext_param.tensor_num_per_layer = 1; std::vector<uint64_t> prompt_blocks = {0, 1, 2, 3}; std::vector<uint64_t> decoder_blocks = {3, 2, 1, 0}; Status ret = llm_datadist.PushKvBlocks(cache, dst_cache_key, prompt_blocks, decoder_blocks , ext_param); |
Returns
- LLM_SUCCESS: Success.
- LLM_PARAM_INVALID: Incorrect parameter.
- LLM_NOT_YET_LINK: No link is established with the remote cluster.
- LLM_TIMEOUT: Push operation timeout.
- LLM_KV_CACHE_NOT_EXIST: The local or remote KV cache does not exist.
- Other values: Failure.
Constraints
Before calling this API, call the Initialize API to complete initialization. src_cache must be the cache allocated via the AllocateCache API.