PPOTrainer: Right way to generate text during inference ?
Hi,
I fine-tune the LLAMA2-7B model using PPOTrainer, for fine-tuning, I use the following generation kwargs:
generation_kwargs = {
"pad_to_multiple_of":16,
"top_k": 0.0,
"top_p": 1.0,
"do_sample": True,
"pad_token_id": tokenizer.pad_token_id,
"eos_token_id": tokenizer.eos_token_id,#,100_000,
"max_new_tokens": max_new_tokens,
}
and got little improvement in the mean reward score
During training the difference between the mean reward of the active and base model is 0.7 on the evaluation dataset and I am satisfied with the result. However, during inference, with below generation_kwargs both the RLHF fine-tune model and base SFT model are performing equally well (mean reward of ~2.3) on the alpaca_eval dataset (100 prompts). Meaning, There is no significant advantage of RLHF fine-tuning.
When the training generation_kwargs, i.e. with top_p=1 and temperature=1 then the RLHF model performs better than the SFT model.
generation_kwargs = {
"top_k": 0,
"top_p": 0.9,
"do_sample": True,
"temperature":0.8,
"max_new_tokens":512
}
During the Inference I am RLHF and SFT models with
rlhf_model = transformers.AutoModelForCausalLM.from_pretrained(
conf.model_name,
use_flash_attention_2=True,
load_in_8bit=True,
device_map=device_map,
torch_dtype=dtype,
cache_dir=CACHE_DIR,
)
# # Load the Lora model
rlhf_model = PeftModel.from_pretrained(base_model,
conf.peft_id+'/final_checkpoint',
adapter_name="rlhf",
is_trainable=False,
device_map=device_map
)
rlhf_model.set_adapter("rlhf")
sft_model = transformers.AutoModelForCausalLM.from_pretrained(
conf.model_name,
use_flash_attention_2=True,
load_in_8bit=True,
device_map=device_map,
torch_dtype=dtype,
cache_dir=CACHE_DIR,
)
I am loading the model incorrectly or setting generation kwargs incorrectly during training? Is it possible to have an example for inference as well?
Interesting, maybe the data you are training with is different than the prompts from alpaca_eval? In general I would try the same generation kwargs you used during training, there the active model should be better, although i wouldn't expect major difference with the slight modifications you made.
Another note: the KL seems quite high towards the end of training (usually ~10 is an ok value).
In summary here's what I would do to debug:
- Use the same generation kwargs as during training
- Use the same prompts as used during training
- Slowly change the 1 + 2 and see when you start to notice the difference
Hope this helps!
Interesting, maybe the data you are training with is different than the prompts from alpaca_eval?
I used the oasst dataset for training, model is behaving similarly even with the evaluation set from the same dataset
The KL seems quite high towards the end of training (usually ~10 is an ok value).
Although KL is higher it does not have any impact on reward and generated responses are relevant and coherent. However, after using the kl-coeff value KL is around 20, which should be better.
In general I would try the same generation kwargs you used during training, there the active model should be better, although i wouldn't expect major difference with the slight modifications you made.
Yes, if I use same generation kwargs used for training then active model is better than sft.
Thanks for your suggestion. I will try them.
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.