Why Local Deployment Is Needed
DeepSeek offers a highly cost-effective cloud API, but in many scenarios, local deployment remains a necessity: data security and compliance (industries such as finance, healthcare, and government require data to stay within borders), ultra-low latency (local inference latency can be as low as 10ms, while cloud API RTT typically ranges from 200-500ms), offline usage (edge devices, disconnected environments), cost control (for enterprises with daily calls exceeding one million tokens, the total cost of local deployment may be lower than API fees), and model customization (local deployment supports LoRA fine-tuning and parameter optimization). DeepSeek's model weights are open-source, which greatly facilitates local deployment.
However, local deployment of large language models is a complex system engineering task involving hardware selection, inference framework choice, model quantization, service deployment, performance optimization, and more. This article provides a complete local deployment guide based on the latest practices in 2026.
Hardware Selection Guide
The most critical hardware for local deployment is the GPU. Here are recommended configurations for different scales of deployment: Entry-level (personal use, 7B-level quantized models): NVIDIA RTX 4070 (12GB VRAM) or Apple M2 Max (32GB unified memory), capable of running Q4-quantized DeepSeek-V2-Lite; Advanced level (small teams, 13B-34B models): NVIDIA RTX 4090 (24GB) or A6000 (48GB), capable of running Q4-quantized DeepSeek-V2; Enterprise level (production environment, 70B+ models): 2-4× NVIDIA A100 (80GB) or H100 (80GB), capable of running full-precision DeepSeek-V3.
For scenarios without high-end GPUs, CPU inference (using llama.cpp's GGUF format) is also a viable option. On Intel Xeon or Apple Silicon, with quantization techniques (Q4_K_M), generation speeds of 5-15 tokens per second can be achieved, which, although slower than GPU, is sufficient for background batch processing tasks.
Option 1: Ollama (Simplest Solution)
Ollama is currently the simplest tool for local model deployment, suitable for individuals and small teams. It encapsulates all the details of model download, quantization, inference, and API service, and a single command starts the service. The downside is that performance optimization is not as good as vLLM, and it is not suitable for high-concurrency production environments.
# Install Ollama (directly from the official website)
# https://ollama.com
# Pull DeepSeek model
ollama pull deepseek-coder-v2:16b
# Start the service
ollama serve
# Test call
curl http://localhost:11434/api/generate -d '{
"model": "deepseek-coder-v2:16b",
"prompt": "Write a quicksort in Python",
"stream": false
}'Ollama also supports Python client calls, compatible with the OpenAI SDK:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
response = client.chat.completions.create(
model="deepseek-coder-v2:16b",
messages=[{"role":"user","content":"Explain the principle of Python decorators"}]
)
print(response.choices[0].message.content)Option 2: vLLM (High-Performance Solution)
vLLM is a high-performance inference engine designed for production environments, supporting advanced features such as PagedAttention, continuous batching, and quantized inference. Its throughput is typically 3-5 times that of Ollama, making it the preferred choice for enterprise-level deployment. vLLM natively supports DeepSeek-V2/V3 models.
# Install vLLM
pip install vllm
# Start the API service
python -m vllm.entrypoints.openai.api_server \
--model deepseek-ai/DeepSeek-V2-Lite \
--tensor-parallel-size 1 \
--max-model-len 8192 \
--port 8000
# Python client call
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-needed")
response = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V2-Lite",
messages=[{"role":"user","content":"Write a short essay about AI"}],
max_tokens=500
)
print(response.choices[0].message.content)Option 3: llama.cpp (CPU/Edge Devices)
llama.cpp focuses on running large models on consumer hardware and edge devices. Its GGUF quantization format can compress a 70B model to under 40GB, running smoothly even on a MacBook. For servers without GPUs, Raspberry Pi, or even mobile phones, llama.cpp is the only viable solution.
Key tuning parameters: number of threads (-t parameter, recommended to set to CPU cores -1), context size (-c parameter, larger consumes more memory), batch size (-b parameter, affects throughput), quantization level (Q4_K_M offers the best balance between speed and quality).
Key Considerations for Production Environments
Model Quantization: Reduce model size and memory usage without significantly losing quality. FP16→INT8 halves memory, INT8→INT4 halves again. For most application scenarios, INT8 quantization has minimal impact on quality (<1%), while INT4 has a slightly larger impact (2-5%) but offers excellent cost-effectiveness.
KV Cache Management: In long-conversation scenarios, KV Cache can consume a large amount of VRAM. Limiting max_model_len, using GQA (Grouped Query Attention), or using vLLM's PagedAttention can effectively manage this.
Load Balancing: Production environments typically deploy multiple inference instances. Use Nginx or HAProxy for load balancing, combined with health checks and auto-scaling (triggering new instances based on request queue length).
Monitoring and Alerting: Monitor GPU utilization, VRAM usage, request latency (P50/P99), throughput (tokens/s), and error rate. Use Prometheus + Grafana to build monitoring dashboards.
Security Hardening: Add authentication to API endpoints (API Key or JWT), enable HTTPS (via Nginx reverse proxy), implement rate limiting, and maintain audit logs (recording all inference requests).
Deep Dive into Model Quantization
Model quantization is a key technology in local deployment, balancing model accuracy against inference speed and VRAM usage. Common quantization schemes: FP16 (half-precision floating point, almost lossless quality, halves VRAM), INT8 (8-bit integer quantization, quality loss <1%, halves VRAM again), INT4 (4-bit integer quantization, using GPTQ or AWQ algorithms, quality loss 2-5%, halves VRAM again). For production environments, INT8 is recommended.Quantization—quality loss is almost negligible, but VRAM savings are 50%. If your GPU memory is really tight, you can use INT4+GPTQ quantization, but you need to verify whether the quality is acceptable on your specific task. Quantization is not 'one-size-fits-all'—you can use different quantization precisions for different layers of the model (mixed-precision quantization), keeping FP16 precision in attention layers to ensure quality, and using INT4 quantization in FFN layers to save VRAM. Model serving and API encapsulation: Locally deployed models need to provide services externally through APIs. It is recommended to use vLLM or TGI (Text Generation Inference) as inference servers, as they provide OpenAI-compatible API interfaces, allowing existing application code to switch without modification. For scenarios that need to support multiple models/multiple LoRA adapters, it is recommended to use LiteLLM as a unified gateway—it can aggregate multiple inference backends (vLLM, Ollama, cloud APIs) into a unified interface and automatically route to the most suitable backend based on request characteristics.
Cost Comparison: On-Premises Deployment vs. Cloud API
A typical mid-sized enterprise scenario (50 million tokens per day) cost comparison: using the DeepSeek cloud API costs approximately ¥100-300/day (¥3,000-9,000/month); using a self-built single A100 (80GB) server costs approximately ¥5,000/month (electricity + hosting), but requires a one-time server purchase cost of about ¥100,000; using a self-built 4×A100 cluster costs approximately ¥20,000/month. For scenarios with less than 10 million tokens per day, the cloud API is more economical; for 50 million to 200 million tokens per day, self-built and cloud costs are similar; for over 200 million tokens per day, the cost advantage of on-premises deployment is significant. However, cost is not the only consideration—non-cost factors such as data security, latency requirements, and customization needs are often the main drivers for on-premises deployment.
Final reminder: On-premises deployment is a "one-time investment + continuous operation and maintenance" model. In addition to hardware purchase costs, you also need to consider ongoing expenses such as electricity, cooling, data center space, and operations personnel. Before making an on-premises deployment decision, it is recommended to conduct a complete TCO (Total Cost of Ownership) analysis, comparing the total cost over 3 years (hardware + operations + electricity + labor) with the estimated 3-year cost of the cloud API. Also consider the elasticity of business growth—the expansion cycle for on-premises deployment is typically measured in weeks, while the cloud API can scale up in seconds.
Want to orchestrate this skill chain yourself?
Open in Skill Chain →