如何快速掌握DeepSeek-LLM:企业级智能应用实战指南
【免费下载链接】DeepSeek-LLMDeepSeek LLM: Let there be answers项目地址: https://gitcode.com/GitHub_Trending/de/DeepSeek-LLM
DeepSeek LLM是一款拥有670亿参数的先进语言模型,通过在2万亿中英文 tokens 上进行从头训练,展现出卓越的通用能力。本文将为新手和普通用户提供一份专业易懂的实战指南,帮助你快速上手这款强大的企业级智能应用。
🚀 为什么选择DeepSeek-LLM?
DeepSeek LLM在推理、编码、数学和中文理解等方面表现出色,67B Base模型性能超越Llama2 70B Base。其67B Chat模型在编码(HumanEval Pass@1: 73.78)和数学(GSM8K 0-shot: 84.1,Math 0-shot: 32.6)任务上表现卓越,还在匈牙利全国高中考试中取得65分的优异成绩,充分证明了其强大的 generalization能力。
💾 模型下载与安装
快速获取模型
你可以通过Huggingface获取DeepSeek LLM的各种模型版本:
| 模型名称 | 序列长度 | 下载地址 |
|---|---|---|
| DeepSeek LLM 7B Base | 4096 | HuggingFace |
| DeepSeek LLM 7B Chat | 4096 | HuggingFace |
| DeepSeek LLM 67B Base | 4096 | HuggingFace |
| DeepSeek LLM 67B Chat | 4096 | HuggingFace |
环境准备
在Python >= 3.8环境基础上,通过以下命令安装必要依赖:
pip install -r requirements.txt📚 快速开始:模型推理
使用Huggingface Transformers进行推理
文本补全
import torch from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig model_name = "deepseek-ai/deepseek-llm-67b-base" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto") 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-llm-67b-chat" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto") model.generation_config = GenerationConfig.from_pretrained(model_name) model.generation_config.pad_token_id = model.generation_config.eos_token_id messages = [ {"role": "user", "content": "Who are you?"} ] 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)使用vLLM进行高吞吐量推理
vLLM是一个高性能的LLM服务库,可以实现高吞吐量推理:
from vllm import LLM, SamplingParams tp_size = 4 # Tensor Parallelism sampling_params = SamplingParams(temperature=0.7, top_p=0.9, max_tokens=100) model_name = "deepseek-ai/deepseek-llm-67b-base" llm = LLM(model=model_name, trust_remote_code=True, gpu_memory_utilization=0.9, tensor_parallel_size=tp_size) prompts = [ "If everyone in a country loves one another,", "The research should also focus on the technologies", "To determine if the label is correct, we need to" ] outputs = llm.generate(prompts, sampling_params) generated_text = [output.outputs[0].text for output in outputs] print(generated_text)📊 性能表现
DeepSeek LLM在各项基准测试中表现优异,特别是在中文理解和数学推理方面:
在LeetCode周赛中,DeepSeek LLM 67B Chat表现出色,Pass@1分数达到31.7%,远超同类模型:
数学能力方面,DeepSeek LLM在GSM8K数据集上达到84.1%的准确率,在匈牙利全国高中数学考试中获得65分:
⚙️ 训练细节
DeepSeek LLM采用与LLaMA相同的架构,7B模型使用多头注意力(MHA),67B模型使用分组查询注意力(GQA)。在2万亿tokens的数据集上进行预训练,序列长度为4096。
训练过程中,模型在多个基准测试上的表现持续提升:
❓ 常见问题解答
GPU内存使用情况
对于7B模型,使用1 NVIDIA A100-PCIE-40GB GPU进行推理时的内存使用情况:
| 批大小 | 序列长度 256 | 序列长度 512 | 序列长度 1024 | 序列长度 2048 | 序列长度 4096 |
|---|---|---|---|---|---|
| 1 | 13.29 GB | 13.63 GB | 14.47 GB | 16.37 GB | 21.25 GB |
| 2 | 13.63 GB | 14.39 GB | 15.98 GB | 19.82 GB | 29.59 GB |
| 4 | 14.47 GB | 15.82 GB | 19.04 GB | 26.65 GB | OOM |
模型量化
DeepSeek LLM使用HuggingFace Tokenizer实现Byte-level BPE算法。对于量化,可以使用llama.cpp或exllamav2等工具。
📄 许可证信息
代码仓库采用MIT许可证,模型使用遵循Model License。DeepSeek LLM系列(包括Base和Chat)支持商业使用。详细信息请参见LICENSE-CODE和LICENSE-MODEL文件。
🤝 加入社区
扫描下方二维码加入DeepSeek官方群聊,与开发者和用户交流经验:
通过本指南,你已经了解了DeepSeek-LLM的核心功能、安装方法、使用技巧和性能表现。开始探索这款强大的企业级智能应用,为你的项目带来更高效的AI能力吧!
【免费下载链接】DeepSeek-LLMDeepSeek LLM: Let there be answers项目地址: https://gitcode.com/GitHub_Trending/de/DeepSeek-LLM
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考