DeepSeek-Coder 是 DeepSeek 的代码大模型系列,从零开始在 2T tokens(87% 代码 + 13% 中英自然语言)上训练,提供 1.3B/5.7B/6.7B/33B 多种规格,窗口 16K,支持项目级代码补全与 infill。
一、项目官方信息
| 项目 | 信息 |
|---|---|
| GitHub 仓库 | https://github.com/deepseek-ai/DeepSeek-Coder |
| 官方网站 | https://www.deepseek.com |
| Hugging Face | https://huggingface.co/deepseek-ai |
| 论文 | https://huggingface.co/papers/2401.14196 |
| 开源协议 | 代码 MIT;模型遵循 Model License |
| 主要语言 | Python(约 99.7%) |
| Star 数 | 约 24k |
二、官方图片
DeepSeek-Coder 在 HumanEval 等基准上的表现:

在线补全演示:

三、环境要求
- Python 3.8+;
- PyTorch(bf16 推荐);
- 33B 模型需 80GB 显存(多卡);
- 6.7B/7B 可在单卡 24GB 上跑。
四、完整部署步骤
1. 安装依赖
git clone https://github.com/deepseek-ai/deepseek-coder.git
cd deepseek-coder
pip install -r requirements.txt
2. 下载权重
从 Hugging Face 选择对应规格:
- Base:deepseek-ai/deepseek-coder-1.3b-base / 6.7b-base / 33b-base
- Instruct:deepseek-ai/deepseek-coder-6.7b-instruct / 33b-instruct
3. 代码补全示例
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-coder-6.7b-base", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
"deepseek-ai/deepseek-coder-6.7b-base",
trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
input_text = "#write a quick sort algorithm"
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_length=128)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
4. 代码插入(FIM infill)
input_text = """<|fim▁begin|>def quick_sort(arr):
if len(arr) <= 1:
return arr[0]
pivot = arr[0]
left = []
right = []
<|fim▁hole|>
if arr[i] < pivot:
left.append(arr[i])
else:
right.append(arr[i])
return quick_sort(left) + [pivot] + quick_sort(right)<|fim▁end|>"""
5. 用 transformers pipeline 对话
from transformers import pipeline
pipe = pipeline("text-generation", model="deepseek-ai/deepseek-coder-6.7b-instruct",
torch_dtype=torch.bfloat16, device_map="auto")
messages = [
{"role": "user", "content": "Write a Python quick sort."}
]
out = pipe(messages, max_new_tokens=512)
print(out[0]["generated_text"][-1])
五、使用方法
支持的编程语言
覆盖 80+ 语言:Python、C/C++、Java、JavaScript、Go、Rust、TypeScript、SQL、Shell、Lua、R 等。
作为智能体(Agent)
Instruct 版本可接入 Agent 框架,支持工具调用。
在线 Demo
Hugging Face Space 提供 33B-Instruct 在线演示:https://huggingface.co/spaces/deepseek-ai/deepseek-coder-33b-instruct 。
VS Code 插件
DeepSeek-Coder 有官方 VS Code 插件,支持行内补全。
六、常见问题 FAQ
1. 支持多少上下文? 16K,可处理整个仓库片段。
2. 33B 单卡能跑吗? BF16 约需 66GB 显存,单卡 A100 80GB 可勉强,多卡更稳。
3. 与 Coder-V2 区别? V2 是 MoE,236B 总参 / 21B 激活,128K 上下文,支持 338 种语言。
4. 如何做 FIM?
用 <|fim▁begin|> / <|fim▁hole|> / <|fim▁end|> 三个特殊 token。
5. 支持商用吗? 代码 MIT;模型遵循 Model License,支持商用。
6. 与 StarCoder 比? HumanEval 上 DeepSeek-Coder-Base-7B 追平 CodeLlama-34B,33B 全面领先。