liveBook · Manning

Low-rank adaptation

As explained in Building Reliable AI Systems

Low-Rank Adaptation is a parameter-efficient fine-tuning method that trains added low-rank matrices while keeping a pretrained model's weights frozen.

Low-rank adaptation (LoRA) fine-tunes a large pretrained model without updating all its weights. It freezes the base model and trains two small added matrices at selected parts of the model. This makes adaptation practical when full fine-tuning would demand too much memory or compute; it also avoids updating every weight, which can risk catastrophic forgetting. section 5.3.3

LoRA trains roughly 0.1–1% of a model’s parameters. The comparison reports about 95–99% of full fine-tuning performance with low memory use, versus full fine-tuning’s higher memory demand and maximum adaptation. Treat those figures as a method comparison, not a guarantee for a particular task. section 5.3.3

peft_config = LoraConfig(   #1
    r=8,                   #2
    lora_alpha=16,              #3
    target_modules=["q_proj", "v_proj"],  #4
    lora_dropout=0.1,           #5
    bias="none",                 #6
    task_type="CAUSAL_LM"        #7
)
model = get_peft_model(model, peft_config)

A PEFT configuration selects rank 8, alpha 16, dropout 0.1, and the attention projection modules q_proj and v_proj; get_peft_model attaches the adapters to the loaded model. section 5.3.4

Customer-support adaptation

Start with a conversational LLaMA-2-7B model and map a 1,000-example Bitext subset into instruction–response pairs about orders, shipping, and returns. Format each pair as a conversational training example, train with SFTTrainer, then try prompts about refunds, addresses, invoices, and order status. For a company deployment, the same mapping can use customer queries and agent responses from a CSV. section 5.3.4

QLoRA adds a memory-saving option: load the base model in 4-bit NF4 form during adapter training. Start from original full- or half-precision weights rather than an already pre-quantized model. For maintenance, set aside evaluation examples, track evaluation loss, and save the adapter-equipped model and tokenizer; reload the trained adapter with its base model. section 5.3.3 section 5.3.4

How Building Reliable AI Systems covers it

How deep it goes
Explains frozen weights and trainable matrices, then configures adapters in PEFT without deriving the underlying matrix mathematics.
Examples
Builds a LLaMA-2-7B customer-support assistant from Bitext instruction–response pairs and tests order, refund, and shipping prompts.
What it assumes
Assumes a pretrained conversational model and Python library workflow; shows how to prepare instruction–response data and configure adapters.
What you can do after
Apply it via PEFT and SFTTrainer to train, evaluate, save, and reload adapters for a pretrained conversational model.
How it connects
Connects LoRA to parameter-efficient fine-tuning, full fine-tuning, QLoRA, quantization, and supervised fine-tuning.

Also explained in

Compare how 9 books explain low-rank adaptation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Reliable AI Systems. The section links point to the parts of the book it draws on.