Architecture Breakdown and Cost Analysis of Large-Scale Inference Frameworks

    This article breaks down the architecture and unit economics of a large-scale LLM inference framework. It starts from daily throughput and per-GPU cost to derive a per-million-token hardware cost, then explains the three-tier disaggregation of vision encoding, prefill, and decode, the split between small expert parallelism and Wide-EP, the three-level KV cache placement with size estimates, bounded replay for sliding-window state, and scheduling strategies such as budget-driven chunking and peak-load balancing. Readers will get a practical framework for sizing GPUs and monitoring cache hit rate, load skew, and replay rate.

    1. Start With the Math: Does Daily Throughput Match Per-GPU Cost?

    The value of any inference framework ultimately comes down to two numbers: how many tokens it can produce per unit of time, and how much each unit of token output costs. The source figures are roughly 155 trillion tokens per day and about $38 per accelerator card per hour. Start with the simplest division:

    1. 155 × 10^12 tokens / 86400 s ≈ 1.79 × 10^9 tokens/s

    That is about 1.79 billion tokens per second. Spread across an assumed fleet of roughly 7,300 cards, each card must handle about 245,000 tokens per second. Pair that with $38 per card-hour and the hardware cost per million tokens is roughly:

    1. 38 / (245000 × 3600) × 10^6 ≈ 0.043 USD / million tokens

    This figure makes one thing clear: the math only works when the cache hit rate is high enough and the share of effective compute is large enough. If the hit rate drops below 85%, or if scheduling imbalance lowers average utilization, the same number of cards can no longer sustain the same throughput, and unit cost climbs quickly. Every architectural decision described below is ultimately in service of pushing the effective compute share as high as possible.

    Note that the card count and unit price above are assumed values for illustration. In a real project, substitute your own hardware inventory, electricity price, and depreciation basis into the same formula.

    2. System Shape: Three-Stage Disaggregation and Independent Storage

    The traditional approach packs encoding, prefill, and decode onto the same pool of instances, so their resource profiles contaminate one another: encoding consists of short, bursty small requests; prefill is compute-intensive large matrix multiplication; decode is memory-intensive small-step loops. Co-locating them means any one stage’s peak drives up the overall resource watermark.

    Stage disaggregation splits resource pools by profile:

    • Encoding (VE) fits on a single card per instance: lightweight, fast to scale out, and best expanded horizontally according to the input-length distribution.
    • Prefill runs on full 8-card nodes, saturating inter-card interconnect bandwidth to compute long sequences in one pass.
    • Decode runs on super-nodes of 64 to 128 cards, using high parallelism to amortize the cost of reading weights.

    Alongside this sits an independent high-throughput storage layer (referred to below as a 3FS-class parallel file system) that handles only persistence of large KV blocks and cross-pool movement, and never sits in the synchronous wait path of online computation.

    3. Parallelism Strategy: Dividing Labor Between Small EP and Wide-EP

    Prefill uses a smaller expert parallelism degree (about 2 to 8), because the bottleneck there is compute and memory bandwidth, and excessive parallelism adds unnecessary communication rounds. Decode uses Wide-EP (64 to 128), spreading expert weights across more cards so each card reads only a small slice of weights per step, which eases the memory-access bottleneck. This design deliberately excludes tensor parallelism and context parallelism for now, avoiding extra partitioning and synchronization overhead on long sequences. The tradeoff is explicit: solve data supply first with the parallel file system and cache tiering, and only then consider more complex partitioning.

    4. Three-Level KV Cache Placement and Size Estimates

    The tiering criterion is “access frequency × size per access”:

    Tier Contents Access pattern
    HBM Hot data, currently active blocks High frequency, low latency
    Host memory Sliding-window attention (SWA) window Medium frequency, reused within a sequence
    Parallel file system Block-level KV (Block KV) Low frequency, large blocks, cross-node

    On sizing, block-level KV is about 528 B/token and the sliding-window portion about 1.4 MB/sequence. For a 128K context, block-level KV per sequence is on the order of 64 MB, which means a single machine’s memory can hold only limited concurrency, and the file system must carry the vast majority of historical context.

    5. Bounded Replay: Trading Compute for Storage and Bandwidth

    Sliding-window content is not written to the file system. When it is missing, bounded replay is used: replaying only the last 128 tokens restores an approximate state; if the workload requires bit-exact results, the replay window expands to 2560 tokens for reconstruction. This is a classic trade of compute for IO — the marginal cost of recomputation is far lower than keeping window data resident on expensive media.

    1. def rebuild(swa_state, tokens, exact=False):
    2. window = 2560 if exact else 128
    3. replay = tokens[-window:]
    4. for t in replay:
    5. swa_state.update(t) # the approximate path replays only the tail window
    6. return swa_state

    Two engineering points matter: replay must be re-entrant and free of side effects; and the approximate and exact paths must be switched explicitly via configuration so production behavior stays predictable.

    6. Scheduling: Budget-Derived Sizing, Two-Dimensional Balancing, and “Shave Peaks, Not Averages”

    • Prefill derives chunk size from a time budget: given a per-request latency ceiling, work backward to a chunk size so long sequences are split into predictable time slices and no long request monopolizes a device.
    • Decode balances on two dimensions: both per-card load and per-card cache hits, avoiding the false balance of “fast but always missing.”
    • Expert load balancing targets the maximum rather than the average: when average load looks good but a few cards are hotspots, overall latency is still set by the slowest card, so the optimization goal should be to lower the peak.

    7. Implementation Recommendations

    First calibrate hit rate and replay ratio on offline data, then use the same formulas to work backward to the required card count and budget. After launch, focus monitoring on three metrics: cache hit rate, peak load deviation, and replay trigger rate. If elastic capacity is needed, container platforms can handle instance scaling, object storage can archive cold data, and monitoring and alerting can close the metrics loop. These are all general capability categories; evaluate specific choices against your own environment.