Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

docs(evals): correct the percentile rationale and harden the test

rahul05ranjan9e02e3863471
diff --git a/laya/evals.py b/laya/evals.py
index e15d2848..a890f999 100644
--- a/laya/evals.py
+++ b/laya/evals.py
@@ -288,12 +288,12 @@ def _group_cases(cases: Sequence[Dict[str, Any]], key: str) -> Dict[str, List[Di
def _percentiles(values: Sequence[float]) -> Tuple[float, float]:
- """(median, 95th) using the nearest-rank rule the report has always used for latency."""
+ """(median, 95th) using the nearest-rank rule for latency."""
ordered = sorted(values)
n = len(ordered)
# Nearest-rank 95th percentile: the ceil(0.95 * n)-th smallest value (1-indexed).
- # Integer arithmetic avoids the float rounding that made `int(n * 0.95)` return the
- # (0.95n + 1)-th value whenever n is a multiple of 20.
+ # `int(n * 0.95)` truncated where it needed to round up, returning the
+ # (0.95n + 1)-th value whenever n is a multiple of 20. Integer ceil fixes that.
rank = (95 * n + 99) // 100
return (float(statistics.median(ordered)), float(ordered[rank - 1]))
diff --git a/tests/test_evals.py b/tests/test_evals.py
index 79f3c223..63024818 100644
--- a/tests/test_evals.py
+++ b/tests/test_evals.py
@@ -97,11 +97,13 @@ def test_percentiles_use_nearest_rank():
# Nearest-rank 95th percentile is the ceil(0.95 * n)-th smallest value (1-indexed).
# `int(n * 0.95)` used to return the (0.95n + 1)-th value whenever n is a multiple of 20.
- for n in (20, 40, 100):
+ # Expected values are written as literals (not the implementation's own formula) so a
+ # formula that is wrong in both places at once still fails.
+ for n, expected in ((20, 19), (40, 38), (100, 95), (30, 29), (50, 48)):
values = list(range(1, n + 1))
_, p95 = _percentiles(values)
- assert p95 == pytest.approx((95 * n + 99) // 100), \
- "95th percentile of 1..%d must be the nearest-rank value, got %r" % (n, p95)
+ assert p95 == pytest.approx(expected), \
+ "95th percentile of 1..%d must be the nearest-rank value %d, got %r" % (n, expected, p95)
# A single value is its own percentile.
assert _percentiles([7.0]) == (7.0, 7.0)