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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
tags:
|
| 5 |
+
- moe
|
| 6 |
+
- int4
|
| 7 |
+
- w4a16
|
| 8 |
+
- vllm
|
| 9 |
+
license: other
|
| 10 |
+
license_name: deepseek
|
| 11 |
+
license_link: https://github.com/deepseek-ai/DeepSeek-V2/blob/main/LICENSE-MODEL
|
| 12 |
+
library_name: transformers
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# DeepSeek-V2.5-1210-quantized.w4a16
|
| 16 |
+
|
| 17 |
+
## Model Overview
|
| 18 |
+
- **Model Architecture:** DeepSeek-V2.5-1210
|
| 19 |
+
- **Input:** Text
|
| 20 |
+
- **Output:** Text
|
| 21 |
+
- **Model Optimizations:**
|
| 22 |
+
- **Weight quantization:** INT4
|
| 23 |
+
- **Activation quantization:** None
|
| 24 |
+
- **Release Date:** 3/1/2025
|
| 25 |
+
- **Version:** 1.0
|
| 26 |
+
- **Model Developers:** Neural Magic
|
| 27 |
+
|
| 28 |
+
Quantized version of [DeepSeek-V2.5-1210](https://huggingface.co/deepseek-ai/DeepSeek-V2.5-1210).
|
| 29 |
+
It achieves an average score of 77.2 on the [OpenLLM](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard) benchmark (version 1), whereas the unquantized model achieves 77.82.
|
| 30 |
+
|
| 31 |
+
### Model Optimizations
|
| 32 |
+
|
| 33 |
+
This model was obtained by quantizing only the weights to INT4 data type, ready for inference with vLLM >= 0.5.2.
|
| 34 |
+
This optimization reduces the number of bits per parameter from 16 to 4, reducing the disk size and GPU memory requirements by approximately 75%. The weights of the linear operators within transformers blocks are quantized, except the MLP routers.
|
| 35 |
+
|
| 36 |
+
## Deployment
|
| 37 |
+
|
| 38 |
+
### Use with vLLM
|
| 39 |
+
|
| 40 |
+
This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
|
| 41 |
+
|
| 42 |
+
```python
|
| 43 |
+
from transformers import AutoTokenizer
|
| 44 |
+
from vllm import LLM, SamplingParams
|
| 45 |
+
|
| 46 |
+
max_model_len, tp_size = 4096, 2
|
| 47 |
+
model_name = "neuralmagic-ent/DeepSeek-V2.5-1210-quantized.w4a16"
|
| 48 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 49 |
+
llm = LLM(model=model_name, tensor_parallel_size=tp_size, max_model_len=max_model_len, trust_remote_code=True)
|
| 50 |
+
sampling_params = SamplingParams(temperature=0.3, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])
|
| 51 |
+
|
| 52 |
+
messages_list = [
|
| 53 |
+
[{"role": "user", "content": "Who are you? Please respond in pirate speak!"}],
|
| 54 |
+
]
|
| 55 |
+
|
| 56 |
+
prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]
|
| 57 |
+
|
| 58 |
+
outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)
|
| 59 |
+
|
| 60 |
+
generated_text = [output.outputs[0].text for output in outputs]
|
| 61 |
+
print(generated_text)
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
vLLM also supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
|
| 65 |
+
|
| 66 |
+
## Creation
|
| 67 |
+
|
| 68 |
+
This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below with the following command:
|
| 69 |
+
|
| 70 |
+
```bash
|
| 71 |
+
python quantize.py --model_path deepseek-ai/DeepSeek-V2.5-1210 --quant_path "output_dir" --calib_size 256 --dampening_frac 0.1 --observer minmax --actorder weight
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
```python
|
| 76 |
+
`from datasets import load_dataset
|
| 77 |
+
from transformers import AutoTokenizer
|
| 78 |
+
from llmcompressor.modifiers.quantization import GPTQModifier
|
| 79 |
+
from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot, apply
|
| 80 |
+
import argparse
|
| 81 |
+
from compressed_tensors.quantization import QuantizationScheme, QuantizationArgs, QuantizationType, QuantizationStrategy
|
| 82 |
+
from llmcompressor.transformers.compression.helpers import calculate_offload_device_map
|
| 83 |
+
import torch
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def parse_actorder(value):
|
| 87 |
+
# Interpret the input value for --actorder
|
| 88 |
+
if value.lower() == "false":
|
| 89 |
+
return False
|
| 90 |
+
elif value.lower() == "weight":
|
| 91 |
+
return "weight"
|
| 92 |
+
elif value.lower() == "group":
|
| 93 |
+
raise ValueError("group not supported for TP>1 and MoEs")
|
| 94 |
+
else:
|
| 95 |
+
raise argparse.ArgumentTypeError("Invalid value for --actorder. Use 'group' or 'False'.")
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
parser = argparse.ArgumentParser()
|
| 99 |
+
parser.add_argument('--model_path', type=str)
|
| 100 |
+
parser.add_argument('--quant_path', type=str)
|
| 101 |
+
parser.add_argument('--num_bits', type=int, default=4)
|
| 102 |
+
parser.add_argument('--sequential_update', type=bool, default=True)
|
| 103 |
+
parser.add_argument('--calib_size', type=int, default=256)
|
| 104 |
+
parser.add_argument('--dampening_frac', type=float, default=0.05)
|
| 105 |
+
parser.add_argument('--observer', type=str, default="minmax")
|
| 106 |
+
parser.add_argument(
|
| 107 |
+
'--actorder',
|
| 108 |
+
type=parse_actorder,
|
| 109 |
+
default=False, # Default value is False
|
| 110 |
+
help="Specify actorder as 'group' (string) or False (boolean)."
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
args = parser.parse_args()
|
| 114 |
+
|
| 115 |
+
device_map = calculate_offload_device_map(
|
| 116 |
+
args.model_path,
|
| 117 |
+
reserve_for_hessians=True,
|
| 118 |
+
num_gpus=torch.cuda.device_count(),
|
| 119 |
+
torch_dtype=torch.bfloat16,
|
| 120 |
+
trust_remote_code=True,
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
model = SparseAutoModelForCausalLM.from_pretrained(
|
| 124 |
+
args.model_path,
|
| 125 |
+
device_map=device_map,
|
| 126 |
+
torch_dtype=torch.bfloat16,
|
| 127 |
+
use_cache=False,
|
| 128 |
+
trust_remote_code=True,
|
| 129 |
+
)
|
| 130 |
+
tokenizer = AutoTokenizer.from_pretrained(args.model_path)
|
| 131 |
+
|
| 132 |
+
NUM_CALIBRATION_SAMPLES = args.calib_size
|
| 133 |
+
DATASET_ID = "garage-bAInd/Open-Platypus"
|
| 134 |
+
DATASET_SPLIT = "train"
|
| 135 |
+
ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
|
| 136 |
+
ds = ds.shuffle(seed=42).select(range(NUM_CALIBRATION_SAMPLES))
|
| 137 |
+
|
| 138 |
+
def preprocess(example):
|
| 139 |
+
concat_txt = example["instruction"] + "\n" + example["output"]
|
| 140 |
+
return {"text": concat_txt}
|
| 141 |
+
|
| 142 |
+
ds = ds.map(preprocess)
|
| 143 |
+
|
| 144 |
+
def tokenize(sample):
|
| 145 |
+
return tokenizer(
|
| 146 |
+
sample["text"],
|
| 147 |
+
padding=False,
|
| 148 |
+
truncation=False,
|
| 149 |
+
add_special_tokens=True,
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
ds = ds.map(tokenize, remove_columns=ds.column_names)
|
| 154 |
+
|
| 155 |
+
quant_scheme = QuantizationScheme(
|
| 156 |
+
targets=["Linear"],
|
| 157 |
+
weights=QuantizationArgs(
|
| 158 |
+
num_bits=args.num_bits,
|
| 159 |
+
type=QuantizationType.INT,
|
| 160 |
+
symmetric=True,
|
| 161 |
+
group_size=128,
|
| 162 |
+
strategy=QuantizationStrategy.GROUP,
|
| 163 |
+
observer=args.observer,
|
| 164 |
+
actorder=args.actorder
|
| 165 |
+
),
|
| 166 |
+
input_activations=None,
|
| 167 |
+
output_activations=None,
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
recipe = [
|
| 171 |
+
GPTQModifier(
|
| 172 |
+
targets=["Linear"],
|
| 173 |
+
ignore=["lm_head", "re:.*\.mlp\.gate$"],
|
| 174 |
+
sequential_update=args.sequential_update,
|
| 175 |
+
dampening_frac=args.dampening_frac,
|
| 176 |
+
config_groups={"group_0": quant_scheme},
|
| 177 |
+
)
|
| 178 |
+
]
|
| 179 |
+
oneshot(
|
| 180 |
+
model=model,
|
| 181 |
+
dataset=ds,
|
| 182 |
+
recipe=recipe,
|
| 183 |
+
num_calibration_samples=args.calib_size,
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
# Save to disk compressed.
|
| 187 |
+
SAVE_DIR = args.quant_path
|
| 188 |
+
model.save_pretrained(SAVE_DIR, save_compressed=True, skip_compression_stats=True)
|
| 189 |
+
tokenizer.save_pretrained(SAVE_DIR)
|
| 190 |
+
```
|
| 191 |
+
|
| 192 |
+
## Evaluation
|
| 193 |
+
|
| 194 |
+
The model was evaluated on OpenLLM Leaderboard [V1](https://huggingface.co/spaces/open-llm-leaderboard-old/open_llm_leaderboard) using the following command:
|
| 195 |
+
|
| 196 |
+
OpenLLM Leaderboard V1:
|
| 197 |
+
```
|
| 198 |
+
lm_eval \
|
| 199 |
+
--model vllm \
|
| 200 |
+
--model_args pretrained="neuralmagic-ent/DeepSeek-V2.5-1210-quantized.w4a16",dtype=float16,add_bos_token=True,max_model_len=4096,tensor_parallel_size=4,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True \
|
| 201 |
+
--tasks openllm \
|
| 202 |
+
--write_out \
|
| 203 |
+
--batch_size auto \
|
| 204 |
+
--output_path output_dir \
|
| 205 |
+
--show_config
|
| 206 |
+
```
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
### Accuracy
|
| 210 |
+
|
| 211 |
+
#### OpenLLM Leaderboard V1 evaluation scores
|
| 212 |
+
|
| 213 |
+
| Metric | deepseek-ai/DeepSeek-V2.5-1210 | neuralmagic-ent/DeepSeek-V2.5-1210-quantized.w4a16 |
|
| 214 |
+
|-----------------------------------------|:---------------------------------:|:-------------------------------------------:|
|
| 215 |
+
| ARC-Challenge (Acc-Norm, 25-shot) | 72.61 | 72.18 |
|
| 216 |
+
| GSM8K (Strict-Match, 5-shot) | 88.25 | 88.10 |
|
| 217 |
+
| HellaSwag (Acc-Norm, 10-shot) | 85.01 | 83.48 |
|
| 218 |
+
| MMLU (Acc, 5-shot) | 79.60 | 78.36 |
|
| 219 |
+
| TruthfulQA (MC2, 0-shot) | 57.18 | 57.01 |
|
| 220 |
+
| Winogrande (Acc, 5-shot) | 84.29 | 84.06 |
|
| 221 |
+
| **Average Score** | **77.82** | **77.20** |
|
| 222 |
+
| **Recovery** | **100.00** | **99.20** |
|
| 223 |
+
|