Skip to content

ncnn KV cache mem opt ncnn 的 KVcache 模式优化 #6512

@chentyjpm

Description

@chentyjpm

detail | 详细描述 | 詳細な説明

NCNN 的 kv cache 目前使用 concat + 完整拷贝的模式
这种模型在 长token下会严重拖慢速度并且占用超多的内存
考虑对这部分进行优化
目前有2个方向

  1. 避免拷贝
    可以采取的路线有
    Paged KV 对 kvcache分块 变成多个 mat 不要求单一KV cache
    cycle RingBuffer KV 固定预分配最大 kvcache长度 超过即开始丢弃
  2. 量化KVcache 节省内存
    压缩kvcache到 int4 int8 减少内存占用

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions