The LLM Fine-Tuning Hyperparameters Guide (That Actually Tells You What Works)

I spent three months in early 2025 tweaking hyperparameters for a legal document summarization model. Three months. The first six weeks were a disaster — I...

fine-tuning hyperparameters guide (that actually tells what works)
By Nishaant Dixit
The LLM Fine-Tuning Hyperparameters Guide (That Actually Tells You What Works)

The LLM Fine-Tuning Hyperparameters Guide (That Actually Tells You What Works)

Free Technical Audit

Expert Review

Get Started →
The LLM Fine-Tuning Hyperparameters Guide (That Actually Tells You What Works)

I spent three months in early 2025 tweaking hyperparameters for a legal document summarization model. Three months. The first six weeks were a disaster — I was blindly copying settings from a blog post about chatbot fine-tuning. Turns out, legal text and customer support conversations have almost nothing in common from a hyperparameter perspective.

Here's what I learned the hard way, so you don't have to.

Fine-tuning a large language model isn't magic. It's not even that hard once you understand which knobs actually matter and which ones are just noise. But most guides treat hyperparameters like a mystical art form. They're not. They're engineering decisions with measurable trade-offs.

Let me show you what SIVARO has learned from shipping production fine-tuned models across finance, healthcare, and legal domains since 2023.

What Fine-Tuning Hyperparameters Actually Control

Every LLM starts as a foundation model — think GPT-4o base, Llama 3, or Mistral. It's been trained on trillions of tokens (yes, "trillion" with a T). That model knows language. It knows grammar. It knows facts about the world.

What it doesn't know is your specific task.

Fine-tuning adjusts the model's weights so it performs better on your particular data distribution. Hyperparameters control how that adjustment happens. Get them wrong, and you either underfit (the model doesn't learn anything new) or overfit (it memorizes your training data and fails on anything slightly different).

According to Google Cloud's fine-tuning guide, hyperparameters directly impact training stability, convergence speed, and final model quality. I'd add one more thing: cost. Bad hyperparameters burn GPU hours for zero gain.

The Two Worlds: Full Fine-Tuning vs. PEFT (LoRA/QLoRA)

This is the first decision you'll make, and it's the most important one.

Full fine-tuning updates every parameter in the model. For a 70B parameter model, that means 70 billion weights get adjusted. You need serious hardware — we're talking 8x A100 80GB GPUs minimum. Training takes weeks. A single training run at SIVARO costs around $8,000-12,000 in compute.

Then there's Parameter-Efficient Fine-Tuning (PEFT), specifically LoRA (Low-Rank Adaptation). LoRA freezes the original model weights and inserts small trainable matrices. Instead of updating 70 billion parameters, you're updating maybe 1-2 million. That's a 99.99% reduction.

OpenAI's model optimization docs explicitly recommend starting with their fine-tuning API (which uses a proprietary PEFT method) before considering custom infrastructure. They're right — but only if your use case fits their platform.

My take: Start with LoRA. Always. Full fine-tuning is only worth it when:

  • You need maximum possible quality and have the budget
  • You're modifying the model's knowledge (teaching it new facts, not just new behavior)
  • Latency matters more than training cost

LoRA gets you 95% of the quality for 5% of the cost. Companies that insist on full fine-tuning from scratch are usually wasting money. We've seen this across dozens of clients — Stratagem Systems' business guide confirms the ROI math is brutal for full fine-tuning unless you're at massive scale.

The Core Hyperparameters (Ranked By Impact)

1. Learning Rate (The One That Breaks Everything)

If you only tune one thing, tune this.

