Six Examples, Two at a Time

OptimizersMedium+20 XP+20

Six Examples, Two at a Time

A training recipe was tuned for batches of 6 examples with learning rate η=0.1\eta = 0.1η=0.1, but the GPU only has room for 2 examples at once. So the engineer uses gradient accumulation. Each batch goes through as three micro-batches of 2. For each micro-batch, the gradient is computed (the mean of its two examples' gradients) and added into an accumulator. Only after the third micro-batch is the accumulator used to take one step. Then the accumulator is reset to zero and the next batch begins.

The goal is for every step to be exactly the step the recipe's batch of 6 would have taken, where a batch's gradient is the mean of its examples' gradients.

The model has a single weight, y^=wx\hat y = w xy^​=wx, and each example's loss is (wx−y)2(w x - y)^2(wx−y)2, whose gradient is

ddw(wx−y)2=2x (wx−y)\frac{d}{dw}(wx - y)^2 = 2x\,(wx - y)dwd​(wx−y)2=2x(wx−y)

The whole dataset is one batch, split into micro-batches like this:

micro-batchxxxyyy
A1112.52.52.5
A2223.53.53.5
B−1-1−1−2-2−2
B3336.56.56.5
C0.50.50.51.51.51.5
C2224.54.54.5

Training starts at w0=0.5w_0 = 0.5w0​=0.5. Two full passes over the data are run, so the weight is updated twice.

What is the weight w2w_2w2​ after the second update? Round your answer to 3 decimal places.

Hints

Solve it to unlock the solution

Once you get it right, the reasoning behind the answer shows up here.