Skip to content

【2026 开源轻训营专属 Issue】KIVI 低比特 KV 缓存 / KIVI Low-Bit KV Cache #590

Open

Description

@xsuler

问题描述 / Problem Description

长上下文 rollout 的 attention KV 缓存限制可用上下文和并发。基线为 BF16 KV;比较固定上下文、并发和模型下的非对称低比特存储。FP8 KV 和已关闭的 #536 是参考背景。

Long-context attention KV limits rollout context and concurrency. Compare asymmetric low-bit storage against BF16 KV at fixed context, concurrency and model. FP8 KV and closed #536 provide background.

期望内容或功能改进 / Expected Improvements or Features

  1. 增加可选 KIVI 路径:key 按 channel、value 按 token 量化,保存尺度及近期未量化 residual 窗口。

    Add opt-in KIVI storage with per-channel keys, per-token values, scales and a recent unquantized residual window.

  2. 接入增量 decode、窗口转移、缓存 reset,并为不支持的 attention 提供明确回退。

    Integrate incremental decode, window transitions and cache reset, with explicit fallback for unsupported attention.

  3. 保留真实 behavior-policy log-probabilities,验证缓存 attention 和元数据生命周期。

    Preserve actual behavior-policy log-probabilities and validate cached attention and metadata lifetime.

  4. 对照 BF16 KV 的内存、吞吐、生成质量及训练原生 log-probability 差异。

    Compare memory, throughput, generation quality and native training log-probability divergence against BF16 KV.

范围边界 / Scope boundaries

首期单卡、一个 dense attention 模型、独立请求缓存;不要求共享 prefix、循环状态量化或其他 issue。

Initially target one GPU, one dense-attention model and private per-request caches; prefix sharing, recurrent-state quantization and other issues are out of scope.

验收标准 / Acceptance Criteria

验收环境:Linux + CUDA;使用一个 AReno 已支持且能装入内存的小型纯文本 dense 模型。固定提交、模型 revision、随机种子、dtype、batch/context 和软件版本;基线与新路径各预热 2 步、测量至少 10 步。报告 allocated/reserved 峰值、步耗时;统一内存设备另报系统内存占用,避免把 CPU offload 当成总内存减少。当前尚无本任务实测收益,首个交付需记录基线。

Validation environment: Linux + CUDA, with one supported small text-only dense model that fits memory. Fix commit, model revision, seed, dtype, batch/context and software versions; warm up each path for two steps and measure at least ten. Report allocated/reserved peaks and step time; on unified-memory devices also report system memory usage rather than treating CPU offload as total-memory savings. No measured gains are claimed yet; establish the baseline in the first deliverable.

  1. 测试 1024/4096/8192 token 缓存及 residual 边界;反量化结果与独立实现一致,reset 后无泄漏。缓存 attention 与同一量化张量参考结果满足 BF16 atol=rtol=1e-2。

    Test caches of 1024/4096/8192 tokens and residual boundaries; dequantization matches an independent implementation and reset leaks no storage. Cached attention matches a reference using the same quantized tensors within BF16 atol=rtol=1e-2.

  2. 长于 residual 窗口的 8192-token 用例,包含尺度和 residual 的缓存字节数低于 BF16;报告完整峰值(含反量化 workspace)、decode 吞吐和下述质量对照。

    For an 8192-token case longer than the residual window, cache bytes including scales/residual are below BF16; report total peak including dequantization workspace, decode throughput and the quality comparison below.

公共 Trainer 端到端运行须包含更新和保存/恢复;报告训练过程原生 train/logp_abs_diff_mean,不得另算替代。涉及近似更新/压缩的路径(GaLore、激活压缩、KIVI),固定数据和预算跑至少 3 个种子:最终验证 loss 相对基线增幅≤2%;若采用 RL 验收,同时报告 reward 曲线,平均末段 reward 不低于基线超过 0.05(reward 归一化到 [0,1])。以上是待验证的验收目标,不是已取得的结果。核心测试和仓库 checks 必须通过。

