Repository navigation
Studio: fetch up to four Hub files at once over HTTP when partials resume - #15781
Merged
Merged
Conversation
shimmyshimmer
pushed a commit
to shimmyshimmer/unsloth-staging-4
that referenced
this pull request
Oct 28, 2026
…-probing [skip ci]
danielhanchen
marked this pull request as ready for review
October 29, 2026 09:32
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
The Studio Hub download worker (
studio/backend/hub/workers/hf_download.py) passedmax_workers=1to everysnapshot_downloadcall, so a model, GGUF variant, scoped snapshot or dataset was fetched one file at a time. Over HTTP each file paid its own HEAD and request latency in series and was limited to what one connection delivers.Over HTTP the worker now fetches up to four files at once, but only where an interrupted partial resumes: on huggingface_hub up to 1.17 (whose stock writer appends to a shared
.incomplete), or on 1.18+ when the worker restored the resumable writer at import (restore_resumable_partials(), which needs a local filesystem whose lock provably excludes a second writer). Over Xet, on 1.18+ where the resumable writer was not restored (for example Windows or a network mount), or with an unreadable huggingface_hub version, it stays at one file at a time exactly as before. In practice: Linux and macOS on a local filesystem overlap files with any supported huggingface_hub; Windows overlaps only on the Python 3.9 pin (huggingface_hub 0.36.2) and stays serial on 1.18+.Why this is safe for resume: the original reason for
max_workers=1was that resume needs a single sequential writer per partial. That still holds per file: huggingface_hub takes a per-blob lock and each file is one sequential writer, so every partial resumes from its own length. The gate means every partial on disk resumes after a kill. What a kill can lose is the chunk each stream is holding in memory before it is written (DOWNLOAD_CHUNK_SIZE, 10 MiB), so up to about 40 MiB with four streams instead of about 10 MiB with one. Xet is unchanged because hf_xet already fans out inside a file, its buffers scale per file (the memory caps from #7742), and a killed Xet file restarts from zero.Nothing else changes: the transport environment, token handling, the purge and marker logic, verification, cancellation (SIGKILL of the worker process), the error raised (the first failing file in listing order) and the byte-based progress that the download manager reads from the cache.
Side effects of overlapping files, all bounded:
DOWNLOAD_CHUNK_SIZE), so the extra memory scales with the number of streams, not with shard size.Results
These were measured against a local fake Hub serving
model_info, the tree listing andresolveHEAD/GET with Range. Each connection had a bandwidth cap and every request had added latency. The real worker script ran end to end as a subprocess. Base and head were interleaved, with 3 runs per arm and a second base arm as the A/A check.The values are medians, with the [min, max] range in brackets. In every run both arms made the same requests: 2 metadata GETs (plus 1 tree GET on hub 1.x) and exactly one HEAD and one GET per file. They also sent the same bytes. The snapshot directories had an identical sha256 digest across all arms, and no
.incompletefile was left behind. The peak number of concurrent GETs was 1 on base and up to 4 on head.A separate re-run on huggingface_hub 1.33.0 (LLM fixture, same link, 3 interleaved runs per arm) gave base 12.82 s [12.82, 13.05], base A/A 12.83 s [12.79, 12.86] and head 4.05 s [4.05, 4.09], with the same request counts, bytes and digest in every run. Peak worker RSS in those runs was 72 to 83 MB on base and 143 to 153 MB on head.
Resume after SIGKILL: the worker was killed partway through the LLM fixture, then run again. On both hub 0.36.2 and 1.33.0, and on both arms, the bytes left in partials plus the bytes the second run fetched add up exactly to the shard total (201,326,592). Nothing was fetched twice. The final snapshot digest was identical. For example, head with a kill at 3.5 s left 4 partials holding 157,286,400 bytes, and the rerun fetched the remaining 44,040,192.
Re-check on the current head (kill triggered once the fake Hub had sent 48 MiB, 4 x 32 MiB shards at about 8 MB/s per connection, real worker subprocess):
Final files were byte-identical and no
.incompletewas left in every run.Offline (
HF_HUB_OFFLINE=1on a cached repo): base and head give the same output and exit 0.Tests
studio/backend/tests/test_hf_download_file_concurrency.py:snapshot_downloadcalls use the transport budget;test_delete_variant_*inhub/tests/test_model_services.pyandtest_optional_loader_retries_with_gpu_init_disabled) do not touch the worker.py_compileon Python 3.9 and 3.10 for every touched file.Not covered