เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การ fine-tune ด้วย PPO

หลังจาก initialize trainer เรียบร้อยแล้ว ขั้นตอนต่อไปคือสร้าง loop สำหรับ fine-tune โมเดล

ได้ initialize reward trainer ppo_trainer โดยใช้คลาส PPOTrainer จากไลบรารี trl ของ Python ไว้แล้ว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Reinforcement Learning from Human Feedback (RLHF)

ดูคอร์ส

คำแนะนำการฝึกหัด

  • สร้าง response tensor โดยใช้ input id และ trainer ภายใน PPO loop
  • เติมโค้ดใน step ของ PPO loop ให้ครบ โดยใช้ข้อมูล queries, response และ reward เพื่อปรับแต่งโมเดล 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)
แก้ไขและรันโค้ด