Deploying AI Coding Assistants On-Premises: Model Selection and Capacity Planning
When adopting an AI coding assistant, teams must choose between cloud APIs and on-premises deployment. This guide compares both options across compliance, cost, latency, and customization; explains how to calculate GPU memory requirements including model weights, KV cache, and runtime overhead; and provides hardware tiers, a capacity estimation example, and stress-testing steps to validate your setup before production rollout.
1. Cloud API or On-Premises: Decide First
When introducing an AI coding assistant, teams typically choose between a cloud API and an on-premises deployment. The differences:
| Dimension | Cloud API | On-Premises |
|---|---|---|
| Data compliance | Code leaves the internal network; compliance depends on the vendor’s certifications and contractual terms | Code and prompts stay inside the corporate network, with a clear audit boundary |
| Cost model | Pay-per-call; costs become hard to predict as usage grows | Sum of hardware depreciation, power, facilities, ops staffing, and model upgrade costs; plan annually |
| Latency | Affected by public network bandwidth and server-side load; highly variable | Direct intranet access; latency can be measured with local load testing |
| Ops staffing | Almost no model service maintenance required | Dedicated staff for the inference service, version upgrades, and monitoring |
| Model customization | Limited by the vendor’s capabilities | Fine-tuning or retrieval augmentation on internal codebases is possible |
A cloud API is more suitable when usage is small, code involves no sensitive assets, and the team has no ops capability. For heavily regulated industries such as finance, government, and healthcare, or for teams of dozens of engineers with steadily growing call volumes, on-premises deployment delivers more value.
Before deciding, complete a data classification exercise:
- Code sensitivity: Distinguish public, internal, and classified code, and define which repositories may enter the model context.
- Log retention: Define retention periods, redaction methods, and access approval workflows for prompts and model responses.
- Cross-border and outsourcing restrictions: Confirm whether outsourced personnel can access the model service and whether any data is subject to cross-border transfer rules.
2. How to Calculate GPU Memory
Many selection mistakes come from memory estimation. Rough claims like “tens of billions of parameters need hundreds of GB of memory” easily lead to procurement errors. At inference time, GPU memory consists of three parts:
Total GPU memory ≈ model weights + KV cache + runtime overhead
2.1 Model Weights
Weight usage equals the parameter count multiplied by the bytes per parameter:
- BF16 or FP16: 2 bytes per parameter
- INT8 or FP8: 1 byte per parameter
- INT4: 0.5 bytes per parameter
The table below shows weight usage by parameter count (B = billion), in GB (billion bytes):
| Parameters | BF16 | INT8 | INT4 |
|---|---|---|---|
| 7B | 14 GB | 7 GB | 3.5 GB |
| 14B | 28 GB | 14 GB | 7 GB |
| 32B | 64 GB | 32 GB | 16 GB |
| 72B | 144 GB | 72 GB | 36 GB |
Conversion note: 1 GiB (binary) ≈ 1.074 GB. The values above are theoretical; actual model files also include quantization scaling parameters, and files grow larger when some layers are kept at higher precision. Use the actual size of the downloaded model files as the reference.
2.2 KV Cache
The KV cache stores attention keys and values for every generated token. It grows with context length and concurrency and is the most commonly underestimated component. Bytes per token:
Bytes per token = 2 × number of layers × number of KV heads × head dimension × bytes per element
The factor of 2 accounts for separate K and V caches. A single sequence’s KV usage equals bytes per token multiplied by context length; add up all concurrent sequences.
An illustrative configuration: 64 layers, 8 KV heads, head dimension 128, stored in BF16 (2 bytes per element). This yields 256 KiB per token.
- One 32K-context sequence: 32768 × 256 KiB = 8 GiB
- 16 concurrent sequences averaging 8K context each: 16 × 8192 × 256 KiB = 32 GiB
This configuration is only an example of the calculation method; use the layer count and KV head count from the actual model configuration file.
2.3 Runtime Overhead
The inference framework itself consumes GPU memory, including the CUDA context, framework buffers, and activation peaks during computation. As a rule of thumb, reserve 2 to 4 GiB per GPU. Frameworks such as vLLM limit the usable memory fraction via the gpu_memory_utilization parameter; start at 0.85 and adjust after load testing.
2.4 Per-GPU Memory After Multi-GPU Sharding
With tensor parallelism (TP), weights and KV cache are sharded across GPUs. Per-GPU memory requirement:
Per-GPU memory ≈ (weights + KV cache) ÷ TP + runtime overhead
After sharding, each GPU’s available memory must still exceed its requirement, with at least 10% headroom for request spikes.
3. Hardware Tiers and Capacity Planning
3.1 Capacity Estimation Example
Suppose you deploy a 32B model with INT8 quantization on two 48 GB GPUs (TP=2), targeting 16 concurrent sequences of 8K context each.
- Weights: 32 GB ≈ 29.8 GiB, about 14.9 GiB per GPU
- KV cache: 16 × 8K × 256 KiB ÷ 2 ≈ 16 GiB per GPU
- Runtime overhead: 3 GiB per GPU
- Per-GPU total: about 33.9 GiB
A 48 GB GPU at 0.9 utilization provides about 40.2 GiB of usable memory, which exceeds 33.9 GiB — the requirement is met.
3.2 Hardware Tier Reference
The table below gives starting configurations, not performance guarantees. Every tier must be validated with load tests using your own team’s data.
| Tier | Typical Configuration | Supported Models (Examples) | Reference Team Size | Memory and Storage Recommendations |
|---|---|---|---|---|
| Entry | Single 24 GB-class GPU | 7B–14B, INT4 or INT8 | Pilot of up to 5 people | System RAM no less than total VRAM; reserve 2× model file size on NVMe |
| Standard | Two 48 GB-class GPUs, PCIe or NVLink | 32B, INT8 or INT4, TP=2 | 10–30 people | System RAM at least 1.5× total VRAM; reserve 2× model size on NVMe |
| Enhanced | 4–8 × 80 GB-class GPUs in one server, NVLink | 72B INT8, or 32B BF16 | Dozens of users, high concurrency | System RAM roughly equal to total VRAM; keep space for multiple model versions |
Without NVLink, inter-GPU communication runs over PCIe, making TP communication overhead more significant. Record this separately during load testing.
3.3 Stress-Test Acceptance Steps
- Prepare a test set: Extract at least 200 completion, Q&A, and rewriting samples from internal codebases, removing sensitive information before use.
- Ramp up load gradually: Set concurrency to 1, 2, 4, 8, and 16 in sequence, running each level for a fixed duration.
- Record metrics: Time to first token (TTFT), output tokens per second, P95 end-to-end latency, and peak GPU memory usage.
