DeepSeek-V2

DeepSeek-V2

兼顾效率与经济性的大规模混合专家语言模型

DeepSeek-V2是一款基于专家混合(MoE)架构的大规模语言模型,总参数量达2360亿,每个token激活210亿参数。相较于DeepSeek 67B,该模型在提升性能的同时,显著降低了训练成本和推理资源消耗。DeepSeek-V2在多项标准基准测试和开放式生成任务中表现优异,展现了其在多领域的应用潜力。

DeepSeek-V2混合专家模型大语言模型预训练模型自然语言处理Github开源项目
<div align="center"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/00694156-3677-4909-91a9-a4f019101431.svg?raw=true" width="60%" alt="DeepSeek-V2" /> </div> <hr> <div align="center" style="line-height: 1;"> <a href="https://www.deepseek.com/" target="_blank" style="margin: 2px;"> <img alt="主页" src="https://yellow-cdn.veclightyear.com/835a84d5/601eac3c-7c0f-4ccd-9e94-fca3f2cbd933.svg?raw=true" style="display: inline-block; vertical-align: middle;"/> </a> <a href="https://chat.deepseek.com/" target="_blank" style="margin: 2px;"> <img alt="聊天" src="https://img.shields.io/badge/🤖%20Chat-DeepSeek%20V2-536af5?color=536af5&logoColor=white" style="display: inline-block; vertical-align: middle;"/> </a> <a href="https://huggingface.co/deepseek-ai" target="_blank" style="margin: 2px;"> <img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-DeepSeek%20AI-ffc107?color=ffc107&logoColor=white" style="display: inline-block; vertical-align: middle;"/> </a> </div> <div align="center" style="line-height: 1;"> <a href="https://discord.gg/Tc7c45Zzu5" target="_blank" style="margin: 2px;"> <img alt="Discord" src="https://img.shields.io/badge/Discord-DeepSeek%20AI-7289da?logo=discord&logoColor=white&color=7289da" style="display: inline-block; vertical-align: middle;"/> </a> <a href="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/figures/qr.jpeg?raw=true" target="_blank" style="margin: 2px;"> <img alt="微信" src="https://img.shields.io/badge/WeChat-DeepSeek%20AI-brightgreen?logo=wechat&logoColor=white" style="display: inline-block; vertical-align: middle;"/> </a> <a href="https://twitter.com/deepseek_ai" target="_blank" style="margin: 2px;"> <img alt="Twitter 关注" src="https://img.shields.io/badge/Twitter-deepseek_ai-white?logo=x&logoColor=white" style="display: inline-block; vertical-align: middle;"/> </a> </div> <div align="center" style="line-height: 1;"> <a href="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/LICENSE-CODE" style="margin: 2px;"> <img alt="代码许可" src="https://img.shields.io/badge/Code_License-MIT-f5de53?&color=f5de53" style="display: inline-block; vertical-align: middle;"/> </a> <a href="https://github.com/deepseek-ai/DeepSeek-V2/blob/main/LICENSE-MODEL" style="margin: 2px;"> <img alt="模型许可" src="https://img.shields.io/badge/Model_License-Model_Agreement-f5de53?&color=f5de53" style="display: inline-block; vertical-align: middle;"/> </a> </div> <p align="center"> <a href="#2-model-downloads">模型下载</a> | <a href="#3-evaluation-results">评估结果</a> | <a href="#4-model-architecture">模型架构</a> | <a href="#6-api-platform">API平台</a> | <a href="#8-license">许可</a> | <a href="#9-citation">引用</a> </p> <p align="center"> <a href="https://arxiv.org/abs/2405.04434"><b>论文链接</b>👁️</a> </p>

DeepSeek-V2:强大、经济且高效的混合专家语言模型

1. 简介

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

<p align="center"> <div style="display: flex; justify-content: center;"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/d6a6f83d-d954-4899-b4dd-b585d3e8fbf9.png?raw=true" style="height:300px; width:auto; margin-right:10px"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/56c47f99-ce9f-4f28-84cd-3ce9f34f9220.png?raw=true" style="height:300px; width:auto; margin-left:10px"> </div> </p>

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

2. 新闻

  • 2024.05.16:我们发布了DeepSeek-V2-Lite。
  • 2024.05.06:我们发布了DeepSeek-V2。

3. 模型下载

<div align="center">
模型总参数量激活参数量上下文长度下载
DeepSeek-V2-Lite16B2.4B32k🤗 HuggingFace
DeepSeek-V2-Lite-Chat (SFT)16B2.4B32k🤗 HuggingFace
DeepSeek-V2236B21B128k🤗 HuggingFace
DeepSeek-V2-Chat (RL)236B21B128k🤗 HuggingFace
</div>

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

4. 评估结果

基础模型

标准基准测试(大于67B的模型)

<div align="center">
基准测试领域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
</div>

标准基准测试(小于16B的模型)

<div align="center"> | **基准测试** | **领域** | **DeepSeek 7B (密集)** | **DeepSeekMoE 16B** | **DeepSeek-V2-Lite (MoE-16B)** | |:-------------:|:----------:|:--------------:|:-----------------:|:--------------------------:| | **架构** | - | MHA+密集 | MHA+MoE | MLA+MoE | | **MMLU** | 英语 | 48.2 | 45.0 | 58.3 | | **BBH** | 英语 | 39.5 | 38.9 | 44.1 | | **C-Eval** | 中文 | 45.0 | 40.6 | 60.3 | | **CMMLU** | 中文 | 47.2 | 42.5 | 64.3 | | **HumanEval** | 代码 | 26.2 | 26.8 | 29.9 | | **MBPP** | 代码 | 39.0 | 39.2 | 43.2 | | **GSM8K** | 数学 | 17.4 | 18.8 | 41.1 | | **Math** | 数学 | 3.3 | 4.3 | 17.1 |

