Skip to content

fix: silence snapshot_download progress bars for cached kernels - #1074

Open
drbh wants to merge 2 commits into
mainfrom
quiet-cached-kernel-install
Open

drbh wants to merge 2 commits into
mainfrom
quiet-cached-kernel-install

Conversation

@drbh

@drbh drbh commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

**UPDATED

this pr avoids printing snapshot_download progress bars when a kernel variant is already cached. previously every load printed Fetching N files and Download complete: 0.00B even though nothing was downloaded, which adds a lot of noise when loading models in transformers

RemoteKernel.install now checks for a digest receipt for the variant, and if there is one it calls snapshot_download with a silent tqdm_class. the download still runs so a partially deleted cache gets restored, it just doesnt print anything

note: cached loads still make the same hub requests as before (trust check, refs and variant listing) since those happen during resolution

tested with kernels-community/relu on metal, a cold cache shows bars, a cached load prints nothing and a deleted .so gets restored

@drbh
drbh force-pushed the quiet-cached-kernel-install branch from e84b5ba to 1b7f119 Compare December 2, 2026 20:43
@drbh drbh changed the title kernels: use cached kernel variant without network calls or progress bars fix: skip snapshot_download for cached kernel variants Dec 2, 2026
@drbh
drbh marked this pull request as ready for review December 2, 2026 20:46
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Coverage report — kernels/

Measured on: Python 3.10 / Torch 2.13.0.
Other CI configurations are not included in this number.
Hardware-gated code paths (ROCm/XPU/NPU/Darwin/Windows) are excluded or unreachable on the Linux+CUDA runner.

Total coverage: 90.6% — threshold: 80% — ✅

Per-file breakdown
Name Stmts Miss Cover Missing
src/kernels/__init__.py 14 0 100%
src/kernels/_internals/_system.py 6 1 83% 10
src/kernels/_internals/_versions.py 130 13 90% 53, 59-60, 63-64, 165-170, 199, 219
src/kernels/_internals/archs.py 56 1 98% 94
src/kernels/_internals/backends.py 256 51 80% 43, 103, 163, 172, 181, 206, 215, 224, 248, 295, 311, 315, 319-350, 358, 381-401
src/kernels/_internals/compat.py 10 1 90% 5
src/kernels/_internals/deps.py 70 1 99% 56
src/kernels/_internals/digest.py 58 5 91% 71-73, 136-137
src/kernels/_internals/hf_hub.py 66 2 97% 22, 24
src/kernels/_internals/importer.py 114 6 95% 18, 227, 232, 235, 249-250
src/kernels/_internals/install.py 21 7 67% 76-100
src/kernels/_internals/layer/__init__.py 7 0 100%
src/kernels/_internals/layer/_interval_tree.py 103 4 96% 23, 52, 147, 150
src/kernels/_internals/layer/device.py 48 12 75% 42, 47-49, 91, 96-98, 101, 149, 152, 156
src/kernels/_internals/layer/func.py 99 3 97% 106, 344, 421
src/kernels/_internals/layer/globals.py 5 0 100%
src/kernels/_internals/layer/inspect.py 27 0 100%
src/kernels/_internals/layer/kernelize.py 84 6 93% 306, 314-315, 328, 344-346
src/kernels/_internals/layer/layer.py 329 11 97% 288, 478, 639-640, 661, 669, 680, 715, 719, 732, 888
src/kernels/_internals/layer/mode.py 14 0 100%
src/kernels/_internals/layer/repos.py 136 36 74% 32, 35-42, 73, 86, 90, 99-100, 103, 106-109, 116-117, 120, 123-126, 133-134, 137, 140-143, 150-151, 154, 157-160, 235
src/kernels/_internals/load.py 96 1 99% 363
src/kernels/_internals/locking.py 89 64 28% 35-83, 91-98, 102-125, 137, 152-159, 165-175, 179-186
src/kernels/_internals/python_deps.py 58 6 90% 59-60, 64-65, 101, 104
src/kernels/_internals/resolver.py 194 1 99% 269
src/kernels/_internals/status.py 50 2 96% 25, 79
src/kernels/_internals/validate.py 105 7 93% 9, 102, 173, 196-197, 233-234
src/kernels/_internals/variants.py 435 11 97% 232, 264, 518-519, 561-564, 566, 749-755
src/kernels/_internals/verify.py 102 6 94% 44, 176-178, 266-267
src/kernels/benchmarks.py 2 0 100%
src/kernels/hf_hub.py 2 2 0% 1-3
src/kernels/load.py 2 2 0% 1-3
src/kernels/lock.py 2 2 0% 1-3
src/kernels/metadata.py 2 0 100%
src/kernels/resolve.py 3 0 100%
src/kernels/validate.py 2 0 100%
TOTAL 2797 264 91%

1 empty file skipped.

Updated by the Test kernels workflow on commit 799efe06e180769e53bb115fb039806e34d8ab34.

Comment on lines +102 to +105
repo_path = download(local_files_only=True)
tree_cache = repo_path.parent.parent / "trees" / f"{self.revision}.json"
if not tree_cache.exists():
raise LocalEntryNotFoundError(f"No cached tree listing for {self.repo_id}@{self.revision}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how do we know that the trees is a complete directory in this context of loading? For example, could trees be an incomplete directory at this point which could later cause troubles during loading of the kernel?

@danieldk danieldk Dec 3, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this seems unsafe, since the tree JSON is created before downloading blobs:

https://github.com/huggingface/huggingface_hub/blob/092dc1e0538bd03abc3b649bb07f658a5085605d/src/huggingface_hub/_snapshot_download.py#L301

We might even have caused the creation of the tree file before when fetching the metadata.

I think the best way to do this is to check if the kernel already has a receipt in the digest receipt store for KernelLocation. Since in that case, the kernel has already been fully downloaded and successfully validated before.

If there is a receipt, we

  • Should still download (to cover the case where the user blew away part of the cache, but not the receipt store), but we can disable the progress bar.
  • If the download fails (e.g. no network connectivity), we could still continue. Since the 'blew away only a part of the cache'-scenario is a bit unlikely.

Alternatively, if there is a receipt, we can also check that the files in the digest still exist and skip the download altogether.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small request: please don't merge without approval from me too, since I'm the most familiar with all the digest stuff, etc.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good points!

went with the receipt in the latest changes, much cleaner than relying on the hub tree cache. if there's a receipt for the variant we still call snapshot_download but with the progress bars disabled, so a partially deleted cache still gets restored. added tests for the quiet cached install and for restoring a deleted file

note: writing the tree file before the blobs is actually what let the hub catch an interrupted download, since it lists the whole repo (and is written atomically) so any missing files raise IncompleteSnapshotError. an unreadable tree file would skip that check though, which the receipt avoids

if not tree_cache.exists():
raise LocalEntryNotFoundError(f"No cached tree listing for {self.repo_id}@{self.revision}")
except (IncompleteSnapshotError, LocalEntryNotFoundError):
repo_path = download(local_files_only=False)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add a test for this behaviour as it seems like an important UX-level improvement.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, thanks for pointing out - added tests in the latest changes

@drbh drbh changed the title fix: skip snapshot_download for cached kernel variants fix: silence snapshot_download progress bars for cached kernels Dec 3, 2026

@danieldk danieldk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

This branch has not been deployed

No deployments
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.

4 participants