11/30
Part 3 of 6 · CausalityLearn and do

Change tokens 7 onward, and outputs before 7 must not move

The causal rule can be tested head on.

def causal_test(model: nn.Module, V: int, T: int = 12, cut: int = 7) -> None:
    """Fails if changing tokens cut onward moves any output before cut."""
    idx = torch.randint(0, V, (1, T))
    later = idx.clone()
    # change every token from cut on
    later[0, cut:] = (later[0, cut:] + 1) % V
    with torch.no_grad():
        before = model(idx)[0][:, :cut]
        after = model(later)[0][:, :cut]
    moved = (before - after).abs().max().item()
    assert moved < 1e-5, f"outputs before position {cut} moved by {moved:.3g}"

A causal model's output at position tt may depend on tokens 0 to tt, and on nothing after. This tests exactly that, on a fresh model, with no training. Positions 0 to 6 get the same input in both runs, so their outputs must not move. Positions 7 onward changed, so theirs may.

Predict

Why run the causality test on the whole model, not on the attention module alone?

Pick an answer above to see the rest