CS 285 HW1: Action Chunking and Flow Policies (UC Berkeley)

The demos go round the T on the left half the time and on the right half the time. A squared-error policy aims at the average, straight into the T. A flow policy samples one whole way round and keeps it for K steps.

A lesson with a workbook. Each chapter explains one part of the homework, then gives you exercises on our own toy data.

Press Play with MSE, then with Flow. Drag K to 1 and play the flow policy again. Switch on the bump and try a long chunk. Then we build each part.

You need imitation learning (cloning, the averaging trap) and ideally CS 224R HW1 (flow matching in one dimension, DAgger). The exercises run JavaScript in your browser.

Based on Homework 1 of UC Berkeley CS 185/285, Deep Reinforcement Learning, Sergey Levine (Spring 2026): the handout (PDF) and Lecture 3 (PDF). The words, the toy and its numbers are our own.

Push the T home

8

Our toy, not the course's Push-T: the finger moves at most 0.3 per step, the T collides as a disc, and only its position counts. Each policy is the perfect version for our two-way expert (Chapters 2 and 4). Faint purple and yellow are the two demo chunks MSE averages.

Workbook progress
0 / 23 exercises (0%)
0
Day streak
Best: 0
23 exercises in five kinds: Derive, Trace, Build, Debug, Design. Build exercises run as JavaScript in your browser; the matching Python is shown beside them.

Chapter 0

The Map: What You Build

Follow one observation through the policy to a chunk of actions

Homework 1 trains two cloned policies for Push-T: a finger pushes a T-shaped block into a goal zone. The observation ot is 5 numbers: the T's x, y and angle, and the finger's x and y. The action is 2 numbers: the point the finger moves toward.

Both policies output an action chunk: the next K actions at once, a K by 2 block. The first policy fits chunks with squared error. The second is a flow policy: it turns random noise into one chunk in n small steps. The plain cloning ideas are in Imitation Learning. This page adds the chunk.

Trace one query

Pick a policy and a chunk length. The strip at the bottom is a 60-step episode; each tick is one call to the network.

8

Shapes from the handout. The episode length 60 and the n = 10 flow steps are our choices; the handout leaves K and n to you.

Worked number: with K = 8 the network outputs 2 × 8 = 16 numbers. A 60-step episode calls it ⌈60 / 8⌉ = 8 times. The flow policy runs its network n times per call, so with n = 10 that is 80 passes.

PartFile and classChapter
Chunks from demosdata.py builds (o, chunk) pairs for you; know their shape1
MSE policymodel.py: MSEPolicy, an MLP with 2K outputs2
Training looptrain.py: batches, Adam, the loss2
Flow trainingmodel.py: FlowMatchingPolicy, the loss3
Flow samplingFlowMatchingPolicy: n Euler steps4
Evaluationevaluation.py: evaluate_policy, called during training5

The failure to expect: a loss that falls while the rollouts stay bad. The loss only scores chunks against demos. Only rollouts show whether the T gets home.

The road

  1. Chunks, run open loop: K steps without looking. The hero's K and bump.
  2. The MSE chunk policy: the average of two ways round. The hero's MSE.
  3. Flow training on chunks: the path, the velocity and τ.
  4. Sampling a chunk: n Euler steps commit to one side. The hero's Flow.
  5. Evaluate by rollouts: a success rate and its error bar.
  6. Field guide: terms, numbers, the core code, where next.
K = 4. What does one call of the MSE policy return?

Workbook

Exercise 0.1: Count the outputs Derive
A chunk policy for our 2-number actions uses K = 10. How many numbers does the MSE network's last layer output?
numbers
Show derivation
one action = 2 numbers (target x, target y)
one chunk = K actions = 10 × 2 = 20 numbers
The code reshapes these 20 numbers into a 10 by 2 chunk. Chapter 2 shows how that reshape can go wrong.
Exercise 0.2: The flow network's inputs Trace
The flow policy's network is called once per Euler step. What goes in?
Exercise 0.3: Order the work Design
Tap the chips in the order you should build them.
?
→
?
→
?
→
?
→
?
write FlowMatchingPolicy call the evaluation during training compare MSE and flow by rollouts write MSEPolicy write the training loop

