P

LoRA: Definition and Examples

LoRA (Low-Rank Adaptation) is an efficient fine-tuning technique that allows adapting a large language model or image generation model to a specific task by modifying only a tiny fraction of its parameters.

Full definition

LoRA, short for Low-Rank Adaptation, is a method for adapting artificial intelligence models developed by Microsoft researchers in 2021. Instead of retraining all billions of parameters of a model, LoRA injects small low-rank matrices into the neural network layers. This achieves results comparable to full fine-tuning while drastically reducing required resources (GPU memory, computation time, storage).

The principle is based on a mathematical observation: during fine-tuning, the modifications to model weights actually occupy a low-dimensional space. LoRA exploits this property by decomposing weight updates into two small matrices (A and B) whose product approximates the full update. Concretely, instead of modifying a weight matrix of size 10,000 × 10,000 (100 million parameters), two matrices of size 10,000 × 8 and 8 × 10,000 (160,000 parameters) are used, a reduction of over 99%.

In image generation, LoRA has become extremely popular with Stable Diffusion. Users create and share LoRAs trained on artistic styles, characters, or specific concepts. A LoRA file typically weighs only a few dozen megabytes, compared to several gigabytes for a full model, facilitating sharing and combination of multiple adaptations.

For language models (LLMs), LoRA enables companies and researchers to adapt models like LLaMA or Mistral to specific business domains (legal, medical, technical) without requiring expensive GPU servers. This democratization of fine-tuning has significantly accelerated the adoption of generative AI in various professional contexts.

Etymology

LoRA is an acronym for "Low-Rank Adaptation of Large Language Models," introduced in a research paper published by Edward Hu et al. at Microsoft Research in June 2021. The term "low-rank" refers to a linear algebra concept describing matrices that can be decomposed into products of smaller matrices.

Concrete examples

Fine-tuning an image generation model to reproduce a specific artistic style

a portrait of a woman in the style of lora:impressionist_style:0.8, oil painting, soft brushstrokes, natural lighting

Adapting an LLM to respond in a specialized legal domain

As a legal assistant specialized in French labor law, analyze the following non-compete clause and identify points of non-compliance with recent case law.

Combining multiple LoRAs for precise results in image generation

photo of a cyberpunk city at night lora:cyberpunk_architecture:0.7 lora:neon_lighting:0.5, 8k, detailed, cinematic composition

Practical usage

In prompt engineering, understanding LoRA allows leveraging specialized models for more accurate results without modifying prompts in complex ways. When a LoRA is active, it often suffices to use the associated activation keywords to trigger the learned style or behavior. For image generation, the LoRA weight (typically between 0.5 and 1.0) can be adjusted directly in the prompt to control the intensity of its effect.

Related concepts

Fine-tuningTransfer LearningStable DiffusionQLoRA

FAQ

What is the difference between LoRA and classic fine-tuning?
Classic fine-tuning modifies all model parameters, requiring a lot of GPU memory and computation time. LoRA only modifies a small fraction of parameters (often less than 1%) by injecting low-rank matrices, making the process much faster, cheaper, and accessible on consumer hardware. Results are often comparable in quality.
Can multiple LoRAs be used at the same time?
Yes, it is entirely possible to combine multiple LoRAs simultaneously, especially in image generation with Stable Diffusion. Each LoRA can be assigned a different weight to control its influence. However, combining too many LoRAs or using incompatible LoRAs can degrade result quality. It is recommended not to exceed 2 to 3 simultaneous LoRAs and to adjust their respective weights.
Do you need technical skills to use a LoRA?
To use a pre-trained LoRA, minimal skills are required: just load it into a compatible interface (like Automatic1111 or ComfyUI for images) and use the activation keywords in your prompts. On the other hand, creating your own LoRA requires knowledge of dataset preparation, training hyperparameter configuration, and access to a sufficiently powerful GPU (minimum 8 GB VRAM).

See also

How to use this prompt

  1. Copy the prompt with the button above.
  2. Paste it into ChatGPT, Claude or your favorite AI assistant.
  3. Replace the bracketed variables with your details, then refine the result.

About Prompt Guide

Prompt Guide is a free library of 2500+ ready-to-use prompts for ChatGPT, Claude and other AIs, with guides to learn prompting and tools to build and optimize your own prompts.

More definitions

Get new prompts every week

Join our newsletter.