Text Generation
Transformers
PyTorch
English
opt
deepspeed
chatgpt
sft
Inference Endpoints
text-generation-inference
Adam
feat: updated links
4e8b8a4
metadata
language:
  - en
tags:
  - deepspeed
  - chatgpt
  - opt
  - sft
license: apache-2.0

ChatGPT OPT 1.3B DeepSpeed Supervised fine tuning

fsalab-chat-opt-1.3b-sft-deepspeed

This model consists of the first step of a modified pipeline the to the traditional training process of Chat-GPT models, which is comprised of a three-step procedure of supervised fine tuning, reward model and RLHF.

This project's main goal was to make proper use of existing frameworks that revolve around the minimisation of training costs and thus the eventual improvements towards both the feasibility and usability of ChatGPT-like models. The framework selected here is DeepSpeed which has been instrumental in the development of this model and through this framework it was possible to train the ChatGPT-like model on much larger data-sets with a reasonable number of GPUs and consequently achieve significantly better performance.

This model follows the blog of ChatGPT and the paper of InstructGPT and especially the Microsoft DeepSpeed Chat Blog.

Our Training Methodology and Speedup Recipes

The training process simply involves a single python run of DeepSpeed-Chat which initiates the whole 3-step pipeline, saving all models in the process:

python train.py --actor-model facebook/opt-1.3b --reward-model facebook/opt-350m --deployment-type single_node

This pipeline can be broken up into three key steps:

  1. Supervised fine-tuning (SFT): In the first step we perform supervised fine tuning by taking the pretrained models, configuring them to use smaller learning rates and then subsequently trained on a labelled data-set.

  2. Reward Model (RM) fine-tuning: See here

  3. Reinforcement-learning from Human feedback (RLHF) fine-tuning: At the completion of the prior two steps, the final RLHF fine-tuning can be initiated. This involves the collection of both the fine-tuned model from step 1 and the reward model* from step 2 and train them on the data-set with comparisons. This generates both an actor and critic.

To view the details behind each step head into their respective links and view the model card there.

Supervised fine tuning training configuration:

Model Configurations:

Parameter Value
Parameters 1.3B
Model type OPT
FFN Dimensions 8192
Hidden Size 2048
Max Position Embedding 2048
Attention Heads 32
Hidden layers 24

Training Configurations:

Parameter Value
Train Batch size 32
Train micro batch size 4
ZeRO stage 2
FP16 True
Gradient clipping 1.0
Dropout 0.1
Bias True
Prescale gradients True

Installation

If using through the HuggingFace transformers library:

from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("FSALab/deepspeed-chatgpt-opt1.3b-sft")

model = AutoModelForCausalLM.from_pretrained("FSALab/deepspeed-chatgpt-opt1.3b-sft")

If you would like to clone from source:

# Make sure you have git-lfs installed (https://git-lfs.github.com)
git lfs install
git clone https://huggingface.co/FSALab/deepspeed-chatgpt-opt1.3b-sft

# if you want to clone without large files – just their pointers
# prepend your git clone with the following env var:
GIT_LFS_SKIP_SMUDGE=1

Why did we choose DeepSpeed?

DeepSpeed Training:

The main.py Python code take the DeepSpeed config with the argument --deepspeed_config ./ds_config.json.

We read up on the DeepSpeed documentation and created a specific coniguration based on their work. The json file ds_config.json here is set to take the ZeRO-2 stage and FP16, allowing must faster training and GPU memory saving. Note that ZeRO-2 is just one of the examples using our DeepSpeed. You may use ZeRO-1, Zero-3, ZeRO-Offload and ZeRO-infinity. For more information on DeepSpeed ZeRO family, please see this tutorial link for Zero-1/2/3 and this tutorial for Zero-Offload.

To enable the DeepSpeed Zero family training, we injected several lines of code in order to enable this i.e.:

model, optimizer, _, lr_scheduler = deepspeed.initialize(model=model, \
  optimizer=optimizer, \
  args=args,       \
  lr_scheduler=lr_scheduler,  \
  dist_init_required=True)

Acknowledgements

We thank the following papers and open-source repositories. We especially thank DeepSpeed for their frameworks as well.