Skip to content

A modular and extensible LoRA fine-tuning framework for question-answering tasks with PEFT integration

Notifications You must be signed in to change notification settings

bhimanbaghel/lora-fine-tuning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LoRA Fine-tuning Example for QA Dataset

This is an easy and structured LoRA fine-tuning codebase, which can be extended for complex tasks.

Purpose

This example demonstrates how to perform LoRA fine-tuning on a QA task using a test dataset.

Structure

LoRAExample/
├── lora_example.py          # Main training script (simplified version of lora.py)
├── src/                     # Core modules
│   ├── __init__.py
│   ├── args.py              # Command line arguments (LoRA-only)
│   ├── models.py            # Model loading and LoRA configuration
│   ├── data.py              # dataset loading
│   ├── dataset_preparation.py # Data preprocessing
│   ├── metrics.py           # Non-binary accuracy calculation
│   ├── training.py          # Simplified training loop
│   └── evaluation.py        # Model evaluation
├── example_config.json      # Example model configuration
├── requirements.txt         # Dependencies
└── README.md               # This file

Usage

Basic Training:

python lora_example.py

With Model Saving:

python lora_example.py --save_model

Evaluation Only:

python lora_example.py --eval

Key Parameters

LoRA Configuration:

  • --lora_r: Rank of LoRA matrices (default: 1)
  • --lora_alpha: LoRA scaling factor (default: 2)
  • --lora_dropout: Dropout for LoRA layers (default: 0.1)

Training Parameters:

  • --learning_rate: Learning rate (default: 2e-4)
  • --batch_size: Batch size (default: 2)
  • --num_train_epochs: Number of epochs (default: 5)
  • --gradient_accumulation_steps: Gradient accumulation (default: 8)
  • --early_stopping_patience: Early stopping patience (default: 2)

Dataset Requirements

This example expects the dataset to be located at:

./data/

The dataset should be in JSON format with the following structure:

[
    {
        "question": "Legal text or question",
        "answer": "Classification label",
    },
    ...
]

Model Configuration

The example expects a model configuration file (e.g., ./hparam/example_config.json) with:

{
    "model_name": "Llama-3.2-3B",
    "model_path": "/path/to/model"
}

Output

The training script will:

  1. Load and preprocess the dataset
  2. Apply LoRA to the base model
  3. Train with the specified parameters
  4. Evaluate on the test set
  5. Save results to tuning_results_single.csv
  6. Optionally save the best model checkpoint

Dependencies

Key dependencies include:

  • torch
  • transformers
  • peft
  • datasets
  • pandas
  • numpy
  • thefuzz

This simplified version serves as a clean example of how to implement LoRA fine-tuning for legal text classification tasks without the complexity of the full research codebase.

About

A modular and extensible LoRA fine-tuning framework for question-answering tasks with PEFT integration

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages