開始使用免費開始

PPO 微調

在你完成訓練器的初始化之後,現在需要初始化迴圈來微調模型。

獎勵訓練器 ppo_trainer 已使用 trl Python 函式庫中的 PPOTrainer 類別進行初始化。

本練習屬於課程

Reinforcement Learning from Human Feedback(RLHF)

檢視課程

練習說明

  • 在 PPO 迴圈中,使用輸入 ids 與訓練器來產生回應張量。
  • 在 PPO 迴圈中完成使用查詢、回應與獎勵資料來最佳化 PPO 模型的步驟。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

for batch in tqdm(ppo_trainer.dataloader): 

    # Generate responses for the given queries using the trainer
    response_tensors = ____(batch["input_ids"])

    batch["response"] = [tokenizer.decode(r.squeeze()) for r in response_tensors]

    texts = [q + r for q, r in zip(batch["query"], batch["response"])]

    rewards = reward_model(texts)

    # Training PPO step with the query, responses ids, and rewards
    stats = ____(batch["input_ids"], response_tensors, rewards)

    ppo_trainer.log_stats(stats, batch, rewards)
編輯並執行程式碼