Low-Precision Reinforcement Learning: Running Soft Actor-Critic in Half Precision

Johan Björck, Xiangyu Chen, Christopher De Sa, Carla P. Gomes, Kilian Q. Weinberger

Abstract

Training Reinforcement Learning (RL) agents in low precision (fp16) typically leads to catastrophic failure due to numerical instability. This paper introduces six straightforward numerical modifications—including a novel "hAdam" optimizer and Kahan summation for updates—that enable the Soft Actor-Critic (SAC) algorithm to match full-precision performance while reducing memory footprint by ~40% and doubling training speed for large models.

Introduction

In supervised learning, training with 16-bit "half-precision" (fp16) is a standard way to speed up computation and save memory. However, the RL community has largely stuck to 32-bit (fp32) because RL agents are notoriously unstable. The gap lies in the dynamic range and precision requirements of RL. Unlike supervised learning, where labels are stationary, RL involves moving targets (the value function) and high-variance gradients. Standard "tricks" from supervised learning, such as loss scaling or mixed precision, often fail in RL because they don't address specific numerical bottlenecks in the policy and optimizer.

Methods

The authors propose six implementation-level modifications that are algebraically equivalent to the original SAC algorithm but are numerically robust in fp16:

  1. hAdam (Hypotenuse Adam): Standard Adam stores the squared gradient ($g^2$), which easily underflows or overflows in fp16. hAdam instead stores the square root of the second moment ($w = \sqrt{v}$) and updates it using the hypot(a, b) function.
  2. Softplus-fix: Rewrites log-probability calculations for tanh-transformed policies to avoid overflow during backpropagation.
  3. Normal-fix: Reorders normal distribution log-probability calculations to prevent variance underflow.
  4. Kahan-momentum: Employs Kahan summation for target network exponential moving average updates to prevent tiny updates from being rounded away.
  5. Compound Loss Scaling: Simultaneously scales Adam buffers and gradients to maintain values within the fp16 representable range.
  6. Kahan-gradients: Applies Kahan summation to weight updates for the critic network and the temperature parameter $\alpha$.

Experimental Results

Failure of Standard Baselines

A naive port to fp16 usually results in the agent "crashing" (producing NaNs or zeros). As shown in Figure 1, standard techniques like mixed precision or simple loss scaling are insufficient to stabilize training in the RL context, whereas the proposed modifications achieve high average returns.

Figure 1: Comparison of the proposed method against standard low-precision baselines. Naive fp16 crashes, while standard mixed precision and loss scaling fail to reach optimal performance.

Performance Parity and Efficiency

The methods were evaluated on the Planet-benchmark subset of the DeepMind Control Suite, covering tasks like Cheetah Run and Ball-in-cup. Across all tasks, the modified fp16 SAC matched the rewards of the fp32 baseline (Figure 2).

Figure 2: Performance parity across six tasks from the DeepMind Control Suite. The proposed fp16 implementation (green) consistently matches the fp32 baseline (blue).

Beyond performance parity, the implementation yielded significant efficiency gains:

  • Memory: Reduced consumption by approximately 1.8x to 1.9x.
  • Speed: For larger network architectures (e.g., width 1024), the fp16 implementation was over 2x faster than fp32 on NVIDIA V100 GPUs.

Conclusion

This work demonstrates that the primary barrier to low-precision RL is numerical, not algorithmic. By implementing robust primitives like hAdam and Kahan summation, practitioners can achieve the speed and memory benefits of fp16 without sacrificing agent performance. Future work may extend these principles to other algorithms like PPO or even lower-precision 8-bit formats.

Summary updated

BibTeX
@inproceedings{bjorck2021low,
  author = {Johan Björck and Xiangyu Chen and Christopher De Sa and Carla P. Gomes and Kilian Q. Weinberger},
  title = {{Low-Precision Reinforcement Learning: Running Soft Actor-Critic in Half Precision}},
  booktitle = {International Conference on Machine Learning},
  year = {2021},
  url = {https://openreview.net/forum?id=6dTF1npNRb},
}
Figure