mrfakename commited on
Commit
c704c39
·
verified ·
1 Parent(s): 1bdc314

Upload .mirror/mirror_worker.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. .mirror/mirror_worker.py +9 -3
.mirror/mirror_worker.py CHANGED
@@ -83,7 +83,13 @@ def direct_download(path: str, target: Path, size: int, expected_sha256: str | N
83
  (start, min(size - 1, start + range_size - 1))
84
  for start in range(0, size, range_size)
85
  ]
86
- timeout = httpx.Timeout(connect=30.0, read=120.0, write=120.0, pool=30.0)
 
 
 
 
 
 
87
  limits = httpx.Limits(max_connections=20, max_keepalive_connections=16)
88
  with httpx.Client(
89
  # ModelScope's redirect endpoint intermittently resets HTTP/2
@@ -99,7 +105,7 @@ def direct_download(path: str, target: Path, size: int, expected_sha256: str | N
99
  def fetch(byte_range: tuple[int, int]) -> None:
100
  start, end = byte_range
101
  full_file_response = start == 0 and end == size - 1
102
- for attempt in range(8):
103
  try:
104
  # A few tiny ModelScope objects return an empty 200 to
105
  # a Range request. Retry their single full-file range
@@ -121,7 +127,7 @@ def direct_download(path: str, target: Path, size: int, expected_sha256: str | N
121
  raise RuntimeError(f"short range {start}-{end}: got {offset - start}")
122
  return
123
  except Exception:
124
- if attempt == 7:
125
  raise
126
  time.sleep(min(60, 2 ** attempt))
127
 
 
83
  (start, min(size - 1, start + range_size - 1))
84
  for start in range(0, size, range_size)
85
  ]
86
+ # A failed small-object request does not become healthier after two
87
+ # minutes. Fail it quickly and leave it for the next pass; retain the
88
+ # longer timeout/retry budget for genuinely large ranges.
89
+ small_object = size < 128 * 1024 * 1024
90
+ request_attempts = 3 if small_object else 8
91
+ read_timeout = 35.0 if small_object else 120.0
92
+ timeout = httpx.Timeout(connect=20.0, read=read_timeout, write=120.0, pool=30.0)
93
  limits = httpx.Limits(max_connections=20, max_keepalive_connections=16)
94
  with httpx.Client(
95
  # ModelScope's redirect endpoint intermittently resets HTTP/2
 
105
  def fetch(byte_range: tuple[int, int]) -> None:
106
  start, end = byte_range
107
  full_file_response = start == 0 and end == size - 1
108
+ for attempt in range(request_attempts):
109
  try:
110
  # A few tiny ModelScope objects return an empty 200 to
111
  # a Range request. Retry their single full-file range
 
127
  raise RuntimeError(f"short range {start}-{end}: got {offset - start}")
128
  return
129
  except Exception:
130
+ if attempt == request_attempts - 1:
131
  raise
132
  time.sleep(min(60, 2 ** attempt))
133