Repository navigation
Studio: price per-layer embedding and Engram lookup tables as host or disk memory, not VRAM - #14465
Conversation
… disk memory - deepseek41 joins the lazily read tables (shared table in core/inference/lookup_tables.py) - offload layout: per_layer_token_embd is its own bucket, the tied rule duplicates token_embd only - planner: a streamed table is not host RAM for the --load-mode none decision - Metal: a lazily read table leaves the unified-memory charge even when llama-fit-params fails - discrete GPUs: host-pinned input embeddings leave the VRAM charge - lazy mode as a managed choice: --lazy-mode off only when RAM holds the table, user choice wins
…oad panel - lookup_table_bytes per GGUF variant (local header scan, bounded Hub range reads for lazily reading archs) - fit badge and quant picker: a 'Fits (lookup tables streamed from disk)' tier, table on its own tooltip line - load panel estimate: Lookup tables as their own line, out of the GPU share and of the total when streamed
- every retry and the CPU fallback hand a resident table back to llama.cpp's auto - the resident table is charged once in the load-mode fit - no managed --lazy-mode off when an -ot may put the table on a device - Metal: adapter guard, unsized KV proves nothing, a user's off takes the table out of the probe discount - load panel: streamed only on a build with a lazy mode, a resident table moved to the GPU stays in the GPU share - listing: no blocking Hub architecture lookup, in-flight reads deduplicated, local answers kept on a Hub failure, shard reads capped - default quant pick prices streamed tables like the recommendation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[skip ci] (cherry picked from commit a01a6d1)
…ice list CUDA/HIP picks are visibility masks and the host preflight passes the GPU inventory, so both follow llama.cpp's default enumeration again. An explicit gpu_ids pick now reaches the fit's lazy decisions before any narrowing. [skip ci] (cherry picked from commit d641527)
…arch retry Split mode none keeps only the main device of an explicit list, so only that device counts. The APU guard reads the child's own device flags and env, and the arch-crash retry prices RAM after its mask and split rewrites, with RAM still read before the kill. [skip ci] (cherry picked from commit 98362e7)
…Us, one RAM snapshot Tensor mode with no device list builds its Meta device from every visible GPU, iGPUs included, and it maps only if every member does. A --device list can name a Vulkan iGPU the automatic filter dropped, so its classification is kept for the lazy check. The opt-out oversized readings reuse their preflights' RAM. (cherry picked from commit 789957dfb6fa2b018f5a39a0136b5502826bd709)
…them The listing and the Load Model estimate subtracted the lazily read table on every host, but llama.cpp resolves --lazy-mode auto to off when a model device lacks mmap support (integrated Vulkan / CUDA, ROCm APUs), so the table is resident there. Both now ask the backend whether a default launch streams. A cold repo architecture is awaited within the listing's deadline when a row is big enough to hold a streamed table, so the first listing is priced. The APU carve-out estimate keeps a table an -ot moves onto the device. [skip ci]
The GPU fit leaves token_embd and resident lookup tables on the host, so the load-mode fit now charges them to host RAM alone instead of to a pool free VRAM can pay for. The estimate resolves lazy auto against the pinned cards and an explicit --lazy-mode on prices every flagged table, and remote table answers expire, since the listed size is not content identity. [skip ci]
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…ting reads are bounded per repo The Load Model estimate now prices a resident per-layer table (gemma3n's, or one under the lazy threshold) as a host-pinned input, off the GPU share but in the total. One listing submits at most a pool's worth of Hub header reads, and a cached non-lazy variant no longer rules out lookup reads for the rest of a mixed repo. [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f31cd7f60c
ℹ️ 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".
| _host_input_embd = 0 | ||
| if ( | ||
| gpus | ||
| and not _integrated_gpus |
There was a problem hiding this comment.
Discount host inputs for pure-discrete subsets on mixed hosts
On a mixed integrated/discrete CUDA or ROCm host, this global not _integrated_gpus gate leaves _host_input_embd at zero even when the later tiered placement selects only discrete cards. The per-layer table and untied input embedding remain CPU-resident for that pure-discrete launch, but model_size_fit charges them to VRAM; for Flash-Next or DeepSeek this can add tens of GiB and unnecessarily force CPU offload or a much smaller context. Compute this discount per candidate subset, as is already done for the host-only projector, rather than disabling it because an unused integrated device was detected.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving this as is in this PR. On a host that reports an integrated GPU next to a discrete one, the discount is off, which charges the input tables to VRAM exactly as main does today, so a pure-discrete subset there gets main's placement, not a worse one. Pricing it per candidate subset means threading the discount through the tiered placement (the projector's _discrete_host_only path plus the APU and integrated-CUDA gates, which today are host-wide), which is a larger change than this fix and is better done with a real mixed host to check it on.
There was a problem hiding this comment.
Keeping this as is for this PR. On a mixed integrated/discrete host the discount stays off, which charges the input tables to VRAM exactly as main does today, so it can only cost context there, never an over-commit. Pricing it per candidate subset means threading the discount through every tier the placement walks (the host-only projector path does this for one term); that is a follow-up rather than part of this fix.
load_model drops an inherited non-layer LLAMA_ARG_SPLIT_MODE (and its tensor split) before spawn, but the lookup-table previews read the raw env, so an inherited split mode none with a negative main GPU priced a GPU child as a CPU one. Factor the scrub into _reconcile_split_mode_env and apply it to spawn and every preview (host inputs, fitter shortfall, load-mode fit, APU guard, Metal discount, listings, estimate route). _child_runs_on_cpu now takes the launch's tensor_parallel, which every launch and estimate site forwards, and the listing CPU-child guard uses it, so an explicit --split-mode none --main-gpu -1 streams beside an empty GPU inventory. [skip ci]
The fitter, load-mode fit and APU RAM guard ask whether llama.cpp turns lazy auto off before load_model pins the child, so they read a compact --device ROCm0 / CUDA0 through the parent's numbering and the ascending gpu_indices. With auto pinning an APU at physical 1 beside a discrete card, ROCm0 resolved to the discrete card: the table was discounted, the fit emitted --load-mode none and the APU RAM warning was lost. With gpu_ids [1, 0] and --split-mode none, the main device was read as Vulkan0 while the child runs on Vulkan1. _planned_child_gpu_order returns the picker order and the visibility mask order the spawn emits (picker reorder factored into _picker_ordered_gpu_indices and shared with the spawn), and _lazy_auto_resolves_off maps compact ordinals through that mask. The estimate route's resident proof classified shared-memory GPUs by total <= 0 on every backend. It now uses the launch's classification, factored into _unified_pool_gpu_ids: total 0 only on Vulkan, plus ROCm APUs and integrated CUDA SoCs. [skip ci]
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts [skip ci]
|
pre-commit.ci run |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
1 similar comment
|
@codex review |
|
pre-commit.ci run |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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/backend/core/inference/llama_cpp.py # studio/backend/routes/inference.py # studio/frontend/src/features/chat/types/api.ts # studio/frontend/src/features/hub/catalog/local-on-device-card.tsx # studio/frontend/src/features/hub/inventory/api.ts # studio/frontend/src/features/model-picker/components/memory-estimate-row.tsx # studio/frontend/src/features/model-picker/components/model-selector/model-catalog.ts # studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx # studio/frontend/src/hooks/use-model-memory.ts [skip ci]
# Conflicts: # studio/backend/core/inference/llama_cpp.py
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Conflict: studio/frontend/scripts/check-bundle-budget.ts (unslothai#14465 lookup-table pricing budget bump). Budget = main's numbers plus the Desktop apps growth (+2,495 B transfer, +8,089 B raw).
Brings in the DSpark/DFlash sidecar --fit-target reserve and Metal OOM recovery (#14431) and the lookup-table host/disk pricing (#14465). - Layout: per_layer_embd_bytes is its own bucket beside token_embd_bytes (main's semantics); the planner's host side adds both and subtracts the lazily read share. - Lazy mode: main's resident-table --lazy-mode off takes precedence; when it is emitted the planner's own -lzm is skipped and the plan prices the table resident. With no -lzm of its own the seam prices the fit's lazy_read_bytes; an emitted -lzm still decides. - Speculative flags: the rebuilt _spec_slice sizes the sidecar per placement argv (main's _sidecar_fit_sized) and keeps the Vulkan draft backend-sampling flag. - Retries revoke the spill plan and drop the managed lazy mode; the spawn keeps both _fit_on_recovered and _sidecar_fit_reserve_mib. [skip ci]
Conflicts kept both sides: the host-pinned discount, tied output and per-candidate discounts beside main's input-embedding pricing (unslothai#14465), discrete tier (unslothai#14372, unslothai#14615), restructured drafter and Auto probes, and the arch-crash retry that now reads memory before the kill. main's input-embedding discount takes only what the host-pinned discount does not already cover. Non-Vulkan APUs and integrated CUDA move from _shared_gpu_ids to _unclassified_gpu_ids, so the discount still waits on them while main's ranking and host-pool checks keep the Vulkan iGPU set.
What users saw
Models with a large lookup-only embedding table (DeepSeek-V4.1 Engram, Qwen3.8-Flash-Next and Gemma 4 per-layer embeddings, gemma-3n PLE) were priced as if the whole table had to sit in VRAM or pinned RAM:
llama-fit-paramsprobe failed, the whole Engram (or Flash-Next) table was charged to unified memory and the context was cut to the minimum.--fit onfallback.Root causes
_LAZY_READ_TENSORSlisted onlygemma4andqwen4exp;deepseek41flags its Engram tableTENSOR_READ_LAZYtoo.offload_layout.pymatched"token_embd" in name, which also swallowedper_layer_token_embd. A tied file (gemma-3n) then moved the per-layer table into the VRAM bucket with the duplicated output head.--load-mode noneto spilled experts.llama-fit-paramsprobe succeeded.Fixes
core/inference/lookup_tables.py: one table of lazily read tensors (gemma4,qwen4exp,deepseek41) and the 4 GiBautothreshold, shared by the launch fit, the layout and the model listing.per_layer_embd_bytesis its own bucket; the tied rule duplicatestoken_embdonly. The Metal probe discount and the unified-memory full-offload check sum both buckets.PlanOptions.lazy_read_byteskeeps the streamed table out ofhost_bytes; a resident table (iGPU/APU,-lzm off) is still charged.autoon. An-otmoving the table onto the GPU keeps it charged.output.weight, every per-layer table) leavemodel_size_fit, unless an-otmay place them on a device (DeepSeek-V4.1's loader forces its table back to the host, so it always counts). Shared pools (iGPU, APU, Apple) keep the old charge. The fitter shortfall no longer subtracts the lazy table twice.--lazy-mode, the file has a lazily read table and llama.cpp would stream it, Studio emits--lazy-mode offonly if the whole load still fits with the table in RAM (weights, KV, prompt cache, a 10% margin, the same fit the load-mode decision uses; on Apple, the Metal budget and free RAM). Otherwise llama.cpp'sautostays. Never on a GPU: an-otthat could move the table onto a device keeps it streamed. A user's-lzm/--lazy-mode(or the env twin, either spelling) always wins, iGPU/APU children are left to llama.cpp, and the decision is logged once. Every retry (no-flash,--fit on, device or architecture fallback, CPU fallback) hands the table back toauto, since the residency proof was for the first placement. Resident is the fast mode where it fits: on Qwen3.8-Flash-Next prefill is stable at ~3150 t/s against 140 to 3158 t/s streamed, and server throughput is 1.6 to 2x.lookup_table_bytesper GGUF variant. Local copies are read from their own headers (cached by file identity). Hub-only quants of an architecture that reads its table lazily are sized from HTTP range reads of the GGUF header, at most 8 shards, with one 2 s deadline per listing; a read already running when the deadline passes lands in a cache for the next listing, and an unstarted one is dropped. A cold repository architecture is waited on within the same deadline only when a row is large enough to hold a streamed table (any row under a forced--lazy-mode on); a late answer is cached. Any failure leaves 0, which is today's pricing.UNSLOTH_LOOKUP_TABLE_REMOTE=0turns the Hub reads off.-lzm off) and leaves a streamed table out of the GPU and total figures; on a build without a lazy mode the table stays priced as resident.Tests
Real header sizes: DeepSeek-V4.1 UD-IQ1_S 216.98 GiB (Engram 103.00 GiB), Qwen3.8-Flash-Next UD-Q2_K_XL 73.45 GiB (PLE 26.82 GiB), gemma-3n-E4B Q4_K_M 4.23 GiB (PLE 1.64 GiB, token_embd 0.28 GiB, tied).
Backend,
studio/backend/tests/test_lookup_table_fit.pyandtest_lookup_table_pricing.py: 53 tests, 46 fail on main (the 7 that pass on main are guards: lazyoffand an iGPUautostay 0, a failure leaves the listing unchanged, and similar).autoandon, not underoffor an iGPUauto.--load-mode nonewith the table streamed, not with it resident.-othandling (first match wins, DeepSeek-V4.1 forced host).-otmoving the table to the GPU keeps the old fallback.--lazy-mode off; on 24 GB + 64 GB it streams; DSV4.1 on 24 GB + 64 GB streams; user-lzmandLLAMA_ARG_LAZY_MODEwin; iGPU and builds without the flag get nothing; the pre-rename spelling is used on older builds; logged once.-lzm offtakes the table back out of a probe discount measured underauto; gemma-3n gets no static discount.--lazy-mode off; the resident table is charged once in the load-mode fit (this test fails if it is charged twice); an-otonto the GPU keeps the table streamed.-lzm offkeeps it in the total but off the GPU, a build without a lazy mode keeps it resident, a resident table moved to the GPU with-otstays in the GPU share.Frontend,
studio/frontend/tests/gguf-fit-lookup-tables.test.ts(7 tests, the file fails on main): Flash-Next UD-Q2_K_XL on a 24 GB GPU + 64 GB RAM goes from "oom" to "streamed" and counts as runnable; DSV4.1 UD-IQ1_S stays "oom" there; gemma-3n on 8 GB / 16 GB keeps its verdict; a table that does not change the verdict leaves it alone; a streamed quant is recommended over the OOM fallback but ranks below a quant that fits resident; a bare repo click picks the streamed quant.hub-row-selection.test.tsaccepts the new classifier. Full frontend suite: 13090 passed, 0 failed (npm test); after the last commit the 68 test files that touch the fit, picker, catalog, download card and estimate code: 994 passed, 0 failed.npm run typecheckclean.Related backend suites (186 files: placement, fit, Metal, load mode, offload planner, memory, GGUF, KV, spill, context), main vs this branch:
The 31 failures are the same tests on both sides and unrelated (diffusion offload precision, training layer offload, the low-VRAM H3 stream, GGUF TTS audio type, a system poll probe). Two timing-sensitive tests (
test_gguf_admission_token_countstream cancel,test_system_poll_no_cuda_contextprobe) pass and fail on both sides across reruns on a loaded host.Known limits
--lazy-modewould be under-charged by the Engram table. The Studio prebuilt that ships DeepSeek-V4.1 support has both.-lzm/--lazy-modein the extra arguments overrides the managed choice.UI before / after
Model Hub quant list for
unsloth/Qwen3.8-Flash-Next-GGUF, based6cb541b6(left) vs this branchb4140ec1c(right), two separate installs. Both sides were shown the same simulated host (24 GB GPU, 64 GB RAM) and ran withLLAMA_ARG_LAZY_MODE=on. Before, every quant is marked "Does not fit". After, UD-IQ1_S moves to the streamed tier, and the tooltip carries the new line "Lookup tables: 28.8 GB, kept in RAM when it fits". The listing now reports 26.82 GiB of lookup tables for UD-Q2_K_XL. That quant still reads "Does not fit" here because the badge sizes it by its full 84 GB download, which includes the companion files.