Text Generation
Transformers
Safetensors
deepseek_v3
conversational
custom_code
text-generation-inference
blockwise_int8
Instructions to use meituan/DeepSeek-R1-Block-INT8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use meituan/DeepSeek-R1-Block-INT8 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="meituan/DeepSeek-R1-Block-INT8", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("meituan/DeepSeek-R1-Block-INT8", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("meituan/DeepSeek-R1-Block-INT8", trust_remote_code=True) 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
- vLLM
How to use meituan/DeepSeek-R1-Block-INT8 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "meituan/DeepSeek-R1-Block-INT8" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "meituan/DeepSeek-R1-Block-INT8", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/meituan/DeepSeek-R1-Block-INT8
- SGLang
How to use meituan/DeepSeek-R1-Block-INT8 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 "meituan/DeepSeek-R1-Block-INT8" \ --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": "meituan/DeepSeek-R1-Block-INT8", "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 "meituan/DeepSeek-R1-Block-INT8" \ --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": "meituan/DeepSeek-R1-Block-INT8", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use meituan/DeepSeek-R1-Block-INT8 with Docker Model Runner:
docker model run hf.co/meituan/DeepSeek-R1-Block-INT8
Update inference/bf16_cast_block_int8.py
#7
by HandH1998 - opened
inference/bf16_cast_block_int8.py
CHANGED
|
@@ -3,6 +3,7 @@ import json
|
|
| 3 |
from argparse import ArgumentParser
|
| 4 |
from glob import glob
|
| 5 |
from tqdm import tqdm
|
|
|
|
| 6 |
|
| 7 |
import torch
|
| 8 |
from safetensors.torch import load_file, save_file
|
|
@@ -14,15 +15,40 @@ def main(bf16_path, int8_path, model_name="deepseek-ai/DeepSeek-R1"):
|
|
| 14 |
torch.set_default_dtype(torch.bfloat16)
|
| 15 |
os.makedirs(int8_path, exist_ok=True)
|
| 16 |
model_index_file = os.path.join(int8_path, "model.safetensors.index.json")
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
snapshot_download(
|
| 20 |
repo_id=model_name,
|
| 21 |
-
|
| 22 |
local_dir=int8_path,
|
| 23 |
local_dir_use_symlinks=False
|
| 24 |
)
|
| 25 |
-
print(f"model index file downloaded to {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
with open(model_index_file, "r") as f:
|
| 28 |
model_index = json.load(f)
|
|
@@ -60,4 +86,3 @@ if __name__ == "__main__":
|
|
| 60 |
args = parser.parse_args()
|
| 61 |
main(args.input_bf16_hf_path, args.output_int8_hf_path, args.model_name)
|
| 62 |
print("done")
|
| 63 |
-
|
|
|
|
| 3 |
from argparse import ArgumentParser
|
| 4 |
from glob import glob
|
| 5 |
from tqdm import tqdm
|
| 6 |
+
import json
|
| 7 |
|
| 8 |
import torch
|
| 9 |
from safetensors.torch import load_file, save_file
|
|
|
|
| 15 |
torch.set_default_dtype(torch.bfloat16)
|
| 16 |
os.makedirs(int8_path, exist_ok=True)
|
| 17 |
model_index_file = os.path.join(int8_path, "model.safetensors.index.json")
|
| 18 |
+
config_file = os.path.join(int8_path, "config.json")
|
| 19 |
+
|
| 20 |
+
if not os.path.exists(model_index_file) or not os.path.exists(config_file):
|
| 21 |
snapshot_download(
|
| 22 |
repo_id=model_name,
|
| 23 |
+
ignore_patterns=["*.safetensors"],
|
| 24 |
local_dir=int8_path,
|
| 25 |
local_dir_use_symlinks=False
|
| 26 |
)
|
| 27 |
+
print(f"model index file and config file downloaded to {int8_path}")
|
| 28 |
+
|
| 29 |
+
# modify config.json and save it
|
| 30 |
+
config = json.load(open(config_file))
|
| 31 |
+
if "quantization_config" in config:
|
| 32 |
+
quant_config = config["quantization_config"]
|
| 33 |
+
quant_config.pop("fmt", None)
|
| 34 |
+
quant_config["quant_method"] = "blockwise_int8"
|
| 35 |
+
quant_config["weight_block_size"] = [
|
| 36 |
+
128,
|
| 37 |
+
128
|
| 38 |
+
]
|
| 39 |
+
quant_config["activation_scheme"] = "dynamic"
|
| 40 |
+
else:
|
| 41 |
+
config["quantization_config"] = {
|
| 42 |
+
"activation_scheme": "dynamic",
|
| 43 |
+
"quant_method": "blockwise_int8",
|
| 44 |
+
"weight_block_size": [
|
| 45 |
+
128,
|
| 46 |
+
128
|
| 47 |
+
]
|
| 48 |
+
}
|
| 49 |
+
with open(config_file, "w", encoding="utf-8") as f:
|
| 50 |
+
json.dump(config, f, indent=2, ensure_ascii=False, sort_keys=True)
|
| 51 |
+
print(f"config.json modified and saved to {config_file}")
|
| 52 |
|
| 53 |
with open(model_index_file, "r") as f:
|
| 54 |
model_index = json.load(f)
|
|
|
|
| 86 |
args = parser.parse_args()
|
| 87 |
main(args.input_bf16_hf_path, args.output_int8_hf_path, args.model_name)
|
| 88 |
print("done")
|
|
|