Use independent HTTP range connections for ModelScope
Browse files- mirror_worker.py +6 -2
mirror_worker.py
CHANGED
|
@@ -64,7 +64,7 @@ def commit_batch(target: HfApi, batch: list[tuple[str, Path]]) -> None:
|
|
| 64 |
|
| 65 |
|
| 66 |
def direct_download(path: str, target: Path, size: int, expected_sha256: str | None) -> None:
|
| 67 |
-
"""Download a ModelScope object via direct HTTP
|
| 68 |
|
| 69 |
This intentionally bypasses ModelScope's snapshot/cache/downloader stack.
|
| 70 |
Ranges write directly into a preallocated temporary file, avoiding the
|
|
@@ -85,7 +85,11 @@ def direct_download(path: str, target: Path, size: int, expected_sha256: str | N
|
|
| 85 |
timeout = httpx.Timeout(connect=30.0, read=120.0, write=120.0, pool=30.0)
|
| 86 |
limits = httpx.Limits(max_connections=20, max_keepalive_connections=16)
|
| 87 |
with httpx.Client(
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
follow_redirects=True,
|
| 90 |
timeout=timeout,
|
| 91 |
limits=limits,
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
def direct_download(path: str, target: Path, size: int, expected_sha256: str | None) -> None:
|
| 67 |
+
"""Download a ModelScope object via direct concurrent HTTP range requests.
|
| 68 |
|
| 69 |
This intentionally bypasses ModelScope's snapshot/cache/downloader stack.
|
| 70 |
Ranges write directly into a preallocated temporary file, avoiding the
|
|
|
|
| 85 |
timeout = httpx.Timeout(connect=30.0, read=120.0, write=120.0, pool=30.0)
|
| 86 |
limits = httpx.Limits(max_connections=20, max_keepalive_connections=16)
|
| 87 |
with httpx.Client(
|
| 88 |
+
# ModelScope's redirect endpoint intermittently resets HTTP/2
|
| 89 |
+
# multiplexed streams. A pool of independent HTTP/1.1 ranges is
|
| 90 |
+
# faster in practice because failed streams do not take siblings
|
| 91 |
+
# down with the same connection.
|
| 92 |
+
http2=False,
|
| 93 |
follow_redirects=True,
|
| 94 |
timeout=timeout,
|
| 95 |
limits=limits,
|