Skip to content

Studio: hide safetensors models that exceed VRAM when the fit filter is on - #13945

Merged
Lyxot merged 8 commits into
unslothai:mainfrom
oobabooga:worktree-safetensors-fit-filter
Oct 16, 2026
Merged

Lyxot merged 8 commits into
unslothai:mainfrom
oobabooga:worktree-safetensors-fit-filter

Conversation

@oobabooga

Copy link
Copy Markdown
Member

Problem

With "Only show models that fit" on, the Hub page keeps safetensors models that their own row badge marks as over budget. On a host with 72 GiB of VRAM and 94 GiB of RAM, Safetensors format selected:

Model Row badge main this branch
Qwen2.5-14B-Instruct Likely fits · ~14.7 GB listed listed
Qwen2.5-72B-Instruct Tight fit · ~66.8 GB listed listed
c4ai-command-r-plus-08-2024 Over VRAM budget · ~94.8 GB listed hidden
Mistral-Large-Instruct-2411 Over VRAM budget · ~111.7 GB listed hidden
falcon-180B Over VRAM budget · ~163 GB listed hidden
Llama-3.1-405B-Instruct Over VRAM budget · ~366.7 GB hidden hidden

Cause

hfModelFitsDevice judged safetensors rows with the GGUF rule: 0.4 bytes per parameter (the smallest GGUF quant), plus half of system RAM as offload room. A safetensors chat load goes through transformers, 4-bit by default, and raise_if_offloaded rejects any CPU offload. The badge already uses the 4-bit estimate (estimateLoadingVram + checkVramFit), so the filter and the badge disagreed.

Fix

On a discrete GPU, a safetensors row now gets the badge's verdict against VRAM only, and is kept unless it is "exceeds". GGUF, MLX, Images / Video, catalog-sized rows, and Macs / APUs (hostPooledMemory) keep the existing rule. Downloaded models still always show.

The estimate is still a heuristic. This makes the filter agree with the badge; it does not prove a kept model will load. I did not run a load.

Verification

  • Live A/B on the Hub page, as in the table.
  • New case in tests/fit-on-device-setting.test.ts: fails on main, passes here. The rest of npm test fails the same pre-existing tests as main, apart from one flaky timing test.
  • npm run typecheck and eslint pass.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 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-16T09:32:15.070779Z 34d31d3 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.

@oobabooga

Copy link
Copy Markdown
Member Author

Reached Codex review convergence at oobabooga#379.

@danielhanchen

Copy link
Copy Markdown
Member

Two reds here are specific to this PR rather than main:

  1. Frontend build + bundle sanity: main at ec411c3 is within the eager startup budget with 0.2 KB raw / 0.2 KB transfer to spare, and this branch lands at raw 6632.0 KB > 6632.0 KB. Either load the new fit logic lazily or raise BUDGET in studio/frontend/scripts/check-bundle-budget.ts in this PR with the measured numbers, as its comment asks.
  2. Chat UI Tests (extra): [ui-modelcfg] FAIL: composer could not be focused after the Hub Run settings closed. The same job passes on the other recent branches (nested-conversation-struct-column, r7e-studio-auto-gpu, r7a-core-mixed-nvidia-caps), so worth checking whether hiding over-VRAM models changes what the Hub Run step lands on.

@oobabooga

Copy link
Copy Markdown
Member Author

Reached Codex review convergence again at oobabooga#379 after the bundle budget fix (9c97d0f).

@carlitogwapito

Copy link
Copy Markdown
Contributor

I put together a small test-only commit on top of 9c97d0f, if it's useful here.

All three groups passed against the unchanged pure modules: 36 filter/badge comparisons across GPU sizes, parameter counts and spare RAM; two inferred-parameter cases; and checks that curated sizes and media loads still take their intended paths. No installs or model loads were needed. This doesn't test the Hub UI, full frontend CI, or the physical accuracy of the estimator.

I'd keep the badge/filter agreement check alongside the size examples, and retain separate checks for the explicit exceptions when this predicate changes. From studio/frontend, the file runs with node --experimental-strip-types --test tests/safetensors-fit-contract.test.ts. This is just extra predicate coverage, not a claim to fix the separately reported composer-focus failure.

@Lyxot Lyxot self-assigned this Oct 16, 2026
One CUDA / ROCm card block-swaps decoder layers into host RAM (offload_layers="auto"), so it counts RAM; several cards and XPU stay VRAM only. Prequantized checkpoints fit as stored, or as a bnb 4-bit rebuild for compressed-tensors; fp8 stays fp8 in Studio. Byte sizes use GiB like the device inventory. The picker passes the device count of the inventory a row is judged against.
@Lyxot

Lyxot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Pushed 8056c3e on top of this branch. The filter now sizes a safetensors row by how the chat load actually places it:

  • One CUDA / ROCm card counts host RAM. Since Fit Gemma 4 E2B on 8 GB cards on Windows and in Studio chat #13425, a single-GPU chat load that does not fit VRAM gets offload_layers="auto" and block-swaps decoder layers into host RAM. raise_if_offloaded passes because hf_device_map stays on the GPU. Several cards (unsloth_balanced) and XPU have no such fallback, so they stay VRAM only, as in this PR.
  • Prequantized checkpoints are sized as stored. quantMethod plus the safetensors byte size are used, converted in GiB like the device inventory. Only bnb checkpoints count host RAM. Weight-only compressed-tensors checkpoints can also take the bnb 4-bit rebuild path the loader arms. fp8 stays fp8, because Studio chat never sends the explicit 4-bit request fp8 -> NF4 needs. Previously gpt-oss-120b MXFP4 was estimated at ~107 GB and hidden on an 80 GB card.
  • The picker passes the device count of the inventory a row is judged against.
  • Tests now cover single and multi card, ROCm, XPU, host pool, MLX, Images / Video, GGUF and the prequantized formats.
  • Bundle budget re-measured: the branch adds 602 B raw / 320 B transfer over main, and the limits are raised by that.