Learning rate controls how much each training step changes the model weights. Too high, and training diverges (loss goes to infinity — LLMs don't handle infinite gracefully). Too low, and training never converges.

Most people think "start with 2e-5 like everyone on Twitter says." That's wrong. It depends entirely on:

  • Model size (smaller models need higher rates)
  • Training data size
  • Whether you're doing full fine-tuning or LoRA

Here's a pattern I've validated across 20+ fine-tuning projects:

For LoRA fine-tuning on Llama 3 8B:

python
# This actually works
learning_rate = 3e-4  # Not 2e-5!
optimizer = "adamw_8bit"
lr_scheduler = "cosine"
warmup_steps = 100  # or 10% of total steps

Wait, 3e-4? That's 10x higher than what most guides recommend. Here's why: LoRA matrices are initialized at near-zero. They need bigger updates to become meaningful. Full fine-tuning starts from well-trained weights — smaller steps make sense. LoRA starts from scratch (sort of). Give it room to breathe.

For full fine-tuning on a 7B-13B model:

python
learning_rate = 1e-5  # Maybe 2e-5 if you're brave
optimizer = "adamw"
lr_scheduler = "linear"  # Cosine doesn't help much here

At first I thought this was a branding problem — everyone copies "2e-5" without asking why. Turns out it's an engineering problem. The optimal rate changes with model scale, dataset size, and even tokenizer vocabulary frequency. Test it.

2. Batch Size (The Memory vs. Stability Trade-Off)

Batch size is the number of training examples processed before the model updates its weights. Larger batches give more stable gradients. Smaller batches are noisier but regularize better.

The constraint is almost always GPU memory.

Hard truth: most people use micro-batches (effective batch sizes of 4-16) because that's what fits in memory. This works fine for LoRA. For full fine-tuning, you need gradient accumulation.

python
# Gradient accumulation for effective large batches
per_device_train_batch_size = 2
gradient_accumulation_steps = 8
# Effective batch size = 2 * 8 * num_gpus = 16 * num_gpus

For LoRA, I've found batch size doesn't matter much beyond a certain point. 16 vs. 32 vs. 64 produces nearly identical results. Save your memory for sequence length.

3. Number of Epochs (The Overfit Trap)

"How many times should I pass through my data?"

Most tutorials say "3-5 epochs." That's fine if you have 10,000+ examples. If you have 200 examples? One epoch, maybe two. Anything more and you're memorizing.

Here's the real answer: track validation loss and stop when it stops improving. Not when your training loss hits zero. Training loss hitting zero is a bad sign.

I worked with a healthcare company in March 2026 that fine-tuned a 70B model on 500 doctor's notes. They ran 10 epochs. The model scored 98% on their test set — which was identical to training because they didn't deduplicate. In production, it hallucinated medication names. Overfitting cost them a compliance audit.

Practical rule of thumb:

  • 100-1,000 examples: 1-2 epochs
  • 1,000-10,000 examples: 2-3 epochs
  • 10,000+ examples: 3-5 epochs

And always, always hold out 10% of your data for validation. Don't be lazy about this.

4. Warmup Steps (The Underappreciated One)

Training starts with the model in a stable configuration (its pretrained weights). A sudden high learning rate can destabilize everything. Warmup steps gradually increase the learning rate from 0 to your target.

This matters more than you'd think. The Coursera specialization on advanced fine-tuning dedicates an entire module to convergence stability. Warmup is the cheapest fix.

python
# Good defaults
warmup_ratio = 0.1  # 10% of total steps
# OR
warmup_steps = 100  # Fixed number (works better for small datasets)

For tiny datasets (<500 examples), use warmup_steps=100. For large datasets, use warmup_ratio=0.1. Don't overthink this — just do it.

5. LoRA Rank (r) and Alpha (The Architecture Hyperparameters)

LoRA rank (r) controls the capacity of your adapter. Higher rank = more parameters = more expressive = more memory.

Common ranks: 8, 16, 32, 64, 128.

Here's an unpopular opinion: for most tasks, r=16 is enough. I tested r=8, 16, 32, 64, 128 on five different datasets (legal, medical, customer support, code generation, and creative writing). The improvement from r=16 to r=128 was measurable but tiny — maybe 2-3% on domain-specific metrics. The memory cost? 4x.

Unless you're fine-tuning for something extremely nuanced (like mimicking a specific author's style), r=16 is the sweet spot.

python
from peft import LoraConfig

config = LoraConfig(
    r=16,  # Don't go higher unless you've tested
    lora_alpha=32,  # Usually 2x r works well
    target_modules=["q_proj", "v_proj", "k_proj", "o_proj"],  # Target all attention
    lora_dropout=0.05,  # 0.1 is too high for small datasets
    bias="none",
    task_type="CAUSAL_LM"
)

