Coder Social home page Coder Social logo

tmbdev-forks / flan-alpaca Goto Github PK

View Code? Open in Web Editor NEW

This project forked from declare-lab/flan-alpaca

0.0 1.0 0.0 23 KB

This repository contains code for extending the Stanford Alpaca synthetic instruction tuning to existing instruction-tuned models such as Flan-T5.

License: Apache License 2.0

Python 100.00%

flan-alpaca's Introduction

๐Ÿฎ ๐Ÿฆ™ Flan-Alpaca: Instruction Tuning from Humans and Machines

This repository contains code for extending the Stanford Alpaca synthetic instruction tuning to existing instruction-tuned models such as Flan-T5. The pretrained models and demos are available on HuggingFace ๐Ÿค— :

Model Parameters Training GPUs
Flan-Alpaca-Base 220M 1x A6000
Flan-Alpaca-Large 770M 1x A6000
Flan-Alpaca-XL 3B 1x A6000
Flan-Alpaca-XXL 11B 4x A6000 (FSDP)
Flan-GPT4All-XL 3B 1x A6000

Why?

Alpaca represents an exciting new direction to approximate the performance of large language models (LLMs) like ChatGPT cheaply and easily. Concretely, they leverage an LLM such as GPT-3 to generate instructions as synthetic training data. The synthetic data which covers more than 50k tasks can then be used to finetune a smaller model. However, the original implementation is less accessible due to licensing constraints of the underlying LLaMA model. Furthermore, users have noted potential noise in the synthetic dataset. Hence, it may be better to explore a fully accessible model that is already trained on high-quality (but less diverse) instructions such as Flan-T5.

Usage

from transformers import pipeline

prompt = "Write an email about an alpaca that likes flan"
model = pipeline(model="declare-lab/flan-alpaca-xl")
model(prompt, max_length=128, do_sample=True)

# Dear AlpacaFriend,
# My name is Alpaca and I'm 10 years old.
# I'm excited to announce that I'm a big fan of flan!
# We like to eat it as a snack and I believe that it can help with our overall growth.
# I'd love to hear your feedback on this idea. 
# Have a great day! 
# Best, AL Paca

Setup

Install dependencies and download data. We used the cleaned data from Alpaca-LoRA for training.

conda create -n paca python=3.8 -y
conda activate paca
pip install -r requirements.txt
mkdir -p data
wget https://raw.githubusercontent.com/tatsu-lab/stanford_alpaca/main/alpaca_data.json -O data/alpaca.json
wget https://raw.githubusercontent.com/tloen/alpaca-lora/main/alpaca_data_cleaned.json -O data/alpaca_clean.json

Preprocess training dataset:

python data_loading.py preprocess_alpaca \
--path_in data/alpaca_clean.json \
--path_out data/train.json

If you want to use GPT4All data instead of Alpaca data, you can use this command:

python data_loading.py preprocess_gpt4all

In the training command below, replace data/train.json with data/train_gpt4all.json

Training

The following command will finetune the Flan-T5-XL (8hrs on a single A6000 GPU).

python training.py --output_dir outputs/model/xl \
--use_compile \
--train_epochs 3 \
--data_path data/train.json \
--model_name_or_path "google/flan-t5-xl" \
--train_batch_size 1 \
--gradient_accumulation_steps 64

If the model does not fit into memory, and you have multiple GPUs, you can try fully-sharded data parallel by replacing --use_compile with --use_fsdp.

Inference

python inference.py test_model \
--path "outputs/model/xl/epoch=2-step=2436.ckpt" \
--prompt "Write an email about an alpaca that likes flan"

Exporting to HuggingFace Hub

Replace declare-lab/flan-alpaca-xl with your desired HuggingFace repo.

huggingface-cli login

python inference.py export_to_hub \
--path "outputs/model/xl/epoch=2-step=2436.ckpt" \
--repo declare-lab/flan-alpaca-xl

flan-alpaca's People

Contributors

chiayewken avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.