LogoLogo
Continuum WebsiteContinuum ApplicationsContinuum KnowledgeAxolotl Platform
Continuum Knowledge
Continuum Knowledge
  • Continuum
  • Data
    • Datasets
      • Pre Training Data
      • Types of Fine Tuning
      • Self Instruct Paper
      • Self-Alignment with Instruction Backtranslation
      • Systematic Evaluation of Instruction-Tuned Large Language Models on Open Datasets
      • Instruction Tuning
      • Instruction Fine Tuning - Alpagasus
      • Less is More For Alignment
      • Enhanced Supervised Fine Tuning
      • Visualising Data using t-SNE
      • UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction
      • Training and Evaluation Datasets
      • What is perplexity?
  • MODELS
    • Foundation Models
      • The leaderboard
      • Foundation Models
      • LLama 2 - Analysis
      • Analysis of Llama 3
      • Llama 3.1 series
      • Google Gemini 1.5
      • Platypus: Quick, Cheap, and Powerful Refinement of LLMs
      • Mixtral of Experts
      • Mixture-of-Agents (MoA)
      • Phi 1.5
        • Refining the Art of AI Training: A Deep Dive into Phi 1.5's Innovative Approach
      • Phi 2.0
      • Phi-3 Technical Report
  • Training
    • The Fine Tuning Process
      • Why fine tune?
        • Does Fine-Tuning LLMs on New Knowledge Encourage Hallucinations?
        • Explanations in Fine Tuning
      • Tokenization
        • Tokenization Is More Than Compression
        • Tokenization - SentencePiece
        • Tokenization explore
        • Tokenizer Choice For LLM Training: Negligible or Crucial?
        • Getting the most out of your tokenizer for pre-training and domain adaptation
        • TokenMonster
      • Parameter Efficient Fine Tuning
        • P-Tuning
          • The Power of Scale for Parameter-Efficient Prompt Tuning
        • Prefix-Tuning: Optimizing Continuous Prompts for Generation
        • Harnessing the Power of PEFT: A Smarter Approach to Fine-tuning Pre-trained Models
        • What is Low-Rank Adaptation (LoRA) - explained by the inventor
        • Low Rank Adaptation (Lora)
        • Practical Tips for Fine-tuning LMs Using LoRA (Low-Rank Adaptation)
        • QLORA: Efficient Finetuning of Quantized LLMs
        • Bits and Bytes
        • The Magic behind Qlora
        • Practical Guide to LoRA: Tips and Tricks for Effective Model Adaptation
        • The quantization constant
        • QLORA: Efficient Finetuning of Quantized Language Models
        • QLORA and Fine-Tuning of Quantized Language Models (LMs)
        • ReLoRA: High-Rank Training Through Low-Rank Updates
        • SLoRA: Federated Parameter Efficient Fine-Tuning of Language Models
        • GaLora: Memory-Efficient LLM Training by Gradient Low-Rank Projection
      • Hyperparameters
        • Batch Size
        • Padding Tokens
        • Mixed precision training
        • FP8 Formats for Deep Learning
        • Floating Point Numbers
        • Batch Size and Model loss
        • Batch Normalisation
        • Rethinking Learning Rate Tuning in the Era of Language Models
        • Sample Packing
        • Gradient accumulation
        • A process for choosing the learning rate
        • Learning Rate Scheduler
        • Checkpoints
        • A Survey on Efficient Training of Transformers
        • Sequence Length Warmup
        • Understanding Training vs. Evaluation Data Splits
        • Cross-entropy loss
        • Weight Decay
        • Optimiser
        • Caching
      • Training Processes
        • Extending the context window
        • PyTorch Fully Sharded Data Parallel (FSDP)
        • Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
        • YaRN: Efficient Context Window Extension of Large Language Models
        • Sliding Window Attention
        • LongRoPE
        • Reinforcement Learning
        • An introduction to reinforcement learning
        • Reinforcement Learning from Human Feedback (RLHF)
        • Direct Preference Optimization: Your Language Model is Secretly a Reward Model
  • INFERENCE
    • Why is inference important?
      • Grouped Query Attention
      • Key Value Cache
      • Flash Attention
      • Flash Attention 2
      • StreamingLLM
      • Paged Attention and vLLM
      • TensorRT-LLM
      • Torchscript
      • NVIDIA L40S GPU
      • Triton Inference Server - Introduction
      • Triton Inference Server
      • FiDO: Fusion-in-Decoder optimised for stronger performance and faster inference
      • Is PUE a useful measure of data centre performance?
      • SLORA
  • KNOWLEDGE
    • Vector Databases
      • A Comprehensive Survey on Vector Databases
      • Vector database management systems: Fundamental concepts, use-cases, and current challenges
      • Using the Output Embedding to Improve Language Models
      • Decoding Sentence-BERT
      • ColBERT: Efficient and Effective Passage Search via Contextualized Late Interaction over BERT
      • SimCSE: Simple Contrastive Learning of Sentence Embeddings
      • Questions Are All You Need to Train a Dense Passage Retriever
      • Improving Text Embeddings with Large Language Models
      • Massive Text Embedding Benchmark
      • RocketQAv2: A Joint Training Method for Dense Passage Retrieval and Passage Re-ranking
      • LLM2Vec: Large Language Models Are Secretly Powerful Text Encoders
      • Embedding and Fine-Tuning in Neural Language Models
      • Embedding Model Construction
      • Demystifying Embedding Spaces using Large Language Models
      • Fine-Tuning Llama for Multi-Stage Text Retrieval
      • Large Language Model Based Text Augmentation Enhanced Personality Detection Model
      • One Embedder, Any Task: Instruction-Finetuned Text Embeddings
      • Vector Databases are not the only solution
      • Knowledge Graphs
        • Harnessing Knowledge Graphs to Elevate AI: A Technical Exploration
        • Unifying Large Language Models and Knowledge Graphs: A Roadmap
      • Approximate Nearest Neighbor (ANN)
      • High Dimensional Data
      • Principal Component Analysis (PCA)
      • Vector Similarity Search - HNSW
      • FAISS (Facebook AI Similarity Search)
      • Unsupervised Dense Retrievers
    • Retrieval Augmented Generation
      • Retrieval-Augmented Generation for Large Language Models: A Survey
      • Fine-Tuning or Retrieval?
      • Revolutionising Information Retrieval: The Power of RAG in Language Models
      • A Survey on Retrieval-Augmented Text Generation
      • REALM: Retrieval-Augmented Language Model Pre-Training
      • Retrieve Anything To Augment Large Language Models
      • Generate Rather Than Retrieve: Large Language Models Are Strong Context Generators
      • Active Retrieval Augmented Generation
      • DSPy: LM Assertions: Enhancing Language Model Pipelines with Computational Constraints
      • DSPy: Compiling Declarative Language Model Calls
      • DSPy: In-Context Learning for Extreme Multi-Label Classification
      • Optimizing Instructions and Demonstrations for Multi-Stage Language Model Programs
      • HYDE: Revolutionising Search with Hypothetical Document Embeddings
      • Enhancing Recommender Systems with Large Language Model Reasoning Graphs
      • Retrieval Augmented Generation (RAG) versus fine tuning
      • RAFT: Adapting Language Model to Domain Specific RAG
      • Summarisation Methods and RAG
      • Lessons Learned on LLM RAG Solutions
      • Stanford: Retrieval Augmented Language Models
      • Overview of RAG Approaches with Vector Databases
      • Mastering Chunking in Retrieval-Augmented Generation (RAG) Systems
    • Semantic Routing
    • Resource Description Framework (RDF)
  • AGENTS
    • What is agency?
      • Rephrase and Respond: Let Large Language Models Ask Better Questions for Themselves
      • Types of Agents
      • The risk of AI agency
      • Understanding Personality in Large Language Models: A New Frontier in AI Psychology
      • AI Agents - Reasoning, Planning, and Tool Calling
      • Personality and Brand
      • Agent Interaction via APIs
      • Bridging Minds and Machines: The Legacy of Newell, Shaw, and Simon
      • A Survey on Language Model based Autonomous Agents
      • Large Language Models as Agents
      • AI Reasoning: A Deep Dive into Chain-of-Thought Prompting
      • Enhancing AI Reasoning with Self-Taught Reasoner (STaR)
      • Exploring the Frontier of AI: The "Tree of Thoughts" Framework
      • Toolformer: Revolutionising Language Models with API Integration - An Analysis
      • TaskMatrix.AI: Bridging Foundational AI Models with Specialised Systems for Enhanced Task Completion
      • Unleashing the Power of LLMs in API Integration: The Rise of Gorilla
      • Andrew Ng's presentation on AI agents
      • Making AI accessible with Andrej Karpathy and Stephanie Zhan
  • Regulation and Ethics
    • Regulation and Ethics
      • Privacy
      • Detecting AI Generated content
      • Navigating the IP Maze in AI: The Convergence of Blockchain, Web 3.0, and LLMs
      • Adverse Reactions to generative AI
      • Navigating the Ethical Minefield: The Challenge of Security in Large Language Models
      • Navigating the Uncharted Waters: The Risks of Autonomous AI in Military Decision-Making
  • DISRUPTION
    • Data Architecture
      • What is a data pipeline?
      • What is Reverse ETL?
      • Unstructured Data and Generatve AI
      • Resource Description Framework (RDF)
      • Integrating generative AI with the Semantic Web
    • Search
      • BM25 - Search Engine Ranking Function
      • BERT as a reranking engine
      • BERT and Google
      • Generative Engine Optimisation (GEO)
      • Billion-scale similarity search with GPUs
      • FOLLOWIR: Evaluating and Teaching Information Retrieval Models to Follow Instructions
      • Neural Collaborative Filtering
      • Federated Neural Collaborative Filtering
      • Latent Space versus Embedding Space
      • Improving Text Embeddings with Large Language Models
    • Recommendation Engines
      • On Interpretation and Measurement of Soft Attributes for Recommendation
      • A Survey on Large Language Models for Recommendation
      • Model driven recommendation systems
      • Recommender AI Agent: Integrating Large Language Models for Interactive Recommendations
      • Foundation Models for Recommender Systems
      • Exploring the Impact of Large Language Models on Recommender Systems: An Extensive Review
      • AI driven recommendations - harming autonomy?
    • Logging
      • A Taxonomy of Anomalies in Log Data
      • Deeplog
      • LogBERT: Log Anomaly Detection via BERT
      • Experience Report: Deep Learning-based System Log Analysis for Anomaly Detection
      • Log-based Anomaly Detection with Deep Learning: How Far Are We?
      • Deep Learning for Anomaly Detection in Log Data: A Survey
      • LogGPT
      • Adaptive Semantic Gate Networks (ASGNet) for log-based anomaly diagnosis
  • Infrastructure
    • The modern data centre
      • Enhancing Data Centre Efficiency: Strategies to Improve PUE
      • TCO of NVIDIA GPUs and falling barriers to entry
      • Maximising GPU Utilisation with Kubernetes and NVIDIA GPU Operator
      • Data Centres
      • Liquid Cooling
    • Servers and Chips
      • The NVIDIA H100 GPU
      • NVIDIA H100 NVL
      • Lambda Hyperplane 8-H100
      • NVIDIA DGX Servers
      • NVIDIA DGX-2
      • NVIDIA DGX H-100 System
      • NVLink Switch
      • Tensor Cores
      • NVIDIA Grace Hopper Superchip
      • NVIDIA Grace CPU Superchip
      • NVIDIA GB200 NVL72
      • Hopper versus Blackwell
      • HGX: High-Performance GPU Platforms
      • ARM Chips
      • ARM versus x86
      • RISC versus CISC
      • Introduction to RISC-V
    • Networking and Connectivity
      • Infiniband versus Ethernet
      • NVIDIA Quantum InfiniBand
      • PCIe (Peripheral Component Interconnect Express)
      • NVIDIA ConnectX InfiniBand adapters
      • NVMe (Non-Volatile Memory Express)
      • NVMe over Fabrics (NVMe-oF)
      • NVIDIA Spectrum-X
      • NVIDIA GPUDirect
      • Evaluating Modern GPU Interconnect
      • Scalable Hierarchical Aggregation and Reduction Protocol (SHARP)
      • Next-generation networking in AI environments
      • NVIDIA Collective Communications Library (NCCL)
    • Data and Memory
      • NVIDIA BlueField Data Processing Units (DPUs)
      • Remote Direct Memory Access (RDMA)
      • High Bandwidth Memory (HBM3)
      • Flash Memory
      • Model Requirements
      • Calculating GPU memory for serving LLMs
      • Transformer training costs
      • GPU Performance Optimisation
    • Libraries and Complements
      • NVIDIA Base Command
      • NVIDIA AI Enterprise
      • CUDA - NVIDIA GTC 2024 presentation
      • RAPIDs
      • RAFT
    • Vast Data Platform
      • Vast Datastore
      • Vast Database
      • Vast Data Engine
      • DASE (Disaggregated and Shared Everything)
      • Dremio and VAST Data
    • Storage
      • WEKA: A High-Performance Storage Solution for AI Workloads
      • Introduction to NVIDIA GPUDirect Storage (GDS)
        • GDS cuFile API
      • NVIDIA Magnum IO GPUDirect Storage (GDS)
      • Vectors in Memory
