GPU GPT-2 Corpus Trainer #
This command trains GPT-2-style models from text in TorchLean.
The model is initialized inside TorchLean and trained by the TorchLean runtime. It does not load a pretrained PyTorch/Hugging Face checkpoint:
- reusable tokenization lives under
TorchLean.text, - the compact GPT-2-style architecture lives under
TorchLean.nn.models, - the runnable corpus trainer enforces CUDA by default.
The byte path uses one output class for each of the 256 UTF-8 byte values.
Passing --bpe-vocab and --bpe-merges loads the GPT-2 tokenizer files, then projects
observed token IDs into a local vocabulary of at most 512 entries. IDs outside that local
vocabulary map to entry zero. The model therefore does not have a 50,257-way GPT-2 output
head. Both paths train randomly initialized models with four-token contexts; generated text is
a runtime demonstration.
Runner subcommand name. This subcommand trains a randomly initialized GPT-2-style model.
Instances For
Default JSON loss-curve path for this command.
Instances For
Minimum corpus size for the default public training path: 100 MiB.
Instances For
Default context window for both corpus trainers.
Keeping this near the file top lets corpus validation and the model architecture agree without depending on declaration order. Four positions are enough to exercise causal attention while keeping this command a compact runtime check.
Instances For
Command-local corpus, training, tokenization, generation, and prompt-loop controls.
- training : TorchLean.CLI.Training.RunOptions
Step, batching, logging, and allocator controls.
- generation : TorchLean.text.PromptGenerationOptions
Prompt and continuation-length settings.
- interaction : TorchLean.text.InteractiveOptions
Terminal prompt-loop policy.
- corpus : TorchLean.text.CorpusFileOptions
Primary corpus and explicit small-data override.
- finetune : TorchLean.text.FinetuneOptions
Optional second corpus pass.
Optional GPT-2 BPE tokenizer bundle.
Instances For
Instances For
Help text for corpus training, optional GPT-2 tokenization, and generation.
Instances For
Read the primary raw text corpus.
Instances For
Compact byte-level vocabulary for the default corpus path.
Instances For
Embed a byte id in the complete 256-entry byte vocabulary.
Instances For
Single-sequence batch for the byte-level corpus path.
Instances For
Context window shared by corpus validation, byte training, BPE training, and generation.
Instances For
Number of attention heads in the compact byte-level Transformer.
Instances For
Per-head width.
Instances For
Transformer embedding width.
Instances For
Feed-forward hidden width.
Instances For
Number of Transformer blocks.
Instances For
Byte-level GPT configuration shared by shapes and the model constructor.
Instances For
Input shape: byte-level one-hot token sequence.
Instances For
Output shape: one byte-logit row per input position.
Instances For
Runnable byte-level GPT-style model for corpus pretraining/fine-tuning.
The model is compact enough for the eager CUDA path while exercising nontrivial causal attention, feed-forward layers, byte tokenization, and the interactive prompt loop.
Instances For
Build one byte-level training sample from a corpus byte offset.
Instances For
Greedy byte-level generation from the trained model.
Instances For
Terminal prompt loop for the trained byte-level model.
Instances For
Compact vocabulary used by the runnable BPE training path.
The tokenizer still uses GPT-2's real 50,257-token BPE files. For this Lean/CUDA model we project the corpus tokens into a local vocabulary of the first observed BPE ids. A full 50k-way output head is a much larger training run; this example focuses on the tokenizer/data path.
Instances For
Batch size for the BPE corpus path.
Instances For
Short context window used by the trainer.
Instances For
Number of attention heads in the miniature BPE Transformer.
Instances For
Per-head width for the BPE Transformer.
Instances For
Transformer embedding width.
Instances For
Feed-forward hidden width.
Instances For
Number of Transformer blocks.
Instances For
BPE GPT configuration shared by shapes and the model constructor.
Instances For
Input shape: local-BPE one-hot token batch.
Instances For
Output shape: one local-BPE logit row per input position.
Instances For
Compact GPT-2-style model with the real GPT-2 BPE tokenizer path.
This TorchLean-native Transformer reads GPT-2 BPE tokenizer files and uses a local output projection over the corpus ids it observes. Its architecture and scale differ from OpenAI GPT-2-small.
Instances For
Example-local compact vocabulary #
Build one BPE training sample from a tokenized corpus.
Instances For
Turn a BPE prompt into one model input window.
Instances For
Decode projected BPE ids at the tokenizer's serialization boundary.
Instances For
Whether a model output id belongs to the compact vocabulary built for this run.
Instances For
Decode one batch row while excluding unassigned compact-vocabulary output slots.
Instances For
Print an argmax prediction report for a prompt under the BPE model.
Instances For
Greedy BPE generation by repeatedly feeding the last contextLength tokens and appending the
final-position argmax. This is a deterministic sampling path for inspecting the trained next-token
model.
Instances For
Terminal prompt loop for the trained BPE model.
Instances For
Train the GPT-2-style model over a text corpus using CUDA.
This materializes only the requested deterministic training schedule, rather than every possible corpus window. The example is compact by GPT-2 standards, but the data path is real: file bytes → token windows → one-hot tensors → TorchLean CUDA training.
Instances For
Validate, optionally cap, and tokenize one UTF-8 corpus file with GPT-2 BPE.
Instances For
Print the first BPE training window for inspecting tokenization and windowing.
Instances For
Train the compact GPT-2-style model with the real GPT-2 BPE tokenizer.
This exercises the GPT-2 tokenizer/vocabulary path and can overfit local windows. It is not a pretrained GPT-2 checkpoint; it is a randomly initialized TorchLean model trained by this command.