[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6MA9DXVFC7VQJ2DQ2DZAFAX":3,"skill-same:01M6MA9DXVFC7VQJ2DQ2DZAFAX":94},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":41,"linkOnly":42,"markdownContent":43,"markdownBody":44,"frontMatter":45,"refName":52,"commitSha":53,"skillDirectory":54,"forksCount":55,"repositoryHtmlUrl":56,"repositoryHomepageUrl":57,"ownerHtmlUrl":58,"ownerBlogUrl":59,"ownerDescription":60,"updatedAt":61,"install":62,"resources":75},"01M6MA9DXVFC7VQJ2DQ2DZAFAX","implementing-llms-litgpt",null,"Implements and trains LLMs using Lightning AI's LitGPT with 20+ pretrained architectures (Llama, Gemma, Phi, Qwen, Mistral). Use when need clean model implementations, educational understanding of architectures, or production fine-tuning with LoRA\u002FQLoRA. Single-file implementations, no abstraction layers.","hashgraph-online\u002Fawesome-codex-plugins","hashgraph-online","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F160371962?v=4","01M6CNB6NRJVNNGN14TR01Q6D3","HOL (Hashgraph Online)","01M6JT1HSKKG9V68KQAQGBA7XP",1571,"MIT","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fimplementing-llms-litgpt\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40],"implementing","implementing llms litgpt","LitGPT","llms","clean","when","single","layers","LLM Implementation","Lightning AI","Model Architecture","architectures","single-file","use","model","phi","tuning","Transformers","LoRA","Fine-Tuning","training","architecture","2026-11-10 10:12:30",false,"---\nname: implementing-llms-litgpt\ndescription: Implements and trains LLMs using Lightning AI's LitGPT with 20+ pretrained architectures (Llama, Gemma, Phi, Qwen, Mistral). Use when need clean model implementations, educational understanding of architectures, or production fine-tuning with LoRA\u002FQLoRA. Single-file implementations, no abstraction layers.\nlicense: MIT\nmetadata:\n  version: 1.0.0\n  category: ml-training\n  maintainer: Kalaris Labs\n  tags: Model Architecture, LitGPT, Lightning AI, LLM Implementation, LoRA, QLoRA, Fine-Tuning, Llama, Gemma, Phi, Mistral, Educational\n  dependencies: litgpt, torch, transformers\n---\n\n# LitGPT - Clean LLM Implementations\n\n## Quick start\n\nLitGPT provides 20+ pretrained LLM implementations with clean, readable code and production-ready training workflows.\n\n**Installation**:\n```bash\npip install 'litgpt[extra]'\n```\n\n**Load and use any model**:\n```python\nfrom litgpt import LLM\n\n# Load pretrained model\nllm = LLM.load(\"microsoft\u002Fphi-2\")\n\n# Generate text\nresult = llm.generate(\n    \"What is the capital of France?\",\n    max_new_tokens=50,\n    temperature=0.7\n)\nprint(result)\n```\n\n**List available models**:\n```bash\nlitgpt download list\n```\n\n## Common workflows\n\n### Workflow 1: Fine-tune on custom dataset\n\nCopy this checklist:\n\n```\nFine-Tuning Setup:\n- [ ] Step 1: Download pretrained model\n- [ ] Step 2: Prepare dataset\n- [ ] Step 3: Configure training\n- [ ] Step 4: Run fine-tuning\n```\n\n**Step 1: Download pretrained model**\n\n```bash\n# Download Llama 3 8B\nlitgpt download meta-llama\u002FMeta-Llama-3-8B\n\n# Download Phi-2 (smaller, faster)\nlitgpt download microsoft\u002Fphi-2\n\n# Download Gemma 2B\nlitgpt download google\u002Fgemma-2b\n```\n\nModels are saved to `checkpoints\u002F` directory.\n\n**Step 2: Prepare dataset**\n\nLitGPT supports multiple formats:\n\n**Alpaca format** (instruction-response):\n```json\n[\n  {\n    \"instruction\": \"What is the capital of France?\",\n    \"input\": \"\",\n    \"output\": \"The capital of France is Paris.\"\n  },\n  {\n    \"instruction\": \"Translate to Spanish: Hello, how are you?\",\n    \"input\": \"\",\n    \"output\": \"Hola, ¿cómo estás?\"\n  }\n]\n```\n\nSave as `data\u002Fmy_dataset.json`.\n\n**Step 3: Configure training**\n\n```bash\n# Full fine-tuning (requires 40GB+ GPU for 7B models)\nlitgpt finetune \\\n  meta-llama\u002FMeta-Llama-3-8B \\\n  --data JSON \\\n  --data.json_path data\u002Fmy_dataset.json \\\n  --train.max_steps 1000 \\\n  --train.learning_rate 2e-5 \\\n  --train.micro_batch_size 1 \\\n  --train.global_batch_size 16\n\n# LoRA fine-tuning (efficient, 16GB GPU)\nlitgpt finetune_lora \\\n  microsoft\u002Fphi-2 \\\n  --data JSON \\\n  --data.json_path data\u002Fmy_dataset.json \\\n  --lora_r 16 \\\n  --lora_alpha 32 \\\n  --lora_dropout 0.05 \\\n  --train.max_steps 1000 \\\n  --train.learning_rate 1e-4\n```\n\n**Step 4: Run fine-tuning**\n\nTraining saves checkpoints to `out\u002Ffinetune\u002F` automatically.\n\nMonitor training:\n```bash\n# View logs\ntail -f out\u002Ffinetune\u002Flogs.txt\n\n# TensorBoard (if using --train.logger_name tensorboard)\ntensorboard --logdir out\u002Ffinetune\u002Flightning_logs\n```\n\n### Workflow 2: LoRA fine-tuning on single GPU\n\nMost memory-efficient option.\n\n```\nLoRA Training:\n- [ ] Step 1: Choose base model\n- [ ] Step 2: Configure LoRA parameters\n- [ ] Step 3: Train with LoRA\n- [ ] Step 4: Merge LoRA weights (optional)\n```\n\n**Step 1: Choose base model**\n\nFor limited GPU memory (12-16GB):\n- **Phi-2** (2.7B) - Best quality\u002Fsize tradeoff\n- **Llama 3 1B** - Smallest, fastest\n- **Gemma 2B** - Good reasoning\n\n**Step 2: Configure LoRA parameters**\n\n```bash\nlitgpt finetune_lora \\\n  microsoft\u002Fphi-2 \\\n  --data JSON \\\n  --data.json_path data\u002Fmy_dataset.json \\\n  --lora_r 16 \\          # LoRA rank (8-64, higher=more capacity)\n  --lora_alpha 32 \\      # LoRA scaling (typically 2×r)\n  --lora_dropout 0.05 \\  # Prevent overfitting\n  --lora_query true \\    # Apply LoRA to query projection\n  --lora_key false \\     # Usually not needed\n  --lora_value true \\    # Apply LoRA to value projection\n  --lora_projection true \\  # Apply LoRA to output projection\n  --lora_mlp false \\     # Usually not needed\n  --lora_head false      # Usually not needed\n```\n\nLoRA rank guide:\n- `r=8`: Lightweight, 2-4MB adapters\n- `r=16`: Standard, good quality\n- `r=32`: High capacity, use for complex tasks\n- `r=64`: Maximum quality, 4× larger adapters\n\n**Step 3: Train with LoRA**\n\n```bash\nlitgpt finetune_lora \\\n  microsoft\u002Fphi-2 \\\n  --data JSON \\\n  --data.json_path data\u002Fmy_dataset.json \\\n  --lora_r 16 \\\n  --train.epochs 3 \\\n  --train.learning_rate 1e-4 \\\n  --train.micro_batch_size 4 \\\n  --train.global_batch_size 32 \\\n  --out_dir out\u002Fphi2-lora\n\n# Memory usage: ~8-12GB for Phi-2 with LoRA\n```\n\n**Step 4: Merge LoRA weights** (optional)\n\nMerge LoRA adapters into base model for deployment:\n\n```bash\nlitgpt merge_lora \\\n  out\u002Fphi2-lora\u002Ffinal \\\n  --out_dir out\u002Fphi2-merged\n```\n\nNow use merged model:\n```python\nfrom litgpt import LLM\nllm = LLM.load(\"out\u002Fphi2-merged\")\n```\n\n### Workflow 3: Pretrain from scratch\n\nTrain new model on your domain data.\n\n```\nPretraining:\n- [ ] Step 1: Prepare pretraining dataset\n- [ ] Step 2: Configure model architecture\n- [ ] Step 3: Set up multi-GPU training\n- [ ] Step 4: Launch pretraining\n```\n\n**Step 1: Prepare pretraining dataset**\n\nLitGPT expects tokenized data. Use `prepare_dataset.py`:\n\n```bash\npython scripts\u002Fprepare_dataset.py \\\n  --source_path data\u002Fmy_corpus.txt \\\n  --checkpoint_dir checkpoints\u002Ftokenizer \\\n  --destination_path data\u002Fpretrain \\\n  --split train,val\n```\n\n**Step 2: Configure model architecture**\n\nEdit config file or use existing:\n\n```python\n# config\u002Fpythia-160m.yaml\nmodel_name: pythia-160m\nblock_size: 2048\nvocab_size: 50304\nn_layer: 12\nn_head: 12\nn_embd: 768\nrotary_percentage: 0.25\nparallel_residual: true\nbias: true\n```\n\n**Step 3: Set up multi-GPU training**\n\n```bash\n# Single GPU\nlitgpt pretrain \\\n  --config config\u002Fpythia-160m.yaml \\\n  --data.data_dir data\u002Fpretrain \\\n  --train.max_tokens 10_000_000_000\n\n# Multi-GPU with FSDP\nlitgpt pretrain \\\n  --config config\u002Fpythia-1b.yaml \\\n  --data.data_dir data\u002Fpretrain \\\n  --devices 8 \\\n  --train.max_tokens 100_000_000_000\n```\n\n**Step 4: Launch pretraining**\n\nFor large-scale pretraining on cluster:\n\n```bash\n# Using SLURM\nsbatch --nodes=8 --gpus-per-node=8 \\\n  pretrain_script.sh\n\n# pretrain_script.sh content:\nlitgpt pretrain \\\n  --config config\u002Fpythia-1b.yaml \\\n  --data.data_dir \u002Fshared\u002Fdata\u002Fpretrain \\\n  --devices 8 \\\n  --num_nodes 8 \\\n  --train.global_batch_size 512 \\\n  --train.max_tokens 300_000_000_000\n```\n\n### Workflow 4: Convert and deploy model\n\nExport LitGPT models for production.\n\n```\nModel Deployment:\n- [ ] Step 1: Test inference locally\n- [ ] Step 2: Quantize model (optional)\n- [ ] Step 3: Convert to GGUF (for llama.cpp)\n- [ ] Step 4: Deploy with API\n```\n\n**Step 1: Test inference locally**\n\n```python\nfrom litgpt import LLM\n\nllm = LLM.load(\"out\u002Fphi2-lora\u002Ffinal\")\n\n# Single generation\nprint(llm.generate(\"What is machine learning?\"))\n\n# Streaming\nfor token in llm.generate(\"Explain quantum computing\", stream=True):\n    print(token, end=\"\", flush=True)\n\n# Batch inference\nprompts = [\"Hello\", \"Goodbye\", \"Thank you\"]\nresults = [llm.generate(p) for p in prompts]\n```\n\n**Step 2: Quantize model** (optional)\n\nReduce model size with minimal quality loss:\n\n```bash\n# 8-bit quantization (50% size reduction)\nlitgpt convert_lit_checkpoint \\\n  out\u002Fphi2-lora\u002Ffinal \\\n  --dtype bfloat16 \\\n  --quantize bnb.nf4\n\n# 4-bit quantization (75% size reduction)\nlitgpt convert_lit_checkpoint \\\n  out\u002Fphi2-lora\u002Ffinal \\\n  --quantize bnb.nf4-dq  # Double quantization\n```\n\n**Step 3: Convert to GGUF** (for llama.cpp)\n\n```bash\npython scripts\u002Fconvert_lit_checkpoint.py \\\n  --checkpoint_path out\u002Fphi2-lora\u002Ffinal \\\n  --output_path models\u002Fphi2.gguf \\\n  --model_name microsoft\u002Fphi-2\n```\n\n**Step 4: Deploy with API**\n\n```python\nfrom fastapi import FastAPI\nfrom litgpt import LLM\n\napp = FastAPI()\nllm = LLM.load(\"out\u002Fphi2-lora\u002Ffinal\")\n\n@app.post(\"\u002Fgenerate\")\ndef generate(prompt: str, max_tokens: int = 100):\n    result = llm.generate(\n        prompt,\n        max_new_tokens=max_tokens,\n        temperature=0.7\n    )\n    return {\"response\": result}\n\n# Run: uvicorn api:app --host 0.0.0.0 --port 8000\n```\n\n## When to use vs alternatives\n\n**Use LitGPT when:**\n- Want to understand LLM architectures (clean, readable code)\n- Need production-ready training recipes\n- Educational purposes or research\n- Prototyping new model ideas\n- Lightning ecosystem user\n\n**Use alternatives instead:**\n- **Axolotl\u002FTRL**: More fine-tuning features, YAML configs\n- **Megatron-Core**: Maximum performance for >70B models\n- **HuggingFace Transformers**: Broadest model support\n- **vLLM**: Inference-only (no training)\n\n## Common issues\n\n**Issue: Out of memory during fine-tuning**\n\nUse LoRA instead of full fine-tuning:\n```bash\n# Instead of litgpt finetune (requires 40GB+)\nlitgpt finetune_lora  # Only needs 12-16GB\n```\n\nOr enable gradient checkpointing:\n```bash\nlitgpt finetune_lora \\\n  ... \\\n  --train.gradient_accumulation_iters 4  # Accumulate gradients\n```\n\n**Issue: Training too slow**\n\nEnable Flash Attention (built-in, automatic on compatible hardware):\n```python\n# Already enabled by default on Ampere+ GPUs (A100, RTX 30\u002F40 series)\n# No configuration needed\n```\n\nUse smaller micro-batch and accumulate:\n```bash\n--train.micro_batch_size 1 \\\n--train.global_batch_size 32 \\\n--train.gradient_accumulation_iters 32  # Effective batch=32\n```\n\n**Issue: Model not loading**\n\nCheck model name:\n```bash\n# List all available models\nlitgpt download list\n\n# Download if not exists\nlitgpt download meta-llama\u002FMeta-Llama-3-8B\n```\n\nVerify checkpoints directory:\n```bash\nls checkpoints\u002F\n# Should see: meta-llama\u002FMeta-Llama-3-8B\u002F\n```\n\n**Issue: LoRA adapters too large**\n\nReduce LoRA rank:\n```bash\n--lora_r 8  # Instead of 16 or 32\n```\n\nApply LoRA to fewer layers:\n```bash\n--lora_query true \\\n--lora_value true \\\n--lora_projection false \\  # Disable this\n--lora_mlp false  # And this\n```\n\n## Advanced topics\n\n**Supported architectures**: See [references\u002Fsupported-models.md](references\u002Fsupported-models.md) for complete list of 20+ model families with sizes and capabilities.\n\n**Training recipes**: See [references\u002Ftraining-recipes.md](references\u002Ftraining-recipes.md) for proven hyperparameter configurations for pretraining and fine-tuning.\n\n**FSDP configuration**: See [references\u002Fdistributed-training.md](references\u002Fdistributed-training.md) for multi-GPU training with Fully Sharded Data Parallel.\n\n**Custom architectures**: See [references\u002Fcustom-models.md](references\u002Fcustom-models.md) for implementing new model architectures in LitGPT style.\n\n## Hardware requirements\n\n- **GPU**: NVIDIA (CUDA 11.8+), AMD (ROCm), Apple Silicon (MPS)\n- **Memory**:\n  - Inference (Phi-2): 6GB\n  - LoRA fine-tuning (7B): 16GB\n  - Full fine-tuning (7B): 40GB+\n  - Pretraining (1B): 24GB\n- **Storage**: 5-50GB per model (depending on size)\n\n## Resources\n\n- GitHub: https:\u002F\u002Fgithub.com\u002FLightning-AI\u002Flitgpt\n- Docs: https:\u002F\u002Flightning.ai\u002Fdocs\u002Flitgpt\n- Tutorials: https:\u002F\u002Flightning.ai\u002Fdocs\u002Flitgpt\u002Ftutorials\n- Model zoo: 20+ pretrained architectures (Llama, Gemma, Phi, Qwen, Mistral, Mixtral, Falcon, etc.)\n\n## Agent operating procedure\n\n1. **Check the environment.** Check GPU type, memory and driver\u002FCUDA versions (`nvidia-smi`), framework versions, and dataset location and size.\n2. **Pin down the inputs.** Confirm formats, identifiers and parameters from the data or the user. Ask rather than guess any value that changes the result.\n3. **Run a small version first.** Do a smoke run: tiny model or subset, few steps, and confirm loss decreases and checkpoints save.\n4. **Execute the full task** using the instructions and references above.\n5. **Validate the result.** Track metrics on held-out data, compare against a baseline, and record seeds, configs and hardware.\n6. **Report.** State what was run (versions, commands, parameters), what was checked, and what is still uncertain.\n\n| If this happens | Do this |\n|---|---|\n| CUDA out-of-memory | Reduce batch size, enable gradient accumulation\u002Fcheckpointing or mixed precision, or shard the model. |\n| Loss is NaN or diverges | Lower the learning rate, check data for invalid values, and enable gradient clipping. |\n| A function, flag or endpoint in these instructions is missing in the installed version | Check the installed version's own documentation (`help()`, `--help`, official docs), adapt, and tell the user. Never invent an API. |\n| A required input, identifier or parameter is ambiguous | Ask the user, or state the assumption explicitly before running. |\n\n**Integrity rules**\n\n- Never fabricate results, parameters, identifiers, citations or statistics. If something cannot be run or verified, say so plainly.\n- Never claim training results without logs; estimate compute cost before launching large jobs.\n- Treat version-specific details here as possibly outdated: confirm them against the official documentation for the installed version.\n- Ask before actions that cost money, consume shared GPUs or cloud quota, touch personal or patient data, or cannot be undone.\n\n## Related skills\n\n- `unsloth`: Provides guidance on fine-tuning large language models with Unsloth, a library for faster, lower-memory training using LoRA and QLoRA, base…\n- `peft-fine-tuning`: Fine-tunes LLMs with Hugging Face PEFT, using LoRA, QLoRA, IA3, AdaLoRA, prefix tuning, and prompt tuning so that under 1% of parameters ar…\n","# LitGPT - Clean LLM Implementations\n\n## Quick start\n\nLitGPT provides 20+ pretrained LLM implementations with clean, readable code and production-ready training workflows.\n\n**Installation**:\n```bash\npip install 'litgpt[extra]'\n```\n\n**Load and use any model**:\n```python\nfrom litgpt import LLM\n\n# Load pretrained model\nllm = LLM.load(\"microsoft\u002Fphi-2\")\n\n# Generate text\nresult = llm.generate(\n    \"What is the capital of France?\",\n    max_new_tokens=50,\n    temperature=0.7\n)\nprint(result)\n```\n\n**List available models**:\n```bash\nlitgpt download list\n```\n\n## Common workflows\n\n### Workflow 1: Fine-tune on custom dataset\n\nCopy this checklist:\n\n```\nFine-Tuning Setup:\n- [ ] Step 1: Download pretrained model\n- [ ] Step 2: Prepare dataset\n- [ ] Step 3: Configure training\n- [ ] Step 4: Run fine-tuning\n```\n\n**Step 1: Download pretrained model**\n\n```bash\n# Download Llama 3 8B\nlitgpt download meta-llama\u002FMeta-Llama-3-8B\n\n# Download Phi-2 (smaller, faster)\nlitgpt download microsoft\u002Fphi-2\n\n# Download Gemma 2B\nlitgpt download google\u002Fgemma-2b\n```\n\nModels are saved to `checkpoints\u002F` directory.\n\n**Step 2: Prepare dataset**\n\nLitGPT supports multiple formats:\n\n**Alpaca format** (instruction-response):\n```json\n[\n  {\n    \"instruction\": \"What is the capital of France?\",\n    \"input\": \"\",\n    \"output\": \"The capital of France is Paris.\"\n  },\n  {\n    \"instruction\": \"Translate to Spanish: Hello, how are you?\",\n    \"input\": \"\",\n    \"output\": \"Hola, ¿cómo estás?\"\n  }\n]\n```\n\nSave as `data\u002Fmy_dataset.json`.\n\n**Step 3: Configure training**\n\n```bash\n# Full fine-tuning (requires 40GB+ GPU for 7B models)\nlitgpt finetune \\\n  meta-llama\u002FMeta-Llama-3-8B \\\n  --data JSON \\\n  --data.json_path data\u002Fmy_dataset.json \\\n  --train.max_steps 1000 \\\n  --train.learning_rate 2e-5 \\\n  --train.micro_batch_size 1 \\\n  --train.global_batch_size 16\n\n# LoRA fine-tuning (efficient, 16GB GPU)\nlitgpt finetune_lora \\\n  microsoft\u002Fphi-2 \\\n  --data JSON \\\n  --data.json_path data\u002Fmy_dataset.json \\\n  --lora_r 16 \\\n  --lora_alpha 32 \\\n  --lora_dropout 0.05 \\\n  --train.max_steps 1000 \\\n  --train.learning_rate 1e-4\n```\n\n**Step 4: Run fine-tuning**\n\nTraining saves checkpoints to `out\u002Ffinetune\u002F` automatically.\n\nMonitor training:\n```bash\n# View logs\ntail -f out\u002Ffinetune\u002Flogs.txt\n\n# TensorBoard (if using --train.logger_name tensorboard)\ntensorboard --logdir out\u002Ffinetune\u002Flightning_logs\n```\n\n### Workflow 2: LoRA fine-tuning on single GPU\n\nMost memory-efficient option.\n\n```\nLoRA Training:\n- [ ] Step 1: Choose base model\n- [ ] Step 2: Configure LoRA parameters\n- [ ] Step 3: Train with LoRA\n- [ ] Step 4: Merge LoRA weights (optional)\n```\n\n**Step 1: Choose base model**\n\nFor limited GPU memory (12-16GB):\n- **Phi-2** (2.7B) - Best quality\u002Fsize tradeoff\n- **Llama 3 1B** - Smallest, fastest\n- **Gemma 2B** - Good reasoning\n\n**Step 2: Configure LoRA parameters**\n\n```bash\nlitgpt finetune_lora \\\n  microsoft\u002Fphi-2 \\\n  --data JSON \\\n  --data.json_path data\u002Fmy_dataset.json \\\n  --lora_r 16 \\          # LoRA rank (8-64, higher=more capacity)\n  --lora_alpha 32 \\      # LoRA scaling (typically 2×r)\n  --lora_dropout 0.05 \\  # Prevent overfitting\n  --lora_query true \\    # Apply LoRA to query projection\n  --lora_key false \\     # Usually not needed\n  --lora_value true \\    # Apply LoRA to value projection\n  --lora_projection true \\  # Apply LoRA to output projection\n  --lora_mlp false \\     # Usually not needed\n  --lora_head false      # Usually not needed\n```\n\nLoRA rank guide:\n- `r=8`: Lightweight, 2-4MB adapters\n- `r=16`: Standard, good quality\n- `r=32`: High capacity, use for complex tasks\n- `r=64`: Maximum quality, 4× larger adapters\n\n**Step 3: Train with LoRA**\n\n```bash\nlitgpt finetune_lora \\\n  microsoft\u002Fphi-2 \\\n  --data JSON \\\n  --data.json_path data\u002Fmy_dataset.json \\\n  --lora_r 16 \\\n  --train.epochs 3 \\\n  --train.learning_rate 1e-4 \\\n  --train.micro_batch_size 4 \\\n  --train.global_batch_size 32 \\\n  --out_dir out\u002Fphi2-lora\n\n# Memory usage: ~8-12GB for Phi-2 with LoRA\n```\n\n**Step 4: Merge LoRA weights** (optional)\n\nMerge LoRA adapters into base model for deployment:\n\n```bash\nlitgpt merge_lora \\\n  out\u002Fphi2-lora\u002Ffinal \\\n  --out_dir out\u002Fphi2-merged\n```\n\nNow use merged model:\n```python\nfrom litgpt import LLM\nllm = LLM.load(\"out\u002Fphi2-merged\")\n```\n\n### Workflow 3: Pretrain from scratch\n\nTrain new model on your domain data.\n\n```\nPretraining:\n- [ ] Step 1: Prepare pretraining dataset\n- [ ] Step 2: Configure model architecture\n- [ ] Step 3: Set up multi-GPU training\n- [ ] Step 4: Launch pretraining\n```\n\n**Step 1: Prepare pretraining dataset**\n\nLitGPT expects tokenized data. Use `prepare_dataset.py`:\n\n```bash\npython scripts\u002Fprepare_dataset.py \\\n  --source_path data\u002Fmy_corpus.txt \\\n  --checkpoint_dir checkpoints\u002Ftokenizer \\\n  --destination_path data\u002Fpretrain \\\n  --split train,val\n```\n\n**Step 2: Configure model architecture**\n\nEdit config file or use existing:\n\n```python\n# config\u002Fpythia-160m.yaml\nmodel_name: pythia-160m\nblock_size: 2048\nvocab_size: 50304\nn_layer: 12\nn_head: 12\nn_embd: 768\nrotary_percentage: 0.25\nparallel_residual: true\nbias: true\n```\n\n**Step 3: Set up multi-GPU training**\n\n```bash\n# Single GPU\nlitgpt pretrain \\\n  --config config\u002Fpythia-160m.yaml \\\n  --data.data_dir data\u002Fpretrain \\\n  --train.max_tokens 10_000_000_000\n\n# Multi-GPU with FSDP\nlitgpt pretrain \\\n  --config config\u002Fpythia-1b.yaml \\\n  --data.data_dir data\u002Fpretrain \\\n  --devices 8 \\\n  --train.max_tokens 100_000_000_000\n```\n\n**Step 4: Launch pretraining**\n\nFor large-scale pretraining on cluster:\n\n```bash\n# Using SLURM\nsbatch --nodes=8 --gpus-per-node=8 \\\n  pretrain_script.sh\n\n# pretrain_script.sh content:\nlitgpt pretrain \\\n  --config config\u002Fpythia-1b.yaml \\\n  --data.data_dir \u002Fshared\u002Fdata\u002Fpretrain \\\n  --devices 8 \\\n  --num_nodes 8 \\\n  --train.global_batch_size 512 \\\n  --train.max_tokens 300_000_000_000\n```\n\n### Workflow 4: Convert and deploy model\n\nExport LitGPT models for production.\n\n```\nModel Deployment:\n- [ ] Step 1: Test inference locally\n- [ ] Step 2: Quantize model (optional)\n- [ ] Step 3: Convert to GGUF (for llama.cpp)\n- [ ] Step 4: Deploy with API\n```\n\n**Step 1: Test inference locally**\n\n```python\nfrom litgpt import LLM\n\nllm = LLM.load(\"out\u002Fphi2-lora\u002Ffinal\")\n\n# Single generation\nprint(llm.generate(\"What is machine learning?\"))\n\n# Streaming\nfor token in llm.generate(\"Explain quantum computing\", stream=True):\n    print(token, end=\"\", flush=True)\n\n# Batch inference\nprompts = [\"Hello\", \"Goodbye\", \"Thank you\"]\nresults = [llm.generate(p) for p in prompts]\n```\n\n**Step 2: Quantize model** (optional)\n\nReduce model size with minimal quality loss:\n\n```bash\n# 8-bit quantization (50% size reduction)\nlitgpt convert_lit_checkpoint \\\n  out\u002Fphi2-lora\u002Ffinal \\\n  --dtype bfloat16 \\\n  --quantize bnb.nf4\n\n# 4-bit quantization (75% size reduction)\nlitgpt convert_lit_checkpoint \\\n  out\u002Fphi2-lora\u002Ffinal \\\n  --quantize bnb.nf4-dq  # Double quantization\n```\n\n**Step 3: Convert to GGUF** (for llama.cpp)\n\n```bash\npython scripts\u002Fconvert_lit_checkpoint.py \\\n  --checkpoint_path out\u002Fphi2-lora\u002Ffinal \\\n  --output_path models\u002Fphi2.gguf \\\n  --model_name microsoft\u002Fphi-2\n```\n\n**Step 4: Deploy with API**\n\n```python\nfrom fastapi import FastAPI\nfrom litgpt import LLM\n\napp = FastAPI()\nllm = LLM.load(\"out\u002Fphi2-lora\u002Ffinal\")\n\n@app.post(\"\u002Fgenerate\")\ndef generate(prompt: str, max_tokens: int = 100):\n    result = llm.generate(\n        prompt,\n        max_new_tokens=max_tokens,\n        temperature=0.7\n    )\n    return {\"response\": result}\n\n# Run: uvicorn api:app --host 0.0.0.0 --port 8000\n```\n\n## When to use vs alternatives\n\n**Use LitGPT when:**\n- Want to understand LLM architectures (clean, readable code)\n- Need production-ready training recipes\n- Educational purposes or research\n- Prototyping new model ideas\n- Lightning ecosystem user\n\n**Use alternatives instead:**\n- **Axolotl\u002FTRL**: More fine-tuning features, YAML configs\n- **Megatron-Core**: Maximum performance for >70B models\n- **HuggingFace Transformers**: Broadest model support\n- **vLLM**: Inference-only (no training)\n\n## Common issues\n\n**Issue: Out of memory during fine-tuning**\n\nUse LoRA instead of full fine-tuning:\n```bash\n# Instead of litgpt finetune (requires 40GB+)\nlitgpt finetune_lora  # Only needs 12-16GB\n```\n\nOr enable gradient checkpointing:\n```bash\nlitgpt finetune_lora \\\n  ... \\\n  --train.gradient_accumulation_iters 4  # Accumulate gradients\n```\n\n**Issue: Training too slow**\n\nEnable Flash Attention (built-in, automatic on compatible hardware):\n```python\n# Already enabled by default on Ampere+ GPUs (A100, RTX 30\u002F40 series)\n# No configuration needed\n```\n\nUse smaller micro-batch and accumulate:\n```bash\n--train.micro_batch_size 1 \\\n--train.global_batch_size 32 \\\n--train.gradient_accumulation_iters 32  # Effective batch=32\n```\n\n**Issue: Model not loading**\n\nCheck model name:\n```bash\n# List all available models\nlitgpt download list\n\n# Download if not exists\nlitgpt download meta-llama\u002FMeta-Llama-3-8B\n```\n\nVerify checkpoints directory:\n```bash\nls checkpoints\u002F\n# Should see: meta-llama\u002FMeta-Llama-3-8B\u002F\n```\n\n**Issue: LoRA adapters too large**\n\nReduce LoRA rank:\n```bash\n--lora_r 8  # Instead of 16 or 32\n```\n\nApply LoRA to fewer layers:\n```bash\n--lora_query true \\\n--lora_value true \\\n--lora_projection false \\  # Disable this\n--lora_mlp false  # And this\n```\n\n## Advanced topics\n\n**Supported architectures**: See [references\u002Fsupported-models.md](references\u002Fsupported-models.md) for complete list of 20+ model families with sizes and capabilities.\n\n**Training recipes**: See [references\u002Ftraining-recipes.md](references\u002Ftraining-recipes.md) for proven hyperparameter configurations for pretraining and fine-tuning.\n\n**FSDP configuration**: See [references\u002Fdistributed-training.md](references\u002Fdistributed-training.md) for multi-GPU training with Fully Sharded Data Parallel.\n\n**Custom architectures**: See [references\u002Fcustom-models.md](references\u002Fcustom-models.md) for implementing new model architectures in LitGPT style.\n\n## Hardware requirements\n\n- **GPU**: NVIDIA (CUDA 11.8+), AMD (ROCm), Apple Silicon (MPS)\n- **Memory**:\n  - Inference (Phi-2): 6GB\n  - LoRA fine-tuning (7B): 16GB\n  - Full fine-tuning (7B): 40GB+\n  - Pretraining (1B): 24GB\n- **Storage**: 5-50GB per model (depending on size)\n\n## Resources\n\n- GitHub: https:\u002F\u002Fgithub.com\u002FLightning-AI\u002Flitgpt\n- Docs: https:\u002F\u002Flightning.ai\u002Fdocs\u002Flitgpt\n- Tutorials: https:\u002F\u002Flightning.ai\u002Fdocs\u002Flitgpt\u002Ftutorials\n- Model zoo: 20+ pretrained architectures (Llama, Gemma, Phi, Qwen, Mistral, Mixtral, Falcon, etc.)\n\n## Agent operating procedure\n\n1. **Check the environment.** Check GPU type, memory and driver\u002FCUDA versions (`nvidia-smi`), framework versions, and dataset location and size.\n2. **Pin down the inputs.** Confirm formats, identifiers and parameters from the data or the user. Ask rather than guess any value that changes the result.\n3. **Run a small version first.** Do a smoke run: tiny model or subset, few steps, and confirm loss decreases and checkpoints save.\n4. **Execute the full task** using the instructions and references above.\n5. **Validate the result.** Track metrics on held-out data, compare against a baseline, and record seeds, configs and hardware.\n6. **Report.** State what was run (versions, commands, parameters), what was checked, and what is still uncertain.\n\n| If this happens | Do this |\n|---|---|\n| CUDA out-of-memory | Reduce batch size, enable gradient accumulation\u002Fcheckpointing or mixed precision, or shard the model. |\n| Loss is NaN or diverges | Lower the learning rate, check data for invalid values, and enable gradient clipping. |\n| A function, flag or endpoint in these instructions is missing in the installed version | Check the installed version's own documentation (`help()`, `--help`, official docs), adapt, and tell the user. Never invent an API. |\n| A required input, identifier or parameter is ambiguous | Ask the user, or state the assumption explicitly before running. |\n\n**Integrity rules**\n\n- Never fabricate results, parameters, identifiers, citations or statistics. If something cannot be run or verified, say so plainly.\n- Never claim training results without logs; estimate compute cost before launching large jobs.\n- Treat version-specific details here as possibly outdated: confirm them against the official documentation for the installed version.\n- Ask before actions that cost money, consume shared GPUs or cloud quota, touch personal or patient data, or cannot be undone.\n\n## Related skills\n\n- `unsloth`: Provides guidance on fine-tuning large language models with Unsloth, a library for faster, lower-memory training using LoRA and QLoRA, base…\n- `peft-fine-tuning`: Fine-tunes LLMs with Hugging Face PEFT, using LoRA, QLoRA, IA3, AdaLoRA, prefix tuning, and prompt tuning so that under 1% of parameters ar…\n",{"name":5,"license":15,"metadata":46,"description":7},{"tags":47,"version":48,"category":49,"maintainer":50,"dependencies":51},"Model Architecture, LitGPT, Lightning AI, LLM Implementation, LoRA, QLoRA, Fine-Tuning, Llama, Gemma, Phi, Mistral, Educational","1.0.0","ml-training","Kalaris Labs","litgpt, torch, transformers","main","2b63f856ce19c2a797929cacabd9e0fc936812fa","plugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fimplementing-llms-litgpt",490,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins","https:\u002F\u002Fhol.org\u002Fplugins\u002Fbest-codex-plugins","https:\u002F\u002Fgithub.com\u002Fhashgraph-online","https:\u002F\u002Fhol.org","Open-source standards and developer tools for interoperable AI agents: discovery, identity, communication, payments, privacy and security.","2026-11-14 02:12:02",{"source":8,"skillName":5,"commands":63,"prompt":73,"zipAvailable":74},[64,67,70],{"tool":65,"command":66},"npx","npx skills add hashgraph-online\u002Fawesome-codex-plugins --skill implementing-llms-litgpt",{"tool":68,"command":69},"bunx","bunx skills add hashgraph-online\u002Fawesome-codex-plugins --skill implementing-llms-litgpt",{"tool":71,"command":72},"pnpm","pnpm dlx skills add hashgraph-online\u002Fawesome-codex-plugins --skill implementing-llms-litgpt","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fimplementing-llms-litgpt\u002FSKILL.md",true,[76,82,86,90],{"path":77,"resourceType":78,"resourceTypeDesc":79,"sizeBytes":80,"sourceHtmlUrl":81},"references\u002Fcustom-models.md","REFERENCE","参考文档",15655,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fimplementing-llms-litgpt\u002Freferences\u002Fcustom-models.md",{"path":83,"resourceType":78,"resourceTypeDesc":79,"sizeBytes":84,"sourceHtmlUrl":85},"references\u002Fdistributed-training.md",11099,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fimplementing-llms-litgpt\u002Freferences\u002Fdistributed-training.md",{"path":87,"resourceType":78,"resourceTypeDesc":79,"sizeBytes":88,"sourceHtmlUrl":89},"references\u002Fsupported-models.md",7935,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fimplementing-llms-litgpt\u002Freferences\u002Fsupported-models.md",{"path":91,"resourceType":78,"resourceTypeDesc":79,"sizeBytes":92,"sourceHtmlUrl":93},"references\u002Ftraining-recipes.md",10978,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002FKalarisLabs\u002Fresearch-agent-skills\u002Fskills\u002Fimplementing-llms-litgpt\u002Freferences\u002Ftraining-recipes.md",[95,104,111,118,144,169],{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":99,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":103},"01M746ZWACVKMZ1BJXJZHYJSSX","migrate-to-e2e","Moves an existing Playwright, Cypress, Selenium, Appium, Detox, Maestro, or TesterArmy suite to e2e one slice at a time, with the old suite running beside the new one until each ported test is proven. Keeps a MIGRATION.md progress file so any later session resumes where the last stopped. Optionally plants a defect to show both suites catch it. Use for \u002Fmigrate-to-e2e, \"migrate our tests to e2e\", \"port these Maestro flows\", \"move our TesterArmy tests\", or when a project has an e2e config and an older suite still running.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Ftester-army\u002Fe2e\u002Fskills\u002Fmigrate-to-e2e\u002FSKILL.md",[],[],"2026-11-11 15:11:14",{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":99,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":103},"01M746ZPTAX1Q0FBKAB1CYND7E","e2e","Writes, runs, and debugs end-to-end tests for web and mobile apps with e2e, the agentic test runner, which mixes agent.act goals with exact locator assertions on a Playwright browser or an iOS or Android device. Also drives a project's running app live over the e2e MCP server to look at a screen, check a UI change, take a screenshot or record a video, and try a locator; and runs bug bashes, parallel e2e explore runs with each bug proven by a repro test. Use when a project depends on e2e or has an e2e.config.ts, when asked for end-to-end, browser, mobile, or agentic UI tests, to check a change in the running app, to QA or bug bash an app or branch, or when an e2e run fails.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Ftester-army\u002Fe2e\u002Fskills\u002Fe2e\u002FSKILL.md",[],[],{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":99,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":103},"01M746ZJN784HVHMDP9MQGCSGG","create-verification-skill","Generate a project-local verify-\u003Capp> skill on top of e2e, so any coding agent can launch the app, check it is worth driving, exercise a feature the way a user does, keep evidence, and bug bash it. Writes the skill, a feature map with one explore charter per feature, and proves it once. Use for \u002Fcreate-verification-skill, \"make a verification skill for this repo\", or when a project has no scripted way to prove UI behavior.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Ftester-army\u002Fe2e\u002Fskills\u002Fcreate-verification-skill\u002FSKILL.md",[],[],{"skillNo":119,"name":120,"nameZh":6,"description":121,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":99,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":124,"publishedAt":41},"01M716A6ETNB9B1SQ3GXZC75VR","deja-search","deja-vu memory — search the user's past AI coding sessions with the deja CLI. Holds what they already settled and never wrote into the repo (naming rules, banned or already-tried tools, required checks before merge, preferred values, who owns what). Use before your first edit in a task, before you call a change done or ready to merge, before you recommend a tool, library, design or reviewer, before re-debugging an error that may already be solved, when they say 'didn't we fix this before', 'what did we decide about X' or 'I already have that', and before telling them something on this machine does not exist.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fvshulcz\u002Fdeja-vu\u002Fskills\u002Fdeja-search\u002FSKILL.md",[],[125,126,127,128,129,130,131,132,133,134,135,24,136,137,138,139,140,141,142,143],"search","deja search","never","error","ready","memory","re","decide","fix","design","debugging","you","done","reviewer","io","change","cli","merge","past",{"skillNo":145,"name":146,"nameZh":6,"description":147,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":99,"licenseFileUrl":6,"sourceHtmlUrl":148,"categories":149,"keywords":150,"publishedAt":41},"01M716A3J2W5SENSE9VGMXB375","deja-reflect","End-of-session reflection and memory curation with deja-vu. Review what was decided, what commands broke and what repaired them, and record durable project rules or decisions with deja remember so the next session starts with them.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Fvshulcz\u002Fdeja-vu\u002Fskills\u002Fdeja-reflect\u002FSKILL.md",[],[151,152,153,139,154,155,156,157,158,159,160,161,162,163,130,164,165,166,167,168],"deja reflect","reflect","review","with","record","github","next","https","node","Rules","decisions","brew","remember","project rules","project","session","end","reflection",{"skillNo":170,"name":171,"nameZh":6,"description":172,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":99,"licenseFileUrl":6,"sourceHtmlUrl":173,"categories":174,"keywords":186,"publishedAt":41},"01M715T3RR4BAYSR57HPPTJ0PF","revid","Make, edit, export and post AI videos with Revid (revid.ai) through the Revid MCP server. Use whenever the user wants a short-form or long-form video made (from an idea, a script, a URL, an article, a PDF, a tweet, a product page, their own clips, or a song), wants to find what is going viral on TikTok, YouTube, Instagram or X before making something, wants to edit or re-export an existing Revid project, generate a standalone AI image or clip, make a series episode, or publish and schedule a finished video to connected social accounts. Covers setup (hosted MCP with OAuth, or an API key), the 36 tools, credits, polling and the rules for publishing. Routes to the more specific revid-* skills when one fits.","https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Ftmakersas\u002Frevid-skills\u002Fskills\u002Frevid\u002FSKILL.md",[175,180,183],{"categoryNo":176,"categoryName":177,"taxonomyType":178,"taxonomyTypeDesc":179},"01JBSEEDCAT000000000000016","图像与多媒体","SCENARIO","使用场景",{"categoryNo":181,"categoryName":182,"taxonomyType":178,"taxonomyTypeDesc":179},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":184,"categoryName":185,"taxonomyType":178,"taxonomyTypeDesc":179},"01JBSEEDCAT000000000000010","后端与接口",[171,187,188,189,190,191,192,165,193,131,194,195,196,197,24,198,199,200,201,202],"URL","Video","short-form","standalone","PDF","viral","tiktok","short","social","MCP","song","image","mcp server","schedule","api","publish"]