TorchLean API

NN.Examples.Models.Sequence.CharGpt

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:

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
Instances For
    def NN.Examples.Models.Sequence.CharGpt.generateSampledFromIds (batch seqLen vocab : ) (opts : Runtime.Autograd.Torch.Options) (model : API.nn.Sequential (Tensor.shapeOfDims [batch, seqLen, vocab]) (Tensor.shapeOfDims [batch, seqLen, vocab])) (params : Runtime.Autograd.Torch.ParamList Float (Runtime.Autograd.TorchLean.NN.Seq.paramShapes model)) (promptIds : List ) (steps : ) (temperature : Float) (topK seed repeatWindow : ) (repeatPenalty : Float) (allowId : Bool := fun (x : ) => true) (padId : := 0) :
    Instances For
      partial def NN.Examples.Models.Sequence.CharGpt.generateSampledFromIds.loop (batch seqLen vocab : ) (opts : Runtime.Autograd.Torch.Options) (model : API.nn.Sequential (Tensor.shapeOfDims [batch, seqLen, vocab]) (Tensor.shapeOfDims [batch, seqLen, vocab])) (params : Runtime.Autograd.Torch.ParamList Float (Runtime.Autograd.TorchLean.NN.Seq.paramShapes model)) (steps : ) (temperature : Float) (topK seed repeatWindow : ) (repeatPenalty : Float) (allowId : Bool) (padId : ) (hSeqLen : ¬seqLen = 0) (b0 : Fin batch) (ids : List ) :
      IO (List )