GithubHelp home page GithubHelp logo

googofz / openthaigpt-finetune Goto Github PK

View Code? Open in Web Editor NEW

This project forked from openthaigpt/openthaigpt-finetune

0.0 0.0 0.0 20.77 MB

Finetune Code for OpenThaiGPT 1.0.0-beta

License: Apache License 2.0

Python 97.65% Dockerfile 2.35%

openthaigpt-finetune's Introduction

๐Ÿ‡น๐Ÿ‡ญ OpenThaiGPT 1.0.0-beta

OpenThaiGPT Version 1.0.0-beta is a 7B-parameter LLaMA model finetuned to follow Thai translated instructions below and makes use of the Huggingface LLaMA implementation.

Support

License

  • Source Code: Apache Software License 2.0.
  • Weight: For research use only (due to the Facebook LLama's Weight LICENSE).
  • Note that: A commercial use license for OpenThaiGPT 0.1.0 weight will be released later soon!

Code and Weight

Sponsors

Pantip.com, ThaiSC

Powered by

OpenThaiGPT Volunteers, Artificial Intelligence Entrepreneur Association of Thailand (AIEAT), and Artificial Intelligence Association of Thailand (AIAT)

Authors

Kobkrit Viriyayudhakorn ([email protected]), Sumeth Yuenyong ([email protected]) and Thaweewat Ruksujarit ([email protected]).

Disclaimer: Provided responses are not guaranteed.

Local Setup

  1. Install dependencies

    pip install -r requirements.txt
  2. If bitsandbytes doesn't work, install it from source. Windows users can follow these instructions.

Training (finetune.py)

This file contains a straightforward application of PEFT to the LLaMA model, as well as some code related to prompt construction and tokenization. PRs adapting this code to support larger models are always welcome.

Example usage:

python finetune.py \
    --base_model 'decapoda-research/llama-7b-hf' \
    --data_path 'Thaweewat/alpaca-cleaned-52k-th' \
    --output_dir './openthaigpt-010-beta'

We can also tweak our hyperparameters:

python finetune.py \
    --base_model 'decapoda-research/llama-7b-hf' \
    --data_path 'Thaweewat/alpaca-cleaned-52k-th' \
    --output_dir './openthaigpt-010-beta' \
    --batch_size 128 \
    --micro_batch_size 4 \
    --num_epochs 3 \
    --learning_rate 1e-4 \
    --cutoff_len 512 \
    --val_set_size 2000 \
    --lora_r 8 \
    --lora_alpha 16 \
    --lora_dropout 0.05 \
    --lora_target_modules '[q_proj,v_proj]' \
    --train_on_inputs \
    --group_by_length

Inference (generate.py)

This file reads the foundation model from the Hugging Face model hub and the LoRA weights from kobkrit/openthaigpt-0.1.0-beta, and runs a Gradio interface for inference on a specified input. Users should treat this as example code for the use of the model, and modify it as needed.

Example usage:

python generate.py \
    --load_8bit \
    --base_model 'decapoda-research/llama-7b-hf' \
    --lora_weights 'kobkrit/openthaigpt-0.1.0-beta'

Official weights

The most recent "official" OpenThaiGPT 0.1.0-beta adapter available at kobkrit/openthaigpt-0.1.0-beta was trained on May 13 with the following command:

python finetune.py \
    --base_model='decapoda-research/llama-7b-hf' \
    --data_path '../datasets/cleaned' \
    --num_epochs=3 \
    --cutoff_len=2048 \
    --group_by_length \
    --output_dir='./openthaigpt-010-beta' \
    --lora_target_modules='[q_proj,k_proj,v_proj,o_proj]' \
    --lora_r=64 \
    --batch_size=64 \
    --micro_batch_size=4

Checkpoint export (export_*_checkpoint.py)

These files contain scripts that merge the LoRA weights back into the base model for export to Hugging Face format and to PyTorch state_dicts. They should help users who want to run inference in projects like llama.cpp or alpaca.cpp.

Docker Setup & Inference

  1. Build the container image:
docker build -t openthaigpt-finetune-010beta .
  1. Run the container (you can also use finetune.py and all of its parameters as shown above for training):
docker run --gpus=all --shm-size 64g -p 7860:7860 -v ${HOME}/.cache:/root/.cache --rm openthaigpt-finetune-010beta generate.py \
    --load_8bit \
    --base_model 'decapoda-research/llama-7b-hf' \
    --lora_weights 'kobkrit/openthaigpt-0.1.0-beta'
  1. Open https://localhost:7860 in the browser

Docker Compose Setup & Inference

  1. (optional) Change desired model and weights under environment in the docker-compose.yml

  2. Build and run the container

docker-compose up -d --build
  1. Open https://localhost:7860 in the browser

  2. See logs:

docker-compose logs -f
  1. Clean everything up:
docker-compose down --volumes --rmi all

openthaigpt-finetune's People

Contributors

kobkrit avatar googofz 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.