Chapter 1

Action Chunks, Run Open Loop

Ask once, then play K actions without looking

A chunk policy looks at the table once, then plays K target points in a row. It does not look again until the chunk ends. Playing actions without looking is open loop.

Call the observation at step t ot and the action at step t at. The chunk is a list of K actions that starts at step t.

At = ( at, at+1, …, at+K−1 ),   next query at ot+K
Say it aloud

A-t is the list a-t, a-t-plus-one, up to a-t-plus-K-minus-one. The next query looks at o-t-plus-K.

At
A-t the chunk the policy returns at step t: a K by 2 block of target points.
at
a-t the first target point, played at step t.
at+K−1
a-t-plus-K-minus-one the last of the K points.
ot+K
o-t-plus-K the observation the policy reads next, K steps later.
In plain words

At step t, read o-t and get K target points. Play a-t, then a-t-plus-one, and so on. After K steps, read the table again.

With numbers

K = 8 and a 60-step episode: queries at steps 0, 8, 16, …, 56. That is ⌈60 / 8⌉ = 8 queries, and the last chunk plays only 4 of its 8 points.

Bump the T mid-chunk

The finger plays the expert's chunks, which go round the nearer side. A bump moves the T before step 20. Change K and play; the strip marks each query and the steps played blind.

8

Illustrative toy: the bump moves the T 0.7 sideways before step 20 runs. Step counts come from our simulator.

Chunks buy two things. The finger keeps one plan for K steps, so it does not flip between plans. The network runs less often, which leaves time for the n passes of a flow policy. The price is reaction time: the policy ignores a bump until the next query.

The data needs the same shape. Each demo step t becomes one training pair: ot and the next K actions. Near the end of a demo there are fewer than K actions left. A common fix repeats the last action.

The trap: padding a chunk with zeros

symptom
Near the end of each episode the finger dashes to one corner of the table.
see it
Print the last training chunk of a demo. Its tail reads (0, 0).
fix
An action is a target point, so (0, 0) means "go to the corner". Pad with the last real action, which means "stay".
K = 8. The T is bumped just before step 21 runs. When can the policy first respond?

Workbook

Exercise 1.1: The query schedule Derive
An episode has 50 steps and K = 6. How many times is the policy queried?
queries
Show derivation
queries at steps 0, 6, 12, 18, 24, 30, 36, 42, 48
⌈50 / 6⌉ = ⌈8.33⌉ = 9
The last chunk plays only 50 − 48 = 2 of its 6 points.
Exercise 1.2: Trace a K = 4 rollout Trace
K = 4. The T is bumped just before step 9 runs. Which steps run blind, and which query first sees the bump?
Exercise 1.3: Cut a demo into chunks Build
Return the training chunk that starts at step t, flattened as [x0, y0, x1, y1, …].
  1. actions is a list of [x, y] target points, one per demo step.
  2. Take K points from index t. Past the end, repeat the last point.
  3. Return 2K numbers, x then y for each point.
Show solution
javascriptfunction chunkAt(actions, t, K) {
  const out = [];
  for (let k = 0; k < K; k++) {
    const a = actions[Math.min(t + k, actions.length - 1)];
    out.push(a[0], a[1]);
  }
  return out;
}
pythonidx = np.minimum(np.arange(t, t + K), len(actions) - 1)
chunk = actions[idx]            # shape [K, 2]
Exercise 1.4: K for a moving goal Design
In a variant, the goal zone jumps to a new place every 5 steps. Demos show sharp turns. Which K suits it best?

Chapter 2

The MSE Chunk Policy and the Averaging Wall

Fit whole chunks with squared error, then see where the best fit points

MSEPolicy is an MLP. It reads ot and outputs 2K numbers, which the code reshapes to a K by 2 chunk. Call the batch size B, the expert chunk of pair j A(j) and the network's chunk πθ(o(j)).

