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

Đang mở Phù hợp với người mới
#800 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@zuhalsicim đang làm issue này rồi.

Từ ngày 29/11/2026.

  • #805 của @zuhalsicim — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
machine-learning

Hướng nghiên cứu

Lệnh gọi có vấn đề nằm trong set_to_eval ở pruna/engine/utils.py, hàm này gọi model.eval() bất cứ khi nào kiểm tra hasattr(model, 'eval') thành công. Hãy đọc hàm đó và nhánh get_nn_modules nằm cạnh nó, rồi xác nhận rằng llama_cpp.Llama.eval yêu cầu tham số tokens. Công việc hoàn tất khi một mô hình được bọc bằng llama.cpp không còn kích hoạt cảnh báo trong các chỉ số độ trễ, năng lượng và bộ nhớ, còn các mô hình torch.nn.Module vẫn được gọi eval() như trước. Kiểm tra các test hiện có của set_to_eval trước khi thay đổi điều kiện bảo vệ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
1.4k
Fork
129
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của PrunaAI/pruna

Tất cả issue của PrunaAI/pruna

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.