Instructions to use deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct
- SGLang
How to use deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct with Docker Model Runner:
docker model run hf.co/deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct
Mismatch between weight files and model architecture
I have noticed the model architecture contains some layers for which no weights exist in the 4 weights files.
First, here's the architecture of the model I am referring to.
DeepseekV2ForCausalLM(
(model): DeepseekV2Model(
(embed_tokens): Embedding(102400, 4096)
(layers): ModuleList(
(0-29): 30 x DeepseekV2DecoderLayer(
(self_attn): DeepseekV2Attention(
(q_a_proj): Linear(in_features=4096, out_features=1536, bias=False)
(q_a_layernorm): DeepseekV2RMSNorm()
(q_b_proj): Linear(in_features=1536, out_features=6144, bias=False)
(kv_a_proj_with_mqa): Linear(in_features=4096, out_features=576, bias=False)
(kv_a_layernorm): DeepseekV2RMSNorm()
(kv_b_proj): Linear(in_features=512, out_features=8192, bias=False)
(o_proj): Linear(in_features=4096, out_features=4096, bias=False)
(rotary_emb): DeepseekV2RotaryEmbedding()
)
(mlp): DeepseekV2MLP(
(gate_proj): Linear(in_features=4096, out_features=11008, bias=False)
(up_proj): Linear(in_features=4096, out_features=11008, bias=False)
(down_proj): Linear(in_features=11008, out_features=4096, bias=False)
(act_fn): SiLU()
)
(input_layernorm): DeepseekV2RMSNorm()
(post_attention_layernorm): DeepseekV2RMSNorm()
)
)
(norm): DeepseekV2RMSNorm()
)
(lm_head): Linear(in_features=4096, out_features=102400, bias=False)
)
The weights files include the weight for layers like 'model.layers.0.self_attn.q_proj.weight' which abviously does not exist in the above model architecture. The closest thing to this naming in the architecture is 'model.layers.0.self_attnq_a_proj' which is a linear layer : Linear(in_features=4096, out_features=1536, bias=False).
I inspected the shape of 'model.layers.0.self_attn.q_proj.weight' and found it to be torch.Size([3072, 2048])
My question is why do such weights exist in the weight files that do not have a place in the architecture? how to find the weights for the layers in the architecture that do not exist in the weights files.
There might be an issue in my understanding so please excuse me. Thank you so much.