Parameters to Change When Fine-Tuning LLMs: A Field Guide

I spent 2024 believing fine-tuning was all about learning rate and batch size. I was wrong. Fine-tuning an LLM isn't a chemistry set. It's a precision instru...

parameters change when fine-tuning llms field guide
By Nishaant Dixit
Parameters to Change When Fine-Tuning LLMs: A Field Guide

Parameters to Change When Fine-Tuning LLMs: A Field Guide

Free Technical Audit

Expert Review

Get Started →
Parameters to Change When Fine-Tuning LLMs: A Field Guide

I spent 2024 believing fine-tuning was all about learning rate and batch size. I was wrong.

Fine-tuning an LLM isn't a chemistry set. It's a precision instrument. And most guides tell you to twiddle knobs without explaining which knobs actually connect to anything. This article is my attempt to fix that.

We've fine-tuned over 200 models at SIVARO — for clients in healthcare, finance, logistics. Some worked. Some were disasters. The difference? Knowing which parameters to change when fine tuning llm and, more importantly, why.

You'll walk away with a mental map of every lever that matters, the trade-offs you can't avoid, and the real-world numbers that separate "this is good enough" from "this is production-grade."

Let's get into it.


The One Parameter Everyone Gets Wrong

Learning rate.

If you're fine-tuning and your model isn't converging, you look at learning rate first. That's correct. But most practitioners screw it up by picking a single value and sticking with it.

Here's the reality: fine-tuning destroys the pretrained distribution. You're not training from scratch. You're redirecting a billion-parameter ship. The learning rate needs to change as you go.

We tested cosine decay vs. constant vs. linear warmup + cosine on a 7B parameter model for a text classification client (insurance claim routing). Constant LR gave us 72% F1. Cosine decay with warmup gave us 79%.

That 7% is millions of dollars in misrouted claims.

The config that works for us:

python
from transformers import get_cosine_schedule_with_warmup

# Typical starting point for 7B model
optimizer = AdamW(model.parameters(), lr=2e-5, weight_decay=0.01)
scheduler = get_cosine_schedule_with_warmup(
    optimizer,
    num_warmup_steps=100,  # ~3% of total steps
    num_training_steps=3000
)

Key insight: llm fine tuning for text classification benefits from lower learning rates than generation tasks. Classification needs stability. Generation needs exploration.


Batch Size: The Silent Quality Killer

Most people think batch size only affects training speed. They're wrong.

Batch size directly changes the gradient noise. Small batches = noisy gradients = worse convergence for fine-tuning. Large batches = smoother gradients but higher memory cost.

We ran an ablation on a 13B model for legal document classification:

  • Batch size 4: 81% accuracy, training took 4 hours
  • Batch size 16: 84% accuracy, took 6 hours (gradient accumulation)
  • Batch size 32: 83% accuracy, training diverged at step 400

The sweet spot? 16. But that changes with model size.

The rule of thumb I use: Start with the largest batch size that fits in memory. Then halve it. That's usually optimal.

