Skip to content

Weight snapshot download progress by file size, not file count - #369

Open
atlascodesai wants to merge 1 commit into
huggingface:mainfrom
atlas-open-sources:byte-weighted-snapshot-progress-on-main
Open

Weight snapshot download progress by file size, not file count#369
atlascodesai wants to merge 1 commit into
huggingface:mainfrom
atlas-open-sources:byte-weighted-snapshot-progress-on-main

Conversation

@atlascodesai

Copy link
Copy Markdown

Problem

HubApi.snapshot aggregates per-file progress into a parent Progress whose totalUnitCount is the number of files, so every file weighs equally. For a typical model repo (one multi-GB weight shard + several tiny JSON/config files), the aggregate fractionCompleted barely moves while the large shard downloads and then jumps near the end — even though the per-file downloader already tracks real bytes.

Change

Weight each file by its remote byte size instead:

  • Pre-fetch each file's FileMetadata once (reusing the downloader's own source URL, so non-model repo-type prefixes stay correct) and size its child Progress by bytes; the parent totalUnitCount is the sum of byte sizes.
  • Thread that metadata into HubFileDownloader.remoteMetadata so download() reuses it instead of issuing a second getFileMetadata request per file — no extra network round-trips vs. before.
  • Files with unknown size fall back to a minimal weight so they still advance progress without dominating it.
  • Offline mode is unaffected (it returns before this path).

Tests

  • Existing snapshot tests now assert completedUnitCount reaches totalUnitCount (correct regardless of weighting scheme).
  • New testSnapshotProgressIsByteWeighted asserts the aggregate totalUnitCount equals the summed remote byte sizes.
  • SnapshotDownloadTests — 12 tests — pass against the live Hugging Face Hub (real downloads from public repos), including large-file, background, revision/PR-revision, and metadata cases.

AI disclosure: this change was written by Anthropic's Claude (Opus 4.8) and independently reviewed by OpenAI's Codex (GPT‑5.5). It was verified by running the full SnapshotDownloadTests suite (12 tests, incl. the new byte-weighting test) against the live Hugging Face Hub, and by building the Hub and test targets against main.

HubApi.snapshot aggregates per-file progress into a parent Progress whose
totalUnitCount is the number of files, giving every file equal weight. For a
typical model repo (one multi-GB weight shard plus several tiny JSON/config
files) the parent fractionCompleted is dominated by file count, so the bar
barely moves while the large shard downloads and then jumps near the end —
even though the per-file downloader already tracks real bytes.

Weight each file by its remote byte size instead:
- Pre-fetch each file's FileMetadata once (reusing the downloader's own
  source URL, so repo-type handling stays correct) and size its child
  Progress by bytes; the parent totalUnitCount is the sum of byte sizes.
- Thread that metadata into HubFileDownloader.remoteMetadata so download()
  reuses it instead of issuing a second getFileMetadata request per file
  (no extra network round-trips vs. before).
- Files with unknown size fall back to a minimal weight so they still
  advance progress without dominating it.

Offline mode is unaffected (it returns before this path). Snapshot tests now
assert completedUnitCount reaches totalUnitCount rather than a hard-coded
file count, which is correct regardless of the weighting scheme.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant