• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    Jupyter Notebook
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

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

Repository Details

Train your own PetGPT at home!

PetGPT

Thanks to LLaMA and Alpaca-LoRA, you can train your own PetGPT at home. This GitHub repository offers a step by step guide in its README.md file.

LLaMA (Large Language Model Meta AI)

This repository assumes that you have already found a way to download the checkpoints and tokenizer for LLaMA (e.g., by filling out this google form). You should create a subdirectory (named LLaMA) within this repository having a structure similar to the following tree.

LLaMA
├── 13B
│   ├── checklist.chk
│   ├── consolidated.00.pth
│   ├── consolidated.01.pth
│   └── params.json
├── 30B
│   ├── checklist.chk
│   ├── consolidated.00.pth
│   ├── consolidated.01.pth
│   ├── consolidated.02.pth
│   ├── consolidated.03.pth
│   └── params.json
├── 65B
│   ├── checklist.chk
│   ├── consolidated.00.pth
│   ├── consolidated.01.pth
│   ├── consolidated.02.pth
│   ├── consolidated.03.pth
│   ├── consolidated.04.pth
│   ├── consolidated.05.pth
│   ├── consolidated.06.pth
│   ├── consolidated.07.pth
│   └── params.json
├── 7B
│   ├── checklist.chk
│   ├── consolidated.00.pth
│   └── params.json
├── llama.sh
├── tokenizer_checklist.chk
└── tokenizer.model

4 directories, 26 files

Clone the LLaMA repository to make sure that everything works as expected.

git clone https://github.com/facebookresearch/llama.git

The LLaMA repository is already included here for reproducibility purposes in the folder named llama. You can now run the following commands.

cd llama

torchrun --nproc_per_node 1 example.py --ckpt_dir ../LLaMA/7B --tokenizer_path ../LLaMA/tokenizer.model

Converting LLaMA to Hugging Face

Create an empty directory within this repository called LLaMA_HF. The following two scripts will then help you convert the LLaMA checkpoints and tokenizer to the Hugging Face format.

convert_llama_tokenizer_to_hf.ipynb
convert_llama_weights_to_hf.ipynb

These two scripts are simplied versions of convert_llama_weights_to_hf.py for pedagogical purposes.

This should result in a subdirectory (named LLaMA_HF) within this repository having a structure similar to the following tree.

LaMA_HF
├── config.json
├── generation_config.json
├── pytorch_model-00001-of-00002.bin
├── pytorch_model-00002-of-00002.bin
├── pytorch_model.bin.index.json
├── special_tokens_map.json
├── tokenizer_config.json
└── tokenizer.model

Exploratory Data Analysis

Clone the Alpaca-LoRA repository.

git clone https://github.com/tloen/alpaca-lora.git

The Alpaca-LoRA repository is already included here for reproducibility purposes in the folder named alpaca-lora. Within this folder, there is a file called alpaca_data_cleaned.json. This file contains a cleaned and curated version of the dataset used to train the original Alpaca. The following script will help you explore this dataset and build some intuition.

exploratory_data_analysis.ipynb

Fine Tuning

You can now use the following commands to finetune the LLaMA model on the alpaca_data_cleaned.json dataset.

cd alpaca-lora

mkdir output

WORLD_SIZE=4 CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --nproc_per_node=4 --master_port=1234 finetune.py --base_model ../LLaMA_HF --data_path alpaca_data_cleaned.json --output_dir output

The command given above works for a machine with 4 GPUs. You should adjust it according to your own setup.

Once the finetuning process is finished, it will write the model artifacts in a folder called output.

alpaca-lora/output/
├── adapter_config.json
├── adapter_model.bin
├── checkpoint-1000
│   ├── optimizer.pt
│   ├── pytorch_model.bin
│   ├── rng_state_0.pth
│   ├── rng_state_1.pth
│   ├── rng_state_2.pth
│   ├── rng_state_3.pth
│   ├── scaler.pt
│   ├── scheduler.pt
│   ├── trainer_state.json
│   └── training_args.bin
├── checkpoint-600
│   ├── optimizer.pt
│   ├── pytorch_model.bin
│   ├── rng_state_0.pth
│   ├── rng_state_1.pth
│   ├── rng_state_2.pth
│   ├── rng_state_3.pth
│   ├── scaler.pt
│   ├── scheduler.pt
│   ├── trainer_state.json
│   └── training_args.bin
└── checkpoint-800
    ├── optimizer.pt
    ├── pytorch_model.bin
    ├── rng_state_0.pth
    ├── rng_state_1.pth
    ├── rng_state_2.pth
    ├── rng_state_3.pth
    ├── scaler.pt
    ├── scheduler.pt
    ├── trainer_state.json
    └── training_args.bin

3 directories, 32 files

Generating Text

Here is how you can interact with the finetuned model.

python generate.py --load_8bit --base_model ../LLaMA_HF --lora_weights output --share_gradio False

The final screen hosted on http://0.0.0.0:7860 will look like the following image.

More Repositories

1

PINNs

Physics Informed Deep Learning: Data-driven Solutions and Discovery of Nonlinear Partial Differential Equations
Python
3,524
star
2

Applied-Deep-Learning

Applied Deep Learning Course
3,054
star
3

HFM

Hidden Fluid Mechanics
Python
277
star
4

DeepHPMs

Deep Hidden Physics Models: Deep Learning of Nonlinear Partial Differential Equations
Python
260
star
5

FBSNNs

Forward-Backward Stochastic Neural Networks: Deep Learning of High-dimensional Partial Differential Equations
Python
139
star
6

HPM

Hidden physics models: Machine learning of nonlinear partial differential equations
MATLAB
137
star
7

DeepVIV

Deep Learning of Vortex Induced Vibrations
Python
83
star
8

NumericalGP

Numerical Gaussian Processes for Time-dependent and Non-linear Partial Differential Equations
MATLAB
65
star
9

MultistepNNs

Multistep Neural Networks for Data-driven Discovery of Nonlinear Dynamical Systems
Python
61
star
10

TutorialGP

Tutorial on Gaussian Processes
MATLAB
58
star
11

ParametricGP

Parametric Gaussian Process Regression for Big Data
Python
45
star
12

backprop

Backpropagation in Python, C++, and Cuda
C++
42
star
13

DeepLearningTutorial

Tutorial on a number of topics in Deep Learning
Python
33
star
14

ParametricGP-in-Matlab

Parametric Gaussian Process Regression for Big Data (Matlab Version)
MATLAB
26
star
15

PDE_GP

Machine learning of linear differential equations using Gaussian processes
MATLAB
24
star
16

Introduction-to-Machine-Learning-in-R

Introduction to Machine Learning in R
Jupyter Notebook
20
star
17

DeepTurbulence

Deep Learning of Turbulent Scalar Mixing
Mathematica
15
star
18

APPM_Colloquium

Applied Mathematics (APPM) Department Colloquium
8
star