1. Introduction
DeepSeek Coder is a powerful open-source code model designed for project-level code generation and infilling. It supports multiple programming languages and achieves state-of-the-art results in code completion tasks.
2. Features of DeepSeek Coder
- Trained on 2T tokens (87% code, 13% natural language in English & Chinese).
- Available in multiple sizes (1.3B, 5.7B, 6.7B, and 33B parameters).
- 16K context window for handling large projects.
- Supports project-level code completion & infilling.
3. How to Use DeepSeek Coder 1.3B
A. Installing Required Dependencies
To use the model in Python, install the necessary libraries:
pip install transformers torch
B. Loading the Model in Python
Use the transformers
library to load the model:
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-coder-1.3b-instruct", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
"deepseek-ai/deepseek-coder-1.3b-instruct",
trust_remote_code=True,
torch_dtype=torch.bfloat16
).cuda() # Use GPU for faster inference
C. Running Code Generation
You can prompt the model to generate code. Here’s an example using QuickSort:
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))
This will generate a Python implementation of QuickSort.
4. Running DeepSeek Coder Locally
If you want to run the model efficiently on your system, consider using GGUF format models with llama.cpp
or text-generation-webui
.
A. Running with llama.cpp
./main -m deepseek-coder-1.3b-instruct.gguf -p "Write a Python function to check if a number is prime."
B. Running with text-generation-webui
- Download the GGUF model from DeepSeek Repository.
- Load it into
text-generation-webui
and start inference.
5. License and Commercial Use
- The code is licensed under MIT.
- The model has a separate Model License allowing commercial use.
6. Conclusion
DeepSeek Coder 1.3B is a powerful AI coding assistant that supports code generation, completion, and infilling. It can be run on your local machine with PyTorch or optimized with GGUF format for efficiency.