Skip to content

Four Places a Deployed LLM Leaks Money, and the Fix for Each

#llm-deployment #quantization #peft #lora #context-window #mcp #token-pruning

Four Places a Deployed LLM Leaks Money, and the Fix for Each ​

A 55,000-token bill arrives before your first prompt ​

GitHub's official MCP server loads about 55,000 tokens across 93 tool definitions. On a 200K context window that is more than a quarter of the budget, spent, before the agent reads a single word of your question.

I did not believe that number until I measured my own. I built a small read-only AWS cost-triage server the way most people build them: one tool per boto3 call, fifteen of them, each with a multi-paragraph docstring. Wired it into Kiro and asked one question. "Where am I wasting money in this account?" The agent needed seven tool calls to answer. It fished around with describe_volumes, then describe_addresses, then describe_snapshots, then instances, NAT gateways, load balancers, correlating everything itself. It got there. It was not pretty.

AWS named the two failure modes in its July 2026 tool-design guidance, and they feed each other.

Bloat: every tool definition loads into the context window on every call, used or not. Each schema runs 550 to 1,400 tokens, so fifty tools means 30,000 to 70,000 tokens of definitions sitting in front of your actual task. A typical Claude Code session with five to ten MCP servers installed starts between 50,000 and 67,000 tokens in the hole, and you pay that tax on every turn.

Confusion: as the context fills with near-identical tools (describe_volumes, describe_addresses, describe_snapshots, all thin, all similar), the model picks the wrong one, passes the wrong parameters, gets an empty result, and retries. Each retry adds tokens. Bloat causes confusion, confusion causes more bloat.

The root cause is the most common way people build these servers: take an API, wrap each endpoint as its own tool, ship thirty of them. It feels complete. It is a trap.

Rebuilding the same server with four tools ​

Same account, same question, same read-only permissions. Four fixes did the work.

Outcome-level tools instead of endpoint wrappers. One find_waste(scope, detail) tool runs every waste check internally and returns findings. "Where am I wasting money" becomes one call instead of seven.

Typed parameters instead of free text. scope is a Literal["account", "region", "service"], so the model cannot pass garbage and does not have to guess a format. AWS Prescriptive Guidance suggests keeping tools at around eight parameters or fewer; every tool in the lean server has two.

Lean responses by default. find_waste returns five decision-relevant fields per finding (id, kind, size, why, region). The full forty-field blob is behind detail=True. This is the fix people skip, and it is the cheapest one available.

Lazy taxonomy. A tiny describe_scope() tool loads valid values only when the agent needs to confirm inputs. Anthropic's Tool Search approach reports up to 85% token reduction by loading definitions on demand rather than up front.

Real errors. A bad scope returns "scope must be one of: account, region, service" instead of "no results". A model can recover from the first. The second sends it into a retry loop that burns context and money.

Metricv1 bloatedv2 leanDelta
Tools exposed154-73%
Tool-description size (chars)7,898897-88%
Tool calls to answer the question72-71%
Real findings cited3 resource IDssame 3 IDsidentical
Attempted any mutationnonoread-only held

The 7,898 characters of v1 definitions are roughly 2,000 input tokens, reloaded on every turn. The lean 897 characters are about 225. On Claude Sonnet at $3 per million input tokens, that gap is half a cent per turn. Half a cent does not sound like anything until you multiply: 40 turns a session, 300 sessions a day, and the schema delta alone runs about $1,900 a month. At 90-plus tools, which is what production setups actually run, the multiplier gets uglier.

The half of the bill nobody measures ​

Quick take: in all four deployment problems below, the win comes from deciding what not to load, not from compressing what you already load.

Everyone counts tool definitions. Almost nobody counts the fat JSON the tools return. My first version handed back the full forty-field boto3 payload for every volume, snapshot, and address in the account. The agent read maybe six of those fields and ignored the rest, but I paid for all of them on every call.