LMSE(θ) = 1/B Σj ‖ A(j) − πθ(o(j)) ‖2
Say it aloud

L-M-S-E of theta equals one over B times the sum over j of the squared distance between A-j and pi-theta of o-j.

LMSE(θ)
L-M-S-E of theta the loss for the network weights θ.
1/B
one over B divide by the number of pairs in the batch.
Σj
the sum over j one term per pair, j from 1 to B.
‖ … ‖2
the squared distance square each of the 2K differences between the two chunks and add them.
In plain words

For each pair j, subtract the network's chunk from the expert chunk A-j. Square all 2K differences and add them. Average that over the B pairs.

With numbers

With made-up numbers: B = 2, K = 2. Pair 1 misses by (0.1, 0) and (0, 0.2): 0.01 + 0.04 = 0.05. Pair 2 misses by (0.3, 0) and (0, 0): 0.09. L = (0.05 + 0.09) / 2 = 0.07.

Now the wall. At the start state a share w of our demos goes round the T on the left. The rest go round on the right. Squared error has one best answer per state: the average.

Â(o) = w AL + (1 − w) AR
Say it aloud

A-hat of o equals w times A-L, plus one minus w times A-R.

Â(o)
A-hat of o the chunk with the lowest squared error at observation o.
w
w the share of demos at o that go left, from 0 to 1.
AL
A-L the left demo chunk.
AR
A-R the right demo chunk.
In plain words

Weight each target point of A-L by w and each of A-R by one minus w. Add them, point by point. No other chunk has a lower squared error.

With numbers

In our toy, point 4 of A-L is (3.24, 5.72) and of A-R is (3.24, 4.28). With w = 0.5 the best fit is (3.24, 5.00): 0.94 from the T's centre. The finger touches the T within 1.05, so it pushes the T straight back.

Average two ways round

Purple is the left demo chunk, yellow the right. Blue is the squared-error best fit. A red ring marks a target point inside the T's reach. Move the left share.

0.50

Our toy with K = 8: each demo point moves 0.3 toward its side. The squared errors are exact for these two demos.

Why the average wins: the summed error of a chunk c is w ‖AL − c‖2 + (1 − w) ‖AR − c‖2. At the average it is w(1 − w) times the gap squared. At AL it is (1 − w) times the gap squared, larger for any w below 1. The proof for one number is in CS 224R HW1, Chapter 3.

The trap: two layouts for one chunk

symptom
The loss falls, but the finger jumps between far-apart points.
see it
Feed one training observation, reshape the output, and plot it beside the demo chunk.
fix
Training flattens the target as x0, y0, x1, y1. Unflatten with reshape(K, 2), never reshape(2, K).T.
At one state, 90% of demos go left. Where does the squared-error chunk point?

Workbook

Exercise 2.1: The best fit for a 75% split Derive
Point 4 of the left chunk is (3.24, 5.72) and of the right chunk is (3.24, 4.28). Three demos in four go left. What is the y of the squared-error best fit?
y
Show derivation
y = 0.75 × 5.72 + 0.25 × 4.28
= 4.29 + 1.07 = 5.36
The point is (3.24, 5.36), 1.007 from the T's centre at (2.3, 5.0). That is still inside the 1.05 reach, so this point still pushes the T.
Exercise 2.2: The error of the average Derive
Same point and w = 0.75. The two demo points differ by 1.44 in y. What is the expected squared error of the best fit at this one point? Give 3 decimals.
error
Show derivation
gap squared = 1.44² = 2.0736
at the average: w(1 − w) × 2.0736 = 0.1875 × 2.0736 = 0.389
at the left point: (1 − w) × 2.0736 = 0.518
The loss prefers the point that pushes the T.
Exercise 2.3: Score a flat output against a chunk Build
The network gives 2K numbers. Score them against a K by 2 demo chunk.
  1. flat holds x0, y0, x1, y1, …
  2. chunk is [[x, y], …] with K rows.
  3. Return the sum of the 2K squared differences.
