Skip to content

Commit a44e215

Browse files
authored
Merge pull request #1 from NousResearch/2024-01-06-upstream-multiple-input
Mirror of upstream PR EleutherAI/lm-evaluation-harness#2576
2 parents 6ccd520 + daa8859 commit a44e215

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lm_eval/api/task.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ def build_all_requests(
450450
ctx=fewshot_ctx,
451451
metadata=(self.config["task"], doc_id, self.config.repeats),
452452
apply_chat_template=apply_chat_template,
453+
chat_template=chat_template,
453454
)
454455

455456
if not isinstance(inst, list):
@@ -1087,6 +1088,8 @@ def fewshot_context(
10871088
example = self.doc_to_text(doc)
10881089
if apply_chat_template:
10891090
if self.multiple_input:
1091+
if not labeled_examples:
1092+
return ""
10901093
return chat_template(labeled_examples)
10911094
if isinstance(example, str):
10921095
self.append_target_question(
@@ -1303,6 +1306,7 @@ def construct_requests(
13031306
self, doc: dict, ctx: str, **kwargs
13041307
) -> Union[List[Instance], Instance]:
13051308
apply_chat_template = kwargs.pop("apply_chat_template", False)
1309+
chat_template: Callable | None = kwargs.pop("chat_template", None)
13061310

13071311
aux_arguments = None
13081312

@@ -1317,9 +1321,20 @@ def construct_requests(
13171321
target_delimiter = ""
13181322
if self.multiple_input:
13191323
# If there are multiple inputs, choices are placed in the ctx
1324+
# apply chat_template to choices if apply_chat_template
13201325
cont = self.doc_to_target(doc)
1326+
13211327
arguments = [
1322-
(ctx + choice, f"{target_delimiter}{cont}") for choice in choices
1328+
(
1329+
ctx
1330+
+ (
1331+
chat_template([{"role": "user", "content": choice}])
1332+
if apply_chat_template
1333+
else choice
1334+
),
1335+
f"{target_delimiter}{cont}",
1336+
)
1337+
for choice in choices
13231338
]
13241339
else:
13251340
# Otherwise they are placed in the continuation

0 commit comments

Comments
 (0)