The first real pushback I got was about auditability, and it was fair. If a tool answers in one call, how do you know the answer is trustworthy? My first instinct was to shove everything into the default return. That is the trap. The moment you say "make it auditable" and add the raw ARNs and tag sets back, the forty-field blob returns and the saving is gone. What worked was splitting the two concerns. Provenance (source check, region, observation time) rides along on every finding because it costs almost nothing. Raw tags, full ARNs, and the underlying API response wait behind detail=True for the one finding I am about to act on.

Production teams need the same split enforced mechanically. A default response schema is a contract, and it should fail CI when it grows. Five fields per finding stays small until an account returns 2,000 findings, so the same check should bound the page size and emit an explicit "more results" signal instead of letting a partial scan look complete.

Key numbers

  • 55,000 tokens of tool definitions load from GitHub's MCP server before your first question, about 27.5% of a 200K window
  • 550 to 1,400 tokens per tool schema, so 50 tools costs 30,000 to 70,000 tokens per turn
  • 88% reduction in schema size after rebuilding 15 tools down to 4
  • 7 tool calls down to 2 for the same question on the same account
  • up to 85% token reduction from loading tool definitions on demand

Quantization that does not buy accuracy with wider codewords ​

Weight quantization is the first lever most people reach for, and vector quantization is the sharpest version of it: instead of rounding each weight independently, you code groups of weights against a shared codebook. The accuracy problem has a standard answer. Increase the effective coding dimension, give the codebook more room to represent combinations, and the error drops.

That answer has a cost at decode time. Decoding a token is memory-bandwidth-bound; you stream the weights, you do not compute much. A larger codeword dimension means a larger lookup table and more compare-and-select work per weight, exactly where you can least afford it.

CoS-VQ takes the other branch. It keeps codewords low-dimensional and instead jointly optimizes the hard codeword indices and a shared scale across positions. The interesting part is why this is hard. The optimal scale depends on the whole codeword combination, and changing the scale changes candidate rankings across positions, so you cannot just update one position's index and re-fit a scale afterward. Pointwise updates stall even after you re-optimize the scale.

The paper's fix is to collect candidates at several probe scales and build a tangent separable upper bound for the residual-aware quadratic objective. That reduces candidate comparison to lower envelopes of lines over positive scales, which yields finitely many representative intervals. In plain terms: instead of enumerating codeword combinations, it enumerates a small set of scale ranges where the ordering of candidates cannot change, then solves inside each one.

On Qwen3.8-27B, CoS-VQ beats QTIP and LLVQ across language modeling, coding, and reasoning benchmarks. The ablation is the part worth reading twice: starting from the same initialization, joint index-and-scale updates produce larger gains than scale-only refinement. The coupling is the mechanism, not a side effect.

Why it matters in practice: a 27B model at 4 bits is roughly 13.5 GB of weights, which fits on a single 24 GB card with room for KV cache. Push to 2 bits and you are near 6.8 GB, small enough to leave a consumer GPU or a single accelerator slice comfortable. Getting usable accuracy at that width without inflating the codebook is what decides whether the small deployment is actually viable or just numerate.

Rank is a budget you are currently splitting evenly ​

Standard LoRA picks one rank, applies it to every adapted layer, and never revisits the decision. That rank is a hyperparameter you guessed. Some layers in a fine-tune need capacity. Others are along for the ride and would be fine at a quarter of the size.

SimplexLoRA makes the split learned. It puts per-adapter importance weights on the n-scaled simplex, runs a short warm-up, then freezes those weights. Capacity moves toward the adapters that earn it, and the total parameter budget does not change. Nothing is added at inference. The adapter you train is the adapter you ship, with the same shape and the same kernels.

The evaluation spans 12 tasks across language understanding, summarization, and reasoning on DeBERTaV3, BART-large, Llama 3.1 8B, and Qwen3-8B. It matches or beats standard LoRA and recent adaptive baselines, with the largest margins at low ranks.

