Fine-Tuning Open-Source LLMs: Lessons from Base Model Selection to Hyperparameter Tuning
A hands-on fine-tuning walkthrough: upgrading from a 4B to a 9B base model, building a 6k-sample dataset with chain-of-thought and tool-calling data, and tuning LoRA hyperparameters. Covers why base model choice matters more than data engineering, how to handle OOM errors, and why 2 epochs is the sweet spot for small instruction-tuning datasets.
Fine-Tuning Open-Source LLMs: Lessons from Base Model Selection to Hyperparameter Tuning
Background and Goals
In a previous fine-tuning experiment, I ran an initial instruction-tuning pass on an open-source model with roughly 4B parameters. The end-to-end pipeline worked, but I wasn’t satisfied with the quality of the final results. The goal of this round was therefore clear: switch to a stronger base model, rebuild the training data, and systematically tune the training hyperparameters to observe how the fine-tuning outcome changes. This post documents the key decisions, pitfalls, and conclusions from the process, in the hope that it helps developers working on similar projects.
Base Model Selection: The First Determinant of Fine-Tuning Success
A common misconception among beginners is that with good enough data and refined enough training techniques, any base model can be fine-tuned to ideal results. Real-world experience says the opposite: base model selection determines your ceiling earlier than data engineering does.
In this round, I upgraded the base model from the previous 4B checkpoint to a 9B next-generation Base variant. After actual training, my impression was that the newer base showed clear improvements in instruction following, Chinese-language comprehension, and the consistency of chain-of-thought outputs. Fine-tuning converged faster and the output style was more stable. By comparison, I previously tried the same task on an older-generation 14B model, and the results were far from ideal. The lesson: model generation matters more than raw parameter count — newer architectures, more thorough pretraining data, and a better alignment foundation directly reduce the difficulty of fine-tuning.
That said, parameter count still matters. Within the same generation, larger models typically have an overwhelming edge in reasoning, knowledge, and generalization, and below 32B parameters this gap is especially pronounced. A sensible selection strategy is:
- Prefer newer-generation base models over older large-parameter models;
- Within your budget, choose the largest variant within the same generation;
- Choose between Base and Chat/Instruct versions based on the task: if you want the model to learn a completely new conversational style or domain format, Base versions are more malleable; for lightweight style alignment only, instruct versions may need less data.
Training Environment and Hyperparameter Configuration
Training ran on a single A100-class GPU with 40GB of VRAM. Here are the LoRA hyperparameters I used and the reasoning behind them:
- lora_rank: 32. Rank determines the expressiveness of the low-rank adaptation matrices. For a dataset of a few thousand samples, rank=32 is sufficient to fit the task’s patterns; a larger rank tends to overfit and increases VRAM usage.
- lora_alpha: 64. Alpha is typically set to about 2x the rank to control the scaling of adapter outputs — a common rule of thumb in the community.
- learning_rate: 1e-4. LoRA fine-tuning tolerates higher learning rates than full-parameter fine-tuning; 1e-4 struck a good balance between convergence speed and stability.
- epoch: 2. Detailed below.
- max_length: 5120. This one comes with a classic pitfall: I originally planned to set it to 8192, but training kept failing with OOM (out-of-memory) errors.
The relationship between max_length and VRAM is worth unpacking: attention computation and memory usage grow super-linearly with sequence length, especially during training, where activations must be cached for backpropagation. Doubling sequence length often more than doubles memory consumption. If you hit OOM, possible mitigations include:
- Lower max_length, or truncate overly long samples;
- Enable gradient checkpointing to trade compute for memory;
- Reduce per_device_batch_size and use gradient accumulation to reach the equivalent batch size;
- Use memory-optimization techniques such as the paged optimizer;
- If your framework supports it, enable FlashAttention-style attention implementations.
I ultimately settled on max_length=5120. Training remained stable throughout, and the vast majority of multi-turn dialogue samples in the dataset were covered in full — an acceptable compromise.
On Epochs: 2 Is the Sweet Spot
One of the most practical findings from this experiment: for text-only instruction tuning, 2 epochs is usually optimal, and by the third epoch clear signs of overfitting typically appear.
Typical overfitting symptoms include: validation loss rising instead of falling; the model mechanically repeating wording from training samples; reduced diversity in generated content, with repetition and boilerplate; and noticeably worse generalization to question formats not covered in the training set.
Why exactly 2 epochs? A rough intuition: the first epoch teaches the model the overall format and distribution of the task, the second epoch further reinforces stylistic consistency and output quality, and from the third epoch onward the model starts “memorizing answers,” hard-coding training-sample details as if they were knowledge, which hurts generalization. Of course, this rule of thumb depends on dataset size: with a few thousand samples, 2 epochs is a fairly common safe choice; with hundreds of thousands of samples, 1 epoch — or even less — may suffice. Always hold out a validation set, monitor loss per step, and spot-check outputs manually, rather than blindly fixing the number of epochs.
Dataset Construction
The dataset used in this round contains roughly 6k samples: about 5k multi-turn dialogue samples with chain-of-thought reasoning, and about 1k tool-calling samples. The mix reflects different training objectives:
- Chain-of-thought multi-turn dialogue data: Shapes the model’s reasoning style and multi-turn contextual coherence. Explicitly including the reasoning process in samples teaches the model a “think first, then answer” output structure, while the multi-turn design ensures role consistency and coreference understanding across long contexts.
- Tool-calling data: Teaches the model to generate structured call intents at the right moments rather than hallucinating answers directly. Pay special attention to consistency in function signature descriptions, parameter formats, and call trigger conditions — any format inconsistency significantly lowers call success rates.
Part of the dataset has been published in the model open-source community; interested readers can search for it. I’d also recommend building your own dataset with a similar structure based on your business scenario.
Evaluation and Takeaways
The measured results after training exceeded expectations, with overall performance showing a qualitative leap compared to the previous 4B model. Looking back at the whole experiment, three core conclusions stand out:
- Base model quality is the foundation of fine-tuning — choosing the right base pays off disproportionately, and newer mid-size models can comprehensively outperform older large-parameter ones;
- Hyperparameters must respect real VRAM constraints — be conservative with settings like max_length; completing training stably matters more than chasing theoretical optima;
- Fewer epochs is better than more — for text-only fine-tuning with a few thousand samples, 2 epochs is usually the sweet spot, and overfitting risk rises sharply beyond that.
Next steps include expanding tool-calling data coverage and experimenting with larger ranks and multi-adapter combinations. Feedback and discussion are welcome.
