Skip to content

feat: Add minimal transformer block with multi-head attention - #10

Merged
ThomasHartDev merged 2 commits into
mainfrom
thomas/feat/transformer-block
Aug 16, 2026
Merged

feat: Add minimal transformer block with multi-head attention#10
ThomasHartDev merged 2 commits into
mainfrom
thomas/feat/transformer-block

Conversation

@ThomasHartDev

Copy link
Copy Markdown
Owner

Add a forward-only Pre-LN self-attention block (multi-head scaled dot-product attention, position-wise GELU FFN, residual + LayerNorm) with optional causal masking.

No backward/grad path yet: parameters() exposes weight tensors for inspection only, not for the MLP optimizers. Attention is checked against a golden softmax(QKᵀ/√d_k)V reference (scale load-bearing). All-masked (-inf) softmax rows return zeros without RuntimeWarning/nan.

Pre-LN encoder block: multi-head self-attention, position-wise GELU FFN,
residual connections, and LayerNorm. Numpy only, with shape and mask tests.
Document transformer as forward-only (no optimizer/grad claim).
Pin scaled_dot_product_attention to softmax(QK^T/sqrt(d_k))V with a
scale-sensitive golden test. Softmax all-(-inf) rows return zeros
without RuntimeWarning/nan; fully-masked attention covered in tests.
@ThomasHartDev
ThomasHartDev force-pushed the thomas/feat/transformer-block branch from 66afdd0 to 7c1f2b0 Compare August 16, 2026 06:27
@ThomasHartDev
ThomasHartDev merged commit 4ee6f71 into main Aug 16, 2026
@ThomasHartDev
ThomasHartDev deleted the thomas/feat/transformer-block branch August 16, 2026 06:27
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.

1 participant