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.
layer package provides Linear for learned linear projections (used throughout attention, the FFN, and the unembedding head) and Embeddings for token-to-vector lookup (the input embedding table that maps integer token IDs to dense vectors). Both layers hold a single weight matrix w initialized with initw().
Linear
Wq, Wk, Wv, Wo), the SwiGLU FFN (W, V, O), and the final unembedding head is a Linear layer.
Input feature dimension — the size of the last axis of the input tensor. Determines the number of rows in the weight matrix.
Output feature dimension. Determines the number of columns in the weight matrix and the size of the last axis of the output tensor.
Parameters
| Parameter | Shape | Initial value |
|---|---|---|
w | (xDim, hiddenDim) | initw(xDim, hiddenDim) |
Forward pass
(B, C, xDim), the output is (B, C, hiddenDim).
Shape examples
Where Linear is used
| Location | xDim | hiddenDim |
|---|---|---|
| Attention Wq / Wk / Wv | embedDim | numOfHeads * headDim |
| Attention Wo | numOfHeads * headDim | embedDim |
| SwiGLU W / V (gate + value) | embedDim | embedDim * 8 / 3 |
| SwiGLU O (output projection) | embedDim * 8 / 3 | embedDim |
| Unembedding head | embedDim | vocabSize |
Embeddings
w, producing a dense vector of dimension embedDim.
Vocabulary size — the total number of distinct token IDs. Determines the number of rows in the embedding table. Input token IDs must be in the range
[0, xDim).Embedding dimension — the length of each token’s dense vector representation. Determines the number of columns in the embedding table and the size of the last axis of the output tensor.
Parameters
| Parameter | Shape | Initial value |
|---|---|---|
w | (xDim, embedDim) | initw(xDim, embedDim) |
Forward pass
The forward pass flattens the input token IDs, performs a batched row-gather (F.GetItem) on w, and reshapes the result to append embedDim to the original input shape.
Shape example
(B, C) — B sequences each of length C — each integer is independently replaced by its row in the embedding table, producing an output of shape (B, C, embedDim).
Embedding table vs. unembedding head
TheEmbeddings layer and the final unembedding Linear layer are separate and do not share weights (no weight tying). The unembedding Linear(embedDim, vocabSize) has its own independently initialized w parameter.
Weight initialization
BothLinear and Embeddings initialize their weight matrices through the same internal helper:
0 and standard deviation 0.02. This is the same initialization strategy used in the original GPT-2 paper and keeps the initial activations small enough to avoid gradient saturation at the start of training.
The standard deviation
0.02 is fixed and not scaled by layer depth. Some implementations apply 1/sqrt(2 * numLayers) scaling to residual projections (Wo and the FFN output) to account for the accumulation of variance across blocks. This model does not apply that scaling.