Off-policy and SAC: how to learn from old experience
In lesson 5.2, PPO trained a policy on its own experience and kept it from being ruined by too large a step. The price was data: after every update, PPO throws away the rollout it collected and collects a new one, and even simple tasks need millions of steps. In simulation, where thousands of robots work in parallel, that's tolerable. The SAC authors' four-legged Minitaur made 160,000 steps in two hours of work, and at that pace a million steps would take more than 12 hours. Methods that store every transition and learn from it again and again appeared before PPO: in 2013, this is how DQN learned to play Atari from pixels. DDPG and TD3 carried the idea over to continuous actions, and in 2018 SAC added a bonus for randomness to the reward and taught Minitaur to walk right in the real world. We'll look at why old records are still good for training, why you need two value estimates and what the temperature α does, and then compare PPO and SAC on Ada's arm.
Why PPO needs millions of steps
In lesson 5.2, PPO collected a rollout batch with the current policy, updated the policy on it for several epochs and then collected the next one. It uses each rollout once. The reason lies in the policy gradient itself: it says how to change the probabilities of the actions that this policy chose, and it holds only as long as this policy is the one choosing them. The probability ratio compares the new policy with the one that collected the rollout, and the clipping zeroes out the gradient as soon as the new policy has moved far away. After that, the rollout teaches nothing more. A method that learns only from the experience of its current policy is called on-policy. The SAC authors say it plainly: TRPO, PPO and A3C (an asynchronous actor-critic that collects experience with many parallel processes at once) need newly collected data for every gradient step.
That's why so many steps are needed. In the PPO paper, each MuJoCo task was trained for a million steps, and humanoid running in Roboschool, OpenAI's open suite of simulated tasks, for up to 50 and 100 million. In 2021, Rudin et al. trained ANYmal to walk on 4,096 robots at once: 1,500 updates of 98,304 steps each added up to about 147 million simulation steps, and it took 20 minutes on a single GPU. In simulation, a step is almost free. On a real robot, every step costs time and wear: the four-legged Minitaur, which we'll get to at the end of the lesson, made 160,000 steps in two hours. At that pace, a million steps would take more than 12 hours of nonstop work, and 147 million, about two and a half months.
What's needed is a method that doesn't throw experience away. A step of experience is recorded as a transition : the state, the action, the reward and the next state, as in lesson 5.1. Transitions are put into a replay buffer, a store from which a random batch is drawn at every training step. A method that can learn from transitions collected by another policy, including its own past versions, is called off-policy.
But why is an old transition any good at all? Its action was chosen by an earlier policy, and the current one might have acted differently in its place.
The Q-function learns from any transitions: DQN and the replay buffer
For the policy gradient, it matters who chose the action. For the action value from lesson 5.1, it doesn't. It answers the question “how much will the agent collect if it takes in state and acts well from then on,” and the Bellman equation for it holds for any pair :
Here is the reward for the step, is the next state, is the discount factor from lesson 5.1, and the maximum is taken over all actions in state . The right-hand side contains no probability with which the action was chosen. Any recorded transition gives a target value , toward which the estimate is pulled, no matter who collected the transition. This is Q-learning (Sec. 6.5 in Sutton and Barto's textbook): the agent evaluates the greedy policy “always take the action with the largest ” but acts differently, for example, choosing a random action on some of the steps in order to explore. The first policy is called the target policy, and the second, the behavior policy; if they differ, learning is off-policy (same book, Sec. 5.5).
DQN (Deep Q-Network; Mnih et al., DeepMind, 2013) is Q-learning with a convolutional network that outputs the value of every joystick action from the latest frames of the game. The network takes the 210 × 160 screen pixels at 60 Hz as input, with no features designed for the game. With one architecture and one set of hyperparameters, DQN beat all previous approaches in six of the seven Atari games, and in Breakout, Enduro and Pong it beat an experienced human player. It was trained on 10 million frames, and the buffer held the last million.
The authors give three reasons for the buffer. Each step of experience can take part in many updates, which saves data. Consecutive frames are strongly correlated, and a random batch breaks this correlation and reduces the variance of the updates. And when learning on-policy, the current weights decide which data come next: if the policy turns left, the data are full of left turns. The buffer averages the behavior over many past versions of the policy. Hence their conclusion: with a buffer, learning has to be off-policy, because the current weights differ from the ones that collected the data, and that is why they chose Q-learning.
One subtlety remains: the target value is computed by the same network that is being trained, so after every step it shifts along with the estimate. DQN keeps the weights it uses to compute fixed while it learns from them; later work keeps a separate target network for this, a copy that is updated less often or slowly catches up with the trained one. Let's see how this works on Ada's arm.
The buffer step by step: which transitions get into training
Ada is a home humanoid on a wheeled base; the course labs are built around her. More about her in lesson 0.1.
Ada's arm is the same as in lesson 0.3: it has a shoulder, an elbow and links of 0.5 and 0.4 m. The goal of the task is a point in front of Ada to which she has to bring the gripper; every episode, it appears in a new place. An episode lasts 25 steps. At each step, Ada chooses one of 9 actions: move the gripper 5 cm up, down, toward herself, away from herself or diagonally, or leave it in place; the arm controller converts the shift into joint rotations, as in lesson 0.3. At each step, Ada gets a reward equal to minus the distance from the gripper to the goal in meters, multiplied by 4, plus 1 more while the gripper is closer than 4 cm. An attempt succeeds if, at the end of the episode, the gripper is closer than 4 cm to the goal.
The learner is DQN: a small network takes the joint angles and the vector from the gripper to the goal and outputs the values of all 9 actions. At first, Ada chooses actions at random, and by step 1,000 the share of random ones drops to 10%. For the first 100 steps, she only fills the buffer; after that, after every step, the network learns from a batch of 32 random transitions. The first scene shows one transition, and the second, the whole buffer.
The “Transition” scene shows the arm from the side: Ada stands on the left, the blue arm is the pose before the step, the pale one is the pose after it, and the orange arrow shows where the gripper moved. The green ring is the goal of this episode, the dashed circle around it is the 4 cm zone, and the gray dashed rectangle marks where goals appear. The “Buffer” scene is a map of all transitions: each cell is one transition, the columns are the episodes in order, and the rows are the 25 steps of an episode. The darker the blue, the more often the transition got into batches. Gray cells are transitions that have already been pushed out of the buffer, orange dots are the batch of the last step, and the black frame marks the transition shown in the “Transition” scene. Click a cell to select a transition.
Legend: marks on the scene
The chart: the horizontal axis shows interaction steps, and the vertical axis shows the share of the 40 test goals that Ada reaches without random actions. The test runs every 100 steps on goals that were not in training.
Under the hood: the DQN target value, the target network and the spread across seeds
Training. A batch of 32 transitions is drawn from the buffer uniformly. For each transition, the target value is computed with the target network , and the estimate of the trained network is moved toward it by reducing the loss function :
Here are the network's weights, is their copy, which is updated once every 100 steps, and . Before the step, the difference is clipped to ±1 so that rare large errors don't destabilize the network. The network has two layers of 24 neurons and is trained by Adam with a step size of 0.003. DQN on Atari also used batches of 32, but its buffer held the last million frames, and training lasted 10 million frames.
Why the target value changes. The first transition of the first episode first got into a batch soon after step 100, when the network knew almost nothing: was near zero, and the target value was almost equal to the reward alone. By step 1,000, the target network knows that from a position where the arm is still far from the goal, many penalized steps lie ahead, and the target value of the same transition has gone down. The record in the buffer hasn't changed; what has changed is what the network can extract from it.
Spread. The numbers in the missions are computed for one random seed (3). Across six seeds, with the buffer, 90% success on the test is reached by step 800–1,200, the average success over the last five tests is 84–96%, and the worst of these tests gives 63–93%. Without the buffer, on the last 32 transitions in a row, the average success is 29–74%, and on the worst test, 0 to 38%. By step 1,000, the transitions of the first episode had been in batches 70–74 times on average.
The buffer does two things at once: a transition made once teaches dozens of times, and batches from different episodes don't drag the network after the latest situation. But DQN picks the best of 9 actions by trying each of them. The motors of a real arm receive a number, not one of nine commands. How do you take the maximum over an infinite number of actions?
Continuous actions: DDPG and TD3
DQN chooses an action by enumeration: it computes for each of the 9 options and takes the largest. For an arm with motors, an action is a set of numbers, one per joint, and there are infinitely many options. You can cut each motor's range into “back, stop, forward,” but the DDPG authors give an example: for an arm with 7 degrees of freedom, like a human one, that's already actions, and precise control needs finer divisions. Searching for the maximum at every step and every update is too expensive.
DDPG (Deep Deterministic Policy Gradient; Lillicrap et al., DeepMind, 2015) adds a second network for this. The actor outputs an action directly from the state. The critic learns as in DQN, except that the target value uses the actor's action instead of the maximum: . And the actor learns from the critic: the critic is differentiable with respect to the action, and the gradient shows which way to shift the action to make the value grow. Such a pair is called an actor-critic. Both networks learn from batches drawn from a buffer of a million transitions, and the target value is computed by target copies of the actor and the critic, which slowly catch up with the trained ones: with . This way, the authors solved more than 20 tasks in a physics simulator, from swinging up a pole on a cart to walking. Almost all of the tasks were solved within 2.5 million steps, “a factor of 20 fewer steps than DQN requires for good Atari solutions.”
This scheme has a weak spot, which Fujimoto et al. described in detail in their TD3 paper (2018). The target value takes a maximum, explicit in DQN or hidden in the DDPG actor, over an estimate that contains noise. The maximum of noisy numbers is on average larger than the maximum of exact ones, so the estimate is systematically inflated: this is overestimation bias (Sec. 6.7 in Sutton and Barto). Worse, the actor itself looks for the actions with the largest and finds the critic's errors first, and an inflated target value passes into the next estimates through the Bellman equation.
TD3 (Twin Delayed DDPG) adds three tricks to DDPG. First, TD3 trains two independent Q-functions, and the smaller of the two goes into the target value: . The smaller one may underestimate, but the authors consider this the lesser evil: the policy simply won't choose an underestimated action, and the error won't spread further. Second, the actor and the target copies are updated less often than the critics, once every two steps. Third, a small clipped noise is added to the action in the target value, so that similar actions get similar values and the actor doesn't latch onto a narrow peak of error. In the paper's table, after a million steps, TD3 scores 9,637 on HalfCheetah, DDPG 3,306 and PPO 1,795.
Both DDPG and TD3 learn a deterministic policy and explore by adding noise to its action. How much noise and of what kind is set by hand, and the SAC authors call such methods “brittle to hyperparameter settings.” Can randomness become part of what the policy learns?
Maximum entropy: reward plus a bonus for randomness
SAC (Soft Actor-Critic; Haarnoja et al., UC Berkeley, 2018) learns not a single action per state but a distribution of actions, and it adds the distribution's entropy, a measure of randomness, to the reward: the more widely the policy spreads its actions, the larger the entropy. SAC looks for the policy with the largest sum of rewards and entropies:
Here is the probability (density) of action in state , is the reward at step , is the entropy of the action distribution, and is the temperature: how much randomness weighs next to the reward. As , what remains is the ordinary RL problem of collecting as much reward as possible. The authors put it this way: “to succeed at the task while acting as randomly as possible.” Such a policy explores more widely but gives up on clearly unpromising directions. This approach is called maximum entropy RL.
The SAC authors name one more property of this objective: if several actions are equally good, a maximum entropy policy splits the probability between them evenly. That's how a policy behaves when its distribution can take any shape. The SAC policy is simpler: in each state, it is a single Gaussian, a mean action with a spread around it. A Gaussian's density is highest at the mean and decreases in all directions from it, so it has only one peak. When there are several correct actions in the same situation, that's the action multimodality from lesson 1.3, and each correct action is a separate mode of the action distribution. A single Gaussian can stick to one mode or widen to cover both, but then part of the probability goes to the actions between and around them. Policies with several peaks, such as the Gaussian mixture from lesson 1.3, can split the probability evenly between the modes. Lab 2, with its two identical shelves, will show what this looks like for SAC.
Everything else SAC takes from its predecessors: the replay buffer and off-policy learning, two Q-functions with the smaller one in the target value, as in TD3, and slow target copies. The target value for the Q-functions includes the action that the current policy would choose in and the bonus for its randomness: . The policy shifts its mean action and its spread toward where the smaller of the two values is higher and is lower. The diagram below goes through one update step by step.
In the first version, the temperature was set by hand, and the result depended on it heavily. In the authors' experiments, with too small a reward scale, that is, with too large an , the policy becomes almost uniformly random and makes no use of the reward. With too small an , it learns quickly at first but then becomes nearly deterministic and gets stuck in poor solutions: it has nothing left to explore with. In the 2018 SAC paper “Algorithms and Applications,” the temperature is tuned automatically: the average entropy of the policy is held near a set level, the target entropy, which by default is : minus the dimension of the action, that is, minus the number of components it has. The action of Ada's arm consists of two numbers, so the target entropy is .
In lesson 5.2, PPO was chosen for its stability, and SAC promises to save steps. Let's check how large the savings are on the same task with the same networks.
PPO and SAC on the same arm: success by interaction steps
The task is the same as in the buffer interactive: bring the gripper to a goal that appears in a new place every episode, within 25 steps. Only now the action is continuous: it's a shift of the gripper of up to 5 cm horizontally and vertically, any value within these limits. The reward and the test are the same: 40 goals that were not in training, and an attempt succeeds if the gripper ends up closer than 4 cm.
Both arms learn from scratch, and both have the same networks: two layers of 24 neurons for the policy and for the value estimates. PPO works as in lesson 5.2: it collects a rollout of 5 episodes, updates on it for 20 epochs with clipping at 1 ± 0.2 and computes advantages with GAE. The rollout size and the number of epochs are chosen so that PPO learns this task as fast as possible. After 200 random steps, SAC makes one update per step, on a batch of 32 transitions, and tunes its temperature itself. The curves are plotted against interaction steps, the thing that costs time on a real robot, not against compute time.
A side view. The test goal is the same for both arms: it's the green ring, and the dashed circle around it is the 4 cm zone. The colored polyline is the gripper's path over 25 steps, and the dots on it are the gripper's positions after each step; the arm is shown at the end of the attempt. The gray dashed rectangle marks where goals appear. Below each scene is the policy's success on all 40 test goals.
Legend: marks on the scene
The chart: the horizontal axis shows the steps of interaction with the world, and the vertical axis shows the share of the 40 test goals that the arm reaches with its mean action. The orange line is SAC, the purple one is PPO, and the vertical dashed line marks the moment shown in the scenes.
Under the hood: the SAC and PPO updates, the choice of settings and the spread across seeds
SAC. The policy outputs a mean and a spread , and the action is obtained as , : the keeps it within ±1. A batch of 32 transitions is drawn from the buffer uniformly. The two Q-functions learn toward a shared target value, and the policy learns through the action it chose itself (this way, the gradient passes through and ):
Here are the weights of the Q-functions, are their target copies ( after every update), are the policy's weights, and . The Adam step size is 0.005, and the temperature tunes itself with a target entropy of −2; we give the formula in Lab 2.
PPO. A PPO rollout consists of 125 steps (5 episodes); it is used for 20 epochs in batches of 50, with a step size of 0.003, clipping at 0.2 and GAE with . On eight seeds, we compared rollouts of 125, 250 and 500 steps and 10, 20 and 60 epochs, and kept the variant that reaches 90% fastest on average; with a rollout of 250 and 20 epochs, it takes 1,375–2,375 steps. With a rollout of 500 and 10 epochs, closer to the settings of the PPO paper, reaching 90% takes 2,625–4,125 steps. With 60 epochs on the same rollout, PPO doesn't get faster: on four of the eight seeds, it didn't reach 90% within 3,000 steps. The policy moves away from the one that collected the rollout, the clipping zeroes out the gradient, and the extra passes add nothing.
Spread. The numbers in the missions are computed for seed 1. Across eight seeds, SAC reaches 90% by step 375–500 and by step 750 reaches all 40 goals; by step 750, PPO scores 0–45% and reaches 90% by step 1,125–1,875, 2.25–3.75 times later. Over 750 steps, each transition in the SAC buffer was in batches 23.5 times on average. To reach 90%, SAC does 0.65 to 1.34 times as many multiplications as PPO, and per interaction step, 2.4–3.0 times more.
In steps, SAC is faster: 2–4 times in our task, and the gap is even larger in the big tasks from the papers. In compute, there is no gain: SAC turns every step into an update of two Q-functions and the policy, and to reach 90% success, both methods do roughly the same number of multiplications. So the choice depends on what is more expensive. In simulation, where thousands of robots run in parallel, compute time is expensive, and PPO is usually chosen there. On a real robot, every step is expensive.
In the lab, SAC tuned its temperature itself: it started at 0.1 and by step 750 lowered it to about 0.04. What happens if you set it by hand?
The temperature α: one strategy, two or none
To see what the temperature does, you need a task with a choice. In front of Ada are two shelves, each with an identical cup. Shelf 1 is farther away, slightly below the shoulder, and shelf 2 is closer to the body, slightly above the shoulder. From the gripper's starting pose, both cups are about 38 cm away. The reward per step grows as the gripper approaches either cup and equals 1 at the cup itself, while far away it's almost 0. Which shelf to choose doesn't matter: the reward is the same.
SAC trains for 2,000 steps with a given temperature. Then Ada makes 40 attempts with her trained policy, with randomness, as during training. An attempt counts for a shelf if, at the end, the gripper is closer than 6 cm to its cup.
A side view: Ada is on the left, the two shelves with cups are in front of her, and around each cup is a dashed 6 cm circle. The dots mark where the 40 attempts ended: blue at shelf 1, purple at shelf 2, gray away from both. The thin lines are the gripper's paths in the first 8 attempts. The orange arm shows the pose at the end of the first attempt.
Legend: marks on the scene
Under the hood: the reward at the shelves, the automatic temperature and the spread across seeds
Reward. Let be the gripper's position and the positions of the cups. The reward per step is with cm: at a cup it equals 1, and 16 cm away from it, about 0.14. The observation includes the joint angles and the gripper's position, and everything else is as in Lab 1.
The temperature tunes itself. In the second version of SAC (2018), α is tuned as a Lagrange multiplier: the average entropy of the policy must be no lower than the target entropy , and α is changed by a gradient step on
If the policy has become more random than the target entropy requires, , the step decreases α; if it's more deterministic, the step increases α. We train with a step size of 0.003; in the “automatic” mode, α starts at 1.
Spread. The numbers in the missions are computed for seed 3. Across six seeds, with α from 0.003 to 0.03, in 16 of the 18 runs at least 98% of the attempts went to one shelf, in one more it was 88%, and in one run with α = 0.01, three attempts out of four ended away from the shelves. With α = 1, no run had more than 3% of its attempts reaching the shelves. With α = 0.2, Ada went to both shelves in three runs out of six, and in the rest, to one shelf or almost nowhere. With the automatic temperature, at least 98% of the attempts went to one shelf in all six runs, and α drops to 0.011–0.026 by the end.
The temperature works like a knob between two extremes. With a small α, the policy quickly finds one strategy and stops trying others; with a large one, it holds on to none. Between them lies a narrow window: at α = 0.2, Ada still goes to both shelves, but she doesn't split the attempts evenly: 10% go to shelf 1, 40% to shelf 2, and half end away from both. This is the same action multimodality as in lesson 1.3: two equally good strategies, two modes. A Gaussian has one peak, and at the start of the path the policy has a single mean action, so it can split the attempts between the shelves only through its spread. A narrow bell sticks to one shelf, while a wide one reaches both but wastes many attempts. Where this window lies depends on the reward scale, on the task and even on the random seed.
That's why α came to be tuned automatically: what is held at the target is not the temperature itself but the policy's entropy. This removes manual tuning, but it doesn't settle the choice between the shelves: with automatic tuning, Ada went to one shelf in all six runs. To keep both strategies, you need a policy with several peaks; the SAC authors note that their way of tuning the temperature also works for such policies.
All the experiments in this lesson ran in simulation, where a step costs nothing. What happens when SAC trains a real robot?
SAC on real robots: Minitaur, a claw and SERL
On a real robot, the cost of a step also includes falls that damage the hardware and people who pick the robot up and return the scene to its starting state. In the “Algorithms and Applications” paper, the SAC authors tested the method on two such robots. The first was Minitaur, a small four-legged robot with eight direct-drive motors, two per leg. It's a different robot, not Ada: Ada has a wheeled base. The policy sets the swing angle and the extension of each leg, and a PD controller, as in lesson 0.3, drives the motors to these angles. Delays and impacts with the floor break the assumption that the next state depends only on the current one, so the state included the current and the five previous observations and actions. The reward was the forward speed, measured by a motion capture system, with penalties for large angular accelerations, large pitch angles and extending the front legs under the body: these were the most common reasons the robot fell. An onboard Jetson TX2 computer collected the data, and a workstation trained the policy; the data exchange ran in parallel with the walking.
Minitaur learned to walk in 160,000 steps: about 400 episodes of up to 500 steps and roughly two hours in the real world, without simulation or pretraining. It was trained only on flat ground and tested on a slope, on an obstacle made of wooden blocks and on steps going down. The robot handled them without any fine-tuning, and the authors attribute this to maximum entropy: a policy that acted as randomly as possible during training got used to different situations. People couldn't be removed entirely: the robot had to be put back in place if it fell or drifted too far.
The second robot was a three-fingered claw with 9 servos that turns a valve to the desired position from any starting one. Learning from camera images, SAC needed 300,000 steps, about 20 hours including resets and network training. When the networks were given the valve angle instead of an image, 3 hours were enough, while PPO took 7.4 hours on the same task in earlier work.
SERL (Luo et al., 2024) is an open-source library for reinforcement learning on a real Franka arm. It runs the RLPD algorithm, a variant of SAC with three changes. It makes many updates per interaction step, saving steps at the cost of compute, as in Lab 1. It takes half of every batch from 20 operator demonstrations recorded with a 3D mouse: an off-policy method doesn't care who chose the action, and the demonstrations simply sit in a buffer of their own. And it normalizes the critic's layers so that many updates in a row don't destabilize it. In the circuit board task, the reward comes from the arm's pose itself, and in the others, from a classifier that decides from an image whether the task succeeded. In the object relocation task, the scene is reset by two policies: one moves the object, and the other moves it back. The policy runs at 10 Hz and tells a 1 kHz impedance controller where to pull the gripper; it's the controller from lesson 0.3 that behaved like a spring of a given stiffness and pressed on the table no harder than the error allowed.
The numbers come from the SAC paper “Algorithms and Applications” (Sec. 7.2–7.3) and the SERL paper (Table 2, Fig. 6). The SERL times include computation, resets and pauses.
For comparison, the SERL authors trained a policy by imitation learning on 100 demonstrations, five times more than RL got. RL beat it by a factor of 10 in success on the circuit board, 5 on the cable and 1.7 on the object relocation, and it did the tasks up to three times faster than the operators in the demonstrations. This is the answer to the question this part asks: a robot's own experience and an evaluation of the result give it what demonstrations lack. But in each of these works, people are nearby: they set up the motion capture cameras, label successes for the classifier, record demonstrations and pick up the robot when it falls. What of this lives on in today's systems?
Simulation for cheap steps, a buffer for expensive ones
The methods of this lesson have split into two roles. Where a step is cheap, in simulation with thousands of robots in parallel, PPO does the work: as lesson 5.2 showed, this is how walking is trained in minutes, and PPO doesn't need to save steps; it needs to process huge rollouts quickly. Where a step is expensive, on a real robot, the work goes to off-policy methods, the successors of SAC: they keep all the experience, put demonstrations into the same buffer and squeeze dozens of updates out of every transition, as SERL does.
The idea of learning from the experience of past versions of the policy has reached large models too. π*0.6 from Physical Intelligence (2025), which came up in lessons 3.8 and 4.6, trains the model on the robots' own attempts from all iterations, with an estimate of which actions were better, and the data aren't thrown away after every update. And lesson 4.6 showed that here, too, the flywheel doesn't spin without people who label the failures.
One question remains that this lesson sidestepped: can you get the cheap steps of simulation without paying for the gap between the simulator and the real world? That's what the next lesson is about.
Eight common misconceptions
Lesson takeaways
- On-policy methods like PPO learn only from the experience of the current policy and throw the rollout away after an update: the policy gradient holds only for the policy that chose the actions. That's why they need millions of steps, which is tolerable in simulation but expensive on a robot.
- The Q-function learns from any transition: the target value doesn't depend on who chose the action. This lets you keep experience in a replay buffer and learn off-policy, like DQN on Atari. In the interactive, by step 1,000 each transition of the first episode had taught 73 times on average, and without the buffer the average success dropped from 96 to 52%.
- DDPG carries the idea over to continuous actions: the actor outputs an action, and the critic tells it which way to shift it. TD3 fights overestimation with three tricks: two Q-functions with the smaller one in the target value, less frequent actor updates and noise in the target value.
- SAC adds a bonus for randomness with weight α to the reward and learns a stochastic policy. With a small α, Ada went to one shelf in 98% of the attempts, and with α = 1, only 3% of the attempts ended at the shelves; that's why α is tuned automatically, holding the policy's entropy at the target, . The SAC policy is a single Gaussian with one peak: it can widen its spread, but it doesn't split the attempts evenly between the two shelves, and with automatic α Ada also went to just one.
- SAC saves steps, not compute: on Ada's arm, it reached 90% in 500 steps versus 1,250 for PPO, but it spent three times as many multiplications per step, and to reach 90%, both made roughly the same number of them.
- On real robots, SAC taught Minitaur to walk in 160,000 steps, about two hours, and SERL teaches an arm to insert a connector in 20 minutes; it keeps 20 demonstrations in the buffer, computes the reward from the arm pose (in the cable and object-relocation tasks SERL takes the reward from a classifier) and resets the scene automatically.
Open questions
If updates per step save experience, why not make a hundred of them for every step?
The more updates on the same transitions, the more the critic fits its own target values and the quirks of a particular batch, and the actor finds its errors, as in the section on overestimation. RLPD in SERL makes many updates per step and therefore normalizes the critic's layers, and in Lab 1, with a single update per step, SAC already spent three times more compute per step than PPO. Where the limit lies depends on the task, the size of the networks and how diverse the buffer is.
Can you learn from the buffer alone, without taking any new steps at all?
If the buffer was collected in advance, from demonstrations, old policies or other robots, learning from it is called offline reinforcement learning. The difficulty is that there's nothing to check the Q-function against: for actions that aren't in the data, the critic makes mistakes, and the actor is drawn exactly to where the estimate is mistakenly high. When learning with new steps, experience corrects such errors; offline, only the caution of the method itself does. That's why SERL starts from demonstrations but then learns from its own attempts.
Paper guide
T. Haarnoja et al., “Soft Actor-Critic Algorithms and Applications”, 2018.
- Read closelySection 4.2 and Algorithm 1: how soft policy iteration turns into the updates of two Q-functions and the policy. Section 5, Eq. 18: the automatic temperature. Sections 7.2–7.3: Minitaur and the valve-turning claw, and what had to be added to the reward and the state for the sake of a real robot.
- Safe to skipThe proofs in Section 4.1 and the derivation of the dual problem for the temperature (Eqs. 7–17): the final Eq. 18 is enough to understand the algorithm.
- Question to keep in mindWhy is the target entropy , a negative number? What happens to a policy with squashing if you set the target entropy much higher?
Other papers in this lesson: DQN (Mnih et al., 2013), DDPG (Lillicrap et al., 2015), TD3 (Fujimoto et al., 2018), SAC (Haarnoja et al., 2018), SERL (Luo et al., 2024). The definitions of on- and off-policy learning, Q-learning and double learning (two independent estimates, so as not to overestimate the maximum, like the two Q-functions in TD3 and SAC) are given in the textbook by R. Sutton and A. Barto, “Reinforcement Learning: An Introduction,” 2nd edition, 2018, Sec. 5.5, 6.5 and 6.7.
Resources
- SAC: Algorithms and ApplicationsProject page: videos of Minitaur and the valve-turning claw learning
- softlearningThe authors' SAC code
- TD3The authors' TD3 code and learning curves
- SERLThe library, documentation and videos of the circuit board, cable and object relocation tasks
SAC learns from old experience, and training on a real robot takes hours, while in a simulator a step costs almost nothing. But a simulator is a single model of the robot: one set of masses, one friction, motors without delay. A policy learned on it may sway and miss on a real arm.
Lesson 5.4 · Sim-to-real transfer: how dynamics randomization prepares a policy for the real robot