CANN/GE PushKvBlocks接口

CANN/GE PushKvBlocks接口

# PushKvBlocks

【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge

产品支持情况

  • Atlas A3 训练系列产品/Atlas A3 推理系列产品:支持
  • Atlas A2 推理系列产品:支持
  • Atlas A2 训练系列产品:不支持

函数功能

通过配置block列表的方式,从本地节点推送Cache到远端节点,仅当角色为Prompt时可调用。

函数原型

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 = {});

参数说明

参数名称输入/输出取值说明
src_cache输入本地源Cache。
dst_cache_index输入远端目的Cache的索引。
src_blocks输入源Cache的block index列表。
dst_blocks输入目的Cache的block index列表。
ext_param输入当前支持ext_param中src_layer_range的sencond与first的差值和dst_layer_range的sencond与first的差值一致。src_layer_range和dst_layer_range的first和second默认值都是-1,表示全部的层。取值范围都是[0, 最大可用层索引],且first小于等于second。 最大可用层索引值的计算公式如下。
(CacheDesc::num_tensors / KvCacheExtParam::tensor_num_per_layer) - 1
当前支持tensor_num_per_layer取值范围是[1, 当前cache的tensor总数],默认值为2。当src_layer_range或dst_layer_range取值为非默认值时, tensor_num_per_layer可以保持默认值,也可以输入其他值,输入其他值的时,tensor_num_per_layer的取值还需要被当前cache的tensor总数整除。

调用示例

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);

返回值

  • LLM_SUCCESS:成功
  • LLM_PARAM_INVALID:参数错误
  • LLM_NOT_YET_LINK:与远端cluster没有建链
  • LLM_TIMEOUT:推送超时
  • LLM_KV_CACHE_NOT_EXIST:本地或远端KV Cache不存在
  • 其他:失败

约束说明

该接口调用之前,需要先调用Initialize接口完成初始化。src_cache必须为AllocateCache接口申请出的Cache。

【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考