Rewriting History with Inverse RL: Hindsight Inference for Policy Improvement

Ben Eysenbach, Xinyang Geng, Sergey Levine, Ruslan Salakhutdinov

TL;DR

This paper introduces Hindsight Inference for Policy Improvement (HIPI), a principled framework that uses Inverse Reinforcement Learning (IRL) to "relabel" past experiences. By asking "what task was this trajectory actually good for?", the authors generalize successful techniques like Hindsight Experience Replay (HER) to arbitrary reward functions, significantly boosting sample efficiency in multi-task learning.

The Challenge of Multi-Task RL

Reinforcement Learning (RL) is notoriously data-hungry. Multi-task RL—where an agent learns to solve many different tasks at once—offers a potential solution: data collected while trying to solve Task A might accidentally be very useful for Task B.

The standard way to exploit this is "relabeling." For example, if a robot tries to reach Goal A but ends up at Goal B, we can "rewrite history" and pretend it was trying to reach Goal B all along. This is the core of Hindsight Experience Replay (HER). However, HER only works for simple "goal-reaching" tasks (where the reward is simply "did I get to this state?"). It struggles with more complex tasks, like "run at a specific velocity" or "maximize a linear combination of different features."

The core challenge addressed by this paper is: How do we principledly relabel experience for any type of reward function?

Hindsight Inference for Policy Improvement (HIPI)

The authors’ key insight is that relabeling is fundamentally an Inverse RL problem. While RL asks "how do I act to maximize this reward?", Inverse RL asks "given these actions, what reward was the agent trying to maximize?"

The paper proposes the HIPI framework, which operates in three main steps:

The HIPI framework: Gather Experience, Infer Intentions with Inverse RL, and Learn from Relabelled Experience.
  1. Gather Experience: Collect trajectories using the current policy.
  2. Infer Intentions: Use Maximum Entropy (MaxEnt) Inverse RL to calculate a posterior distribution over tasks. Essentially, for a given trajectory, it calculates which tasks in the task-space would have found this trajectory "optimal."
  3. Learn: Update the policy using this relabeled data.

A crucial component of their method is the partition function ($Z$). Without it, relabeling would be biased toward "easy" tasks where any random movement looks good. By normalizing by the partition function, HIPI accounts for task difficulty, ensuring trajectories are assigned to tasks they are specifically good for.

The authors present two algorithmic variants:

  • HIPI-RL: An off-policy version that uses Soft Actor-Critic (SAC) as the backbone.
  • HIPI-BC: A behavioral cloning version that learns directly from relabeled past "successes."

Key Insights and Ideas

  • Relabeling is Inverse RL: This mathematical bridge proves that HER is just a special case of Inverse RL where the reward is a delta function at the final state.
  • The Duality of MaxEnt RL/IRL: The paper proves that MaxEnt RL and MaxEnt IRL optimize the same joint objective over tasks and trajectories. RL optimizes the policy, while IRL optimizes the task labels.
  • The Importance of "Normalizing for Easy": Simply picking the task with the highest reward fails because easy tasks always give higher rewards. The partition function is the "secret sauce" that makes relabeling work for complex, varying reward scales.
  • Stitching Experience: HIPI can identify when parts of a trajectory are useful for other tasks, effectively allowing the agent to learn from "crossing" paths.
HIPI successfully stitches trajectories in a gridworld and outperforms HER in success rate.

Experimental Results

The authors evaluated their approach on a diverse suite of simulated environments, including didactic gridworlds, goal-reaching tasks (like quadruped locomotion and robotic manipulation), general reward tasks with linear reward functions, and discrete task sets.

  • Outperforming HER: On standard goal-reaching tasks, HIPI-RL learned faster and reached higher asymptotic rewards than HER. In extremely sparse reward settings, HIPI was often the only method that could learn at all.
  • Generalization: Unlike prior methods, HIPI successfully accelerated learning in environments with linear reward functions and discrete task sets where HER is inapplicable.
  • Robustness to Scale: Through "partition function ablation," the authors showed that HIPI is robust to reward misspecification. Even if one task has a reward 10x larger than another, the IRL step correctly normalizes them, preventing the agent from ignoring the "smaller" tasks.
  • Behavioral Cloning Boost: HIPI-BC showed that even without a complex RL objective, simply relabeling and imitating one's own past "intentional" behavior leads to significantly better performance than task-agnostic imitation.

Limitations and Future Work

  • Manual Task Families: The user must still manually specify the family of reward functions (e.g., "all linear combinations of these 4 features"). If the true "intent" isn't in that family, the model defaults to random relabeling.
  • Computational Complexity: While the authors used a non-parametric approximation to keep things efficient, performing IRL in the inner loop of RL can be computationally demanding.
  • Future Directions: The authors suggest that this framework could be a powerful tool for meta-learning, where the agent must quickly infer a new task from a few frames of experience. They also hope this spurs more research into efficient, parametric Inverse RL algorithms that can be plugged into the HIPI framework.

Summary updated

BibTeX
@inproceedings{eysenbach2020rewriting,
  author = {Ben Eysenbach and Xinyang Geng and Sergey Levine and Ruslan Salakhutdinov},
  title = {{Rewriting History with Inverse RL: Hindsight Inference for Policy Improvement}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2020},
}
Figure