Guide · Open source
How to use DeepSeek-Coder: setup, code completion and chat
Updated · written with AI from the project's own documentation and checked against our catalogue data
DeepSeek-Coder is a family of open code language models released under the MIT license. You give it code or a plain-language request, and it generates code, fills in missing lines in a file, or answers coding questions in chat form. This guide shows how to install its dependencies, run the three example patterns from the project README, and decide whether it fits your setup.
Quick start
- 1Clone the repository. Download the deepseek-coder project from GitHub and open its folder.
- 2Install dependencies. Run pip install -r requirements.txt to install what the examples need.
- 3Check your GPU. Confirm you have a CUDA-capable NVIDIA GPU, because the examples call .cuda().
- 4Pick a model. Use a base model for completion and infilling, or an instruct model for chat.
- 5Run a completion example. Load the tokenizer and model from Hugging Face and generate code from a comment prompt.
- 6Try fill-in-the-middle. Wrap your file with the fim markers and place the hole where the missing code goes.
- 7Review the output. Test and read any generated code before relying on it.
What DeepSeek-Coder is and which model size to pick
DeepSeek Coder is a series of code language models trained from scratch on 2T tokens, with a composition of 87% code and 13% natural language in English and Chinese. The README lists sizes from 1B to 33B, including 1.3B-class and 6.7B-class checkpoints referenced in the examples.
The project offers base models for completion and infilling, and instruction-tuned models for chat. The README names DeepSeek-Coder-Base and DeepSeek-Coder-Instruct as the two families.
- Base models: use for code completion and fill-in-the-middle.
- Instruct models: use for question-and-answer and chat-style requests.
- Larger sizes generally need more GPU memory; the README does not give exact memory figures.
Install DeepSeek-Coder dependencies
Clone the repository from GitHub, open its folder, and install the dependencies listed in requirements.txt. The README says you need to do this before running the examples.
The examples use Python with Hugging Face's transformers library and PyTorch, and they call .cuda(), so you need a CUDA-capable NVIDIA GPU to run them as written.
- Prerequisites: Python, pip, and a CUDA-capable GPU.
- The README does not list a specific Python or CUDA version, so check the repository's requirements.txt.
pip install -r requirements.txtRun code completion from a prompt
Code completion takes a partial piece of code or a comment and continues it. The README example loads the 6.7B base model, sends the comment #write a quick sort algorithm, and prints the generated code.
The model is loaded with bfloat16 precision and moved to the GPU. The output length is capped with max_length=128.
- Change the prompt string to request other code.
- Raise max_length if the output is cut off.
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))Fill in missing code in the middle of a file
Fill-in-the-middle (infilling) lets the model write the missing section between existing code above and below it. The README pattern wraps the file in special markers: <|fim▁begin|> before the code, <|fim▁hole|> where the gap is, and <|fim▁end|> after it.
In the README example, the model returns the missing line for the loop, and the script prints only the new text by slicing off the input length.
- Place <|fim▁hole|> exactly where the missing code belongs.
- Use the base model for this pattern; the README example uses deepseek-coder-6.7b-base.
input_text = """<|fim▁begin|>def quick_sort(arr):
if len(arr) <= 1:
return arr
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|>"""
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)[len(input_text):])Ask questions in chat format with the instruct model
For plain-language requests, use an instruct model such as deepseek-coder-6.7b-instruct. The script builds a chat message list and applies the tokenizer's chat template, then generates a reply.
The README example uses greedy decoding (do_sample=False) with max_new_tokens=512 and stops at the end-of-turn token.
- Add more entries to messages to continue a conversation.
- The README example output is a Python quick sort with a short test, but the model's wording will vary with your prompt and settings.
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-coder-6.7b-instruct", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-coder-6.7b-instruct", trust_remote_code=True, torch_dtype=torch.bfloat16).cuda()
messages=[
{ 'role': 'user', 'content': "write a quick sort algorithm in python."}
]
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, top_k=50, top_p=0.95, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))Check the output before you use it
The README reports benchmark results such as pass@1 on HumanEval, MBPP and DS-1000. These scores describe average performance on test sets, not a guarantee that any generated code is correct.
Run generated code through your own tests and review it before it reaches production.
- Test generated functions with your own inputs.
- Read generated code for security and edge cases before merging it.
What people use it for
- Completing a function from a comment describing what it should do.
- Filling in a missing loop or block inside an existing Python file.
- Asking a chat-style question to write a sorting or utility function.
- Comparing open code models on benchmarks such as HumanEval and MBPP.
Frequently asked questions
Is DeepSeek-Coder free to use?
The project is released under the MIT license, according to the repository. The MIT license allows use, modification and redistribution, but you should read the license text yourself for the exact terms.
What do I need to run DeepSeek-Coder?
The README lists Python, pip and a CUDA-capable GPU as prerequisites, since the examples call .cuda(). The examples also use bfloat16 precision and Hugging Face's transformers library.
How do I install DeepSeek-Coder?
Clone the repository and run pip install -r requirements.txt, as the README instructs. The README does not describe a packaged installer or desktop app.
Can I run DeepSeek-Coder without a GPU?
The README examples move the model to a GPU with .cuda(), so they will not run as written on a machine without one. The README does not describe a CPU-only setup.
How does DeepSeek-Coder compare to CodeLlama or StarCoder?
The README compares its models with CodeLlama-34B and GPT-3.5-turbo on benchmarks, and reports leads on HumanEval, MBPP and DS-1000. It does not compare directly with StarCoder or Qwen2.5-Coder, so run your own tests on your tasks.
Is DeepSeek-Coder good for production code?
The README reports benchmark scores, not a guarantee of correct code. Review and test generated code before using it in production.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
DeepSeek-Coder suits developers, teams and researchers who want an MIT-licensed code model they can run on their own NVIDIA GPU, especially for completion and infilling inside existing files. It is a poor fit if you want a finished app or IDE plugin, lack a suitable GPU, or need code you can ship without review.
Install options & downloads