19/30
Part 4 of 6 · Positions, targets, shapes and twinsLearn and do

Swap the twin into every block

The twin also narrows down a failing model.

for block in model.blocks:
    block.attn.forward = lambda x, a=block.attn: twin(a, x)

When a whole-model test fails, swap the twin in for every block and run the test again:

The failing test, rerun with the twin in every blockMeans
passes nowthe bug is inside your attention
still failsthe bug is somewhere else

With the mask removed, the causality test fails, and it passes again once the twin is in.

Assigning to block.attn.forward replaces that one module's forward, so block.attn(x) now runs the twin.

Predict

Leave out the default a=block.attn in the lambda. Which block's attention would every lambda call?

Pick an answer above to see the rest