Skip to content

mxagar/llm_peft_fine_tuning_example

Repository files navigation

Applying Parameter-Efficient Fine-Tuning (PEFT) to a Large Language Model (LLM)

This example project shows how to fine-tune a Large Language Model using the PEFT library from HuggingFace.

The HuggingFace library transformers in combination with peft makes it very easy to fine-tune Large Language Models (LLMs) for our specific tasks. This small project shows how to use those libraries end-to-end to perform a text classification task.

Specifically:

  • We use the ag_news dataset, which consists of 120k news texts, each of them with a label related to its associated topic: 'World', 'Sports', 'Business', 'Sci/Tech'.
  • The DistilBERT model is fine-tuned for the news classification task. In the process, Low-Rank Adaptation (LoRA) is used to accelerate the fine-tuning thanks to the peft library.

The underlying LLM is abstracted and easily handled thanks to the transformers library; the user only needs to understand basic concepts such as

  • Tokenization of text sequences
  • Embedding vectors of tokens and associated dimensions
  • The motivation and usage of the encoder & decoder modules in LLMs
  • Task-specific heads, such as classification

LLM Architecture Simplified

For a primer in those topics, you can visit

Setup

A recipe to set up a conda environment with the required dependencies:

# Create the necessary Python environment
conda env create -f conda.yaml
conda activate peft

# Compile and install all dependencies
pip-compile requirements.in
pip-sync requirements.txt

# If we need a new dependency,
# add it to requirements.in 
# And then:
pip-compile requirements.in
pip-sync requirements.txt

Notebook

The notebook llm_peft.ipynb contains all the code and explanations necessary to perform the aforementioned fine-tuning.

Interesting Links

About

Example project in which a Large Language Model is fine-tuned using PEFT.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published