Powered by GitBook
LogoLogo

Continuum - Accelerated Artificial Intelligence

  • Continuum Website
  • Axolotl Platform

Copyright Continuum Labs - 2023

On this page

Was this helpful?

  1. Training
  2. The Fine Tuning Process
  3. Parameter Efficient Fine Tuning

What is Low-Rank Adaptation (LoRA) - explained by the inventor

Edward Hu

PreviousHarnessing the Power of PEFT: A Smarter Approach to Fine-tuning Pre-trained ModelsNextLow Rank Adaptation (Lora)

Last updated 12 months ago

Was this helpful?

Edward Hu, formerly a researcher at Microsoft, introduces Low Rank Adaptation (LoRa), a method to efficiently customise pretrained neural networks like diffusion models or language models.

LoRa enhances training speed and significantly reduces checkpoint sizes by fine-tuning a minimal number of parameters, maintaining the performance level of comprehensive fine-tuning.

Originating in early 2021 during Microsoft's collaboration with OpenAI, LoRa addressed the limitations of few-shot prompting and the prohibitive expense of full fine-tuning, especially for models with vast numbers of parameters.

LoRa operates by questioning the necessity and extent of parameter fine-tuning, using a 2D plane to illustrate the range of possible configurations. It controls matrix update expressivity through rank limitation, enabling substantial parameter reduction without compromising transformation capabilities.

