Reinforcement learning (RL) agents often fail to generalize to new environments, especially when trained on static, offline datasets. To address this, researchers have introduced Generalized Similarity Functions (GSF), a self-supervised framework that groups states based on their expected future behavior rather than just immediate actions or rewards. By using contrastive learning on these behavioral similarities, GSF significantly improves zero-shot generalization on complex, pixel-based offline RL tasks.
The Challenge: Zero-Shot Generalization in Offline RL
In real-world scenarios, such as autonomous driving, agents must handle visually distinct environments (e.g., day versus night) that they did not explicitly encounter during training. While online RL agents can use Self-Supervised Learning (SSL) to build robust, generalizable representations by actively interacting with the environment, these methods struggle in the offline setting, where the agent learns from a fixed, static dataset.
Prior offline SSL methods often attempt to group observations by looking at future action sequences. However, this approach has a critical flaw: in complex environments with multiple valid ways to solve a task (high entropy), two states might be functionally identical but feature drastically different action sequences. For example, in a platformer game, an agent might jump early or late to cross a gap. Both actions are optimal, but the sequences differ. Relying on action similarity in these cases leads to poor state representations and failed generalization.
The Solution: Generalized Similarity Functions (GSF)
To overcome the limitations of action-matching, the authors propose GSF, a framework that unifies and improves how RL agents measure the similarity between different observations. The method consists of four key components:
1. Generalized Value Functions (GVFs): Instead of solely predicting future rewards, GSF predicts the accumulation of any instantaneous signal, referred to as a "cumulant." This cumulant could be the reward, future state visitations (successor representations), or action counts. Grouping by value or expected future state proves much more robust than grouping by action sequences.
2. Quantile Binning: A major challenge is that GVF values operate on different scales across different tasks or levels. To compare them robustly, the authors use order statistics. They calculate the empirical cumulative distribution of the GVFs and divide them into $K$ quantile bins.
3. Contrastive Learning: These quantile bins serve as pseudo-labels. The authors apply a multiclass InfoNCE loss—a contrastive learning technique—to force the neural network's encoder to map observations that fall into the same GVF quantile bin to nearby points in the latent space.
4. Integration: This self-supervised representation learning objective is optimized jointly with Conservative Q-Learning (CQL), a standard offline RL algorithm.
Datasets and Benchmarks
Because existing offline RL datasets (like D4RL) are not designed to test zero-shot generalization across visual perturbations, the authors introduced two new benchmarks:
- Offline Procgen: 5 million transitions collected from 200 procedurally generated levels across 16 distinct arcade games with discrete action spaces.
- Offline Distracting Control Suite: 1 million transitions from 3 visual variations (background perturbations) of 4 continuous control tasks.
Key Results and Insights
- Superior Offline Performance: After 1 million training steps on Offline Procgen, GSF outperformed standard behavioral cloning, state-of-the-art offline RL (CQL), and a wide array of representation learning baselines (including CURL, DeepMDP, VPN, CSSC, and PSE).
- The Importance of the Cumulant: The choice of cumulant matters and is environment-dependent. In Procgen, using rewards or successor features worked best. However, in the Distracting Control Suite, using action counts as the cumulant yielded the highest scores and the lowest optimality gap compared to standard CQL.
- A Unifying Framework: GSF is highly flexible. By simply changing the cumulant function, GSF can mathematically recover previous state-of-the-art self-supervised objectives.
- Online Transfer: While designed for offline RL, GSF is versatile. When combined with an online PPO agent on the standard Procgen benchmark, PPO+GSF matched or outperformed existing online generalization methods.
Limitations and Future Work
Like all offline RL methods, GSF is limited by compounding extrapolation errors in areas of the dataset with low state-action coverage. Furthermore, the number of quantile bins ($K$) controls a critical bias-variance trade-off: too few bins group unrelated observations together (high bias), while too many bins pair states by exact rankings, introducing high variance from limited offline data. Because the optimal choice of the cumulant and $K$ is highly environment-dependent, searching for the perfect hyperparameter pair can be computationally expensive. Future work will likely explore ways to automatically learn or adapt these parameters during training.
Summary updated