How to Calculate the Cost of Deploying a Large Language Model On-Premises
This article breaks down the real cost of self-hosting a large language model, using a 743B total-parameter MoE model with 39B activated parameters and native 1M context as an example. It explains why pricing GPUs alone underestimates the investment, details the three layers of VRAM usage (weights, runtime overhead, and KV Cache), covers parallelism and multi-node requirements, and provides cost estimates ranging from about RMB 3.5 million for an entry-level single-node setup to RMB 7.3–8 million for a production-grade dual-node deployment, along with commonly overlooked network, facility, and operations expenses.
How to Calculate the Cost of Deploying a Large Language Model On-Premises
1. Frame the Cost Question Correctly: You Are Buying a System, Not Just GPUs
When many teams evaluate on-premises deployment of a large language model, their first instinct is to look up the price of an accelerator card, multiply it by the number of cards, and arrive at a number that “seems acceptable.” This approach almost always underestimates the true investment. The reason is that inference serving is a systems engineering problem: model weights are only a static part of the footprint. What really drives cost is whether the system can reliably produce tokens at an acceptable latency under a given concurrency and context length.
A more rigorous way to frame the question is: Under the constraints of a target concurrency, target context length, target time-to-first-token, and target output rate, how much compute and storage capacity is required, and what are the upfront capital expenditure and annual operating expenses? Cost is not the outcome of a hardware selection; it is a function of your service level objectives.
2. Key Parameters of the Sample Model: MoE Architecture Changes the Cost Model
This article uses a common large-scale Mixture-of-Experts (MoE) model as a worked example. Its core parameters are:
- Approximately 743B total parameters;
- Approximately 39B parameters actually activated per generated token;
- Native support for roughly 1M (one million) tokens of context.
These three numbers correspond to three completely different cost pressures:
- Total parameters set the VRAM floor. The weights must reside entirely in VRAM. MoE’s “sparse activation” reduces computation, not storage. This is the most commonly misunderstood point: activating 39B does not mean you only need hardware sized for a 39B model.
- Activated parameters determine compute demand. The per-token computation is significantly lower than that of a dense model of the same scale, so throughput is higher on the same hardware. This is the core advantage of MoE on the inference side.
- Context length determines KV Cache size. As context grows from a few thousand tokens to the million level, the KV Cache goes from “negligible” to “a second mountain on par with the weights,” and it scales linearly with concurrency.
3. The VRAM Math: Weights, Framework, and KV Cache Stack Up in Three Layers
3.1 Weight Footprint
Using FP8 (8-bit floating point) quantization as an example, each parameter takes about 1 byte, so 743B parameters correspond to roughly 743GB of weights; with 16-bit precision, this doubles to more than about 1.4TB. This does not yet account for temporary buffers needed for quantization/dequantization, communication buffers, and the working space of certain operators.
3.2 Runtime Overhead
The inference framework itself, communication libraries, VRAM allocator fragmentation, CUDA graph capture caches, and more typically require reserving an additional few to a dozen-plus percent of VRAM. This portion fluctuates noticeably under long-context and dynamic batching scenarios, so headroom must be left; otherwise you get the classic failure mode of “fine under normal load, service collapse at peak.”
3.3 KV Cache
The KV Cache size can be approximated as:
KV_bytes ≈ 2 × num_layers × num_kv_heads × head_dim × context_length × concurrency × bytes_per_element
The factor of 2 comes from the two tensors for Key and Value. As you can see, it is proportional to “context length × concurrency.” When context increases from 8K to 1M (about 128×), the KV Cache also grows by roughly 128×; adding concurrency on top can easily make it exceed the weight footprint itself.
Common mitigation techniques in engineering include: KV Cache quantization, paged memory management, prefix sharing (storing only one copy of an identical system prompt), and context chunking with on-demand swapping. However, each of these adds extra complexity or latency cost, so you cannot assume that “using optimizations makes it free.”
4. Compute and Parallelism: Why a Single Node Is Often Not Enough
An 8-card single machine is the current mainstream high-density configuration. With 141GB of VRAM per card, a single node has about 1.1TB of total VRAM, which can theoretically hold the FP8 weights, but the space left for the KV Cache is severely compressed.
A common combination of parallelism strategies is: tensor parallelism (TP) to split computation within a layer, pipeline parallelism (PP) to split layers, and expert parallelism (EP) to distribute MoE experts across devices. The higher the degree of parallelism, the more frequent the cross-card communication, and the more demanding the requirements on inter-card interconnect bandwidth and inter-node networking. Once cross-node communication becomes the bottleneck, throughput drops non-linearly, and the marginal benefit of “piling on more cards” diminishes rapidly.
A practical rule of thumb is: first run a benchmark with a smaller context to measure the maximum concurrency a single node can stably support; then gradually increase the context length and observe the throughput decay curve. If the target scenario is “moderate concurrency + very long context,” you will almost certainly need two nodes or more.
5. Cost Range Estimates
5.1 Entry Tier: Around RMB 3.5 Million
An FP8 version on a single 8-card node with high-end accelerators requires a hardware investment on the order of about RMB 3.5 million. This tier can run the model, validate results, and support small-scale internal trials, but it usually cannot provide high-concurrency service at the million-token context level — there is insufficient VRAM headroom, and long-context requests will quickly exhaust the KV Cache space.
5.2 Production Tier: Around RMB 7.3–8 Million
To stably support the full million-token context at FP8 precision with a certain level of concurrency, provisioning two nodes (16 cards total) puts the budget roughly in the RMB 7.3–8 million range. This tier also requires high-speed inter-node networking, parallel storage, and redundancy design.
5.3 Easily Overlooked Cost Items
- Networking and storage: high-speed interconnect, and a parallel file system or object storage for weight distribution and data persistence;
- Facilities and power: high-power racks, cooling, UPS, and long-term electricity bills, which are often the main driver of ongoing expenses;
- Operations and staffing: inference framework tuning, monitoring and alerting, logging services, and capacity planning, all requiring steady engineering investment;
- Iteration costs: model upgrades, quantization scheme changes, and load-test regression all repeatedly consume manpower and compute.
As a rule of thumb, the three-to-five-year total cost of ownership (TCO) beyond hardware is typically on the same order of magnitude as the hardware investment, and should not be ignored when budgeting.
6. Cost Reduction and Selection Recommendations
- Define the service level first, then the hardware. Clarify concurrency, context, and latency targets to avoid “buying a fully loaded configuration for the peak.”
- Prioritize trying quantization and sparsification. Under the premise of acceptable quality, lower-precision weights can directly reduce VRAM and bandwidth pressure.
- Use elasticity instead of always-on capacity. If the workload has clear peaks and troughs, using a container platform with auto-scaling and on-demand general-purpose cloud compute is often more economical than building an always-on cluster.
- Deploy in tiers. Split long-context, low-concurrency tasks and short-context, high-concurrency tasks into separate resource pools that scale independently.
- Build an observability system. Continuously track VRAM usage, batching efficiency, and tail latency through monitoring, alerting, and logging services, and let data drive scaling decisions.
7. Conclusion
Open source does not mean low cost. For a MoE model with 743B total parameters, 39B activated, and native million-token context, RMB 3.5 million is only the entry ticket. A truly production-oriented, high-concurrency, long-context service needs a budget on the order of two nodes and RMB 7.3–8 million, plus ongoing investment in networking, facilities, and operations. Only by treating cost as a function of the service level can you avoid the common trap of “can afford to buy it, can’t run it, can’t afford to keep it.”