This method proved nearly as effective as full fine-tuning but with vastly smaller storage and quicker deployment benefits.

LoRa's applicability extends beyond language models to any architecture involving matrix multiplication, offering a clear path for adjustment if underperformance occurs.

It significantly cuts down checkpoint sizes (e.g., reducing a 1 TB checkpoint to 25 MB) and allows for additional low-rank matrices without introducing inference latency.

The updates are additive, allowing seamless model switching and parallel training of multiple modules. LoRa's additive nature also supports hierarchical model specialization, enabling efficient, layered fine-tuning and rapid task or user-specific model adaptation.

Full Transcript

Low Rank Adaptation, or LoRa, allows you to efficiently customise pre trained neural networks, such as diffusion models or language models.

It speeds up training and drastically reduces the size of model checkpoints by training very few parameters compared to the base model, while preserving the performance of full fine tuning. And it has become one of the go to methods for customizing AI models.

My name is Edward Hu, and I led the invention of LoRa when I was a researcher at Microsoft. In this video, I'll share the research story behind LoRa, how I understand it, and its technical benefits.

My team at Microsoft was tasked with answering, can this GPU 3 stuff actually make money? Somewhat surprising finding was that few shot prompting was not enough to get even the largest models performed well enough for production, especially for tasks like natural language to code because it rarely appears in the training data.

