🚀 DeepSeek-Coder-V2-Lite-Instruct-FP8
本項目是 DeepSeek-Coder-V2-Lite-Instruct 的量化版本,將權重和激活量化為 FP8 數據類型,可使用 vLLM >= 0.5.2 進行推理。該模型適用於英文的商業和研究用途,可用於類似助手的聊天場景。
🚀 快速開始
模型概述
屬性 |
詳情 |
模型類型 |
DeepSeek-Coder-V2-Lite-Instruct |
輸入 |
文本 |
輸出 |
文本 |
模型優化 |
權重量化:FP8;激活量化:FP8 |
預期用例 |
適用於英文的商業和研究用途,用於類似助手的聊天場景 |
不適用範圍 |
任何違反適用法律法規(包括貿易合規法律)的使用方式;非英文語言的使用 |
發佈日期 |
2024 年 7 月 18 日 |
版本 |
1.0 |
許可證 |
deepseek-license |
模型開發者 |
Neural Magic |
該量化版本在 HumanEval+ 基準測試中達到了 79.60 的平均分數,而未量化的模型為 79.33。
模型優化
此模型是通過將 DeepSeek-Coder-V2-Lite-Instruct 的權重和激活量化為 FP8 數據類型得到的,可使用 vLLM >= 0.5.2 進行推理。這種優化將每個參數的位數從 16 位減少到 8 位,使磁盤大小和 GPU 內存需求大約減少了 50%。
僅對 Transformer 塊內線性算子的權重和激活進行量化,採用對稱的逐張量量化,即使用單個線性縮放來映射量化權重和激活的 FP8 表示。使用 AutoFP8 對 512 個 UltraChat 序列進行量化。
📦 安裝指南
文檔未提及安裝步驟,此處跳過。
💻 使用示例
基礎用法
可以使用 vLLM 後端高效部署該模型,示例代碼如下:
from vllm import LLM, SamplingParams
from transformers import AutoTokenizer
model_id = "neuralmagic/DeepSeek-Coder-V2-Lite-Instruct-FP8"
sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
tokenizer = AutoTokenizer.from_pretrained(model_id)
messages = [
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
{"role": "user", "content": "Who are you?"},
]
prompts = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
llm = LLM(model=model_id, trust_remote_code=True, max_model_len=4096)
outputs = llm.generate(prompts, sampling_params)
generated_text = outputs[0].outputs[0].text
print(generated_text)
vLLM 還支持 OpenAI 兼容的服務,更多詳情請參閱 文檔。
🔧 技術細節
模型創建
該模型是通過應用 帶有來自 ultrachat 的校準樣本的 AutoFP8 創建的,專家門控保持原始精度,代碼示例如下:
from datasets import load_dataset
from transformers import AutoTokenizer
from auto_fp8 import AutoFP8ForCausalLM, BaseQuantizeConfig
pretrained_model_dir = "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct"
quantized_model_dir = "DeepSeek-Coder-V2-Lite-Instruct-FP8"
tokenizer = AutoTokenizer.from_pretrained(pretrained_model_dir, use_fast=True, model_max_length=4096)
tokenizer.pad_token = tokenizer.eos_token
ds = load_dataset("mgoin/ultrachat_2k", split="train_sft").select(range(512))
examples = [tokenizer.apply_chat_template(batch["messages"], tokenize=False) for batch in ds]
examples = tokenizer(examples, padding=True, truncation=True, return_tensors="pt").to("cuda")
quantize_config = BaseQuantizeConfig(
quant_method="fp8",
activation_scheme="static"
ignore_patterns=["re:.*lm_head"],
)
model = AutoFP8ForCausalLM.from_pretrained(
pretrained_model_dir, quantize_config=quantize_config
)
model.quantize(examples)
model.save_quantized(quantized_model_dir)
儘管此特定模型使用了 AutoFP8,但 Neural Magic 正在過渡到使用 llm-compressor,它支持多種量化方案和 AutoFP8 不支持的模型。
模型評估
該模型在 HumanEval+ 基準測試中進行了評估,使用 Neural Magic 分支 的 EvalPlus 實現的 HumanEval+ 和 vLLM 引擎,使用以下命令:
python codegen/generate.py --model neuralmagic/DeepSeek-Coder-V2-Lite-Instruct-FP8 --temperature 0.2 --n_samples 50 --resume --root ~ --dataset humaneval
python evalplus/sanitize.py ~/humaneval/neuralmagic--DeepSeek-Coder-V2-Lite-Instruct-FP8_vllm_temp_0.2
evalplus.evaluate --dataset humaneval --samples ~/humaneval/neuralmagic--DeepSeek-Coder-V2-Lite-Instruct-FP8_vllm_temp_0.2-sanitized
準確率
HumanEval+ 評估分數
基準測試 |
DeepSeek-Coder-V2-Lite-Instruct |
DeepSeek-Coder-V2-Lite-Instruct-FP8(本模型) |
恢復率 |
base pass@1 |
80.8 |
79.3 |
98.14% |
base pass@10 |
83.4 |
84.6 |
101.4% |
base+extra pass@1 |
75.8 |
74.9 |
98.81% |
base+extra pass@10 |
77.3 |
79.6 |
102.9% |
平均 |
79.33 |
79.60 |
100.3% |
📄 許可證
本項目使用 deepseek-license 許可證。