That last detail is the deployment-relevant one. At rank 64 the difference between a well-allocated and a badly allocated adapter is mostly an academic question, because you already committed the memory. At rank 8 or rank 16, which is where serving many adapters on one base model actually lives, the allocation is the whole game. If the gains concentrate at low rank, you can hold eight task adapters at rank 8 instead of one at rank 64 and keep the same memory line.

Freezing the weights after warm-up means training-time dynamism never leaks into your serving path. No variable-rank kernels, no recompilation per adapter, no runtime branch that only fires for some layers. That is the difference between a method you can deploy and a method you can only benchmark.

Pruning scene tokens before they reach the model ​

The 3D LLM case is the cleanest illustration of context cost, because the pipeline is so blunt. Take every object token from a room scan, concatenate with the instruction text, feed the whole sequence to the model. A cluttered scene produces hundreds of object tokens, and most of them have nothing to do with the question. That is noise going in and hallucinations coming out.

3D-SceneQ attacks both halves of the problem. Query-Guided Adaptive Pruning uses a learnable latent query to select the objects that matter for the instruction, keeping the critical ones and suppressing the rest. Multi-modal Object-level Feature Enhancement pulls 2D feature embeddings from pretrained vision models into the 3D representation, because a point cloud carries geometry but not color, texture, or material.

The results are +5.7 CIDEr on Scan2Cap and +17.0 EM@1 on SQA3D. That second number is not a refinement. Seventeen points of exact-match on embodied question answering is the difference between a model that usually answers wrong about where an object is and one that usually answers right. The pruning is doing real work, not just shrinking a sequence.

If you run any multimodal pipeline with per-object token stuffing, the lesson transfers directly. The sequence you build before the model sees anything is a design decision, and an aggressive one at that. Pruning at the encoder boundary costs you nothing in inference complexity and removes a class of failure that scaling the model will not fix.

What trips people up ​

Wrapping one API endpoint per tool. It is the default because it maps cleanly to the API docs, and it produces thirty tools with overlapping descriptions. Group by what the agent needs to accomplish, not by what the endpoint is called. The lean rebuild went from 15 tools to 4 by asking what a whole business action looks like.

Counting tool definitions and ignoring response payloads. The schema tax is on every turn. The response tax is on every call, and the payloads are usually bigger than the schemas. Default to five fields and put the blob behind an explicit escalation flag.

Leaving the scope parameter as free text. A Literal costs one word in the signature and removes an entire category of retry loop. Two typed parameters beat eight loosely described ones.

Applying one LoRA rank to every layer. It is the simplest thing to configure and it wastes a fixed budget on layers that do not need it. If you are serving multiple adapters at low rank, adaptive allocation buys real capacity for free.

Assuming you can only get accuracy back by widening the codebook. Every increment of codeword dimension makes decode more expensive at the exact moment you are bandwidth-bound. Jointly optimizing index and scale sidesteps that trade instead of paying it.

What this means ​

If you run MCP servers in production with more than ten tools each, audit the tool count and the default response schema before you touch anything else. The schema tax is measurable in a single turn and multiplies across every agent session you pay for. Cutting 15 tools to 4 and 7 calls to 2 does not require a new model or a new framework, just a different grouping of the same read-only checks.

If your LLM deployment is memory-bound on a single card, push on the weight coding before you shrink the model. A 27B at 4 bits around 13.5 GB leaves real headroom; getting to 2-bit accuracy without inflating codeword dimension is what buys you the smaller device class. Read the CoS-VQ ablation first, because it tells you which half of the update is doing the work.

If you are serving several fine-tuned variants off one base model, stop tuning fixed LoRA rank and let the allocation move. The gains show up at low ranks, which is exactly the regime where serving many adapters fits in memory. The adapter shape is frozen after warm-up, so nothing changes on your inference stack.