core/nn/gpt library
A minimal GPT-style causal language model.
Compared to TransformerLM this module follows the GPT-2 recipe:
- Learned positional embeddings of shape
[maxCtx, embedDim](not sinusoidal). - An embedding dropout applied to
tokenEmb + posEmbbefore the encoder. - The output head is weight-tied to the token embedding when
tieWeights: true(default). No separateLinearand no head bias — the token-embedding matrix[V, D]is transposed and used to project the final hidden state[N, D]to logits[N, V]. Because the same tensor appears in both the embedding lookup and the head matmul, its gradient accumulates contributions from both paths automatically. - A trailing
LayerNorminside the TransformerEncoder (finalNorm: true, standard for pre-LN GPT). - A
generatemethod that samples autoregressively with greedy, temperature, or top-k modes and truncates context tomaxCtx.
Same 2D-only, single-sequence tensor convention as the rest of the
library: tokens is a 1D [seqLen] tensor of class indices stored
as float32.