Home

Awesome

Bonito Experiments

Bonito is an open-source model for generating task-specific synthetic instruction tuning datasets conditioned on unannotated text.

This repo contains code to reproduce the experiments from the Bonito paper. For the Bonito package, see the bonito repo.

Table of Contents

Installation

To install all the relevant packages, run the following:

conda create -n bonito-experiments python==3.9
conda activate bonito-experiments
pip3 install -r requirements.txt

Training

To train models, run the following script:

deepspeed training/train_decoder.py --model_name_or_path mistralai/Mistral-7B-v0.1 --supervision_source bonito --dataset_name pubmed_qa --output_dir output/models/bonito_pubmed_qa_mistral

Options:

Notes:

  1. If you are using a multi-gpu environment, ensure you adjust the per_device_train_batch_size and gradient_accumulation_steps to achieve an effective batch size of 16.
  2. We train the model for 10,000 steps. If the dataset has fewer than 160,000 samples, then we train for 1 epoch.

Evaluation

We evaluate the pretrained and fine-tuned models on prompted datasets. We use ranked evaluation for pubmed_qa, privacy_qa, contract_nli, and vitaminc and SQuAD evaluation for squadshifts_nyt, squadshifts_amazon, and squadshifts_reddit. All the evaluation datasets are uploaded to BatsResearch/bonito-experiment-eval.

Ranked Evaluation

The following script evaluates the model on the target dataset:

deepspeed evaluation/evaluate_decoder.py --dataset_name pubmed_qa --model_name_or_path mistralai/Mistral-7B-v0.1 --checkpoint_model_id_or_path <checkpoint_path> --output_dir results/bonito-mistral-pubmed_qa --bf16

Options:

Additional options:

SQuAD Evaluation

The following script merges the base model with the checkpoint adapter and evaluates the model on five templates from the SQuADShifts dataset:

python3 evaluation/merge_and_evaluate_squad.py --dataset_name squadshifts_nyt --model_name_or_path mistralai/Mistral-7B-v0.1 --checkpoint_model_id_or_path <checkpoint_path> --output_dir results/bonito-mistral-squadshifts_nyt

Options:

Notes:

  1. We use SQuADShifts templates from promptsource.
  2. The merging operation saves a new model in the scratch directory. Change --scratch path to save the model in a different directory. Additionally ensure you have enough space to save the model.

Training the Bonito Model

Generating CTGA-v1 Training Dataset

To generate the CTGA-v1 dataset, run the following script:

python3 ctga/task_type_bonito.py --output_dir output/dataset/ctga-v1

Training

To train the Bonito model, run the following script:

deepspeed training/train_decoder.py --model_name_or_path mistralai/Mistral-7B-v0.1 --training_type="bonito_training" --dataset_name ctga-v1 --output_dir output/model/bonito_ctga-v1_mistral --max_steps 100000 --max_eval_samples 10000 --save_steps 10000 --save_total_limit 10

Generating Instruction Tuning Datasets with Bonito

To generate instruction tuning datasets, run the following script:

python3 generation/generate_data.py --model_name_or_path BatsResearch/bonito-v1 --output_dir output/dataset/contract_nli --dataset_name contract_nli --task_type nli

Options:

Credits

The training code is adapted from Q-LoRA. The evaluation code is adapted from t-zero.

Citation

If you use Bonito in your research, please cite the following paper:

@article{bonito:arxiv24,
  Author = {Nihal V. Nayak and Yiyang Nan and Avi Trost and Stephen H. Bach},
  Title = {Learning to Generate Instruction Tuning Datasets for Zero-Shot Task Adaptation},
  Volume = {arXiv:2402.18334 [cs.CL]},
  Year = {2024}}