14/30
Part 4 of 6 · Positions, targets, shapes and twinsLearn and do
One repeated token shows whether order gets in
A model can also ignore position entirely, and still train.
def position_test(model: nn.Module) -> None:
"""Prints how much positions 1 and 4 differ, at the logits and at block 0."""
seen = {}
def keep(module: nn.Module, inputs: tuple, out: torch.Tensor) -> None:
# what block 0 receives
seen["x"] = inputs[0]
hook = model.blocks[0].register_forward_hook(keep)
try:
with torch.no_grad():
logits = model(torch.full((1, 6), 3))[0][0]
finally:
hook.remove()
gap = lambda rows: (rows[1] - rows[4]).abs().max().item()
print("logits, position 1 vs 4: ", gap(logits))
print("block 0 input, position 1 vs 4:", gap(seen["x"][0]))
A model that can't tell positions apart still trains. Causal attention leaks some order, and the tokens carry a lot on their own. So use the sharpest input there is: one token, repeated. Every position then sees copies of the same vector, and only the positions can make the outputs differ.
Zero the position table, and feed one token six times. How different is block 0's input at positions 1 and 4?
Pick an answer above to see the rest