Show solution
javascriptfunction chunkSqErr(flat, chunk) {
  let s = 0;
  chunk.forEach((p, k) => {
    s += (flat[2 * k] - p[0]) ** 2 + (flat[2 * k + 1] - p[1]) ** 2;
  });
  return s;
}
pythonerr = ((flat.reshape(K, 2) - chunk) ** 2).sum()
Exercise 2.4: The scrambled chunk Debug
A neighbouring policy trains on targets flattened with A.reshape(-1). Its loss falls, but the finger jumps around. Click the buggy line.
def act(net, obs, K):
    out = net(obs)               # 2K numbers
    chunk = out.reshape(2, K).T  # K rows of (x, y)
    return chunk
Show why
Line 3 reads the first K numbers as x values. The network learned x0, y0, x1, y1. Use out.reshape(K, 2).

Chapter 3

Flow Training on Whole Chunks

Draw a straight path from a noise chunk to a demo chunk, and teach its velocity

FlowMatchingPolicy keeps the MLP and changes what it predicts. The idea in one dimension is in CS 224R HW1, Chapter 4. Here every quantity is a whole K by 2 chunk.

Draw a noise chunk A0: 2K random numbers from a standard normal, the same shape as the demo chunk A. Draw one flow time τ between 0 and 1 for the pair.

Aτ = τ A + (1 − τ) A0
Say it aloud

A-tau equals tau times A, plus one minus tau times A-zero.

Aτ
A-tau the chunk at time τ on the path: the network's input.
τ
tau the flow time, one number per pair, drawn evenly from 0 to 1.
A
A the demo chunk: the end of the path.
A0
A-zero the noise chunk: the start of the path.
In plain words

Move every one of the 2K noise numbers in A-zero the fraction tau of the way to its partner in A. All points share the same tau.

With numbers

Point 1 of a left demo, as an offset from the finger: A = (−0.24, 0.18). Noise A-zero = (0.5, −1.0), tau = 0.4. Then A-tau = (−0.096 + 0.3, 0.072 − 0.6) = (0.204, −0.528).

Slide a chunk along its path

Grey rings are the noise chunk, coloured dots the demo chunk. Blue dots sit at time τ; teal arrows show each point's target velocity. Move τ and pick a demo.

0.40

Our toy with K = 8, offsets from the finger in table units. We draw arrows at 0.3 of their length. Point 1's first noise draw is fixed to match the worked number.

The target is the velocity of the straight path, A − A0: the same at every τ. Call the network vθ.

LFM(θ) = 1/B Σj ‖ vθ(o, Aτ, τ) − (A − A0) ‖2
Say it aloud

L-F-M of theta equals one over B times the sum over j of the squared distance between v-theta of o, A-tau, tau and A minus A-zero.

LFM(θ)
L-F-M of theta the flow matching loss, averaged over the B pairs of a batch.
vθ(o, Aτ, τ)
v-theta of o, A-tau and tau the network's velocity: a K by 2 chunk.
A − A0
A minus A-zero the target velocity: the whole step from noise to demo.
In plain words

Give the network the observation o, the mixed chunk A-tau and tau. Score its velocity against A minus A-zero with squared error, summed over the 2K numbers.

With numbers

Point 1 again: target (−0.24 − 0.5, 0.18 + 1.0) = (−0.74, 1.18). If the network says (−0.6, 1.0), this point adds 0.14² + 0.18² = 0.052.

Why τ must go in: one point can sit on many paths. In one dimension take the point 0.6 and the demo 1.0. At τ = 0.2 it came from noise 0.5, so the velocity is 0.5. At τ = 0.6 it came from noise 0, so the velocity is 1.0. Without τ the network must give one answer to both.

The trap: a network that cannot see τ

symptom
The loss stalls well above zero. Samples land short of both demos, near their average.
see it
Print the network's input size. It should be 5 + 2K + 1.
fix
Concatenate τ to the input. Draw one τ per pair and broadcast it over the chunk.
A pair has τ = 0.9. What is the target velocity for point 1?

