models icon indicating copy to clipboard operation
models copied to clipboard

从bert pretrain打印的结果如何计算吞吐率性能?

Open mir-of opened this issue 6 years ago • 5 comments

跑单机单卡, batch_size: 16, 打印的结果如下:

epoch: 1, progress: 1/64, step: 2, loss: 11.409644, ppl: 14829.729492, next_sent_acc: 0.562500, speed: 5.488533 steps/s, file: part-00012-01b065c2-8e4a-442b-9920-d986845ab3d2-c000.txt.gz

跑单机4卡, batch_size: 64, 打印的结果如下: epoch: 1, progress: 1/64, step: 3, loss: 8.647623, ppl: 2778.657471, next_sent_acc: 0.433594, speed: 1.436274 steps/s, file: part-00035-01b065c2-8e4a-442b-9920-d986845ab3d2-c000.txt.gz

我的问题是: 单机单卡的速度是5.488533 steps/s, 换算成吞吐率是:5.488533 * 16 = 87.816528 sample/s。

单机4卡的速度是1.436274 steps/s, 换算成吞吐率是:1.436274 * 64 = 91.921536 samples/s。

那么,4卡相对于单卡,加速比是 91.921536/87.816528 = 1.046。

1)请问这样计算吞吐率和加速比的方法是正确的吗? 2)如果计算方式是正确的,请问加速比很低的原因是什么? 3)如果计算方式是错误的,请问正确的计算方法是什么?

附上我的运行命令: 仓库:https://github.com/PaddlePaddle/models.git commit: 4ffbe264e69b296cab387b4879e0ee0a37801c61

单机单卡:

CUDA_VISIBLE_DEVICES=0 \
python3 -u PaddleNLP/PaddleLARK/BERT/train.py \
	--is_distributed false \
        --use_cuda true \
        --weight_sharing true \
        --batch_size 16 \
        --in_tokens False \
        --data_dir $PADDLE_BERT_DATA_DIR \
        --validation_set_dir $PADDLE_BERT_DATA_DIR \
        --bert_config_path $CONFIG_PATH \
        --vocab_path $VOCAB_PATH \
        --num_train_steps 120 \
        --warmup_steps 0 \
        --epoch 1 \
        --max_seq_len 128 \
        --skip_steps 1 \
        --generate_neg_sample=False

单机4卡:

CUDA_VISIBLE_DEVICES=0,1,2,3 \
python3 -u PaddleNLP/PaddleLARK/BERT/train.py \
	--is_distributed false \
        --use_cuda true \
        --weight_sharing true \
        --batch_size 64 \
        --in_tokens False \
        --data_dir $PADDLE_BERT_DATA_DIR \
        --validation_set_dir $PADDLE_BERT_DATA_DIR \
        --bert_config_path $CONFIG_PATH \
        --vocab_path $VOCAB_PATH \
        --num_train_steps 120 \
        --warmup_steps 0 \
        --epoch 1 \
        --max_seq_len 128 \
        --skip_steps 1 \
        --generate_neg_sample=False

mir-of avatar Dec 17 '19 14:12 mir-of

这里的--batch_size 是单卡的batch大小,所以在测吞吐率时,对于单机4卡的情况,也要把batch size设置成16.

kuke avatar Dec 18 '19 02:12 kuke

这里的--batch_size 是单卡的batch大小,所以在测吞吐率时,对于单机4卡的情况,也要把batch size设置成16.

不对吧,代码里说的是“The total number of examples in one batch for training”。并且代码里没有找到关于多卡会将batch_size加倍的逻辑。 https://github.com/PaddlePaddle/models/blob/1c52e00543f52fa46f6420f4fb6bf76b3a56249b/PaddleNLP/PaddleLARK/BERT/train.py#L83

mir-of avatar Dec 18 '19 06:12 mir-of

按照您的说法,--batch_size=32, 是指单卡的batch大小,运行了单机单卡,单机4卡,和2机8卡:

单机单卡: epoch: 1, progress: 1/64, step: 2, loss: 10.309646, ppl: 11803.237305, next_sent_acc: 0.562500, speed: 3.092194 steps/s, file: part-00060-01b065c2-8e4a-442b-9920-d986845ab3d2-c000.txt.gz

单机4卡: epoch: 1, progress: 1/64, step: 2, loss: 9.583839, ppl: 7204.416016, next_sent_acc: 0.656250, speed: 2.411773 steps/s, file: part-00029-01b065c2-8e4a-442b-9920-d986845ab3d2-c000.txt.gz

2机8卡: epoch: 1, progress: 1/64, step: 2, loss: 10.032979, ppl: 6925.938477, next_sent_acc: 0.609375, speed: 4.589401 steps/s, file: part-00008-01b065c2-8e4a-442b-9920-d986845ab3d2-c000.txt.gz

