转自:https://www.sourcefind.cn/#/model-zoo/1885958664579317762,如有侵权请联系删除
DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning
https://github.com/deepseek-ai/DeepSeek-R1/blob/main/DeepSeek_R1.pdf
模型结构
该模型基于Transformer,采用Multi-Head Latent Attention和DeepSeekMoE架构,其中MLA通过减少KV缓存降低内存占用可用于高效推理,DeepSeekMoE通过auxiliary loss平衡专家负载。
算法原理
DeepSeek-R1的模型结构通过MLA、DeepSeekMoE、辅助损失无关的负载均衡策略、多令牌预测和FP8混合精度训练等创新技术,显著提升了模型的性能和训练效率,使用强化学习训练模型,增强模型的思考能力,这些设计使得DeepSeek-R1在保持高性能的同时,大幅降低了训练成本。
环境配置
Docker(方法一)
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.3.0-ubuntu22.04-dtk24.04.3-py3.10
docker run --shm-size 500g --network=host --name=dpskr1 --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 项目地址(绝对路径):/home/ -v /opt/hyhal:/opt/hyhal:ro -it bash
cd inference
pip install -r requirements.txt
Dockerfile(方法二)
docker build -t <IMAGE_NAME>: .
docker run --shm-size 500g --network=host --name=dpskr1 --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v 项目地址(绝对路径):/home/ -v /opt/hyhal:/opt/hyhal:ro -it bash
cd inference
pip install -r requirements.txt
数据集
无
训练
无
推理
注意:运行该模型需要4x8x64(GB)显存。
模型转换
fp8 -> bf16
cd inference
python fp8_cast_bf16.py --input-fp8-hf-path /path/to/fp8_weights --output-bf16-hf-path /path/to/bf16_weights
模型划分
python convert.py --hf-ckpt-path /path/to/DeepSeek-R1-bf16 --save-path /path/to/DeepSeek-R1-Demo --n-experts 256 --model-parallel 32
run
chat
torchrun --nnodes 4 --nproc-per-node 8 --node-rank $RANK --master-addr $ADDR generate.py --ckpt-path /path/to/DeepSeek-R1-Demo --config configs/config_671B.json --interactive --temperature 0.7 --max-new-tokens 200
直接推理
torchrun --nnodes 4 --nproc-per-node 8 --node-rank $RANK --master-addr $ADDR generate.py --ckpt-path /path/to/DeepSeek-R1-Demo --config configs/config_671B.json --input-file $FILE
注意:需要将/path/to/fp8_weights中的json文件复制到/path/to/DeepSeek-V3-Demo中。
在K100_AI和ECO显卡上需要添加环境变量
export NCCL_ALGO=Ring
export NCCL_PROTO=Simple
我是海持,AI顶尖大厂攻城狮+创业者,为梦想窒息的老少年,追求自由、健身、智慧。
推荐云+AI头部大厂工作机会和指导面试(阿里、字节、华为、微软、大疆等);办理美港股开户;陪伴年轻人终身成长。
个税APP,航X、网X、军X 架构师