Online, Offline, and Continual Learning › Batch and Streaming Updates
World Models HandbookAll chapters Online, Offline, and Continual Learning › Batch and Streaming UpdatesOne section · Sections in this chapter2 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The distinction between batch and streaming updates is about how data reaches the optimizer, not about how the optimizer works.
In the batch (or offline) setting you have a dataset collected beforehand. You choose parameters by minimizing the empirical risk
where:
- : the parameter estimate that minimizes the average loss over the dataset
- : the parameters being optimized
- : the dataset of input-target pairs,
- : the number of examples in the dataset
- : the per-example loss function, such as squared error
- : the model's prediction for input
- : the target value paired with
- : the -th input example
For a world model, is a transition input such as , is the target such as , and is the learned dynamics. This is the setting of Part V and Part VI so far. It has several properties worth naming explicitly:
- Reproducibility. The result can be reproduced when the dataset, architecture, optimization procedure, software stack, hardware, and random seeds are controlled.
- Multiple passes. You can shuffle and revisit every example as many times as you like.
- Auditability. You can inspect exactly what the model was trained on.
- Staleness. Once training stops, the model has no mechanism to notice that the world changed.
These properties are tightly connected. Reproducibility comes from the fact that the dataset is fixed, so the same optimization procedure applied to the same data yields the same result up to random seeds and hardware nondeterminism. Multiple passes are possible because the dataset is stored in full and can be revisited indefinitely; this is what allows offline training to extract many gradient steps per example. Auditability follows from the same storage: the training distribution is not a moving target but a concrete artifact that can be inspected, versioned, and checked for biases or gaps. Staleness is the price. A model that was trained on a fixed dataset has no internal signal that the world has moved on. Its errors on the new world are not necessarily large, but they are unmonitored.
In the streaming (or online) setting data arrives as a sequence and you update after each arrival:
where:
- : the parameters after processing the -th example
- : the parameters before the update
- : the learning rate at step
- : the current step index in the stream
- : the -th input and target pair arriving from the stream
- : the per-example loss function
- : the gradient of the loss on the current example with respect to the parameters
- : the model's prediction for input using the current parameters
- : the model parameters
This is stochastic approximation. Under the usual regularity assumptions on the objective, gradients, and noise, a standard route to convergence uses the classical Robbins--Monro step-size conditions. They require that the learning rates accumulate enough total step size to keep moving while the squared learning rates accumulate little enough total noise for it to average out:
where:
- : the learning rate applied at step
- : the total accumulated step size, which must diverge so the estimator can travel any distance
- : the total accumulated squared step size, which must converge so gradient noise averages out
Here is the learning rate applied at step . Such schedules are called square-summable but not summable: the first condition keeps the estimator moving in expectation, while the second keeps its variance from accumulating.
The first condition says the learning rate must not shrink so fast that the model freezes before it arrives. The second says it must shrink fast enough that accumulated gradient noise averages out. A schedule like satisfies both. The schedule and a positive constant both violate square summability; the constant still satisfies the divergent-sum condition. That persistent step size is useful in non-stationary settings because it keeps the estimator responsive, at the cost of a nonzero noise floor.
The schedule shape determines how the estimator behaves over time. The figure below compares three common choices on logarithmic axes, where the difference between square-summable and non-summable decay is easiest to read.
import numpy as np
schedule_t = np.arange(1, 201)
eta_inverse_t = 1.0 / schedule_t
eta_inverse_sqrt = 1.0 / np.sqrt(schedule_t)
eta_constant = np.full_like(schedule_t, 0.05, dtype=float)
The Robbins and Monro conditions are a useful reference point even when they do not literally apply. They describe the behavior of an estimator that is trying to converge to a fixed target in a stationary world. In a world-modeling loop, the target is not fixed: the true dynamics may change, and even if they do not, the distribution of states and actions that the model sees depends on the policy, which depends on the model. The classical conditions therefore tell us what convergence would require if the world stood still. They also tell us why practical systems use constant or slowly decaying learning rates: the agent is not trying to converge to a fixed answer, because the answer keeps moving.
A useful mental model is to separate two questions. The first is whether the optimizer can reach a good solution if one exists. The second is whether the optimizer can track a solution that changes over time. Batch learning is optimized for the first question. Streaming learning with a constant learning rate is optimized for the second. Continual learning must answer both, often without knowing which regime it is currently in.
Batch and streaming are endpoints of a spectrum. Full-batch gradient descent uses all examples per step. Mini-batch SGD uses examples per step. Pure online SGD uses one. Everything between is a design choice about how much of the historical distribution to include in each update. A replay buffer, which we turn to in the next section, is the device that lets you move along this spectrum even when data arrives one sample at a time.
The spectrum covers both batch size at a single step and how long data is retained. A method could update on a mini-batch of recent data and still be highly online if that mini-batch is discarded immediately. Another method could update on a single example drawn from a large historical buffer and behave much more like batch training. The relevant quantity is the effective age distribution of the data contributing to each update.
The learning rate as a memory knob
There is a precise sense in which the learning rate controls how much history the estimator remembers. Consider the simplest case: a scalar linear model with zero-mean and independent of . The SGD update is
where:
- : the updated parameter estimate
- : the current parameter estimate
- : the constant learning rate
- : the scalar input at step
- : the observed target at step
- : the prediction error, which drives the update
Here is the current parameter estimate, is the constant learning rate, is the scalar input at step , is the observed target, and is the prediction error that drives the update.
Writing the error as and substituting gives
where:
- : the parameter error after the update,
- : the parameter error before the update,
- : the learning rate
- : the scalar input at step
- : the zero-mean observation noise at step
- : the parameter estimate before the update
- : the parameter estimate after the update
- : the true parameter value
The first term shrinks the existing error, while the second term injects noise. Take expectations over the noise and inputs, assuming the current sample is independent of , , and :
where:
- : the expected parameter error at step
- : the learning rate
- : the variance of the inputs
- : the geometric decay rate of the bias
- : the expected parameter error at step
The bias decays geometrically at rate . A large learning rate forgets old errors quickly. A small one holds onto them. We will return to this in the worked example.
This recursion is the simplest possible model of memory in gradient descent. The current error is a weighted combination of the previous error and a noise term. The weight on the previous error is approximately one minus the learning rate times the input variance. If that weight is close to one, the estimator remembers its old error for a long time. If it is close to zero, the estimator discards its old error almost immediately. In a stationary world, a small weight is good, because the old error was itself caused by noise or by initialization and should be forgotten. In a non-stationary world, the old error may contain information about dynamics that are still partially valid, and forgetting it completely may be wasteful.
There is a second sense in which the learning rate controls memory. The stationary variance of the estimator is proportional to the learning rate. A large learning rate makes the estimator responsive but noisy. A small learning rate makes it precise but slow. The memory knob and the noise knob are the same knob, turned in opposite directions. This is the fundamental tradeoff that reappears in every method in this chapter.
Recursive least squares and the Kalman connection
For linear models there is an exact streaming estimator that avoids gradient descent entirely. Recursive least squares (RLS) maintains a parameter estimate and a covariance matrix :
where:
- : the inverse information matrix after step ; under a matching linear-Gaussian model with normalized observation noise, it is proportional to the posterior covariance of
- : the covariance before the update
- : the input (feature) vector at step
- : the parameter estimate after step
- : the parameter estimate before the update
- : the target at step
- : the prediction residual, which drives the parameter correction
- : the parameter vector being estimated
If you have read Bayesian Filtering and Belief States, this should look familiar: RLS is a Kalman filter for a constant parameter with no process noise. Under a matching linear-Gaussian model, is proportional to the posterior covariance of , and it shrinks as evidence accumulates. With persistent excitation in every parameter direction, approaches zero and the gain becomes arbitrarily small. Plain RLS then adapts increasingly slowly to a change; directions that are not sufficiently excited need not collapse.
The intuition is that RLS is not merely averaging recent samples. It is maintaining a full second-order description of what it knows. When data is plentiful and the model is confident, the covariance becomes small, so the update gain becomes small. When data is scarce or the input directions are poorly explored, the covariance remains large, so the estimator is willing to move. This is exactly the behavior a learner should have in a stationary world. It is exactly the wrong behavior in a world that changes, because the estimator becomes most confident precisely when it has seen the most data, which may be the data from before the change.
The fix is to add process noise, which produces a forgetting factor :
where:
- : the forgetting factor, with ; smaller down-weights older data more aggressively and inflates the covariance to preserve plasticity
- : the covariance after and before the update
- : the input vector at step
With , older observations are exponentially down-weighted with time constant . This is the cleanest formal statement of the memory-versus-plasticity tradeoff: the forgetting factor is a literal discount on history. A value of means the effective window is roughly 100 samples; means roughly 1000.
The forgetting factor has a statistical interpretation: it inflates the covariance carried from the previous step, expressing a belief that old information is becoming less relevant. In a Kalman interpretation this resembles process noise, although exponential forgetting generally implies a state-dependent covariance inflation rather than a fixed random-walk covariance. In a world model, the drifting quantity might be a physical coefficient, a reward function, or an entire latent dynamics model.
Update-to-data ratio
A quantity that matters in every model-based agent is the update-to-data ratio, sometimes called the replay ratio: how many gradient steps the model takes per environment step collected. In offline training the ratio is enormous (many epochs over a fixed dataset). In a purely streaming loop it is one. In practice, agents such as Dreamer and MBPO sit somewhere in between, and the choice has real consequences. A high ratio extracts more information per real interaction, which is the entire appeal of learning a model in the first place. But a high ratio also means the model is repeatedly optimized against a fixed, possibly stale dataset, so it overfits to whatever the last batch of data happened to contain. Modern practice typically sets an explicit update budget and monitors both open-loop and closed-loop metrics against it.
The update-to-data ratio is one of the few quantities in model-based learning that directly connects computational budget to statistical behavior. If the ratio is one, the model sees each transition exactly once and then moves on. If the ratio is large, the model may see the same transition many times, which can be useful when real interaction is expensive but dangerous when the transition is no longer representative. A high ratio also changes the effective learning rate schedule: many small updates on the same data can approximate a larger update, and many updates on stale data can drive the model to memorize idiosyncrasies of the buffer.
Assumptions that quietly break
The streaming update above assumes the data are drawn from a stationary distribution and that consecutive samples are independent. Neither assumption holds in a world-modeling loop.
- Stationarity fails whenever the environment changes, the agent's policy changes, or the agent's own learning changes what it does.
- Independence fails because consecutive transitions in a trajectory are highly correlated. A robot that has just turned left is likely to turn left again.
Correlated samples make the gradient an average over a stretch of trajectory rather than over the distribution of interest, which biases updates and inflates effective variance. This is one reason practical systems shuffle, buffer, and batch rather than truly updating one sample at a time. It is also why the word "online" in modern deep RL usually means "interleaved with data collection," not "one gradient step per sample with no memory."
There is a further assumption that is often invisible: the loss being minimized is assumed to be the right objective for the deployment distribution. In a stationary supervised problem, minimizing average loss on the training distribution is a reasonable proxy for minimizing loss on the test distribution. In a world model, the training distribution is generated by the agent's own behavior, and the test distribution is whatever distribution the agent will encounter in the future. Those two distributions can diverge dramatically. Minimizing loss on yesterday's data may not reduce loss on tomorrow's data if the policy has moved on.