Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Multiple `ZeroDivisionError` bugs in `lm_eval/api/metrics.py` aggregation functions

Đang mở
#8 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend

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

  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 microsoft/StableQAT

Tất cả issue của microsoft/StableQAT

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.