MiniGPT is a decoder-only transformer with the GPT-2 geometry, plus the training and inference machinery needed to take it from random init to a served, aligned model.
config.py—GPTConfigdataclass; defaults describe the 124M model.attention.py—CausalSelfAttentionbuilt onscaled_dot_product_attention(FlashAttention kernels when available) with an optional KV-cache.gpt.py— embeddings, a stack of pre-normBlocks, tied LM head, weight init, andconfigure_optimizers(decoupled weight decay, fused AdamW on CUDA).
Documents are GPT-2 BPE tokenized and packed into a flat uint16 memmap. The
dataset samples contiguous block_size + 1 windows, so batches are produced
with a single slice and no padding.
pretrain.py— DDP, gradient accumulation, bf16/fp16 autocast, cosine LR.sft.py— supervised fine-tuning with loss masked to completion tokens.dpo.py— Direct Preference Optimization against a frozen reference model.utils.py— config loading, LR schedule, checkpointing, DDP bootstrap.
KV-cached autoregressive generation, INT8 weight-only quantization, and a
continuous-batching engine that packs sequences of differing lengths into each
decode step via explicit position_ids.
Held-out perplexity and an MT-Bench-style judging harness.