TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/itsubaki/gpt/llms.txt
Use this file to discover all available pages before exploring further.
itsubaki/gpt model is a decoder-only transformer that performs a single forward pass: integer token IDs are looked up in an embedding table, passed through a configurable stack of transformer blocks, normalized by a final RMSNorm, and projected by a bias-free linear layer to produce a logit vector over the vocabulary. The highest-probability token at the last position is sampled to generate the next token autoregressively.
Architecture diagram
Major components
| Component | Role |
|---|---|
| Embeddings | Maps each token ID to a dense vector of size EmbedDim |
| Transformer blocks | NumOfBlocks stacked pre-norm blocks; each contains causal attention and a SwiGLU FFN |
| RMSNorm (final) | Normalizes the residual stream before projection |
| Linear (unembed) | Projects from EmbedDim back to VocabSize; no bias |
Embeddings layer
Embeddings(vocabSize, embedDim) holds a single weight matrix of shape [vocabSize, embedDim] initialized from a normal distribution with σ = 0.02. During the forward pass, token IDs are used as row indices to select embedding vectors, which are then reshaped to (B, C, EmbedDim).
Transformer blocks
NumOfBlocks identical BlockT instances are registered under the keys block[0] … block[N-1]. A single RoPEFunc closure — precomputed once in NewGPT — is shared across every block’s attention layer, so the cos/sin tables are allocated only once regardless of depth.
Final RMSNorm
After the last transformer block, the residual stream is normalized byRMSNorm(embedDim). This layer holds a single learnable gamma vector of length EmbedDim (initialized to ones) and applies y = gamma * x / rms with ε = 1e-5.
Linear unembedding
Linear(embedDim, vocabSize) projects the normalized hidden state to logits of shape (B, C, VocabSize). Unlike many implementations this layer carries no bias; the weight matrix is tied to the vocabulary dimension.
The GPT struct
| Field | Description |
|---|---|
VocabSize | Number of tokens in the vocabulary (e.g. 1000) |
MaxContextLen | Maximum sequence length; also bounds the RoPE table (e.g. 256) |
EmbedDim | Hidden dimension for embeddings and residual stream (e.g. 192) |
NumOfHeads | Number of attention heads; headDim = EmbedDim / NumOfHeads |
NumOfBlocks | Depth of the transformer stack (e.g. 6) |
Theta | RoPE base frequency, typically 10000 |
Constructor
useCache is an optional variadic flag. When true, every attention layer inside each block allocates a KV cache that is populated incrementally during autoregressive generation. Pass false (or omit it) for training.
Forward pass
NumOfBlocks transformer blocks using sequential string keys. The embedding lookup, all block computations, the final norm, and the linear projection are all differentiable operations in the autograd engine, so a single call to logits.Backward() propagates gradients through the entire model.
KV caching
WhenuseCache: true is passed to NewGPT, each MultiHeadAttentionT layer maintains a running cache of key and value tensors. During the first generation step the full prompt is processed normally with a causal mask; subsequent single-token steps append to the cache and skip the mask. Use ClearCache() to reset between independent generation calls:
Related pages
Transformer Block
Pre-norm, causal attention, residual connections, and SwiGLU FFN inside each block.
Attention
Multi-head causal self-attention with RoPE and optional KV cache.
Positional Encoding
Rotary Position Embeddings (RoPE): precomputed cos/sin tables and backward pass.
Quickstart
Train and run text generation end-to-end.