DEV Community

Sparkle Qwen27b
Sparkle Qwen27b

Posted on

How I Run a 27B Local Agent on a 12GB Laptop GPU: KVMem, Tiered KV, and Honest Long-Context Limits

Most local-LLM advice stops at the weights. Pick a smaller quantized model, fit it in VRAM, done. That works for chat. It breaks the moment you want a real agent: long files, long tool histories, multi-turn work. The weights are only half the memory problem. The KV cache is the other half, and it grows with context.

Sparkle-Qwen27b-Kvmem-ninfer is my attempt to solve the second half on ordinary hardware. It runs Qwen3 27B as a local coding, files and web agent on an RTX 5070 Ti Laptop with 12GB of VRAM. The stack is NInfer inference, KVMem tiered KV, MTP3 speculative decoding, and a local agent workspace called dsh, with an optional Tauri desktop UI. The code is Apache-2.0.

This article explains how the memory budget works, what KVMem actually does, what I measured, and where it still falls short. I am not going to claim this beats cloud models, or that 256K context means 256K of attention on every step. It does not.

The budget: 12GB is smaller than it looks

The validated machine is an RTX 5070 Ti Laptop with 12GB VRAM, an i7-14650HX, and 32GB of system RAM, running Windows. The default model is Qwen3.8-27B GSQ-RCO IQ3_XXS with MTP3, using RK4V4 plus GDN FP32, with DeviceKV 36864, Retrieve 3840, and HostKV 7168 MiB.

The daily peak is 11,220 to 11,236 MiB of whole-GPU memory. That leaves about 12 MiB of headroom. This is not a comfortable margin. It is deliberate: the pool is sized to use almost everything available, and the first advice when you run out of memory is to shrink the pool to 38,912 or 38,400, not to switch quantization and hope.

Quantization choice matters here in a surprising way. The previous daily profile used NVFP4 and peaked at 11,168 MiB. The current RK4V4 profile peaks slightly higher, but it is the default anyway, because on a 39-question short-context check it scored 35 out of 39 correct with a mean total variation of 0.0262 against BF16 and zero prediction flips, while NVFP4 scored 34 out of 39 with one flip. NVFP4 is also not a VRAM-saving option here: at the same pool, RK4V4 already uses about 20 MiB less. The cheapest quantization on paper is not always the cheapest once the KV budget is included.

Why the KV cache is the real problem

Transformer inference stores a key and a value for every token in the context. That cache grows linearly with context length, and for a 27B model it grows fast. Hold the whole cache on the GPU and a long agent session exhausts 12GB long before the weights do. Evict aggressively and you lose the history the agent needs: the file it edited three turns ago, the error from the last tool call, the plan it agreed to at the start.

The usual answers are to shorten the context, summarize early, or restart the session. All three work, and all three make the agent dumber at exactly the moment a task gets interesting. KVMem takes a different approach: do not keep all of the cache hot. Keep some of it, retrieve the rest.

How KVMem works

KVMem divides the KV cache into tiers. The GPU holds hot pages: sink pages at the start, recent pages, and retrieved pages that a query scores highly. Cold history lives in host RAM — 7 GiB of Host KV in the default profile — and is restored to the GPU on demand.

A request flows like this: the agent sends a request to the cache guard, which keeps the sent prefix stable and reduces repeated prefill; the engine scores the query against stored pages, selects a small set, and restores only those pages. The model then decodes with sink, recent, and retrieved pages in GPU memory. It does not reread all history on every step.

Two details from v1.1.0 show why retrieval quality matters. First, evidence can span two KV pages. If the selector keeps only the second half, the model sees a fragment. The fix uses overlap-retrieval slots to add the predecessor page: at most eight pages per selection, replacing only lower-ranked members of the recent range, with no increase in total selected pages. Second, filling is allowed only after the known query end has been read and the full query has been scored. That change removed a regression that had appeared at 218K in an earlier candidate.

MTP3 sits on top of this. It uses three draft tokens for speculative decoding, which reduces decode steps. Daily sampling stays unchanged. It does not change what the model knows; it changes how fast it produces tokens it was already going to produce.

What I measured, and what I did not

All measurements are from the maintainer's machine, with different binaries, ports and fixtures across runs. They are not a unified benchmark. I report them as fixtures, not leaderboard scores.

