Skip to content

Commit

Permalink
Add delay between retries
Browse files Browse the repository at this point in the history
  • Loading branch information
mvafin committed Jul 19, 2024
1 parent 043d489 commit 61c19fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions tests/model_hub_tests/models_hub_common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def print_stat(s: str, value: float):
print(s.format(round_num(value)))


def retry(max_retries=3, exceptions=(Exception,)):
def retry(max_retries=3, exceptions=(Exception,), delay=None):
def retry_decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
Expand All @@ -157,7 +157,9 @@ def wrapper(*args, **kwargs):
return func(*args, **kwargs)
except exceptions as e:
print(f"Attempt {attempt + 1} of {max_retries} failed: {e}")
if attempt == max_retries - 1:
if attempt < max_retries - 1 and delay is not None:
time.sleep(delay)
else:
raise e
return wrapper
return retry_decorator
2 changes: 1 addition & 1 deletion tests/model_hub_tests/pytorch/test_hf_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def setup_class(self):
self.image = Image.open(requests.get(url, stream=True).raw)
self.cuda_available, self.gptq_postinit = None, None

@retry(3, exceptions=(HfHubHTTPError,))
@retry(3, exceptions=(HfHubHTTPError,), delay=1)
def load_model(self, name, type):
name_suffix = ''
if name.find(':') != -1:
Expand Down

0 comments on commit 61c19fe

Please sign in to comment.