shibing624 / MedicalGPT

MedicalGPT: Training Your Own Medical GPT Model with ChatGPT Training Pipeline. 训练医疗大模型,实现了包括增量预训练(PT)、有监督微调(SFT)、RLHF、DPO、ORPO。
Apache License 2.0
3.19k stars 487 forks source link

rm阶段,loss降到0,并且图看起来很奇怪 #403

Open zhengshi119 opened 3 weeks ago

zhengshi119 commented 3 weeks ago

Describe the Question

Please provide a clear and concise description of what the question is.

我的 sh 如下: CUDA_VISIBLE_DEVICES=1,3 python reward_modeling.py \ --model_type llama \ --model_name_or_path ./test_4/merged-sft_CHIP-MDCFNPC \ --train_file_dir ./test_4/data/reward \ --validation_file_dir ./test_4/data/reward \ --per_device_train_batch_size 1 \ --per_device_eval_batch_size 1 \ --do_train \ --use_peft True \ --seed 42 \ --max_train_samples 1000 \ --max_eval_samples 10 \ --num_train_epochs 1 \ --max_steps 1000 \ --learning_rate 2e-5 \ --warmup_ratio 0.05 \ --weight_decay 0.001 \ --logging_strategy steps \ --logging_steps 10 \ --eval_steps 100 \ --evaluation_strategy steps \ --save_steps 500 \ --save_strategy steps \ --save_total_limit 3 \ --max_source_length 256 \ --max_target_length 256 \ --output_dir ./test_4/outputs-rm-v1_IMCS-V2 \ --overwrite_output_dir \ --ddp_timeout 30000 \ --logging_first_step True \ --target_modules all \ --lora_rank 8 \ --lora_alpha 16 \ --lora_dropout 0.05 \ --torch_dtype float32 \ --device_map auto \ --report_to tensorboard \ --ddp_find_unused_parameters False \ --remove_unused_columns False \ --gradient_checkpointing True

我已经把torch_dtype设置为float32了,为什么还是会出现loss=0的情况。 微信图片_20240822113105

shibing624 commented 3 weeks ago

--per_device_train_batch_size 1 需要改为大于1

zhengshi119 commented 3 weeks ago

--per_device_train_batch_size 1 需要改为大于1

当per_device_train_batch_size==4时,出现问题:Cannot handle batch sizes > 1 if no padding token is defined,这是为什么?

shibing624 commented 2 weeks ago

set padding token = 0

zhengshi119 commented 2 weeks ago

set padding token = 0

出问题:ValueError: Cannot set a non-string value as the PAD token

我在代码添加 tokenizer.pad_token = 0 的位置: if tokenizer.pad_token_id is None: if tokenizer.unk_token_id is not None: tokenizer.pad_token = tokenizer.unk_token else: tokenizer.pad_token = tokenizer.eos_token tokenizer.pad_token = 0 logger.info(f"Add pad_token: {tokenizer.pad_token}, pad_token_id: {tokenizer.pad_token_id}") logger.debug(f"Tokenizer: {tokenizer}")

这是为什么

XiaozhuLove commented 2 weeks ago

set padding token = 0

出问题:ValueError: Cannot set a non-string value as the PAD token

我在代码添加 tokenizer.pad_token = 0 的位置: if tokenizer.pad_token_id is None: if tokenizer.unk_token_id is not None: tokenizer.pad_token = tokenizer.unk_token else: tokenizer.pad_token = tokenizer.eos_token tokenizer.pad_token = 0 logger.info(f"Add pad_token: {tokenizer.pad_token}, pad_token_id: {tokenizer.pad_token_id}") logger.debug(f"Tokenizer: {tokenizer}")

这是为什么

我直接改了权重文件里的config文件,不报错了,也能运行了,不知道对不对 "attention_dropout": 0.0, "pad_token_id": 151643, "bos_token_id": 151643,

shibing624 commented 2 weeks ago

用的啥模型?为啥pad token都没设置?是非标准模型吗

zhengshi119 commented 2 weeks ago

用的啥模型?为啥pad token都没设置?是非标准模型吗

模型是Meta-Llama-3.1-8B

zhengshi119 commented 2 weeks ago

是llama3 的 pad token的问题, 在在以下json文件添加pad_token就没问题了 image

修改完之后,不会出现忽高忽低的情况,但是step==30时,就已经loss=0,eval_loss接近0 image

为什么step才30,loss就接近0 了,这是为什么?

我的sh如下: CUDA_VISIBLE_DEVICES=0,1,2,3 python reward_modeling.py \ --model_type llama \ --model_name_or_path ./test_5/merged-sft \ --train_file_dir ./test_4/data/reward \ --validation_file_dir ./test_4/data/reward \ --per_device_train_batch_size 2 \ --per_device_eval_batch_size 1 \ --do_train \ --use_peft True \ --seed 42 \ --max_train_samples 1000 \ --max_eval_samples 100 \ --num_train_epochs 1 \ --max_steps 500 \ --learning_rate 2e-5 \ --warmup_ratio 0.05 \ --weight_decay 0.001 \ --logging_strategy steps \ --logging_steps 10 \ --eval_steps 10 \ --evaluation_strategy steps \ --save_steps 100 \ --save_strategy steps \ --save_total_limit 3 \ --max_source_length 1024 \ --max_target_length 256 \ --output_dir ./test_5/outputs-rm-v1 \ --overwrite_output_dir \ --ddp_timeout 30000 \ --logging_first_step True \ --target_modules all \ --lora_rank 8 \ --lora_alpha 16 \ --lora_dropout 0.05 \ --torch_dtype float32 \ --device_map auto \ --report_to tensorboard \ --ddp_find_unused_parameters False \ --remove_unused_columns False \ --gradient_checkpointing True