This project is designed for fine-tuning language models using the Unsloth library with LoRA adapters, and it provides utilities for training, testing, and formatting data for various models like Phi-3, Gemma, and Meta-Llama.
Google Colab or a local environment with Python 3.x and CUDA support.
Installed packages like unsloth, huggingface_hub, peft, trl, and others (automatically installed in the notebooks).
NOTE GPU Requirements:
python
1models =[2'Phi-3.5-mini-instruct-bnb-4bit',# |Min Training Gpu : T4, Min Testing GPU: T4, Max Model size : 14.748 GB|3'gemma-2-27b-it-bnb-4bit',# |Min Training Gpu: A100, Min Testing GPU: L4, Max Model size: 39.564GB|4'Meta-Llama-3.1-8B-Instruct-bnb-4bit'# |Min Training Gpu: T4, Min Testing GPU: T4, Max Model size : 22.168GB|5]
This notebook is responsible for training a language model with LoRA adapters using the Unsloth library. The core functionality includes:
Loading a pre-trained model from Hugging Face using FastLanguageModel.
Attaching LoRA adapters for efficient fine-tuning of large models.
Setting training configurations (e.g., learning rate, number of epochs, batch size) using the SFTTrainer from the transformers library.
Optionally, resuming training from the last checkpoint.
Uploading checkpoints and models to Hugging Face during or after training.
How to Use:
Open this notebook in Google Colab or a similar environment.
Ensure you have set up your Hugging Face token (refer to the section below for setup).
Customize the training parameters if needed.
Run the notebook cells to train the model.
2. TESTER.ipynb
This notebook handles the evaluation of a fine-tuned model. It allows testing the model's accuracy and efficiency on a test dataset using pre-defined metrics like accuracy, precision, recall, and F1 score. It provides the following functionalities:
Loads the fine-tuned model with its LoRA adapters.
Defines a function to evaluate the model's predictions on a test dataset.
Outputs accuracy and other classification metrics.
Displays confusion matrices for better insight into model performance.
How to Use:
Load this notebook in your environment.
Specify the test dataset and model details.
Run the evaluation loop to get accuracy, predictions, and metrics visualizations.
3. dataFormat.ipynb
This notebook formats datasets into the correct structure for training and testing models. It provides functionality to map raw text data into a format suitable for language model training, particularly for multi-turn conversations:
Formats conversations into a chat-based template using Unsloth's chat_templates.
Maps data fields like "role", "content", and user/assistant conversations.
Prepares the dataset for tokenization and input to the model.
How to Use:
Open the notebook and specify the dataset you wish to format.
Adjust any template settings based on the model you're using.
Run the notebook to output the formatted dataset.
Usage
Environment Setup
Install Unsloth:
The following command is included in the notebooks to install Unsloth: