[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 件 担当者 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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

PrunaAI/pruna のほかの issue

PrunaAI/pruna の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。