From 7fc3fbb4d400a57a05c4fdd34d7c686e5529f7fd Mon Sep 17 00:00:00 2001 From: Pu Fanyi Date: Sun, 22 Sep 2024 17:49:42 +0800 Subject: [PATCH] [Bug] Fix the checking error in gpt4v generation (#274) * fix * Fix error handling in GPT4V class --- lmms_eval/models/gpt4v.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lmms_eval/models/gpt4v.py b/lmms_eval/models/gpt4v.py index 1edeebb8..fc29d553 100755 --- a/lmms_eval/models/gpt4v.py +++ b/lmms_eval/models/gpt4v.py @@ -185,7 +185,9 @@ def generate_until(self, requests) -> List[str]: payload["max_tokens"] = gen_kwargs["max_new_tokens"] payload["temperature"] = gen_kwargs["temperature"] - for attempt in range(5): + NUM_ATTEMPTS = 5 + + for attempt in range(NUM_ATTEMPTS): try: response = url_requests.post(API_URL, headers=headers, json=payload, timeout=self.timeout) response_data = response.json() @@ -200,10 +202,10 @@ def generate_until(self, requests) -> List[str]: error_msg = "" eval_logger.info(f"Attempt {attempt + 1} failed with error: {str(e)}.\nReponse: {error_msg}") - if attempt <= 5: + if attempt < NUM_ATTEMPTS - 1: time.sleep(NUM_SECONDS_TO_SLEEP) else: # If this was the last attempt, log and return empty string - eval_logger.error(f"All 5 attempts failed. Last error message: {str(e)}.\nResponse: {response.json()}") + eval_logger.error(f"All {NUM_ATTEMPTS} attempts failed. Last error message: {str(e)}.\nResponse: {response.json()}") response_text = "" res.append(response_text) pbar.update(1)