Compare commits

..
3 changed files with 32 additions and 18 deletions

No files matched your search

+3
View File
@@ -292,6 +292,9 @@ 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.
+9 -1
View File
@@ -235,6 +235,10 @@ class Model:
)
],
max_new_tokens=1,
# The KV cache is deliberately left enabled here so we can
# catch dtype errors related to the cache, which we will need
# for generating responses.
# use_cache=False,
)
except Exception as error:
self.model = None
@@ -855,7 +859,11 @@ class Model:
)
)
self.generate(prompts, max_new_tokens=1)
self.generate(
prompts,
max_new_tokens=1,
use_cache=False,
)
for hook_handle in hook_handles:
hook_handle.remove()
+20 -17
View File
@@ -3,7 +3,7 @@
import lm_eval
from lm_eval.models.huggingface import HFLM
from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, NonNegativeInt
from heretic.scorer import Context, Score, Scorer
@@ -24,6 +24,11 @@ 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):
"""
@@ -40,29 +45,27 @@ class BenchmarkScore(Scorer):
def score_name(self) -> str:
return self.settings.score_name
def init(self, ctx: Context) -> None:
model = ctx.get_model()
self.hflm = HFLM(
pretrained=model.model,
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
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,
)
results = lm_eval.simple_evaluate(
model=self.hflm,
model=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]
)