The public Trainer end-to-end run must include updates and save/resume; report its native train/logp_abs_diff_mean, not a separately computed substitute. For approximate updates/compression (GaLore, activation compression and KIVI), use fixed data/budget and at least three seeds: final validation loss must increase by no more than 2% versus baseline; if RL is used for acceptance, also report reward curves and a mean final-window reward no more than 0.05 below baseline on a [0,1] reward scale. These are acceptance targets to validate, not achieved results. Core tests and repository checks must pass.

完成方式与交付物 / Submission Method and Deliverables

向 oss-camp2026 分支提交 PR;交付代码、自动化测试、使用说明,以及包含基线/对照原始日志、命令、配置和误差/内存/吞吐表的可复现报告。演示视频不作要求。

Open a PR against oss-camp2026; deliver code, automated tests, usage documentation and a reproducible report containing baseline/comparison raw logs, commands, configuration and numerical-error/memory/throughput tables. A demo video is not required.

参考资料与环境 / References and Environment

开发和验收环境见上述验收标准;各任务可独立实现,不互相依赖。

See the acceptance section for development and validation environments. Each task is independently implementable with no dependency on the other tasks.

是否支持多人并行认领 / Can Multiple Contributors Claim This Task in Parallel?

是,可按不同方向并行认领并增量合入。

Yes. Distinct directions may be claimed in parallel and merged incrementally.

并行认领范围 / Scope for Parallel Claims

可分别认领核心实现、数值正确性与回归测试、性能评测及文档。认领时请在评论区登记具体子任务、接口边界和预计交付物;同一范围避免重复认领,重叠部分先协商拆分,再分别提交 PR。活动认领仍按下方云燕平台流程完成。

Contributors may claim core implementation, numerical correctness and regression tests, or benchmarking and documentation. Register the subtask, interface boundaries and expected deliverables in the comments when claiming. Avoid duplicate scopes; agree on a split for overlapping work before submitting separate PRs. Complete the event claim through the Yunyan process below.

是否要求 AI 使用策略报告 / Is an AI Usage Strategy Report Required?

不要求。

Not required.

发布前确认 / Pre-Publication Checklist

  • 我已确认任务边界清晰,且适合学生在活动周期内完成。 / I have confirmed that the task has clear boundaries and can be completed by students during the event.
  • 我已提供基线或参考实现,并确认验收标准可量化、可复现。 / I have provided a baseline or reference implementation and confirmed that the acceptance criteria are measurable and reproducible.
  • 我已在标题前缀后补充一句话任务描述。 / I have added a concise task description after the title prefix.

首项待活动维护者结合活动周期确认。 / The first item awaits event-maintainer confirmation against the event schedule.

认领方式 / How to Claim This Issue

本 Issue 为【2026 蚂蚁开源轻训营 · 高校行】专属 Issue,仅供已报名参与活动的同学认领。

【认领方式】在云燕平台注册并点击认领按钮即认领成功。

【活动报名】注册云燕平台并加入“蚂蚁开源轻训营”实验室,信息收集将仅用于活动登记和奖励发放。

This Issue is exclusively for the 2026 Ant Open Source Camp University Tour and may only be claimed by students who have registered for the event.

[How to Claim] Register on the Yunyan platform and click the claim button. The task is successfully claimed once the action is confirmed.

[Event Registration] Register on the Yunyan platform and join the "Ant Open Source Camp" lab. Collected information will be used only for event registration and reward distribution.