Workbook

Exercise 3.1: One number on the path Derive
The y offset of a demo point is A = 0.36. Its noise is A0 = −0.8 and τ = 0.75. Compute Aτ.
offset
Show derivation
τ A = 0.75 × 0.36 = 0.27
(1 − τ) A0 = 0.25 × (−0.8) = −0.20
Aτ = 0.07
The target velocity is 0.36 − (−0.8) = 1.16. From 0.07, the remaining 0.25 of time at 1.16 reaches 0.36.
Exercise 3.2: The flow loss for one chunk Build
A neighbouring version on flat arrays. The network is passed in as a function, so the tests are fixed.
  1. Build x = τ × A + (1 − τ) × noise, number by number.
  2. Get the velocity: v = net(x, tau).
  3. Return the sum of (vi − (Ai − noisei))².
Show solution
javascriptfunction fmLoss(A, noise, tau, net) {
  const x = A.map((a, i) => tau * a + (1 - tau) * noise[i]);
  const v = net(x, tau);
  return v.reduce((s, vi, i) => s + (vi - (A[i] - noise[i])) ** 2, 0);
}
pythonx = tau * A + (1 - tau) * noise
loss = ((net(x, tau) - (A - noise)) ** 2).sum()
Exercise 3.3: The blind velocity Debug
A neighbouring linear velocity model trains, but its samples bunch near the average of the demos. Click the buggy line.
def velocity(W, b, obs, x, tau):
    h = np.concatenate([obs, x])
    return W @ h + b
Show why
Line 2 drops τ. The same x needs different velocities at different times, so the model learns their average. Use np.concatenate([obs, x, [tau]]).
Exercise 3.4: The shape of τ Trace
A batch of chunks has shape [B, K, 2]. You draw tau = torch.rand(B). What shape must τ have before it multiplies the chunks?

Chapter 4

Sampling a Chunk in n Euler Steps

Start from noise and follow the velocity until the whole chunk picks a side

At run time there is no demo. The policy draws a fresh noise chunk and follows vθ from τ = 0 to τ = 1 in n equal steps. This is Euler integration.

Aτ+1/n = Aτ + 1/n · vθ(o, Aτ, τ)
Say it aloud

A at tau plus one over n equals A-tau, plus one over n times v-theta of o, A-tau and tau.

Aτ+1/n
A at tau plus one over n the chunk after one step.
Aτ
A-tau the chunk now. At τ = 0 it is fresh noise.
1/n
one over n the step size: 0.1 for n = 10.
vθ(o, Aτ, τ)
v-theta of o, A-tau and tau the velocity the network predicts here and now.
In plain words

Ask the network for the velocity at the current chunk A-tau and time tau. Move one n-th of it, and add one n-th to tau. After n steps, play the chunk.

With numbers

One number of the chunk, exact field for two demos at +1.44 and −1.44, half each, n = 2, start 0.3. At tau = 0 the velocity is −0.30, so the number moves to 0.15. At tau = 0.5 it is 0.87, and the number ends at 0.59: between the demos.

Sample 20 chunks

Each line is one sampled chunk of 8 target points from the finger. Purple went left, yellow right, red stayed in the middle and pushes the T. Pick n and sample.

The velocity is the exact best field for our two demo chunks at the start state, not a trained network. A chunk counts as middle if its last point is within 0.72 of the centre line.

Try n = 1. Every sample lands on the average chunk: the MSE answer. At τ = 0 the noise says nothing about the side, so the best velocity points at the average. With more steps the whole chunk moves together and commits to one side. All 16 numbers pick the same side, because the field uses the whole chunk.

The cost is time. A rollout makes n × ⌈T / K⌉ network passes. With T = 60, K = 8 and n = 10 that is 80 passes. Without chunks, K = 1, it is 600.

The trap: a flow time that never moves

symptom
The flow policy behaves like the MSE policy and pushes the T straight back.
see it
Log τ inside the sampling loop. It should read 0, 1/n, 2/n, …
fix
Set τ = i / n at step i. A τ stuck at 0 aims every step at the average.
With a perfect network and n = 1, where does every sampled chunk land?

