Introduction
In our last lesson, we played the role of a training diagnostician, learning to interpret learning curves to spot the tell-tale signs of overfitting and underfitting. You now know how to read the "story" told by training and validation loss to assess the health of a fine-tuning job.
Today, we transition from diagnosis to treatment. Knowing a model is overfitting is one thing; knowing which knobs to turn to fix it is another. This lesson focuses on the key hyperparameters of Parameter-Efficient Fine-Tuning (PEFT), specifically LoRA, which act as the primary controls for managing model capacity and behavior. By mastering these, you'll gain the ability to steer your fine-tuning process, preventing the very issues we learned to identify and ultimately building more robust, generalizable models. Our goal is to describe key hyperparameters for PEFT (e.g., rank, alpha) and strategies for their optimization.
1. LoRA's Main Controls: Rank and Alpha
As a quick refresher, LoRA (Low-Rank Adaptation) avoids updating the massive number of weights in a pre-trained model. Instead, it injects small, trainable "adapter" matrices into the model's layers. The beauty of this approach lies in its efficiency, but its power comes from configuring these adapters correctly. The two most fundamental hyperparameters are rank and alpha.
To get a clear, visual intuition for how these work, let's start with a video.
LoRA explained (and a bit about precision and quantization)
The video 'LoRA explained' from DeepFindr provides an excellent conceptual and mathematical breakdown of LoRA, focusing on the roles of rank and alpha.
Watch from 07:03 to 13:09. Pay close attention to: The explanation of matrix rank and the motivation for low-rank updates. The visualization of how the update matrix ΔW is decomposed into two smaller matrices, A and B. The introduction of the rank (r) and alpha hyperparameters and the crucial scaling formula: alpha / rank.
Now, let's formalize these concepts, drawing on the deep dive provided by the LoRA Hyperparameters article. This will be our primary reference for the technical details.
LoRA Hyperparameters: Rank, Alpha & Target Module Selection
The article 'LoRA Hyperparameters: Rank, Alpha & Target Module Selection' by Michael Brenndoerfer is an exceptionally detailed guide. We'll use it to explore the practical and mathematical implications of each hyperparameter.
Read the sections 'Rank Selection' and 'The Alpha Parameter.' Focus on understanding: Rank (r): How it directly controls the number of trainable parameters and acts as the 'capacity' knob. Note the empirical guidelines for choosing a rank based on task complexity. Alpha (α): How it functions as a 'strength' knob, scaling the contribution of the LoRA adapter. Internalize the alpha / rank ratio as the key factor determining the adaptation's magnitude.
The rank (r): The Capacity Knob
As you've just read, the rank (r) is the single most important LoRA hyperparameter. It defines the inner dimension of the low-rank matrices A and B, directly controlling the number of trainable parameters.
- Function: It sets the "capacity" or "expressiveness" of the adaptation.
- Intuition: Think of
rankas the number of independent patterns the adapter can learn.- A low rank (e.g., 4, 8) constrains the model to learn simple, broad adjustments. This is a form of regularization and is effective for simple tasks or when you have little data, helping to prevent overfitting.
- A high rank (e.g., 64, 128) gives the model more freedom to learn complex, nuanced changes. This is necessary for tasks that are very different from the model's pre-training data but increases the risk of overfitting.
The alpha (α): The Strength Knob
The alpha (α) parameter acts as a scaling factor for the LoRA update. The crucial part isn't alpha itself, but the ratio alpha / r.
- Function: This ratio determines the magnitude of the adapter's output before it's added back to the original, frozen weights.
- Intuition: If
rankis the capacity,alphahelps you set the "volume" of that capacity.alpha = r: The scaling factor is 1. The LoRA update is added with its "natural" magnitude. This is a neutral, common baseline.alpha = 2 * r: The scaling factor is 2. The LoRA update is amplified. This is a very common heuristic, often used to make the adapter's contribution more significant without needing a higher learning rate.alpha < r: The scaling factor is less than 1. The LoRA update is dampened, resulting in a more conservative change that preserves more of the base model's behavior.
The reason alpha exists is to decouple the choice of rank from the learning rate. By using the alpha/r scaling, you can change the rank without having to drastically re-tune your learning rate, as the magnitude of the updates remains more consistent.
Test your understanding!
You are fine-tuning a model with r=16 and alpha=32.
- What is the effective scaling factor of your LoRA update?
- You decide the model is underfitting and want to increase the adapter's capacity by changing the rank to
r=64. If you want to maintain the same adaptation strength (i.e., the same scaling factor), what should your newalphabe?
Show answer
- The scaling factor is
alpha / r=32 / 16= 2. - To maintain a scaling factor of 2 with a new rank of
r=64, you need to solve for alpha inalpha / 64 = 2. The new alpha should be 128.
2. Where to Adapt: Target Module Selection
LoRA adapters don't have to be applied to every layer. You can choose which parts of the Transformer architecture to modify. This choice has a significant impact on both performance and efficiency.
Let's return to our main textual resource to understand this.
LoRA Hyperparameters: Rank, Alpha & Target Module Selection
We continue with the 'LoRA Hyperparameters' article to explore which layers are the best candidates for adaptation.
Read the section 'Target Module Selection.' Focus on: The difference between adapting attention projections (WQ, WK, WV) and feed-forward networks (FFN). The practical guidelines for which modules to target and why attention-only is a common starting point. How the number of trainable parameters changes based on the target module strategy.
To summarize the strategies:
- Attention-Only (e.g.,
q_proj,v_proj): This is the most common starting point. It's highly parameter-efficient and focuses on changing how the model routes information. For many instruction-following tasks, modifying the query and value matrices is sufficient. - All Attention (
q_proj,k_proj,v_proj,o_proj): A slightly more comprehensive approach that still focuses on the attention mechanism. - All Linear Layers (Attention + FFN): This is the most powerful but also most parameter-heavy PEFT approach. The Feed-Forward Networks (FFNs) are thought to store factual knowledge. Adapting them is crucial when you need to teach the model new facts or adapt it to a domain with specialized knowledge.
An important finding from the QLoRA paper, as discussed in the video below, is that to match the performance of full fine-tuning, adapting all linear layers is often necessary.
LoRA & QLoRA Fine-tuning Explained In-Depth
This clip from Mark Hennings' 'LoRA & QLoRA Fine-tuning Explained' highlights a key empirical finding about target modules.
Watch from 09:25 to 10:25. The speaker discusses two key takeaways from the QLoRA paper. Pay special attention to the first one regarding which layers to train.
This gives you a clear trade-off: start with attention-only for maximum efficiency, but if performance is lacking, expand to all linear layers for maximum capacity, memory permitting.
3. Preventing Overfitting: LoRA Dropout
Just like in traditional deep learning, dropout is a powerful regularization technique. In LoRA, it's applied specifically to the adapter pathway.
- Function: During training, it randomly sets some of the activations within the LoRA adapter to zero.
- Intuition: It forces the adapter to learn redundant representations, preventing it from becoming too reliant on any single pathway. This makes the learned adaptation more robust and less likely to memorize the training data.
- Practical Use: A
lora_dropoutof0.05or0.1is a common choice. It's especially useful when you have a small dataset or are using a high rank, both of which increase the risk of overfitting.
4. Practical Recipes and Optimization Strategy
Now that we understand the individual components, how do we combine them? Hyperparameter tuning can be a daunting search problem. Fortunately, community experience has produced some reliable starting points.
Let's look at a summary of practical recipes and an image that shows the real-world impact of these choices.
LoRA Hyperparameters: Rank, Alpha & Target Module Selection
The 'LoRA Hyperparameters' article concludes with excellent configuration recipes and a structured search strategy.
Read the sections 'Putting It Together: Configuration Recipes' and 'Hyperparameter Search Strategies.' This will consolidate your knowledge into actionable starting points.
The table below, from Sebastian Raschka's experiments, shows how different r and alpha settings on a 7B model affect performance on various benchmarks. Notice how there is no single "best" setting; performance varies by task. For instance, r=256, alpha=512 does well on MMLU, but r=256, alpha=128 is better on TruthfulQA.

