Multiple `ZeroDivisionError` bugs in `lm_eval/api/metrics.py` aggregation functions
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Đọc lm_eval/api/metrics.py, bắt đầu với mean(), sample_stddev(), mean_stderr(), weighted_mean() và bits_per_byte(). Theo dõi cách các đầu vào rỗng, chỉ có một phần tử và có trọng số bằng không đi đến các phép tổng hợp đã đăng ký này. Được xem là hoàn tất khi các đầu vào suy biến trả về kết quả NaN hoặc bằng không mà không gây lỗi, như đã chỉ định, trong khi các đầu vào thông thường vẫn giữ nguyên hành vi hiện tại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Multiple ZeroDivisionError bugs in lm_eval/api/metrics.py aggregation functions
Description
Several aggregation functions in lm_eval/api/metrics.py lack guards against edge-case inputs, causing ZeroDivisionError crashes that halt the entire evaluation pipeline. Three related bugs are reported here:
1. mean() — empty result list
@register_aggregation("mean")
def mean(arr):
return sum(arr) / len(arr) # ZeroDivisionError if arr is []
When a task produces zero evaluation samples (e.g., due to filtering, an empty dataset split, or a misconfigured evaluation), len(arr) is 0.
2. mean_stderr() / sample_stddev() — single-element or empty list
def sample_stddev(arr):
mu = mean(arr)
return math.sqrt(sum([(x - mu) ** 2 for x in arr]) / (len(arr) - 1))
# ^^^^^^^^^^^
# ZeroDivisionError when len(arr) == 1
def mean_stderr(arr):
return sample_stddev(arr) / math.sqrt(len(arr))
# ^^^^^^^^
# ZeroDivisionError when len(arr) == 0
A single-sample evaluation task (valid for quick sanity checks) crashes the entire results computation.
3. weighted_mean() / bits_per_byte() — weights summing to zero
def weighted_mean(items):
a, b = zip(*items)
if len(a) == 0: # guards empty list...
return np.nan
return sum(a) / sum(b) # ...but not sum(b) == 0
The len(a) == 0 guard catches empty inputs, but if the list is non-empty and all weights (b values) are zero (zero-length documents or degenerate tokenization), sum(b) is 0 and the division still fails. This is reachable through bits_per_byte():
@register_aggregation("bits_per_byte")
def bits_per_byte(items):
return -weighted_mean(items) / math.log(2)
Expected behavior
These functions should return np.nan (or 0.0) gracefully on degenerate inputs rather than crashing the pipeline.
Suggested fix
@register_aggregation("mean")
def mean(arr):
if len(arr) == 0:
return np.nan
return sum(arr) / len(arr)
def sample_stddev(arr):
if len(arr) < 2:
return float('nan')
mu = mean(arr)
return math.sqrt(sum([(x - mu) ** 2 for x in arr]) / (len(arr) - 1))
def mean_stderr(arr):
if len(arr) == 0:
return float('nan')
return sample_stddev(arr) / math.sqrt(len(arr))
def weighted_mean(items):
a, b = zip(*items)
if len(a) == 0:
return np.nan
total_weight = sum(b)
if total_weight == 0:
return np.nan
return sum(a) / total_weight
How this was found
These were identified via static analysis, which flagged all unguarded divisions as DSE-confirmed reachable DIV_ZERO bugs.
- Ngôn ngữ chính
- Python
- Star
- 12
- Fork
- 0
- 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
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/StableQAT
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 48/100
Tất cả issue của microsoft/StableQAT
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
-
[Bug]: Queen's own Ollama model loses num_ctx when a running session switches to itCó thể đã có người làm @anasamin26 đã nhận hôm nay. Đang mởbug enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
aden-hive/hive#7508 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
llm translation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
BerriAI/litellm#47884 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug 🐛
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
netalertx/NetAlertX#1856 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày