Search

Search papers and lessons

Eureka: Human-Level Reward Design via Coding Large Language Models

Yecheng Jason Ma, William Liang, Guanzhi Wang et al. · 2023

Eureka uses a coding language model to write reward functions, then improves them by evolutionary search guided by written feedback on training, and beats expert-written rewards on most tasks.

On this page

  • Colour = topic mix
  • Reinforcement learning
  • Calculus
  • Discrete math
  • Probability
  • Neural network basics
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

Reinforcement learning needs a reward function, and writing one that makes a robot do a hard task well is slow, expert work. Eureka hands that job to a coding language model: it reads the simulator's source code, writes candidate reward functions in Python, trains a policy with each one on a GPU, and feeds a summary of the training back to the model so it can edit the best candidate. Over 29 benchmark tasks, its rewards beat the expert-written rewards on 83 percent of tasks, and with curriculum learning it produced the first simulated pen-spinning skill on a five-finger hand.

Builds on: Reinforcement Learning, Reward Shaping, In-Context Learning, Genetic Algorithm, Proximal Policy Optimization (PPO) · Leads to: Reward Model

Why it mattered

Reward design is a known bottleneck. The paper cites a survey in which 92 percent of polled reinforcement learning researchers and practitioners reported manual trial-and-error reward design, and 89 percent said their rewards were sub-optimal. Rewards also cause unintended behaviour when they are slightly wrong.

Before Eureka, language models had been used for reward design in a limited way. The L2R approach asks an LLM to fill in a motion template and then to call hand-written reward primitives, so it can only express what its template allows. Eureka removes that limit by asking for free-form Python, with no task-specific template and no few-shot examples, and it showed that the generated rewards could beat expert ones on hard dexterous tasks where earlier LLM approaches lagged.

The paper also opened a route to human input without retraining the model. A person can give a reward as a starting point, or describe in words what a good behaviour should look like, and Eureka folds that into its next round of reward writing. The authors show this produced a safer gait for a simulated humanoid.

The problem

Formally, the paper frames reward design as a reward generation problem. A task is described in a string ll. Every part of the environment is code, and the goal is to output a reward function RR, as code, such that a learning algorithm trained on RR produces a policy that scores highly under a fitness function FF. The fitness function is the true measure of success, and it can only be queried by training a policy and scoring it. It is not a differentiable signal the learner can follow. The reward is the designer's proxy for FF.

Three obstacles make this hard for a language model. First, the first reward it writes may not run. Second, even a runnable reward is usually far from the best one. Third, the fitness score alone says little about why a reward failed. Prompts with task-specific hints fix the first two for one task, but they do not scale to new tasks. That gap is what Eureka tries to close without human hints.

The paper also notes that reward design interacts with the reinforcement learning algorithm. The same reward can perform very differently under different hyperparameters. This makes a single number from one training run a noisy guide to a reward's quality.

How it works

Eureka runs a loop of three steps. Each step has a clear input and output, and the loop repeats for a fixed number of rounds.

flowchart LR
  A[Task text and environment code] --> B[Coding LLM writes K reward functions]
  B --> C[Train a policy with each reward on a GPU simulator]
  C --> D[Score each policy with the fitness function]
  D --> E[Reflection: summarise reward components over training]
  E --> F[Next prompt holds the best reward and its reflection]
  F --> B

Here is one round, traced with small round numbers. The numbers are illustrative; they are not from the paper.

  1. Start with the environment as context. The prompt contains the task description and the raw environment code, with only the parts that expose the state and action variables. Check: the model sees the variables a reward can use, and nothing about the simulator's internals.
  2. Sample K=3K = 3 reward functions. Suppose the model returns three Python functions. One fails to run, and two run. The paper uses K=16K = 16 samples per round, which makes it very likely that at least one runs. Check: three candidates, one error, two usable.
  3. Train a policy for each usable reward. Each reward is used to train a policy with the same reinforcement learning algorithm and the same hyperparameters. Suppose the two policies score 0.70.7 and 0.40.4 on the fitness function. Check: the scores are measured on the true task fitness, not on the reward itself.
  4. Reflect on the best candidate. The system records the values of each reward component across training checkpoints and writes a short text summary. Suppose the best reward has a penalty term that stays near zero for the whole run. The reflection says so. Check: the reflection names a specific component and what it did.
  5. Ask for an edit. The next prompt contains the best reward so far, its reflection, and an instruction to improve it. The model returns new candidates, which may change a weight, a function shape, or add a term. Check: each new candidate starts from the best one, not from scratch.
  6. Keep the best and repeat. If the new best score beats the stored score, it replaces it. The paper runs 55 iterations per run and 55 independent runs per task. Check: the stored reward never gets worse.

