SAFER: Data-Efficient and Safe Reinforcement Learning Through Skill Acquisition

Dylan Z Slack, Yinlam Chow, Bo Dai, Nevan Wichers

TL;DR

Standard behavioral priors accelerate reinforcement learning by mapping simple latent actions to complex skills, but they often assign dangerously high likelihoods to unsafe actions when trained only on safe data. SAFER (SAFEty skill pRiors) introduces a contrastive learning framework that explicitly trains on both safe and unsafe offline data, inferring a latent safety context to safely bound the robot's exploration. In challenging vision-based robotic manipulation tasks, SAFER dramatically reduces safety violations while achieving up to triple the downstream task success rates of standard behavioral priors.

What Problem Does This Paper Address?

Reinforcement learning (RL) in safety-critical, high-dimensional environments (such as robotics operating from raw camera pixels) suffers from two major hurdles: extreme sample inefficiency and the difficulty of mathematically formulating continuous safety constraints.

To boost sample efficiency, recent approaches use behavioral priors (e.g., PARROT), which use deep generative models (like normalizing flows) trained on offline demonstrations to transform raw action spaces into abstract "skill" spaces. However, because these generative models are typically trained exclusively on successful/safe demonstrations, unsafe scenarios are Out-Of-Distribution (OOD). Counterintuitively, deep generative models frequently assign higher likelihood to OOD and unsafe actions. As a result, agents guided by standard behavioral priors can aggressively pursue catastrophic actions.

Methods

To resolve this issue, the authors introduce SAFER, which couples contrastive objective design with contextual inference:

  • Latent Safety Variable ($c$): Rather than conditioning priors solely on the current state $s_t$, SAFER introduces a latent variable $c \sim q_\rho(c | \Lambda)$, inferred from a sliding temporal window of past observations $\Lambda = [s_t, s_{t-1}, \dots, s_{t-w}]$. This history allows the agent to remember obstacles or constraints that might be temporarily occluded in a single camera frame.
  • Architecture: Visual observations are processed via a CNN and combined across time using a Transformer architecture to predict the diagonal Gaussian posterior $q_\rho(c | \Lambda)$. The behavioral prior $f_\varphi(z; s; c)$ itself is parameterized by an invertible conditional normalizing flow (Real NVP).
  • Contrastive Chance-Constrained Objective: The authors formulate prior learning as a chance-constrained optimization problem to ensure the probability of taking unsafe actions is bounded. They derive a tractable surrogate lower bound: $$\max_{\rho, \varphi, \lambda} \mathbb{E}_{c \sim q_\rho(c|\Lambda)} \left[ \log p_\varphi(a_{\text{safe}}|s, c) - \lambda \log p_\varphi(a_{\text{unsafe}}|s, c) - D_{\mathrm{KL}}(q_\rho(c|\Lambda) \parallel p(c)) \right]$$ This explicitly pushes down the likelihood of unsafe actions while boosting safe, useful ones.

  • Tunable Safety Assurances: Leveraging the flow model's exact invertibility, the authors calculate bounded hypercubes $(-\eta, \eta)$ in the latent action space $\mathcal{Z}$. This provides a verifiable empirical upper bound on the percentage of unsafe actions generated at any state $s$.

[Window of States Λ] ──> [CNN + Transformer] ──> [Safety Context c]
                                                        │
[Abstract Action z]  ──> [Real NVP Flow f_φ(z; s; c)] ──┴──> [Safe Action a]

Datasets

The authors designed a suite of safety-critical manipulation environments in PyBullet inspired by the classic tabletop game Operation:

  • Task Setup: A 5-DoF robotic arm must grasp and lift an object out of an enclosing container from $48 \times 48$ RGB images without touching the container walls (which triggers a binary collision penalty $\omega(s, a) = 1$).
  • Data Collection: An offline dataset of 1,000,000 steps across 40 container/object pairs was generated using an automated scripted policy with additive actuation noise, labeled for safety violations and trajectory success.
  • Evaluation: Evaluated across 6 held-out complex container-object configurations.

Key Insights and Ideas

  • Unsafe Data is Essential for Safety: Training purely on positive/safe demonstrations does not teach a generative model what not to do. Using unsafe data contrastively is necessary to suppress dangerous modes in the latent prior.
  • Pruning Unsafe Actions Boosts Task Success: Intuitively, penalizing unsafe actions might seem like a performance constraint. In practice, eliminating unsafe actions collapses the search space, focusing downstream RL exploration onto viable regions and accelerating task completion.
  • Context is Key: Ablating the latent safety variable causes success rates to collapse below 10%, showing that memory over recent interactions ($\Lambda$) is crucial for disambiguating safe vs. unsafe dynamics from image pixels.

Key Results

Downstream policies were trained using Soft Actor-Critic (SAC) for 50,000 steps using fixed priors:

Metric SAC (From Scratch) PARROT Contextual PARROT SAFER (Ours)
Task 2 Success Rate (%) $0.0 \pm 0.0$ $12.8 \pm 0.2$ $24.2 \pm 0.2$ $87.4 \pm 0.2$
Task 2 Safety Violations $876 \pm 117$ $307 \pm 291$ $1576 \pm 1208$ $51 \pm 61$
Task 3 Success Rate (%) $0.0 \pm 0.0$ $25.7 \pm 0.2$ $27.0 \pm 0.3$ $89.3 \pm 0.0$
Task 3 Safety Violations $1055 \pm 216$ $13 \pm 21$ $1039 \pm 777$ $10 \pm 14$
Task 6 Success Rate (%) $2.3 \pm 0.0$ $6.3 \pm 0.1$ $12.0 \pm 0.2$ $83.3 \pm 0.0$
Task 6 Safety Violations $756 \pm 293$ $932 \pm 844$ $2085 \pm 1951$ $7 \pm 9$
  • In Task 6, SAFER achieved 83.3% success with only 7 violations, compared to PARROT's 6.3% success and 932 violations.
  • Safety Bounds: Calibrating the latent action bound $(-\eta, \eta)$ reliably constrained real-world empirical violations to remain below target risk thresholds (e.g., targeting a 15% ceiling held empirical violations well below that bound across all tasks).

Limitations and Future Work

  • Requirement of Negative Data: SAFER relies on access to logged unsafe trajectories. While feasible in simulation or via controlled offline logs, generating unsafe data on real-world safety-critical hardware remains unacceptable without a simulator.
  • Per-Step Constraints vs. Long-Horizon Risk: SAFER formalizes safety as an immediate per-step constraint ($\mathbb{E}[\omega(s, a)] \le \epsilon$). It does not explicitly optimize for cumulative trajectory-level safety budgets or worst-case failure probabilities.
  • Scale of Evaluation: The evaluation is restricted to simulated PyBullet robotic manipulation; verifying performance on real robotic systems and high-speed domains (like autonomous driving) is left to future work.

Summary updated

BibTeX
@inproceedings{slack2022safer,
  author = {Dylan Z Slack and Yinlam Chow and Bo Dai and Nevan Wichers},
  title = {{SAFER: Data-Efficient and Safe Reinforcement Learning Through Skill Acquisition}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=xwAw8QZkpWZ},
}
Figure