[BUG] set_to_eval calls Llama.eval() on llama.cpp models, so latency/energy/memory metrics log a warning on every run

未关闭 适合新手
#800 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@zuhalsicim 已经在做这个了。

开始于 2026年11月29日。

  • #805 来自 @zuhalsicim —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

有问题的调用位于 pruna/engine/utils.py 中的 set_to_eval,只要 hasattr(model, 'eval') 检查通过,它就会调用 model.eval()。请阅读该函数以及旁边的 get_nn_modules 分支,然后确认 llama_cpp.Llama.eval 需要 tokens 参数。当经过 llama.cpp 封装的模型不再在延迟、能耗和内存指标中触发警告,并且 torch.nn.Module 模型仍像以前一样调用 eval() 时,即视为完成。修改守卫条件之前,请先检查 set_to_eval 的现有测试。

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

描述

Describe the bug

set_to_eval in pruna/engine/utils.py calls model.eval() whenever the model has an eval attribute. For a model compressed with the llama_cpp algorithm, the wrapped object is a llama_cpp.Llama, and its eval(tokens) is not a train/eval switch but "process these tokens". The call fails with a TypeError, which is caught and logged, so every metric that goes through PrunaModel.set_to_eval (latency, energy, memory) logs a warning on every run.

The metric still runs, so this is noise rather than a crash. But it reads like an error, and a wrapper whose eval() takes no arguments and does something else would actually be called.

What I did

Smashed Qwen2.5-Coder-1.5B-Instruct with
SmashConfig({"llama_cpp": {"quantization_method": "q4_k_m", "n_gpu_layers": 0}}, device="cpu"),
loaded it with PrunaModel.from_pretrained and ran EvaluationAgent with the latency metric:

Could not set model to evaluation mode: Llama.eval() missing 1 required positional argument: 'tokens'

Expected behavior

No eval() call on objects where eval is not a train/eval switch. A llama.cpp model has nothing to switch, so no warning.

A possible fix: call model.eval() only when model is a torch.nn.Module, and otherwise use the existing get_nn_modules branch, which should find no torch modules in a llama.cpp model and do nothing. I have not tested this change yet, and I have not checked which other wrappers rely on the hasattr branch, so I would like to hear whether you want it before opening a PR.

Environment

  • pruna version: 0.3.5 (set_to_eval is unchanged on main today)
  • python version: 3.12.16
  • llama-cpp-python: 0.3.36
  • Operating System: Ubuntu (GitHub-hosted runner), CPU only

Additional context

Found while benchmarking Qwen2.5-Coder-1.5B through pruna's llama_cpp algorithm at four precisions: https://github.com/zuhalsicim/sql-under-compression. pruna's EvaluationAgent with a custom metric agreed with my own scoring on all 800 answers of the 200-question run.

主要语言
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 摘要。