Self-Hosted GPUs Carry Nearly Half of Tokens: Inference Cost and Cache Optimization

    A technical discussion of why self-hosted GPUs can serve roughly 44% of tokens in large-scale Agent and AI coding workloads, focusing on repeated prefix reuse, KV Cache, prefill/decode separation, prefix-cache design, economics, implementation risks, and best practices.

    In a recently shared technical presentation, an AI coding tool disclosed that about 44% of its tokens are provided by self-hosted GPUs, with total volume on the order of 10 trillion tokens. The interesting point is not whether self-hosting is new, but the underlying trend it reveals: in large-scale Agent and AI coding scenarios, the inference cost structure is shifting from “single generation” to “repeated context reuse.” Whoever can reduce the prefill cost of repeated prefixes can carry more tokens with the same GPU resources.

    The same public discussion also provided several abstract technical signals: single-cluster daily throughput reaches the 100-trillion-token scale; average input length is in the tens of thousands of tokens; the input cache hit rate is high; prefix reuse through a cache cluster improves prefill throughput by more than an order of magnitude; and the system separates prefill and decode into different hardware pools. Prefill uses conventional GPU servers, while decode uses large-scale supernodes with dozens to hundreds of accelerator cards, with scheduling at a ratio close to 1:1. Putting these signals together leads to a clear judgment: in Agent scenarios, the largest cost is often not “generating new content,” but “repeatedly reading the same prefix.”

    Why Self-Hosted GPUs Can Carry Nearly Half of Tokens

    A high share of self-hosted GPU tokens is usually not caused by a single factor. It is the combined result of cost, supply, compliance, and software-hardware co-design.

    First, Agent and AI coding workloads have an obvious “long prefix, short increment” pattern. System prompts, tool descriptions, codebase context, retrieval-augmented documents, and multi-turn conversation history appear repeatedly across a large number of requests. For such workloads, the prefill stage needs to encode long context into the KV Cache and has high compute density; the decode stage generates token by token and has more pronounced memory-access and scheduling overhead. If every request performs prefill again, GPU compute will be consumed by a large amount of repeated computation.

    Second, self-hosted resource pools make end-to-end optimization easier. Prefix caching requires coordinated design across cache clusters, request routing, schedulers, model version management, and tokenizer version management. In a self-hosted environment, teams can control GPU models, network topology, storage tiers, and batching strategies, making “cache hit rate” an operational metric rather than passively accepting a black box.

    Third, large-scale self-hosting can amortize unit costs. When token volume reaches the 10-trillion-token scale, GPU-hour costs, cache storage costs, and network bandwidth costs are all amplified. At that point, even an order-of-magnitude improvement in prefill throughput can lower costs enough to change the resource mix. Self-hosted GPUs carrying nearly half of tokens is essentially about placing predictable, stable workloads in a self-built resource pool while leaving peak elasticity to external resources or hybrid scheduling.

    The Main Cost in Agent Scenarios: Repeatedly Reading the Same Prefix

    In traditional short question answering, input length is limited, so wasted repeated prefixes are not obvious. In Agent scenarios, however, requests often carry long system prompts, tool schemas, code file snippets, and historical traces. Suppose a request has an input length of tens of thousands of tokens, and more than 80% of it is a prefix shared by multiple requests. Re-running prefill for every request then means repeatedly computing the same content.

    The cost model can be simplified as:

    Unit token cost ≈ GPU-hour cost / (effective throughput × utilization) + cache storage cost + network and scheduling overhead

    “Effective throughput” is affected by both prefill and decode. After a prefix-cache hit, the system can directly reuse the computed KV Cache and only prefill the newly added suffix, significantly reducing prefill compute consumption. The higher the cache hit rate, the less repeated computation. But cache is not free: it consumes GPU memory, host memory, or a remote cache cluster, and introduces routing, eviction, consistency, and security-isolation overhead. Therefore, prefix caching is not “enable it and save money”; it requires balancing hit rate, storage cost, and scheduling complexity.

    Engineering Logic of Prefill/Decode Disaggregation

    Prefill and decode have different hardware requirements. Prefill is compute-intensive and is suited to high-compute GPUs, larger batches, and higher compute utilization. Decode is memory-access-intensive and is more affected by KV Cache capacity, memory bandwidth, and scheduling latency. Putting both in the same resource pool can easily create interference: prefill queuing affects time to first token, while decode occupying GPU memory affects batching.

    The core of disaggregated deployment is to split the two stages into independent resource pools: the prefill pool handles long-context encoding and cache writes, while the decode pool handles token-by-token generation and cache reads. The prefill pool can scale horizontally with conventional GPU servers, while the decode pool can be carried by larger supernodes with higher interconnect bandwidth. A ratio close to 1:1 is an empirical starting point; the actual ratio should be dynamically adjusted based on input/output length distribution, cache hit rate, time-to-first-token targets, and GPU utilization.

    The key to this architecture is not “splitting” itself, but “how the cache flows.” The KV Cache produced by prefill must be efficiently readable by the decode pool, and the cache cluster must support prefix reuse, block indexing, and tenant isolation. Otherwise, splitting only adds cross-node transfer costs.

    Key Prefix-Cache Designs and Code Sketch

    The first principle of prefix caching is that “cache keys must be stable and invalidatable.” A cache key should include at least the model version, tokenizer version, tenant or security domain, system-prompt template version, and block hash. After a model or tokenizer change, old caches must be invalidated; otherwise, semantic mismatches will occur.

    An illustrative code sketch is as follows:

    1. def build_prefix_cache_keys(prefix_text, model_version, tokenizer_version, tenant_id, block_size=1024):
    2. blocks = split_into_blocks(prefix_text, block_size)
    3. keys = []
    4. for block in blocks:
    5. raw = f"{tenant_id}|{model_version}|{tokenizer_version}|{block}"
    6. keys.append(stable_hash(raw))
    7. return keys
    8. def route_request(prefix_keys, cache_index, prefill_pool, decode_pool):
    9. hit_blocks = cache_index.lookup(prefix_keys)
    10. if hit_blocks.ratio > 0.8:
    11. return prefill_pool.cache_affinity_node(prefix_keys), decode_pool.affinity_node(prefix_keys)
    12. return prefill_pool.normal_node(), decode_pool.normal_node()

    In engineering practice, four points also matter. First, block granularity should not be too fine; otherwise, indexing and routing overhead increases. Second, request routing should preserve prefix affinity as much as possible so that the same prefix hits the same cache node. Third, cache eviction should consider access frequency, prefix length, and tenant quotas. Fourth, multi-tenant scenarios require security isolation to prevent cross-tenant reuse from causing information leakage.

    Economics of Self-Hosting and Cloud Elasticity

    A high share of self-hosted GPUs does not mean completely rejecting cloud resources. A more reasonable strategy is tiering: place stable, predictable workloads with high long-prefix reuse in self-hosted resource pools; use elastic resources for peaks, bursts, and short-term experiments. In general cloud environments such as Baidu AI Cloud, container platforms, object storage, logging, and monitoring/alerting can be used to build resource orchestration and observability, but core optimization still depends on cache hit rate, scheduling affinity, and the prefill/decode resource ratio.

    For evaluation, consider the following metrics: prefill throughput, decode throughput, P99 time to first token, per-token output latency, GPU utilization, cache hit rate, prefix reuse rate, cross-node cache read bandwidth, cache storage cost, and request queuing time. Only by putting these metrics into the same cost dashboard can teams judge whether “self-hosted GPUs carrying nearly half of tokens” is truly cost-effective.

    Implementation Risks and Best Practices

    Major risks include: model version upgrades causing batch cache invalidation; long-context caches occupying too much memory and squeezing decode GPU memory; cross-node cache reads increasing network jitter; insufficient multi-tenant isolation creating security risks; and an imbalanced prefill/decode ratio causing idle resources. Best practices are to first profile prefixes and measure the repetition ratio of system prompts, tool descriptions, code context, and historical traces; then establish block hashing and cache namespaces; next, validate cache hit rate and P99 latency with small traffic; finally, gradually expand the self-hosted share.

    In summary, nearly half of tokens being carried by self-hosted GPUs is a cost signal worth watching, but what really determines success is the cache and scheduling system behind it. Inference optimization for Agent scenarios cannot focus only on decode throughput; it must treat “repeated prefixes” as a first-class concern. Whoever can steadily improve prefix reuse, reduce repeated prefill computation, and dynamically match prefill and decode resource pools to workload demand will gain more controllable unit token costs in the long-context era.