Git Product home page Git Product logo

llm-use-cases's Introduction

Introduction

This repository contains several cases study regarding Large Language Model (LLM)

Performance of fine-tuning methods

There are three main approaches to fine-tune a large language model (LLM): a) updating the model weights via traditional gradient descent, b) using a LoRA adapter, and c) replacing decision layers with domain-specific decision layers while freezing the main body of the LLM. This section investigates the performance of each fine-tuning approach.

Experiment Setup

We use Meta OPT-350m, a pre-trained LLM. The LLM is fine-tuned on IMDb, a dataset of 50,000 samples for sentiment analysis. The data is split into 25,000 samples for training and 25,000 samples for testing. In this experiment, we replace the model decision layer with a linear layer of 1,000 neurons to output a binary classification: negative or positive sentiment. We train the model using AdamW on the dataset for three epochs with a batch size of 8. The learning rate is set at 2e-5.

We compare three main approaches: a) traditional training (trad), b) fine-tuning the linear decision layer while the base LLM is frozen (linear), and c) using a low-rank adapter (LoRA).

Implementation Detail
  • dev-llm-finetune-sentimental-classification.ipynb fine-tuning a LLM for sentimental classification on idbm dataset

  • dev-llm-finetune-sentimental-classification-LORA.ipynb fine-tuning a LLM for sentimental classification on idbm dataset, with LORA adapter

  • dev-llm-finetune-sentimental-classification-Linear-basefrozen-promptengineer.ipynb, fine-tuning a LLM for sentimental classification on idbm dataset where base model is frozen and a prompt is added for few-shot training

  • dev-llm-finetune-sentimental-classification-Linear-basefrozen.ipynb, fine-tuning a LLM for sentimental classification on idbm dataset where base model is frozen and only a linear decision layer is trained.

Result

As expected, traditional fine-tuning results in the highest accuracy at 92%. The accuracy of LoRA is slightly lower at 89%, as LoRA focuses on fine-tuning the attention component of the model instead of adjusting the parameters of the whole network. We observe that the accuracy of the linear approach is significantly lower compared to the RNN baseline. This result suggests that extra caution should be taken when using the linear approach for fine-tuning.

We also measure the inference latency of the three approaches. We see a slight decrease in latency with LoRA compared to traditional fine-tuning. The latency of the linear approach is significantly lower.

llm-use-cases's People

Contributors

phananh1010 avatar

Watchers

 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.