Workbook

Exercise 4.1: Four Euler steps by hand Trace
A made-up field: v(x, τ) = 1 − x. Start at x = 0 and take n = 4 steps. Where does x end? Give 3 decimals.
x
Show derivation
step 1: x = 0 + (1 − 0)/4 = 0.25
step 2: x = 0.25 + 0.75/4 = 0.4375
step 3: x = 0.4375 + 0.5625/4 = 0.578
step 4: x = 0.578 + 0.422/4 = 0.684
This field is not straight, so 4 steps fall short of 1. A learned field is not perfectly straight either.
Exercise 4.2: Sample a chunk Build
The noise chunk comes in flat, so the tests are fixed.
  1. Copy x0 into x.
  2. For i = 0 to n − 1: set tau = i / n, get v = field(x, tau), add v / n to x.
  3. Return x, still flat.
Show solution
javascriptfunction sampleChunk(x0, n, field) {
  let x = x0.slice();
  for (let i = 0; i < n; i++) {
    const v = field(x, i / n);
    x = x.map((xi, k) => xi + v[k] / n);
  }
  return x;
}
pythonx = x0.copy()
for i in range(n):
    x = x + field(x, i / n) / n
Exercise 4.3: Steps in a time budget Design
One network pass takes 3 ms. A new chunk must be ready within one control step of 50 ms. What is the largest n you can use?
steps
Show derivation
n × 3 ms ≤ 50 ms
n ≤ 16.7, so n = 16
A longer chunk does not change this budget, but it spreads the passes over more steps of motion.
Exercise 4.4: The stuck clock Debug
This neighbouring sampler always returns the average chunk. Click the buggy line.
x = rng.standard_normal(2 * K)
for i in range(n):
    tau = 0.0
    x = x + field(obs, x, tau) / n
return x.reshape(K, 2)
Show why
Line 3 keeps τ at 0. At τ = 0 the best velocity points at the average, so every step heads there. Use tau = i / n.

Chapter 5

Evaluate by Rollouts: MSE against Flow

Run many episodes, count the wins, and put an error bar on the count

evaluate_policy runs the policy in the environment and logs its reward. You call it every few thousand training steps. In our toy an episode is a success if the T reaches the goal zone within 60 steps.

A success rate from N episodes is a noisy estimate. Call the number of successes k and the rate p̂ = k / N.

SE = √( p̂(1 − p̂) / N )
Say it aloud

S-E equals the square root of p-hat times one minus p-hat, over N.

SE
S-E the standard error: the typical size of the gap between p-hat and the true rate.
√( p̂(1 − p̂) / N )
root of p-hat, one minus p-hat, over N p-hat is the success share, from 0 to 1; N is the number of episodes.
In plain words

Multiply the success share p-hat by the failure share. Divide by the number of episodes N. Take the square root.

With numbers

With made-up counts: flow wins 41 of 50, so p-hat = 0.82 and SE = √(0.82 × 0.18 / 50) = 0.054. MSE wins 22 of 50: 0.44 and 0.070. The gap 0.38 is 4.3 times its own error of 0.089.

Run 50 episodes each

Bars are success rates with one standard error. Dots are episodes: green reached the goal, red pushed the T off, grey ran out of time. Change K or add the bump, then run.

8

Illustrative: rates from our simulator, with the perfect MSE policy and the exact-field flow policy at n = 10. Both policies get the same 50 starts.

Read the toy's three regimes. Flow with K = 1 redraws its side every step and pushes the T off now and then. Flow with K of 8 or more commits and almost always wins. With the bump on, K = 16 plays 12 steps blind and runs out of time. MSE gets worse as K grows: it commits to the average for longer.

The trap: too few episodes

symptom
The reward curve jumps up and down between checkpoints.
see it
Compute SE. With N = 10 and p̂ = 0.5 it is 0.16, so a jump of 0.2 means little.
fix
Use more episodes, the same starts for both policies, and compare curves, not single checkpoints.
Flow wins 45 of 50 and MSE 40 of 50 on the same starts. What can you say?