A 110K task with 12 sequential pins finished 12 out of 12, producing 733 output tokens in 275.9 seconds at a peak of 11,232 MiB. The previous daily build had exhausted its 4,096 output budget without a final answer on the same fixture. A 218K task finished 26 out of 26, with normalized JSON matching the correct baseline. A 159K task finished 16 out of 16. A 232K sequential-pin task finished 24 out of 24, but sequential codes are easy to extrapolate, so I treat that as a weaker signal than the real-content test.

The real-content test is the one I trust most. It used 189,954 tokens of real content across multiple turns, with 16 code facts and 8 earlier conversation facts to recall. It passed 24 out of 24. That is a better proxy for agent work than needle tests, because it requires the model to use retrieved history to answer questions about code it saw earlier in the same session.

Short-context fidelity was checked on 39 questions. The default RK4V4 plus GDN32 scored 35 out of 39 with zero flips. Tool and JSON regression was 20 out of 22, the same score and failures as v1.0.0. A 66K input with 3,668 output tokens completed without running out of memory.

Now the limits, stated plainly. The logical context capacity is 262,144 tokens, which is where the 256K number comes from. Full 256K is not validated. The dsh compaction threshold is around 184K, and long-history middle sections are retrieved by page selection. A step does not read all history. The 232K random-order stress test was unstable across repeats, so it is not a release claim. Anyone who tells you a tiered cache gives you full attention over 256K on a 12GB card is selling something.

There are practical limits too. The prebuilt engine covers Windows x64 with sm120a only. RTX 30 and 40 series cards need an architecture-matched build. Search needs the internet, because dsh search is not an offline index. Private requests, sessions and logs stay local. Version 1.2.0 fixes a CPU vision chunk-boundary scatter error and adds bounded recovery from truncated summaries, but a known multi-image plus compaction failure mode remains: if it hits, start a new session.

The agent layer, and how to try it

The engine alone would be a fast inference server. The dsh agent workspace is what makes it usable for work. It provides edit validation before execution, a task ledger that reminds the model of remaining actions, tool-result fidelity, and a deterministic state card after significant tool results. The optional Pmod desktop, built with Tauri 2 and Vue 3.5, adds chat, model configuration, VRAM monitoring, and an OpenAI-compatible gateway. The engine API listens on http://127.0.0.1:1234/v1, the cache guard on port 1236, and the dsh UI on port 3080.

You need Node.js 24 or later, the VC++ x64 runtime, a CUDA 13-compatible NVIDIA driver, and a v3 .ninfer model containing MTP. Install with: git clone https://github.com/CSUNX233/Sparkle-Qwen27b-Kvmem-ninfer.git, then run setup.ps1 with your model path, then start.cmd. The first start downloads checksum-pinned dependencies, loads weights, and captures CUDA graphs. The private dsh login URL is written to runtime/logs/dsh.stdout.log. Do not publish it. git pull alone does not replace the executable; rerun setup.ps1 after updating source.

If you try it, I would like to hear where it breaks for you. Does retrieval hold up on your long tasks, or does the model lose the middle of the history first? Does the pool size need to change for your GPU? Those are the questions that will decide what v1.3.0 focuses on.

Repo: https://github.com/CSUNX233/Sparkle-Qwen27b-Kvmem-ninfer

Official community group coming soon — invite will be posted in the repo.

Top comments (8)

Collapse
 
pomereneio profile image
Kyle Ma •

The tiered-KV framing is the right one — the question is what the repeat unit is. On a local 27B agent the KV tiering saves the re-derive cost on the prefix, but the trajectory itself still re-runs: what repeats is the goal, not the prompt text, so a recorded trajectory replays without re-invoking the model at all — a 14-step audit trajectory replays in 47ms vs 3.9s live, with zero LLM invocation on the hit path. Worth measuring how often the same goal repeats before sizing the tiers: if the repeat rate is high, replaying the trajectory cuts the re-derivation term that tiered KV leaves on the table, and the two compose because they cut different terms.

Collapse
 
jaxsinclair profile image
Jax Sinclair •

Your 47ms vs 3.9s replay number is the right shape, and the ceiling on it is computable from a published fixture, so it does not have to stay rhetorical.

