[BUG] kvpress algorithm: KVzipPress and FastKVzipPress never compress during generate

未关闭
#784 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

  • #797 来自 @RajVardhan853381 —— 已关闭,未合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python, pytorch

调研方向

Read src/pruna/algorithms/kvpress.py around the model.generate wrapper and inspect tests/algorithms/testers/kvpress.py. Reproduce the reported behavior with KVzipPress or FastKVzipPress, then check whether the cache is compressed during generation. Done means the supported presses compress before decoding, or are rejected clearly, with a test that catches the reported uncompressed-cache behavior.

由索引模型根据 Issue 内容生成。

描述

stale

Describe the bug

For a causal LM, KVPress._apply wraps model.generate in the press context (kvpress.py#L163-L165):

def generate_with_press(*args, **kwargs):
    with press(model):
        return original_generate(*args, **kwargs)

Some KVPress presses compress only when their context manager exits. Two of them are in PRESS_TYPES: KVzipPress and FastKVzipPress. Under this wrapper the exit comes after generation has finished, so nothing is compressed while the model generates. No KV entry is masked, and the output equals the uncompressed model's. A model smashed with kvpress_press_type="KVzipPress" therefore silently runs uncompressed.

This is upstream KVPress behaviour for this usage (NVIDIA/kvpress#297; a maintainer replied that the README will be updated). Pruna's wrapper uses exactly that usage, so it inherits the problem.

What I did

I reproduced the underlying behaviour with kvpress alone, using the same with press(model): model.generate(...) pattern as the wrapper. Setup: kvpress 66c5b09, transformers 5.2.0, SmolLM2-360M-Instruct, SDPA, CPU, compression_ratio=0.5.

KVzipPress: prompt 1111 tokens, cache 1126 rows, masked entries 0, output identical to no press: True

FastKVzipPress on Qwen3-4B-Instruct-2507 (the smallest model with released gates) gives the same result: 0 entries masked during generation. With prefill-only usage under the press, it masks 50% of entries as expected.

I have not run this through Pruna itself. The kvpress algorithm declares runs_on: ["cuda"] and my reproduction ran on CPU and Apple silicon, so the Pruna part of this report rests on the wrapper code above.

Expected behavior

Either:

  • compression is applied before decoding starts: prefill under the press, then generate from the compressed cache, as kvpress's own kv-press-text-generation pipeline does; or
  • these presses are removed from PRESS_TYPES or rejected with a clear error.

tests/algorithms/testers/kvpress.py only checks that _kvpress_press and _kvpress_original_generate are attached. A test that checks the cache is actually smaller, or that entries are masked, after a smashed generate would catch this.

Environment

  • pruna version: main @ c622a77 (code reading; not executed)
  • reproduction: kvpress 66c5b09, transformers 5.2.0, torch 2.9.1
  • python version: 3.12
  • Operating System: macOS (reproduction)

Additional context

KVgradPress and KVComposePress share the exit-time compression upstream but are not in PRESS_TYPES.

AI-assisted: drafted with an AI coding assistant. I reviewed the report and the reproduction output above.

主要语言
Python
星标
1.4k
派生
129
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

PrunaAI/pruna 的其他 Issue

查看 PrunaAI/pruna 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。