A General Hyperparameter Search Strategy
When you need to find the optimal settings for your specific task, don't search randomly. Prioritize your search budget based on impact:
- Target Modules: Decide if you can get away with attention-only or if you need to include FFNs. This is your biggest lever for capacity.
- Rank (
r): This is your next most important knob. Search in powers of 2 (e.g., 8, 16, 32, 64). Observe the trade-off between performance and training time/memory. - Alpha (
α): Instead of searching foralphaindependently, search for thealpha/rratio. A common approach is to simply setalpha = 2 * rand focus on tuning the rank. - Dropout: Tune this last. A small value like
0.05is often a safe bet. If you see clear signs of overfitting, you can increase it.
Conclusion
You've now demystified the key control knobs for LoRA. You've moved beyond just running fine-tuning jobs to understanding how to intelligently configure them, directly connecting the diagnostics from our last lesson to concrete, actionable treatments.
Key Takeaways:
rank(r) is Capacity: It controls the number of trainable parameters. Higher ranks allow for more complex adaptations but risk overfitting. Lower ranks act as a regularizer.alpha(α) is Strength: It controls the magnitude of the adaptation. The key is thealpha / rratio, withalpha = 2 * rbeing a common and effective heuristic.- Target Modules are Location: Applying LoRA to attention layers modifies information flow, while applying it to FFNs modifies stored knowledge. Targeting all linear layers offers the most power at the cost of more parameters.
- LoRA Dropout is Regularization: It's a targeted tool to combat overfitting within the adapter itself, especially useful for small datasets or high ranks.
- Optimize Systematically: When tuning, prioritize your search: Target Modules → Rank → Alpha → Dropout.
What's Next?
So far, we've focused on Supervised Fine-Tuning (SFT), where we teach a model to mimic the style and format of a curated dataset. However, SFT doesn't guarantee the model will be helpful, harmless, or aligned with complex human preferences. In our next lesson, we'll explore the next frontier: explaining the conceptual difference between SFT and alignment techniques like DPO and RLHF, which are designed to shape a model's behavior in more nuanced ways.