HuggingFace镜像/DeepSeek-V2
模型介绍文件和版本分析
下载使用量0
DeepSeek-V2

Homepage Chat Hugging Face
Discord Wechat Twitter Follow
Code License Model License

模型下载 | 评估结果 | 模型架构 | API 平台 | 许可协议 | 引用方式

论文链接👁️

DeepSeek-V2:性能强劲、经济高效的混合专家语言模型

1. 引言

今天,我们正式推出DeepSeek-V2,这是一款性能强劲的混合专家(MoE)语言模型,其特点是训练经济且推理高效。该模型总参数达2360亿,其中每个token激活210亿参数。与DeepSeek 67B相比,DeepSeek-V2不仅性能更优,还节省了42.5%的训练成本,KV缓存减少93.3%,最大生成吞吐量提升至5.76倍。

我们在包含8.1万亿token的多样化高质量语料库上对DeepSeek-V2进行了预训练。在全面的预训练之后,我们又进行了监督微调(SFT)和强化学习(RL)过程,以充分释放模型的能力。评估结果证实了我们方法的有效性,DeepSeek-V2在标准基准测试和开放式生成评估中均取得了卓越性能。

2. 模型下载

模型上下文长度下载
DeepSeek-V2128k🤗 HuggingFace
DeepSeek-V2-Chat (RL)128k🤗 HuggingFace

由于HuggingFace的限制,当前开源代码在GPU上运行时的性能低于我们内部代码库。为了便于高效执行我们的模型,我们提供了专门的vllm解决方案,以优化模型的运行性能。

3. 评估结果

基础模型

标准基准测试

基准测试领域LLaMA3 70BMixtral 8x22BDeepSeek-V1 (Dense-67B)DeepSeek-V2 (MoE-236B)
MMLU英文78.977.671.378.5
BBH英文81.078.968.778.9
C-Eval中文67.558.666.181.7
CMMLU中文69.360.070.884.0
HumanEval代码48.253.145.148.8
MBPP代码68.664.257.466.6
GSM8K数学83.080.363.479.2
Math数学42.242.518.743.6
有关更多评估细节,如少样本设置和提示词,请查阅我们的论文。

上下文窗口

“大海捞针”(NIAH)测试的评估结果。DeepSeek-V2 在所有上下文窗口长度下均表现出色,最高支持128K。

对话模型

标准基准测试

基准测试领域QWen1.5 72B ChatMixtral 8x22BLLaMA3 70B InstructDeepSeek-V1 Chat (SFT)DeepSeek-V2 Chat (SFT)DeepSeek-V2 Chat (RL)
MMLU英文76.277.880.371.178.477.8
BBH英文65.978.480.171.781.379.7
C-Eval中文82.260.067.965.280.978.0
CMMLU中文82.961.070.767.882.481.6
HumanEval代码68.975.076.273.876.881.1
MBPP代码52.264.469.861.470.472.0
LiveCodeBench (0901-0401)代码18.825.030.518.328.732.5
GSM8K数学81.987.993.284.190.892.2
Math数学40.649.848.532.652.753.9

英文开放式生成评估

我们在AlpacaEval 2.0和MTBench上对模型进行了评估,结果显示DeepSeek-V2-Chat-RL在英文对话生成方面具有竞争力。

中文开放式生成评估

Alignbench (https://arxiv.org/abs/2311.18743)

模型开源/闭源总分中文推理中文语言
gpt-4-1106-preview闭源8.017.738.29
DeepSeek-V2 Chat (RL)开源7.917.458.35
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分数超过了其他几个复杂模型。这一表现凸显了该模型在处理实时编码任务方面的有效性。

4. 模型架构

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

  • 在注意力机制方面,我们设计了 MLA(Multi-head Latent Attention,多头潜在注意力),它利用低秩键值联合压缩来消除推理时键值缓存的瓶颈,从而支持高效推理。
  • 对于前馈网络(FFNs),我们采用 DeepSeekMoE 架构,这是一种高性能的 MoE 架构,能够以更低的成本训练出更强的模型。

5. 聊天网站

您可以在深度求索官方网站与 DeepSeek-V2 进行对话:chat.deepseek.com

6. API 平台

我们还在深度求索平台提供与 OpenAI 兼容的 API:platform.deepseek.com。注册即可获得数百万免费 tokens。您也可以选择极具竞争力的按需付费模式。

7. 本地运行方法

若要使用 BF16 格式的 DeepSeek-V2 进行推理,需要 80GB*8 的 GPU。

使用 Huggingface's Transformers 进行推理

您可以直接使用 Huggingface's 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` should be set based on your devices
max_memory = {i: "75GB" for i in range(8)}
# `device_map` cannot be set to `auto`
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True, device_map="sequential", torch_dtype=torch.bfloat16, max_memory=max_memory, attn_implementation="eager")
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` should be set based on your devices
max_memory = {i: "75GB" for i in range(8)}
# `device_map` cannot be set to `auto`
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True, device_map="sequential", torch_dtype=torch.bfloat16, max_memory=max_memory, attn_implementation="eager")
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)

完整的聊天模板可在 Hugging Face 模型仓库的 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:

使用 vLLM 进行推理(推荐)

若要使用 vLLM 进行模型推理,请将以下拉取请求合并到您的 vLLM 代码库中:https://github.com/vllm-project/vllm/pull/4650。

from transformers import AutoTokenizer
from vllm import LLM, SamplingParams

max_model_len, tp_size = 8192, 8
model_name = "deepseek-ai/DeepSeek-V2-Chat"
tokenizer = AutoTokenizer.from_pretrained(model_name)
llm = LLM(model=model_name, tensor_parallel_size=tp_size, max_model_len=max_model_len, trust_remote_code=True, enforce_eager=True)
sampling_params = SamplingParams(temperature=0.3, max_tokens=256, stop_token_ids=[tokenizer.eos_token_id])

messages_list = [
    [{"role": "user", "content": "Who are you?"}],
    [{"role": "user", "content": "Translate the following content into Chinese directly: DeepSeek-V2 adopts innovative architectures to guarantee economical training and efficient inference."}],
    [{"role": "user", "content": "Write a piece of quicksort code in C++."}],
]

prompt_token_ids = [tokenizer.apply_chat_template(messages, add_generation_prompt=True) for messages in messages_list]

outputs = llm.generate(prompt_token_ids=prompt_token_ids, sampling_params=sampling_params)

generated_text = [output.outputs[0].text for output in outputs]
print(generated_text)

8. 许可协议

本代码仓库基于 MIT 许可协议 授权。DeepSeek-V2 Base/Chat 模型的使用受 模型许可协议 约束。DeepSeek-V2 系列(包括 Base 和 Chat)支持商业用途。

9. 引用

@misc{deepseekv2,
      title={DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model}, 
      author={DeepSeek-AI},
      year={2024},
      eprint={2405.04434},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}

10. 联系方式

如有任何问题,请提交 issue 或通过 service@deepseek.com 与我们联系。