单机单卡吞吐率: 3.092194 * 32 = 98.950208 samples/s 单机4卡吞吐率: 2.411773 * 32 * 4 = 308.706944 sample/s, 加速比: 308.706944/98.950208 = 3.12 2机8卡吞吐率:4.589401 * 32 * 8 = 1174.886656, sample/s, 加速比:1174.886656/ 98.950208 = 11.87

我的问题是:

1)2机8卡相对于单机单卡的加速比计算方式正确吗? 2)如果不正确,请问正确的计算方法是什么? 3)另外对于多机运行,请问这里skip_steps = args.skip_steps * nccl2_num_trainers, 需要乘nccl2_num_trainers原因是什么? https://github.com/PaddlePaddle/models/blob/1c52e00543f52fa46f6420f4fb6bf76b3a56249b/PaddleNLP/PaddleLARK/BERT/train.py#L353

附上运行命令: 单机单卡:

CUDA_VISIBLE_DEVICES=0 \
python3 -u PaddleNLP/PaddleLARK/BERT/train.py \
	--is_distributed false \
        --use_cuda true \
        --weight_sharing true \
        --batch_size 32 \
        --in_tokens False \
        --data_dir $PADDLE_BERT_DATA_DIR \
        --validation_set_dir $PADDLE_BERT_DATA_DIR \
        --bert_config_path $CONFIG_PATH \
        --vocab_path $VOCAB_PATH \
        --num_train_steps 120 \
        --warmup_steps 0 \
        --epoch 1 \
        --max_seq_len 128 \
        --skip_steps 1 \
        --generate_neg_sample=False

单机4卡:

CUDA_VISIBLE_DEVICES=0,1,2,3 \
python3 -u PaddleNLP/PaddleLARK/BERT/train.py \
	--is_distributed false \
        --use_cuda true \
        --weight_sharing true \
        --batch_size 32 \
        --in_tokens False \
        --data_dir $PADDLE_BERT_DATA_DIR \
        --validation_set_dir $PADDLE_BERT_DATA_DIR \
        --bert_config_path $CONFIG_PATH \
        --vocab_path $VOCAB_PATH \
        --num_train_steps 120 \
        --warmup_steps 0 \
        --epoch 1 \
        --max_seq_len 128 \
        --skip_steps 1 \
        --generate_neg_sample=False

2机8卡:

node1:

CUDA_VISIBLE_DEVICES=0,1,2,3 \
current_endpoint=${node1_ip}:9184 \
worker_endpoints=${node1_ip}:9184,${node2_ip}:9185 \
python3 -u PaddleNLP/PaddleLARK/BERT/train.py \
	--is_distributed true \
        --use_cuda true \
        --weight_sharing true \
        --batch_size 32 \
        --in_tokens False \
        --data_dir $PADDLE_BERT_DATA_DIR \
        --validation_set_dir $PADDLE_BERT_DATA_DIR \
        --bert_config_path $CONFIG_PATH \
        --vocab_path $VOCAB_PATH \
        --num_train_steps 120 \
        --warmup_steps 0 \
        --epoch 1 \
        --max_seq_len 128 \
        --skip_steps 1 \
        --generate_neg_sample=False

node2:

CUDA_VISIBLE_DEVICES=0,1,2,3 \
current_endpoint=${node2_ip}:9185 \
worker_endpoints=${node1_ip}:9184,${node2_ip}:9185 \
python3 -u PaddleNLP/PaddleLARK/BERT/train.py \
	--is_distributed true \
        --use_cuda true \
        --weight_sharing true \
        --batch_size 32 \
        --in_tokens False \
        --data_dir $PADDLE_BERT_DATA_DIR \
        --validation_set_dir $PADDLE_BERT_DATA_DIR \
        --bert_config_path $CONFIG_PATH \
        --vocab_path $VOCAB_PATH \
        --num_train_steps 120 \
        --warmup_steps 0 \
        --epoch 1 \
        --max_seq_len 128 \
        --skip_steps 1 \
        --generate_neg_sample=False

mir-of avatar Dec 18 '19 07:12 mir-of

两机加速比的计算方式没有问题,乘以nccl2_num_trainers是内部在实验的时候,为了方便换算成单机的吞吐量而做的修改,也可以不乘以机器数量

kuke avatar Dec 19 '19 09:12 kuke

两机加速比的计算方式没有问题,乘以nccl2_num_trainers是内部在实验的时候,为了方便换算成单机的吞吐量而做的修改,也可以不乘以机器数量

好的,谢谢

mir-of avatar Dec 20 '19 08:12 mir-of