This project aims to fine-tune the Flan-T5 language model using Hugging Face's Transformers library. By following these steps, you can fine-tune the model and use it for inference.
Before getting started, make sure you have the following:
- Hugging Face API token (HF token)
- Python installed on your system
- CUDA-enabled GPU (for training)
-
Clone this repository to your local machine.
git clone https://github.com/mltrev23/Fine-Tuning-LLaMA-2/
-
Install the required packages using the following command:
pip install -r requirements.txt
There are four methods of fine-tuning available:
-
Additive Fine-Tuning: Adds layers to train.
python additive-fine-tuning.py
-
Full Fine-Tuning: Trains all weights of the model.
python full-fine-tuning.py
-
Selective Fine-Tuning: Chooses specific layers of the original model to train.
python selective-fine-tuning.py
-
Template Fine-Tuning: Uses a predefined template for training. The template can be modified as needed.
To ingest your own data for fine-tuning, modify the code in your scripts to load your dataset. Here’s an example of loading a text dataset:
from transformers import LineByLineTextDataset
dataset = LineByLineTextDataset(tokenizer=tokenizer, file_path='datasets/bittensor.txt', block_size=128)
To perform inference using the fine-tuned Flan-T5 model, you can use the following scripts:
-
Generate Using Forward Pass: This script demonstrates generating text using a forward pass approach.
python generate-using-forward.py
-
Main Inference Script: This script provides a straightforward way to generate outputs from the model.
python main.py
You can modify the input text in the main.py
file to test the model:
input_text = ["What is FAANG?"]
This will generate an output based on the input provided.
Feel free to modify the scripts as needed for your specific tasks and datasets. If you encounter any issues, check the Hugging Face documentation or seek help from the community.
- Title and Introduction: Describes the purpose of the project.
- Prerequisites: Lists necessary requirements.
- Setup: Instructions for cloning the repo, setting up the environment, and installing dependencies.
- Fine-tuning Methods: Details the four methods available for fine-tuning.
- Custom Data Ingestion: Provides an example of how to load custom datasets.
- Inference: Explains how to run inference with the fine-tuned model, including example scripts.
- Conclusion: Encourages users to modify scripts and seek help if needed.
Feel free to adjust any sections further based on your specific needs!