Skip to content

Studio: don't re-download updated GGUFs on load#7209

Merged
oobabooga merged 9 commits into
unslothai:mainfrom
oobabooga:gguf-load-cache-reuse
Jul 17, 2026
Merged

Studio: don't re-download updated GGUFs on load#7209
oobabooga merged 9 commits into
unslothai:mainfrom
oobabooga:gguf-load-cache-reuse

Conversation

@oobabooga

@oobabooga oobabooga commented Jul 17, 2026

Copy link
Copy Markdown
Member

When a GGUF repo is re-uploaded (as with the recent Gemma QAT quants), the next load of an already-downloaded model re-downloads the whole file. The load path resolves against the repo's current revision, counts the on-disk copy as "0.0 GB already cached", and starts a full fetch with no consent step. The Update button, which does ask first, never gets involved. Users reported this as "Unsloth is re-downloading a model I already have and I never gave it permission".

While that download runs, the hub download manager can start a second download of the same repo. Its registry cannot see the load path's downloader, so two writers hit the same cache blobs. The hub worker's cache preparation then purges partial blobs it does not own, which can stall the other transfer.

Fix

  • _download_gguf reuses a complete cached copy (any revision) before any sizing or fetch, online or offline. If a re-upload renamed the file, the variant label resolves against the local cache. Split sets are reused only when every shard is co-located.
  • mmproj files prefer a sibling in the reused main's snapshot, so cached vision models load without fetching and remain revision-consistent. Online MTP resolution uses the same preference, while offline MTP keeps its existing root-first cache fallback.
  • Updates stay the only path that replaces a cached main GGUF with files from a newer revision (force still re-fetches). Snapshots iterate newest-first, so a load right after an update picks up the new files.
  • The load route marks its repo in flight, and /api/hub/download returns 409 for that repo while marked. Conversely, /load returns 409 when a hub download is active for the repo and no cached copy exists to reuse. A reuse-load proceeds since it never touches in-flight blobs. The guard and the load path share one probe (cached_gguf_for_load), so their verdicts cannot drift.
  • Removed the superseded offline-only reuse block. This also fixes a low-disk load of a fully cached model silently swapping to a smaller quant.

Out of scope

Safetensors/transformers loads keep their existing behavior (separate worker, same race class). The hub worker still lacks the xet-stall HTTP fallback the load path has. Both are follow-ups.

Verification

New tests in test_gguf_load_cache_reuse.py cover reuse after a revision bump, renamed files, force re-fetch, split sets, newest-snapshot preference, an mmproj snapshot sibling, the in-flight marker, the hub-side 409, and the shared probe behind the /load guard. test_download_online_does_not_reuse_old_snapshot was flipped to pin the new policy (now test_download_online_reuses_complete_cached_snapshot). The full gguf/download/llama_cpp/hub test sweep passes (1163 tests).

@oobabooga
oobabooga requested a review from danielhanchen as a code owner July 17, 2026 16:37
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ac0e2fb10

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread studio/backend/core/inference/llama_cpp.py Outdated
Comment thread studio/backend/routes/inference.py Outdated
Comment thread studio/backend/core/inference/llama_cpp.py Outdated
Comment thread studio/backend/routes/inference.py Outdated
Comment thread studio/backend/hub/services/models/downloads.py Outdated
Comment thread studio/backend/core/inference/llama_cpp.py
Comment thread studio/backend/core/inference/llama_cpp.py Outdated
@Imagineer99

Copy link
Copy Markdown
Collaborator

I reproduced the original issue and the main fix works. There are still a few cache/split and download-race edge cases in the inline reviews, but once those are addressed this looks good. Happy to retest.

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ae9a76189

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread studio/backend/core/inference/llama_cpp.py
Comment thread studio/backend/core/inference/llama_cpp.py Outdated
Comment thread studio/backend/hub/services/models/downloads.py Outdated
Comment thread studio/backend/core/inference/llama_cpp.py Outdated
Comment thread studio/backend/routes/inference.py Outdated
@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 616746d30f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread studio/backend/routes/inference.py Outdated
Comment thread studio/backend/routes/inference.py
@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 519d46d4de

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 8124b5747e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@oobabooga
oobabooga merged commit 2139200 into unslothai:main Jul 17, 2026
42 of 44 checks passed
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.

2 participants