Skip to content

fix(models): reliable model downloads and storage location on Windows - #1247

Open
procdeveloper wants to merge 5 commits into
jamiepine:mainfrom
procdeveloper:fix/models-dir-windows
Open

procdeveloper wants to merge 5 commits into
jamiepine:mainfrom
procdeveloper:fix/models-dir-windows

Conversation

@procdeveloper

Copy link
Copy Markdown

Summary

Model downloads were unreliable on Windows, and some of the problems affect every platform. This PR fixes them one commit each:

  1. Custom models folder ignored on fresh installs. If no models had been downloaded yet, choosing a folder skipped the "move" step and never saved the new location, so the next download still went to the default C: cache. The folder is now saved and the server restarted even when there's nothing to move.
  2. Moving models broke HuggingFace cache links. The cache stores snapshots/<rev>/file -> ../../blobs/<hash> links. Migration copied every link target in full (so each file was copied twice) and the folder size counted them twice. Links that stay inside the cache are now recreated. Where Windows refuses the symlink (no Developer Mode, network shares), it falls back to a hard link to the copied blob, then to a plain copy.
  3. Parallel downloads corrupted each other. A "download" is a model load, and transformers/accelerate patch process-global state while loading (init_empty_weights, no_init_weights, the default dtype). Two loads running at once produced Cannot copy out of meta tensor errors. Both downloads also patched the same tqdm classes, so progress bars jumped between models ([BUG] Download progress bars display incorrect values when downloading multiple models concurrently (Windows) #708). Loads are now serialized in model_load_progress, and a queued download shows "Waiting for another model to finish loading...".
  4. UI froze with many downloads running. Each download toast held its own Server-Sent Events stream open, and the webview only allows 6 connections per host. With 6 or more downloads, every other request stalled: the Download button did nothing, the list stopped refreshing, and dropped streams showed "Failed to track download progress". Toasts now read the shared, polled /tasks/active query. They also finish only when the server reports the model downloaded, not when the first file reaches 100%.
  5. VRAM filled up during downloads. Each download left its model loaded on the GPU, so queued downloads later failed with CUDA out of memory. A model loaded only for its download is now unloaded afterwards, unless it was already loaded or a generation is running.
  6. TADA 3B never downloaded. The generic load path called load_model() without a size, so downloading TADA 3B loaded the cached 1B and reported success. The loaded check and unload ignored the size too. A stale "Connecting to HuggingFace..." entry was also left in /tasks/active for good.
  7. Offline mode stuck to reused threads. huggingface_hub 0.x caches one requests.Session per thread, and a session created while HF_HUB_OFFLINE is forced refuses every request for the rest of that thread's life. Model loads run on reused worker threads, so after a cached model loaded, a later download (or a Kokoro generation fetching a voice file) on the same thread failed with "outgoing traffic has been disabled". The session cache is now reset whenever the offline window opens or closes. TADA 3B's sharded weights were also never recognised as cached, which would have blocked generating with it.

Testing

  • New tests: test_models_migrate_symlinks.py, test_model_load_serialization.py, test_download_unloads_model.py, test_offline_session_reset.py. They pass together with the existing offline, progress and model tests.
  • Two existing tests fail the same way without these changes: test_progress.py::test_hf_progress_tracker and test_offline_guard.py::test_nesting_opposite_mode_on_same_thread_raises_instead_of_deadlocking.
  • Frontend: tsc --noEmit is clean.
  • Manually on Windows 10 (RTX 5070 Ti, CUDA build) with a locally built app:
    • downloaded one model to C:, moved the cache to D: through the UI with links intact, then downloaded the rest to D:
    • queued all models at once: one loads at a time, the others show "Waiting...", the UI stays responsive, and no CUDA out of memory
    • downloaded TADA 3B and generated with Kokoro after the offline fix

🤖 Generated with Claude Code

zharijs and others added 5 commits November 14, 2026 03:15
…cate HF links on migration

Picking a models folder before any model was downloaded called
/models/migrate, which returned moved=0; the UI then showed "no models to
migrate" and returned without saving the folder or restarting the server.
The choice was silently discarded and every download kept going to the
default HuggingFace cache (C:\Users\<user>\.cache\huggingface\hub on
Windows). Now the new location is adopted even when there is nothing to
move.

The cross-filesystem migration path (e.g. C: -> D: on Windows) followed
the snapshots/<rev>/* -> blobs/<hash> symlinks, so every model was written
twice at the destination and the progress total double-counted. Symlinks
inside the cache are now recreated (relative symlink, then NTFS hard link
when symlinks are not permitted, then a plain copy as a last resort), and
the size calculation skips links.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t each other

Starting a second download while another model was loading (e.g. Whisper
while Qwen TTS was downloading) made the first load fail with "Cannot copy
out of meta tensor; no data!" and made progress bars jump between models.

Every model download in voicebox is a load, and loads run on worker threads.
transformers/accelerate build models inside init_empty_weights(), which
replaces torch.nn.Module.register_parameter for the whole process, so layers
another backend built at the same moment landed on the meta device.
no_init_weights() and from_pretrained's default-dtype switch are global too.
HFProgressTracker also patches the shared tqdm classes, so two concurrent
downloads reported each other's bytes (jamiepine#708), and whichever finished first
restored tqdm underneath the other.

All backends load through model_load_progress, so serialize there with a
process-wide re-entrant lock. A load that has to wait reports "Waiting for
another model to finish loading..." instead of looking stuck.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ter each

Download toasts opened one Server-Sent Events stream per active model. The
webview allows only six HTTP connections per server, so with six or more
downloads active (queued ones included) every other request stalled behind
them: the model list stopped refreshing, the Download button appeared to do
nothing, and dropped streams surfaced as "Failed to track download progress".
The toasts now read the shared, polled ['activeTasks'] query instead, which
costs one short request per second however many downloads are tracked. A
download is no longer reported complete when its first file reaches 100%;
it completes when the server drops the task and the model is downloaded.

/models/download works by loading the model, which left it resident on the
GPU. A few queued downloads filled VRAM until later ones failed with "CUDA
out of memory" although their files were fine. The route now unloads a model
it loaded only to fetch its weights, unless a generation is running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tada-1b and tada-3b-ml share one backend, but the generic download path
called load_model() without a size, so "downloading" TADA 3B loaded the
cached 1B model and reported success without fetching anything. The
loaded check and unload likewise ignored the size.

The download task also never closed its initial "Connecting to
HuggingFace..." progress entry when the load reported under a different
name, so TADA 3B stayed in /tasks/active as a download that never ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…harded TADA 3B

huggingface_hub 0.x caches one requests.Session per thread, and a session
created while HF_HUB_OFFLINE is forced mounts an adapter that refuses
every request for the rest of the thread's life. Model loads run on reused
worker threads, so after a cached model had loaded on a thread, a later
download landing there failed with "outgoing traffic has been disabled"
(seen with TADA 3B) even though the offline window was long closed.
Reset the session cache whenever the window opens or closes.

TADA 3B ships sharded weights, but the cache check required a single
model.safetensors, so the backend always treated 3B as not downloaded and
generation would refuse it. Require config.json plus any weight file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

2 participants