Chapter 5
Making the flow-matching action head a scorable stochastic policy
5 sections · about 6 minutes
5.1 Why the deterministic sampler is a problem
A policy-gradient method needs and its gradient with respect to the parameters. The Euler ODE sampler in infer_action maps an initial noise to a chunk through a deterministic, invertible-in-principle but practically intractable map. The density of exists but computing it would require the Jacobian determinant of 20 stacked transformer evaluations, which is out of the question.
The standard solution, introduced for diffusion policies by DPPO and adapted to flow matching by ReinFlow, πRL (Flow-SDE), and Flow-GRPO, is to stop treating the denoising process as a black box. Instead, each denoising step is treated as a transition in a small inner MDP whose transition distribution is Gaussian, and the log-probability of the final action is the sum of the per-step Gaussian log-densities. To make the transitions Gaussian you have to inject noise at each step, which turns the ODE into an SDE. The crucial property is that you can do this while keeping the marginal distribution at each noise level the same as the ODE's, so the model's training objective is not violated.
5.2 The Flow-SDE step in Fast-WAM's variables
Fast-WAM's forward process is , and the network predicts . From these two relations the score function (the gradient of the log marginal density at noise level σ) is
(Appendix A derives this and checks it against the form πRL states.) The probability-flow ODE can be converted into a family of SDEs
that all share the same marginals , for any non-negative noise function (this is the reverse-SDE construction of Song et al., 2021). Both πRL and Flow-GRPO make the specific choice
with a single scalar controlling the overall noise level. Substituting the score, the drift coefficient simplifies to . Discretising with Fast-WAM's Euler scheme and step (negative, so time runs from noise to data) gives the update the rollout worker will actually execute:
This is, up to notation, exactly the update printed in Flow-GRPO and πRL (, with their equal to Fast-WAM's and their equal to ).
Two things to notice. With the update collapses exactly to the existing deterministic step , which is a useful unit test (Chapter 13). And diverges as , so the very first step (where ) must never be a stochastic one; the mixed sampler in the next section guarantees this, and a defensive clamp of costs nothing. A constant is mathematically just as valid and avoids the divergence, but it is not what the cited papers use, so treat it as an untested variant.
The log-probability of the whole chunk is then
summed over all 32×7 dimensions, with the chain stored from the rollout. Note that depends on the parameters through , while std_k does not, so the gradient flows through the mean only.
5.3 Three practical choices, following πRL and Flow-GRPO
Fewer denoising steps during RL. Each stochastic step adds a term to the log-probability, and each term requires a forward (and, in the learner, backward) pass through the action expert. πRL discretises into uniform steps and ablates ; suffers from ODE-to-SDE discretisation error, larger costs more, and is the setting its main results use. Flow-GRPO collects training rollouts with 10 steps and evaluates with the original 40 ("denoising reduction"). Fast-WAM's default is 20 steps with shift 1.0, and the README reports that shifts from 1.0 to 3.0 perform similarly, which suggests the sampler is not very sensitive to the schedule. Use for RL rollouts and training (a compromise between πRL's 4 and Flow-GRPO's 10 that keeps Fast-WAM's uniform σ grid at multiples of 0.125), and verify before you start that the pretrained checkpoint's deterministic success rate at is within a point of its rate at . Always evaluate at .
Mixed ODE–SDE. πRL's mixed sampler does not make every step stochastic. For each chunk it randomly samples one denoising index , runs the SDE step there, and runs every other step as the deterministic ODE. The policy's log-probability then has a single Gaussian term, which keeps the learner cheap and the variance low, and because is never the first index the divergence of never arises. This is the grounded default. A variant worth testing, but not from the literature, is to make the last K_sde (say 4) steps stochastic, which concentrates exploration where the action is taking shape and gives the learner more log-probability terms per sample at proportionally higher cost.
Noise scale . This is the exploration knob. πRL ablates and finds best: is unstable (a much higher PPO clip fraction), and degrades the rollout policy too much. Flow-GRPO uses for image generation, which is a different domain. Since Fast-WAM's actions are min/max normalised to about , the same scale as π₀'s, start at . If the policy's success rate collapses in the first iteration, is too high; if advantages are all zero because every rollout does the same thing, is too low.
5.4 What to store from each rollout
For each macro-step the worker must save enough to recompute the log-probability exactly in the learner:
- the state (image, proprio, task id; the context is looked up by task id);
- the full denoising chain (
[K+1, 32, 7]) together with the index (or indices) of the stochastic step(s); - the old log-probability per stochastic step (one value with πRL's single-step sampler,
K_sdevalues with the variant), computed by the worker at sampling time; - the reward inputs (Chapter 6) and the done flag.
The chain is small (9 × 32 × 7 floats). The images are the bulk of the storage.
5.5 The alternative for a cheap first baseline: DSRL
If you want to validate the environment plumbing and reward computation before touching the model's gradients, DSRL (Wagenmaker et al., 2025) offers a way to do RL on a frozen flow policy. It keeps the sampler exactly as it is and instead trains a small actor-critic (SAC) whose "action" is the initial noise ; the frozen Fast-WAM turns that noise into a chunk. Because nothing inside Fast-WAM is trained, the compiled inference path can be used unchanged. It will not get you WAM-RL's world-model benefits, but it is a few hundred lines and a strong sanity check.