• Stars
    star
    10,409
  • Rank 3,310 (Top 0.07 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

20+ high-performance LLMs with recipes to pretrain, finetune and deploy at scale.
Lit-GPT

⚡ Lit-GPT

cpu-tests license Discord

Lit-GPT and pineapple pizza

 

⚡ Lit-GPT

Hackable implementation of state-of-the-art open-source large language models released under the Apache 2.0 license.

Supports the following popular model checkpoints:

Model and usage Reference
Meta AI Llama 2 Touvron et al. 2023
Stability AI FreeWilly2 Stability AI 2023
Stability AI StableCode Stability AI 2023
TII UAE Falcon TII 2023
OpenLM Research OpenLLaMA Geng & Liu 2023
LMSYS Vicuna Li et al. 2023
LMSYS LongChat LongChat Team 2023
Together RedPajama-INCITE Together 2023
EleutherAI Pythia Biderman et al. 2023
StabilityAI StableLM Stability AI 2023
Platypus Lee, Hunter, and Ruiz 2023
NousResearch Nous-Hermes Org page
Meta AI Code Llama Rozière et al. 2023

This implementation extends on Lit-LLaMA and nanoGPT, and it's powered by Lightning Fabric.

 


🏆 NeurIPS 2023 Large Language Model Efficiency Challenge: 1 LLM + 1 GPU + 1 Day

The Lit-GPT repository is the official starter kit for the NeurIPS 2023 LLM Efficiency Challenge, which is a competition focused on finetuning an existing non-instruction tuned LLM for 24 hours on a single GPU. The competition has two tracks, one for the A100 and another for the 4090 GPUs.

If you are interested in participating, you can learn more about the NeurIPS LLM Efficiency Challenge on the official website here. Also see the Lit-GPT NeurIPS Challenge Quickstart Guide for helpful tips.

The submission deadline is Oct 15th, 2023.


 

Lit-GPT design principles

This repository follows the main principle of openness through clarity.

Lit-GPT is:

  • Simple: Single-file implementation without boilerplate.
  • Correct: Numerically equivalent to the original model.
  • Optimized: Runs fast on consumer hardware or at scale.
  • Open-source: No strings attached.

Avoiding code duplication is not a goal. Readability and hackability are.

 

Get involved!

Join our Discord to build high-performance, truly open-source models for the common benefit of the community.

 

Setup

Clone the repo

git clone https://github.com/Lightning-AI/lit-gpt
cd lit-gpt

Lit-GPT currently relies on flash attention from PyTorch nightly. Until PyTorch 2.1 is released you'll need to install nightly manually. Luckily this is straightforward, as shown below.

 

On CUDA

pip install --index-url https://download.pytorch.org/whl/nightly/cu118 --pre 'torch>=2.1.0dev'

On CPU (incl Macs)

pip install --index-url https://download.pytorch.org/whl/nightly/cpu --pre 'torch>=2.1.0dev'

(Optional) install Flash Attention 2

MAX_JOBS=4 pip install 'flash-attn>=2.0.0.post1' --no-build-isolation

All good, now install the dependencies plus some optional ones:

pip install -r requirements.txt tokenizers sentencepiece

You are all set! 🎉

 

Use the model

To generate text predictions, you need to download the model weights. If you don't have them, check out our guide.

Run inference:

python generate/base.py --prompt "Hello, my name is"

This will run the 3B pretrained model and require ~7 GB of GPU memory using the bfloat16 datatype.

Full guide for generating samples from the model.

You can also chat with the model interactively:

python chat/base.py

 

Run large models on smaller consumer devices

We support 4-bit quantization (as in QLoRA), LLM.int8, and GPTQ.int4 inference by following this guide.

 

Finetune the model

We provide a simple training scripts (finetune/adapter.py, finetune/adapter_v2.py, and finetune/lora.py) that instruction-tunes a pretrained model on the Alpaca dataset.

  1. Download the data and generate an instruction tuning dataset:
python scripts/prepare_alpaca.py
  1. Run the finetuning script

For example, you can either use

Adapter (Zhang et al. 2023):

python finetune/adapter.py

or Adapter v2 (Gao et al. 2023):

python finetune/adapter_v2.py

or LoRA (Hu et al. 2021):

python finetune/lora.py

(Please see the tutorials/finetune_adapter for details on the differences between the two adapter methods.)

The finetuning requires at least one GPU with ~12 GB memory (RTX 3060).

It is expected that you have downloaded the pretrained weights as described above. More details about each finetuning method and how you can apply it to your own data can be found in our technical how-to guides.

 

Finetuning how-to guides

These technical tutorials illustrate how to run the finetuning code.

 

Understanding finetuning -- conceptual tutorials

Looking for conceptual tutorials and explanations? We have some additional articles below:

 

Pretraining

We provide simple training scripts based on Fabric if you want to venture into pretraining. Conversion scripts for our optimized streaming PackedDataset are included.

Follow this guide to start pretraining on

 

Supported datasets

Lit-GPT includes a variety of dataset preparation scripts for finetuning and pretraining. Additional information about the datasets and dataset preparation is provided in the Preparing Datasets tutorial.

 

XLA

Lightning AI has partnered with Google to add first-class support for Cloud TPUs in Lightning’s frameworks and Lit-GPT, helping democratize AI for millions of developers and researchers worldwide.

Using TPUs with Lightning is as straightforward as changing one line of code.

We provide scripts fully optimized for TPUs in the XLA directory

 

Get involved!

We are on a quest towards fully open source AI.

Lit-GPT

Join us and start contributing, especially on the following areas:

We 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.

Unsure about contributing? Check out our How to Contribute to Lit-GPT and Lit-LLaMA guide.

Don't forget to join our Discord!

 

Acknowledgements

 

License

Lit-GPT is released under the Apache 2.0 license.

More Repositories

1

pytorch-lightning

Pretrain, finetune ANY AI model of ANY size on multiple GPUs, TPUs with zero code changes.
Python
28,208
star
2

lit-llama

Implementation of the LLaMA language model based on nanoGPT. Supports flash attention, Int8 and GPTQ 4bit quantization, LoRA and LLaMA-Adapter fine-tuning, pre-training. Apache 2.0-licensed.
Python
5,973
star
3

LitServe

Lightning-fast serving engine for any AI model of any size. Flexible. Easy. Enterprise-scale.
Python
2,278
star
4

torchmetrics

Machine learning metrics for distributed, scalable PyTorch applications.
Python
2,117
star
5

deep-learning-project-template

Pytorch Lightning code guideline for conferences
Python
1,236
star
6

lightning-thunder

Make PyTorch models up to 40% faster! Thunder is a source to source compiler for PyTorch. It enables using different hardware executors at once; across one or thousands of GPUs.
Python
1,178
star
7

litdata

Transform datasets at scale. Optimize datasets for fast AI model training.
Python
347
star
8

dl-fundamentals

Deep Learning Fundamentals -- Code material and exercises
Jupyter Notebook
342
star
9

tutorials

Collection of Pytorch lightning tutorial form as rich scripts automatically transformed to ipython notebooks.
Python
286
star
10

engineering-class

Lightning Bits: Engineering for Researchers repo
Python
131
star
11

utilities

Common Python utilities and GitHub Actions in Lightning Ecosystem
Python
50
star
12

lightning-ColossalAI

Large Scale Distributed Model Training with Colossal AI and Lightning AI
Python
50
star
13

ecosystem-ci

Automate issue discovery for your projects against Lightning nightly and releases.
Python
45
star
14

forked-pdb

Python pdb for multiple processes
Python
30
star
15

lightning-Habana

Lightning support for Intel Habana accelerators.
Python
25
star
16

lightning-Hivemind

Lightning Training strategy for HiveMind
Python
9
star
17

lightning-Graphcore

Python
7
star
18

Lightning-multinode-templates

Multinode templates for Pytorch Lightning
Python
7
star
19

LAI-E2E-ContinualAI-Emulator

Python
6
star
20

lightning-ui

Frontend for Lightning apps and home of the Design System
TypeScript
4
star
21

lightning-gan

Python
3
star
22

e2e-speed-benchmark-tests

Tests scripts which ensure that app startup times do not regress
Python
2
star
23

lightning-Horovod

Lightning Training strategy for Horovod
Python
2
star
24

LAI-lightning-template-jupyterlab-App

Python
1
star
25

cloud-training-workshop

Jupyter Notebook
1
star