Instructions to use deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B") model = AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B") 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]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B" # 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-R1-Distill-Qwen-1.5B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B
- SGLang
How to use deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B 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-R1-Distill-Qwen-1.5B" \ --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-R1-Distill-Qwen-1.5B", "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-R1-Distill-Qwen-1.5B" \ --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-R1-Distill-Qwen-1.5B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B with Docker Model Runner:
docker model run hf.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B
Failed to load the model
🥲 Failed to load the model
Failed to load model
llama.cpp error: 'error loading model vocabulary: unknown pre-tokenizer type: 'deepseek-r1-qwen''
on LM studio 0.3.8
if you are trying to load deepseek r1 qwen distll.. this I crated and works fine. I can chat with the model. # -- coding: utf-8 --
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
Set the path to the locally downloaded model directory
MODEL_PATH = "F:/Deepseek1.5" # Change this to your actual path
Load the tokenizer from the local directory
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
Load the model from local files
device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModelForCausalLM.from_pretrained(
MODEL_PATH,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
trust_remote_code=True # Enables loading custom DeepSeek model code
)
Move model to the available device
model.to(device)
def chat_with_model(history, max_length=150, temperature=0.7, top_p=0.9, repetition_penalty=1.2):
"""Generate chatbot response while managing history effectively."""
# Keep only the last few exchanges for context (prevents infinite history buildup)
MAX_HISTORY_LENGTH = 1000 # Adjust based on available memory
if len(history) > MAX_HISTORY_LENGTH:
history = history[-MAX_HISTORY_LENGTH:]
inputs = tokenizer(history, return_tensors="pt", truncation=True, max_length=4096).to(device)
with torch.no_grad():
output = model.generate(
**inputs,
max_new_tokens=max_length,
temperature=temperature, # Controls randomness (higher = more creative)
top_p=top_p, # Nucleus sampling for diversity
repetition_penalty=repetition_penalty, # Reduces repeated phrases
pad_token_id=tokenizer.eos_token_id # Fixes padding issue
)
response = tokenizer.decode(output[0], skip_special_tokens=True)
# Extract only new model-generated text (remove repeated history)
response = response[len(history):].strip()
# Stop the model from going off-track
response = response.split("\n")[0] # Keep only the first response line
return response
Interactive chat loop
if name == "main":
print("\n🤖 DeepSeek Chatbot: Type 'exit', 'quit', or 'bye' to end the chat.\n")
history = "" # Keeps conversation history
while True:
user_input = input("You: ")
if user_input.lower() in ["exit", "quit", "bye"]:
print("DeepSeek: Goodbye! 👋")
break
# Append user input to history
history += f"\nYou: {user_input}\nDeepSeek:"
# Generate response
response = chat_with_model(history)
# Display response
print(f"DeepSeek: {response}")
# Append response to history for continuity
history += f" {response}"