This is a custom project from Stanford CS224N Winter 2023 class. The goal of this project is to answer this question
Will alignment from human feedback also help small language models such as GPT-2?
And the answer is YES! With RLHF, evaluation shows that ChatGPT prefers the aligned GPT-2 outputs for 96% of times over the vanilla GPT-2 outputs, and 88% times over the supervised fine-tuning baseline. Please see the technical report for more details.
Also, you can test minChatGPT in Colab Notebook
Disclaimer:

src
|_train_ppo.py # training script for PPO
|_train_rm.py # trianing script for Reward Model
|_train_sft.py # training script for SFT model
|_tariners.py # the actual training loops and other trainer utilities, such as saving states
|_loss.py # loss functions used in different training
|_main.py # some scratch code to quickly test something
|_gpt.py # GPT-2 implementation with LoRA
|_evaluate.py # evaluate the generation with ChatGPT
|_dataset.py # multiple datasets definition
|_tokenizer.py # tokenizers in a unified class
|_llama.py # wish I could have more time to test with LLaMA
init_debian.sh # in case you need to initialize a debian system from scratch
requirements.txt # dependencies without PyTorch! Install your own pytorch 2.0 nightly.
First of all, you should know that ChatGPT (or InstructGPT, which is the last open publication on this topic from OpenAI) has three stages: Supervised Fine-tuning, Reward Model Training and RL with Human Feedback (with Proximal Policy Gradient). Here's a diagram from the InstructGPT paper:

pip install -r requirements.txt
src directory, run this command. You can change batch size via -b. The bigger VRAM you have the larger batch size you can afford. Optionally, you can open the tensorboard.ipynb to check the training progress.python train_sft.py --n experiment_name -b 2`
sft_ in your runs directory. Find the final model weights and run this. This should start a reward model training for 1 epoch and generate a directory started with rm_ with weights in it.python train_rm.py -b 2 -n experiment_name -p "./runs/path/to/your/weights"
ppo_.python train_rm.py -b 2 -n experiment_name -a "./runs/path/to/sft/weights" -c "./runs/path/to/reward_model/weights" -s naive
src, run this:python evaluate.py -s "/path/to/sft/model" -p "/path/to/ppo/model"
just in case you need this:
@misc{minChatGPT,
author = {Yanjia Li},
title = {minChatGPT: A minimum example of aligning language models with RLHF similar to ChatGPT},
year = {2023},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/ethanyanjiali/minChatGPT}},
}
This project wouldn't been done without the help from:
49 commits
Python
97.3%
Jupyter Notebook
1.9%
This is a custom project from Stanford CS224N Winter 2023 class. The goal of this project is to answer this question
Will alignment from human feedback also help small language models such as GPT-2?
And the answer is YES! With RLHF, evaluation shows that ChatGPT prefers the aligned GPT-2 outputs for 96% of times over the vanilla GPT-2 outputs, and 88% times over the supervised fine-tuning baseline. Please see the technical report for more details.
Also, you can test minChatGPT in Colab Notebook
Disclaimer:

src
|_train_ppo.py # training script for PPO
|_train_rm.py # trianing script for Reward Model
|_train_sft.py # training script for SFT model
|_tariners.py # the actual training loops and other trainer utilities, such as saving states
|_loss.py # loss functions used in different training
|_main.py # some scratch code to quickly test something
|_gpt.py # GPT-2 implementation with LoRA
|_evaluate.py # evaluate the generation with ChatGPT
|_dataset.py # multiple datasets definition
|_tokenizer.py # tokenizers in a unified class
|_llama.py # wish I could have more time to test with LLaMA
init_debian.sh # in case you need to initialize a debian system from scratch
requirements.txt # dependencies without PyTorch! Install your own pytorch 2.0 nightly.
First of all, you should know that ChatGPT (or InstructGPT, which is the last open publication on this topic from OpenAI) has three stages: Supervised Fine-tuning, Reward Model Training and RL with Human Feedback (with Proximal Policy Gradient). Here's a diagram from the InstructGPT paper:

pip install -r requirements.txt
src directory, run this command. You can change batch size via -b. The bigger VRAM you have the larger batch size you can afford. Optionally, you can open the tensorboard.ipynb to check the training progress.python train_sft.py --n experiment_name -b 2`
sft_ in your runs directory. Find the final model weights and run this. This should start a reward model training for 1 epoch and generate a directory started with rm_ with weights in it.python train_rm.py -b 2 -n experiment_name -p "./runs/path/to/your/weights"
ppo_.python train_rm.py -b 2 -n experiment_name -a "./runs/path/to/sft/weights" -c "./runs/path/to/reward_model/weights" -s naive
src, run this:python evaluate.py -s "/path/to/sft/model" -p "/path/to/ppo/model"
just in case you need this:
@misc{minChatGPT,
author = {Yanjia Li},
title = {minChatGPT: A minimum example of aligning language models with RLHF similar to ChatGPT},
year = {2023},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/ethanyanjiali/minChatGPT}},
}
This project wouldn't been done without the help from:
49 commits
Python
97.3%
Jupyter Notebook
1.9%