Add generator-style run_batch function (#2513)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Xingyao Wang
2025-01-06 18:04:55 -05:00
committed by GitHub
parent 287427e2e6
commit 1acbaf1b5a
3 changed files with 95 additions and 1 deletions

View File

@@ -509,13 +509,35 @@ def test_hellaswag_select():
temperature=0,
num_threads=64,
progress_bar=True,
generator_style=False,
)
preds = [choices[i].index(rets[i]["answer"]) for i in range(len(rets))]
preds = []
for i, ret in enumerate(rets):
preds.append(choices[i].index(ret["answer"]))
latency = time.time() - tic
# Compute accuracy
accuracy = np.mean(np.array(preds) == np.array(labels))
# Test generator style of run_batch
tic = time.time()
rets = few_shot_hellaswag.run_batch(
arguments,
temperature=0,
num_threads=64,
progress_bar=True,
generator_style=True,
)
preds_gen = []
for i, ret in enumerate(rets):
preds_gen.append(choices[i].index(ret["answer"]))
latency_gen = time.time() - tic
# Compute accuracy
accuracy_gen = np.mean(np.array(preds_gen) == np.array(labels))
assert np.abs(accuracy_gen - accuracy) < 0.01
assert np.abs(latency_gen - latency) < 1
return accuracy, latency