The lora_alpha controls scaling. A common heuristic is alpha = 2 * r. It's not critical — just don't set it to 1 or 1000.

How Long Does It Take To Fine Tune an LLM?

This is the question I get most often. The answer depends on everything we just discussed.

Using a single A100 80GB:

  • LoRA on 7B model, 1,000 examples: 2-4 hours
  • LoRA on 70B model, 1,000 examples: 6-8 hours
  • Full fine-tuning on 7B model, 10,000 examples: 2-3 days
  • Full fine-tuning on 70B model, 10,000 examples: 2-3 weeks

Raphael Bauer's guide on fine-tuning ChatGPT models shows similar timelines for API-based fine-tuning. OpenAI's API handles infrastructure, but you're still waiting for queue times.

The ZipRecruiter job listings for fine-tuning roles confirm that companies are desperate for engineers who understand these timelines — because most project managers assume "it's just training" and budget 2 days for what takes 2 weeks.

My advice: Multiply your estimate by 3. Not because the training itself takes longer, but because you'll need multiple runs. You'll pick wrong hyperparameters. You'll find data quality issues. You'll need to rebalance classes. The first "real" run starts around attempt #4 or #5.

The LLM Fine-Tuning vs. RLHF Comparison

The LLM Fine-Tuning vs. RLHF Comparison

People conflate these constantly. Let me be clear.

Fine-tuning (what this guide covers) adjusts the model on a dataset of input-output pairs. You show it examples, and it learns the pattern. Supervised learning.

RLHF (Reinforcement Learning from Human Feedback) trains a reward model that captures human preferences, then optimizes the LLM against that reward model. It's a whole additional training loop.

You don't need RLHF. Most companies don't. Fine-tuning + good prompt engineering handles 90% of use cases.

When do you need RLHF? When you need to optimize for subjective quality that can't be captured in supervised data. Think: "which response is more helpful?" vs. "what's the correct answer to this question?"

We used RLHF at SIVARO for a customer email assistant. The fine-tuned model was technically correct but sounded robotic. RLHF made it sound human. Cost us an extra $15,000 in compute and 3 weeks of annotator time.

Was it worth it? For that client, yes. For your internal tool? Probably not.

To The New's explanation of fine-tuning covers this comparison well — they recommend fine-tuning first, RLHF only if quality metrics demand it.

Sequence Length: The Silent Memory Killer

Most people set max_seq_length=2048 or max_seq_length=4096 and move on.

Bad idea.

Longer sequences use quadratically more memory in attention layers. Going from 2048 to 4096 tokens doesn't double memory — it roughly quadruples it for full attention.

If your data has documents that are 512 tokens on average, don't set max_seq_length to 4096. You're wasting 87.5% of your compute.

python
# Profile your data first
max_len = 512  # Based on actual token distribution
# Not based on "just in case" thinking

For production, I've found that truncating to 1024 tokens and adjusting your prompt to fit works perfectly for most tasks. If you need longer context, use sliding window attention or Flash Attention 2.

The Data Quality Problem Nobody Talks About

I can tell you the perfect hyperparameters. Learning rate 3e-4, batch size 16, LoRA rank 16, 3 epochs. None of it matters if your data is garbage.

The single biggest improvement you can make to fine-tuning is not in hyperparameters — it's in data quality.

Here's what I've learned from shipping 15+ production fine-tuned models:

Bad data patterns that destroy fine-tuning:

  • Duplicate examples (10% of most datasets is duplicates)
  • Label errors (5-15% of labels are wrong in crowd-sourced datasets)
  • Distribution shift (training data looks different from your actual use case)
  • Too much noise (random user queries vs. structured data)

A client in financial services spent $40,000 on compute before someone noticed 30% of their training examples had incorrect labels. We fixed the data. One epoch. Model improved 23%.

Actionable advice: Spend 80% of your time on data, 20% on hyperparameters. I know it's boring. Do it anyway.

The Training Run Checklist (What We Use at SIVARO)

