BERT 采用fp16预测出错
Created by: Meiyim
paddel: 1.5.1, CUDA9,
在xnli任务上用如下脚本启动finetune(不加载pretrian参数,直接冷启动)会出错。如果加载pretrain参数--init_pretraining_params ${MODEL_PATH}/params
会出一样的错误。
./app/bin/python3 -u run_classifier.py \
--use_cuda true \
--do_train true \
--do_val true \
--do_test false \
--verbose true \
--batch_size 8192 \
--in_tokens true \
--data_dir ./xnli_data/ \
--vocab_path ${MODEL_PATH}/vocab.txt \
--bert_config_path ${MODEL_PATH}/ernie_config.json \
--checkpoints ./checkpoints \
--task_name xnli \
--save_steps 1000 \
--weight_decay 0.01 \
--warmup_proportion 0.0 \
--validation_steps 1000 \
--use_fp16 true \
--epoch 3 \
--max_seq_len 512 \
--learning_rate 1e-4 \
--skip_steps 10 \
--num_iteration_per_drop_scope 1 \
--random_seed 1
~
报错信息:
Python Callstacks:
File "/home/work/chenxuyi/gits/models/PaddleNLP/language_representations_kit/BERT/app/lib/python3.6/site-packages/paddle/fluid/framework.py", line 1771, in append_op
attrs=kwargs.get("attrs", None))
File "/home/work/chenxuyi/gits/models/PaddleNLP/language_representations_kit/BERT/app/lib/python3.6/site-packages/paddle/fluid/optimizer.py", line 1383, in _append_optimize_op
stop_gradient=True)
File "/home/work/chenxuyi/gits/models/PaddleNLP/language_representations_kit/BERT/app/lib/python3.6/site-packages/paddle/fluid/optimizer.py", line 386, in _create_optimization_pass
param_and_grad)
File "/home/work/chenxuyi/gits/models/PaddleNLP/language_representations_kit/BERT/app/lib/python3.6/site-packages/paddle/fluid/optimizer.py", line 532, in apply_gradients
optimize_ops = self._create_optimization_pass(params_grads)
File "/home/work/chenxuyi/gits/models/PaddleNLP/language_representations_kit/BERT/optimization.py", line 107, in optimization
optimizer.apply_gradients(master_param_grads)
File "run_classifier.py", line 209, in main
loss_scaling=args.loss_scaling)
File "run_classifier.py", line 426, in <module>
main(args)
C++ Callstacks:
Tensor holds the wrong type, it holds ::paddle::platform::float16, but desires to be float at [/paddle/paddle/fluid/framework/tensor_impl.h:30]
PaddlePaddle Call Stacks:
0 0x7f5c1be70890p void paddle::platform::EnforceNotMet::Init<char const*>(char const*, char const*, int) + 352
1 0x7f5c1be70c09p paddle::platform::EnforceNotMet::EnforceNotMet(std::__exception_ptr::exception_ptr, char const*, int) + 137
2 0x7f5c1be77c89p float const* paddle::framework::Tensor::data<float>() const + 233
3 0x7f5c1d2aa10bp paddle::operators::AdamOpKernel<paddle::platform::CUDADeviceContext, float>::Compute(paddle::framework::ExecutionContext const&) const + 6507
4 0x7f5c1d2aae53p std::_Function_handler<void (paddle::framework::ExecutionContext const&), paddle::framework::OpKernelRegistrarFunctor<paddle::platform::CUDAPlace, false, 0ul, paddle::operators::Ad
amOpKernel<paddle::platform::CUDADeviceContext, float>, paddle::operators::AdamOpKernel<paddle::platform::CUDADeviceContext, double> >::operator()(char const*, char const*, int) const::{lambda(paddle::fra
mework::ExecutionContext const&)#1}>::_M_invoke(std::_Any_data const&, paddle::framework::ExecutionContext const&) + 35
5 0x7f5c1defef67p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinned
Place, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::deta
il::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_
, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&, paddle::framework::RuntimeContext*) const + 375
6 0x7f5c1deff341p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinned
Place, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::deta
il::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_
, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) const + 529