Skip to content

Commit 746a199

Browse files
committed
feat: make prefill optional
1 parent a4f300a commit 746a199

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

bigcodebench/generate.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ def run_codegen(
140140
backend: str = "vllm",
141141
base_url: str = None,
142142
tp: int = 1,
143-
instruction_prefix: str = None,
144-
response_prefix: str = None,
143+
instruction_prefix: str = "Please provide a self-contained Python script that solves the following problem in a markdown code block:",
144+
response_prefix: str ="Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:",
145+
prefill: bool = True,
145146
revision: str = "main",
146147
trust_remote_code: bool = False,
147148
tokenizer_name: str = None,
@@ -163,11 +164,6 @@ def run_codegen(
163164
# Make project dir
164165
os.makedirs(root, exist_ok=True)
165166

166-
if instruction_prefix is None:
167-
instruction_prefix = "Please provide a self-contained Python script that solves the following problem in a markdown code block:"
168-
if response_prefix is None:
169-
response_prefix = "Below is a Python script with a self-contained function that solves the problem and passes corresponding tests:"
170-
171167
# Make dir for codes generated by each model
172168
model_runner = make_model(
173169
model=model,
@@ -179,6 +175,7 @@ def run_codegen(
179175
reasoning_effort=reasoning_effort,
180176
instruction_prefix=instruction_prefix,
181177
response_prefix=response_prefix,
178+
prefill=prefill,
182179
base_url=base_url,
183180
tp=tp,
184181
revision=revision,

bigcodebench/provider/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def make_model(
1414
# instruction model only
1515
instruction_prefix: str = None,
1616
response_prefix: str = None,
17+
prefill: bool = True,
1718
# vllm and hf only
1819
revision: str = "main",
1920
# vllm only
@@ -42,6 +43,7 @@ def make_model(
4243
tp=tp,
4344
instruction_prefix=instruction_prefix,
4445
response_prefix=response_prefix,
46+
prefill=prefill,
4547
trust_remote_code=trust_remote_code,
4648
tokenizer_name=tokenizer_name,
4749
tokenizer_legacy=tokenizer_legacy,
@@ -60,6 +62,7 @@ def make_model(
6062
direct_completion=direct_completion,
6163
instruction_prefix=instruction_prefix,
6264
response_prefix=response_prefix,
65+
prefill=prefill,
6366
attn_implementation=attn_implementation,
6467
trust_remote_code=trust_remote_code,
6568
tokenizer_name=tokenizer_name,

bigcodebench/provider/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def __init__(
2020
tokenizer_legacy: bool = False,
2121
instruction_prefix: str = None,
2222
response_prefix: str = None,
23+
prefill: bool = True,
2324
) -> None:
2425
print("Initializing a decoder model: {} ...".format(name))
2526
self.name = name
@@ -37,6 +38,7 @@ def __init__(
3738
self.tokenizer_legacy = tokenizer_legacy
3839
self.instruction_prefix = instruction_prefix
3940
self.response_prefix = response_prefix
41+
self.prefill = prefill
4042

4143
@abstractmethod
4244
def codegen(

bigcodebench/provider/utility.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def make_raw_chat_prompt(
2828
split: str,
2929
instruction_prefix: str,
3030
response_prefix: str,
31+
prefill: bool,
3132
tokenizer: AutoTokenizer,
3233
direct_completion: bool = False,
3334
) -> str:
@@ -58,13 +59,21 @@ def make_raw_chat_prompt(
5859
```
5960
"""
6061
if tokenizer:
61-
task_prompt = tokenizer.apply_chat_template(
62-
[
63-
{"role": "user", "content": task_prompt},
64-
{"role": "assistant", "content": response},
65-
],
66-
tokenize=False,
67-
).split(_MAGIC_SPLITTER_)[0]
62+
if prefill:
63+
task_prompt = tokenizer.apply_chat_template(
64+
[
65+
{"role": "user", "content": task_prompt},
66+
{"role": "assistant", "content": response},
67+
],
68+
tokenize=False,
69+
).split(_MAGIC_SPLITTER_)[0]
70+
else:
71+
task_prompt = tokenizer.apply_chat_template(
72+
[
73+
{"role": "user", "content": task_prompt},
74+
],
75+
tokenize=False,
76+
).split(_MAGIC_SPLITTER_)[0]
6877
return task_prompt
6978

7079

bigcodebench/provider/vllm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def codegen(
4747
split=self.split,
4848
instruction_prefix=self.instruction_prefix,
4949
response_prefix=self.response_prefix,
50+
prefill=self.prefill,
5051
tokenizer=self.tokenizer,
5152
direct_completion=self.direct_completion,
5253
)

0 commit comments

Comments
 (0)