fix(claim): size the memory floor from the fit estimate, KV cache included #1269
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.53) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.53 · 528 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.375
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #1269"
general
weight: 0.35
thejesh23
Problem
llmfit claimwrites# memory: ≥ N Gi (weights + KV/runtime headroom)into the claim header, but for themodel's own quant the floor is only the weights:
The catalog's
min_vram_gbdoesn't include KV. It's the scraper's weights-only figure (params × 0.5 B × 1.1,per AGENTS.md), and at 0.58 bpp it is smaller than
weights_gb, so the floor ends up as the bare weights.The kube-scheduler then places the model on devices that
llmfit's own fit/plan reject.Concrete case,
Qwen/Qwen3-14Bat its catalog quant (Q4_K_M), currentmain:So the claim admits a 9 Gi or 10 Gi device, but
fitsizes that quant at 10.32 GB (8.57 weights + 1.25 fp16 KVat the 8,192-token estimation context + 0.5 runtime overhead) and grades a 10 GB card TooTight. The same happens
on every default-quant claim, e.g. Llama-3.1-8B-Instruct gets 5 Gi while
planputs its minimum VRAM at 6.2 GB.Fix
fit_boundsnow computesestimate_memory_gb(quant, min(context_length, DEFAULT_ESTIMATION_CTX)), the same numberfitandplanuse, and takes that as a lower bound on both paths.min_vram_gb(entry quant) andweights × 1.2(quant override) still apply when they are larger, so a floor only ever goes up. The bandwidthfloor is unchanged. I also corrected the comments that said
min_vram_gbalready includes KV.memoryGibefore and after, from the real CLI (bandwidth identical in every row):| Model | Quant | main | this PR |
|---|---|---|---|
| Qwen/Qwen3-14B | Q4_K_M (entry) | 9 | 11 |
| meta-llama/Llama-3.1-8B-Instruct | Q4_K_M (entry) | 5 | 7 |
| Qwen/Qwen2.5-7B-Instruct | Q4_K_M (entry) | 5 | 6 |
| Qwen/Qwen3-30B-A3B | Q4_K_M (entry) | 18 | 19 |
| openai/gpt-oss-20b | entry | 13 | 14 |
| Qwen/Qwen3-14B |
--quant Q2_K| 7 | 8 || Qwen/Qwen3-14B |
--quant Q6_K/Q8_0| 15 / 19 | 15 / 19 (1.2× headroom already covered it) || Qwen/Qwen3-30B-A3B |
--quant Q2_K/Q6_K/Q8_0| 14 / 30 / 39 | unchanged |Tests
memory_floor_covers_kv_cache_and_runtime_overheaduses a Qwen3-14B-shaped entry (40 layers, 8 KV heads,head_dim 128,
min_vram_gb7.6) and asserts the floor is at leastfit's estimate for the entry quant and for a--quant Q2_Koverride. I wrote it first. On unfixedmainit fails withdefault quant: claim floor 9 Gi < fit estimate 10.32 GB, and the override half on its own fails withQ2_K override: claim floor 7 Gi < fit estimate 7.21 GB. Both pass with the change. (Greptile pointed out thatmy first version used Q5_K_M for the override, which the 1.2× headroom already covered; switched to Q2_K.)
bounds_use_active_parameters_for_moe_bandwidthasserted the bare-weights floor (17.4 GB → 18 Gi). It nowexpects 20 Gi (17.4 weights + 1.97 KV from the linear fallback + 0.5). Its bandwidth assertions are unchanged.
Local gate (macOS arm64, stable Rust 1.97):
cargo fmt --all -- --checkis clean,cargo clippy --all-targets --all-featuresshows the same pre-existing warnings as
mainand nothing new, andcargo testpasses(1,260 passed, 3 ignored, 0 failed;
mainis 1,259 passed, so the difference is the new test).Out of scope
The floor is the
fitestimate rounded up to whole Gi. It does not addfit's 0.98 Marginal ceiling on top, so a modelwhose estimate lands within 2% under a whole Gi could still be admitted by the claim and graded TooTight by
fit. Addingthat would mean sharing
FIT_MARGINAL_MAX_RATIOout offit.rs, so I kept this change toclaim.rs. I'm happy to add itif you want the two to match exactly.
🤖 Generated with Claude Code