Repository navigation
Description
Describe the bug
evaluate.combine() can silently overwrite a metric result when a generated prefixed key equals another metric's raw result key. All supplied module names can be distinct. The result looks valid but one score is missing. This was found through source inspection and local reproduction, not a production incident.
Steps to reproduce
This uses real local Metric objects with in-memory data; no Hub metric, model, or dataset download is required.
import tempfile
import evaluate
from datasets import Features, Value
class Score(evaluate.Metric):
def __init__(self, key, score, **kwargs):
self.key, self.score = key, score
super().__init__(**kwargs)
def _info(self):
return evaluate.MetricInfo(
description="Local score", citation="", inputs_description="",
features=Features({"predictions": Value("int64"), "references": Value("int64")}),
)
def _compute(self, predictions, references):
return {self.key: self.score}
with tempfile.TemporaryDirectory() as cache:
for last_key in ["other_score", "model_score"]:
modules = {
"model": Score("score", 0.1, cache_dir=cache, keep_in_memory=True),
"baseline": Score("score", 0.2, cache_dir=cache, keep_in_memory=True),
"custom": Score(last_key, 0.9, cache_dir=cache, keep_in_memory=True),
}
print(last_key, evaluate.combine(modules).compute(predictions=[1], references=[1]))Actual output:
other_score {'model_score': 0.1, 'baseline_score': 0.2, 'other_score': 0.9}
model_score {'model_score': 0.9, 'baseline_score': 0.2}
Changing only the third raw score name loses the first metric's 0.1 result. I expected either all scores to be retained or an explicit error that the final keys are ambiguous.
force_prefix=True does not eliminate all cases: module a_b returning c and module a returning b_c both produce a_b_c; reversing their order changes which score survives. That is distinct from closed #339, which proposed always prefixing and was closed because force_prefix already existed.
Source and proposed scope
CombinedEvaluations._merge_results() detects duplicate raw keys, but assignments to the final merged_results dictionary do not check whether a generated key already exists. Searches for _merge_results, collision, and overwrite/combine found no matching repair. #832 handles distributed None results and #776 handles scalar results, which are separate issues.
Would a focused guard raising a descriptive ValueError when two results resolve to the same final key be appropriate? It would preserve current names and values for collision-free inputs. I would avoid inventing automatic renaming without maintainer agreement on the naming policy.
Environment
- Pristine main
a5db2ad54aaeadf15c7aa1f056bc6f7bbeeb7e5f, editableevaluate==0.4.7.dev0 - Python 3.13.7; macOS 26.0.1 arm64
datasets==5.1.0,pyarrow==26.0.0
AI assistance was used for investigation and local reproduction. No repository patch has been made.
Activity
FOWEPJF255 commentedon Nov 8, 2026
I reproduced both cases on unchanged main
a5db2ad: the default-prefix example losesmodel_score: 0.1, and the forced-prefix example returns only{'a_b_c': 0.9}. A collision-free control preserves all three scores. This used real localMetricinstances on Windows/Python 3.12.10, Datasets 2.21.0 and PyArrow 17.0.0, without Hub downloads.I am preparing a focused guard that raises
ValueErrorwhen the existing naming rules produce a duplicate final key, with publiccombine().compute()regression tests for both input orders and numbered duplicate module names. Collision-free naming stays unchanged. Related #835 is closed and unmerged; this work starts from official upstream main.I attempted the contribution guide's self-assignment step, but GitHub denied
ReplaceActorsForAssignablefor this account. The issue currently has no assignee. Investigation and this message used OpenAI Codex assistance.