Step 4 is what separates Eureka from a plain search. A score of 0.40.4 says that a reward is worse, but not why. The reflection points at the component that helped or hurt.

The math

Definition: Reward generation problem
Given a task description ll, an environment written as code MM, and a fitness function FF that scores any policy, find a reward function RR, written as code, that maximises F(AM(R))F(\mathcal{A}_M(R)), where AM\mathcal{A}_M is the reinforcement learning algorithm that returns a policy trained on RR in MM.

The paper's setting extends the reward design problem of Singh and colleagues. In their notation, a world model M=(S,A,T)M = (S, A, T) has states SS, actions AA and transition function TT. The learner AM\mathcal{A}_M maps a reward to a policy π:S→Δ(A)\pi : S \to \Delta(A), which is a probability distribution over actions in each state. The learner turns a reward into a Policy (Reinforcement Learning) by solving the Markov decision process defined by MM and RR.

Step 1 in symbols: the sample

Each round draws KK candidate rewards from the language model, conditioned on the prompt pp:

R1,…,RK∼LLM(l,M,p).R_1, \dots, R_K \sim \mathrm{LLM}(l, M, p).

The independence matters. If each sample fails to run with probability qq, and samples are independent, then all KK fail with probability qKq^K. With q=0.5q = 0.5 and K=16K = 16 that is 0.516≈1.5×10−50.5^{16} \approx 1.5 \times 10^{-5}. The paper's claim is this exponential decrease, and it reports that 16 samples gave at least one executable reward in the first round for every environment it considered.

Step 2 in symbols: score and select

Each runnable candidate gets a score sk=F(Rk)s_k = F(R_k), the fitness of the policy trained on it. The round's best candidate is the one with the highest score:

k∗=arg⁡max⁡ksk.k^{\ast} = \arg\max_{k} s_k.

The prompt for the next round uses Rk∗R_{k^{\ast}}, and a stored best reward REurekaR_{\mathrm{Eureka}} is replaced only when sk∗s_{k^{\ast}} beats the stored score. This is the elitism rule in Algorithm 1 of the paper, and it is why the stored reward never gets worse.

Step 3 in symbols: the reflection

The reflection is a text summary of the component values c1(t),…,cm(t)c_1(t), \dots, c_m(t) logged at intermediate checkpoints tt of the policy's training, together with the fitness value. Its purpose is to give the next round a signal that separates the components. The fitness score alone is one number per run; the reflection gives a trajectory per component.

Step 4 in symbols: the human normalised score

For the Isaac tasks, where the fitness metric changes meaning from task to task, the paper reports a normalised score relative to the sparse benchmark reward and the human reward:

normalised score=Method−Sparse∣Human−Sparse∣.\text{normalised score} = \frac{\texttt{Method} - \texttt{Sparse}}{\lvert \texttt{Human} - \texttt{Sparse} \rvert}.

A score of 11 means the method matches the human reward, and a score above 11 means it beats it. The denominator is the gap the human reward closes, so it scales the comparison across tasks. For the 52 percent average in the abstract, the paper clips each task's score to the range 0 to 3 before averaging over all 29 tasks, so a few very large outliers do not dominate.

Illustration with round numbers. If Method =0.6= 0.6, Sparse =0.1= 0.1 and Human =0.9= 0.9, then the normalised score is (0.6−0.1)/∣0.9−0.1∣=0.5/0.8=0.625(0.6 - 0.1) / |0.9 - 0.1| = 0.5 / 0.8 = 0.625. This is our arithmetic on invented values, not a figure from the paper.

Results

The results below come from the paper's experiments section and abstract. Policies were trained with PPO, using hyperparameters tuned for the human rewards, and each final reward was trained with five PPO runs.

EvaluationTasksResultWhere it is reported
Overall29 tasks, 10 robot morphologiesOutperforms human rewards on 83 percent of tasks; average normalised improvement of 52 percentAbstract
Isaac benchmark9Matches or exceeds human level on all tasksSection 4.3
Dexterity benchmark20Exceeds or matches human level on 15 of 20 tasksSection 4.3
Ablation: no reward reflectionIsaacAverage normalised score lower by 28.6 percentSection 4.3
Ablation: GPT-3.5 instead of GPT-4IsaacDegrades, but matches or exceeds human level on most tasksSection 4.3
Pen spinning, fine-tuned after curriculumShadow HandSpins the pen for many cycles in a rowSection 4.3
Pen spinning, from scratch or pre-trained onlyShadow HandCannot complete a single cycleSection 4.3