Macs / APUs are unchanged (host pool keeps the existing rule).

@Lyxot

Lyxot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

@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: 8056c3e61e

ℹ️ 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".

@Lyxot

Lyxot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 8056c3e61e

ℹ️ 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".

# Conflicts:
#	studio/frontend/scripts/check-bundle-budget.ts
@Lyxot

Lyxot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Merged latest main (2f54e7a). The only conflict was the startup bundle budget: kept main's entry and re-measured this branch against 23bbee09b1 on one machine and build (+602 B raw / +284 B transfer, still 95 chunks), raising the limits by that growth.

@Lyxot

Lyxot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

@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: 2f54e7a91d

ℹ️ 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".

A prequantized row with no safetensors byte size fell back to the 0.9 B/param bnb estimate, hiding packed checkpoints the filter kept before.
@Lyxot

Lyxot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

@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: ee242dd750

ℹ️ 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".

@Lyxot

Lyxot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

@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: ee242dd750

ℹ️ 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".

@Lyxot

Lyxot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

@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: ee242dd750

ℹ️ 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".

Studio's Default engine runs no compressed-tensors checkpoint (it offers vLLM / SGLang, which place the stored weights), so crediting a bnb 4-bit rebuild for it kept rows that do not fit. Only a bitsandbytes checkpoint counts host RAM.
@Lyxot

Lyxot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

@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: 34d31d32d3

ℹ️ 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".

@Lyxot

Lyxot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 34d31d32d3

ℹ️ 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".

@Lyxot

Lyxot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Review loop done on 34d31d32d3.

What changed during this round:

  • 8056c3e61e sizes safetensors rows by how the chat load places them. One CUDA / ROCm card counts host RAM, because a single-GPU load that does not fit block-swaps layers into it (offload_layers="auto", Fit Gemma 4 E2B on 8 GB cards on Windows and in Studio chat #13425). Several cards and XPU stay VRAM only. Byte sizes are in GiB. The picker passes the device count of the inventory a row is judged against.
  • 2f54e7a91d merges main. The only conflict was the bundle budget: main's entry is kept, and this branch is re-measured against 23bbee09b1.
  • ee242dd750: a prequantized row with no safetensors byte size is sized as the smallest quant, not the bnb estimate.
  • 34d31d32d3: every prequantized row is sized as stored, and only bitsandbytes counts host RAM. Studio's Default engine rebuilds no compressed-tensors / fp8 checkpoint as bnb: compressed-tensors goes to vLLM / SGLang, and fp8 -> NF4 needs an explicit 4-bit request Studio never sends.
  • Net bundle growth over main: +497 B raw / +184 B transfer; the limits are raised by that.

Codex findings answered without a change, with reasons in their threads: the UNSLOTH_FP8_TO_NF4 override; GPTQ / AWQ recognised only by name (vLLM-only rows); FP8 rows with total but no dtype map (the Hub never returns that shape); and legacy compressed_tensors / sparseml spellings (no compressed_tensors package in the Default engine).

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Codex converged and CI passes on 34d31d3.

@Lyxot
Lyxot merged commit 6c555fa into unslothai:main Oct 16, 2026
danielhanchen added a commit that referenced this pull request Oct 16, 2026
…13991)

## Summary

`Frontend build + bundle sanity` is red on main again. #13969 merged
with it red, and its run reported `over the startup budget: transfer
1995.0 KB > 1994.7 KB, raw 6633.8 KB > 6632.7 KB`. Main at 6106de9
measures 6,796,799 B raw / 2,044,202 B transfer, against limits of
6,792,425 / 2,042,777.

Measured commit by commit (one machine and build, Node 24, 95 chunks
throughout, `rm -rf dist` before each build):

| commit | raw B | transfer B |
|---|---|---|
| 1790106 (#13983, last raise from me) | 6,791,768 | 2,042,404 |
| 7d33eff (#13965) | 6,792,034 | 2,042,515 |
| cc0cb59 (#13966) | 6,792,447 | 2,042,693 |
| 7bee02d (#13969) | 6,793,737 | 2,043,138 |
| ce83dee (#13973) | 6,796,298 | 2,044,201 |
| 6106de9 (main, after #13974, #13972, #13951, #13945) | 6,796,799 |
2,044,202 |

The two largest steps:
- Inline chat markdown tables with hover controls and the expand dialog
(#13973): +2,561 B raw / +1,063 B transfer, in the eager chat chunk.
- Latest Unsloth Models ranking (#13969): +1,290 B raw / +445 B
transfer.

#13945 already raised the budget for its own 497 B.

## Change

The budget is set to the measured build plus the margin main had at
1790106 (160 B raw, 189 B transfer), with the per-commit numbers
recorded beside the limits as in the earlier raises. If #13973's expand
dialog should be lazy-loaded instead, that is a follow-up for its owner.
This only gets main and every open PR off a red that none of them
caused.

## Testing

- `npm run build && npm run bundle:check` on main with this change:
within budget (0.2 KB transfer, 0.2 KB raw to spare). Without it: over
by 4,374 B raw / 1,425 B transfer.
- `tests/bundle-budget-cli.test.ts` and
`tests/bundle-budget-closure.test.ts`: 43 passed.
- `prettier --check scripts/check-bundle-budget.ts`: clean.
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