25 interview questions on policy gradients & actor-critic, each answered in full. Free to read, no account needed.
What is a policy gradient and why do we use it?
hard- A policy gradient directly optimizes the parameters theta of a stochastic policy πθ(a∣s) to maximize expected return: grad J=E[gradlogπθ(a∣s)⋅A(s,a)].
- Advantages: handles continuous action spaces, learns stochastic policies (crucial for partial observability), and integrates naturally with neural networks.
- Disadvantages: high variance — you need baselines/advantage estimation to stabilize.
What is an actor-critic algorithm?
medium- Actor-critic combines a policy (actor) that picks actions and a value function (critic) that estimates the advantage or value.
- The critic reduces the variance of the policy-gradient estimate.
- Popular variants: A2C/A3C, PPO (clipped surrogate objective, on-policy), and SAC (off-policy, entropy-regularized).
- PPO is the workhorse for RLHF of language models.
Why is PPO so widely used?
medium- PPO is a policy-gradient method with a clipped surrogate objective that prevents the policy from moving too far from the old one at each update.
- It is on-policy, simple to implement, robust across environments with default hyperparameters, and empirically competitive with more complex methods.
- It is the standard algorithm for RLHF of large language models.
REINFORCE — the vanilla policy-gradient algorithm.
medium- For episode τ with return G(τ), update θ ← θ + α G(τ) ∇_θ log π_θ(at∣st) summed over trajectory.
- Unbiased gradient of expected return via log-derivative trick.
- Very high variance: rewards accumulate over full episode → large gradient variance.
- Fixes: (1) subtract baseline b(s) (state-dep baseline / value function), (2) use advantage A(s, a) instead of raw G, (3) reward-to-go instead of full return.
TRPO — Trust Region Policy Optimization.
hard- Constrained optimization: max_θ E[πθ/πold⋅A] s.t.
- E[KL(πold∣∣πθ)] ≤ δ.
- Solved via conjugate gradient + line search on the natural gradient direction.
- Guarantees monotonic policy improvement (theoretically).
- Complex to implement + expensive per update.
- PPO simplifies this to a clipped objective (much easier, similar performance) → PPO is basically TRPO's practical successor.
PPO's clipped surrogate objective — write it and explain.
hard- LCLIP(θ)=E[min(rt(θ)At,clip(rt(θ),1−ε,1+ε)At)] where rt(θ)=π_θ(a∣s)/πold(a∣s).
- Clip stops the policy from moving too far from πold on either side. min ensures we take the more conservative estimate.
- Typical ε = 0.2.
- Combined with GAE advantage and clipped value loss → PPO2 (standard).
- Simpler and works better in practice than TRPO's constrained optimization.
PPO implementation details that actually matter.
hard- Engstrom et al. 2020 'Implementation Matters': (1) value function clipping, (2) reward scaling by running SD, (3) orthogonal init, (4) Adam with fixed lr (β2=0.999), (5) global gradient clip to 0.5, (6) GAE with λ = 0.95, (7) normalize advantages per-batch, (8) LR annealing, (9) N epochs per rollout (~4-10).
- Many published gains are due to these tricks, not the core algorithm.
- Always study a modern reference implementation.
A2C vs A3C — the difference.
medium- A3C (Asynchronous Advantage Actor-Critic, Mnih 2016): multiple async workers each with own env, updating shared params — lock-free async gradient updates.
- A2C (synchronous): workers step in parallel, batch gradients synchronously, single update per batch — better GPU utilization, more reproducible.
- A2C is simpler and empirically as good; A3C was pre-GPU thinking.
- Modern default: A2C or PPO on batched vectorized envs.
Why add an entropy bonus to the policy objective?
medium- Encourages stochastic exploration + prevents premature convergence to suboptimal deterministic policy.
- Loss = -E[log π · A] - β H(π).
- Also gives robustness (multiple near-optimal actions).
- Foundation of SAC (with automatic α tuning) and A3C-style entropy regularization.
- Trade-off: too high β → agent won't commit; too low → early exploitation.
- In LLM RLHF: entropy prevents mode collapse toward one response.
PPO vs SAC — which do you pick?
medium- PPO: on-policy, simple to implement + tune, works everywhere reasonably, standard for RLHF of LLMs. SAC: off-policy, sample-efficient (uses replay), maximum entropy → robust, best for continuous control (robotics).
- Rule: (1) discrete + easy tuning + big rollouts → PPO.
- (2) Continuous + sample efficiency matters → SAC.
- (3) Large-scale distributed → PPO with IMPALA-style actors.
- (4) LLM alignment → PPO (RLHF standard).
DPO — Direct Preference Optimization instead of RLHF PPO.
hard- Rafailov et al. 2023: skips explicit reward model + PPO.
- Direct loss on preference pairs: L(θ) = -E[logσ(βlogπθ(yw∣x)/πref(yw∣x)−βlogπθ(yl∣x)/πref(yl∣x))].
- Derived from KL-constrained reward-maximization → closed-form optimal policy in terms of reward → invert to remove reward.
- Simpler + more stable than PPO.
- Now standard for open-source LLM alignment (Llama, Zephyr).
GRPO — Group Relative Policy Optimization (DeepSeekMath, R1).
hard- PPO variant that skips the value network.
- For each prompt, sample G responses, compute rewards, normalize as advantages: Ai=(ri−meanr)/stdr.
- Uses group-normalized rewards as advantage estimates → no critic needed.
- Preserves PPO's clipped surrogate loss.
- Enables efficient RL fine-tuning of reasoning models (DeepSeek-R1).
- Modern efficiency win for LLM RL.
Categorical vs Gaussian vs beta policies — which and when?
medium- Categorical: discrete actions, softmax over logits.
- Gaussian: continuous, N(μθ(s),σθ(s)2). σ can be state-dependent or state-independent parameter.
- Beta: bounded continuous [a, b] → avoids clipping bias of unbounded Gaussian.
- Tanh-Gaussian (squashed): Gaussian pass through tanh → bounded.
- Modern default: tanh-Gaussian (SAC uses it).
- Beta useful for asymmetric action bounds.
Value function clipping in PPO — why and how?
hard- LVF=max((Vθ(st)−Vtarg)2, (clip(Vθ(st),Vold−ε,Vold+ε)−Vtarg)²) → same trust-region-style clip for the value function.
- Prevents value update from swinging wildly per epoch.
- Modest empirical improvement + more stable.
- Implementation detail buried in original PPO paper's appendix but has real impact.
How does batch size / rollout length affect PPO?
medium- Larger rollout length → lower variance advantage estimates (more MC-like), but slower feedback.
- Batch size (nactors×rolloutlength): must be big enough for a stable gradient estimate; typical 2048-16384.
- Too small → noisy gradients + unstable KL.
- Too big → wasted computation.
- Modern LLM RLHF uses very large batch sizes (millions of tokens per update).
Ornstein-Uhlenbeck noise vs Gaussian noise for continuous control.
medium- OU: temporally correlated noise: dxt=θ(μ−xt)dt + σ dWt → mean-reverting Brownian.
- Used in original DDPG for exploration on physical control tasks — smooth trajectories match physical inertia.
- Later work (TD3, SAC) uses simple Gaussian action noise with equal performance.
- Modern default: Gaussian noise; OU is historical / niche.
MADDPG — Multi-Agent DDPG.
hard- Lowe et al. 2017.
- Each agent has its own actor πi(oi) and critic Qi(s,a1,,an) (centralized: sees ALL agents' actions).
- Actor uses only local obs, critic uses joint info → CTDE.
- Handles cooperative + competitive + mixed.
- Foundational cooperative-continuous-action MARL algorithm.
- Modern variants: MATD3, MASAC.
MAPPO — Multi-Agent PPO.
medium- Yu et al. 2022.
- Simply PPO with a centralized value function using joint observations, shared across cooperative agents.
- Surprisingly strong: matches or beats specialized MARL algorithms (QMIX, MADDPG) on many benchmarks (SMAC, MPE) with careful implementation.
- Foundation of 'PPO is enough' school of MARL.
- Simpler than QMIX/MADDPG; recommended default.
Hierarchical RL — why and how?
hard- Decompose long-horizon tasks into (1) high-level policy over sub-goals or options, (2) low-level policy executing skills.
- Advantages: temporal abstraction (reason over many steps at high level), sample efficiency, transfer of skills.
- Frameworks: Options (Sutton, Precup, Singh), FeUdal Networks (Vezhnevets), HIRO (goal-conditioned low-level), option-critic architecture.
- Modern: hierarchical planners in LLM agents.
DIAYN — Diversity is All You Need for skill discovery.
hard- Eysenbach et al. 2018.
- Unsupervised skill learning: (1) sample skill z from prior, (2) train π(a∣s,z) to maximize mutual information between z and visited states s: max I(s; z).
- Uses a discriminator D(z∣s) trained to identify skill from state.
- Yields diverse skills without external reward.
- Foundation of unsupervised RL and skill libraries for downstream tasks.
Goal-conditioned RL — setup.
medium- Policy π(a∣s,g) conditioned on desired goal g.
- Reward r(s, a, g) = f(distance to g) or -1 until g reached.
- Enables one policy for many tasks.
- Combined with HER (relabel failed attempts) for sample efficiency.
- Foundation of universal value function approximation (UVFA, Schaul 2015).
- Modern uses: robot manipulation reaching diverse target poses, hierarchical HIRO planning, generalist RL agents.
Interview: 'explain why PPO is on-policy but uses a ratio to importance-sample.'
hard- On-policy in spirit: PPO uses only recent data collected under πold (closetoπθ).
- The importance ratio r = π_θ / πold accounts for the fact that after several gradient steps within the epoch, π_θ has drifted from the data-generating πold — but not far (clipping enforces this).
- Compare: fully off-policy (SAC, Q-learning) reuses ancient data.
- PPO's 'small IS correction' is the whole point of the clipped surrogate.
Curriculum learning in RL — how to design one?
medium- Order training from easy to hard tasks: (1) start with dense reward, gradually sparsify.
- (2) Start with easy env, add complexity (obstacles, distractors).
- (3) Adaptive: automatic difficulty tuning to keep learning at frontier of ability (POET, ADR).
- (4) Self-play induces natural curriculum via opponent's growing skill.
- (5) Sub-goal decomposition: reach intermediate states before final.
- Modern: adversarial curriculum where env teacher proposes tasks the student can barely solve.
What is the clipping in PPO actually protecting you from?
hard- From a policy update so large that the data you collected no longer describes the policy you now have.
- Policy gradient estimates are only valid near the behaviour policy, so a big step invalidates the very samples that justified it, and the classic symptom is a policy that collapses after a promising run.
- Clipping the probability ratio removes the incentive to move a given action's probability beyond a trust region, so the objective flattens instead of rewarding ever larger changes.
- It is a cheap surrogate for the constrained optimization TRPO solves exactly, trading theoretical guarantees for a first-order method that fits in a few lines.
- It does not prevent divergence on its own, which is why implementations also limit epochs per batch and monitor the KL divergence.
When does the sample inefficiency of on-policy methods stop mattering?
medium- When samples are cheap and stability is expensive, which is the case with a fast parallelizable simulator.
- If you can run thousands of environment steps per second across many workers, PPO's need for fresh data on every update costs wall-clock time you have, and you get back a method that is markedly less brittle and has far fewer hyperparameters that can silently destroy a run.
- Off-policy methods such as SAC reuse a replay buffer and can be an order of magnitude more sample efficient, which is what you need when each interaction involves a real robot, a real user, or a slow physics engine.
- The decision therefore rests on the cost of an environment step relative to the cost of engineering time spent stabilizing training.