Compare commits

..
Author SHA1 Message Date
Philipp Emanuel Weidmann 505f3bcada perf: disable KV cache when obtaining module I/O 2026-11-05 17:55:42 +05:30
2 changed files with 15 additions and 21 deletions

No files matched your search

-3
View File
@@ -292,9 +292,6 @@ task = "piqa"
# Task metric to use as the benchmark score.
metric = "acc_norm,none"
# Number of input sequences to process in parallel (0 = auto).
batch_size = 0 # auto
[scorer.ResponseLength]
# Whether to strip leading and trailing whitespace from responses before measuring their length.
+15 -18
View File
@@ -3,7 +3,7 @@
import lm_eval
from lm_eval.models.huggingface import HFLM
from pydantic import BaseModel, Field, NonNegativeInt
from pydantic import BaseModel, Field
from heretic.scorer import Context, Score, Scorer
@@ -24,11 +24,6 @@ class Settings(BaseModel):
description="Task metric to use as the benchmark score.",
)
batch_size: NonNegativeInt = Field(
default=0, # auto
description="Number of input sequences to process in parallel (0 = auto).",
)
class BenchmarkScore(Scorer):
"""
@@ -45,27 +40,29 @@ class BenchmarkScore(Scorer):
def score_name(self) -> str:
return self.settings.score_name
def get_score(self, ctx: Context) -> Score:
def init(self, ctx: Context) -> None:
model = ctx.get_model()
hflm = HFLM(
self.hflm = HFLM(
pretrained=model.model,
tokenizer=model.tokenizer, # ty: ignore[invalid-argument-type]
batch_size="auto"
if self.settings.batch_size == 0
else self.settings.batch_size,
tokenizer=model.tokenizer, # ty:ignore[invalid-argument-type]
batch_size="auto",
)
def get_score(self, ctx: Context) -> Score:
# The purpose of this hack, where we initialize the HFLM object once,
# then update its internal model every time we calculate the score,
# is to get the benefits of batch size caching while allowing for
# model reloads, e.g. when using --evaluate-model.
model = ctx.get_model()
self.hflm.pretrained = model.model
self.hflm._model = model.model
results = lm_eval.simple_evaluate(
model=hflm,
model=self.hflm,
tasks=[self.settings.task],
)
if self.settings.batch_size == 0 and hflm.batch_sizes:
# Cache automatically determined batch size to avoid re-determining
# the batch size on every future run.
self.settings.batch_size = min(hflm.batch_sizes.values())
benchmark_score = float(
results["results"][self.settings.task][self.settings.metric]
)