시작하기무료로 시작하기

PPO 미세 조정

트레이너를 초기화했으니, 이제 모델을 미세 조정하기 위한 루프를 초기화해야 합니다.

보상 트레이너 ppo_trainertrl Python 라이브러리의 PPOTrainer 클래스를 사용해 초기화되어 있습니다.

이 연습은 강의의 일부입니다

Reinforcement Learning from Human Feedback (RLHF)

강의 보기

연습 안내

  • 입력 ID와 트레이너를 사용해 PPO 루프 내에서 응답 텐서를 생성하세요.
  • 쿼리, 응답, 보상 데이터를 사용해 PPO 모델을 최적화하는 PPO 루프 내의 step을 완성하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

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)
코드 편집 및 실행