CopyKvCache
Applicability
Product |
Supported (Yes/No) |
|---|---|
Atlas 350 Accelerator Card |
No |
Yes |
|
Yes |
|
No |
|
No |
|
No |
Note: For the
Function Description
Copies the KV cache. D2D and D2H copy operations are supported.
To pipeline PullKvCache operations with other cache-consuming operations, you can allocate an additional intermediate cache. While other processes are using the current cache, you can prefetch the next cache block into this intermediate cache. After the current cache is released, copy the prefetched data from the intermediate cache to the designated location. This pipelines the PullKvCache latency, hiding it behind other operations and reducing the overall processing time.
In the common prefix scenario, before inference on a new request, the common prefix can be copied to a new memory space and merged with the KV cache of the current request for inference.
Prototype
1 2 3 4 5 6 | Status CopyKvCache(const Cache &src_cache, const Cache &dst_cache, uint32_t src_batch_index = 0U, uint32_t dst_batch_index = 0U, uint64_t offset = 0U, int64_t size = -1) |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
src_cache |
Input |
Source cache. |
dst_cache |
Input |
Destination cache. |
src_batch_index |
Input |
Batch index of the source cache. |
dst_batch_index |
Input |
Batch index of the destination cache. |
offset |
Input |
Copy offset, in bytes. |
size |
Input |
If this parameter is set to an integer greater than 0, it indicates the size of the data to be copied. If this parameter is set to -1, it indicates a full copy. The default value is -1. |
Example
1 | Status ret = llm_datadist.CopyKvCache(src_cache, dst_cache, 0, 0) |
Returns
- LLM_SUCCESS: Success.
- LLM_PARAM_INVALID: Incorrect parameter.
- Other values: Failure.
Constraints
Before calling this API, call the Initialize API to complete initialization. Only D2D and D2H copy operations are supported.