Skip to content

Commit 19f6ae0

Browse files
Fix retries and handle corner cases
1 parent f35d534 commit 19f6ae0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

optillm/cepo/cepo.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def llm_call(
225225
- finish_reason: Why generation stopped.
226226
- completion_tokens: Number of tokens generated.
227227
"""
228-
retries = cepo_config.num_of_retries # total attempts = retries + 1 initial call
228+
retries = cepo_config.num_of_retries + 1 # total attempts = retries + 1 initial call
229229
for attempt in range(retries):
230230
try:
231231
response_object = client.chat.completions.create(
@@ -907,11 +907,11 @@ def majority_vote_math(completions, last_n_chars=100):
907907

908908
counts = Counter(answer for _, answer in extracted_answer_map)
909909
majority_answer, count = counts.most_common(1)[0]
910-
# TODO it may return all "None", we probably should handle this case
911-
# Return one response whose extracted answer matches the majority
910+
912911
for response, answer in extracted_answer_map:
913912
if answer == majority_answer:
914913
return response, count
914+
return extracted_answer_map[0][0], 0
915915

916916

917917
def majority_vote_mcq(completions, last_n_chars=100):
@@ -922,10 +922,11 @@ def majority_vote_mcq(completions, last_n_chars=100):
922922

923923
counts = Counter(answer for _, answer in extracted_answer_map)
924924
majority_answer, count = counts.most_common(1)[0]
925-
# TODO it may return all "None", we probably should handle this case
925+
926926
for response, answer in extracted_answer_map:
927927
if answer == majority_answer:
928928
return response, count
929+
return extracted_answer_map[0][0], 0
929930

930931

931932
def rate_completions_majority(completions: list[str], last_n_chars: int = 150) -> tuple[str, int, dict]:

0 commit comments

Comments
 (0)