Skip to content

Fix incorrect Example 2 output in Causal Self-Attention - #331

Open
claude[bot] wants to merge 1 commit into
mainfrom
claude/issue-123-causal-attention-example
Open

claude[bot] wants to merge 1 commit into
mainfrom
claude/issue-123-causal-attention-example

Conversation

@claude

@claude claude Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Found while verifying the in-repo assets for 53_casual_attention in response to #123 / #88.

challenge.html Example 2 listed the output as a straight copy of V:

published correct
row 0 3.0 4.0 3.0 4.0
row 1 5.0 6.0 4.0 5.0

For Q = [[0,0],[1,1]], K = I, d = 2, query 1's logits are Q[1]·K[0] = Q[1]·K[1] = 1, so after scaling by 1/sqrt(2) both keys are tied and neither is masked (j <= i for i = 1). Softmax gives [0.5, 0.5], hence 0.5*[3,4] + 0.5*[5,6] = [4.0, 5.0].

Verification

Recomputed both examples directly from reference_impl's definition (causal mask, scale = sqrt(d), row-wise softmax). Example 1 reproduces the published values exactly — 3.4898373 vs the documented 3.4898374 — which cross-validates the computation; Example 2 does not.

Example 1 is the one mirrored by generate_example_test(), so this error was invisible to the test harness. Confirmed via run_challenge.py --action run (T4): the example test passes unchanged, since it only covers Example 1.

Docs-only change; no challenge.py or starter behavior is affected.

🤖 Generated with Claude Code

Example 2 in 53_casual_attention listed the output as [[3,4],[5,6]],
which is just a copy of V. For Q = [[0,0],[1,1]], K = I, the second
query's logits are both 1/sqrt(2), so row 1 attends to both keys with
weight 0.5 and the correct output row is [4.0, 5.0].

Verified against reference_impl (causal mask, scale = sqrt(d), row-wise
softmax); Example 1's published values reproduce exactly to 7 decimals
under the same computation, which cross-validates the method.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants