Here is the English translation of the provided text about deploying DeepSeek-R1 on a VPS.
Foreword
AI has been exceptionally popular over the last two years, and there are many AI models on the market. Essentially, every major technology company has its own AI offering, each with its own pros and cons. Today, I'll share the configurations and steps required to deploy DeepSeek-R1 on a VPS server, considering all necessary factors. For specific details, please always refer to the official DeepSeek documentation.
DeepSeek Official Links:
https://github.com/deepseek-ai/DeepSeek-R1
https://github.com/deepseek-ai/DeepSeek-V3
I. Basic Hardware Configuration
II. Software Environment
III. Deployment Steps
1: Environment Initialization
# Update System
sudo apt update && sudo apt upgrade -y
# Install Basic Tools
sudo apt install -y git curl wget python3-pip
# Install CUDA (for GPU scenario)
# Refer to NVIDIA Official Documentation: https://developer.nvidia.com/cuda-downloads
2: Python Environment Setup
# Use conda to manage environment
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
conda create -n deepseek python=3.10
conda activate deepseek
3: Install Model Dependencies
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117 # Adjust based on your CUDA version
pip install transformers accelerate sentencepiece
4: Download the Model
Obtain the model weights from the Hugging Face Hub or official channels:
Python
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained("deepseek-ai/deepseek-llm-7b")
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-llm-7b")
5: Deploy API Service
Use FastAPI to write the inference interface:
Python
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Query(BaseModel):
text: str
@app.post("/predict")
async def predict(query: Query):
inputs = tokenizer(query.text, return_tensors="pt")
outputs = model.generate(**inputs)
return {"response": tokenizer.decode(outputs[0])}
6: Configure Web Server
Use Nginx for reverse proxy and SSL configuration:
Nginx
server {
listen 80;
server_name your-domain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name your-domain.com;
ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
}
}
IV. Security and Optimization
1: Firewall Settings
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw enable
2: Process Management
Use systemd to manage the service:
Ini, TOML
# /etc/systemd/system/deepseek.service
[Unit]
Description=DeepSeek API
After=network.target
[Service]
User=ubuntu
WorkingDirectory=/opt/deepseek
ExecStart=/opt/miniconda3/envs/deepseek/bin/uvicorn main:app --host 0.0.0.0 --port 8000
Restart=always
[Install]
WantedBy=multi-user.target
3: Monitoring and Logging
Use journalctl to view logs:
journalctl -u deepseek.service -f
Key Considerations
Model Quantization: If resources are limited, use bitsandbytes for 4/8-bit quantization to reduce VRAM usage.
Caching Optimization: Enable vLLM or TGI (Text Generation Inference) to significantly boost inference speed.
Bandwidth Limit: Ensure your VPS has sufficient traffic ($1\text{TB}+$), to avoid unexpected overage charges.
Adjust configurations based on actual needs. It is recommended to test with a minimal setup first and then gradually scale up.
Summary
Most of these steps follow the official documentation. If anything is unclear, you can check the official DeepSeek documents. To ensure your deployed DeepSeek performs well, you need a computer or server with high RAM and CPU performance. However, the cost of building a high-performance computer yourself is high. I recommend using a cloud server, where you can experience a high-performing DeepSeek for just a small monthly fee.