Workbook

Exercise 5.1: An error bar Trace
A policy wins 9 of 20 episodes. What is the standard error of its success rate? Give 3 decimals.
SE
Show derivation
p̂ = 9 / 20 = 0.45
SE = √(0.45 × 0.55 / 20) = √0.01238 = 0.111
Exercise 5.2: How many episodes? Derive
You want SE at most 0.05, and the rate may be near 0.5, where SE is largest. How many episodes N do you need?
episodes
Show derivation
√(0.25 / N) ≤ 0.05
0.25 / N ≤ 0.0025, so N ≥ 100
Exercise 5.3: Rate and error Build
Return the success rate and its standard error.
  1. outcomes is a list of 1 (success) and 0 (failure).
  2. p = the mean; se = √(p(1 − p) / N).
  3. Return [p, se].
Show solution
javascriptfunction successRate(outcomes) {
  const N = outcomes.length;
  const p = outcomes.reduce((s, o) => s + o, 0) / N;
  return [p, Math.sqrt(p * (1 - p) / N)];
}
pythonp = outcomes.mean()
se = np.sqrt(p * (1 - p) / len(outcomes))
Exercise 5.4: A fair comparison Design
You want to show that the flow policy beats the MSE policy. Which plan is fair?

Chapter 6

The Field Guide

Keep the terms, the numbers, the core code and the next steps in one place

A chunk policy reads the table once and plays K targets. Squared error fits the average chunk, which goes into the T when the demos split. A flow policy turns noise into one chunk in n Euler steps, and the chunk keeps that choice for K steps. Rollouts with error bars decide which policy is better.

TermMeaningToy number
chunk AtK target points from one query, played open loopK = 8: 16 numbers
queries⌈T / K⌉ network calls per episodeT = 60, K = 8: 8
blind stepssteps between a surprise and the next queryup to K − 1 = 7
averaging wallthe squared-error fit is w AL + (1 − w) ARpoint 4: 0.94 from the T, reach 1.05
flow pathAτ = τ A + (1 − τ) A0, target A − A0one τ per chunk
Euler steps nnetwork passes per sampled chunkn = 1 gives the average
passes per episoden × ⌈T / K⌉80 at K = 8, 600 at K = 1
standard error√(p̂(1 − p̂) / N)41 of 50: 0.054

What you can build now

The core, on our toy

javascript// one query of a flow chunk policy, then K steps open loop
function flowQuery(obs, K, n, field) {
  let x = Array.from({ length: 2 * K }, randn);   // noise chunk A_0
  for (let i = 0; i < n; i++) {
    const v = field(obs, x, i / n);               // v_theta(o, A_tau, tau)
    x = x.map((xi, k) => xi + v[k] / n);         // Euler step
  }
  return x;                                       // [x0, y0, x1, y1, ...]
}
function rollout(env, policy, K, T) {
  let obs = env.reset(), chunk = [];
  for (let t = 0; t < T; t++) {
    if (t % K === 0) chunk = policy(obs, K);     // query every K steps
    const k = t % K;
    obs = env.step([chunk[2 * k], chunk[2 * k + 1]]);
    if (env.success()) return 1;
  }
  return 0;
}

Where next

This workbook follows UC Berkeley CS 185/285, Deep Reinforcement Learning, Sergey Levine (Spring 2026). See the course page, the Homework 1 handout and Lecture 3 on models for imitation. The handout cites Diffusion Policy by Chi et al.

The takeaway. When demos split, a chunk policy must sample one way round and keep it. Squared error cannot sample; a flow policy can, if τ goes in and the sampler takes enough steps.
Teach it back with the Teach pill, or go back to the T on the table and play K = 1 against K = 8.
CS 285 HW1: Action Chunking and Flow Policies (UC Berkeley)
The course page · Homework 1 handout · Lecture 3 slides · Back to Gleams