本地部署大模型,ollama 是最省心的方案。
安装步骤:
# 安装 ollama
curl -fsSL https://ollama.com/install.sh | sh
# 下载 qwen2.5
ollama pull qwen2.5:7b
# 运行
ollama run qwen2.5:7b
性能测试:
- 7B 模型:8g 显存,生成速度 30 token/s
- 14B 模型:16g 显存,生成速度 15 token/s
- 32B 模型:24g 显存,生成速度 8 token/s
API 调用:
import requests
response = requests.post(
"http://localhost:11434/api/generate",
json={
"model": "qwen2.5:7b",
"prompt": "你好",
"stream": False
}
)
print(response.json()["response"])
兼容 OpenAI 格式,直接换 base_url 就行。
8g 显存的兄弟,qwen2.5:7b 闭眼入。