Apache License 2.0

项目介绍

declare-lab/flan-alpaca 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 Apache License 2.0 许可证,目前获得 357 个 Star、38 次 Fork。

仓库全名
declare-lab/flan-alpaca
开源许可证
Apache License 2.0
Star 数
357
Fork 数
38
未关闭 Issue
8

README 摘要

🍮 🦙 Flan-Alpaca: Instruction Tuning from Humans and Machines 📣 We developed Flacuna by fine-tuning Vicuna-13B on the Flan collection. Flacuna is better than Vicuna at problem-solving. Access the model here https://huggingface.co/declare-lab/flacuna-13b-v1.0. 📣 FLAN-T5 is also useful in text-to-audio generation. Find our work at https://github.com/declare-lab/tango if you are interested. This repository contains…

完整内容见 GitHub 原始 README 或本页 。

常见问题

flan-alpaca 用什么语言开发?

主要使用 Python 编写,采用 Apache License 2.0 许可证,目前有 357 个 Star。

flan-alpaca 可以免费商用吗?

仓库采用 Apache License 2.0 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 flan-alpaca 的源码?

可以直接克隆仓库:git clone https://github.com/declare-lab/flan-alpaca.git,默认分支为 main;安装与运行步骤见仓库 README。

flan-alpaca 最近还在维护吗?

仓库最近一次更新为 2023年7月5日,当前有 8 个未关闭 Issue;Star 数为 357,可作为社区活跃度的参考。

关于

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

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
790
价值分
260
活跃状态
活跃

语言占比

Python

Release

README

🍮 🦙 Flan-Alpaca: Instruction Tuning from Humans and Machines

📣 We developed Flacuna by fine-tuning Vicuna-13B on the Flan collection. Flacuna is better than Vicuna at problem-solving. Access the model here https://huggingface.co/declare-lab/flacuna-13b-v1.0.

📣 FLAN-T5 is also useful in text-to-audio generation. Find our work at https://github.com/declare-lab/tango if you are interested.

This repository contains code for extending the Stanford Alpaca synthetic instruction tuning to existing instruction-tuned models such as Flan-T5. We have a live interactive demo thanks to Joao Gante! We are also benchmarking many instruction-tuned models at declare-lab/flan-eval. Our pretrained models are fully available on HuggingFace 🤗 :

Model Parameters Instruction Data Training GPUs
Flan-Alpaca-Base 220M Flan, Alpaca 1x A6000
Flan-Alpaca-Large 770M Flan, Alpaca 1x A6000
Flan-Alpaca-XL 3B Flan, Alpaca 1x A6000
Flan-Alpaca-XXL 11B Flan, Alpaca 4x A6000 (FSDP)
Flan-GPT4All-XL 3B Flan, GPT4All 1x A6000
Flan-ShareGPT-XL 3B Flan, ShareGPT/Vicuna 1x A6000
Flan-Alpaca-GPT4-XL* 3B Flan, GPT4-Alpaca 1x A6000

*recommended for better performance

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-gpt4-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://github.com/declare-lab/flan-alpaca/releases/download/v0.1.0/alpaca_data.json -O data/alpaca.json
wget https://github.com/declare-lab/flan-alpaca/releases/download/v0.1.0/alpaca_data_cleaned.json -O data/alpaca_clean.json
wget https://github.com/declare-lab/flan-alpaca/releases/download/v0.1.0/alpaca_gpt4_data.json -O data/alpaca_gpt4.json

Preprocess Cleaned Alpaca training dataset:

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

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

python data_loading.py preprocess_gpt4all --path_out data/train.json

If you want to use ShareGPT data, you can use this command:

wget https://github.com/declare-lab/flan-alpaca/releases/download/v0.1.0/ShareGPT_unfiltered_cleaned_split.json -O data/sharegpt.json
python data_loading.py preprocess_sharegpt --path_out data/train.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 \
--max_source_length 64 \
--max_target_length 512 \
--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=2439.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=2439.ckpt" \
--repo declare-lab/flan-alpaca-xl

评论

暂无评论