Improved Context-Based Offline Meta-RL with Attention and Contrastive Learning

Lanqing Li, Yuanhao Huang, Dijun Luo

TL;DR

This paper introduces FOCAL++, an enhanced approach to offline meta-reinforcement learning (OMRL) that significantly improves task representation learning. By incorporating intra-task attention and inter-task contrastive learning, FOCAL++ achieves more robust performance, especially in challenging scenarios with sparse rewards and distribution shifts, outperforming existing state-of-the-art methods.

What Problem Does This Paper Address?

Deep reinforcement learning (RL) has shown remarkable success, but its reliance on extensive online interaction and exploration limits its applicability in safety-critical domains like healthcare or autonomous driving. Offline RL addresses this by learning from pre-collected datasets, but it struggles with sample efficiency and generalization. Meta-RL aims to accelerate learning by leveraging experience across multiple tasks. Combining these, offline meta-RL (OMRL) seeks to enable efficient and robust learning from fixed datasets across a distribution of tasks. A key challenge in OMRL is learning effective "task representations" – essentially, inferring which specific task an agent is currently facing from the data. Existing methods, like FOCAL, use context-based encoders to infer task identity, but these representations can be brittle, especially when rewards are sparse or the data distribution shifts, leading to poor generalization. This paper tackles the problem of learning robust task representations in OMRL that are less susceptible to these challenges.

Methods

FOCAL++ builds upon the FOCAL algorithm by introducing two main innovations to improve task representation learning:

  • Intra-Task Attention Mechanisms: The authors incorporate two types of attention within the context encoder:
  • Batch-Wise Gated Attention: This mechanism adaptively re-weights transitions within a batch, giving more importance to informative samples (e.g., those with non-zero rewards) when inferring task identity.
  • Sequence-Wise Self-Attention: This module processes the sequence of states, actions, and rewards within a transition, allowing the model to better capture correlations and dependencies relevant to the task's reward and transition functions.
  • Inter-Task Contrastive Learning: To further enhance task representations, FOCAL++ employs a matrix-form reformulation of Momentum Contrast (MoCo). This objective encourages representations of transitions from the same task to be similar, while pushing apart representations from different tasks. This is implemented using a meta-batch of tasks, where a "query" encoder learns to distinguish between positive (same task) and negative (different task) examples.

The authors also provide theoretical analyses to demonstrate that their proposed contrastive loss is a better surrogate for supervised learning than traditional unsupervised contrastive losses and that the attention mechanism can reduce the variance of task embeddings, particularly in sparse reward settings.

Datasets

The experiments were conducted on several continuous control meta-environments, including:

  • Sparse-Point-Robot: A 2D navigation task with sparse rewards, where tasks differ only in reward functions.
  • Point-Robot-Wind: A variant of Sparse-Point-Robot where tasks differ in transition functions due to a sampled wind vector.
  • Sparse-Cheetah-Vel, Sparse-Ant-Fwd-Back, Sparse-Cheetah-Fwd-Back: Sparse-reward variants of popular meta-RL benchmarks.
  • Walker-2D-Params: An environment where tasks differ in transition functions due to randomized system dynamics parameters.

Additionally, the authors introduced a relabeled Sparse-Point-Robot dataset. This dataset was specifically constructed to prevent information leakage from state-action distributions to task identity, forcing the context encoder to rely solely on reward functions for task inference. This was achieved by merging state-action supports across tasks and then recomputing and sparsifying rewards according to task-specific functions.

Key Insights and Ideas

  • Attention is Crucial for Sparse Rewards: The paper strongly suggests that attention mechanisms are particularly effective in sparse reward settings. By allowing the model to focus on informative transitions, attention helps overcome the challenge of inferring task identity when most data provides little signal.
  • Contrastive Learning Enhances Task Discrimination: The inter-task contrastive learning objective proves effective in learning distinct representations for different tasks, leading to better generalization.
  • Theoretical Guarantees for Robustness: The theoretical analysis provides a formal grounding for why the proposed methods improve robustness, particularly by showing how attention can reduce embedding variance in sparse settings.
  • Decomposing Task Inference from Control: The work builds on the idea that robust task representation learning can be decoupled from the control policy, allowing for more stable and effective meta-learning.

Key Results

  • Asymptotic Performance: FOCAL++ consistently outperformed existing OMRL algorithms, including FOCAL, across various meta-environments, achieving higher average testing returns. For instance, in the Sparse-Ant-Dir environment, FOCAL++ achieved a return of 719.77 (std 57.58) compared to FOCAL's 429.92 (std 41.52).
  • Robustness to Distribution Shift: FOCAL++ demonstrated significantly lower performance drops when tested on datasets with varying qualities (expert, medium, random, mixed) compared to FOCAL. This was particularly evident on the Sparse-Point-Robot dataset, where FOCAL failed on a mixed dataset, while FOCAL++ variants were able to learn.
  • Reduced Variance in Task Embeddings: Table 2 shows that FOCAL++ variants consistently achieved lower variance in context embeddings compared to FOCAL across most environments. This aligns with the theoretical findings that attention can reduce embedding variance in sparse reward scenarios.
  • Effective Attention Weighting: On the relabeled Sparse-Point-Robot dataset, experiments showed that the batch-wise attention mechanism effectively assigned higher weights to non-zero reward transitions and lower weights to sparse (zero-reward) transitions, confirming its ability to attend to informative data for task inference.

Limitations and Future Work

  • Computational Cost: While FOCAL++ shows improved performance, the addition of attention mechanisms and contrastive learning likely increases computational requirements. The paper mentions that larger meta-batch sizes lead to faster convergence but require greater computational power.
  • Hyperparameter Sensitivity: As with many deep learning models, the performance of FOCAL++ might be sensitive to hyperparameter choices, although the paper provides detailed hyperparameters used in their experiments.
  • Future Work: The paper implicitly suggests future work by highlighting the effectiveness of their combined approach. Further exploration into different attention architectures, contrastive learning strategies, and their application to even more complex or challenging OMRL scenarios could be promising directions. The authors also mention that learning meta-policies in the presence of sparse rewards is an active area of research, implying potential for integration with other techniques.

Summary updated

Abstract

Meta-learning for offline reinforcement learning (OMRL) is an understudied problem with tremendous potential impact by enabling RL algorithms in many real-world applications. A popular solution to the problem is to infer task identity as augmented state using a context-based encoder, for which efficient learning of robust task representations remains an open challenge. In this work, we provably improve upon one of the SOTA OMRL algorithms, FOCAL, by incorporating intra-task attention mechanism and inter-task contrastive learning objectives, to robustify task representation learning against sparse reward and distribution shift. Theoretical analysis and experiments are presented to demonstrate the superior performance and robustness of our end-to-end and model-free framework compared to prior algorithms across multiple meta-RL benchmarks.
BibTeX
@inproceedings{li2022improved,
  author = {Lanqing Li and Yuanhao Huang and Dijun Luo},
  title = {{Improved Context-Based Offline Meta-RL with Attention and Contrastive Learning}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=89W18gW0-6o},
}
Figure