For LoRA fine-tuning (which we'll get to), you can push batch sizes higher because you're only updating a fraction of parameters.

python
# Using gradient accumulation to simulate larger batch
training_args = TrainingArguments(
    per_device_train_batch_size=4,
    gradient_accumulation_steps=4,  # effective batch size = 16
    ...
)

Weight Decay: Most People Turn It On. That's a Mistake.

Weight decay is regularization. It penalizes large weights. In full fine-tuning, it prevents overfitting.

But here's the contrarian take: don't use weight decay when fine-tuning for classification on small datasets.

We tested this on a 500-sample medical text dataset:

  • weight_decay=0.01: 88% F1 on validation, 63% on test (overfit)
  • weight_decay=0.0: 91% F1 on validation, 89% on test

The decay forced the model to stay too close to pretrained weights. It couldn't adapt. On small datasets, the pretrained representation is already strong. You don't need to regularize that heavily.

For large datasets (10K+ samples), weight decay helps. Set it to 0.01 or 0.1. But for anything under 5000? Turn it off.


Number of Epochs: The 3-Epoch Myth

I hear "fine-tune for 3 epochs" everywhere. That's cargo-cult advice.

The optimal number of epochs depends on dataset size, model size, and task type. For llm fine tuning for text classification, we've seen:

  • Small dataset (<1000 samples): 5-10 epochs, with aggressive early stopping
  • Medium (1000-10000): 2-5 epochs
  • Large (>10000): 1-2 epochs

Why the spread? Overfitting. More epochs = more risk of memorizing noise.

But here's what surprised me: generation tasks need fewer epochs than classification. For a summarization project, 1 epoch was enough. For classification, we needed 3-5.

Monitor validation loss every 50 steps. Stop when it plateaus for 3 consecutive evaluations. Don't trust the final epoch.


LoRA Parameters: Rank, Alpha, and Target Modules

Low-Rank Adaptation (LoRA) is the standard for fine-tuning now. It's 2026 — nobody runs full fine-tuning on premise unless they're Google.

But LoRA has its own set of parameters to change.

Rank (r)

The rank controls the capacity of the adapter. Higher rank = more parameters = better fit, but more memory.

My rule: Start with r=8 for classification. Go up to r=32 for complex generation tasks. Never go above r=64 unless you have 100K+ samples.

We compared r=8 vs r=32 on a sentiment model:

  • r=8: 85% accuracy, 2.1M trainable params
  • r=32: 87% accuracy, 8.4M trainable params

That 2% improvement cost 4x the memory. Not worth it for most cases.

Alpha (scaling factor)

Alpha is a multiplier on the adapter weights. The original LoRA paper suggested setting alpha = 2 * r. But in practice, that's not optimal for all tasks.

For classification, alpha = r works better. For generation, alpha = 2r.

We learned this the hard way after a client's chatbot started hallucinating on a 13B model. Dialing alpha down from 2r to r fixed it.

python
from peft import LoraConfig

lora_config = LoraConfig(
    r=8,
    lora_alpha=8,  # was 16, causing instability
    target_modules=["q_proj", "v_proj"],  # only attention layers
    lora_dropout=0.05,
    bias="none",
    task_type="SEQ_CLS"
)

Target Modules

Most people just target all linear layers. Don't.

For text classification, only fine-tuning the query and value projection matrices (q_proj, v_proj) is enough. Adding k_proj and o_proj adds noise.

For generation, include all four attention projections. But skip the feed-forward layers — they're not as important for adapting to a new style.


Optimizer: AdamW Is Default. It Shouldn't Be.

Optimizer: AdamW Is Default. It Shouldn't Be.

AdamW is the default optimizer for fine-tuning. But for classification tasks, Adam without weight decay often works better — assuming you turned off weight decay (as I suggested above).

We compared on a 10K sample customer intent dataset:

  • AdamW (weight_decay=0.01): 91% accuracy
  • Adam (weight_decay=0.0): 93% accuracy

Small improvement, but consistent across three runs.

For larger models (70B+), consider Adafactor. It uses less memory and handles gradient accumulation better. We switched to Adafactor for a 70B-classification project and cut GPU memory by 40% with no accuracy loss.

python
from transformers.optimization import Adafactor

optimizer = Adafactor(
    model.parameters(),
    scale_parameter=False,
    relative_step=False,
    warmup_init=False,
    lr=1e-4
)

Warmup Steps: Not Just for Stability

Warmup steps prevent the model from overshooting in the first few updates. But they also serve another purpose: they let the model "warm up" the new parameter distribution.

For classification, I've found 3% warmup is a good starting point. For generation, 10%.

Why the difference? Classification is a narrower task — the model doesn't need to explore much. Generation benefits from a slower start to adapt its output distribution without breaking coherence.


Dataset Mixing: The Parameter No One Talks About

Your training data isn't just files on disk. How you mix it — order of samples, class balance, repetition — is a tuning parameter.

Class imbalance is the most common killer. If your classification dataset has 90% class A and 10% class B, your model will learn to predict A. Always.

We mitigate it by oversampling minority classes or using weighted loss. The latter is better because it doesn't change the data distribution artificially.

python
from torch.nn import CrossEntropyLoss

class_weights = torch.tensor([1.0, 5.0, 3.0])  # order matches class labels
loss_fn = CrossEntropyLoss(weight=class_weights)

But even weighting isn't enough. We've found that mixing in a small amount (5-10%) of the original pretraining data helps maintain model generality. This is called data replay and it's a parameter you control.

We added 5% of random C4 subset to a classification fine-tuning job. Overfitting dropped from 12% to 4%. IBM's comparison of RAG vs fine-tuning touches on this concept — when fine-tuning, you're trading off specialization vs. generalization.


Evaluation Strategy: The Hidden Hyperparameter

You're probably evaluating every 500 steps. That's a mistake.

The frequency of evaluation is itself a parameter that affects your final model. Too frequent and you waste compute. Too infrequent and you might miss the optimal checkpoint.

Here's what we do: Train for 1000 steps total. Evaluate every 50 steps for the first 200 steps. Then every 200 steps after. This catches early overfitting (which happens fast) and later plateaus.

We caught a model that peaked at step 180 and then declined. Most would have trained to step 500 and picked a worse checkpoint.


When Fine-Tuning Is the Wrong Choice

I've talked a lot about parameters to change when fine-tuning. But sometimes the right answer is don't fine-tune.

If your task is knowledge retrieval or question-answering over a changing dataset, use Retrieval-Augmented Generation (RAG). If you just need to adapt the model's style or tone, prompt engineering is cheaper and faster. The RAG vs fine-tuning debate in 2026 has largely settled: fine-tuning is for behavior change, RAG is for knowledge injection.

We had a client who wanted to fine-tune a model to answer questions about their internal API docs. They had 50 pages. Fine-tuning gave them hallucination rates of 15%. Switching to RAG dropped it to 2%.

This decision framework from earlier this year breaks it down cleanly.


FAQ: Parameters to Change When Fine Tuning LLM

Q: What's the single most impactful parameter for fine-tuning?

Learning rate schedule. Warmup + cosine decay beats constant or linear every time. We saw 5-8% improvement across three different tasks.

Q: How do I know when I've over-tuned a parameter?

Run three seeds for each parameter setting. If variance across seeds is larger than the improvement, you're over-tuning. Accept the default and move on.

Q: Can I fine-tune a 70B model on a single A100?

Yes, with LoRA. Use rank=8, Adafactor optimizer, gradient checkpointing, and 4-bit quantization. You'll get about 8-hour training for 10K samples.

Q: Should I ever fine-tune the embedding layer?

Rarely. Embedding layers are huge and changing them destroys the model's general knowledge. Only if you're adding new tokens (e.g., domain-specific vocabulary).

Q: What's the difference between fine-tuning for classification vs. generation?

Classification needs lower learning rates, higher epochs, and weight decay off. Generation needs more warmup, lower epochs, and weight decay on. The loss functions are different too — use cross-entropy for classification, causal LM loss for generation.

Q: I have 100 samples. Should I fine-tune?

Probably not. You'll overfit. Try zero-shot or few-shot prompting first. This paper shows that prompt engineering outperforms fine-tuning on datasets under 500 samples.

Q: Do I need to freeze the base model during LoRA?

Yes. That's the point of LoRA — only update the adapters. If you unfreeze the base model, you're doing full fine-tuning with extra memory overhead.

Q: How do I pick the best checkpoint?

Don't use the last checkpoint. Use the one with lowest validation loss. Save checkpoints every 100 steps and pick the best.


The Bottom Line

The Bottom Line

Fine-tuning an LLM is about controlling which parameters to change when fine tuning llm. It's not about throwing compute at the problem. It's about understanding the trade-offs.

I've seen teams spend weeks tweaking LoRA rank when their learning rate was wrong. I've seen production models fail because nobody checked batch size. I've seen classification models that cost $10K to train perform worse than a simple prompt.

Don't be that team.

Start with the defaults I've given you. Run your first experiment with three seeds. Change one parameter at a time. Keep a log. Measure everything.

And if you're still stuck, ask yourself: do you even need to fine-tune? Or is a RAG pipeline or a better prompt what you actually need?

Because the best fine-tuning decision is sometimes the one you don't make.


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