Sim-to-real transfer: dynamics randomization
In lessons 5.2 and 5.3, policies learned in a simulator, where a step costs almost nothing: PPO trains walking on thousands of copies of a robot in minutes. But a simulator is a single model of the robot, with one set of masses, one friction value and motors that execute a command instantly. On a real arm, the cup may be heavier, the joints stiffer and the motors weaker, and the command reaches the actuator late, so a policy learned on one exact model can oscillate and miss on the robot. In 2018, Peng et al. trained an arm to push a puck and varied 95 simulator parameters in every episode: on the real robot, such policies brought the puck to the goal in 67–89% of attempts, while the policy trained without these variations succeeded in none of 10. Tan et al. and Hwangbo et al. added an actuator model and latency to the simulator, and in 2019 OpenAI made the variation ranges grow on their own, and a hand trained only in simulation solved a Rubik's cube on the real robot. We'll look at what exactly doesn't match, how to train a policy on many worlds at once, what this costs, and how to choose the width of the ranges without tuning them by hand.
How an arm in the simulator differs from a real one
In lesson 5.2, Rudin et al. trained the ANYmal quadruped to walk on 4,096 copies at once, and 20 minutes on a single GPU were enough. In lesson 5.3, SAC saved steps because on a real robot, every step costs time and wear. We'd like the best of both: train the policy in a simulator, where a step is almost free, and transfer it to the robot without fine-tuning. Lesson 4.5 showed what gets in the way for vision: light, paint and shadows in the renderer differ from what the camera sees, and image randomization helps, with random tablecloths, light and paint in every training scene. For a policy that commands motors, the gap lies elsewhere: in the dynamics, that is, in how the body responds to a command.
The simulator knows the robot's nominal model: the masses and dimensions of the links from the drawings, the friction from the datasheet, and a motor that delivers exactly the torque requested, at the same instant. On a real robot, everything is a little different. The masses are known with an error: Hwangbo et al. estimate that ANYmal's inertia differs from the drawings by up to 20% because of the cables and electronics the drawings leave out. Friction varies from joint to joint and over time. A motor can't deliver more than its limit: Tan et al. write that in a real motor, the torque stops growing along with the current. And the command doesn't arrive instantly. On the Minitaur quadruped, 15–19 ms passed between the policy and the motor, while in the Bullet simulator, where the policy was trained, a command took effect immediately. The time from the policy's decision until the actuator starts executing it is called control latency.
Each mismatch seems small on its own. But Peng et al. sent the same trajectory to the Fetch arm in the simulator and to the real one and got noticeably different joint angles. And a policy trained with reinforcement learning actively seeks out the ways the simulator differs from the world: the authors write plainly that such policies tend to exploit the idiosyncrasies of the simulator. The diagram below shows how latency and a weak motor change the path of the same command.
In the nominal world, the same controller brings the gripper to the target in 0.6 seconds and holds it there, while on the real arm, it moves more slowly and oscillates around the target until the end of the attempt. Which of the mismatches are dangerous for a policy trained with reinforcement learning, and which will it survive? Let's test this on Ada's arm.
A map of worlds: where a policy from an exact simulator stops coping
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, and it holds a cup in its gripper. Now the arm has dynamics: masses at the ends of the links, inertia, gravity. Each joint is driven by a PD controller with gravity compensation, as in lesson 0.3, and the controller computes the compensation for a cup of nominal mass. Twenty times per second, the policy decides where to move the gripper, by up to 10 cm horizontally and vertically, and the arm controller converts this shift into joint targets. Ada has to bring the cup to a target that appears in a new place in every attempt and hold it there. An attempt lasts 2 seconds and succeeds if, for the last half second, the gripper stays within 3 cm of the target.
The policy was trained by PPO from lesson 5.2 for 12,000 steps, that is, 300 attempts of 2 seconds each, in the nominal world: a 0.25 kg cup, 0.1 N·m of joint friction, no latency, and motors that deliver 100% of their torque. In this world, it holds the cup in all 20 test attempts. The map shows worlds it has never seen. The horizontal axis is the command latency, the vertical axis is the cup mass, and the other parameters are nominal. Click a cell, and Ada will make 20 attempts in that world, at the same 20 targets.
The map of worlds. Each cell is a world with those parameters, and its color shows the share of 20 attempts in which Ada held the cup at the target: green means all of them, red means none, and gray means the cell isn't opened yet. The black ring marks the nominal world in which the policy was trained, and the frame marks the selected cell. Click a cell to open it.
A side view of the selected world: Ada stands on the left, the arm is shown at the end of the attempt, the orange line is the gripper's path over 2 seconds, and the dots mark its position every 0.05 s. The green ring is the target, and the dashed circle is the 3 cm zone.
Under the hood: the arm dynamics, an actuator with latency and the spread across seeds
Dynamics. Let be the shoulder and elbow angles, and and their velocities and accelerations. The arm's motion obeys the equation from lesson 0.3:
Here is the inertia matrix, holds the centrifugal and Coriolis torques, is the gravity torque, and is the motor torques. The masses are point masses: 1.2 kg at the elbow and 0.9 kg at the gripper, plus the cup . The integration step is 5 ms.
The actuator. The policy outputs a gripper shift, and the arm controller converts it into joint targets through the Jacobian. The motor of joint delivers
Here and are the PD controller gains (110 and 55 N·m/rad, 7 and 3.5 N·m·s/rad), is the gravity compensation computed for the nominal 0.25 kg cup, is the torque limit (30 and 14 N·m), is the motor strength as a fraction of nominal, and is the joint friction: dry friction of magnitude plus viscous friction . The latency works like this: a new joint target takes effect ms after the policy's decision, and until then, the actuator keeps driving toward the previous one.
The policy and the test. The observation contains the joint angles and velocities and the vector from the gripper to the target. The policy has no memory: it sees only the current moment. The 20 test targets are the same in all worlds, and during the test, the policy acts with its mean action, without randomness.
Spread. The numbers in the missions are computed for random seed 3. Across six seeds, with a 1 kg mug and no latency, 90–100% of attempts succeed, and with 40 ms of latency and the nominal cup, 30–55%. The boundary beyond which Ada holds the cup in fewer than half of the attempts lies at 40–50 ms. With motors at 60%, 70–85% of attempts succeed, and at 50%, 45–65%, while joint friction of up to 1.3 N·m has almost no effect.
The policy survives a heavy cup and stiff joints. These are constant disturbances: the arm sags or moves more slowly, the policy sees that the gripper isn't where it should be, and corrects. Latency is different: it breaks the feedback loop itself. The policy corrects an error that no longer exists by the time the command is executed, and the arm oscillates around the target. Weak motors are a third case: when there isn't enough torque to hold the cup, no policy will help. And Ada's real arms have latencies of 25–45 ms. How do you train a policy that survives this too, without knowing in advance which arm it will get?
Dynamics randomization: learning on many worlds at once
The policy from the exact simulator saw one world and adapted to it, including its errors. You could spend years refining the simulator, but you can't measure everything: Tobin et al. list nonrigidity, gear backlash and wear-and-tear, which the model doesn't have at all, and latency also changes from run to run. Lesson 4.5 offered another way for images: make the simulator not exact but varied, so that the real world becomes one of the variants for the model. Peng et al. (OpenAI and UC Berkeley, 2018) carried this idea over to physics. At the start of every episode, the dynamics parameters are drawn at random from given ranges, and the policy learns on all these worlds at once. This is called dynamics randomization. Training looks for the policy with the highest expected return, averaged not only over trajectories, as in lesson 5.2, but also over worlds:
Here is the policy, is a set of dynamics parameters (masses, friction, latency), is the distribution they are drawn from, is the trajectory of one episode, is the probability of getting it when acting with policy in a world with parameters , is the reward at step , and is the episode length. Without randomization, there is no outer average: there is one world, and is always nominal.
In Peng et al.'s work, a Fetch arm with seven degrees of freedom has to push a puck to a random point on a table. The reward is binary: 0 if the puck is at the goal and −1 otherwise. In total, 95 parameters were varied: the link masses from 0.25 to 4 times nominal, joint damping, the puck's mass from 0.1 to 0.4 kg and its friction from 0.1 to 5, the table height, the controller gains from half to twice nominal, observation noise and the time between actions. With the random time between actions, the authors modeled the controller's latency. Masses and friction stay fixed for the whole episode, while the time between actions and the noise change at every step. Training took about 100 million steps, roughly 8 hours on a 100-core cluster, and the authors did almost no calibration of the simulator to the robot.
On the real robot, the policy trained without randomization failed in all 10 attempts. With randomization, a network without memory brought the puck to the goal in 67% of attempts, and a network with memory, an LSTM that receives the current state and the previous action as input, in 89% of 28 attempts, almost as in simulation (91%). When a packet of chips was attached to the bottom of the puck, changing its friction against the table, success stayed at the same level: 91%. An ablation showed which randomizations matter most: without the random time between actions, success fell to 29%; without observation noise, to 25%; with fixed link masses, to 64%; and with fixed puck friction, to 48%.
Briefly, why the policy needs memory: from how the world responded to its past actions, it can work out which of the worlds it is in. We'll discuss this in detail in the next lesson. Here we're interested in randomization itself, so we'll test it on Ada's arm without memory: the policy sees only the current state.
With and without randomization: one budget, the same real arms
We'll train two arms the same way: PPO from lesson 5.2 with the same networks, reward and random seed, 12,000 steps each. The first one learns only in the nominal world; this is the policy from the interactive above. The second gets a new world at the start of every attempt: cup mass from 0.1 to 0.6 kg, joint friction from 0 to 0.5 N·m, latency from 0 to 50 ms, motor strength from 75 to 110%. As Peng et al. did, we draw the mass uniformly on a log scale, and everything else uniformly.
We test both on Ada's six “real” arms. They run in the same simulator, but with parameters that weren't in training: each arm has its own cup, its own joints, its own link latency and its own motor wear, listed in the table under the scene. The real gap is bigger: a physical arm has backlash, compliance and much else that our model lacks. Each policy makes 20 attempts on each arm, at the same targets as in the interactive.
Side view: both scenes show the same real arm and the same target. The target is the green ring, and the dashed circle around it is the 3 cm zone. The colored line is the gripper's path over 2 seconds, and the arm is shown at the end of the attempt. Under the scenes is the share of successful attempts on all six arms. The table below lists the six real arms: their parameters and how many of 20 attempts each policy succeeded in. Click a row to show that arm in the scenes.
Under the hood: PPO training, the test and the spread across seeds
PPO. Everything is as in lesson 5.2. A rollout consists of 10 attempts of 40 steps each, and it goes through 8 epochs of updates in mini-batches of 100 steps, with the probability ratio clipped to . Advantages are computed with GAE with and discount , and the Adam step size is 0.003. The policy is a Gaussian: a network with two layers of 24 neurons outputs the mean gripper shift, and the spread is set by a single shared trainable parameter. The value is computed by a network of the same kind. The reward per step is , where is the distance from the gripper to the target in meters; 1 is added while the gripper is within 3 cm of the target, and a small penalty for abrupt commands is subtracted.
Randomization. The world is drawn once at the start of an attempt and kept until its end. The policy doesn't know which world it got: its input has only the joint angles and velocities and the vector to the target.
Time to target is counted up to the moment from which the gripper entered the 3 cm zone and didn't leave it until the end of the attempt, and it's averaged over successful attempts.
Spread. The numbers in the missions are computed for seed 3. Across six seeds, without randomization, 48–88% of attempts on the real arms succeed, and with randomization, 97–100%. Without randomization, the worst arm is Ada 4 with 45 ms of latency: 10–50%. In the nominal world, both policies hold the cup in all attempts, but the policy without randomization reaches the target faster on all six seeds.
With the same budget, randomization pulled through all six arms, and the price was speed in the nominal world. But our “real” arms differ from the nominal one in exactly the parameters we varied during training. If the gap lies in something the simulator can't do at all, such as how the actuator works, varying parameters is useless. What then?
Actuator model and latency: bringing the simulator closer to the robot
Randomization helps when the real world resembles one of the simulator's variants. But if the simulator is built differently from the robot, no matter how you vary the parameters, the real world won't be among the variants. Tan et al. (Google, 2018) ran into this with the Minitaur quadruped. Its eight direct-drive motors are run by a position controller, and in the Bullet simulator, this controller was modeled as a constraint that is satisfied exactly by the end of the step. The authors write that with large gains, such motors “can remain stable in simulation but oscillate in reality.” The policy trained in this simulator learned a slow walk, and the real Minitaur fell to the ground immediately.
So the authors brought the simulator closer to the robot. They took the Minitaur apart and weighed and measured its links. They described the motor as an ideal DC motor, with a correction: in a real one, the torque stops growing along with the current, and they set this dependence with a piecewise linear function fitted to measurements. They measured the latency, 3 ms for the motor controller on the microcontroller and 15–19 ms for the policy on the onboard computer, and added it to the simulator. The authors' conclusion: without the actuator model or without the latency, the learned policies don't work on the robot. With both, the Minitaur learned to gallop and trot: the gallop reached 1.34 m/s in simulation and 1.18 m/s on the robot and used 35% less power than a hand-tuned gallop. They used randomization too, with mass ±20%, latency 0–40 ms, motor strength 80–120% and ground friction 0.5–1.25, but noted that “if the model discrepancy is too big, even a robust controller trained with random perturbations cannot overcome the reality gap.”
The Minitaur's motor can be described by a formula because its drive is direct. With ANYmal's series elastic actuators, this didn't work. In lesson 0.2, we trained a small network to reproduce a real actuator from its recordings: that's an actuator model from data. Hwangbo et al. (ETH Zurich and Intel, 2019) did this for all 12 of ANYmal's actuators: a network with three layers of 32 neurons predicts the torque from the position errors and velocities over the last 0.02 s. The data, more than a million examples, were collected in less than 4 minutes. The network's mean error was 0.74 N·m versus 3.55 N·m for the ideal actuator model. For comparison, the authors trained policies with an ideal actuator and with an analytical model that they had tuned for more than a week. Neither could make a single step without falling: the legs shook violently, and the authors attribute this to delays that these models get wrong.
ANYmal's policy was trained in a simulator with these actuator networks inside: it computed almost 500,000 steps per second on a single computer, and training took no more than 11 hours. The error of the inertia estimated from the drawings, up to 20%, was handled by randomization: 30 variants of the robot with link masses ±15% and centers of mass ±2 cm. ANYmal reached 1.5 m/s, 25% faster than the previous record for this robot. The authors sum up what each technique did: the learned actuator model significantly reduces the reality gap, while the randomness in the model makes the policy sufficiently conservative. And they write that in practice, both approaches, a more accurate model and a more robust policy, “are typically employed in conjunction.” So how much of this caution is needed?
Range width: reliability versus speed
The ranges in lab 1 were chosen to roughly match the spread of the real arms; let's call this width ×1. The slider changes it with a single multiplier for all four parameters. At ×½, the training latency goes up to 25 ms, and the cup mass up to 0.43 kg. At ×2, the latency goes up to 100 ms, the mass up to 0.95 kg, and the motor strength goes down to 50%. At ×0, there's no randomization. For each width, the policy is trained from scratch for 12,000 steps with the same seed, and the test is the same: six real arms, 20 attempts each.
At the top is the map of worlds, as in the interactive, for the policy of the selected width: the orange frame is the region from which worlds were drawn during training, and the dots are the real arms. At the bottom is where each width ended up on two measures at once: how many attempts succeeded on the real arms and how long, on average, the trip to the target took in successful attempts.
The map of worlds: each cell is 20 attempts in a world with that latency and cup mass, with the other parameters nominal, and the color shows the share of successful ones. The orange dashed frame surrounds the cells whose latency and mass fell within the training ranges. The numbered blue dots are Ada's real arms (they have their own friction and motor strength, so their positions on the map are approximate). The black ring is the nominal world.
The chart: the horizontal axis shows how long, on average, the trip to the target took in successful attempts on the real arms, in seconds; the vertical axis shows the share of successful attempts on the six arms. Each dot is the policy of one width, and the label next to the dot is the multiplier. The best place to be is the upper left corner: reliable and fast.
Under the hood: how the width works and the spread across seeds
Width. For each parameter, the shifts of the range boundaries from nominal at width ×1 are fixed: cup mass from −0.15 to +0.35 kg, joint friction from −0.1 to +0.4 N·m, latency from 0 to +50 ms, motor strength from −25 to +10%. At width , the range equals the nominal value plus these shifts multiplied by , within physical limits: the mass is at least 0.02 kg, friction is at least zero, latency is at most 150 ms, and motor strength is at least 30%. At ×3, the ranges are: cup up to 1.3 kg, friction up to 1.3 N·m, latency up to 150 ms, motors from 30% strength.
Why slower. A policy without memory doesn't know which world it got, and it picks one behavior for all the training worlds. If those include a world with 150 ms of latency, a fast approach to the target ends in oscillation there, and the reward over all such worlds pulls the policy toward a slow, cautious approach, even in a world with short latency. Tan et al. saw the same on the Minitaur: with randomization, the returns have a lower mean but also a smaller spread across worlds, and in the authors' words, “the controllers learn to behave conservatively.”
Spread. The numbers in the missions are computed for seed 3. Across six seeds, ×½ gives 94–100% successful attempts on the real arms, and ×1 gives 97–100%. Width ×3 gives 40–98% successful attempts versus 97–100% for ×1, and the arm takes 0.84–1.02 s to reach the target versus 0.69–0.78 s, so it is slower on all six seeds. On one of them, the ×3 policy never learned the task in 12,000 steps: even in the nominal world, it held the cup in 3 attempts out of 20.
Even narrow randomization shifts the policy toward behavior that transfers beyond the training range. Too wide a range makes it cautious all the time: there are too many worlds where a fast approach is dangerous. That's why the width is chosen to match the real spread with a small margin, as Tan et al. did, and for that, you need to know the spread. In Dactyl from lesson 4.5, the ranges had to be tuned by hand, and the full randomization cost 100 years of simulated experience versus 3 years without it. Can the ranges be chosen automatically?
Automatic domain randomization: the ranges grow on their own
Tuning the ranges by hand is expensive: in Dactyl, as the authors write, it “required a significant amount of manual tuning and a tight iteration loop between randomization design in simulation and validation on a robot.” By the time of the Rubik's cube work (OpenAI, 2019), the Shadow hand and the simulator had changed, and the old manual randomization no longer transferred: a policy trained with it on the new setup made 42.5 turns of the cube in a row on average in simulation and 2.7 on the real hand. Instead of tuning the ranges again, the authors made them tune themselves. This is automatic domain randomization (ADR).
Training starts in a single world, with the parameters measured during calibration of the real hand. Each parameter has its own interval from which it is drawn, and at first, both ends coincide with the calibrated value. From time to time, ADR sets one random parameter to one of the boundaries of its interval, draws the rest from their current intervals, and checks whether the policy copes. The results are accumulated separately for each boundary. When of them have accumulated, ADR compares their mean with two thresholds:
Here and are the upper and lower performance thresholds, and is the step size. OpenAI measures performance by the number of successful turns in a row in an episode, with these settings: , , , ; boundary checks are done in half of the episodes. This creates a curriculum: first, the policy solves the task in a single world, and then worlds are added exactly as fast as it masters them. The authors measure how wide the distribution is with the ADR entropy: the mean over the parameters of the logarithm of the interval widths.
On the same new setup, ADR was trained for as long as the manual randomization, about 14 days. A snapshot of the policy taken when the ADR entropy reached 0.126 nats per parameter (a nat is the unit of entropy computed with the natural logarithm) made 13.3 turns in a row on average on the real hand, versus 2.7 for the manual one; the wider the ranges had managed to become, the better the transfer. A policy trained longer and at a larger scale made 32 turns on average and 42 at the median. The authors also compared ADR with fixed ranges of different widths: “the larger the fixed randomization entropy, the longer it takes to train from scratch,” while ADR “makes progress much faster due to its curriculum property.”
The policy for the Rubik's cube was trained for several months, about 13,000 years of simulated experience. With it, the Shadow hand solved a cube whose solution required 15 face rotations in 60% of attempts, and one requiring 26 rotations in 20%. Without being trained on such disturbances, it kept turning the cube in a rubber glove, with its fingers tied together, and while the cube was poked with a pen and a plush giraffe. The authors explain this by meta-learning: in the first seconds of an attempt, a policy with memory figures out which world it is in; from the LSTM's hidden state, the cube size can be predicted with over 80% accuracy. Nobody programmed this ability; it emerged from the breadth of the worlds. Let's see how ADR widens the ranges of Ada's arm.
ADR on Ada's arm: where the ranges stop
All four ranges start at nominal: a 0.25 kg cup, 0.1 N·m of friction, zero latency, motors at 100%. Half of the attempts are boundary attempts: in them, one random parameter is set to its current boundary. When a boundary has accumulated 5 such attempts, ADR looks at the share of successful ones: if it's 80% or more, the boundary moves outward by a quarter of the ×1 width from lab 2, and if it's 40% or less, it moves back, but not past nominal. Boundary attempts are used for training too. The training is done by the same PPO and lasts 24,000 steps.
At the top are the ranges of the four parameters at the selected moment of training. The slider below them moves this moment. At the bottom is the share of successful attempts on the six real arms over the course of training.
Each bar shows the range from which ADR draws the parameter at this moment of training: the orange one is ADR's, and the gray dashed frame is the fixed wide range for comparison in the second mission. The black tick is nominal, and the blue ticks are Ada's real arms.
The chart: the horizontal axis is training steps, and the vertical axis is the share of successful attempts on the six real arms (120 attempts) for the policy at that moment. The orange line is ADR, the gray dashed one is the fixed ×3 range from the first step, and the vertical dotted line marks the moment shown by the bars.
Under the hood: ADR in the paper and here, entropy and the spread across seeds
The algorithm. The distribution of worlds is a product of uniform intervals, one per parameter: . OpenAI measures the width of the whole distribution with the ADR entropy:
where is the number of parameters, and and are the boundaries of the interval of the -th parameter; the entropy is measured in nats per parameter. With probability , each of the parallel experience-collecting workers performs a boundary check, and otherwise it simply collects experience for training; OpenAI uses , and the data from boundary checks also go into training the policy.
In our version. We use , a boundary buffer of attempts and thresholds of and successful attempts. The step is a quarter of the shift at width ×1: 0.0375 and 0.0875 kg for the mass, 0.025 and 0.1 N·m for friction, 12.5 ms for latency, 6.25 and 2.5% for motor strength. The lower boundary of latency is zero and doesn't move. We don't show the entropy: for an interval of zero width at the start, it equals minus infinity.
The comparison. For comparison, we take the fixed ×3 range from lab 2 from the first step, with the same PPO, the same budget and the same seed. “Reached 90%” means the first test (every 1,200 steps) at which the policy holds the cup in at least 108 attempts out of 120.
Spread. The numbers in the missions are computed for seed 3. Across six seeds, ADR reaches 90% on the real arms by step 3,600–4,800, and the fixed ×3 range by step 10,800–14,400. By the end, ADR succeeds in 97–100% of attempts, and ×3 in 93–100%. ADR's time to target is 0.68–0.73 s, and that of ×3 is 0.75–0.93 s, so ADR is faster on all six seeds. By the end of training, ADR's upper boundary of latency reaches 75–150 ms, the lower boundary of motor strength drops to 63–81%, and the upper boundary of cup mass reaches 0.6–0.78 kg. With the threshold , the latency range comes out no wider than with 80% on four seeds out of four, and with 60%, no narrower.
ADR doesn't know in advance what matters. It widens each range as long as the policy copes at its edge, and finds on its own where the limit lies: the policy learned to survive latency with a large margin, but not weak motors with a heavy cup, because there isn't enough torque there. The curriculum also saves steps: at the start, the policy learns in a simple world, and the hard worlds are added when it's ready for them. What of this lives on in today's systems?
Actuator models, randomization and curricula together
The recipe of this lesson, a more accurate model where it can be measured and randomization where it can't, has become standard for policies trained with reinforcement learning in simulation. Rudin et al., who in lesson 5.2 trained ANYmal to walk in 20 minutes on 4,096 copies, prepared the transfer to the robot like this: they randomized the ground friction from 0.5 to 1.25, pushed the robots every 10 seconds, accelerating the body to up to 1 m/s in a random direction, and added noise to the observations at a level measured on the real robot. The actuator torques were computed by a network trained on data, as in Hwangbo et al.'s work.
Their curriculum works like ADR, only for terrain. Each robot has its own difficulty level: the step height grows from 5 to 20 cm, and the slope up to 25°. A robot that made it to the edge of its terrain gets a higher level in the next episode, and one that didn't cover even half of the required distance gets a lower one. The difficulty adapts to the policy without manual tuning. As lesson 4.5 mentioned, humanoids are taught to walk the same way, such as the legs of HOMIE from lesson 4.2; we'll talk about this in more detail in part 6. For now, Ada has a wheeled base, and her arm in this lesson is the same case, only simpler.
Randomization without memory has a ceiling: the policy doesn't know which world it is in and picks one behavior for all worlds, so it is cautious everywhere. On the real ANYmal, Rudin et al. limited the speed to 0.6 m/s because the robot's height map is imprecise, and they pointed to the teacher-student setup of Miki et al. (lesson 5.5), which, in their words, “provided outstanding robustness even in adverse conditions.” Peng et al. already fed the world parameters to the critic as input, and in OpenAI's work, a policy with memory figured out the cube size on its own. How to make use of the fact that everything is known in the simulator, we'll cover in the next lesson.
Eight common misconceptions
Lesson takeaways
- The simulator knows the robot's nominal model, while the real robot has different masses, friction and motor strength, plus control latency. Not all mismatches are equally dangerous: on Ada's arm, a 1 kg mug barely bothered the policy from the exact simulator (100% successful attempts), while 40 ms of latency dropped success to 45%.
- Dynamics randomization trains the policy on a distribution of worlds. For Peng et al., the policy without it failed in all 10 attempts on the robot, and the policy with it succeeded in 67–89% of attempts. On Ada's six real arms, with the same budget of 12,000 steps, the share of successful attempts was 78% without randomization and 99% with it.
- Robustness is paid for with speed: the policy picks a behavior that is safe in all the training worlds. In the nominal world, the randomized arm took 0.55 s to reach the target versus 0.49 s, and at width ×3 on the real arms, 0.88 s versus 0.72 s at ×1, with no more successful attempts.
- Randomization can't cover what the simulator can't do at all. Tan et al. added a motor model and latency, and without them, the Minitaur policies didn't work on the robot; in Hwangbo et al.'s work, ANYmal's actuators are computed by a network trained on 4 minutes of data, and with an ideal actuator, the policy couldn't make a single step. In practice, a more accurate model and randomization go together.
- ADR starts from the calibrated world and widens each range as long as the policy copes at its boundary. For OpenAI, this raised transfer from 2.7 to 13.3 cube turns in a row and made it possible to solve a Rubik's cube. On Ada's arm, ADR reached 90% on the real arms by step 4,800, versus 10,800 for the wide range from the first step, pushed latency out to 75 ms and stopped motor strength at 63%.
Open questions
A randomized policy works “on average” across all worlds. Why not give it the world parameters as input?
In the simulator, the parameters are known, and a policy that sees them can be fast where the world allows it and cautious where it doesn't. But a real robot has no masses, friction or latency at its input: they have to be estimated from how the arm responds to commands. Peng et al. gave the parameters only to the critic, which is needed only during training, and gave the policy memory. How to turn the simulator's knowledge into a policy that doesn't need it on the robot, we'll cover in lesson 5.5.
How do you tell what exactly to randomize and how widely?
You can measure what can be measured, such as masses, latencies and motor characteristics, and randomize around the measured values with a margin, as Tan et al. did. You can check with an ablation what matters for transfer, as Peng et al. did, for whom random latency turned out to matter more than the masses. Or you can hand the choice over to ADR, but then you need to check that the ranges grew toward where the real robot lies, and not into worlds that don't exist: wide worlds make the policy more cautious.
Paper guide
- Read closelySections IV-C and IV-D and Table I: which parameters to vary, within what limits, and why latency is modeled with a random time between actions. Tables II and III: which architectures and which randomizations are needed for transfer to the real arm.
- Safe to skipSection III-B on Hindsight Experience Replay and the details of Algorithm 1: for the idea of randomization, the training objective from Section IV is enough.
- Question to keep in mindWhy did success on the robot fall to 25% without observation noise, even though noise isn't dynamics? What else in the real robot, besides the sensors, could it stand in for?
Other papers in this lesson: Tan et al., 2018 (Minitaur, the motor model and latency), Hwangbo et al., 2019 (ANYmal, the actuator network), OpenAI, 2019 (the Rubik's cube, ADR), OpenAI, 2018 (Dactyl), Tobin et al., 2017 (domain randomization), Rudin et al., 2021 (walking in minutes, a terrain curriculum).
Resources
- Video for Peng et al.The Fetch arm pushes the puck, including one with a packet of chips attached
- Video for Tan et al.The Minitaur's gallop and trot in simulation and on the robot
- Solving Rubik’s Cube with a Robot HandOpenAI's post with videos of ADR and the disturbances
- legged_gymThe open code of Rudin et al.: parallel training of walking with randomization and a curriculum
Randomization carries the policy over to the real robot: it works in all worlds at once, but cautiously, because without knowing which world it is in, it prepares for the worst. Yet the simulator knows everything about its world: the floor friction, the mass of the load, the terrain.