Negative loss and KL when using PPO trainer with llama2
Thank you so much for such a great library. But I'm having some problems trying to train with the PPO trainer for llama2-7b. I found that my training charts are strange, the loss appears negative and the KL oscillates between positive and negative.
I have checked other related issues,I was not able to find a solution. My setup details are as follows: config = PPOConfig( steps=50000, model_name="meta-llama/Llama-2-7b-hf", learning_rate=1.41e-5, log_with='wandb', batch_size=512, mini_batch_size=16, gradient_accumulation_steps=4, optimize_cuda_cache=True, early_stopping=False, target_kl=1, ppo_epochs=4, seed=0, init_kl_coef=0.2, adap_kl_ctrl=True, ) generation_kwargs = { "min_length": -1, "min_new_tokens": 10, "top_k": 0.0, "top_p": 1.0, "do_sample": True, "pad_token_id": tokenizer.eos_token_id, "eos_token_id":tokenizer.eos_token_id, "no_repeat_ngram_size":3, "max_new_tokens":50, } I have limited knowledge in this area and would appreciate your guidance, thanks very much!
Can you try to remove: "min_new_tokens": 10? That can lead to negative KL, see: https://huggingface.co/docs/trl/how_to_train#how-to-generate-text-for-training
Can you try to remove:
"min_new_tokens": 10? That can lead to negative KL, see: https://huggingface.co/docs/trl/how_to_train#how-to-generate-text-for-training
Thanks for your qucik reply, I removed min_new_tokens, but the loss/policy and KL are still negative:
Very weird. Can you try switching to GPT-2 just to narrow down the issue? Have you tried running the example script without any modifications?
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
hi I am also encountering this issue with llama-2-7b right now. the strange thing is I started with the llama base model without SFT and it converges just fine, but when I apply the llama model with SFT for ppo with the same set of hyperparameter this problem starts to appear. just wondering if there are any updates on this matter?
I also had the same problem. I believe that Lora-Finetuning an already Lora fine-tuned SFT model causes this problem. After using a full-finetuned SFT model, the problem goes away.
I think this is because the kl_penalty is set to 'kl', in these mode the kl is calculate only on the target tokens, which is the approximate KL divergence. If you set kl_penalty to 'full', the kl will always be positive. https://github.com/huggingface/trl/blob/main/trl/trainer/ppo_trainer.py
Using LoRA fine-tuning, this issue occurred, but when fine-tuning with all parameters, the problem disappeared. So, could it be due to LoRA dropout?
Hi, I am getting 0 KL for my PPO training for my text generation to have a fixed length. I have been using llma3.2 1B model with learning rate 1e-4. Anyone came across 0 KL issue? Mean reward is in the range 0.2. Have trained for 5 epochs, 5k dataset.