Skip to content

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

Open
ThomasHartDev wants to merge 2 commits into
mainfrom
thomas/feat/transformer-block
Open

feat: Add minimal transformer block with multi-head attention#10
ThomasHartDev wants to merge 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.
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