Fine tuning through gradient updates was a necessity. However, full fine tuning is prohibitively expensive.

A single model checkpoint for the 175,000,000,000 parameter variant is 1 terabyte large, which is hard to store and takes minutes to load when deployed. And that's not gonna work when we need to switch among tasks and users rapidly. We tried many off the shelf, parameter efficient fine tuning methods, but all of them had a compromise for our case.

It was with product impact in mind that we invented LoRa.

So what is LoRa? I like to see it as a generalization of full fine tuning by asking 2 questions.

Question 1: Do we need to fine tune all the parameters?

Question 2: For the weight matrices we fine tune, how expressive should the updates be in terms of matrix rank?

We can turn these two questions into the 2 axes of a 2 d plane.

Full fine tuning is all the way in the upper right corner and the axes, including the origin, correspond to the original model. Any point in this box is a valid LoRa configuration. Let's quickly talk about how we control the expressivity of a matrix update by controlling its rank. A d by d matrix can represent any linear transformation in a d dimensional vector space.

However, if we start with a vector in Rd, first transform it to rr, where r is less than d, and finally transform it back to rd, we restrict the kind of linear transformations we can represent.

How does stopping by rr achieve that? Imagine an extreme case where r, or rank, equals 1. Whatever the input does boils down to just one number, which can only scale the output. By picking a small r, the kind of linear transformation we can represent is greatly limited, even though the output is still in rd.