Activity

  1. self-assigned this
    on Oct 10, 2026
  2. changed the title [-]feat: add KIVI-style asymmetric low-bit KV-cache storage[/-] [+]【2026 开源轻训营专属 Issue】KIVI 低比特 KV 缓存 / KIVI Low-Bit KV Cache[/+] on Oct 12, 2026
  3. added
    蚂蚁开源轻训营专属
    轻训营-中高难度
    on Oct 12, 2026
  4. removed their assignment
    on Oct 12, 2026
  5. EricChan2028 commented on Oct 29, 2026

    @EricChan2028

    认领 / Claim:核心实现 + 数值正确性与回归测试 + 性能评测与文档(全部三部分;如有同学希望分担评测部分,欢迎协商拆分)
    Claiming all three parts: core implementation, numerical-correctness/regression tests, and benchmarking + docs (happy to split benchmarking if someone else wants it).

    接口边界 / Interface (opt-in, default unchanged)

    • RuntimeConfig.kv_cache_dtype: "auto" | "kivi2" | "kivi4" (default auto = model dtype), kivi_group_size=32, kivi_residual_length=128 (paper defaults), reachable from the SDK through CudaConfig(runtime={...}). I would also add --kv-cache-dtype / --kivi-group-size / --kivi-residual-length to areno train and areno serve; since AGENTS.md asks to confirm CLI/SDK config surfaces first, please let me know if you prefer different names.
    • Storage: paged quantized pool reusing the existing block table. K per channel (groups of G tokens), V per token (groups of G channels), fp16 scale/zero, packed 2/4-bit codes; a BF16 residual window (the most recent R..R+G-1 tokens) per rollout slot, indexed by the existing recurrent slots.
    • Kernels: Triton under areno/accel/kernels/: group quantize/pack, a fused flush + append for decode, and a split-K decode attention that dequantizes paged tiles in registers (no full-cache BF16 materialization), CUDA-graph capturable.
    • Fresh prompt attention stays full precision; cached-prefix prefill reads the quantized cache through a bounded per-row dequantization.
    • Explicit fallback (RuntimeWarning, model-dtype KV): unsupported model families, sliding-window/MLA/linear attention, speculative decoding, NPU.
    • Rollout keeps the logprobs actually produced by the KIVI attention used for sampling (no BF16 recomputation).

    交付物 / Deliverables

    • CPU tests (config/fallback, residual bookkeeping, prefill planning); CUDA tests against an independent PyTorch reference for 1024/4096/8192-token caches and residual boundaries, dequantization vs the reference, cached attention on the same quantized tensors (BF16 atol=rtol=1e-2), chunked prefill, reset/slot-reuse leak checks, CUDA-graph replay.
    • Report on Qwen3-0.6B (fixed commit/revision/seed, 2 warmup + >=10 measured steps): BF16 vs KIVI-2/KIVI-4 cache bytes incl. metadata, allocated/reserved peaks incl. dequantization workspace, decode throughput at fixed context/concurrency and at max feasible concurrency, PPL/KL/token agreement from 1K to 32K, GSM8K; GSPO with 3 seeds per arm, reward curves, native train/logp_abs_diff_mean, save/resume.
    • Usage docs.

    环境 / Env: Linux, RTX PRO 5000 72GB (Blackwell sm_120), CUDA 12.8, PyTorch 2.8.

    问题 / Questions

    1. oss-camp2026 is currently 23 commits behind main (KV-cache and decode-graph code changed in between), and recent camp PRs target main. Could the branch be synced, or should the PR target main?
    2. areno train has no seed option. For the 3-seed protocol I plan to drive the stock GSPO trainer from a small harness in examples/kivi/ that sets SamplingParams.seed per step (dataset order fixed). Would you prefer an opt-in --seed for areno train instead (as a separate PR)?

    A working prototype with the tests above is in progress; I will open a draft PR once the measurements are complete.

  6. EricChan2028 commented on Oct 30, 2026

    @EricChan2028

    进度更新 / Progress update

    PR:#641(单个提交,基于 main e17794c)。可复现报告见 PR 中的 examples/kivi/README.md(命令、配置、误差/内存/吞吐表),原始日志在 fork 的 kivi-590-artifacts 分支。

    Qwen3-0.6B,单张 RTX PRO 5000 72GB BF16 KIVI-4 KIVI-2
    8192 token 缓存字节(含 scale 与 residual) 1 0.331x 0.206x
    decode 注意力,128 行 × 16K token(CUDA graph) 7.01 ms 3.95 ms 4.06 ms
    GSM8K 准确率(1319 题 × 4 次采样,T=1) 72.16% 72.25% 68.82%(R=512:72.25%)
    8K token 上下文下可同时运行的 rollout 48 128 256
    GSPO 末段 reward,相对 BF16 0.806 +0.000(6 种子) −0.097(R=512:−0.036)
    原生 train/logp_abs_diff_mean 0.015 0.032 0.209(R=512:0.117)
    训练后策略的验证 loss 变化 – +0.20% +1.28%(R=512:+1.22%)

    KIVI-4 达到全部验收目标。KIVI-2 在默认 R=128 时 RL reward 低于 0.05 的目标,R=512 时达标;报告中按此给出推荐配置。

    想请维护者确认三点:

    1. 目标分支:oss-camp2026 目前停在 25f5fed,比 main 落后 23 个提交,本改动依赖 main 上的引擎代码。PR 暂时提到 main;能否把 oss-camp2026 同步到 main,或者以 main 为准?同步后我可以把 PR 改到 oss-camp2026。
    2. CLI:是否在本 PR 中为 areno train / areno serve 增加 --kv-cache-dtype / --kivi-group-size / --kivi-residual-length?目前通过 SDK 的 CudaConfig(runtime={...}) 使用,areno serve 暂时无法开启。
    3. 行为策略校正:GSPO / GRPO 的 ratio 以训练时重算的 log-prob 为基准(logprobs - logprobs.detach()),rollout 被当作 on-policy,rollout log-prob 只用于指标。量化 rollout(如 KIVI-2)的偏差因此得不到校正,这正是 KIVI-2 在 R=128 时训练停滞的原因。是否需要我另开 issue,讨论一个默认关闭、基于 rollout log-prob 的截断重要性采样?

    English summary. PR #641 is a single commit on main e17794c; examples/kivi/README.md holds the reproducible report and the fork branch kivi-590-artifacts holds the raw logs. KIVI-4 meets every acceptance target (6 seeds: GSPO final-window reward +0.000, validation loss +0.20%). KIVI-2 misses the reward target with the default 128-token residual window (−0.097) and meets it with 512 tokens (−0.036). Questions: (1) oss-camp2026 is 23 commits behind main and this change builds on main; could the branch be synced, or should camp PRs target main? (2) Should this PR add --kv-cache-dtype / --kivi-group-size / --kivi-residual-length to areno train and areno serve? (3) GSPO/GRPO treat rollouts as on-policy, so quantized-rollout drift is never corrected; would you like a separate issue on an opt-in truncated importance weight based on rollout log-probabilities?

  7. DoubleCore commented on Nov 4, 2026

    @DoubleCore

    认领 / Claim:独立复现与回归验证(增量范围,与 @EricChan2028 的 PR #641 主线互补,不重复其实现)

    看到 #641 已覆盖核心实现、数值正确性与性能评测。我认领的是第三方独立复现这一增量:

    • 在干净的固定环境(固定 commit/model revision/seed/dtype/batch·context)下按 PR 内 examples/kivi/README.md 的步骤原样跑通,核对报告中的误差/内存/吞吐表;
    • 补充 feat(engine): add opt-in KIVI 2/4-bit KV cache for CUDA rollout #641 未覆盖的边界用例:quant group size 非法值、非整除通道、batch=1 与长 context 退化路径、CPU/无 CUDA 环境的清晰报错;
    • 若发现偏差,提 issue/PR 修正而非重写主线。

    预计交付物:独立复现报告(含原始日志与命令)、边界回归测试 PR。
    预计完成时间:5 个工作日内给出复现结论。

  8. DoubleCore commented on Nov 4, 2026

    @DoubleCore

    增量交付:独立参考实现 + CPU 边界回归

    我在主线实现(#641)之外补了一份独立验证产物,不改动你们任何主线文件:

    PR: #658 — 3 files, +738

    • areno/accel/kivi_reference.py — 按 issue 语义从零写的 KIVI 参考实现(key 按 channel 量化 / value 按 token 量化 / residual 窗口)
    • tests/test_kivi_reference_cpu.py — 25 passed,覆盖 residual 窗口空/半满/满、cache reset、非法 attention 类型报错、与 BF16 基线的偏差上界
    • docs/dev/kivi-reference-verification.rst — 与主线 PR 的语义对照点

    说明:这是 CPU 环境产物,未覆盖 CUDA 显存收益与真机吞吐,这一点已在报告里明确标注。若需要 GPU 实测数据,我这边可以补。

  9. DoubleCore commented on Nov 4, 2026

    @DoubleCore

    补充:已开增量 PR #658(KIVI 独立参考实现 + CPU 边界回归,25 passed)。不改动主线实现,仅作交叉验证。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    蚂蚁开源轻训营专属轻训营-中高难度

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions