Skip to content

Commit 24e42d1

Browse files
committed
feat(generate): add reasoning effort for o1 and o3
1 parent 3314ebe commit 24e42d1

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

bigcodebench/gen/util/openai_request.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ def make_request(
1010
model: str,
1111
max_tokens: int = 512,
1212
temperature: float = 1,
13+
reasoning_effort: str = "medium",
1314
n: int = 1,
1415
**kwargs
1516
) -> ChatCompletion:
1617
kwargs["top_p"] = 0.95
1718
kwargs["max_completion_tokens"] = max_tokens
1819
kwargs["temperature"] = temperature
19-
if model.startswith("o1-"): # pop top-p and max_completion_tokens
20+
if model.startswith("o1-") or model.startswith("o3-"): # pop top-p and max_completion_tokens
2021
kwargs.pop("top_p")
2122
kwargs.pop("max_completion_tokens")
2223
kwargs.pop("temperature")
24+
kwargs["reasoning_effort"] = reasoning_effort
25+
2326
return client.chat.completions.create(
2427
model=model,
2528
messages=[

bigcodebench/generate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def run_codegen(
132132
temperature: float = 0.0,
133133
max_new_tokens: int = 1280,
134134
greedy: bool = False,
135+
reasoning_effort: str = "medium", # o1 and o3 only
135136
strip_newlines: bool = False,
136137
direct_completion: bool = False,
137138
resume: bool = True,
@@ -175,6 +176,7 @@ def run_codegen(
175176
split=split,
176177
temperature=temperature,
177178
max_new_tokens=max_new_tokens,
179+
reasoning_effort=reasoning_effort,
178180
instruction_prefix=instruction_prefix,
179181
response_prefix=response_prefix,
180182
base_url=base_url,

bigcodebench/provider/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def make_model(
99
dataset: str = "bigcodebench",
1010
temperature: float = 0.0,
1111
max_new_tokens: int = 1280,
12+
# o1 and o3 only
13+
reasoning_effort: str = "medium",
1214
# instruction model only
1315
instruction_prefix: str = None,
1416
response_prefix: str = None,
@@ -73,6 +75,7 @@ def make_model(
7375
split=split,
7476
temperature=temperature,
7577
max_new_tokens=max_new_tokens,
78+
reasoning_effort=reasoning_effort,
7679
base_url=base_url,
7780
instruction_prefix=instruction_prefix,
7881
response_prefix=response_prefix,

bigcodebench/provider/openai.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
from bigcodebench.provider.utility import concurrent_call
1010

1111
class OpenAIChatDecoder(DecoderBase):
12-
def __init__(self, name: str, base_url=None, **kwargs) -> None:
12+
def __init__(self, name: str, base_url=None, reasoning_effort="medium", **kwargs) -> None:
1313
super().__init__(name, **kwargs)
1414
self.base_url = base_url
15+
self.reasoning_effort = reasoning_effort
1516

1617
def codegen(
1718
self, prompts: List[str], do_sample: bool = True, num_samples: int = 200
@@ -45,6 +46,7 @@ def _codegen_api_batch(self, messages: List[str], num_samples: int) -> List[str]
4546
model=self.name,
4647
max_tokens=self.max_new_tokens,
4748
temperature=self.temperature,
49+
reasoning_effort=self.reasoning_effort,
4850
n=num_samples,
4951
)
5052
outputs = []

0 commit comments

Comments
 (0)