!2196 DeepSeek-R1-Distill-Qwen-1.5B and LLaMA-8B、70B

Merge pull request !2196 from guoxinjie/distill-qwen
This commit is contained in:
guoxinjie
2025-02-09 12:46:23 +00:00
committed by i-robot
parent 95af7c9abe
commit e89e1b1db2
10 changed files with 598 additions and 2 deletions

View File

@@ -19,6 +19,27 @@ MindSpeed-LLM是基于昇腾生态的大语言模型分布式训练框架
---
## NEWS !!!
🚀🚀🚀**DeepSeek-R1-Distill** 系列模型已上线!!🚀🚀🚀
**[DeepSeek-R1-Distill-Qwen](./examples/mcore/deepseek_r1_distill_qwen/)** 😊
**[DeepSeek-R1-Distill-LLaMA](./examples/mcore/deepseek_r1_distill_llama/)** 😊
包含数据处理、权重转换、在线推理、全参微调
## COMING !!!
🚀🚀 On 2.16 will release **DeepSeekV3-671B**: Pretrain、Lora、QLora 👋👋
🚀🚀 On 2.16 will release **DeepSeek-R1-ZERO** 👋👋
🚀🚀 On 2.23 will release **DeepSeek-R1**SFT、GRPO、Reward 👋👋
🚀🚀 On 3.30 will release **[MindSpeed-RL](https://gitee.com/ascend/MindSpeed-RL)** 👋👋
---
## 版本配套表
MindSpeed-LLM的以来配套如下表安装步骤参考[安装指导](./docs/features/install_guide.md)。

View File

@@ -726,9 +726,17 @@
<td>【Test】</td>
</tr>
<tr>
<td rowspan="3"><a href="https://huggingface.co/deepseek-ai">DeepSeek-R1-Distill-Qwen</a></td>
<td rowspan="4"><a href="https://huggingface.co/deepseek-ai">DeepSeek-R1-Distill-Qwen</a></td>
<td><a href="https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B">1.5B</a></td>
<td rowspan="4"><a href="../../examples/mcore/deepseek_r1_distill_qwen">deepseek_r1_distill_qwen</a></td>
<td> 4K </td>
<th>Mcore</th>
<td> 1x8 </td>
<td>【Ascend】</td>
<td>【Test】</td>
</tr>
<tr>
<td><a href="https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B">7B</a></td>
<td rowspan="3"><a href="../../examples/mcore/deepseek_r1_distill_qwen">deepseek_r1_distill_qwen</a></td>
<td> 4K </td>
<th>Mcore</th>
<td> 1x8 </td>
@@ -751,6 +759,24 @@
<td>【Ascend】</td>
<td>【Test】</td>
</tr>
<tr>
<td rowspan="2"><a href="https://huggingface.co/deepseek-ai">DeepSeek-R1-Distill-LLaMA</a></td>
<td><a href="https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Llama-8B">8B</a></td>
<td rowspan="2"><a href="../../examples/mcore/deepseek_r1_distill_llama/">deepseek_r1_distill_llama</a></td>
<td> 8K </td>
<th>Mcore</th>
<td> 1x8 </td>
<td>【Ascend】</td>
<td>【Test】</td>
</tr>
<tr>
<td><a href="https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Llama-70B">70B</a></td>
<td> 8K </td>
<th>Mcore</th>
<td> 4x8 </td>
<td>【Ascend】</td>
<td>【Test】</td>
</tr>
</tbody>
</table>

View File

@@ -0,0 +1,16 @@
# 修改 ascend-toolkit 路径
source /usr/local/Ascend/ascend-toolkit/set_env.sh
# 权重格式转换
python convert_ckpt.py \
--use-mcore-models \
--model-type-hf llama2 \
--model-type GPT \
--load-model-type hf \
--save-model-type mg \
--params-dtype bf16 \
--target-tensor-parallel-size 1 \
--target-pipeline-parallel-size 1 \
--load-dir ./model_from_hf/llama3_distill/ \
--save-dir ./model_weights/llama3_mcore/ \
--tokenizer-model ./model_from_hf/llama3_distill/tokenizer.json # --num-layer-list 17,20,22,21 等参数根据模型需求添加

View File

@@ -0,0 +1,16 @@
# 请根据 examples/README.md 下 “数据集准备及处理” 章节下载 Alpaca 数据集
# 请按照您的真实环境修改 set_env.sh 路径
source /usr/local/Ascend/ascend-toolkit/set_env.sh
mkdir ./finetune_dataset
python ./preprocess_data.py \
--input ./dataset/train-00000-of-00001-a09b74b3ef9c3b56.parquet \
--tokenizer-name-or-path ./model_from_hf/llama3-distill/ \
--output-prefix ./finetune_dataset/alpaca \
--workers 4 \
--log-interval 1000 \
--tokenizer-type PretrainedFromHF \
--tokenizer-not-use-fast \
--handler-name AlpacaStyleInstructionHandler \
--prompt-type llama3 \
--seq-length 8192 \

View File

@@ -0,0 +1,55 @@
#!/bin/bash
export CUDA_DEVICE_MAX_CONNECTIONS=1
# please fill these path configurations
TOKENIZER_PATH="your tokenizer directory path"
CHECKPOINT="your model directory path"
# Change for multinode config
MASTER_ADDR=localhost
MASTER_PORT=6001
NNODES=1
NODE_RANK=0
NPUS_PER_NODE=4
WORLD_SIZE=$(($NPUS_PER_NODE*$NNODES))
DISTRIBUTED_ARGS="--nproc_per_node $NPUS_PER_NODE --nnodes $NNODES --node_rank $NODE_RANK --master_addr $MASTER_ADDR --master_port $MASTER_PORT"
torchrun $DISTRIBUTED_ARGS inference.py \
--tensor-model-parallel-size 4 \
--pipeline-model-parallel-size 1 \
--use-mcore-models \
--num-layers 80 \
--hidden-size 8192 \
--ffn-hidden-size 28672 \
--position-embedding-type rope \
--rotary-base 500000 \
--num-attention-heads 64 \
--group-query-attention \
--num-query-groups 8 \
--swiglu \
--normalization RMSNorm \
--norm-epsilon 1e-5 \
--use-fused-swiglu \
--use-fused-rmsnorm \
--use-fused-rotary-pos-emb \
--use-rotary-position-embeddings \
--load ${CHECKPOINT} \
--tokenizer-type PretrainedFromHF \
--tokenizer-name-or-path ${TOKENIZER_PATH} \
--tokenizer-not-use-fast \
--seq-length 8192 \
--max-position-embeddings 8192 \
--max-new-tokens 256 \
--micro-batch-size 1 \
--hidden-dropout 0 \
--attention-dropout 0 \
--untie-embeddings-and-output-weights \
--disable-bias-linear \
--attention-softmax-in-fp32 \
--exit-on-missing-checkpoint \
--make-vocab-size-divisible-by 16032 \
--bf16 \
--seed 42 \
| tee logs/generate_mcore_llama_distill_70b.log

View File

@@ -0,0 +1,54 @@
#!/bin/bash
export CUDA_DEVICE_MAX_CONNECTIONS=1
# please fill these path configurations
TOKENIZER_PATH="your tokenizer directory path"
CHECKPOINT="your model directory path"
# Change for multinode config
MASTER_ADDR=localhost
MASTER_PORT=6001
NNODES=1
NODE_RANK=0
NPUS_PER_NODE=1
WORLD_SIZE=$(($NPUS_PER_NODE*$NNODES))
DISTRIBUTED_ARGS="--nproc_per_node $NPUS_PER_NODE --nnodes $NNODES --node_rank $NODE_RANK --master_addr $MASTER_ADDR --master_port $MASTER_PORT"
torchrun $DISTRIBUTED_ARGS inference.py \
--tensor-model-parallel-size 1 \
--pipeline-model-parallel-size 1 \
--use-mcore-models \
--num-layers 32 \
--hidden-size 4096 \
--ffn-hidden-size 14336 \
--position-embedding-type rope \
--rotary-base 500000 \
--num-attention-heads 32 \
--group-query-attention \
--num-query-groups 8 \
--swiglu \
--normalization RMSNorm \
--norm-epsilon 1e-5 \
--seq-length 8192 \
--max-position-embeddings 8192 \
--max-new-tokens 256 \
--micro-batch-size 1 \
--use-fused-swiglu \
--use-fused-rmsnorm \
--use-fused-rotary-pos-emb \
--load ${CHECKPOINT} \
--tokenizer-type PretrainedFromHF \
--tokenizer-name-or-path ${TOKENIZER_PATH} \
--tokenizer-not-use-fast \
--hidden-dropout 0 \
--attention-dropout 0 \
--untie-embeddings-and-output-weights \
--disable-bias-linear \
--attention-softmax-in-fp32 \
--exit-on-missing-checkpoint \
--make-vocab-size-divisible-by 16032 \
--bf16 \
--seed 42 \
| tee logs/generate__mcore_llama_distill_8b.log

View File

@@ -0,0 +1,108 @@
#!/bin/bash
export CUDA_DEVICE_MAX_CONNECTIONS=1
NPUS_PER_NODE=8
MASTER_ADDR="your master IP Address"
MASTER_PORT="your master IP Port, can be changed if current port is occupied"
NNODES=4
NODE_RANK=0
WORLD_SIZE=$(($NPUS_PER_NODE*$NNODES))
CKPT_SAVE_DIR="your model save ckpt path"
DATA_PATH="your data path"
TOKENIZER_PATH="your tokenizer path"
CKPT_LOAD_DIR="your model ckpt path"
TP=8
PP=4
DISTRIBUTED_ARGS="
--nproc_per_node $NPUS_PER_NODE \
--nnodes $NNODES \
--node_rank $NODE_RANK \
--master_addr $MASTER_ADDR \
--master_port $MASTER_PORT
"
TUNE_ARGS="
--finetune \
--stage sft \
--is-instruction-dataset \
--variable-seq-lengths \
--prompt-type llama3 \
"
GPT_ARGS="
--tensor-model-parallel-size ${TP} \
--pipeline-model-parallel-size ${PP} \
--num-layers-per-virtual-pipeline-stage 2 \
--use-mcore-models \
--micro-batch-size 1 \
--global-batch-size 128 \
--sequence-parallel \
--use-fused-rotary-pos-emb \
--use-fused-rmsnorm \
--use-fused-swiglu \
--tokenizer-type PretrainedFromHF \
--tokenizer-name-or-path ${TOKENIZER_PATH} \
--num-layers 80 \
--hidden-size 8192 \
--ffn-hidden-size 28672 \
--num-attention-heads 64 \
--group-query-attention \
--num-query-groups 8 \
--position-embedding-type rope \
--rotary-base 500000 \
--normalization RMSNorm \
--norm-epsilon 1e-5 \
--swiglu \
--seq-length 8192 \
--max-position-embeddings 8192 \
--make-vocab-size-divisible-by 16032 \
--untie-embeddings-and-output-weights \
--disable-bias-linear \
--attention-dropout 0.0 \
--init-method-std 0.01 \
--hidden-dropout 0.0 \
--no-masked-softmax-fusion \
--attention-softmax-in-fp32 \
--lr 1.25e-6 \
--train-iters 2000 \
--lr-decay-style cosine \
--min-lr 1.25e-7 \
--weight-decay 1e-1 \
--lr-warmup-fraction 0.01 \
--clip-grad 1.0 \
--adam-beta1 0.9 \
--adam-beta2 0.95 \
--initial-loss-scale 4096 \
--no-gradient-accumulation-fusion \
--no-shared-storage \
--no-load-optim \
--no-load-rng \
--no-save-optim \
--no-save-rng \
--bf16
"
DATA_ARGS="
--data-path $DATA_PATH \
--split 100,0,0
"
OUTPUT_ARGS="
--log-interval 1 \
--save-interval 2000 \
--eval-interval 2000 \
--eval-iters 0 \
"
torchrun $DISTRIBUTED_ARGS posttrain_gpt.py \
$TUNE_ARGS \
$GPT_ARGS \
$DATA_ARGS \
$OUTPUT_ARGS \
$ACCELERATE_ARGS \
--distributed-backend nccl \
--load ${CKPT_LOAD_DIR} \
--save ${CKPT_SAVE_DIR} \
| tee logs/tune_mcore_distill_llama_70b_full_8k.log

View File

@@ -0,0 +1,117 @@
#!/bin/bash
export CUDA_DEVICE_MAX_CONNECTIONS=1
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
GPUS_PER_NODE=8
MASTER_ADDR=localhost
MASTER_PORT=6024
NNODES=1
NODE_RANK=0
WORLD_SIZE=$(($GPUS_PER_NODE*$NNODES))
CKPT_SAVE_DIR="your model save ckpt path"
DATA_PATH="your data path"
TOKENIZER_PATH="your tokenizer path"
CKPT_LOAD_DIR="your model ckpt path"
TP=1
PP=2
DISTRIBUTED_ARGS="
--nproc_per_node $GPUS_PER_NODE \
--nnodes $NNODES \
--node_rank $NODE_RANK \
--master_addr $MASTER_ADDR \
--master_port $MASTER_PORT
"
TUNE_ARGS="
--finetune \
--stage sft \
--is-instruction-dataset \
--variable-seq-lengths \
--prompt-type llama3 \
"
GPT_ARGS="
--tensor-model-parallel-size ${TP} \
--pipeline-model-parallel-size ${PP} \
--use-mcore-models \
--num-layers 32 \
--hidden-size 4096 \
--ffn-hidden-size 14336 \
--num-attention-heads 32 \
--group-query-attention \
--num-query-groups 8 \
--position-embedding-type rope \
--rotary-base 500000 \
--normalization RMSNorm \
--norm-epsilon 1e-5 \
--swiglu \
--micro-batch-size 1 \
--global-batch-size 64 \
--use-flash-attn \
--prompt-type llama3 \
--rope-scaling-type llama3 \
--rope-scaling-factor 8.0 \
--rotary-percent 1.0 \
--low-freq-factor 1.0 \
--high-freq-factor 4.0 \
--original-max-position-embeddings 8192 \
--tokenizer-type PretrainedFromHF \
--tokenizer-name-or-path ${TOKENIZER_PATH} \
--tokenizer-not-use-fast \
--seq-length 8192 \
--max-position-embeddings 8192 \
--make-vocab-size-divisible-by 1 \
--padded-vocab-size 128256 \
--untie-embeddings-and-output-weights \
--disable-bias-linear \
--attention-dropout 0.0 \
--init-method-std 0.02 \
--hidden-dropout 0.0 \
--no-masked-softmax-fusion \
--attention-softmax-in-fp32 \
--lr 1e-7 \
--train-iters 2000 \
--lr-decay-style constant \
--weight-decay 0.0 \
--clip-grad 1.0 \
--adam-beta1 0.9 \
--adam-beta2 0.999 \
--initial-loss-scale 4096 \
--no-gradient-accumulation-fusion \
--no-load-optim \
--no-load-rng \
--no-save-optim \
--no-save-rng \
--bf16 \
--seed 42 \
--vocab-size 128256 \
--reuse-fp32-param \
--use-distributed-optimizer \
"
DATA_ARGS="
--data-path $DATA_PATH \
--split 100,0,0
"
OUTPUT_ARGS="
--log-interval 1 \
--save-interval 2000 \
--eval-interval 2000 \
--eval-iters 10 \
--load ${CKPT_LOAD_DIR} \
--save ${CKPT_SAVE_DIR} \
"
torchrun $DISTRIBUTED_ARGS posttrain_gpt.py \
$TUNE_ARGS \
$GPT_ARGS \
$DATA_ARGS \
$OUTPUT_ARGS \
--distributed-backend nccl \
| tee logs/tune_mcore_distill_llama_8b_full_8k.log

View File

@@ -0,0 +1,64 @@
#!/bin/bash
export CUDA_DEVICE_MAX_CONNECTIONS=1
# Change for multinode config
MASTER_ADDR=localhost
MASTER_PORT=6002
NNODES=1
NODE_RANK=0
NPUS_PER_NODE=1
WORLD_SIZE=$(($NPUS_PER_NODE*$NNODES))
# please fill these path configurations
CHECKPOINT="your model ckpt path"
TOKENIZER_PATH="your tokenizer path"
TP=1
PP=1
MBS=1
SEQ_LEN=4096
DISTRIBUTED_ARGS="
--nproc_per_node $NPUS_PER_NODE \
--nnodes $NNODES \
--node_rank $NODE_RANK \
--master_addr $MASTER_ADDR \
--master_port $MASTER_PORT
"
torchrun $DISTRIBUTED_ARGS inference.py \
--use-mcore-models \
--tensor-model-parallel-size ${TP} \
--pipeline-model-parallel-size ${PP} \
--num-layers 28 \
--hidden-size 1536 \
--ffn-hidden-size 8960 \
--num-attention-heads 12 \
--group-query-attention \
--num-query-groups 2 \
--tokenizer-type PretrainedFromHF \
--tokenizer-name-or-path ${TOKENIZER_PATH} \
--max-position-embeddings ${SEQ_LEN} \
--seq-length ${SEQ_LEN} \
--make-vocab-size-divisible-by 1 \
--padded-vocab-size 151936 \
--rotary-base 10000 \
--micro-batch-size ${MBS} \
--swiglu \
--add-qkv-bias \
--untie-embeddings-and-output-weights \
--disable-bias-linear \
--load ${CHECKPOINT} \
--normalization RMSNorm \
--norm-epsilon 1e-6 \
--position-embedding-type rope \
--hidden-dropout 0 \
--attention-dropout 0 \
--tokenizer-not-use-fast \
--max-new-tokens 256 \
--no-gradient-accumulation-fusion \
--exit-on-missing-checkpoint \
--attention-softmax-in-fp32 \
--seed 42 \
--bf16 \
| tee logs/generate_mcore_distil_qwen_1point5b.log

View File

@@ -0,0 +1,119 @@
export CUDA_DEVICE_MAX_CONNECTIONS=1
NPUS_PER_NODE=8
MASTER_ADDR=localhost
MASTER_PORT=6000
NNODES=1
NODE_RANK=0
WORLD_SIZE=$(($NPUS_PER_NODE*$NNODES))
# please fill these path configurations
CKPT_LOAD_DIR="your model ckpt path"
CKPT_SAVE_DIR="your model save ckpt path"
DATA_PATH="your data path"
TOKENIZER_PATH="your tokenizer path"
TP=1
PP=1
SEQ_LEN=4096
MBS=1
GBS=64
DISTRIBUTED_ARGS="
--nproc_per_node $NPUS_PER_NODE \
--nnodes $NNODES \
--node_rank $NODE_RANK \
--master_addr $MASTER_ADDR \
--master_port $MASTER_PORT
"
TUNE_ARGS="
--finetune \
--stage sft \
--is-instruction-dataset \
--variable-seq-lengths \
--prompt-type qwen \
"
GPT_ARGS="
--use-mcore-models \
--tensor-model-parallel-size ${TP} \
--pipeline-model-parallel-size ${PP} \
--num-layers 28 \
--hidden-size 1536 \
--ffn-hidden-size 8960 \
--num-attention-heads 12 \
--max-position-embeddings ${SEQ_LEN} \
--seq-length ${SEQ_LEN} \
--disable-bias-linear \
--add-qkv-bias \
--group-query-attention \
--num-query-groups 2 \
--use-flash-attn \
--swiglu \
--use-fused-swiglu \
--normalization RMSNorm \
--norm-epsilon 1e-6 \
--use-fused-rmsnorm \
--position-embedding-type rope \
--rotary-base 10000 \
--use-fused-rotary-pos-emb \
--untie-embeddings-and-output-weights \
--micro-batch-size ${MBS} \
--global-batch-size ${GBS} \
--make-vocab-size-divisible-by 1 \
--padded-vocab-size 151936 \
--tokenizer-type PretrainedFromHF \
--tokenizer-name-or-path ${TOKENIZER_PATH} \
--tokenizer-not-use-fast \
--attention-dropout 0.0 \
--hidden-dropout 0.0 \
--train-iters 2000 \
--lr 1.25e-6 \
--lr-decay-style cosine \
--min-lr 1.25e-7 \
--lr-warmup-fraction 0.01 \
--init-method-std 0.01 \
--weight-decay 0.0 \
--clip-grad 1.0 \
--adam-beta1 0.9 \
--adam-beta2 0.95 \
--initial-loss-scale 4096 \
--no-gradient-accumulation-fusion \
--no-masked-softmax-fusion \
--attention-softmax-in-fp32 \
--bf16
"
DATA_ARGS="
--data-path $DATA_PATH \
--split 100,0,0
"
CKPT_ARGS="
--no-load-optim \
--no-load-rng \
--no-save-optim \
--no-save-rng \
--seed 1234 \
"
OUTPUT_ARGS="
--log-interval 1 \
--save-interval 2000 \
--eval-interval 2000 \
--eval-iters 0 \
--log-throughput
"
torchrun $DISTRIBUTED_ARGS posttrain_gpt.py \
$GPT_ARGS \
$DATA_ARGS \
$CKPT_ARGS \
$OUTPUT_ARGS \
$TUNE_ARGS \
--load ${CKPT_LOAD_DIR} \
--save ${CKPT_SAVE_DIR} \
--distributed-backend nccl \
| tee logs/tune_mcore_distill_qwen_1.5b_full_4k.log