Навчання з PPO

Reinforcement Learning from Human Feedback (RLHF)

Mina Parham

AI Engineer

Тонке налаштування з підкріплювальним навчанням

Початкові LLM і модель винагород у процесі RLHF.

Reinforcement Learning from Human Feedback (RLHF)

Тонке налаштування з підкріплювальним навчанням

Повний процес RLHF.

Reinforcement Learning from Human Feedback (RLHF)

Тонке налаштування мовної моделі з PPO

 

Схема: запит до LLM для генерації продовження.

Reinforcement Learning from Human Feedback (RLHF)

Тонке налаштування мовної моделі з PPO

 

Схема: запит до LLM, що завершує рядок: 'we're half way there, oh livin' on a prayer'.

Reinforcement Learning from Human Feedback (RLHF)

Тонке налаштування мовної моделі з PPO

 

Схема: запит до LLM з завершенням 'we're half way there, oh livin' on a prayer', яке оцінює інша LLM.

Reinforcement Learning from Human Feedback (RLHF)

Тонке налаштування мовної моделі з PPO

  • PPO: поступове коригування моделі
  • Уникає перенавчання на відгуках

Робот і равлик як символ повільного вдосконалення алгоритму.

Reinforcement Learning from Human Feedback (RLHF)

Реалізація PPOTrainer у TRL

from trl import PPOConfig
config = PPOConfig(model_name="gpt2",learning_rate=1.4e-5)
from trl import AutoModelForCausalLMWithValueHead
model = AutoModelForCausalLMWithValueHead.from_pretrained(config.model_name)
tokenizer = AutoTokenizer.from_pretrained(config.model_name)
from trl import PPOTrainer
ppo_trainer = PPOTrainer(model=model,config=config,dataset=dataset,
                         tokenizer=tokenizer)
Reinforcement Learning from Human Feedback (RLHF)

Запуск циклу навчання

for epoch in tqdm(range(10), "epoch: "):


for batch in tqdm(ppo_trainer.dataloader):
# Get responses response_tensors = ppo_trainer.generate(batch["input_ids"])
batch["response"] = [tokenizer.decode(r.squeeze()) for r in response_tensors]
# Compute reward score texts = [q + r for q, r in zip(batch["query"], batch["response"])]
rewards = reward_model(texts)
stats = ppo_trainer.step(query_tensors, response_tensors, rewards) ppo_trainer.log_stats(stats, batch, rewards)
Reinforcement Learning from Human Feedback (RLHF)

Давайте потренуємось!

Reinforcement Learning from Human Feedback (RLHF)

Preparing Video For Download...