Coder Social home page Coder Social logo

thekaranacharya / llm-fine-tuning Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 412 KB

Comparing popular Parameter Efficient Fine-Tuning (PEFT) techniques for Large Language Models

License: MIT License

Python 100.00%
adapter fine-tuning lora nlp peft-fine-tuning-llm transformers

llm-fine-tuning's Introduction

Parameter Efficient Fine-Tuning (PEFT) Techniques for LLMs: A Comparative Study

This project provides a detailed, from-scratch exploration and implementation of three popular PEFT techniques for fine-tuning large language models:

  • Simple Fine-Tuning: Unfreeze and fine-tune the last two layers (classification head)
  • Adapter Layers: Introduce small adapter modules in the transformer block.
  • LoRA (Low-Rank Adaptation): Efficiently fine-tune by injecting low-rank matrices across the network.

The primary focus is on deep understanding of the mechanics behind these techniques, rather than achieving state-of-the-art performance. The dataset used for the experiments is a binary text classification task, which you can replace with your own dataset.

πŸš€πŸš€πŸš€ Blog Post

The project is accompanied by a detailed blog post that provides a comprehensive overview of PEFT techniques, their implementation, and a comparative study of the three methods: Fine-tuning LLMs efficiently: A practical deepΒ dive

Key Goals

  • Understanding PEFT: Build a strong foundation in the theoretical underpinnings and practical implementation of PEFT methods.
  • Direct Comparison: Conduct rigorous experiments to compare the three PEFT techniques across various metrics.
  • Hands-On Implementation: Implement the techniques from scratch using PyTorch.
  • Reproducibility: Ensure that the experiments are reproducible and well-documented.
  • Insights and Findings: Draw key insights from the experiments and summarize the findings.
  • Educational Resource: Serve as a comprehensive educational resource for PEFT techniques.

Project Structure

  • data_utils/: Contains the the utility functions to load and preprocess the dataset.
    • Loads the data, tokenizes the text, and sets up the dataloaders.
  • modeling/: Houses the OOP implementation of the 3 PEFT techniques.
    • Simple Fine-Tuning
    • Adapter Layers
    • LoRA
  • evaluation/: Contains helpful utilies to save the experiment results and visualize them using plots.
  • finetuning.py: The main script to run the experiments.

Experiments

The experiments compare the PEFT techniques on the following metrics:

  • Training Accuracy and Loss
  • Test Accuracy and Loss
  • Percentage of Trainable Parameters
  • Training Time

Usage

  • Install the required packages using pip install -r requirements.txt.
  • Use a GPU for faster training. Check whether GPU is available using nvidia-smi.
  • Run the experiments using the command: python finetuning.py.

Details

Results and Findings

  • Simple Fine-Tuning:

    • Achieved a test accuracy of 87.96%.
    • Highest percentage of trainable parameters.
    • Slowest convergence.
  • Adapter Layers:

    • Achieved a test accuracy of 92.24%.
    • Lowest percentage of trainable parameters.
    • Fastest convergence compared to simple fine-tuning and LoRA.
  • LoRA:

    • Achieved a test accuracy of 91.6%.
    • Moderate percentage of trainable parameters, just lower than simple fine-tuning.
    • Faster convergence compared to simple fine-tuning.
  • Plots:

    Comparing trainable parameters Comparing training time
    Comparing test accuracy Comparing training accuracy

References

llm-fine-tuning's People

Contributors

thekaranacharya avatar

Watchers

Kostas Georgiou 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.