Instructions to use deepseek-ai/deepseek-math-7b-rl with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use deepseek-ai/deepseek-math-7b-rl with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="deepseek-ai/deepseek-math-7b-rl") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-math-7b-rl") model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-math-7b-rl", device_map="auto") 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use deepseek-ai/deepseek-math-7b-rl with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "deepseek-ai/deepseek-math-7b-rl" # 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-math-7b-rl", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/deepseek-ai/deepseek-math-7b-rl
- SGLang
How to use deepseek-ai/deepseek-math-7b-rl 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-math-7b-rl" \ --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-math-7b-rl", "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-math-7b-rl" \ --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-math-7b-rl", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use deepseek-ai/deepseek-math-7b-rl with Docker Model Runner:
docker model run hf.co/deepseek-ai/deepseek-math-7b-rl
Add cot instruction
Browse files
README.md
CHANGED
|
@@ -28,19 +28,24 @@ Here give some examples of how to use our model.
|
|
| 28 |
|
| 29 |
**Chat Completion**
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
```python
|
| 33 |
import torch
|
| 34 |
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
|
| 35 |
|
| 36 |
-
model_name = "deepseek-ai/deepseek-math-7b-
|
| 37 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 38 |
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
|
| 39 |
model.generation_config = GenerationConfig.from_pretrained(model_name)
|
| 40 |
model.generation_config.pad_token_id = model.generation_config.eos_token_id
|
| 41 |
|
| 42 |
messages = [
|
| 43 |
-
{"role": "user", "content": "what is the integral of x^2 from 0 to 2?"}
|
| 44 |
]
|
| 45 |
input_tensor = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
|
| 46 |
outputs = model.generate(input_tensor.to(model.device), max_new_tokens=100)
|
|
|
|
| 28 |
|
| 29 |
**Chat Completion**
|
| 30 |
|
| 31 |
+
❗❗❗ **Please use chain-of-thought prompt to test DeepSeekMath-Instruct and DeepSeekMath-RL:**
|
| 32 |
+
|
| 33 |
+
- English questions: **{question}\nPlease reason step by step, and put your final answer within \\boxed{}.**
|
| 34 |
+
|
| 35 |
+
- Chinese questions: **{question}\n请通过逐步推理来解答问题,并把最终答案放置于\\boxed{}中。**
|
| 36 |
|
| 37 |
```python
|
| 38 |
import torch
|
| 39 |
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
|
| 40 |
|
| 41 |
+
model_name = "deepseek-ai/deepseek-math-7b-instruct"
|
| 42 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 43 |
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
|
| 44 |
model.generation_config = GenerationConfig.from_pretrained(model_name)
|
| 45 |
model.generation_config.pad_token_id = model.generation_config.eos_token_id
|
| 46 |
|
| 47 |
messages = [
|
| 48 |
+
{"role": "user", "content": "what is the integral of x^2 from 0 to 2?\nPlease reason step by step, and put your final answer within \\boxed{}."}
|
| 49 |
]
|
| 50 |
input_tensor = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
|
| 51 |
outputs = model.generate(input_tensor.to(model.device), max_new_tokens=100)
|