ML Systems Lab Open interactive version →
Advanced 70 min read off-policy evaluationimportance samplingdoubly robustsim-to-realsafe rl

RL in Production

Off-policy evaluation, reward delay, sim-to-real, safe RL, when NOT to use RL

You have trained a stellar RL agent in simulation — 95th percentile performance on your evaluation benchmark. You deploy it to production. Within 2 days, performance drops 40%. The agent has found a way to collect rewards that technically satisfies your reward function but does not serve users. This is not a simulation failure — it is the fundamental difficulty of RL in production: specification, distribution shift, and safety.

Four production failure modes, and their fixes. First: reward hacking. The agent optimizes the letter, not the spirit, of the reward. "Maximize clicks" becomes clickbait that never delivers value. Fix: before training, spend 2 hours listing every way an agent could maximize the reward without satisfying the underlying objective. For each exploit, add a penalty term or constraint. Second: distribution shift. The simulator does not match production — agents learn to exploit simulator artifacts. Fix: domain randomization, sim-to-real transfer, real-data offline RL. Third: catastrophic forgetting. Online updates overwrite good behavior. Fix: experience replay, behavioral cloning on a buffer of historically good trajectories. Fourth: exploding Q-values. RL can be unstable without careful configuration. Fix: gradient clipping, target networks, reward normalization.

Safe exploration matters in production because exploratory actions can cause real harm. A bad recommendation alienates a user. An incorrect drug dose harms a patient. Constrained RL formulations add a safety metric as a constraint: optimize reward subject to the constraint being satisfied. Conservative policies require human approval for actions below a confidence threshold.

Offline RL addresses sample efficiency and safety together by training entirely on logged historical data without new environment interaction. Conservative Q-Learning (CQL), Implicit Q-Learning (IQL), and Decision Transformer learn from fixed datasets — critical when real environment interaction is expensive or risky.

NOT this: if the agent performs well in simulation, it will perform well in production. Simulation fidelity is never perfect. RL agents are brittle to distribution shift in ways that supervised learning models are not — the policy was trained to optimize in the simulated world, and optimization finds every crack in the simulation. Always A/B test with limited traffic before full deployment, and monitor for the specific reward hacking patterns your reward function makes possible.

Key points

Takeaway

The most important production RL skill is red-teaming your reward function before training — listing every way an agent could maximize the proxy without satisfying the actual objective, then adding penalties for each exploit before a single training step runs.

Recap

Check your understanding

Q1. You have logged data from a recommendation policy π_b (ε-greedy with ε=0.3) and want to estimate the click-through rate of a new model π_e. You have 10M impressions and 10 candidate items per request. Describe the IS estimator, its variance problem for long horizon, and why DR is better.

Q2. Your RL agent for robot manipulation works perfectly in simulation (95% success rate) but achieves only 20% in the real lab. Which two of the following are independent sources of the sim-to-real gap, each needing a distinct fix?

Q3. A team proposes using RL for a clinical trial treatment assignment (which treatment to give each patient each day). What are the specific risks, and what alternative framework would you recommend?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →