Text Generation
Transformers
Safetensors
MLX
deepseek_v3
conversational
custom_code
text-generation-inference
2-bit
Instructions to use mlx-community/DeepSeek-R1-2bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mlx-community/DeepSeek-R1-2bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mlx-community/DeepSeek-R1-2bit", trust_remote_code=True) 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("mlx-community/DeepSeek-R1-2bit", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("mlx-community/DeepSeek-R1-2bit", trust_remote_code=True, 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]:])) - MLX
How to use mlx-community/DeepSeek-R1-2bit with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("mlx-community/DeepSeek-R1-2bit") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- vLLM
How to use mlx-community/DeepSeek-R1-2bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mlx-community/DeepSeek-R1-2bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlx-community/DeepSeek-R1-2bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/mlx-community/DeepSeek-R1-2bit
- SGLang
How to use mlx-community/DeepSeek-R1-2bit 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 "mlx-community/DeepSeek-R1-2bit" \ --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": "mlx-community/DeepSeek-R1-2bit", "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 "mlx-community/DeepSeek-R1-2bit" \ --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": "mlx-community/DeepSeek-R1-2bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - MLX LM
How to use mlx-community/DeepSeek-R1-2bit with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "mlx-community/DeepSeek-R1-2bit"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "mlx-community/DeepSeek-R1-2bit" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8080/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlx-community/DeepSeek-R1-2bit", "messages": [ {"role": "user", "content": "Hello"} ] }' - Docker Model Runner
How to use mlx-community/DeepSeek-R1-2bit with Docker Model Runner:
docker model run hf.co/mlx-community/DeepSeek-R1-2bit
- Atomic Chat
Commit History
-
Fix chat_template crash when assistant message omits the `content` key
Verified signature## Fix `chat_template` to handle assistant messages without a `content` key **⚠️ This template will start crashing for every tool-calling user as soon as the next `transformers` release ships.** The upstream PR https://github.com/huggingface/transformers/pull/45422 normalizes message inputs by stripping `content=None` before rendering (`None` and absent are semantically identical, and `content=None` is exactly what the OpenAI API returns for tool-call-only messages). That normalization is correct, but it exposes a latent bug in this template: the `tool_calls` branch reads `message['content']` directly, which raises when the key is absent. Concretely, this code path is hit by **any tool-calling pipeline** (OpenAI-compatible servers, agent frameworks, function-calling demos) that produces assistant messages with `tool_calls` and no textual content. Today most of them happen to pass `content=None` explicitly and get away with it. After the transformers release, all of them break. ### …b079fcd
-
Delete model-00044-of-00044.safetensors
Verified signaturec121c74 -
Delete model-00043-of-00044.safetensors
Verified signaturee7401fb -
Delete model-00042-of-00044.safetensors
Verified signature3caf374 -
Delete model-00041-of-00044.safetensors
Verified signature1c1f1ea -
Delete model-00040-of-00044.safetensors
Verified signature2eceb14 -
Delete model-00039-of-00044.safetensors
Verified signature1786615 -
Delete model-00038-of-00044.safetensors
Verified signature4291af0 -
Delete model-00037-of-00044.safetensors
Verified signature28e8f59 -
Delete model-00036-of-00044.safetensors
Verified signaturef74ffaf -
Delete model-00035-of-00044.safetensors
Verified signaturef90a017 -
Delete model-00034-of-00044.safetensors
Verified signature26a4bf7 -
Delete model-00033-of-00044.safetensors
Verified signature2a3e9af -
Delete model-00032-of-00044.safetensors
Verified signaturefa48e5f -
Delete model-00031-of-00044.safetensors
Verified signature097cb53 -
Delete model-00030-of-00044.safetensors
Verified signature22c44c9 -
Delete model-00029-of-00044.safetensors
Verified signature933e8db -
Delete model-00028-of-00044.safetensors
Verified signature089e566 -
Delete model-00027-of-00044.safetensors
Verified signatureb9216cb -
Delete model-00026-of-00044.safetensors
Verified signature3faa882 -
Delete model-00025-of-00044.safetensors
Verified signature2e1ab1c -
Delete model-00024-of-00044.safetensors
Verified signature50cd9df -
Delete model-00023-of-00044.safetensors
Verified signature454c454 -
Delete model-00022-of-00044.safetensors
Verified signature8e145da -
Delete model-00021-of-00044.safetensors
Verified signature7e0cff2 -
Delete model-00020-of-00044.safetensors
Verified signature6e639af -
Delete model-00019-of-00044.safetensors
Verified signature08dfe8a -
Delete model-00018-of-00044.safetensors
Verified signature52e8f7c -
Delete model-00017-of-00044.safetensors
Verified signature47fc848 -
Delete model-00016-of-00044.safetensors
Verified signaturea25f170 -
Delete model-00007-of-00044.safetensors
Verified signature4cf21ed -
Delete model-00012-of-00044.safetensors
Verified signature0620d38 -
Delete model-00010-of-00044.safetensors
Verified signaturefab9a83 -
Delete model-00009-of-00044.safetensors
Verified signaturea55606b -
Delete model-00005-of-00044.safetensors
Verified signature264f16c -
Delete model-00015-of-00044.safetensors
Verified signature913ece3 -
Delete model-00014-of-00044.safetensors
Verified signature20fe147 -
Delete model-00013-of-00044.safetensors
Verified signature8ae67be -
Delete model-00011-of-00044.safetensors
Verified signature30451e8 -
Delete model-00008-of-00044.safetensors
Verified signatureaf5d658 -
Delete model-00006-of-00044.safetensors
Verified signaturee27a9f5 -
Delete model-00004-of-00044.safetensors
Verified signatureeb361e4 -
Delete model-00003-of-00044.safetensors
Verified signaturee7db54e -
Delete model-00002-of-00044.safetensors
Verified signatureb31aa13 -
Delete model-00001-of-00044.safetensors
Verified signature2c95b0a -
Add files using upload-large-folder tool
Verified signature88cc573
-
Delete .DS_Store
Verified signature2cb88fb
-
Add files using upload-large-folder tool
7054501 -
initial commit
Verified signaturefa79459