The post above: 733 output tokens in 275.9 s. At a realistic 18 to 27 tok/s decode rate for a resident 27B IQ3_XXS on that laptop GPU, decode accounts for 27 to 41 s of the turn. That leaves 85 to 91% of the wall clock outside decode. On a 110K-token agent turn the re-derive term is most of the bill, and that is why replay has more room than a KV tier: the tier changes where the KV comes from, not the prefill you pay before it.

What decides the valuation is the unit you count. Prompt text repeats every turn inside a session. A goal repeats across sessions. A goal plus its state almost never repeats exactly. A replay keyed on the goal alone only pays when the recorded trajectory is still valid for the new state, and the failure there is not a stall, it is a plausible wrong answer, which is worse. Your 18 adversarial pairs post reads like you already know that.

So the number I want next to 47ms is a hit rate at each unit: text, goal, goal+state. Publish one fixture where the same goal runs N times with the hit count, and I will put the decode ceiling beside it. Free, and it decides whether a 12GB box should buy the cache or the KV tier first. jax-5@ilands.app

Collapse
 
pomereneio profile image
Kyle Ma •

You're asking the right question, and the honest answer is that the per-unit numbers don't exist yet in published form — I don't have a clean fixture that reports text vs goal vs goal+state hit rates, so I'm not going to quote you one.

What is published, and what it maps to: on the τ-bench airline benchmark, 86% of paraphrased requests were served from cache and 78% judged correct. That's the goal unit — same goal, different wording — not text and not goal+state. The 47ms vs 3.9s figure is a 14-step trajectory replay, same shape.

Your ordering is right, and it's why the cache is keyed the way it is: prompt text repeats constantly inside a session and is worth almost nothing; a goal repeats across sessions and is where the saving lives; goal+state exact repeats are rare, and a replay keyed on goal alone only pays when the recorded trajectory is still valid for the new state — which is exactly the failure mode the write gate exists for. Reads can fuzzy-match; writes never do. And since the October core fixes, an abstract match no longer counts as an exact repeat, a trajectory with no taint records plus a context change is a miss, and a hit never serves past a declared external_write. So a goal+state fixture would mostly measure principled misses — which is the point. The cache's job is to refuse the unsafe replay.

Fair ask on the fixture: same goal run N times with the hit count at each unit. I'll run that and publish the numbers. The eval post shows how the 18 adversarial pairs were built — dev.to/pomereneio/how-to-build-an-... — and this is the natural next measurement. In the meantime, the honest way to get your number for your own workload is the measure-first framework (cluster completed runs by goal, not by exact prompt text): dev.to/pomereneio/how-much-of-your... — the kit's diagnostics endpoint shows hit rates and the L1/L2/miss breakdown on your real traffic.

Thread Thread
 
jaxsinclair profile image
Jax Sinclair •

Good. The fixture is the answer, and I'll take it. Two things to pin before it ships, because they decide what the number means.

First: 86% and 78% are published as separate figures. If 78% is conditional on a cache hit, then per 100 turns you serve 67 correct replays and 19 wrong ones. The number that competes with a KV tier is 67, not 86. If 78% is overall task accuracy with the cache on, I need the uncached baseline beside it, because a cache that buys latency with accuracy has to state the price. Which is it?

Second, the gate converts hits into misses, so the hit rate the kit reports and the hit rate after the gate are different numbers. The fixture should publish three per 100 turns: offered, served, served-and-correct. The gap between the last two is the price of the safety rule, and it is the number a buyer asks for first.

On the 47ms: at 86% served the mean turn is 0.14 x 3.9s + 0.86 x 0.047s = 0.59s, a 6.7x mean win. Real, and the least interesting line, because the 14% still pays 3.9s. What a user feels is the wrong 19.

When it ships I'll put the decode ceiling from this laptop fixture beside it, same terms as the offer: free, credited.

Thread Thread
 
pomereneio profile image
Kyle Ma •

Good questions — and your 67/19 reading is the right one. The published figures are separate for exactly this reason: 86% is the share of paraphrased τ-bench requests served from cache, and 78% is the share of those served answers judged correct — conditional on a hit, not overall. So per 100 turns: 86 served, about 67 served-and-correct, about 19 served-and-wrong. The number that competes with a KV tier is 67, and the 19 is the number that has to be reported, not hidden.

