Instructions to use webnn/DeepSeek-R1-Distill-ONNX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use webnn/DeepSeek-R1-Distill-ONNX with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="webnn/DeepSeek-R1-Distill-ONNX") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("webnn/DeepSeek-R1-Distill-ONNX", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use webnn/DeepSeek-R1-Distill-ONNX with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "webnn/DeepSeek-R1-Distill-ONNX" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "webnn/DeepSeek-R1-Distill-ONNX", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/webnn/DeepSeek-R1-Distill-ONNX
- SGLang
How to use webnn/DeepSeek-R1-Distill-ONNX 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 "webnn/DeepSeek-R1-Distill-ONNX" \ --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": "webnn/DeepSeek-R1-Distill-ONNX", "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 "webnn/DeepSeek-R1-Distill-ONNX" \ --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": "webnn/DeepSeek-R1-Distill-ONNX", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use webnn/DeepSeek-R1-Distill-ONNX with Docker Model Runner:
docker model run hf.co/webnn/DeepSeek-R1-Distill-ONNX
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,109 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
pipeline_tag: text-generation
|
| 4 |
+
tags:
|
| 5 |
+
- ONNX
|
| 6 |
+
- ONNXRuntime
|
| 7 |
+
license: mit
|
| 8 |
+
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
## DeepSeek-R1-Distill-Qwen ONNX models
|
| 12 |
+
|
| 13 |
+
https://huggingface.co/onnxruntime/DeepSeek-R1-Distill-ONNX/resolve/main/deepseek-r1-distill-qwen-1.5B/gpu/gpu-int4-rtn-block-32/
|
| 14 |
+
|
| 15 |
+
This repository hosts the optimized versions of [DeepSeek-R1-Distill-Qwen-1.5B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B/) and [DeepSeek-R1-Distill-Qwen-7B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B/) to accelerate inference with ONNX Runtime.
|
| 16 |
+
Optimized models are published here in [ONNX](https://onnx.ai) format to run with [ONNX Runtime](https://onnxruntime.ai/) on CPU and GPU across devices, including server platforms, Windows, Linux and Mac desktops, and mobile CPUs, with the precision best suited to each of these targets.
|
| 17 |
+
|
| 18 |
+
To easily get started with the model, you can use our ONNX Runtime Generate() API. See instructions [here](https://github.com/microsoft/onnxruntime/blob/gh-pages/docs/genai/tutorials/deepseek-python.md)
|
| 19 |
+
|
| 20 |
+
For CPU:
|
| 21 |
+
|
| 22 |
+
```bash
|
| 23 |
+
# Download the model directly using the Hugging Face CLI
|
| 24 |
+
huggingface-cli download onnxruntime/DeepSeek-R1-Distill-ONNX --include deepseek-r1-distill-qwen-1.5B/cpu_and_mobile/* --local-dir .
|
| 25 |
+
|
| 26 |
+
# Install the CPU package of ONNX Runtime GenAI
|
| 27 |
+
pip install onnxruntime-genai
|
| 28 |
+
|
| 29 |
+
# Please adjust the model directory (-m) accordingly
|
| 30 |
+
curl -o https://raw.githubusercontent.com/microsoft/onnxruntime-genai/refs/heads/main/examples/python/model-chat.py
|
| 31 |
+
python model-chat.py -m /path/to/cpu-int4-rtn-block-32-acc-level-4/ -e cpu --chat_template "<|begin▁of▁sentence|><|User|>{input}<|Assistant|>"
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
For CUDA:
|
| 35 |
+
|
| 36 |
+
```bash
|
| 37 |
+
# Download the model directly using the Hugging Face CLI
|
| 38 |
+
huggingface-cli download onnxruntime/DeepSeek-R1-Distill-ONNX --include deepseek-r1-distill-qwen-1.5B/gpu/* --local-dir .
|
| 39 |
+
|
| 40 |
+
# Install the CUDA package of ONNX Runtime GenAI
|
| 41 |
+
pip install onnxruntime-genai-cuda
|
| 42 |
+
|
| 43 |
+
# Please adjust the model directory (-m) accordingly
|
| 44 |
+
curl -o https://raw.githubusercontent.com/microsoft/onnxruntime-genai/refs/heads/main/examples/python/model-chat.py
|
| 45 |
+
python model-chat.py -m /path/to/gpu-int4-rtn-block-32/ -e cuda --chat_template "<|begin▁of▁sentence|><|User|>{input}<|Assistant|>"
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
For DirectML:
|
| 49 |
+
|
| 50 |
+
```bash
|
| 51 |
+
# Download the model directly using the Hugging Face CLI
|
| 52 |
+
huggingface-cli download onnxruntime/DeepSeek-R1-Distill-ONNX --include deepseek-r1-distill-qwen-1.5B/gpu/* --local-dir .
|
| 53 |
+
|
| 54 |
+
# Install the DirectML package of ONNX Runtime GenAI
|
| 55 |
+
pip install onnxruntime-genai-directml
|
| 56 |
+
|
| 57 |
+
# Please adjust the model directory (-m) accordingly
|
| 58 |
+
curl -o https://raw.githubusercontent.com/microsoft/onnxruntime-genai/refs/heads/main/examples/python/model-chat.py
|
| 59 |
+
python model-chat.py -m /path/to/gpu-int4-rtn-block-32/ -e dml --chat_template "<|begin▁of▁sentence|><|User|>{input}<|Assistant|>"
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
## ONNX Models
|
| 64 |
+
Here are some of the optimized configurations we have added:
|
| 65 |
+
|
| 66 |
+
1. ONNX model for CPU and mobile using int4 quantization via RTN.
|
| 67 |
+
2. ONNX model for GPU using int4 quantization via RTN.
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
## Performance
|
| 71 |
+
|
| 72 |
+
ONNX enables you to run your models on-device across CPU, GPU, NPU. With ONNX, you can run your models on any machine across all silica (Qualcomm, AMD, Intel, Nvidia, etc).
|
| 73 |
+
|
| 74 |
+
See the table below for some key benchmarks for Windows GPU and CPU devices that the ONNX models were tested on.
|
| 75 |
+
| **Model** | **Precisionl** | **Device Type** | **Execution Provider** | **Device** | **Token Generation Throughput** | **Speed up vs base model**|
|
| 76 |
+
| :------------: | :------------: | :------------: | :------------: | :------------: | :------------: | :------------:|
|
| 77 |
+
| deepseek-ai_DeepSeek-R1-Distill-Qwen-1.5B | ONNX | fp16 | CUDA | RTX 4090 | 197.195 | 4X |
|
| 78 |
+
| deepseek-ai_DeepSeek-R1-Distill-Qwen-1.5B | ONNX | int4 | CUDA | RTX 4090 | 313.32 | 6.3X |
|
| 79 |
+
| deepseek-ai_DeepSeek-R1-Distill-Qwen-1.5B | ONNX | int4 | CPU | Intel i9 | 11.749 | 1.4x |
|
| 80 |
+
| deepseek-ai_DeepSeek-R1-Distill-Qwen-7B | ONNX | fp16 | CUDA | RTX 4090 | 57.316 | 1.3X |
|
| 81 |
+
| deepseek-ai_DeepSeek-R1-Distill-Qwen-7B | ONNX | int4 | CUDA | RTX 4090 | 161.00 | 3.7X |
|
| 82 |
+
| deepseek-ai_DeepSeek-R1-Distill-Qwen-7B | ONNX | int4 | CPU | Intel i9 | 3.184 | 20X |
|
| 83 |
+
|
| 84 |
+
CPU build specs:
|
| 85 |
+
|
| 86 |
+
- onnxruntime-genai==0.6.0-dev
|
| 87 |
+
- transformers==4.46.2
|
| 88 |
+
- onnxruntime==1.20.01
|
| 89 |
+
|
| 90 |
+
CUDA build specs:
|
| 91 |
+
|
| 92 |
+
- onnxruntime-genai-cuda==0.6.0-dev
|
| 93 |
+
- transformers==4.46.2
|
| 94 |
+
- onnxruntime-gpu==1.20.1
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
## Model Description
|
| 98 |
+
|
| 99 |
+
- **Developed by:** ONNX Runtime
|
| 100 |
+
- **Model type:** ONNX
|
| 101 |
+
- **Language(s) (NLP):** Python, C, C++
|
| 102 |
+
- **License:** MIT
|
| 103 |
+
- **Model Description:** This is a conversion of the Deepseek R1 for ONNX Runtime inference.
|
| 104 |
+
- **Disclaimer:** Model is only an optimization of the base model, any risk associated with the model is the responsibility of the user of the model. Please verify and test for you scenarios. There may be a slight difference in output from the base model with the optimizations applied. **
|
| 105 |
+
|
| 106 |
+
## Base Model Information
|
| 107 |
+
|
| 108 |
+
See HF links [DeepSeek-R1-Distill-Qwen-1.5B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B/) and [DeepSeek-R1-Distill-Qwen-7B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B/) for details.
|
| 109 |
+
|