Skip to content

Prefetch: keep subfolder weights that a root safetensors index maps to - #15184

Merged
danielhanchen merged 4 commits into
mainfrom
root-index-subfolder-prefetch
Oct 25, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
root-index-subfolder-prefetch

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

maybe_prefetch_hf_snapshot warms the cache before a bare remote load. For repos with weights at the root it drops every */...safetensors file, since the load only reads root weights. That breaks repos whose root model.safetensors.index.json maps shards into subfolders. nvidia/Cosmos3-Nano and nvidia/Cosmos3-Edge keep every transformer shard under transformer/ and list them in the root index. The prefetch skips those shards, so FastModel / FastVisionModel then download them uncached, or fail offline, unless HF_HUB_OFFLINE=1 is set by hand.

Change

  • _root_index_weight_subfolders reads the root model.safetensors.index.json and returns the subfolders its weight_map points into. Any failure (no index, 404, bad JSON, non-dict map) returns (), so the prefetch keeps its old behaviour.
  • It is probed next to the existing sentence-transformers module probe, under the same conditions: root weights, no subfolder=, not tokenizer-only / adapter-only / GGUF. When it finds subfolders, the subdir-weight prune is skipped, like the ST case.
  • revision, token and cache_dir are forwarded to the probe.

Who is affected: only repos whose root index names a path with a /. Root-sharded models (model-00001-of-00002.safetensors at the root) return () and prune exactly as before. Repos without a root index get a 404 and keep their current path.

Tests: tests/test_root_index_subfolder_weights.py (19 cases) drives the prefetch through a fake Hub with a Cosmos3-shaped listing, a root-sharded listing and no index. It checks the allow/ignore patterns snapshot_download receives and the probe's forwarded arguments. 11 of the 19 fail on main and all pass here. The existing prefetch tests (test_prefetch_snapshot_scope.py, test_st_subfolder_weights_are_fetched.py, python/test_revision_forwarding.py, test_hf_login_keeps_saved_token.py) still pass: 166 passed in total.

Split out of #14554, which adds the Cosmos3 Studio video families. The Studio path loads through diffusers and does not depend on this.

@danielhanchen danielhanchen self-assigned this Oct 25, 2026
danielhanchen added a commit to sbabamohamad/unsloth that referenced this pull request Oct 25, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T06:10:45.082337Z 79eb470 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 79eb470e01

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 3fe735b into main Oct 25, 2026
21 of 37 checks passed
@danielhanchen
danielhanchen deleted the root-index-subfolder-prefetch branch October 25, 2026 08:33
danielhanchen added a commit that referenced this pull request Oct 26, 2026
Adds `nvidia/Cosmos3-Nano` and `nvidia/Cosmos3-Edge` as Studio video
families, following #13376 and #13378: text-to-video and image-to-video
through diffusers' `Cosmos3OmniPipeline` (diffusers >= 0.41.0: 0.40.0
resolves a group-offloaded transformer's device as the CPU).

**What's different about Cosmos3**
- Its transformer is also the text model, so the pipeline has a
tokenizer and no text encoder. A family whose bf16 component table
prices the text encoder at 0.0 is now read as having none: sizing needs
only transformer and VAE, a snapshot without `text_encoder/` counts as
complete, and an explicit `text_encoder_quant` is refused with the
reason (relates to #14000).
- Each card samples with scheduler and call settings its shipped configs
don't hold. New `VideoFamily` fields `scheduler_overrides` and
`call_kwargs` carry them.
- The pipeline takes the first frame through its own `image=` and crops
it itself.
- Components come from the nvidia repos: no unsloth-hosted copies exist,
both are public and ungated (OpenMDW-1.1), allowlist gains the same two
lines Wan2.1 has (relates to #14003).

**Fidelity**: Studio output is frame-for-frame identical to the plain
diffusers pipeline for both models (Nano 189/189 frames, Edge 121/121,
four clips each, seed 0). Three settings were needed: `cudnn.benchmark`
off, the VAE encoder on stock kernels, and untiled decode when it fits,
including at speed off and under model / group / streaming offload (the
stock 16x tiles leave a 4-latent edge tile at 480/832 px). When untiled
does not fit, and on CPU / MPS, the tiled decode uses per-canvas strides
that keep every edge tile at 8 or more latents (stock strides wherever
they already do).

**Also in this PR** (separate commits, can be split out; the root-index
prefetch fix moved to #15184)
- The latest-transformers offer in the UI covers the `cosmos3` /
`cosmos3_edge` model types (the `unsloth run` prompt for it is left to a
separate PR).
- Frontend: picker rows, Hub "Video gen" label, page defaults; bundle
budget raised by the bytes the rows add.

**Tests**: backend and frontend suites show no new failures against main
(same failing ids on both trees, all environment-related); typecheck
clean. Real-weight renders were checked against plain diffusers outside
the test suite (Edge on a B200: bit-identical, t2v and i2v; Edge on a
T4: valid fp32 output).

**Not in this PR**: training support, and quantized Cosmos3 checkpoints
(#12851); diffusers has no single-file converter for
`Cosmos3OmniTransformer`, so a quant needs a hosted source and a key-map
loader.

`cosmos_guardrail` is not required: Nano's `model_index.json` enables
the safety checker by default, so the load either passes the opt-out or
refuses with a message naming the package. Edge ships with it off.



**Download and offload**: a Nano download skips `sound_tokenizer/` (1.99
GB, passed as None), a local Nano folder without `sound_tokenizer/` or
`vision_encoder/` validates, and under `low_vram` the VAE goes back to
the CPU after the conditioning encode for both t2v and i2v (real Edge:
VAE on `cuda:0` at every transformer step before, `cpu` after).

## Screenshots

Video page model picker on the merge base (left) and this branch
(right): the branch lists Cosmos3 Edge after the HunyuanVideo rows.

![Video picker before and after: Cosmos3 Edge row
appears](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/14554/pr14554_pair_00-cbaced2e803a.png)

The Hub pair below is harness state, not this PR: the two sides read the
live Hub listing at different times, so the trending rows differ (the
masked shot is otherwise identical). macOS and Windows legs: 41 of 41
steps identical.

<!-- studio-regress:start -->
### Studio UI regression check
Base `c9e5d4ab0` vs head `4aa1f7b91`. Functional: **NO_REGRESSION**, UI
coverage 89%, 1 visual change(s), 0 text-only change(s). Only steps
whose screenshots differ are shown.

**crawl/r_hub**: masks cover 37% of the shot | reproduced on confirm
(VISUAL_DIFF)
Facts: `missing`: {'before': ['button:DeepSeek-V#.#-Flash-#-GGUF',
'button:Model hub', 'button:NVIDIA-Nemotron-#.#-Super-VL-#B-A#B-GGUF',
'button:Qwen#.#-#B-A#B-GGUF', 'button:Search', 'button:Show workflows',
'button:gemma-#-#B-A#B-it-GGUF'], 'after': ['button:Filters',
'button:MiniMax-H#-GGUF',
'button:NVIDIA-Nemotron-#.#-Super-VL-#B-A#B-GGUF', 'button:Show
workflows']}

![crawl/r_hub](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/14554/crawl_r_hub-aa425f260167.png)
<!-- studio-regress:end -->

---------

Co-authored-by: Daniel Han <[email protected]>
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