有关更多评估细节,如少样本设置和提示,请查阅我们的论文。

上下文窗口

<p align="center"> <img width="80%" src="https://yellow-cdn.veclightyear.com/835a84d5/43a09b38-7db8-49f8-b3ad-70435fe96eb8.png?raw=true"> </p>

"大海捞针"(NIAH)测试的评估结果。DeepSeek-V2在所有长度达128K的上下文窗口中表现良好。

对话模型

标准基准测试(大于67B的模型)

<div align="center">
基准测试领域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
</div>

标准基准测试(小于16B的模型)

<div align="center">
基准测试领域DeepSeek 7B Chat (SFT)DeepSeekMoE 16B Chat (SFT)DeepSeek-V2-Lite 16B Chat (SFT)
MMLU英语49.747.255.7
BBH英语43.142.248.1
C-Eval中文44.740.060.1
CMMLU中文51.249.362.5
HumanEval代码45.145.757.3
MBPP代码39.046.245.8
GSM8K数学62.662.272.0
Math数学14.715.227.9
</div>

英语开放式生成评估

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

<p align="center"> <img width="50%" src="https://yellow-cdn.veclightyear.com/835a84d5/57b869a5-65bd-4f9b-87a7-89743a07f2e5.png?raw=true" /> </p>

中文开放式生成评估

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

<div align="center">
模型开源/闭源总分中文推理中文语言
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
DeepSeek-V2-Lite 16B Chat开源6.014.717.32
</div>

编程基准测试

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

<p align="center"> <img width="50%" src="https://yellow-cdn.veclightyear.com/835a84d5/dca3984f-7fc3-404e-b8fd-74f52d0b9b6c.png?raw=true"> </p>

5. 模型架构

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

  • 对于注意力机制,我们设计了MLA(多头潜在注意力),它利用低秩键值联合压缩来消除推理时键值缓存的瓶颈,从而支持高效推理。
  • 对于前馈网络(FFNs),我们采用DeepSeekMoE架构,这是一种高性能的MoE架构,能够以更低的成本训练更强大的模型。
<p align="center"> <img width="90%" src="https://yellow-cdn.veclightyear.com/835a84d5/aff739dd-9383-4c51-9d8d-93bca5784ce6.png?raw=true" /> </p>

6. 聊天网站

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

7. API平台

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

<p align="center"> <img width="40%" src="https://yellow-cdn.veclightyear.com/835a84d5/d882af83-5061-47d8-87d6-39ab610e5c4b.png?raw=true"> </p> ## 8. 如何本地运行 **要使用BF16格式的DeepSeek-V2进行推理,需要80GB*8的GPU。** ### 使用Huggingface的Transformers进行推理 您可以直接使用[Huggingface的Transformers](https://github.com/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)} # `device_map`不能设置为`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 = "注意力函数可以被描述为将一个查询和一组键值对映射到一个输出,其中查询、键、值和输出都是向量。输出是" 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)} # `device_map`不能设置为`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": "用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} A: {assistant_message_1}<|end▁of▁sentence|>User: {user_message_2} A:

您还可以添加一个可选的系统消息:

<|begin▁of▁sentence|>{system_message} User: {user_message_1} A: {assistant_message_1}<|end▁of▁sentence|>User: {user_message_2} A:

使用vLLM进行推理(推荐)

要使用vLLM进行模型推理,请将此Pull Request合并到您的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": "你是谁?"}], [{"role": "user", "content": "直接将以下内容翻译成中文:DeepSeek-V2 adopts innovative architectures to guarantee economical training and efficient inference."}], [{"role": "user", "content": "用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)

LangChain支持

由于我们的API与OpenAI兼容,您可以轻松地在langchain中使用它。 以下是一个示例:

from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
    model='deepseek-chat',
    openai_api_key=<your-deepseek-api-key>,
    openai_api_base='https://api.deepseek.com/v1',
    temperature=0.85,
    max_tokens=8000)

9. 许可证

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

10. 引用

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

11. 联系方式

如果您有任何问题,请提出issue或联系我们:service@deepseek.com

编辑推荐精选

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

Trae

Trae

字节跳动发布的AI编程神器IDE

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

openai-agents-python

openai-agents-python

OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。

openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。

Hunyuan3D-2

Hunyuan3D-2

高分辨率纹理 3D 资产生成

Hunyuan3D-2 是腾讯开发的用于 3D 资产生成的强大工具,支持从文本描述、单张图片或多视角图片生成 3D 模型,具备快速形状生成能力,可生成带纹理的高质量 3D 模型,适用于多个领域,为 3D 创作提供了高效解决方案。

3FS

3FS

一个具备存储、管理和客户端操作等多种功能的分布式文件系统相关项目。

3FS 是一个功能强大的分布式文件系统项目,涵盖了存储引擎、元数据管理、客户端工具等多个模块。它支持多种文件操作,如创建文件和目录、设置布局等,同时具备高效的事件循环、节点选择和协程池管理等特性。适用于需要大规模数据存储和管理的场景,能够提高系统的性能和可靠性,是分布式存储领域的优质解决方案。

下拉加载更多