Skip to content

Commit bfe3925

Browse files
Address sporadic hanging of evals on certain samples (#1482)
As has been brought up before (#1384, #1292, #270), evals suffer from a hanging issue, where an evaluation run will hang for a very long time (if not indefinitely) at the end of a run (say, on the 99th sample of out 100). This PR addresses this issue, by replacing a seemingly redundant single-threaded thread creation that was happening when making requests, nested inside the already multi-threaded eval loop. My impression is that this nested multithreading was causing overhead that resulted in the hanging experienced. I had also noticed this hanging issue in `EVALS_SEQUENTIAL=1` mode (where it no longer occurs at the end, but instead randomly in the middle of the run). I was able to identify the source of this issue though debugging print statements that ultimately pointed to the `request_with_timeout` function as the culprit. We have tested the new `request_with_timeout` code on a fork where we have run multiple new and pre-existing evals, including with 3rd party solvers, and found no change in behaviour or errors, and a clear improvement on the hanging issue.
1 parent 5805c20 commit bfe3925

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

evals/utils/api_utils.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
This file defines various helper functions for interacting with the OpenAI API.
33
"""
4-
import concurrent
54
import logging
65
import os
76

@@ -38,16 +37,14 @@ def openai_completion_create_retrying(client: OpenAI, *args, **kwargs):
3837

3938
def request_with_timeout(func, *args, timeout=EVALS_THREAD_TIMEOUT, **kwargs):
4039
"""
41-
Worker thread for making a single request within allotted time.
40+
Function for making a single request within allotted time.
4241
"""
4342
while True:
44-
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
45-
future = executor.submit(func, *args, **kwargs)
46-
try:
47-
result = future.result(timeout=timeout)
48-
return result
49-
except concurrent.futures.TimeoutError:
50-
continue
43+
try:
44+
result = func(*args, timeout=timeout, **kwargs)
45+
return result
46+
except openai.APITimeoutError as e:
47+
continue
5148

5249

5350
@backoff.on_exception(

0 commit comments

Comments
 (0)