DeepSeek选择了开源路线,在github上可以下载到所有的源代码还有参数(数据集应该没有开源),大语言模型的源代码规模其实非常小,DeepSeek V3的模型函数不过804行,阅读源代码有助于更好理解大语言模型。
1. DeepSeek V3的源代码可以从https://github.com/deepseek-ai/DeepSeek-V3获得,其中关键模型函数位于/inference/model.py
2. 运行Deep Seek V3需要安装以下四个包,torch由Meta公司开发,提供PyTorch机器学习框架,triton由OpenAI公司开发,transformers和safetensors两个包由Huggingface公司开发。由此可以看到百度的PaddlePaddle框架尽管在传统机器学习、深度学习领域表现不错,不过在最前沿的大语言模型领域尚有缺失,目前还没有看到哪个大语言模型是基于PaddlePaddle训练出来的
torch==2.4.1
triton==3.0.0
transformers==4.46.3
safetensors==0.4.5
3. Triton 起源于 2019 年的一篇论文,名为《Triton: An Intermediate Language and Compiler for Tiled Neural Network Computations》,旨在让研究人员和开发者能够以更少的代码量,实现与专家级 CUDA 相媲美的性能。它支持多种深度学习框架,包括 TensorFlow、TensorRT、PyTorch、ONNX 等。
4. 通过pip在windows11环境安装triton时遇到错误
pip install triton
ERROR: Could not find a version that satisfies the requirement triton (from versions: none)
ERROR: No matching distribution found for triton
5. 查资料后意识到triton并没有提供对windows环境的支持,考虑通过.whl包方式安装,在madbuda/triton-windows-builds · Hugging Face找到了适用于windows环境的whl包
6. 我使用的是Python 3.12,找到上图对应的链接,复制粘贴后运行下面pip安装指令安装成功
pip install https://huggingface.co/madbuda/triton-windows-builds/resolve/main/triton-3.0.0-cp312-cp312-win_amd64.whl
Collecting triton==3.0.0
Downloading https://huggingface.co/madbuda/triton-windows-builds/resolve/main/triton-3.0.0-cp312-cp312-win_amd64.whl (24.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 24.0/24.0 MB 25.7 MB/s eta 0:00:00
Requirement already satisfied: filelock in c:\users\admin\appdata\local\programs\python\python312\lib\site-packages (from triton==3.0.0) (3.16.1)
Installing collected packages: triton
Successfully installed triton-3.0.0
7. 当然细心的读者发现我这里安装的版本并不是DeepSeek V3指定的版本,如果要完全复刻,最好使用指定的版本。基于现实条件,我的目的只是做基本的代码解读,并不真正尝试运行代码,因为后续还需要使用GPU版的Torch等条件本机并不满足,且笔记本也不可能跑得动大语言模型的训练^-^