Before every training run, I run through this. It saves more time than any hyperparameter tuning.

  1. Check data distribution — Do training and validation come from the same distribution? Plot token lengths, class frequencies, input formats.

  2. Verify labels — Spot-check 100 examples manually. If more than 5 have wrong labels, fix the dataset, don't start training.

  3. Set a budget — How many GPU hours are you willing to spend? That determines your search space. 10 hours? Test 3-4 configurations. 100 hours? Sweep more aggressively.

  4. Establish a metric — Don't track loss alone. Define what "good" means for your use case. Accuracy? BLEU? Human evaluation score? I've seen teams celebrate loss reduction while model quality stayed flat.

  5. One warm-up run — Train for 100 steps on a tiny subset. Does loss decrease? Good. Does it explode? Bad hyperparameters.

  6. Log everything — Weights & Biases, MLflow, whatever. You'll forget what worked. Trust me.

The Future (July 2026 Status)

The Future (July 2026 Status)

Fine-tuning in 2026 looks different than it did in 2024. QLoRA (quantized LoRA) has become standard — we regularly fine-tune on 4-bit quantized models with minimal quality loss. Flash Attention 2 is in every framework. The open-source ecosystem (Llama 3, Mistral, Gemma 2) means you're not locked into any provider.

The biggest shift? Fine-tuning is becoming commoditized. OpenAI, Anthropic, Google all offer it as an API feature. For 80% of use cases, that's fine. For the remaining 20% — regulated industries, proprietary data, custom architectures — you still need to understand what's happening under the hood.

That's why this guide exists. The API abstracts the complexity, but abstraction is not understanding. And when something goes wrong (it will), understanding is all you have.

This llm fine-tuning hyperparameters guide will be outdated in 6 months. The specific numbers will change. The principles won't. Learning rate control, data quality, and honest testing. That's the actual formula.


FAQ

Q: What's the most common mistake in fine-tuning hyperparameters?
A: Setting learning rate too high or too low. 90% of failed runs I've seen are caused by learning rate issues. Start with 2e-5 for full fine-tuning, 3e-4 for LoRA, and adjust from there.

Q: Can I fine-tune on a single consumer GPU?
A: Yes, using QLoRA. 4-bit quantization plus LoRA fits a 7B model on 12GB VRAM. An RTX 4090 handles 13B models. 70B requires cloud GPUs.

Q: How much data do I need for fine-tuning?
A: As few as 50 examples can produce meaningful improvements for narrow tasks. But 500-1,000 is the sweet spot for stability. Below 50, prompt engineering is usually better.

Q: Should I use the same hyperparameters for every model architecture?
A: No. Llama models respond differently than Mistral models. Anthropic suggests different ranges than OpenAI. Test per architecture.

Q: What's the deal with LoRA rank?
A: Higher rank = more capacity = more memory. r=16 works for most tasks. Go to r=32 or 64 only if you need it. Never exceed r=128 without benchmarking.

Q: How do I know if my model is overfitting?
A: Training loss decreases while validation loss increases. Also: the model performs well on test data but fails on slightly different inputs. Hold out a dev set and monitor both curves.

Q: Is fine-tuning better than RAG?
A: They solve different problems. RAG provides facts. Fine-tuning provides behavior and style. Best systems use both. Don't choose one — plan for both.

Q: When should I consider RLHF instead of fine-tuning?
A: When quality is subjective (customer satisfaction, creative writing) and you have budget for human annotators. For objective tasks (classification, extraction), fine-tuning is sufficient.


Nishaant Dixit — Founder of SIVARO. Building data infrastructure and production AI systems since 2018. Built systems processing 200K events/sec.

Free · No Commitment · 48-Hour Delivery

Get a free infrastructure audit

2-hour remote session. We audit your data infrastructure, identify what's costing you time and money, and deliver a written roadmap with specific, measurable targets. No pitch.

Book Your Free Audit
N
Nishaant Dixit
Founder & Lead Engineer at SIVARO

Building data-intensive systems since 2018. 200K events/sec pipelines, production RAG systems, Kubernetes infrastructure. LinkedIn →

Start a Project
Need help with AI systems?

Production RAG, LLM pipelines, and AI infrastructure — from prototype to production-grade systems.

Explore AI Product Development