GPT-2 Checkpoint Example #
This is the load-and-sample half of the byte-level GPT example.
- Train and save a model checkpoint:
lake -R -K cuda=true build torchlean:exe
lake -R -K cuda=true exe torchlean gpt2 --device cuda --tiny-shakespeare --steps 1 --windows 1 \
--prompt "First Citizen:" --generate 0 \
--save-checkpoint data/examples/gpt2_shakespeare.state.json
- Load the checkpoint and sample text (no training loop or optimizer state):
lake -R -K cuda=true exe torchlean gpt2_saved --device cuda \
--checkpoint data/examples/gpt2_shakespeare.state.json \
--prompt "First Citizen:" --generate 0
What A Checkpoint Is Here #
This example uses the simplest TorchLean checkpoint format:
- a shape-indexed pack of model state tensors,
- stored as exact
Float.toBitsvalues in JSON, and - checked against the model's state layout before inference starts.
So save/load is model-agnostic: if we can name the model, TorchLean can compute the expected state shapes and reject stale or mismatched checkpoint files.
Why This Is A Separate Example #
The inference-only workflow is direct: load a checkpoint, convert it into runtime handles, and sample text without building a training loop.
CLI subcommand name used in terminal banners and error messages.
Instances For
Help text for checkpoint-only GPT-2 sampling.
Instances For
Command-local options for loading one checkpoint and sampling from it.
- generation : TorchLean.text.GenerationOptions
Prompt and token-sampling policy.
- checkpointPath : System.FilePath
Model checkpoint loaded before sampling starts.
Instances For
Instances For
Load model state from disk and run sampling with the fixed byte-level GPT architecture.
The checkpoint must match Gpt2.model's state shapes. If the model configuration
in Gpt2.lean changes (heads, width, layers, etc.), mismatched checkpoints fail the shape check
before sampling starts.