On The Fragility of Learned Reward Functions
Abstract
Reward functions are notoriously difficult to specify, especially for tasks with complex goals.
Reward learning approaches attempt to infer reward functions from human feedback and preferences.
Prior works on reward learning have mainly focused on the performance of policies trained alongside the reward function.
This practice, however, may fail to detect learned rewards that are not capable of training new policies from scratch and thus do not capture the intended behavior.
Our work focuses on demonstrating and studying the causes of these relearning failures in the domain of preference-based reward learning.
We demonstrate with experiments in tabular and continuous control environments that the severity of relearning failures can be sensitive to changes in reward model design and the trajectory dataset composition.
Based on our findings, we emphasize the need for more retraining-based evaluations in the literature.
Introduction
Reward functions for most real-world tasks are difficult or impossible to specify procedurally.
Specifically, hand-designed reward functions frequently misspecify the task [19].
The field of reward learning attempts to overcome this challenge by designing algorithms to infer reward functions from data.
These learned reward functions aim to succinctly represent the desired behaviors [23], drastically reduce the amount of human feedback required to learn a task [8] and allow practitioners to generalize these behaviors to new environments [10].
One of the most promising approaches is to learn reward functions from binary human preferences over trajectory segments where these segments are collected online using a sampler agent trained to optimize the learned reward [8].
This form of preference-based reward learning is already being used to train large language models to summarize [43] and become more helpful and harmless [3].
Prior work has typically focused on the performance of the sampler agent [20, 8].
Unfortunately, the sampler agent performing the correct behavior does not guarantee that a robust reward function has been uncovered.
In particular, when using reinforcement learning to train a randomly initialized relearner agent on the learned reward, the reward may fail to induce the correct behavior despite the sampler agent behaving well [15].
If we only require a policy that works passably well in the exact training environment, this may not be an issue because we can use the sampler agent and throw away the learned reward.
We argue, however, that such a method cannot be accurately described as learning a reward function. At most, it is a preference-based policy learning technique, using reward functions to give a helpful inductive bias during training.
Moreover, it is desirable for many applications to truly uncover a reward function.
For example, we might wish to train a new policy using a learned reward function with a more powerful R.L. algorithm or different agent architecture than was used during the initial reward learning process.
Past work has preformed preliminary investigations into the robustness of learned rewards in toy environments [29], in Atari [15] and for fine tuning language models [3, 33].
However, these investigations are typically only reported short sections of their respective papers.
Inspired by this work, our paper empirically examines the relearner performance for learned reward functions.
Since we have access to a ground truth reward in our synthetic experiments, we define poor relearner performance as achieving relatively low ground truth returns.
Our results show that relearing can produce very different policies than the sampler, frequently achieving low ground-truth returns.
Thus, we argue that current preference-based reward learning methods may produce reward functions that are not reliable as signals for policy relearning.
Our paper makes three key contributions:
• We demonstrate that state-of-the-art reward learning algorithms can produce reward models that fail to train new agents from scratch in tabular and continuous control settings; • We show that the severity can increase as the trajectory dataset concentrates on high reward regions; • Finally, as an example of how how these relearning failures can be sensitive to changes in reward model design, we demonstrate that reward ensembles can effect relearning failures.
Related Work
Preference-based reward learning Our primary focus is on methods that learn from preference comparisons between two trajectories [2, 37, 30, 8].
Preference comparison is one of the most scalable reward learning methods, successfully applied to fine-tune large transformer language models [25, 33, 22, 3] to enhance their performance at certain tasks.
Note that trajectory comparison methods contain more information about the reward than demonstrations, so they tend to produce better results when available [31].
However, note that these methods may still fare poorly when the human preference feedback does not match their model of human rationality [21].
Other reward learning approaches Many other methods have been developed to learn reward functions from human data [16].
One of the most popular is Inverse reinforcement learning (IRL) [23] methods that infer a reward function from demonstrations [1, 28, 41, 40, 42, 9, 10].
T-REX [6] is a hybrid approach, learning from a ranked set of demonstrations.
An alternative approach learns from “sketches” of cumulative reward over an episodeCabi et al.
Reward hacking Pan et al.
provides the first systematic empirical study of reward hacking : RL agents exploiting misspecified reward functions [26].
Notably, they find that increasing agent capabilities, such as by increasing the RL policy’s model size, can sometimes lead to worse performance on the ground truth reward, while performance on the misspecified proxy reward increases.
In contrast to our work, Pan et al.
only study reward hacking in hand-designed rewards designed to illustrate the phenomenon, whereas we investigate this phenomenon in learned rewards.
Reward hacking has also been studied from a theoretical perspective. Under the framework of general principle agent problems Zhuang and Hadfield-Menell examines the case where the agent’s utility function can only account for a limited subspace of the set of attributes that make the true utility [39].
The authors proceed to show that, within their model, an optimal state under this proxy utility can have arbitrarily low ground truth utility, assuming the attributes that make up the reward exhibit a condition analogous to decreasing marginal utility and increasing opportunity cost.
Skalse et al.
instead propose a formal definition of reward hacking [32]. In our paper, however, we focus on more concrete cases of relearning failures and practically attainable measures, such as relearner performance being close to sampler performance.
The most closely related work is by Ibarz et al., which evaluates their learned reward functions by freezing them and training a new policy, analogous to our relearner evaluations [15, Section 3.2].
However, this study was only a small, half-page section of their paper, and they did not examine factors that may increase or decrease the chances/severity of relearning failures.
Another important related work is by Reddy et al., who observes that rewards can fail to generalize due to a lack of informative trajectories in their training data [29].
They attempt to ameliorate this by querying humans on diverse hypothetical trajectories generated from a model.
However, their method requires a world model and primarily focuses on taking advantage of this model to improve reward quality.
In addition, they assume the user provides feedback through quantitative reward labels, whereas we focus on the more realistic and widely used preference comparison setting.
Finally, past work has found that language models trained on a preference-based reward model can learn to exploit their reward model [33, Section 4.3].
In a similar vein, Bai et al. found that the ability of their reward model to correctly predict human preferences over a pair of inputs degraded as those inputs where perceived as more rewarding by the model [3, Section 4.2]. However, none of these works have offered much analysis of what leads to reward hacking or in general relearning failures, beyond training against the learned reward for to long [33, Section 4.3] or a lack of data from off distribution [29].
Robustness of learned rewards from demonstrations There has also been work to improve the robustness of rewards learned from expert demonstrations i.e. inverse reinforcement learning (IRL).
Xu and Denil [38] propose addressing the reward generalization problem via positive-unlabeled learning [18], with human feedback (e.g. demonstrations) being “positive” data and rollouts from the agent being unlabeled data.
They demonstrate this approach improves robustness in a semi-supervised RL and imitation learning setting.
In addition, past IRL methods have learned a reward with no sampler removing the problem of relearning failures entirely.
For example Wang et al.
[35] borrows methods from random network distillation to directly estimate the expert distribution with only expert data.
In addition, multiple works have explored relearning and transfer in this domain.
Fu et al.
[10] propose an IRL method to learn state-only reward functions disentangled from transition dynamics via a state-only reward and preform some experiments on retraining new environments.
Ni et al.
[24] derive an analytic gradient estimator for an arbitrary f-divergence between expert and on policy distributions with respect to the reward functions parameters.
They preform relearning evaluations.
In these evaluations, their method appears to be able to recover the expert policy well.
In contrast to these IRL methods, our work focuses on the more scalable preference-based reward learning setting.
Background
Deep RL from Human Preferences We follow the framework of learning a preference model ˆ r ϕ from trajectory segment comparisons.
Our method is the closest to deep reinforcement learning from human preferences [8].
It consists of four phases iterated: trajectory collection, preference elicitation, reward inference and policy optimization.
During trajectory collection , the current policy, initially a random policy, samples rollouts from the environment collecting trajectory segments σ i = ( s 0 , a 0 , s 1 , a 1 , · · · , s n ) without reward labels and stores them in B. In phase two, the algorithm, elicits preferences y ∈ {≻ , ≺ , ≡} for randomly selected pairs of segments ( σ 1 , σ 2 ) ∈ B from a labeler — human or synthetic 1 .
The preferences are then stored in a preference dataset
D .
The algorithm assumes these preferences have been been sampled from the Bradly-Terry model [4],
[Equation]
a widely used approximate model for human data in the preference based reward learning literature [8, 15, 20].
In the third phase reward inference , the reward ˆ r ϕ is fit by using Adam [17] to minimize the negative log likelihood of ˆ r ϕ under D .
The fourth and final phase of each iteration consists of policy optimization .
In this stage, we can apply existing deep reinforcement learning algorithms to improve our policies expected return under the learned reward, and the process repeats.
Training and Evaluation Procedure
Reward Learning We train reward models with synthetic data that is sampled from the BradleyTerry model of Eq.
1 with r set to the ground truth reward.
In the tabular setting, we train the sampler
[Figure]
G r o un d T r u t h
R e t u r n
RL Budget 0.
5M1M2M4M8M 0.
[Figure] 1e [Figure]
G r o un d T r u t h
R e t u r n RL [Figure] [Figure]
[Figure] [Figure] en t P a i r A v e r age
R e t u r n
RL Budget1M8M
[Figure]
In plots (a-b), for each RL budget setting, we performed ten runs of reward learning, and for each of these we five policy using soft Q-Learning [13] and the learned reward networks simply take the current state as a one-hot vector for input. In the continuous control setting, we use soft actor-critic (SAC) [14] from
Stable-Baselines3 [27] and the learned reward networks receive the observation, action and next observation as input. See Appendix A for further details.
Reward Ensembles Christiano et al.
and Lee et al.
use reward ensembles to estimate the uncertainty of the learned reward [8, 20].
We explore how these ensembles may have an another benefit, reducing the variance of off-distribution transitions.
As in prior works, we train each ensemble member on bootstrapped datasets, normalize their outputs separately and use their mean as the reward.
Relearning We freeze the learned reward and train a new, randomly initialized, relearner policy to evaluate our reward functions.
We evaluate this policy under the ground truth reward.
This is similar to the method employed by Ibarz et al.
[15, Section 3.2] to study reward hacking.
In the continuous control settings this consist of training a new agent from the learned reward function using the same R.L. algorithm as the sampler, then evaluating it under the ground truth reward.
In the tabular setting, we simply solve for the soft-optimal policy ( α = 0 . 1 ) [13] under the learned reward function.
Experiments
First, we investigate the occurrence of relearning failures in the continuous control domain.
We use
HalfCheetah environment as our test bed since it has been used in past works on preference-based reward learning [8].
Here we find that increasing the number of training timesteps the sampler takes between sampling trajectories for labeling increases the severity of relearning failures.
Next, we focus on the effects of reward model design and observe that reward ensembles may reduce reward hacking in tabular environments by reducing the variance of off-distribution transitions.
To demonstrate this failure mode we use the stay inside environment which consists of two rooms separated by a wall with a small doorway.
The agent receives reward for staying in the inside room see Figure 2b.
5.1 Preference Trajectory Dataset Imbalance and Relearning Failure
The reward model is a function of the dataset D used to train it.
One of the simplest ways to change the preference dataset is to vary the number of timesteps T spent training the sampler between collecting trajectory fragments.
We call the total number of interactions the sampler has with the environment during reward learning the RL budget .
Note the RL budget does not affect the number of comparisons collected.
Figure 1 shows the learning curves of the sampler and relearner experiments in HalfCheetah .
We find that despite higher RL budget leading to higher sampler returns during reward learning, the relearners’ performance has the reverse trend; increasing sampler RL budget actually decreases relearner ground truth return.
[Figure]
R e l e a r n e r M i nu s S a m p l e r R e t u r n (a) Effect of reward ensembles on sampler and relener return (
[Figure] ) Ground truth reward (c) Example no ensemble (d) Example with ensemble 5 Number of Ensemble Members
M a x i m u m R e w a r d (e) Max reward
We can gain some insight into why this is happening by exploring preference datasets shown in
Figure 2c.
First let’s consider the preference dateset produced by one of the runs with the highestbudget (8M timesteps).
We find that the trajectory segments contained in this datset are concentrated in high ground truth reward regions.
On the other hand, when we consider the low-budget dataset (1M timesteps), the distribution of trajectory segments provides a better coverage across all the ground truth reward scales within the support.
We hypothesize that having an overwhelming proportion of high-reward trajectory segments in the preference dataset — and little preference data on trajectories in the transition from high to low reward — may cause the reward model to effectively over-fit to the high-reward region.
This overfitting leads to poor supervision over randomly initialized policies.
Overall, we believe this could explain the observed relearning failures.
It’s important to note that we did not see a significant increase in relearning failure when increasing the RL budget in the tabular setting.
See Appendix D.
5.2 Reward Ensembles
Our tabular experiments provide a concrete, interpretable example of how relearning failures can be effected by reward model implementation details.
In particular, we focus on reward ensembles and observe that they have drastic effects on relearners but leave the sampler’s performance unchanged.
In the stay inside environment, when using a reward ensemble of size five, all relearners preform at least as well as their respective samplers, as can be seen in Figure 2a.
However, if we use only a single reward, the relearners behaviour is inconsistent; some relearners do substantially better then their respective samplers, but almost as many do substantially worse, getting near zero return.
Thus, while adding an ensemble has a minimal effect on the sampler, it changes the behaviour of the relearners.
To understand why this happens we must consider the off-distribution behaviour of our reward models.
In the stay inside environment, the samplers typically stay in the inside half of the environment.
Thus there is often insufficient coverage of the outside half of the environment in our trajectory dataset.
Thus, the reward off-distribution is largely unconstrained by the data.
This means that small changes in the off-distribution behavior of our reward network can become critically important.
Reward models based on neural networks produce spurious high rewards off distribution, see Figure 2.
When these reward delusions are more rewarding than any of the in-distribution transitions, reward hacking can occur and cause relearning failures.
Reward ensembles tends to have lower variance off distribution than an individual reward network.
Thus, any reward delusions tend to have a lower reward (according to the reward model).
This can be directly seen in Figure 2 (c-e).
This effect reduces the chance that the optimal policy will be attracted to one of these spurious rewards during relearning, which is what we see in Figure 2a.
Limitations and Discussion
Our experiments have a few important limitations.
First, they are limited to simple ground truth reward functions and environments.
For example, in Half-Cheetah-v3 [5, 11], the reward function is essentially a linear in the observation, action and next observation.
While these relearning failures also appear in more complex tasks [15, Section 3.2], it is unclear if it is precisely the same phenomenon that causes them.
The design decisions that seem to improve retraining performance in small-scale experiments, in our case, reward ensembles and less sampler training, may not be the same as those that address the problem at a larger scale.
We leave such explorations to future work.
Overall, we have demonstrated that evaluations of relearning performance can differ substantially from the results of simply evaluating the sampler agent trained alongside the reward model.
We hope to see future works include relearning evaluation as they appear to hold fruitful insights into the quality of the learned reward functions.
Author
Contributions
Lev McKinney designed and implemented the tabular experiments and wrote the relevant parts of the method and experiments sections.
In addition, he wrote the introduction, discussion and related works sections of the paper/appendix. Yawen Duan designed and ran the initial experiments that displayed reward model relearning failure on continuous control environments, and wrote relevant sections of the paper. David Krueger provided ideas, guidance and general feedback on experiment design and analysis. Adam Gleave provided initial ideas of the project, provided high-level and detailed feedback on experiments and analysis.
This paper was completed as part of an internship at the Center for Human-Compatible Artificial Intelligence. Funding for this internships was provided by the Berkeley Existential Risk Initiative.
Appendices A Training Details and Hyperparameters A.1 Reinforcement learning algorithms
In the tabular setting we train the sampler policy using soft Q-Learning [13].
We use soft actor-critic (SAC) [14] implementations of Stable-Baselines3 [27] in the locomotion control tasks.
Both algorithms are off-policy and use a replay buffer, which ensures their high sample efficiency compared to on-policy RL algorithms.
Note that the learned reward function ˆ r ϕ changes during training, so we relabel the transitions in the replay buffer after each iteration, similar to PEBBLE [20].
The main difference between our algorithm and PEBBLE is that we omit the unsupervised pre-training stage used in PEBBLE.
We used the implementations from Imitation Learning Baseline
Implementations [36] to perform the experiments.
A.2 Continuous Control Experiments
In the tabular setting, all reward networks only take the current state as a one-hot vector.
They consist of a multi-layer perceptron with two hidden layers of size 256 and ReLU activations, similar to those used in PEBBLE [20].
Training details For reward learning experiments, we used the implementations of Preference
Comparisons Algorithm from Imitation Learning Baseline Implementations [36] with a full list of hyperparameters in Table 1.
For the RL component, we used soft actor-critic (SAC) [14] implementations from Stable-Baselines3 [27] in the locomotion control tasks with a list of hyperparameters in
Table 2.
For retraining evaluations, we use the same hyperparameters for SAC to train new agents against the frozen learned reward models.
Reward model
The reward model consists of a single multi-layer perceptrons with two hidden layers of size 256 and LeakyReLU activations with slope 0.01.
The input of the model consists of the state, action and next state vectors, and the input vector is normalized by running normalization.
The output the the reward model is normalized by by exponential moving average.
During relearning experiments, we directly use the raw reward output from the reward network while being normalzed by a VecNormalize layer in Stable-Baselines ( https://stable-baselines3.readthedocs.io/en/master/guide/vec_envs.html#vecenv ).
Reward normalization We compute a normalized version of the learned reward using an Exponential Moving Average to normalize the reward to mean zero and unit standard deviation.
This normalized reward was then used for policy optimization.
Note that normalizing the reward does not change the optimal policy, which is invariant to positive affine transformations.
However, it does simplify the optimization problem.
In particular, a normalized reward is a more stable objective for the critic to learn over time.
Additionally, RL hyperparameters can depend on the reward scale (for example, learning rate should be set inversely proportional to reward scale) – normalizing the learned reward therefore allows us to use a consistent set of hyperparameters.
[Table]
[Table]
Learning
[Table]
from
A.3 Tabular Experiments
Similarly to the continuous control experiments we use Imitation’s implementation of preference comparison [36].
However, we use a tabular soft-q learning algorithm with a replay buffer [13] with reward relabling [20] to solve the environments.
The reward network again uses a similar MLP architecture to the continuous control setting with a sightly smaller hidden size of 32.
Finally, we normalize the reward functions before ensembling them using a simple running norm over sampled transitions which is frozen during retraining.
Hyperparamaters can be found in Table 3.
Tabular Relearning When relearning we solve for the soft-optimal policy under the learned reward function with temperature 0.1 and discount factor 0.99.
B Environments
Locomotion Control Task We ran reward learning and relearning on a MuJoCo locomotion task [34] – HalfCheetah environment from the seals benchmark suite [11], a modification of
[Table]
frac.
of comparisons from inital random trajs
[Table]
select fragments for comparison
[Table]
HalfCheetah-v3 in the gym environment suite which adds the x-coordinate of the robot’s center of mass (COM) to the first dimension of the observation space.
The ground-truth reward function of the HalfCheetah environment is a linear combination of the x-velocity of the robot’s COM and a control cost dependent on the L 2 norm of the action vector.
Consequently, the reward function in seals HalfCheetah is a function of the observations, which is not strictly true in the original gym [5] environment, avoiding a potential confounder.
Tabular Environment We constructed the stay inside environment , which consists of a 20x closed grid of cells.
The top "outside” and bottom "inside” halves of the environment are separated by a wall with a narrow two cell gap in the middle.
The reward for each state is shown in Figure 2 (a), with reward values ranging from +10 to -1.
C Epic Distance as an Evaluation Metric
As an additional evaluation criterion, we consider using EPIC distance [12] to measure the distance between learned reward functions and the ground truth reward.
EPIC works by canonicalizing the rewards to be invariant to potential shaping, normalizing them to be invariant to scale, and then computing the L 2 norm of the difference of those functions over a coverage distribution of transitions.
Here we consider two coverage distributions: uniform and expert distribution.
The uniform distribution is uniform over feasible transitions.
The expert distribution is the distribution of a soft-optimal policy with a temperature of 10 to give slightly more coverage.
D Additional Tabular Experiments
To study the effects of training the sampler for a more time steps, we first consider a simple environment consisting of a 10x10 grid world.
The agent begins in the lower left-hand corner of the environment and gains a ground-truth reward of 10 for reaching the lower right-hand cell, as seen in
Figure 5.
The performance of the sampler and relearner initially increases with more training timesteps, with our relearners generalizing well and achieving slightly higher performance than their respective samplers.
However, it quickly plateaus even though we do not see significant reductions in relearner
[Figure]
Examples of the on policy distributions of the samplers in the stay inside environment, marginalized over the entire training run.
[Figure]
performance with an increased number of time steps.
The EPIC distances of our learned reward functions from the ground truth reward begin to increase after 400,000 timesteps Figure 4 (b).
Increasing the number of total training timesteps used for DRLHP does seem to degrade the quality of the reward function according to EPIC distance.
However, it does not appear to hurt relearning performance in the same way in this simple tabular environment.
This is a strikingly different effect than we see in HalfCheetah .
This may be because in a tabular setting the sampler either finds the optimal policy induced by the learned reward function every iteration, so the sampler and relearner have equal performance, or it insufficiently explores the environment, and reward learning completely fails.
This dichotomy leaves little room for the subtle degradation in relearner performance we see in Figure 1.