Now, we only have to store 2 times d times r parameters instead of d squared. This is how LoRa stores matrix updates. Now back to the 2 d plane we talked about.

The surprising result of the LoRa paper is that a point near the origin performed just as well as full fine tuning all the way in the corner. Once we see LoRa as a generalization of full fine tuning, we can easily answer some commonly asked questions for using LoRa, such as how to choose the rank R, or when to use full fine tuning.

Since full fine tuning is a special case of LoRa, and we know that full fine tuning works, we can start with a point near the origin and work our way back to the corner. At some point, this has to work, and more likely than not, what ended up working will be near the origin. Otherwise, just give up and do full fine tuning. How might that happen? Let's consider a thought experiment.

If we take a language model pre trained on English and English only, but we wanna adapt it for some tasks, say in Martian. And let's say that English and Martian have little in common, since we're basically training a model all over again. Parameter efficient fine tuning methods shouldn't work too well, So we might as well do full fine tuning instead. Another question is, can I use LoRa for a certain model of architecture? Say a wave net or a support vector machine.

And by the way, nobody really asks about the latter, but as long as the model uses matrix multiplication, we can ask, do we need to fine tune all the parameters and how expressive should the updates be? As long as we can ask these 2 questions, we can use LoRa, which makes it very generally applicable. Indeed, while we invented LoRa for large language models, people later found it to be very effective for diffusion models as well. I wanna point out that one advantage of LoRa is that it's clear what to do next if underperformance. We adapt more parameters and increase the rank.

For approaches like prefix tuning, midfit, or adapter, it is not clear what we can do next because there isn't a knob to turn that allow these methods to recover full fine tuning, unlike LoRa. Now, let's dive into the specifics of the benefits of LoRa. The most visible one is a reduction of checkpoint sizes. On GP3, we reduce the checkpoint size from 1 terabyte down to 25 megabytes. This is a direct result of training much fewer parameters 4,700,000 in this case compared to 175,000,000,000.

Another important benefit is that LoRa doesn't introduce any inference latency. You might say, hold on, don't we have these additional low rank matrices on the side while that's truly trained? What happens during inference stats? Since LoRa updates are additive to the original parameters, we can expand the low rank matrices by multiplying out the low rank bottleneck and add the updates to the original parameters. Now, we can perform inference literally the same way as with a base model, and there is no additional latency by definition.

When we need to switch tasks, we simply repeat the process but this time subtract the updates. By being careful about numerical precisions, we can recover the original parameters and we repeat to load another LoRa module. This process can be done in parallel for all parameters and is faster than a single forward pass. This is how we can switch models quickly without introducing any additional inference latency. Finally, I want to mention a few engineering ideas enabled by LoRa.

The first one is to cache many LoRa modules in RAM during deployment. So model switching simply involves data transfer between RAM and VRAM. Since RAM is usually much larger than VRAM, we can cache thousands of LoRa modules and never worry about reading from the disk again. Another idea is to train multiple LoRa modules in parallel, each on its own task. This is achieved by sharing the same base model and routing different inputs in a single batch through different LoRa modules.

This way, we can batch different LoRa jobs together and fully utilize the GPUs. There are several community implementations of this, which are linked in the video description. The final idea uses the fact that LoRa models are additive. Imagine a pipeline where a pre trained model is gradually specialized, or maybe it's first fine tuned for a particular language, and then a particular domain, and finally a particular task or even a specific user. The adaptive models form a tree, Each non root node can be a Lua module on top of the sum of its ancestors.

The model rank can be larger near the root and smaller near the leaves to accommodate different dataset sizes. Model switching here becomes tree traversal and we never have to load the base model more than once. Let me know in the comments if you have any cool ideas on how LoRa can be used or extended or if you just have any questions. I'll see you in the next video.

LoRA explained by the genius inventor Edward Hu
Page cover image