강화학습 기초RL Fundamentals
MDP·가치·정책 경사·PPO. LLM 사후학습에 필요한 만큼, 정확하게.MDPs, values, policy gradients and PPO — exactly as much as LLM post-training needs.
- MDP와 Bellman 방정식MDPs and the Bellman equation35 분min
강화학습 문제를 MDP로 적고, return·가치함수·Bellman 방정식으로 "좋은 정책"을 정의한다. 같은 틀에 LLM 생성(상태 = prompt + 지금까지의 토큰, 행동 = 다음 토큰)을 올려놓고 무엇이 같고 무엇이 다른지 설명할 수 있게 된다.Write a reinforcement learning problem as an MDP, and define a "good policy" through the return, value functions and the Bellman equation. Then place LLM generation (state = prompt + tokens so far, action = next token) in the same frame and explain what is the same and what is different.
- TD 학습과 Q-learningTD learning and Q-learning35 분min
모델 없이 경험만으로 가치를 배우는 두 길, Monte Carlo와 TD를 bias–variance로 비교하고, SARSA(on-policy)와 Q-learning(off-policy)이 절벽 앞에서 왜 다른 길을 고르는지 설명한다. 이 이분법이 PPO의 critic과 GRPO의 group baseline으로 그대로 이어진다.Compare the two ways of learning values from experience alone, without a model — Monte Carlo and TD — through bias–variance, and explain why SARSA (on-policy) and Q-learning (off-policy) choose different paths at the edge of a cliff. This dichotomy carries straight over to PPO's critic and GRPO's group baseline.
- 정책 경사와 REINFORCEPolicy gradients and REINFORCE40 분min
기대 보상 J(θ)의 기울기를 log-derivative trick으로 유도하고, REINFORCE·reward-to-go·baseline이 왜 불편성을 유지하면서 분산을 줄이는지 증명한다. LLM에서는 이것이 "완성문의 토큰 log-prob 합에 (보상 − baseline)을 곱한 손실"이 된다.Derive the gradient of the expected reward J(θ) with the log-derivative trick, and prove why REINFORCE, reward-to-go and baselines reduce variance while staying unbiased. For an LLM this becomes "a loss that multiplies the sum of a completion's token log-probs by (reward − baseline)".
- Actor-critic과 GAEActor-critic and GAE35 분min
REINFORCE의 Monte Carlo return을 학습된 가치함수(critic)로 대체해 분산을 줄이는 actor-critic을 유도하고, n-step advantage들의 지수 가중평균인 GAE(γ, λ)를 TD 오차의 합으로 정리한다. λ가 critic 오차(bias)와 보상 잡음(variance)을 어떻게 맞바꾸는지 식과 그림으로 보고, PPO-RLHF의 토큰 단위 critic과 그것을 버린 GRPO의 선택을 이해한다.Derives actor-critic, which lowers variance by replacing REINFORCE's Monte Carlo return with a learned value function (the critic), and writes GAE(γ, λ), an exponentially weighted average of n-step advantages, as a sum of TD errors. Shows in formulas and figures how λ trades critic error (bias) against reward noise (variance), and explains the token-level critic of PPO-RLHF and GRPO's choice to drop it.
- Trust region에서 PPO까지From trust regions to PPO40 분min
정책 경사를 크게 밟으면 왜 무너지는지(매개변수 공간의 거리 ≠ 정책 공간의 거리)에서 출발해, importance sampling surrogate, TRPO의 KL trust region, PPO의 clipped objective를 유도한다. A > 0, A < 0 두 경우의 clip을 분석하고, value clipping·entropy·minibatch epoch·approx KL·clip fraction까지 LLM RL에서 쓰는 PPO 손실을 끝까지 구현한다.Starting from why big policy-gradient steps collapse (distance in parameter space ≠ distance in policy space), derives the importance-sampling surrogate, TRPO's KL trust region and PPO's clipped objective. Analyses the clip in both cases, A > 0 and A < 0, and implements the full PPO loss used in LLM RL, down to value clipping, entropy, minibatch epochs, approx KL and clip fraction.