decoder-only transformer model architecture with 20+ pre-configured model families
Implements minimal-abstraction decoder-only transformer architectures (GPT, Llama, Mistral, Phi, Gemma, Qwen, etc.) using PyTorch with explicit, modifiable code rather than wrapper abstractions. The Config dataclass in litgpt/config.py defines ~100 parameters per model (layer count, embedding dimensions, attention heads, RoPE scaling, GQA variants) that map directly to model instantiation. Supports model sizes from 0.5B to 405B parameters with native support for architectural variants like grouped query attention, sliding window attention, and mixture-of-experts.
Unique: Provides from-scratch, fully readable implementations of 20+ model architectures without abstraction layers, allowing direct inspection and modification of every transformer component (attention, normalization, embeddings) vs frameworks like HuggingFace Transformers that wrap models in high-level abstractions
vs alternatives: Offers superior code transparency and hackability compared to HuggingFace Transformers, enabling researchers to understand and modify exact architectural details without navigating wrapper abstractions
lora and qlora parameter-efficient fine-tuning with selective layer freezing
Implements Low-Rank Adaptation (LoRA) and Quantized LoRA (QLoRA) fine-tuning via the litgpt/lora.py module, which injects trainable low-rank decomposition matrices (A, B) into attention and linear layers while freezing base model weights. QLoRA variant uses BitsAndBytes 4-bit quantization to reduce base model memory footprint to ~6GB for 70B models. Supports selective layer targeting (e.g., only attention layers or specific transformer blocks) and integrates with PyTorch Lightning's distributed training for multi-GPU LoRA fine-tuning.
Unique: Integrates LoRA and QLoRA with PyTorch Lightning's FSDP for distributed multi-GPU LoRA training, and provides explicit control over which layers receive LoRA injection (vs HuggingFace PEFT which uses heuristic layer selection)
vs alternatives: Tighter integration with PyTorch Lightning enables seamless distributed LoRA training across multiple GPUs, whereas HuggingFace PEFT requires manual distributed training setup
http server deployment with litserve and openai-compatible endpoints
Integrates with LitServe (Lightning AI's inference server) to deploy models as HTTP APIs with OpenAI-compatible endpoints (/v1/chat/completions, /v1/completions). Handles request batching, concurrent inference, and automatic scaling across multiple GPUs. Supports streaming responses (Server-Sent Events), request validation, and error handling. Models can be served with quantization, LoRA adapters, or full precision, with automatic device placement and memory management.
Unique: Provides OpenAI-compatible endpoints via LitServe with automatic request batching and streaming support, enabling drop-in replacement for OpenAI API in existing applications, vs vLLM which requires custom endpoint implementation
vs alternatives: Simpler deployment than vLLM for LitGPT models due to tight integration with PyTorch Lightning, with automatic batching and streaming; more lightweight than TensorRT-LLM but less optimized for inference latency
evaluation integration with lm-evaluation-harness for benchmarking
Integrates with EleutherAI's lm-evaluation-harness to run standardized benchmarks (MMLU, HellaSwag, ARC, TruthfulQA, etc.) on trained models. Provides evaluation scripts that load LitGPT checkpoints, apply prompt formatting, and compute benchmark metrics. Supports both zero-shot and few-shot evaluation, with configurable number of shots and prompt templates. Results are comparable across models and frameworks, enabling reproducible evaluation.
Unique: Provides direct integration with lm-evaluation-harness for standardized benchmarking, with automatic prompt formatting and result logging, vs manual benchmark implementation which requires custom evaluation code
vs alternatives: Enables reproducible evaluation comparable across frameworks and models, with automatic handling of prompt formatting and metric computation vs custom evaluation scripts which are error-prone and non-standardized
tokenizer abstraction with huggingface and sentencepiece backend support
Implements a unified Tokenizer class (litgpt/tokenizer.py) that wraps both HuggingFace Tokenizers and SentencePiece backends, providing a consistent encode/decode interface. Handles special tokens, padding, truncation, and batch tokenization. Supports loading tokenizers from HuggingFace hub or local paths, with automatic caching. Integrates with model-specific tokenizer configurations (e.g., Llama's special tokens, Mistral's chat tokens).
Unique: Provides a unified Tokenizer abstraction supporting both HuggingFace and SentencePiece backends with consistent API, vs using tokenizers directly which requires different code for each backend
vs alternatives: Simpler tokenizer management than switching between HuggingFace and SentencePiece APIs, with automatic special token handling and batch processing support
configuration system with dataclass-based model and training configs
Implements a Config dataclass system (litgpt/config.py) that defines model architectures via ~100 parameters (num_layers, hidden_size, num_heads, etc.) and training hyperparameters (learning_rate, batch_size, warmup_steps). Provides named configurations for 20+ model families (Llama, Mistral, Phi, etc.) that can be loaded by name or customized. Configs are Python dataclasses, enabling IDE autocomplete, type checking, and programmatic manipulation. Supports config serialization to YAML for reproducibility.
Unique: Uses Python dataclasses for configuration with IDE autocomplete and type checking, vs YAML-based configs which lack IDE support and type safety
vs alternatives: More developer-friendly than YAML configs due to IDE autocomplete and type checking; more flexible than hardcoded configs, enabling programmatic model customization
prompt formatting system with model-specific instruction templates
Implements a Prompt system (litgpt/prompts.py) that applies model-specific instruction templates for chat and instruction-following tasks. Supports templates for Llama Chat, Mistral Instruct, Phi, Gemma, and other models. Handles multi-turn conversations, system prompts, and automatic token counting. Templates are defined as Python classes with format() methods, enabling transparent prompt construction and debugging.
Unique: Provides explicit model-specific prompt templates as Python classes with format() methods, enabling transparent prompt construction and debugging, vs HuggingFace which uses string templates or chat templates in model configs
vs alternatives: More transparent and debuggable than string-based templates, with explicit support for multi-turn conversations and token counting integrated into the prompt system
configuration hub with pre-defined model architectures and hyperparameters
LitGPT provides a configuration hub (litgpt/config.py) with pre-defined Config dataclasses for 20+ model families (Llama, Mistral, Phi, Gemma, Qwen, Falcon, OLMo, etc.), each specifying ~100 architectural parameters (layer count, embedding dimensions, attention heads, RoPE, GQA, etc.). Named configurations enable one-line model instantiation without manual parameter specification. The hub is extensible — new models can be added by defining a Config dataclass and registering it.
Unique: Explicit Config dataclass registry with 20+ pre-defined model families, enabling transparent architecture specification without wrapper abstractions or configuration files
vs alternatives: More transparent than Hugging Face's config.json system, with explicit Python dataclasses, but less flexible for dynamic configuration discovery
+8 more capabilities