Skip to content

Commit

Permalink
fix: handle 401s for lora dls as terminal; spend less time retrying
Browse files Browse the repository at this point in the history
  • Loading branch information
tazlin committed Mar 6, 2024
1 parent 45a769e commit 59cb36c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions hordelib/model_manager/lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class LoraModelManager(BaseModelManager):
LORA_API = "https://civitai.com/api/v1/models?types=LORA&sort=Highest%20Rated&primaryFileOnly=true"
MAX_RETRIES = 10 if not TESTS_ONGOING else 3
MAX_DOWNLOAD_THREADS = 3
RETRY_DELAY = 5 if not TESTS_ONGOING else 0.2
RETRY_DELAY = 3 if not TESTS_ONGOING else 0.2
"""The time to wait between retries in seconds"""
REQUEST_METADATA_TIMEOUT = 30
REQUEST_METADATA_TIMEOUT = 20
"""The time to wait for a response from the server in seconds"""
REQUEST_DOWNLOAD_TIMEOUT = 300
"""The time to wait for a response from the server in seconds"""
Expand Down Expand Up @@ -528,14 +528,22 @@ def _download_thread(self, thread_number):
except (requests.HTTPError, requests.ConnectionError, requests.Timeout, json.JSONDecodeError) as e:
# We will retry
logger.debug(
f"Error downloading {lora['versions'][version]['filename']} {e}. "
f"Error downloading {lora['versions'][version]['filename']} {e} ({type(e)}). "
f"Retry {retries}/{self.MAX_RETRIES}",
)

# If this is a 401, we're not going to get anywhere, just just give up
if isinstance(e, requests.HTTPError) and e.response.status_code == 401:
logger.error(
f"Error downloading {lora['versions'][version]['filename']}. "
"CivitAI appears to be redirecting us to a login page. Aborting",
)
break

except Exception as e:
# Failed badly, ignore and retry
logger.debug(
f"Fatal error downloading {lora['versions'][version]['filename']} {e}. "
f"Fatal error downloading {lora['versions'][version]['filename']} {e} ({type(e)}). "
f"Retry {retries}/{self.MAX_RETRIES}",
)

Expand Down

0 comments on commit 59cb36c

Please sign in to comment.