copy_cache

Applicable Products

Product

Supported (Yes/No)

Ascend 950PR/Ascend 950DT

No

Atlas A3 training products/Atlas A3 inference products

Yes

Atlas A2 training products/Atlas A2 inference products

Yes

Atlas 200I/500 A2 inference products

No

Atlas inference products

No

Atlas training products

No

Note: For the Atlas A2 training products/Atlas A2 inference products, only the Atlas 800I A2 inference server and A200I A2 Box heterogeneous subrack are supported.

Function Description

Copies the KV cache.

Prototype

1
copy_cache(dst: KvCache, src: KvCache, dst_batch_index: int = 0, src_batch_index: int = 0, offset: int = 0, size: int = -1, req_id: Optional[int] = None)

Parameters

Parameter

Data Type

Value Description

dst

KvCache

Target cache.

src

KvCache

Source cache.

dst_batch_index

int

Batch index of the destination cache. The default value is 0.

src_batch_index

int

Batch index of the source cache. The default value is 0.

offset

int

Offset of each tensor. The default value is 0.

size

int

Set this parameter to an integer greater than 0, indicating the size of the copy.

Or set this parameter to -1, indicating full copy.

The default value is -1.

req_id

Optional[int]

Request ID associated with the current call. If this parameter is set, the request ID is recorded in the maintenance and debugging logs related to the local call.

The default value is None.

Example

1
kv_cache_manager.copy_cache(dst_cache, src_cache, 0, 1, 0, 128)

Returns

In normal cases, no value is returned.

If a parameter is incorrect, a TypeError or ValueError may be thrown.

If the execution time exceeds the value of sync_kv_timeout, an LLMException is thrown.

Constraints

  • CacheDesc of src/dst needs to be matched.
  • This API does not support concurrent calls. Concurrent calls will be queued.