On the baseline: I don't have a published uncached τ-bench accuracy to put beside it, so I won't quote one. The fixture will measure and publish the uncached baseline alongside the cached numbers — same fixture, same turns — so the price, if any, is stated as a number.

On the gate: you're right that the reported hit rate and the post-gate hit rate are different numbers. The fixture will publish all of them per 100 turns — offered, served (post-gate), and served-and-correct — plus the pre-gate offered rate, so the gate converting hits into misses is visible rather than folded in. The gap between served and served-and-correct is the price of the safety rule, stated as a number, not a footnote. And the gate's job is exactly that: a wrong replay must not become a wrong side effect, so risky hits become misses instead.

On the 47ms: your mean-turn math checks out (0.59s, about a 6.7x mean win), and your point stands — the mean isn't what a user feels. What a user feels is the wrong 19. That's the number the fixture is built to move, and to report honestly whether it does.

When it ships, your decode ceiling goes beside it, same terms as offered: free, credited. Thanks for pinning this down before it ships rather than after.

Thread Thread
 
jaxsinclair profile image
Jax Sinclair •

Agreed on the split, and on the uncached baseline. One variable is still undefined before the fixture ships: where the 19 land.

They are served, so by definition nothing caught them in the tau-bench run. That makes the gate a risk filter, not a correctness filter. Nineteen wrong answers per 100 turns reached the user because the gate cannot see wrongness, only risk. So the fixture needs a third cut: of the 19, how many would a real agent loop catch downstream (test failure, retry, human correction), and how many reach the user. If most are caught, 67 stands and the cache is cheap. If they leak, 19 is the real price and it belongs next to 67 in the abstract, not in a footnote.

Report that per 100 and the decode ceiling goes beside it on the same turns. Free, credited, as offered.

jax-5@ilands.app

Thread Thread
 
pomereneio profile image
Kyle Ma •

You're right to push on this — the 19 are the uncomfortable number, and the published 86/78 doesn't say where they land. The τ-bench run measured the gate as it stood then: a paraphrase mapping to the same intent counted as a hit and was served, with nothing in that run re-checking the served trajectory against the live context. So the 19 are served-and-wrong by construction — the gate let them through; it didn't bound them. Calling it a boundary would be the wrong word. It's a risk, and the fixture has to price it.

Two commitments for the fixture (W6, due ~Nov 28). First, it re-measures against the current gate, not the old one: the October core fixes — an abstract-goal match no longer counts as an exact repeat, no-taint-info plus a context change is a miss, and a hit never serves past a declared external_write — change what counts as a hit. So the 19 get re-counted and broken out per 100 turns by which match class served each one, and whether any post-serve check would have caught it. I won't claim now that the fixes shrink the 19; the fixture measures that. Second, the table reports offered / served post-gate / served-and-correct per 100 turns, plus the pre-gate offered rate and a measured uncached baseline — and the decode ceiling goes beside it on the same turns, free and credited, as offered. The 19 stay in the table.

Collapse
 
jaxsinclair profile image
Jax Sinclair •

One number your post doesn't state, and I think it's the most useful one in it: 733 output tokens in 275.9 s is 2.66 tok/s end to end on the 110K fixture.

I don't read that as a decode rate. A 27B IQ3_XXS weight set is roughly 10 to 11 GB; one pass per token at even a modest 300 GB/s of VRAM bandwidth gives a ceiling near 30 tok/s. At that ceiling your 733 tokens cost about 24 s, so ~91% of the 275.9 s sits outside decode. Even at a slow 10 tok/s decode, 73% of the wall clock is outside decode.

So what your fixture prices is prefill, page selection, and pulling cold KV back into the GPU. If DeviceKV 36864 and Retrieve 3840 are token counts, the hot pool covers about a third of a 110K context, which means most of the history is coming out of the 7 GiB host pool every turn, over PCIe. That is the bill for tiered KV, and almost nobody publishes it: a fit table answers "does it fit", your number answers "what does a 110K-token turn cost in wall clock".

If you have the split (prefill tok/s at 110K, decode tok/s at short context), post it. I'm assembling a three-machine comparison from published rows: a 4 GB card streaming weights from DDR4, a 128 GB unified box, and now your 12 GB laptop GPU holding the weights resident. Both other rows published decode tok/s. Yours is the only one that would tell me what the tiered-KV tier actually costs per turn.