Instructions to use unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit") model = AutoModelForCausalLM.from_pretrained("unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit", 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit
- SGLang
How to use unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit 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 "unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit" \ --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": "unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit", "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 "unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit" \ --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": "unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit", max_seq_length=2048, ) - Docker Model Runner
How to use unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit with Docker Model Runner:
docker model run hf.co/unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit
VLLM with error Blockwise quantization only supports 16/32-bit floats, but got torch.uint8
I ran the VLLM service command the same as the document example as well as in the discussion but get error
INFO 01-31 07:17:38 loader.py:1059] Loading weights with BitsAndBytes quantization. May take a while ...
INFO 01-31 07:17:38 weight_utils.py:251] Using model weights format ['*.safetensors']
Loading safetensors checkpoint shards: 0% Completed | 0/4 [00:00<?, ?it/s]
Loading safetensors checkpoint shards: 0% Completed | 0/4 [00:00<?, ?it/s]
ERROR 01-31 07:17:39 engine.py:387] Blockwise quantization only supports 16/32-bit floats, but got torch.uint8
ERROR 01-31 07:17:39 engine.py:387] Traceback (most recent call last):
ERROR 01-31 07:17:39 engine.py:387] File "/root/miniconda3/envs/Chloe/lib/python3.10/site-packages/vllm/engine/multiprocessing/engine.py", line 378, in run_mp_engine
ERROR 01-31 07:17:39 engine.py:387] engine = MQLLMEngine.from_engine_args(engine_args=engine_args,
ERROR 01-31 07:17:39 engine.py:387] File "/root/miniconda3/envs/Chloe/lib/python3.10/site-packages/vllm/engine/multiprocessing/engine.py", line 121, in from_engine_args
ERROR 01-31 07:17:39 engine.py:387] return cls(ipc_path=ipc_path,
This is the command I ran
vllm serve
"unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit"
--load-format bitsandbytes
--quantization bitsandbytes
--max-model-len=8192
--gpu-memory-utilization=0.99
--host 0.0.0.0
--port 8000
I ran the VLLM service command the same as the document example as well as in the discussion but get error
INFO 01-31 07:17:38 loader.py:1059] Loading weights with BitsAndBytes quantization. May take a while ...
INFO 01-31 07:17:38 weight_utils.py:251] Using model weights format ['*.safetensors']
Loading safetensors checkpoint shards: 0% Completed | 0/4 [00:00<?, ?it/s]
Loading safetensors checkpoint shards: 0% Completed | 0/4 [00:00<?, ?it/s]ERROR 01-31 07:17:39 engine.py:387] Blockwise quantization only supports 16/32-bit floats, but got torch.uint8
ERROR 01-31 07:17:39 engine.py:387] Traceback (most recent call last):
ERROR 01-31 07:17:39 engine.py:387] File "/root/miniconda3/envs/Chloe/lib/python3.10/site-packages/vllm/engine/multiprocessing/engine.py", line 378, in run_mp_engine
ERROR 01-31 07:17:39 engine.py:387] engine = MQLLMEngine.from_engine_args(engine_args=engine_args,
ERROR 01-31 07:17:39 engine.py:387] File "/root/miniconda3/envs/Chloe/lib/python3.10/site-packages/vllm/engine/multiprocessing/engine.py", line 121, in from_engine_args
ERROR 01-31 07:17:39 engine.py:387] return cls(ipc_path=ipc_path,This is the command I ran
vllm serve
"unsloth/DeepSeek-R1-Distill-Qwen-32B-bnb-4bit"
--load-format bitsandbytes
--quantization bitsandbytes
--max-model-len=8192
--gpu-memory-utilization=0.99
--host 0.0.0.0
--port 8000
oh weird the bnb version should work since it's just qwen, could you file a ticket on their github issue?
So that means I should could ran the VLLM with this bnb-4bit model?
I ran into this problem with the Llama-70B-bnb-4bit model.
I think the problem is that there's no quantization_config key in the config.json, so vllm tries to requantize the model weights, leading to this error. To stop the error, I manually added the quantization_config from the previous distillation to config.json that was downloaded.
For Llama-70B-bnb-4bit, I copied it from here
"quantization_config": {
"_load_in_4bit": true,
"_load_in_8bit": false,
"bnb_4bit_compute_dtype": "bfloat16",
"bnb_4bit_quant_storage": "uint8",
"bnb_4bit_quant_type": "nf4",
"bnb_4bit_use_double_quant": true,
"llm_int8_enable_fp32_cpu_offload": false,
"llm_int8_has_fp16_weight": false,
"llm_int8_skip_modules": [
"lm_head",
"multi_modal_projector",
"merger",
"modality_projection"
],
"llm_int8_threshold": 6.0,
"load_in_4bit": true,
"load_in_8bit": false,
"quant_method": "bitsandbytes"
},
For Qwen-32B-bnb-4bit, I would think it's this one:
"quantization_config": {
"_load_in_4bit": true,
"_load_in_8bit": false,
"bnb_4bit_compute_dtype": "bfloat16",
"bnb_4bit_quant_storage": "uint8",
"bnb_4bit_quant_type": "nf4",
"bnb_4bit_use_double_quant": true,
"llm_int8_enable_fp32_cpu_offload": false,
"llm_int8_has_fp16_weight": false,
"llm_int8_skip_modules": null,
"llm_int8_threshold": 6.0,
"load_in_4bit": true,
"load_in_8bit": false,
"quant_method": "bitsandbytes"
},
All that said, I'm not sure if the same quantization configs were used for the distilled models though, so it would be great if someone from unsloth could confirm. @shimmyshimmer
Yes, that would be great if someone from unsloth could confirm. : ) I get ERROR 02-01 22:35:23 engine.py:387] start (0) + length (6912) exceeds dimension size (1). after adding "quantization_config": {
"_load_in_4bit": true,
"_load_in_8bit": false,
"bnb_4bit_compute_dtype": "bfloat16",
"bnb_4bit_quant_storage": "uint8",
"bnb_4bit_quant_type": "nf4",
"bnb_4bit_use_double_quant": true,
"llm_int8_enable_fp32_cpu_offload": false,
"llm_int8_has_fp16_weight": false,
"llm_int8_skip_modules": null,
"llm_int8_threshold": 6.0,
"load_in_4bit": true,
"load_in_8bit": false,
"quant_method": "bitsandbytes"
}, in config.json
I ran into this problem with the Llama-70B-bnb-4bit model.
I think the problem is that there's no
quantization_configkey in theconfig.json, so vllm tries to requantize the model weights, leading to this error. To stop the error, I manually added the quantization_config from the previous distillation toconfig.jsonthat was downloaded.For Llama-70B-bnb-4bit, I copied it from here
"quantization_config": { "_load_in_4bit": true, "_load_in_8bit": false, "bnb_4bit_compute_dtype": "bfloat16", "bnb_4bit_quant_storage": "uint8", "bnb_4bit_quant_type": "nf4", "bnb_4bit_use_double_quant": true, "llm_int8_enable_fp32_cpu_offload": false, "llm_int8_has_fp16_weight": false, "llm_int8_skip_modules": [ "lm_head", "multi_modal_projector", "merger", "modality_projection" ], "llm_int8_threshold": 6.0, "load_in_4bit": true, "load_in_8bit": false, "quant_method": "bitsandbytes" },For Qwen-32B-bnb-4bit, I would think it's this one:
"quantization_config": { "_load_in_4bit": true, "_load_in_8bit": false, "bnb_4bit_compute_dtype": "bfloat16", "bnb_4bit_quant_storage": "uint8", "bnb_4bit_quant_type": "nf4", "bnb_4bit_use_double_quant": true, "llm_int8_enable_fp32_cpu_offload": false, "llm_int8_has_fp16_weight": false, "llm_int8_skip_modules": null, "llm_int8_threshold": 6.0, "load_in_4bit": true, "load_in_8bit": false, "quant_method": "bitsandbytes" },All that said, I'm not sure if the same quantization configs were used for the distilled models though, so it would be great if someone from unsloth could confirm. @shimmyshimmer
Did you revise any other files or only config.json?
@ChloeHuang1 @blnewman-uw thanks a lot guys we fixed the problem and reuploaded the models so good catch finding it out! :)