幻方發布全球最強MOE大模型! DeepSeek-V2
1. 介紹
今天,我們介紹了DeepSeek-V2,這是一個強大的專家混合(MoE)語言模型,其特點是訓練經濟且推理高效。它總共包含236B個參數,每個token激活21B個。與DeepSeek 67B相比,DeepSeek-V2實現了更強的性能,同時節省了42.5%的訓練成本,減少了93.3%的KV緩存,并將最大生成吞吐量提高了5.76倍。
圖片
圖片
我們在包含8.1萬億token的多樣化和高質量語料庫上預訓練了DeepSeek-V2。隨后,我們通過監督式微調(SFT)和強化學習(RL)的過程來充分釋放模型的潛力。評估結果驗證了我們方法的有效性,因為DeepSeek-V2在標準基準測試和開放式生成評估上都取得了顯著的性能。
2. 模型下載
由于HuggingFace的限制,當前開源代碼在GPU上運行時的性能比我們內部代碼庫慢。為了促進我們模型的有效執行,我們提供了一個專門的vllm解決方案,該解決方案優化了我們模型的運行性能。
Model | Context Length | Download |
DeepSeek-V2 | 128k | ?? HuggingFace |
DeepSeek-V2-Chat(RL) | 128k | ?? HuggingFace |
3. 評估結果
基礎模型
Benchmark | Domain | LLaMA3 70B | Mixtral 8x22B | DeepSeek V1 (Dense-67B) | DeepSeek V2 (MoE-236B) |
MMLU | English | 78.9 | 77.6 | 71.3 | 78.5 |
BBH | English | 81.0 | 78.9 | 68.7 | 78.9 |
C-Eval | Chinese | 67.5 | 58.6 | 66.1 | 81.7 |
CMMLU | Chinese | 69.3 | 60.0 | 70.8 | 84.0 |
HumanEval | Code | 52.4 | 39.0 | 42.7 | 40.9 |
MBPP | Code | 68.6 | 64.2 | 57.4 | 66.6 |
GSM8K | Math | 83.0 | 80.3 | 63.4 | 79.2 |
Math | Math | 42.2 | 42.5 | 18.7 | 43.6 |
在Needle In A Haystack (NIAH)測試中,DeepSeek-V2在所有上下文窗口長度上表現良好,直到128K。
圖片
chat模型
我們在AlpacaEval 2.0和MTBench上評估了我們的模型,展示了DeepSeek-V2-Chat-RL在英語對話生成上的競爭力。
Benchmark | Domain | QWen1.5 72B Chat | Mixtral 8x22B | LLaMA3 70B Instruct | DeepSeek V1 Chat (SFT) | DeepSeek V2 Chat(SFT) | DeepSeek V2 Chat(RL) |
MMLU | English | 76.2 | 77.8 | 80.3 | 71.1 | 78.4 | 77.8 |
BBH | English | 65.9 | 78.4 | 80.1 | 71.7 | 81.3 | 79.7 |
C-Eval | Chinese | 82.2 | 60.0 | 67.9 | 65.2 | 80.9 | 78.0 |
CMMLU | Chinese | 82.9 | 61.0 | 70.7 | 67.8 | 82.4 | 81.6 |
HumanEval | Code | 68.9 | 75.0 | 76.2 | 73.8 | 76.8 | 81.1 |
MBPP | Code | 52.2 | 64.4 | 69.8 | 61.4 | 70.4 | 72.0 |
LiveCodeBench (0901-0401) | Code | 18.8 | 25.0 | 30.5 | 18.3 | 28.7 | 32.5 |
GSM8K | Math | 81.9 | 87.9 | 93.2 | 84.1 | 90.8 | 92.2 |
Math | Math | 40.6 | 49.8 | 48.5 | 32.6 | 52.7 | 53.9 |
圖片
Chinese Open Ended Generation Evaluation
模型 | 開源/閉源 | 總分 | 中文推理 | 中文語言 |
gpt-4-1106-preview | 閉源 | 8.01 | 7.73 | 8.29 |
DeepSeek-V2 Chat(RL) | 開源 | 7.91 | 7.45 | 8.36 |
erniebot-4.0-202404(文心一言) | 閉源 | 7.89 | 7.61 | 8.17 |
DeepSeek-V2 Chat(SFT) | 開源 | 7.74 | 7.30 | 8.17 |
gpt-4-0613 | 閉源 | 7.53 | 7.47 | 7.59 |
erniebot-4.0-202312(文心一言) | 閉源 | 7.36 | 6.84 | 7.88 |
moonshot-v1-32k-202404(月之暗面) | 閉源 | 7.22 | 6.42 | 8.02 |
Qwen1.5-72B-Chat(通義千問) | 開源 | 7.19 | 6.45 | 7.93 |
DeepSeek-67B-Chat | 開源 | 6.43 | 5.75 | 7.11 |
Yi-34B-Chat(零一萬物) | 開源 | 6.12 | 4.86 | 7.38 |
gpt-3.5-turbo-0613 | 閉源 | 6.08 | 5.35 | 6.71 |
編碼基準測試
我們在LiveCodeBench (0901-0401)上評估了我們的模型,這是一個為實時編碼挑戰設計的基準測試。如圖所示,DeepSeek-V2在LiveCodeBench上展示了相當的熟練程度,其Pass@1得分超過了其他幾個復雜的模型。這一性能突出了模型在處理實時編碼任務方面的有效性。
圖片
4. 模型架構
DeepSeek-V2采用創新的架構以保證訓練經濟和推理高效:
- 對于注意力機制,我們設計了IEAttn,它使用低秩鍵值聯合壓縮來消除推理時鍵值緩存的瓶頸,從而支持高效推理。
- 對于前饋網絡(FFNs),我們采用了DeepSeekMoE架構,這是一種高性能的MoE架構,使我們能夠以更低的成本訓練更強的模型。
圖片
5. 聊天網站
你可以在DeepSeek的官方網站上與DeepSeek-V2進行聊天:chat.deepseek.com
6. API平臺
我們還提供與OpenAI兼容的API,可以在DeepSeek平臺上使用:platform.deepseek.com。注冊即可獲得數百萬免費token。你也可以按使用量付費,享受無與倫比的價格。
圖片
7. 如何本地運行
要使用BF16格式的DeepSeek-V2進行推理,需要80GB*8的GPU。
使用Huggingface的Transformers進行推理
你可以直接使用Huggingface的Transformers進行模型推理。
文本補全
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
model_name = "deepseek-ai/DeepSeek-V2"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
# `max_memory` 應根據你的設備設置
max_memory = {i: "75GB" for i in range(8)}
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True, device_map="auto", torch_dtype=torch.bfloat16, max_memory=max_memory)
model.generation_config = GenerationConfig.from_pretrained(model_name)
model.generation_config.pad_token_id = model.generation_config.eos_token_id
text = "An attention function can be described as mapping a query and a set of key-value pairs to an output, where the query, keys, values, and output are all vectors. The output is"
inputs = tokenizer(text, return_tensors="pt")
outputs = model.generate(**inputs.to(model.device), max_new_tokens=100)
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(result)
聊天補全
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
model_name = "deepseek-ai/DeepSeek-V2-Chat"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
# `max_memory` 應根據你的設備設置
max_memory = {i: "75GB" for i in range(8)}
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True, device_map="auto", torch_dtype=torch.bfloat16, max_memory=max_memory)
model.generation_config = GenerationConfig.from_pretrained(model_name)
model.generation_config.pad_token_id = model.generation_config.eos_token_id
messages = [
{"role": "user", "content": "Write a piece of quicksort code in C++"}
]
input_tensor = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
outputs = model.generate(input_tensor.to(model.device), max_new_tokens=100)
result = tokenizer.decode(outputs[0][input_tensor.shape[1]:], skip_special_tokens=True)
print(result)
完整的聊天模板可以在huggingface模型倉庫中的tokenizer_config.json找到。
一個聊天模板的示例如下:
<|begin of sentence|>User: {user_message_1}
Assistant: {assistant_message_1}<|end of sentence|>User: {user_message_2}
Assistant:
你也可以添加一個可選的系統消息:
<|begin of sentence|>{system_message}
User: {user_message_1}
Assistant: {assistant_message_1}<|end of sentence|>User: {user_message_2}
Assistant:
8. 許可證
此代碼庫在MIT許可證下授權。DeepSeek-V2基礎/聊天模型的使用受模型許可證的約束。DeepSeek-V2系列(包括基礎和聊天)支持商業用途。
9. 引用
@misc{deepseek-v2,
author = {DeepSeek-AI},
title = {DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model},
year = {2024},
note = {GitHub repository},
url = {https://github.com/deepseek-ai/deepseek-v2}
}