PPO로 학습하기

Reinforcement Learning from Human Feedback (RLHF)

Mina Parham

AI Engineer

강화학습으로 미세조정

RLHF 과정의 초기 LLM과 보상 모델.

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)

TRL로 PPOTrainer 구현하기

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...