From a40371d532f9bae0fe42bcea5847de88829ee659 Mon Sep 17 00:00:00 2001 From: pewdiepie-archdaemon Date: Sat, 27 Jun 2026 20:52:31 +0000 Subject: [PATCH] Clamp unified llama context estimate --- static/js/cookbookServe.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/static/js/cookbookServe.js b/static/js/cookbookServe.js index deb6ea7a5..8b41fcb54 100644 --- a/static/js/cookbookServe.js +++ b/static/js/cookbookServe.js @@ -513,12 +513,29 @@ function _estimateLlamaContextFit(model, fields, modelCtxMax, modelWeightsGb = 0 } const raw = Math.floor(freeForKv / kvGbPerToken); const rounded = Math.max(1024, Math.floor(raw / 1024) * 1024); - const ctx = Math.min(modelMax, rounded); + let ctx = Math.min(modelMax, rounded); + let reasonSuffix = ''; + if (isUnifiedMode) { + // Unified memory should not advertise *less* context than plain GPU mode + // for the same llama.cpp launch. It may be slower when pages spill into + // system RAM, but the memory pool is at least the GPU path plus overflow. + const gpuUsableGb = Math.max(1, totalVramGb - Math.max(1.0, selectedCount * 0.6)); + const gpuFreeForKv = gpuUsableGb - modelGb; + if (gpuFreeForKv > 0) { + const gpuRaw = Math.floor(gpuFreeForKv / kvGbPerToken); + const gpuRounded = Math.max(1024, Math.floor(gpuRaw / 1024) * 1024); + const gpuCtx = Math.min(modelMax, gpuRounded); + if (gpuCtx > ctx) { + ctx = gpuCtx; + reasonSuffix = `; floored to GPU estimate`; + } + } + } return { ctx, modelGb, kvGbPerToken, - reason: `~${ctx.toLocaleString()} tokens fits llama.cpp KV (${freeForKv.toFixed(1)}G free ${isUnifiedMode ? 'unified' : 'VRAM'})`, + reason: `~${ctx.toLocaleString()} tokens fits llama.cpp KV (${freeForKv.toFixed(1)}G free ${isUnifiedMode ? 'unified' : 'VRAM'}${reasonSuffix})`, }; }