Git Product home page Git Product logo

finetune-phi-2's Introduction

Fine-tuning Phi 2 for Persona-Grounded Chat

This project is a tutorial on parameter-efficient fine-tuning (PEFT) and quantization of the Phi 2 model for persona-grounded chat. We use LoRA for PEFT and 4-bit quantization to compress the model, and fine-tune the model on a new persona-based chat dataset - nazlicanto/persona-based-chat. Refer to the dataset page and Hugging Face model page for additional details.

Usage

Start by cloning the repository, setting up a conda environment and installing the dependencies. We tested our scripts with python 3.9 and CUDA 11.7.

git clone https://github.com/alaradirik/finetune-phi-2.git
cd finetune-phi-2

conda create -n llm python=3.9
conda activate llm
pip install -r requirements.txt

You can finetune the model on chat dataset or another dataset. Note that you will need to have the same features as our dataset and pass in your HF Hub token as an argument if using a private dataset. Fine-tuning takes about 9 hours on a single A40, you can either use the default accelerate settings or configure it to use multiple GPUs. To fine-tune the model:

accelerate config default

python finetune_phi.py --dataset=<HF_DATASET_ID_OR_PATH> --base_model="microsoft/phi-2" --model_name=<YOUR_MODEL_NAME> --auth_token=<HF_AUTH_TOKEN> --push_to_hub

One model training is completed, only the fine-tuned (LoRA) parameters are saved, which are loaded to overwrite the corresponding parameters of the base model during testing. To test the fine-tuned model with a random sample selected from the dataset, run python test.py.

License

The code and trained model are licensed under the MIT license.

finetune-phi-2's People

Contributors

alaradirik avatar

Stargazers

 avatar  avatar  avatar

Watchers

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