Char-GPT (minGPT-style) Example #
This example mirrors the classic "character-level GPT on a single text file" walkthrough popularized by Andrej Karpathy's minGPT/nanoGPT teaching material:
- build an alphabet (
itos) from the training text, - build a
stoitokenizer from that alphabet, - train a small causal Transformer to predict the next character,
- sample text continuations from a prompt.
It uses TorchLean's one-hot token interface (batch × seqLen × vocab) so the whole demo stays in
the same typed tensor world as the rest of the codebase.
Implementation note: training draws a fresh deterministic random window each step (minGPT-style
get_batch). The --windows flag is still accepted for compatibility, but it no longer controls
how many windows are precomputed.
lake build -R -K cuda=true torchlean:exe
lake exe torchlean chargpt --cuda --tiny-shakespeare --steps 500 \
--prompt \"First Citizen:\" --generate 200
- base : API.Common.ModelTrainFlags
- batch : ℕ
- seqLen : ℕ
- windows : ℕ
Accepted for CLI compatibility with fixed-window trainer entrypoints.
CharGPT draws a fresh random window each step (minGPT-style), so training does not depend on precomputing a fixed
windowsarray. We still accept--windowsso scripts don't break. - prompt : String
- generate : ℕ
- temperature : Float
- topK : ℕ
- repeatPenalty : Float
- repeatWindow : ℕ
- seed : ℕ
- asciiOnly : Bool
- loadParams? : Option System.FilePath
- saveParams? : Option System.FilePath