Introduction
Deep Reinforcement Learning (RL) agents often exhibit significant brittleness when faced with distribution shifts. An agent trained to navigate a vehicle on a green track may fail catastrophically if the background color changes, as the underlying visual encoder produces latent representations that the downstream controller does not recognize. Traditionally, addressing such shifts requires extensive retraining or fine-tuning. This paper introduces Semantic Alignment for Policy Stitching (SAPS), a modular approach that enables the "stitching" of a visual encoder from one environment with a controller from another in a zero-shot manner.
Problem Formulation
In standard Deep RL, policies are typically represented as a composition of an encoder $\phi$ and a controller $\psi$, such that $\pi(o) = \psi(\phi(o))$. These components are usually trained end-to-end, leading to a tight coupling. When an agent encounters a new environment variation (e.g., a change in background color), the encoder $\phi$ generates a latent space that is semantically consistent but geometrically shifted relative to what the controller $\psi$ expects. SAPS aims to bridge this gap without further training by finding a transformation between latent spaces.
Semantic Alignment for Policy Stitching (SAPS)
The core of the SAPS method is the use of "anchor" observations to align disparate latent spaces. The process involves four primary steps:
- Anchor Collection: Identifying a small set of semantically matched observation pairs $(o_A, o_B)$ from two different environments (e.g., the same car position on a green track vs. a yellow track).
- Latent Mapping: Passing these anchors through their respective pre-trained encoders to generate two sets of latent vectors.
- Affine Transformation: Utilizing Singular Value Decomposition (SVD) to compute an optimal linear transformation (rotation and translation) that maps the latent space of the source encoder onto that of the target controller.
- Zero-Shot Stitching: At inference, new observations are processed by the source encoder, transformed via the calculated mapping, and then fed into the target controller.
Experimental Evaluation
The authors evaluated SAPS on two benchmarks: CarRacing and LunarLander. In CarRacing, variations included changes in background color (green, red, blue, yellow) and task constraints like speed and control mapping. LunarLander experiments involved background shifts and gravity modifications. SAPS was compared against "naive" stitching (no alignment) and Relative Representations (R3L), which requires specialized training to enforce relative distances in latent space.
Results and Discussion
In the CarRacing domain, SAPS demonstrated performance comparable to agents trained end-to-end on specific variations. For instance, on a standard track, SAPS achieved a score of 822 ± 62, significantly outperforming naive stitching, which scored only 175 ± 304.
Key insights from the results include:
- Structural Similarity: Independently trained encoders often learn structurally similar representations, suggesting that latent spaces can be aligned with simple affine transformations.
- Efficiency: Only a small number of anchor points are required to estimate the transformation effectively.
- Flexibility: Unlike R3L, SAPS does not require modifying the training objective, allowing for the reuse of existing, "off-the-shelf" models.
However, the method faces challenges in high-precision tasks like LunarLander, where minor latent misalignments can lead to failure. Additionally, the reliance on semantically matched anchors may be difficult to satisfy in highly stochastic environments.
Conclusion
SAPS provides a lightweight, mathematically grounded framework for zero-shot policy stitching. By treating RL agents as modular components and aligning their latent spaces through semantic anchors, the method offers a promising path toward more reusable and robust RL systems. Future work will focus on automating anchor discovery and extending the method to complex robotic control tasks.
Summary updated