{"id":13472516,"url":"https://github.com/Lightning-AI/litgpt","last_synced_at":"2025-03-26T17:30:39.102Z","repository":{"id":161729807,"uuid":"636372163","full_name":"Lightning-AI/litgpt","owner":"Lightning-AI","description":"20+ high-performance LLMs with recipes to pretrain, finetune and deploy at scale.","archived":false,"fork":false,"pushed_at":"2025-03-20T07:56:11.000Z","size":4488,"stargazers_count":11846,"open_issues_count":281,"forks_count":1194,"subscribers_count":113,"default_branch":"main","last_synced_at":"2025-03-22T18:05:24.871Z","etag":null,"topics":["ai","artificial-intelligence","deep-learning","large-language-models","llm","llm-inference","llms"],"latest_commit_sha":null,"homepage":"https://lightning.ai","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Lightning-AI/lit-llama","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lightning-AI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-04T17:46:11.000Z","updated_at":"2025-03-22T15:29:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"c57547ab-da1f-4d04-a7b2-0fa4f9755033","html_url":"https://github.com/Lightning-AI/litgpt","commit_stats":null,"previous_names":["lightning-ai/lit-gpt","lightning-ai/litgpt","lightning-ai/lit-parrot"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lightning-AI%2Flitgpt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lightning-AI%2Flitgpt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lightning-AI%2Flitgpt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lightning-AI%2Flitgpt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lightning-AI","download_url":"https://codeload.github.com/Lightning-AI/litgpt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245407773,"owners_count":20610234,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","artificial-intelligence","deep-learning","large-language-models","llm","llm-inference","llms"],"created_at":"2024-07-31T16:00:55.284Z","updated_at":"2025-03-26T17:30:39.094Z","avatar_url":"https://github.com/Lightning-AI.png","language":"Python","funding_links":[],"categories":["Python","LLM Training / Finetuning","NLP","HarmonyOS","微调 Fine-Tuning","Projects","artificial-intelligence","🎯 Fine-Tuning \u0026 Training","Fine-tuning","💾 Practical Guide for Novice","🔓 Open Source Inference Engines","LLM Training Frameworks","Repos","7. Training \u0026 Fine-tuning Ecosystem","1. **Large Language Models**","\u003ca name=\"Python\"\u003e\u003c/a\u003ePython","Training \u0026 Fine-Tuning","Writing \u0026 Editing"],"sub_categories":["Windows Manager","Global AI Projects","Embedding Models","🛠️ How to build an LLM-based Text-to-SQL model:","Fine-Tuning Tools"],"readme":"\u003cdiv align=\"center\"\u003e\n\n\n# ⚡ LitGPT\n\n**20+ high-performance LLMs with recipes to pretrain, finetune, and deploy at scale.**\n\n\u003cpre\u003e\n         ✅ From scratch implementations     ✅ No abstractions    ✅ Beginner friendly\n            ✅ Flash attention                  ✅ FSDP               ✅ LoRA, QLoRA, Adapter\n✅ Reduce GPU memory (fp4/8/16/32)  ✅ 1-1000+ GPUs/TPUs  ✅ 20+ LLMs\n\u003c/pre\u003e\n\n\n---\n\n\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytorch-lightning)\n![cpu-tests](https://github.com/lightning-AI/lit-stablelm/actions/workflows/cpu-tests.yml/badge.svg) [![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/Lightning-AI/lit-stablelm/blob/master/LICENSE) [![Discord](https://img.shields.io/discord/1077906959069626439)](https://discord.gg/VptPCZkGNa)\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#quick-start\"\u003eQuick start\u003c/a\u003e •\n  \u003ca href=\"#choose-from-20-llms\"\u003eModels\u003c/a\u003e •\n  \u003ca href=\"#finetune-an-llm\"\u003eFinetune\u003c/a\u003e •\n  \u003ca href=\"#deploy-an-llm\"\u003eDeploy\u003c/a\u003e •\n  \u003ca href=\"#all-workflows\"\u003eAll workflows\u003c/a\u003e •\n  \u003ca href=\"#state-of-the-art-features\"\u003eFeatures\u003c/a\u003e •\n  \u003ca href=\"#training-recipes\"\u003eRecipes (YAML)\u003c/a\u003e •\n  \u003ca href=\"https://lightning.ai/\"\u003eLightning AI\u003c/a\u003e •\n    \u003ca href=\"#tutorials\"\u003eTutorials\u003c/a\u003e\n\u003c/p\u003e\n\n\u0026nbsp;\n\n\u003ca target=\"_blank\" href=\"https://lightning.ai/lightning-ai/studios/litgpt-quick-start\"\u003e\n  \u003cimg src=\"https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/app-2/get-started-badge.svg\" height=\"36px\" alt=\"Get started\"/\u003e\n\u003c/a\u003e\n\n\u0026nbsp;\n\n\u003c/div\u003e\n\n# Use, finetune, pretrain, and deploy LLMs Lightning fast ⚡⚡\nEvery LLM is implemented from scratch with **no abstractions** and **full control**, making them blazing fast, minimal, and performant at enterprise scale.\n\n✅ **Enterprise ready -** Apache 2.0 for unlimited enterprise use.\u003c/br\u003e\n✅ **Developer friendly -** Easy debugging with no abstraction layers and single file implementations.\u003c/br\u003e\n✅ **Optimized performance -** Models designed to maximize performance, reduce costs, and speed up training.\u003c/br\u003e\n✅ **Proven recipes -** Highly-optimized training/finetuning recipes tested at enterprise scale.\u003c/br\u003e\n\n\u0026nbsp;\n\n# Quick start\nInstall LitGPT\n```\npip install 'litgpt[all]'\n```\n\nLoad and use any of the [20+ LLMs](#choose-from-20-llms):\n```python\nfrom litgpt import LLM\n\nllm = LLM.load(\"microsoft/phi-2\")\ntext = llm.generate(\"Fix the spelling: Every fall, the family goes to the mountains.\")\nprint(text)\n# Corrected Sentence: Every fall, the family goes to the mountains.\n```\n\n\u0026nbsp;\n\n✅ Optimized for fast inference\u003c/br\u003e\n✅ Quantization\u003c/br\u003e\n✅ Runs on low-memory GPUs\u003c/br\u003e\n✅ No layers of internal abstractions\u003c/br\u003e\n✅ Optimized for production scale\u003c/br\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eAdvanced install options\u003c/summary\u003e\n\nInstall from source:\n\n```bash\ngit clone https://github.com/Lightning-AI/litgpt\ncd litgpt\npip install -e '.[all]'\n```\n\u003c/details\u003e\n\n[Explore the full Python API docs](tutorials/python-api.md).\n\n\u0026nbsp;\n\n---\n# Choose from 20+ LLMs\nEvery model is written from scratch to maximize performance and remove layers of abstraction:\n\n| Model | Model size | Author | Reference |\n|----|----|----|----|\n| Llama 3, 3.1, 3.2, 3.3 | 1B, 3B, 8B, 70B, 405B | Meta AI | [Meta AI 2024](https://github.com/meta-llama/llama3)                                           |\n| Code Llama | 7B, 13B, 34B, 70B | Meta AI | [Rozière et al. 2023](https://arxiv.org/abs/2308.12950)                                       |\n| CodeGemma | 7B | Google | [Google Team, Google Deepmind](https://ai.google.dev/gemma/docs/codegemma)                                     |\n| Gemma 2 | 2B, 9B, 27B | Google | [Google Team, Google Deepmind](https://storage.googleapis.com/deepmind-media/gemma/gemma-2-report.pdf)  |\n| Phi 4 | 14B | Microsoft Research | [Abdin et al. 2024](https://arxiv.org/abs/2412.08905)                                                                            |\n| Qwen2.5 | 0.5B, 1.5B, 3B, 7B, 14B, 32B, 72B | Alibaba Group | [Qwen Team 2024](https://qwenlm.github.io/blog/qwen2.5/)                                               |\n| Qwen2.5 Coder | 0.5B, 1.5B, 3B, 7B, 14B, 32B | Alibaba Group | [Hui, Binyuan et al. 2024](https://arxiv.org/abs/2409.12186)                                          |\n| R1 Distill Llama | 8B, 70B | DeepSeek AI | [DeepSeek AI 2025](https://github.com/deepseek-ai/DeepSeek-R1/blob/main/DeepSeek_R1.pdf)                                                                                 |\n| ... | ... | ... | ...   |\n\n\u003cdetails\u003e\n  \u003csummary\u003eSee full list of 20+ LLMs\u003c/summary\u003e\n\n\u0026nbsp;\n\n#### All models\n\n| Model | Model size | Author | Reference |\n|----|----|----|----|\n| CodeGemma | 7B | Google | [Google Team, Google Deepmind](https://ai.google.dev/gemma/docs/codegemma)                                                                 |\n| Code Llama | 7B, 13B, 34B, 70B | Meta AI | [Rozière et al. 2023](https://arxiv.org/abs/2308.12950)                                                                   |\n| Falcon | 7B, 40B, 180B | TII UAE | [TII 2023](https://falconllm.tii.ae)                                                                                              |\n| Falcon 3 | 1B, 3B, 7B, 10B | TII UAE | [TII 2024](https://huggingface.co/blog/falcon3)                                                                                              |\n| FreeWilly2 (Stable Beluga 2) | 70B | Stability AI | [Stability AI 2023](https://stability.ai/blog/stable-beluga-large-instruction-fine-tuned-models)                 |\n| Function Calling Llama 2 | 7B | Trelis | [Trelis et al. 2023](https://huggingface.co/Trelis/Llama-2-7b-chat-hf-function-calling-v2)                                  |\n| Gemma | 2B, 7B | Google | [Google Team, Google Deepmind](https://storage.googleapis.com/deepmind-media/gemma/gemma-report.pdf)                                       |\n| Gemma 2 | 9B, 27B | Google | [Google Team, Google Deepmind](https://storage.googleapis.com/deepmind-media/gemma/gemma-2-report.pdf)                                  |\n| Llama 2 | 7B, 13B, 70B | Meta AI | [Touvron et al. 2023](https://arxiv.org/abs/2307.09288)                                                                           |\n| Llama 3.1 | 8B, 70B | Meta AI | [Meta AI 2024](https://github.com/meta-llama/llama3)                                                                                 |\n| Llama 3.2 | 1B, 3B | Meta AI | [Meta AI 2024](https://ai.meta.com/blog/llama-3-2-connect-2024-vision-edge-mobile-devices/)                                           |\n| Llama 3.3 | 70B | Meta AI | [Meta AI 2024](https://huggingface.co/meta-llama/Llama-3.3-70B-Instruct)                                                                                 |\n| Mathstral | 7B | Mistral AI | [Mistral AI 2024](https://mistral.ai/news/mathstral/)                                                                                  |\n| MicroLlama | 300M | Ken Wang | [MicroLlama repo](https://github.com/keeeeenw/MicroLlama)                                                                             |\n| Mixtral MoE | 8x7B | Mistral AI | [Mistral AI 2023](https://mistral.ai/news/mixtral-of-experts/)                                                                     |\n| Mistral | 7B, 123B | Mistral AI | [Mistral AI 2023](https://mistral.ai/news/announcing-mistral-7b/)                                                                  |\n| Mixtral MoE | 8x22B | Mistral AI | [Mistral AI 2024](https://mistral.ai/news/mixtral-8x22b/)                                                                         |\n| OLMo | 1B, 7B | Allen Institute for AI (AI2) | [Groeneveld et al. 2024](https://aclanthology.org/2024.acl-long.841/)    |\n| OpenLLaMA | 3B, 7B, 13B | OpenLM Research | [Geng \u0026 Liu 2023](https://github.com/openlm-research/open_llama)                                                         |\n| Phi 1.5 \u0026 2 | 1.3B, 2.7B | Microsoft Research  | [Li et al. 2023](https://arxiv.org/abs/2309.05463)                                                                  |\n| Phi 3 | 3.8B | Microsoft Research | [Abdin et al. 2024](https://arxiv.org/abs/2404.14219)                                                                            |\n| Phi 4 | 14B | Microsoft Research | [Abdin et al. 2024](https://arxiv.org/abs/2412.08905)                                                                            |\n| Platypus | 7B, 13B, 70B |  Lee et al. | [Lee, Hunter, and Ruiz 2023](https://arxiv.org/abs/2308.07317)                                                               |\n| Pythia | {14,31,70,160,410}M, {1,1.4,2.8,6.9,12}B | EleutherAI | [Biderman et al. 2023](https://arxiv.org/abs/2304.01373)                                            |\n| Qwen2.5 | 0.5B, 1.5B, 3B, 7B, 14B, 32B, 72B | Alibaba Group | [Qwen Team 2024](https://qwenlm.github.io/blog/qwen2.5/)                                               |\n| Qwen2.5 Coder | 0.5B, 1.5B, 3B, 7B, 14B, 32B | Alibaba Group | [Hui, Binyuan et al. 2024](https://arxiv.org/abs/2409.12186)                                          |\n| Qwen2.5 Math | 1.5B, 7B, 72B | Alibaba Group | [An, Yang et al. 2024](https://arxiv.org/abs/2409.12122)                                          |\n| QwQ | 32B | Alibaba Group | [Qwen Team 2024](https://qwenlm.github.io/blog/qwq-32b-preview/)                                                                         |\n| R1 Distill Llama | 8B, 70B | DeepSeek AI | [DeepSeek AI 2025](https://github.com/deepseek-ai/DeepSeek-R1/blob/main/DeepSeek_R1.pdf)                                                                                 |\n| SmolLM2 | 135M, 360M, 1.7B | Hugging Face | [Hugging Face 2024](https://github.com/huggingface/smollm)                                                               |\n| Salamandra | 2B, 7B | Barcelona Supercomputing Centre | [BSC-LTC 2024](https://github.com/BSC-LTC/salamandra)                                                                         |\n| StableCode | 3B | Stability AI | [Stability AI 2023](https://stability.ai/blog/stablecode-llm-generative-ai-coding)                                                  |\n| StableLM  | 3B, 7B | Stability AI | [Stability AI 2023](https://github.com/Stability-AI/StableLM)                                                                    |\n| StableLM Zephyr | 3B | Stability AI | [Stability AI 2023](https://stability.ai/blog/stablecode-llm-generative-ai-coding)                                             |\n| TinyLlama | 1.1B | Zhang et al. | [Zhang et al. 2023](https://github.com/jzhang38/TinyLlama)                                                                         |\n\n\n**Tip**: You can list all available models by running the `litgpt download list` command.\n\n\n\u003c/details\u003e\n\n\u0026nbsp;\n\n---\n\n# Workflows\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#finetune-an-llm\"\u003eFinetune\u003c/a\u003e •\n  \u003ca href=\"#pretrain-an-llm\"\u003ePretrain\u003c/a\u003e •\n  \u003ca href=\"#continue-pretraining-an-llm\"\u003eContinued pretraining\u003c/a\u003e •\n    \u003ca href=\"#evaluate-an-llm\"\u003eEvaluate\u003c/a\u003e •\n    \u003ca href=\"#deploy-an-llm\"\u003eDeploy\u003c/a\u003e •\n    \u003ca href=\"#test-an-llm\"\u003eTest\u003c/a\u003e\n\u003c/p\u003e\n\n\u0026nbsp;\n\nUse the command line interface to run advanced workflows such as pretraining or finetuning on your own data.\n\n\n## All workflows\nAfter installing LitGPT, select the model and workflow to run (finetune, pretrain, evaluate, deploy, etc...):\n\n```bash\n# ligpt [action] [model]\nlitgpt  serve     meta-llama/Llama-3.2-3B-Instruct\nlitgpt  finetune  meta-llama/Llama-3.2-3B-Instruct\nlitgpt  pretrain  meta-llama/Llama-3.2-3B-Instruct\nlitgpt  chat      meta-llama/Llama-3.2-3B-Instruct\nlitgpt  evaluate  meta-llama/Llama-3.2-3B-Instruct\n```\n\n\u0026nbsp;\n\n----\n\n## Finetune an LLM\n\n\u003cdiv align=\"center\"\u003e\n\u003ca target=\"_blank\" href=\"https://lightning.ai/lightning-ai/studios/litgpt-finetune\"\u003e\n  \u003cimg src=\"https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/app-2/run-on-studio.svg\" height=\"36px\" alt=\"Run on Studios\"/\u003e\n\u003c/a\u003e\n\u003c/div\u003e\n\n\u0026nbsp;\n\nFinetuning is the process of taking a pretrained AI model and further training it on a smaller, specialized dataset tailored to a specific task or application.\n\n\n\u0026nbsp;\n\n```bash\n# 0) setup your dataset\ncurl -L https://huggingface.co/datasets/ksaw008/finance_alpaca/resolve/main/finance_alpaca.json -o my_custom_dataset.json\n\n# 1) Finetune a model (auto downloads weights)\nlitgpt finetune microsoft/phi-2 \\\n  --data JSON \\\n  --data.json_path my_custom_dataset.json \\\n  --data.val_split_fraction 0.1 \\\n  --out_dir out/custom-model\n\n# 2) Test the model\nlitgpt chat out/custom-model/final\n\n# 3) Deploy the model\nlitgpt serve out/custom-model/final\n```\n\n[Read the full finetuning docs](tutorials/finetune.md)\n\n\u0026nbsp;\n\n----\n\n## Deploy an LLM\n\n\u003cdiv align=\"center\"\u003e\n\u003ca target=\"_blank\" href=\"https://lightning.ai/lightning-ai/studios/litgpt-serve\"\u003e\n  \u003cimg src=\"https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/app-2/deploy-on-studios.svg\" height=\"36px\" alt=\"Deploy on Studios\"/\u003e\n\u003c/a\u003e\n\u003c/div\u003e\n\n\u0026nbsp;\n\nDeploy a pretrained or finetune LLM to use it in real-world applications. Deploy, automatically sets up a web server that can be accessed by a website or app.\n\n```bash\n# deploy an out-of-the-box LLM\nlitgpt serve microsoft/phi-2\n\n# deploy your own trained model\nlitgpt serve path/to/microsoft/phi-2/checkpoint\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eShow code to query server:\u003c/summary\u003e\n\n\u0026nbsp;\n\nTest the server in a separate terminal and integrate the model API into your AI product:\n```python\n# 3) Use the server (in a separate Python session)\nimport requests, json\nresponse = requests.post(\n    \"http://127.0.0.1:8000/predict\",\n    json={\"prompt\": \"Fix typos in the following sentence: Example input\"}\n)\nprint(response.json()[\"output\"])\n```\n\u003c/details\u003e\n\n[Read the full deploy docs](tutorials/deploy.md).\n\n\u0026nbsp;\n\n----\n\n## Evaluate an LLM\nEvaluate an LLM to test its performance on various tasks to see how well it understands and generates text. Simply put, we can evaluate things like how well would it do in college-level chemistry, coding, etc... (MMLU, Truthful QA, etc...)\n\n```bash\nlitgpt evaluate microsoft/phi-2 --tasks 'truthfulqa_mc2,mmlu'\n```\n\n[Read the full evaluation docs](tutorials/evaluation.md).\n\n\u0026nbsp;\n\n----\n\n##  Test an LLM\n\n\u003cdiv align=\"center\"\u003e\n\u003ca target=\"_blank\" href=\"https://lightning.ai/lightning-ai/studios/litgpt-chat\"\u003e\n  \u003cimg src=\"https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/app-2/run-on-studio.svg\" height=\"36px\" alt=\"Run on Studios\"/\u003e\n\u003c/a\u003e\n\u003c/div\u003e\n\n\u0026nbsp;\n\nTest how well the model works via an interactive chat. Use the `chat` command to chat, extract embeddings, etc...\n\nHere's an example showing how to use the Phi-2 LLM:\n```bash\nlitgpt chat microsoft/phi-2\n\n\u003e\u003e Prompt: What do Llamas eat?\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eFull code:\u003c/summary\u003e\n\n\u0026nbsp;\n\n```bash\n# 1) List all supported LLMs\nlitgpt download list\n\n# 2) Use a model (auto downloads weights)\nlitgpt chat microsoft/phi-2\n\n\u003e\u003e Prompt: What do Llamas eat?\n```\n\nThe download of certain models requires an additional access token. You can read more about this in the [download](tutorials/download_model_weights.md#specific-models-and-access-tokens) documentation.\n\n\u003c/details\u003e\n\n[Read the full chat docs](tutorials/inference.md).\n\n\u0026nbsp;\n\n----\n\n## Pretrain an LLM\n\n\u003cdiv align=\"center\"\u003e\n\u003ca target=\"_blank\" href=\"https://lightning.ai/lightning-ai/studios/litgpt-pretrain\"\u003e\n  \u003cimg src=\"https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/app-2/run-on-studio.svg\" height=\"36px\" alt=\"Run on Studios\"/\u003e\n\u003c/a\u003e\n\u003c/div\u003e\n\n\u0026nbsp;\n\nPretraining is the process of teaching an AI model by exposing it to a large amount of data before it is fine-tuned for specific tasks.\n\n\u003cdetails\u003e\n  \u003csummary\u003eShow code:\u003c/summary\u003e\n\n\u0026nbsp;\n\n```bash\nmkdir -p custom_texts\ncurl https://www.gutenberg.org/cache/epub/24440/pg24440.txt --output custom_texts/book1.txt\ncurl https://www.gutenberg.org/cache/epub/26393/pg26393.txt --output custom_texts/book2.txt\n\n# 1) Download a tokenizer\nlitgpt download EleutherAI/pythia-160m \\\n  --tokenizer_only True\n\n# 2) Pretrain the model\nlitgpt pretrain EleutherAI/pythia-160m \\\n  --tokenizer_dir EleutherAI/pythia-160m \\\n  --data TextFiles \\\n  --data.train_data_path \"custom_texts/\" \\\n  --train.max_tokens 10_000_000 \\\n  --out_dir out/custom-model\n\n# 3) Test the model\nlitgpt chat out/custom-model/final\n```\n\u003c/details\u003e\n\n[Read the full pretraining docs](tutorials/pretrain.md)\n\n\u0026nbsp;\n\n----\n\n## Continue pretraining an LLM\n\n\u003cdiv align=\"center\"\u003e\n\u003ca target=\"_blank\" href=\"https://lightning.ai/lightning-ai/studios/litgpt-continue-pretraining\"\u003e\n  \u003cimg src=\"https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/app-2/run-on-studio.svg\" height=\"36px\" alt=\"Run on Studios\"/\u003e\n\u003c/a\u003e\n\u003c/div\u003e\n\n\u0026nbsp;\n\nContinued pretraining is another way of finetuning that specializes an already pretrained model by training on custom data:\n\n\u003cdetails\u003e\n  \u003csummary\u003eShow code:\u003c/summary\u003e\n\n\u0026nbsp;\n\n```bash\nmkdir -p custom_texts\ncurl https://www.gutenberg.org/cache/epub/24440/pg24440.txt --output custom_texts/book1.txt\ncurl https://www.gutenberg.org/cache/epub/26393/pg26393.txt --output custom_texts/book2.txt\n\n# 1) Continue pretraining a model (auto downloads weights)\nlitgpt pretrain EleutherAI/pythia-160m \\\n  --tokenizer_dir EleutherAI/pythia-160m \\\n  --initial_checkpoint_dir EleutherAI/pythia-160m \\\n  --data TextFiles \\\n  --data.train_data_path \"custom_texts/\" \\\n  --train.max_tokens 10_000_000 \\\n  --out_dir out/custom-model\n\n# 2) Test the model\nlitgpt chat out/custom-model/final\n```\n\n\u003c/details\u003e\n\n[Read the full continued pretraining docs](tutorials/pretrain.md#continued-pretraining-on-custom-data)\n\n\u0026nbsp;\n\n----\n\n# State-of-the-art features\n\n✅ State-of-the-art optimizations: Flash Attention v2, multi-GPU support via fully-sharded data parallelism, [optional CPU offloading](tutorials/oom.md#do-sharding-across-multiple-gpus), and [TPU and XLA support](extensions/xla).\u003c/br\u003e\n✅ [Pretrain](tutorials/pretrain.md), [finetune](tutorials/finetune.md), and [deploy](tutorials/inference.md)\u003c/br\u003e\n✅ Reduce compute requirements with low-precision settings: FP16, BF16, and FP16/FP32 mixed.\u003c/br\u003e\n✅ Lower memory requirements with [quantization](tutorials/quantize.md): 4-bit floats, 8-bit integers, and double quantization.\u003c/br\u003e\n✅ [Configuration files](config_hub) for great out-of-the-box performance.\u003c/br\u003e\n✅ Parameter-efficient finetuning: [LoRA](tutorials/finetune_lora.md), [QLoRA](tutorials/finetune_lora.md), [Adapter](tutorials/finetune_adapter.md), and [Adapter v2](tutorials/finetune_adapter.md).\u003c/br\u003e\n✅ [Exporting](tutorials/convert_lit_models.md) to other popular model weight formats.\u003c/br\u003e\n✅ Many popular datasets for [pretraining](tutorials/pretrain.md) and [finetuning](tutorials/prepare_dataset.md), and [support for custom datasets](tutorials/prepare_dataset.md#preparing-custom-datasets-for-instruction-finetuning).\u003c/br\u003e\n✅ Readable and easy-to-modify code to experiment with the latest research ideas.\u003c/br\u003e\n\n\u0026nbsp;\n\n---\n\n# Training recipes\n\nLitGPT comes with validated recipes (YAML configs) to train models under different conditions.  We've generated these recipes based on the parameters we found to perform the best for different training conditions.\n\nBrowse all training recipes [here](config_hub).\n\n### Example\n\n```bash\nlitgpt finetune \\\n  --config https://raw.githubusercontent.com/Lightning-AI/litgpt/main/config_hub/finetune/llama-2-7b/lora.yaml\n```\n\u003cdetails\u003e\n  \u003csummary\u003e✅ Use configs to customize training\u003c/summary\u003e\n\nConfigs let you customize training for all granular parameters like:\n\n```yaml\n# The path to the base model's checkpoint directory to load for finetuning. (type: \u003cclass 'Path'\u003e, default: checkpoints/stabilityai/stablelm-base-alpha-3b)\ncheckpoint_dir: checkpoints/meta-llama/Llama-2-7b-hf\n\n# Directory in which to save checkpoints and logs. (type: \u003cclass 'Path'\u003e, default: out/lora)\nout_dir: out/finetune/qlora-llama2-7b\n\n# The precision to use for finetuning. Possible choices: \"bf16-true\", \"bf16-mixed\", \"32-true\". (type: Optional[str], default: null)\nprecision: bf16-true\n\n...\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e✅ Example: LoRA finetuning config\u003c/summary\u003e\n\n\u0026nbsp;\n\n```yaml\n# The path to the base model's checkpoint directory to load for finetuning. (type: \u003cclass 'Path'\u003e, default: checkpoints/stabilityai/stablelm-base-alpha-3b)\ncheckpoint_dir: checkpoints/meta-llama/Llama-2-7b-hf\n\n# Directory in which to save checkpoints and logs. (type: \u003cclass 'Path'\u003e, default: out/lora)\nout_dir: out/finetune/qlora-llama2-7b\n\n# The precision to use for finetuning. Possible choices: \"bf16-true\", \"bf16-mixed\", \"32-true\". (type: Optional[str], default: null)\nprecision: bf16-true\n\n# If set, quantize the model with this algorithm. See ``tutorials/quantize.md`` for more information. (type: Optional[Literal['nf4', 'nf4-dq', 'fp4', 'fp4-dq', 'int8-training']], default: null)\nquantize: bnb.nf4\n\n# How many devices/GPUs to use. (type: Union[int, str], default: 1)\ndevices: 1\n\n# How many nodes to use. (type: int, default: 1)\nnum_nodes: 1\n\n# The LoRA rank. (type: int, default: 8)\nlora_r: 32\n\n# The LoRA alpha. (type: int, default: 16)\nlora_alpha: 16\n\n# The LoRA dropout value. (type: float, default: 0.05)\nlora_dropout: 0.05\n\n# Whether to apply LoRA to the query weights in attention. (type: bool, default: True)\nlora_query: true\n\n# Whether to apply LoRA to the key weights in attention. (type: bool, default: False)\nlora_key: false\n\n# Whether to apply LoRA to the value weights in attention. (type: bool, default: True)\nlora_value: true\n\n# Whether to apply LoRA to the output projection in the attention block. (type: bool, default: False)\nlora_projection: false\n\n# Whether to apply LoRA to the weights of the MLP in the attention block. (type: bool, default: False)\nlora_mlp: false\n\n# Whether to apply LoRA to output head in GPT. (type: bool, default: False)\nlora_head: false\n\n# Data-related arguments. If not provided, the default is ``litgpt.data.Alpaca``.\ndata:\n  class_path: litgpt.data.Alpaca2k\n  init_args:\n    mask_prompt: false\n    val_split_fraction: 0.05\n    prompt_style: alpaca\n    ignore_index: -100\n    seed: 42\n    num_workers: 4\n    download_dir: data/alpaca2k\n\n# Training-related arguments. See ``litgpt.args.TrainArgs`` for details\ntrain:\n\n  # Number of optimizer steps between saving checkpoints (type: Optional[int], default: 1000)\n  save_interval: 200\n\n  # Number of iterations between logging calls (type: int, default: 1)\n  log_interval: 1\n\n  # Number of samples between optimizer steps across data-parallel ranks (type: int, default: 128)\n  global_batch_size: 8\n\n  # Number of samples per data-parallel rank (type: int, default: 4)\n  micro_batch_size: 2\n\n  # Number of iterations with learning rate warmup active (type: int, default: 100)\n  lr_warmup_steps: 10\n\n  # Number of epochs to train on (type: Optional[int], default: 5)\n  epochs: 4\n\n  # Total number of tokens to train on (type: Optional[int], default: null)\n  max_tokens:\n\n  # Limits the number of optimizer steps to run (type: Optional[int], default: null)\n  max_steps:\n\n  # Limits the length of samples (type: Optional[int], default: null)\n  max_seq_length: 512\n\n  # Whether to tie the embedding weights with the language modeling head weights (type: Optional[bool], default: null)\n  tie_embeddings:\n\n  #   (type: float, default: 0.0003)\n  learning_rate: 0.0002\n\n  #   (type: float, default: 0.02)\n  weight_decay: 0.0\n\n  #   (type: float, default: 0.9)\n  beta1: 0.9\n\n  #   (type: float, default: 0.95)\n  beta2: 0.95\n\n  #   (type: Optional[float], default: null)\n  max_norm:\n\n  #   (type: float, default: 6e-05)\n  min_lr: 6.0e-05\n\n# Evaluation-related arguments. See ``litgpt.args.EvalArgs`` for details\neval:\n\n  # Number of optimizer steps between evaluation calls (type: int, default: 100)\n  interval: 100\n\n  # Number of tokens to generate (type: Optional[int], default: 100)\n  max_new_tokens: 100\n\n  # Number of iterations (type: int, default: 100)\n  max_iters: 100\n\n# The name of the logger to send metrics to. (type: Literal['wandb', 'tensorboard', 'csv'], default: csv)\nlogger_name: csv\n\n# The random seed to use for reproducibility. (type: int, default: 1337)\nseed: 1337\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e✅ Override any parameter in the CLI:\u003c/summary\u003e\n\n```bash\nlitgpt finetune \\\n  --config https://raw.githubusercontent.com/Lightning-AI/litgpt/main/config_hub/finetune/llama-2-7b/lora.yaml \\\n  --lora_r 4\n```\n\u003c/details\u003e\n\n\u0026nbsp;\n\n----\n\n# Project highlights\n\nLitGPT powers many great AI projects, initiatives, challenges and of course enterprises. Please submit a pull request to be considered for a feature.\n\n\u003cdetails\u003e\n  \u003csummary\u003e📊 SAMBA: Simple Hybrid State Space Models for Efficient Unlimited Context Language Modeling\u003c/summary\u003e\n\nThe [Samba](https://github.com/microsoft/Samba) project by researchers at Microsoft is built on top of the LitGPT code base and combines state space models with sliding window attention, which outperforms pure state space models.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e🏆 NeurIPS 2023 Large Language Model Efficiency Challenge: 1 LLM + 1 GPU + 1 Day\u003c/summary\u003e\n\nThe LitGPT repository was the official starter kit for the [NeurIPS 2023 LLM Efficiency Challenge](https://llm-efficiency-challenge.github.io), which is a competition focused on finetuning an existing non-instruction tuned LLM for 24 hours on a single GPU.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e🦙 TinyLlama: An Open-Source Small Language Model\u003c/summary\u003e\n\n\nLitGPT powered the [TinyLlama project](https://github.com/jzhang38/TinyLlama) and [TinyLlama: An Open-Source Small Language Model](https://arxiv.org/abs/2401.02385) research paper.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e🍪 MicroLlama: MicroLlama-300M\u003c/summary\u003e\n\n[MicroLlama](https://github.com/keeeeenw/MicroLlama) is a 300M Llama model pretrained on 50B tokens powered by TinyLlama and LitGPT.\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e🔬 Pre-training Small Base LMs with Fewer Tokens\u003c/summary\u003e\n\nThe research paper [\"Pre-training Small Base LMs with Fewer Tokens\"](https://arxiv.org/abs/2404.08634), which utilizes LitGPT, develops smaller base language models by inheriting a few transformer blocks from larger models and training on a tiny fraction of the data used by the larger models. It demonstrates that these smaller models can perform comparably to larger models despite using significantly less training data and resources.\n\n\u003c/details\u003e\n\n\u0026nbsp;\n\n----\n\n# Community\n\nWe welcome all individual contributors, regardless of their level of experience or hardware. Your contributions are valuable, and we are excited to see what you can accomplish in this collaborative and supportive environment.\n\n- [Request a feature](https://github.com/Lightning-AI/litgpt/issues)\n- [Submit your first contribution](https://lightning.ai/pages/community/tutorial/how-to-contribute-to-litgpt/)\n- [Join our Discord](https://discord.gg/VptPCZkGNa)\n\n\u0026nbsp;\n\n# Tutorials\n\n🚀 [Get started](tutorials/0_to_litgpt.md)\u003c/br\u003e\n⚡️ [Finetuning, incl. LoRA, QLoRA, and Adapters](tutorials/finetune.md)\u003c/br\u003e\n🤖 [Pretraining](tutorials/pretrain.md)\u003c/br\u003e\n💬 [Model evaluation](tutorials/evaluation.md)\u003c/br\u003e\n📘 [Supported and custom datasets](tutorials/prepare_dataset.md)\u003c/br\u003e\n🧹 [Quantization](tutorials/quantize.md)\u003c/br\u003e\n🤯 [Tips for dealing with out-of-memory (OOM) errors](tutorials/oom.md)\u003c/br\u003e\n🧑🏽‍💻 [Using cloud TPUs](extensions/xla)\u003c/br\u003e\n\n\u0026nbsp;\n\n----\n\n### Acknowledgments\n\nThis implementation extends on [Lit-LLaMA](https://github.com/lightning-AI/lit-llama) and [nanoGPT](https://github.com/karpathy/nanoGPT), and it's **powered by [Lightning Fabric](https://lightning.ai/docs/fabric/stable/) ⚡**.\n\n- [@karpathy](https://github.com/karpathy) for [nanoGPT](https://github.com/karpathy/nanoGPT)\n- [@EleutherAI](https://github.com/EleutherAI) for [GPT-NeoX](https://github.com/EleutherAI/gpt-neox) and the [Evaluation Harness](https://github.com/EleutherAI/lm-evaluation-harness)\n- [@TimDettmers](https://github.com/TimDettmers) for [bitsandbytes](https://github.com/TimDettmers/bitsandbytes)\n- [@Microsoft](https://github.com/microsoft) for [LoRA](https://github.com/microsoft/LoRA)\n- [@tridao](https://github.com/tridao) for [Flash Attention 2](https://github.com/Dao-AILab/flash-attention)\n\n### License\n\nLitGPT is released under the [Apache 2.0](https://github.com/Lightning-AI/litgpt/blob/main/LICENSE) license.\n\n### Citation\n\nIf you use LitGPT in your research, please cite the following work:\n\n```bibtex\n@misc{litgpt-2023,\n  author       = {Lightning AI},\n  title        = {LitGPT},\n  howpublished = {\\url{https://github.com/Lightning-AI/litgpt}},\n  year         = {2023},\n}\n```\n\n\u0026nbsp;\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLightning-AI%2Flitgpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLightning-AI%2Flitgpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLightning-AI%2Flitgpt/lists"}