This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · lib/gpt/api

The GPT of lib/gpt, called from Python

The entry points vp.gpt calls (python/vipyr/_gpt.py). Each takes the sizes of a GptConfig as plain numbers and the model as one flat vector: its matrices, row by row, in the order for_leaves visits a Gpt (the token embedding, the position embedding, each block's heads' query, key and value matrices, the attention's output map, the MLP's two matrices, then the output map). Python cuts that vector back into named arrays, model.blocks[0].attn.Wo, and joins them into it again for generate and loss.

  • gpt_train: draws a model from seed and trains it on tokens for steps steps (lib/gpt/gpt.viv's train: Muon on the blocks' matrices, Adam on the embeddings and the output map); returns the loss of every step and the trained model.
  • gpt_generate: continues prompt by count tokens, each drawn from the softmax of the last position's logits divided by temperature (the largest logit when temperature is 0).
  • gpt_attention: where each head of each block looks, for one sequence: the attention weights, one T by T matrix per head, blocks in order.
  • gpt_loss: the mean cross-entropy of the next token over every window of context tokens of tokens, the windows training draws its batches from.

Used with from gpt.api import gpt_train, gpt_generate, gpt_attention, gpt_loss.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 30–177