The paper also reports that Eureka improves steadily across its evolution iterations, and that a control which spends the same reward budget on 32 first-attempt samples, with no evolution, scores lower after two iterations of Eureka. So the gain comes from the iterative edits, not from sampling more.

Human-in-the-loop results are reported more qualitatively. Starting Eureka from a human reward gave rewards that beat both Eureka alone and the human reward on the chosen tasks. In a user study with 20 people, users preferred the policy trained on a reward that was edited from human reward reflection, which the paper describes as a large majority.

What they mean. Free-form reward code, written from the source of the environment, can match or beat expert design across a broad set of benchmarks, and the iterative loop is what drives the gains. The paper finds that Eureka rewards are mostly weakly correlated with the human rewards, and least correlated on the harder tasks, which suggests the model is finding reward structures the human did not write. The pen-spinning result shows the method can reach a skill that earlier reward design had not.

Limits. The benchmarks are simulated, and the policy learner is PPO with hyperparameters tuned on the human rewards, which favours the human baseline. The main backbone was GPT-4 at a fixed snapshot, and results with GPT-3.5 are lower. The benchmark tasks were released concurrently with or after GPT-4's knowledge cut-off, which the paper uses as evidence against memorisation. Finally, the paper evaluates against a single task fitness, and for tasks where that fitness is missing or misaligned, the human feedback route is a separate, less measured step.

Reading guide

The paper has a short introduction, a formal setting, a method with three parts, an experiments section, related work, a conclusion, and a long appendix. Read them in this order.

  • Section 1, Introduction. Motivation, the reward design survey, and the three design choices. Needs Reinforcement Learning, Reward Shaping and Sparse Reward Problem. The sparse reward problem explains why shaping is needed in the first place.
  • Section 2, Problem setting. The reward design problem and the reward generation problem. Needs Markov Decision Process and Policy (Reinforcement Learning).
  • Section 3.1, Environment as context. How the environment code is passed to the model. Needs Language Model and In-Context Learning, because the method depends on the model reading code in its prompt.
  • Section 3.2, Evolutionary search. Sampling KK candidates, selecting the best, and mutating it. Needs Genetic Algorithm and Evolution Strategies.
  • Section 3.3, Reward reflection. The text summary of component values. Needs Reward Shaping.
  • Section 4, Experiments. Baselines, training details, and the results. Needs Proximal Policy Optimization (PPO) for the learner and Curriculum Learning for the pen-spinning setup.
  • Section 5, Related Work. Manual reward design, evolutionary reward search and inverse reinforcement learning. The paper contrasts Eureka with Inverse Reinforcement Learning, which learns rewards from demonstrations instead of writing them.
  • Appendices. Appendix A has the full prompts and is the place to look if you want the exact wording. Appendix H discusses limitations.

Check yourself

QuestionWhy does Eureka sample many reward functions per round instead of one?Show answer
Because the first reward the model writes may not run, and even a runnable reward is usually sub-optimal. If samples are independent and each fails with some probability, the chance that all of them fail falls exponentially with the number of samples. Sampling many also gives the selection step several candidates to compare. The paper uses K=16K = 16 per round.
QuestionA round has three candidate rewards with fitness scores 0.20.2, 0.70.7 and 0.40.4. Which one is kept, and what happens if the stored best so far is 0.60.6?Show answer
The candidate with score 0.70.7 is the round's best. Since 0.70.7 is greater than the stored 0.60.6, the stored reward is replaced by this candidate. If the stored score had been 0.80.8, nothing would be replaced, because the stored reward is kept unless a candidate beats it.
QuestionWhy does the reflection report the values of individual reward components instead of only the fitness score?Show answer
The fitness score is a single number per trained policy. It shows whether a reward is better or worse, but not which part of the reward helped or hurt. The reflection logs each component across training checkpoints, so the next prompt can point at a specific term, such as a penalty that never changes, and ask for a targeted edit.
QuestionUsing the normalised score formula, a method scores 0.90.9 on a task where the sparse reward is 0.20.2 and the human reward is 0.60.6. What is the normalised score, and is the method better than the human reward?Show answer
Numerator: 0.9−0.2=0.70.9 - 0.2 = 0.7. Denominator: ∣0.6−0.2∣=0.4|0.6 - 0.2| = 0.4. The normalised score is 0.7/0.4=1.750.7 / 0.4 = 1.75. Since it is above 11, the method does better than the human reward on this task, by the paper's measure.

Sources

Read the full paper

Yecheng Jason Ma, William Liang, Guanzhi Wang et al., 2023. arXiv:2310.12931