Welcome to parameter-efficient fine-tuning, or PEFT: the discipline of adapting billion-parameter language models by updating a tiny trainable subset, while freezing the residual stream, attention projections, and feed-forward weights that already encode broad capability.
PEFT means optimizing a small parameter vector theta while the pretrained weights remain fixed; the objective is still the negative log likelihood of each token given its context, but gradients touch only adapters, not the full Jacobian.
LoRA, from Hu and colleagues in twenty twenty-one, approximates each weight update as a low-rank product, with rank far below the hidden dimension, so storage grows linearly with width instead of quadratically.
QLoRA, from Dettmers and colleagues in twenty twenty-three, freezes four-bit NormalFloat weights, backpropagates through a dequantized computation graph, and trains LoRA adapters with paged optimizers, fitting sixty-five-billion-parameter tuning on a single high-memory GPU.
The roadmap assumes transformers, layer normalization, causal masking, cross-entropy, and AdamW; we move from full fine-tuning baselines to adapters, LoRA, QLoRA, ablations of rank and alpha, and evaluation under limited memory.
The key claim is sharp: most capability lives in frozen pretrained weights, while adaptation is low-dimensional; next we quantify that claim, then implement and stress-test each method.
Equations, code and original cards
Course Introduction and Overview
• Parameter-Efficient Fine-Tuning (PEFT)
Definition: update a small adapter parameter set while pretrained weights stay frozen.
Importance: cuts optimizer states, gradient memory, and compute with minimal quality loss.
• LoRA: Low-Rank Adaptation
• Hu et al. 2021: learn update as low-rank product, rank r << hidden width.
• Trainable parameters scale as O(r·d), not O(d²); base weights unchanged.
• QLoRA Enhancements
• Dettmers et al. 2023: 4-bit NormalFloat base, LoRA adapters in higher precision.
• Paged optimizers enable 65B-scale tuning on limited GPU memory.
Today we examine the mathematical foundations of LoRA, low-rank adaptation, the dominant method for parameter-efficient fine-tuning of large pretrained models.
We begin by contrasting full fine-tuning, which updates every parameter, with freezing the base weights entirely. This framing explains why LoRA's inductive bias is so effective.
Here is the core decomposition: the output h equals the frozen pretrained transformation W zero applied to x, plus a low-rank update, scaled by alpha over r, given by the product B A x.
Concretely, W zero stays fixed throughout training, while A and B are the only learnable matrices, with inner dimension r far smaller than either outer dimension. Alpha rescales the update so the learning rate transfers across ranks.
Because the update is constrained to rank r, the trainable parameter count drops from d squared to two times r times d, often under one percent of the full weight matrix.
This low-rank constraint is the key mechanism: gradients flow only through A and B, so we adapt billion-parameter models on a single GPU without touching the residual stream's pretrained weights.
Adjust the rank slider: LoRA, from Hu and colleagues 2021, decomposes the weight update into a product of two low-rank matrices, so trainable parameters scale as r times d-in plus d-out.
Watch the count fall as r drops, but note the scaling is linear in rank, not exponential: at rank 8, trainable parameters shrink by orders of magnitude versus full fine-tuning.
The forward pass computes W x plus alpha over r times the product B A x; that scaling factor keeps the update magnitude stable as you sweep the rank.
Because the base weights stay frozen, LoRA adds no inference latency once the low-rank product is merged into W, and optimizer state shrinks from gigabytes to megabytes.
Equations, code and original cards
Moment 04 / 09
Gradient Computation and Loss in LoRA
Today we derive the gradient computation and loss formulation underlying LoRA fine-tuning. This clarifies how low-rank adaptation updates a frozen foundation model while preserving stable optimization dynamics.
We focus on three components: backpropagation through the low-rank factors, the closed-form gradients for the LoRA parameters, and how the objective shapes the update trajectory.
Recall the reparameterization: the effective weight is W plus B A, where the pretrained W stays frozen and only the low-rank factors A and B, with rank r much smaller than the hidden dimension, receive gradient updates.
Backpropagation proceeds through this product by the chain rule. The upstream gradient of the loss with respect to the adapter output contracts with one factor to produce the gradient for the other.
Concretely, the gradient of the loss with respect to B equals the upstream gradient times A transpose times the input, and the gradient with respect to A equals B transpose times the upstream gradient times the input. Each update costs order r times d rather than d squared.
The objective is typically the task loss, such as cross-entropy on next-token prediction, optionally with weight decay on A and B. Because W is frozen, the optimizer state is tiny and the low-rank constraint itself acts as a strong regularizer.
Together, this gradient flow shows why LoRA matches full fine-tuning quality at a fraction of the memory: all learning signal is funneled through an r-dimensional subspace of the weight update.
Clarification: LoRA factor gradients need X, transposes, and the chosen scaling.
Equations, code and original cards
Gradient Computation and Loss in LoRA
Key Concepts
• Backpropagation through low-rank factors A and B
Welcome to today's lecture on QLoRA, Dettmers et al. 2023, which extends low-rank adaptation with quantization to make fine-tuning large language models feasible on commodity hardware.
Start with quantized LLMs. Compressing weights from sixteen-bit to four-bit precision cuts memory by roughly four times, but naive rounding destroys accuracy, and backpropagating through quantized weights complicates training.
QLoRA addresses this by pairing four-bit NormalFloat quantization, an information-theoretically optimal type for normally distributed weights, with frozen base weights and trainable LoRA adapters, plus double quantization of the constants and paged optimizers.
The payoff is substantial: a sixty-five-billion-parameter model fine-tunes on a single forty-eight-gigabyte GPU, matching sixteen-bit full fine-tuning quality on standard benchmarks.
Research since then pushes further: scaling quantized adaptation to larger models, refining quantization schemes, and improving alignment with human preferences under tight compute budgets.
In summary, QLoRA fuses quantization with low-rank adaptation, dropping memory requirements by an order of magnitude without sacrificing downstream performance. These principles underpin how most practitioners fine-tune large models today.
Equations, code and original cards
Introduction to QLoRA
Quantized Low-Rank Adaptation (Dettmers et al. 2023)
• QLoRA: 4-bit NormalFloat (NF4) base weights + trainable LoRA adapters in higher precision
• Double quantization and paged optimizers; 65B model fine-tunes on one 48GB GPU
• Ongoing research: scaling, quantization schemes, training efficiency, alignment
Moment 06 / 09
Advanced Optimization Techniques in PEFT
Today we examine advanced optimization in parameter-efficient fine-tuning: low-rank adaptation, quantization-aware variants, and rank scheduling methods that dominated PEFT research from 2024 onward.
Here are the load-bearing ideas that organize this scene and its experiments.
First, scaling laws: adaptation quality tracks base loss, trainable parameter fraction, and tokens seen, so rank cannot compensate for an undertrained backbone.
Second, adaptive rank and alpha scaling allocate capacity across layers, since attention projections often need higher rank than embeddings or normalization gains.
Third, memory: four-bit quantization, gradient checkpointing, paged optimizers, and offloaded adapters cut VRAM while preserving most downstream accuracy.
Fourth, alignment: PEFT can shift refusal behavior and calibration, so evaluate safety, divergence from the base policy, and reward hacking.
The throughline is simple: optimize only where curvature and signal justify parameters, then verify capability, efficiency, and alignment under matched compute budgets.
Equations, code and original cards
Advanced Optimization in PEFT
Low-rank adaptation, quantization, and alignment-aware tuning
Key Points
• Scaling laws for adapters: rank, tokens, backbone loss
Let's move from the LoRA mathematics to its implementation in PyTorch. This slide walks through the four components: the adapter module, the forward pass, QLoRA integration with a quantized backbone, and gradient masking.
First, the LoRA module itself: a class wrapping two low-rank projections, A and B, that parameterize the weight update delta-W as the product B times A, with rank r far smaller than the base dimension.
The forward pass adds the adapter's residual branch to the frozen base computation. The pretrained weight matrix is never modified, and at inference the low-rank update can be merged in with zero added latency.
For QLoRA, the base model loads in four-bit NormalFloat quantization while the adapters stay in higher precision, which is what lets us fine-tune a sixty-five-billion-parameter model on a single GPU.
Finally, the parameter loop freezes everything except tensors whose names contain lora, so gradients flow only into A and B. The optimizer then maintains states for a small fraction of the model's parameters.
Together these pieces are the complete recipe: low-rank adapters on a frozen, quantized backbone, recovering full fine-tuning quality at a fraction of the memory and compute cost.
Equations, code and original cards
Implementation Details: Python & PyTorch Code
Key Implementation Aspects
# 1. LoRA module: low-rank projections A and Bclass LoRALayer(nn.Module): def __init__(self, base_dim, rank): super().__init__() self.lora_A = nn.Linear(base_dim, rank, bias=False) self.lora_B = nn.Linear(rank, base_dim, bias=False)# 2. Forward pass: frozen base plus adapter residual def forward(self, x): return x + self.lora_B(self.lora_A(x))# 3. QLoRA: 4-bit quantized base, full-precision adaptersquantized_model = load_quantized_model() # e.g., 4-bitlora_module = LoRALayer(base_dim=768, rank=8)model_with_lora = integrate_lora(quantized_model, lora_module)# 4. Freeze base weights; gradients flow to LoRA onlyfor name, param in model_with_lora.named_parameters(): if 'lora_' in name: param.requires_grad = True else: param.requires_grad = False
Moment 08 / 09
Open Research Questions and Cutting-Edge Variations
Open problems in parameter efficient fine tuning are now mostly about inductive bias, not parameter counts. The question is which small update spaces preserve pretrained structure while still changing behavior.
Architecture compatibility is first: mixture of experts routers, state space backbones, retrieval layers, and multimodal encoders all place gradients differently. A method tuned for dense transformers may fail where routing, recurrence, or cross attention dominates.
Robustness is the harder constraint. Adapters can overfit narrow instruction data, lose calibration under distribution shift, or forget base capabilities; we need guarantees across domains, not just lower validation loss.
The design space is widening beyond low rank matrix factorization: vector rescaling, tensorized adapters, hypernetwork generated weights, sparse masks, and quantized updates trade expressivity against memory.
Alignment adds a coupled objective: preference optimization or reinforcement learning must steer behavior without undoing safety, while merging, pruning, and quantization decide whether dozens of task adapters can coexist cheaply.
The frontier is therefore precise: match full fine tuning quality, prove transfer across architectures and shifts, and make composition auditable. Progress will come from better theory, harder ablations, and honest compute accounting.
Equations, code and original cards
Open Research Questions in Parameter-Efficient Fine-Tuning
From low rank updates to composable, robust, architecture-aware adaptation
• Compatibility with mixture of experts, state space, retrieval, and multimodal stacks
• Robustness under distribution shift: calibration, forgetting, and worst-domain transfer
• Alignment plus efficiency: preference tuning, adapter merging, pruning, and auditability
Moment 09 / 09
Comprehensive Knowledge Quiz
Now let's assess how well the material on parameter-efficient fine-tuning and low-rank adaptation has settled. Work through each question independently, and reason from the mechanics, not from memorized definitions.
Once you've submitted your answers, I'll walk through any items that need clarification, whether that's the rank constraint, the scaling factor, or where adapters sit relative to the frozen weights.
Equations, code and original cards
MAKE IT YOURS
Explain the change.
References, scope & corrections
Research snapshots in the source material are not a claim of current state of the art. The reference review corrects identified errors; it is not exhaustive certification of every historical statement. Source code snippets are examples, not a tested production training system.