← Back to Pull requests

fix(claim): size the memory floor from the fit estimate, KV cache included #1269

Closed
unknown closed this pull request without merging on Nov 24, 2026 10:04 UTC
View on GitHub
unknown unknown commented on Nov 22, 2026 16:44 UTC
Author

Problem

llmfit claim writes # memory: ≥ N Gi (weights + KV/runtime headroom) into the claim header, but for the
model's own quant the floor is only the weights:

// llmfit-core/src/claim.rs (fit_bounds)
// Memory floor: the database's min_vram_gb is authoritative for the
// entry's own quant (it already includes KV/runtime headroom); ...
let memory_gb = if quant == model.quantization {
    model.min_vram_gb.unwrap_or(model.min_ram_gb).max(weights_gb)
} else {
    weights_gb * WEIGHTS_HEADROOM
};

The catalog's min_vram_gb doesn'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-14B at its catalog quant (Q4_K_M), current main:

$ llmfit --json claim Qwen/Qwen3-14B          # memoryGi
9
$ llmfit plan Qwen/Qwen3-14B --quant Q4_K_M --context 8192
Minimum Hardware:
  VRAM: 10.3 GB

So the claim admits a 9 Gi or 10 Gi device, but fit sizes that quant at 10.32 GB (8.57 weights + 1.25 fp16 KV
at 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 plan puts its minimum VRAM at 6.2 GB.

Fix

fit_bounds now computes estimate_memory_gb(quant, min(context_length, DEFAULT_ESTIMATION_CTX)), the same number
fit and plan use, and takes that as a lower bound on both paths. min_vram_gb (entry quant) and
weights × 1.2 (quant override) still apply when they are larger, so a floor only ever goes up. The bandwidth
floor is unchanged. I also corrected the comments that said min_vram_gb already includes KV.

memoryGi before 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

  • New memory_floor_covers_kv_cache_and_runtime_overhead uses a Qwen3-14B-shaped entry (40 layers, 8 KV heads,

  • head_dim 128, min_vram_gb 7.6) and asserts the floor is at least fit's estimate for the entry quant and for a
    --quant Q2_K override. I wrote it first. On unfixed main it fails with
    default quant: claim floor 9 Gi < fit estimate 10.32 GB, and the override half on its own fails with
    Q2_K override: claim floor 7 Gi < fit estimate 7.21 GB. Both pass with the change. (Greptile pointed out that
    my 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_bandwidth asserted the bare-weights floor (17.4 GB → 18 Gi). It now

  • expects 20 Gi (17.4 weights + 1.97 KV from the linear fallback + 0.5). Its bandwidth assertions are unchanged.
  • The other claim tests (golden JSON, entry-DB floor, override headroom, YAML shape) pass unchanged.
  • Local gate (macOS arm64, stable Rust 1.97): cargo fmt --all -- --check is clean, cargo clippy --all-targets --all-features
    shows the same pre-existing warnings as main and nothing new, and cargo test passes
    (1,260 passed, 3 ignored, 0 failed; main is 1,259 passed, so the difference is the new test).

    Out of scope

    The floor is the fit estimate rounded up to whole Gi. It does not add fit's 0.98 Marginal ceiling on top, so a model
    whose estimate lands within 2% under a whole Gi could still be admitted by the claim and graded TooTight by fit. Adding
    that would mean sharing FIT_MARGINAL_MAX_RATIO out of fit.rs, so I kept this change to claim.rs. I'm happy to add it
    if you want the two to match exactly.

    🤖 Generated with Claude Code

    Diff: 528 lines (+396 / -132) across 6 files Reviewer: thejesh23 Review duration: 2480m
    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
    0.53
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52.8% (MEDIUM) · Higher = larger blast radius
    52.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.9% · Safe to merge
    20.9%