幻方发布全球最强MOE大模型! DeepSeek-V2

outside_default.png
仓库和技术报告地址:https://github.com/deepseek-ai/DeepSeek-V2

来自:包包算法笔记
EMNLP2024投稿群建立!

1. 介绍

今天,我们介绍了DeepSeek-V2,这是一个强大的专家混合(MoE)语言模型,其特点是训练经济且推理高效。它总共包含236B个参数,每个token激活21B个。与DeepSeek 67B相比,DeepSeek-V2实现了更强的性能,同时节省了42.5%的训练成本,减少了93.3%的KV缓存,并将最大生成吞吐量提高了5.76倍。

6d7c346992a18b804f0e28ad82fc3c70.png dd8448dc870eb51c0e07f1492d8a86f0.png

我们在包含8.1万亿token的多样化和高质量语料库上预训练了DeepSeek-V2。随后,我们通过监督式微调(SFT)和强化学习(RL)的过程来充分释放模型的潜力。评估结果验证了我们方法的有效性,因为DeepSeek-V2在标准基准测试和开放式生成评估上都取得了显著的性能。

2. 模型下载

由于HuggingFace的限制,当前开源代码在GPU上运行时的性能比我们内部代码库慢。为了促进我们模型的有效执行,我们提供了一个专门的vllm解决方案,该解决方案优化了我们模型的运行性能。

ModelContext LengthDownload
DeepSeek-V2128k🤗 HuggingFace
DeepSeek-V2-Chat(RL)128k🤗 HuggingFace

3. 评估结果

基础模型

BenchmarkDomainLLaMA3 70BMixtral 8x22BDeepSeek V1 (Dense-67B)DeepSeek V2 (MoE-236B)
MMLUEnglish78.977.671.378.5
BBHEnglish81.078.968.778.9
C-EvalChinese67.558.666.181.7
CMMLUChinese69.360.070.884.0
HumanEvalCode52.439.042.740.9
MBPPCode68.664.257.466.6
GSM8KMath83.080.363.479.2
MathMath42.242.518.743.6

Needle In A Haystack (NIAH)测试中,DeepSeek-V2在所有上下文窗口长度上表现良好,直到128K

4b77d2a27d80417fec8bd5e00dd29f23.png

chat模型

我们在AlpacaEval 2.0和MTBench上评估了我们的模型,展示了DeepSeek-V2-Chat-RL在英语对话生成上的竞争力。

BenchmarkDomainQWen1.5 72B ChatMixtral 8x22BLLaMA3 70B InstructDeepSeek V1 Chat (SFT)DeepSeek V2 Chat(SFT)DeepSeek V2 Chat(RL)
MMLUEnglish76.277.880.371.178.477.8
BBHEnglish65.978.480.171.781.379.7
C-EvalChinese82.260.067.965.280.978.0
CMMLUChinese82.961.070.767.882.481.6
HumanEvalCode68.975.076.273.876.881.1
MBPPCode52.264.469.861.470.472.0
LiveCodeBench  (0901-0401)Code18.825.030.518.328.732.5
GSM8KMath81.987.993.284.190.892.2
MathMath40.649.848.532.652.753.9
a678783e664073c858502f4ec7a41b7c.png

Chinese Open Ended Generation Evaluation

模型开源/闭源总分中文推理中文语言
gpt-4-1106-preview闭源8.017.738.29
DeepSeek-V2 Chat(RL)开源7.917.458.36
erniebot-4.0-202404(文心一言)闭源7.897.618.17
DeepSeek-V2 Chat(SFT)开源7.747.308.17
gpt-4-0613闭源7.537.477.59
erniebot-4.0-202312(文心一言)闭源7.366.847.88
moonshot-v1-32k-202404(月之暗面)闭源7.226.428.02
Qwen1.5-72B-Chat(通义千问)开源7.196.457.93
DeepSeek-67B-Chat开源6.435.757.11
Yi-34B-Chat(零一万物)开源6.124.867.38
gpt-3.5-turbo-0613闭源6.085.356.71

编码基准测试

我们在LiveCodeBench (0901-0401)上评估了我们的模型,这是一个为实时编码挑战设计的基准测试。如图所示,DeepSeek-V2在LiveCodeBench上展示了相当的熟练程度,其Pass@1得分超过了其他几个复杂的模型。这一性能突出了模型在处理实时编码任务方面的有效性。

dae7e7f1001d88fb266f8f30e0e63dc4.png

4. 模型架构

DeepSeek-V2采用创新的架构以保证训练经济和推理高效:

  • 对于注意力机制,我们设计了IEAttn,它使用低秩键值联合压缩来消除推理时键值缓存的瓶颈,从而支持高效推理。

  • 对于前馈网络(FFNs),我们采用了DeepSeekMoE架构,这是一种高性能的MoE架构,使我们能够以更低的成本训练更强的模型。

49e08a81f90a865042d63e6266088003.png

5. 聊天网站

你可以在DeepSeek的官方网站上与DeepSeek-V2进行聊天:chat.deepseek.com

6. API平台

我们还提供与OpenAI兼容的API,可以在DeepSeek平台上使用:platform.deepseek.com。注册即可获得数百万免费token。你也可以按使用量付费,享受无与伦比的价格。

47f7f39a42ff02f1d10b003f3bf42ccc.png

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}
}

备注:昵称-学校/公司-方向/会议(eg.ACL),进入技术/投稿群

e7bdd75f8b1e23ab92441766c0b07ffe.png

id:DLNLPer,记得备注呦

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值