Repository navigation
Studio: use the VRAM a small card has left when Auto offloads Inkling 2 (DSpark draft counted once, budget-sized fit margin) - #18800
Conversation
…lots The inkling2_loop layout keeps each physical layer once and lets llama.cpp expand the looped core to one cache slot per visit. Read loop.start, loop.end and loop.count, expand block_count and the per-layer arrays to those slots, and give the layout the same relative-bias compute estimate as inkling2, so both GGUF layouts of one model get the same KV and compute estimates.
llama.cpp counts -ngl, -ts and --n-cpu-moe for looped models in physical layers (llama_model_n_layer_weights), 24 for Inkling-2-Mini on both GGUF layouts, while KV and recurrent state stay per cache slot (48). - llama_cpp: read the visit-indexed loop keys (loop.core_start/core_end, num_loops) and keep a separate _n_weight_layers; n_layers, n_moe_layers, the pipeline-parallel predicate and the output-row device use it, KV sizing keeps the slots. - gguf_metadata: the staged layer_count drops the repeat passes of a visit-indexed loop core, so the gpu-layers ceiling is 24. - routes: runtime layer_count follows the physical layers. - offload_layout: looped layouts list the physical layers as rows, record the physical row of each cache slot and price KV per slot from per-layer head counts; the per-device split and the tensor spill fold slot caches onto their rows. Non-looped architectures, including inkling2 without loop keys, are unchanged.
…s to a small card An Auto load that does not fit hands placement to llama.cpp's fitter (--fit on), which keeps its own 1024 MiB default free on every card. Studio's budget keeps max(3% of the card, 512 MiB), and Manual + Auto layers already passes that 512 MiB floor. On an 8 GB card the default leaves an extra 512 MiB idle, so the fitter keeps one to three more MoE layers in host RAM (Inkling-2-Mini UD-IQ1_S: 8 instead of 6 of 24 expert layers on the CPU). Auto now trims the fitter margin to the card's budget reserve wherever that is smaller, so 8 to 16 GB cards keep 512 MiB and a 24 GB card 3%. The margin never rises: cards over about 34 GB keep 1024 MiB and an unchanged command. Windows CUDA keeps the default, since WDDM spills an overrun to host RAM there instead of failing; integrated and shared-pool devices are left alone too. A multi-card broadcast keeps the largest card's margin.
…draft With a DSpark or DFlash sidecar under --fit on, Studio adds the draft's reserve to --fit-target unless the llama.cpp build's fitter measures borrowed-tensor drafts itself. It looked for a trace string from the first version of that fitter, in libllama-common.so.0. The prebuilds Studio ships (b12588, and b12602 next) measure every borrowed draft up front in common_fit_draft_target, which logs nothing of its own, and their common library is libllama-common.so.1. Neither was recognised, so the draft was counted twice: the fitter charged its 1230 MiB and Studio kept another 1.36 GB free. Inkling-2-Mini with its DSpark sidecar (Auto's default for unsloth/Inkling-2-Mini-GGUF), on a dedicated T4 capped to 8 GB: UD-Q4_K_XL kept 23 of 24 expert layers in host RAM with 2.4 GB of VRAM idle (19 of 24 after this change, decode 6.4 -> 6.9 tok/s); UD-Q2_K_XL decoded 21.2 -> 25.3 tok/s and UD-IQ1_S 23.6 -> 25.2. At 12 GB UD-Q4_K_XL went 22.9 -> 25.5. The detection now also takes the common_fit_draft_target symbol and follows libllama-common.so.1 (and .1.dylib). A build that strips the symbol still fails closed and keeps the reserve.
|
@codex review |
Codex Review Summary: ✅ CompletedThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5a6cffbff1
ℹ️ 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".
| 0.0 | ||
| if _idx in _integrated_gpus or _idx in _shared_pool_gpus | ||
| # Free stands in for an unreported total, as for the slider. | ||
| else _auto_fit_target_trim_mib( | ||
| total_by_idx.get(_idx) or _free, _vram_frac |
There was a problem hiding this comment.
Detect integrated GPUs independently of multi-GPU tiering
On a single integrated CUDA GPU with a positive reported total, such as a 16 GiB Jetson, this guard does not exclude the shared-memory device: _integrated_gpus is populated only inside if not gpu_ids and not is_vulkan_backend and len(gpus) > 1, and _shared_pool_gpus contains only devices reporting a nonpositive total. Explicitly selecting an integrated CUDA GPU also bypasses that classification. Consequently, an offloaded Auto load now reduces its fitter margin from 1024 to 512 MiB and permits additional consumption of shared host RAM, despite the intended integrated-GPU exclusion. Classify integrated devices independently of the discrete-first subset planner before applying this trim.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in d9940f7. The trim now checks for host-RAM-backed devices directly instead of relying on the planner's multi-GPU classification: any ROCm unified-memory APU, any integrated CUDA device (the answer the CUDA memory probe already settled for this mask, so a Vulkan load does not initialise CUDA), or a Vulkan iGPU among the picked cards keeps today's margin. Ids are not joined to rows here, so an integrated device anywhere on the host turns the trim off. New tests: a lone 16 GB integrated CUDA GPU and a lone ROCm APU, and an explicitly picked integrated card, all keep the default margin.
| _trimmed_by_idx[i] != _base_delta_by_idx[i] for i in _trimmed_by_idx | ||
| ): | ||
| # A single broadcast value must hold every card's margin. | ||
| _fit_target_delta_mib = max(_trimmed_by_idx.values()) |
There was a problem hiding this comment.
Emit per-device margins when the broadcast delta is zero
For an offloaded Auto load spanning an 8 GiB and a 48 GiB CUDA card with provable per-device ordering, the computed deltas are approximately {0: -512, 1: 0}, so this assignment leaves the broadcast delta at zero. _ctx_integrity_flags then omits --fit-target because the scalar margin equals the default; the launch code consequently leaves _fit_target_margins_by_idx unset, and _per_device_fit_target_argv cannot add a missing flag either. The smaller card therefore retains the full 1024 MiB margin instead of receiving the intended 512 MiB trim. Ensure a nondefault per-device margin causes the flag to be emitted even when the broadcast margin remains the default.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in d9940f7. _ctx_integrity_flags now takes the per-card deltas and emits --fit-target whenever they differ, even when the broadcast value restates llama.cpp's default, so _per_device_fit_target_argv has a flag to spell per device. All five call sites pass the same map, so the sidecar-margin cleanup still matches. Equal per-card deltas keep the default unspelled as before. New test: an 8 GB card beside a 48 GB one under PCI_BUS_ID gets --fit-target 512,1024.
…er-card margins when the broadcast one is the default A lone Jetson, AMD APU or picked iGPU never reached the multi-GPU planner's integrated classification, so its fitter margin was trimmed. Check those devices directly (a settled CUDA answer only on Vulkan, so no CUDA init). An 8 GB card beside a 48 GB one left the broadcast margin at llama.cpp's default, so --fit-target was never emitted and the small card's trim was lost. Differing per-card deltas now always emit the flag.
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |
…p dunders spreading the decode-rewrap scan (#18815) ## Problem `(Python 3.13, diffusion)` fails on `main` and on every PR based on it (for example #18806) with two failures: ``` test_diffusion_family_data_freeze.py::test_family_data_resolves_identically AssertionError: tables test_diffusion_vae_oom.py::test_every_decode_rewrap_site_restores_the_oom_scope 510 sites flagged, first ('diffusion.py', 'DiffusionBackend.__init__') ``` Both reproduce locally on `main` (`d8ff4de6a1`). Running both tests on each Studio inference commit since the last green `main` attributes them: | commit | freeze | decode rewrap | |---|---|---| | `8d41610c50` (#18800) | pass | pass | | `d66aa77cee` (#18779) | fail | pass | | `6f4c2a7bd9` (#18780) | fail | fail | ## Causes **Family data freeze (#18779).** #18779 adds the dense FastWan students as trusted video repos. The frozen table was not regenerated, so the only difference is two new `trusted_video_repos` entries, `fastvideo/fastwan2.1-t2v-1.3b-diffusers` and `fastvideo/fastwan2.2-ti2v-5b-fullattn-diffusers`. The PR is right; the fixture is behind. **Decode-rewrap scan (#18780).** The test seeds every function that assigns `.decode`, then marks any function that calls one of those *by bare name* as a rewrap helper too, to a fixpoint. #18780's opt-in draft decode is a context manager, `TinyVaeDraftDecode`, which swaps `vae.decode` in `__enter__` and restores it in `__exit__`. That made `__enter__` and `__exit__` seeds, and a bare-name match on `__exit__` / `__enter__` reaches every function that drives any context manager by hand, so the fixpoint spread to 510 functions. The draft swap itself is scoped and restores the previous `decode` on exit, and its fallback calls the decode it replaced, so the OOM scope is intact. The PR is right; the scan's name matching is too loose for dunders. ## Fix Test-only: - `tests/fixtures/diffusion_family_data_freeze.json`: regenerated with `UNSLOTH_FREEZE_UPDATE=1`. The diff is exactly the two FastWan repos (2 lines added). - `test_every_decode_rewrap_site_restores_the_oom_scope`: dunder method names are not propagated by name. A dunder is reached through `with` or an object protocol, never by a call to that name, so matching it by name cannot identify a caller. Named helpers such as `install_untiled_decode` still propagate as before. ## Verification - `test_diffusion_family_data_freeze.py`, `test_diffusion_vae_oom.py`, `test_video_tiny_vae.py`, `test_video_tiny_vae_wiring.py`: 134 passed, 5 skipped. - Sabotage: adding `def _sabotage_leak(vae): install_untiled_decode(vae)` to `video.py` fails the rewrap test with `[('video.py', '_sabotage_leak')]`, so a real unguarded rewrap is still caught. Restored afterwards. - The freeze fails on `main` without the regenerated fixture, as on CI.
On 8 GB and 12 GB cards, Inkling-2-Mini in Studio left 1.5 to 2.5 GB of VRAM idle and kept expert layers in host RAM. There were two causes, and both are fixed here.
Changes
common_fit_draft_target. Studio detected that by greppinglibllama-commonfor a trace string that only the first fork version logged, and it only looked atlibllama-common.so.0while the prebuilds ship.so.1. So Studio reserved the draft (about 1.36 GB) on top of the fitter's own charge. Detection now also accepts thecommon_fit_draft_targetsymbol and the.so.1/.1.dylibnames. A build without either marker keeps the old reserve, so older binaries are unchanged.--fit on, Studio passed llama.cpp's default 1024 MiB margin, while its own budget keeps max(3%, 512 MiB). The margin now drops to the card's budget reserve when that is smaller. It never goes up, so cards over about 34 GB get the same command as before. Integrated GPUs, shared pools, Windows WDDM spill risk and Manual with an explicit-nglare left alone. With several cards, the per-device form is used when the binary supports it, otherwise the largest per-card margin.The default load of
unsloth/Inkling-2-Mini-GGUF(Auto, speculativeautopicks the DSpark sidecar) hits both.Results
Dedicated Colab T4, VRAM capped to 8 or 12 GB, shipped b12588 prebuilt, Studio's own command line, base and head alternating launch by launch (repeat spread about 2%). Decode tok/s:
A hand-tuned
--fit-target 256is at most one layer better than head. On 12 GB and 16 GB, UD-IQ1_S and UD-Q2_K_XL already fit fully on the GPU and their commands do not change. Auto context was already 90 to 100% of the largest-cthat loads, so the context choice itself is not changed.Tests
tests/test_auto_fit_target_trim.py(new, 60 cases) andtests/test_fit_measures_shipped_drafts.py(new, 6 cases) pass on head; on base 56 and 4 of them fail, the rest are no-regression guards (large cards, integrated GPUs, Manual mode, old binaries).test_spec_sidecar_fit_reserve.pyandtest_spec_sidecar_fit_reserve_multi_gpu.pyhard-code the 1024 MiB margin, so their fixtures turn the trim off.Not covered