VLA · Phase 3 · Robot Learning Foundations
3.5 — Distribution Shift and Generalization
Why a policy that works on its training data can fail in a slightly different setting.
Robots meet new rooms, lights and objects all the time. This lesson shows what distribution shift is, two small experiments in which a model fails, and two cheap defences.
Claims about papers, models and textbooks carry numbered references, listed with what each one is cited for in the References. Code marked “Toy model” is our own illustration, not the cited system.
Learning objectives
After this lesson, you should be able to:
- Define distribution shift and covariate shift.
- Explain why models fail outside the range of their training data.
- Explain how varied training data helps, and its limit.
- Flag unfamiliar inputs with a simple statistic.
- Train on data from one setting
- Deploy in a slightly different setting
- Inputs fall outside what training covered
- The model is unreliable there
- Defend with variety in training and an alarm at run time
The one-sentence idea
Models are reliable where they had data, and unreliable elsewhere.
Plan for the situations the training data did not contain.
The test is not like the training
Machine learning quietly assumes that the data you meet later looks like the data you trained on. On a robot that assumption is broken all the time: different lighting, a new table, another object, a different robot. This is called distribution shift. The standard reference on the topic describes dataset shift as the situation where the joint distribution of inputs and outputs differs between training and test, and covariate shift as the special case where only the input distribution changes.[1]
Robots add a second source that we met in lesson 3.3: the policy’s own mistakes change the states it visits, so the data it sees at run time differs from the demonstrations even in an unchanged room.[2] And the simulator-to-real-world version is the reality gap: policies trained in simulation can perform worse on real hardware because simulated and real environments differ.[3]
Outside the range it was trained on
The simplest picture: a model fitted on inputs between 0 and 1 and asked about inputs it never saw. The underlying rule here is a gentle curve. A flexible model fits it nicely where it has data, and goes wrong the moment it leaves:
import numpy as np
rng = np.random.default_rng(0)
x_train = rng.uniform(0.0, 1.0, 200)
y_train = np.sin(2 * x_train) + rng.normal(0, 0.02, 200)
coef = np.polyfit(x_train, y_train, 5) # a flexible model
for lo, hi in ((0.0, 1.0), (1.0, 1.5), (1.5, 2.5)):
x = np.linspace(lo, hi, 100)
err = np.abs(np.polyval(coef, x) - np.sin(2 * x)).mean()
print(f"inputs in [{lo}, {hi}] -> average error {err:.3f}")Output:
inputs in [0.0, 1.0] -> average error 0.003 inputs in [1.0, 1.5] -> average error 0.117 inputs in [1.5, 2.5] -> average error 9.691
Toy model. A curve fitted with a polynomial. Neural networks behave differently in detail, but the lesson holds: nothing in the training loss controls the model where there was no data.
The error is tiny inside the training range and grows quickly outside it. A robot gets there easily: a slightly different start position, an object in a new place.
A look-alike that breaks: lighting
Here is a visual version. A tiny classifier decides whether a patch of pixels is “object” or “background” using brightness. In training the room was always dimly lit. Then the lights come on:
import numpy as np
rng = np.random.default_rng(0)
def make_patches(n, light):
label = rng.integers(0, 2, n) # 1 = object (darker than the background), 0 = background
brightness = light * (0.6 + 0.3 * (1 - label)) + rng.normal(0, 0.03, n)
return brightness, label
def accuracy(threshold, light):
b, y = make_patches(2000, light)
return float(np.mean((b < threshold) == (y == 1)))
b, y = make_patches(2000, light=0.5) # training: a dim room
threshold = (b[y == 1].mean() + b[y == 0].mean()) / 2 # the learned rule: darker than this means object
print("learned threshold:", round(float(threshold), 3))
print("accuracy in the dim room: ", accuracy(threshold, 0.5))
print("accuracy in a bright room: ", accuracy(threshold, 1.0))Output:
learned threshold: 0.374 accuracy in the dim room: 0.9945 accuracy in a bright room: 0.508
Toy model. A one-feature classifier with made-up pixel values, chosen so that lighting scales every brightness.
In the bright room the whole picture is brighter, so nearly every patch is brighter than the learned threshold and gets called “background”; accuracy drops to about 0.5, no better than a coin. Nothing about the object changed. Only the conditions did.
Cheap defences: variety and a smoke alarm
The most common defence is to make training data more varied. Domain randomization, introduced in the context of sim-to-real, trains with randomised non-realistic textures in simulation; a detector trained only on such images localised real objects to about 1.5 cm, and the argument is that with enough variability in the simulator the real world looks like just another variation.[4] The same idea works for real data: record in many rooms, many lights, many objects. Pooling data across robots is a version of it, and the Open X-Embodiment collaboration reported positive transfer between platforms.[5] Even so, the RT-2 paper notes that physical skills remain limited to the distribution of skills seen in the robot data.[6]
Applied to our brightness rule, variety means training under many lights. The rule learns its threshold as a fraction of the scene brightness (which, in this toy, it is told):
import numpy as np
rng = np.random.default_rng(0)
def make_patches(n, light):
label = rng.integers(0, 2, n)
brightness = light * (0.6 + 0.3 * (1 - label)) + rng.normal(0, 0.03, n)
return brightness, label
def accuracy(rule, light):
b, y = make_patches(2000, light)
return float(np.mean(rule(b, light) == (y == 1)))
# Randomised training: the threshold is learned as a fraction of the scene brightness
ratios = []
for _ in range(50):
light = rng.uniform(0.3, 1.2) # a different room each time
b, y = make_patches(200, light)
ratios.append(((b[y == 1].mean() + b[y == 0].mean()) / 2) / light)
ratio = float(np.mean(ratios))
rule = lambda b, light: b < ratio * light # needs the room brightness as input (e.g. measured from the whole image)
print("accuracy in a dim room: ", accuracy(rule, 0.5))
print("accuracy in a bright room:", accuracy(rule, 1.0))Output:
accuracy in a dim room: 0.9925 accuracy in a bright room: 1.0
Variety only helps for kinds of variation that were present. A second defence is a smoke alarm: check whether new inputs look like the training inputs, and be careful when they do not. A simple version compares each new input’s feature with the training mean in units of standard deviation:
import numpy as np
rng = np.random.default_rng(0)
train_brightness = rng.normal(0.5, 0.1, 1000)
mean, std = train_brightness.mean(), train_brightness.std()
for name, value in (("dim room (as trained)", 0.52), ("slightly brighter", 0.7), ("lights fully on", 1.0)):
z = (value - mean) / std
print(f"{name:<22} z = {z:5.1f} ->", "UNFAMILIAR, slow down or ask for help" if abs(z) > 3 else "looks familiar")Output:
dim room (as trained) z = 0.3 -> looks familiar slightly brighter z = 2.1 -> looks familiar lights fully on z = 5.2 -> UNFAMILIAR, slow down or ask for help
Real systems use richer checks, but the principle is the same: an alarm for “I have not seen this before” is cheap, and a policy that knows when it is out of its depth is safer (lesson 1.1).
Common misconceptions
Misconception 1 “If it works in the lab, it works anywhere.”
Correction A change as simple as lighting broke the toy classifier completely.
Misconception 2 “A bigger model generalises to anything.”
Correction RT-2 reports that physical skills remain limited to the distribution of skills in the robot data.
Misconception 3 “Randomization covers everything.”
Correction It only covers the kinds of variation you randomise.
Engineering takeaways
- Shift = test differs from training.
- Errors grow outside the training range.
- Variety in training helps for the variation included.
- An unfamiliarity alarm is cheap and useful.
A model knows only what its data showed it.
Knowledge check
Try each question first, then reveal the explanation.
Question 1
What is covariate shift?
Explanation
Only the input distribution changes between training and test; the relationship from input to output stays the same.
Question 2
Why did the brightness rule fail in the bright room?
Explanation
Lighting scaled every brightness, so a threshold learned in the dim room misclassified everything.
Question 3
A feature has training mean 0.5 and standard deviation 0.1. A new input is 0.9. What is its z-score?
Explanation
4. (0.9 − 0.5) / 0.1.
References
Numbered notes in the text, like [1], point here. Each entry says what it is cited for and how that was checked. Papers and books can be revised or misread, so follow the links before relying on a detail. Code marked “Toy model” is our own illustration of an idea, not the code of the cited system.
(2009). Dataset Shift in Machine Learning. MIT Press. ISBN 978-0262170055
Cited for:
- Dataset shift is the situation where the joint distribution of inputs and outputs differs between training and test; covariate shift is the special case in which only the input distribution changes. Checked against the textbook (a standard definition, not re-read line by line for this lesson).
(2011). A reduction of imitation learning and structured prediction to no-regret online learning. AISTATS 2011, pp. 627–635 / arXiv. arXiv:1011.0686
Cited for:
- Sequential problems such as imitation learning break the i.i.d. assumption of standard statistical learning, which hurts performance. Checked against the paper’s abstract.
(2020). Sim-to-real transfer in deep reinforcement learning for robotics: a survey. IEEE Symposium Series on Computational Intelligence (SSCI) 2020. arXiv:2009.13303 · doi:10.1109/SSCI47803.2020.9308468
Cited for:
- Policies trained in simulation can perform worse on real hardware because simulated and real environments differ (the reality gap); the survey covers domain randomization, domain adaptation, imitation learning, meta-learning and knowledge distillation as responses. Checked against the paper’s abstract.
(2017). Domain randomization for transferring deep neural networks from simulation to the real world. IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS) 2017. arXiv:1703.06907
Cited for:
- A detector trained only on simulated images with randomised, non-realistic textures localised real objects to about 1.5 cm; the argument is that with enough variability in the simulator the real world looks like just another variation. Checked against the paper’s abstract.
(2023). Open X-Embodiment: Robotic learning datasets and RT-X models. arXiv:2310.08864
Cited for:
- A high-capacity model (RT-X) trained on the pooled data shows positive transfer, improving several robots using experience from other platforms. Checked against the paper’s abstract.
(2023). RT-2: Vision-language-action models transfer web knowledge to robotic control. Conference on Robot Learning (CoRL) 2023. arXiv:2307.15818
Cited for:
- The model’s physical skills remain limited to the distribution of skills seen in the robot data, although it can apply them in new ways using web knowledge. Checked against the paper’s abstract.
What’s next
That completes the robot-learning foundations. Next the roadmap moves on to the VLA models themselves.