swap_blocks
产品支持情况
产品 |
是否支持 |
---|---|
√ |
|
√ |
|
x |
|
x |
|
x |
|
x |
函数功能
对cpu_cache和npu_cache进行换入换出。
对于swap out功能,该接口启用了4个线程执行并行任务;对于swap in功能,该接口启用了1个d2d线程。为了性能稳定,建议进行进程绑核。
swap in功能分为H2D和D2D两个阶段,为了保障性能,该接口申请了4个block大小的buffer用作流水拷贝,所以建议预留出对应的device内存,防止出现OOM。
函数原型
1 | swap_blocks(src_chche: Cache, dst_chche: Cache, src_to_dst: Dict[int, int]) |
参数说明
调用示例
1 2 3 4 5 6 7 | from llm_datadist import Cache npu_cache = cache_manager.allocate_blocks_cache(npu_cache_desc, npu_cache_key) cpu_cache = Cache.create_cpu_cache(cpu_cache_desc, cpu_addrs) # cpu_addrs来自创建的cpu tensors # swap in cache_manager.swap_blocks(cpu_cache, npu_cache, {1:2, 3:4}) # swap out cache_manager.swap_blocks(npu_cache, cpu_cache, {1:2, 3:4}) |
返回值
正常情况下无返回值。
传入数据类型错误,src和dst不匹配情况下会抛出TypeError或ValueError异常。
传入参数为None,会抛出AttributeError异常。
约束说明
仅支持PagedAttention场景使用。
父主题: CacheManager