Domain Specialization in LLMs: A Practical Guide to Fine-Tuning vs. Distillation
This article explores how to transform large language models into domain experts by comparing fine-tuning and distillation. It provides clear selection criteria based on available assets, details three critical practices for successful distillation, and highlights the importance of high-quality data and locked evaluation sets. Readers will learn how to make cost-effective architectural decisions and implement a minimal training workflow for domain-specific reasoning models.
1. Clarifying the Basics: Fine-Tuning Modifies Weights, Distillation Learns Behavior
When transforming an LLM into a domain expert, the first question should not be “how do I do it,” but rather: do I need fine-tuning or distillation? These are two distinct technical approaches with different goals, cost structures, and use cases.
Fine-tuning directly modifies model weights. It requires domain-labeled data and uses gradient updates to help the model “grow” domain capabilities. The model’s behavior within the domain genuinely changes.
Distillation involves a small model (student) mimicking the behavior of a larger model (teacher). The student learns the teacher’s outputs on specific inputs, not its weights. The weight structures of the student and teacher can be entirely different; as long as the output behavior is sufficiently similar, the goal is achieved.
A critical misconception to correct: A domain expert = small model + domain data + an evaluation loop, rather than “copying an entire large model.” Many teams obsess over making the large model itself an expert. However, in most scenarios, a well-trained small model paired with a strict evaluation process offers a much better return on investment than forcibly fine-tuning a large model.
2. Route Selection: Depends on What You Have
The selection criteria are straightforward:
- If you have a teacher model that can batch-produce high-quality outputs → Choose distillation. The teacher’s single inference cost can be amortized into the student’s training. Later, only the small model is needed for online serving, drastically reducing inference costs.
- If you only have domain-labeled data and no readily available teacher → Choose fine-tuning. The data itself is the knowledge source; simply perform parameter updates directly on the target model.
For reasoning LLMs, domain specialization typically involves two viable paths that can be combined:
- Distill then deploy: Use a large model to generate answers with complete reasoning chains on domain questions, then use these answers to train a small model.
- Direct lightweight fine-tuning: Perform lightweight parameter updates (e.g., LoRA-based methods) directly on the large model using domain data.
Both paths work, but their cost structures differ fundamentally: Distillation front-loads compute on the teacher side, resulting in low downstream costs. Fine-tuning applies compute pressure to the model itself, leading to high inference costs. This trade-off must be weighed against business volume and latency requirements.
3. Three Key Practices for Distillation
1. Teacher Output Quality Determines the Student’s Ceiling
The student learns the teacher’s output, including its mistakes. In practice, this is a real pitfall: a systematic bias existed in the teacher’s outputs, the student inherited it completely, and it was only caught later using a validation set.
Therefore, you must sample teacher outputs before distillation:
- Randomly select a few hundred domain questions and manually check the correctness and stability of the teacher’s answers.
- Sample the same question multiple times to observe output variance.
- If the teacher is unstable in certain domains, the distilled student will only be more unstable. In such cases, improve the teacher’s capabilities first instead of rushing to train the student.
2. Data Should Be “Correct” and “Dense,” Not Just Abundant
In a real distillation project, the dataset contained 2,674 rows: 1,869 for training and 401 for validation. While 1,869 rows is small for LLM fine-tuning, each entry was a teacher-generated answer featuring a complete reasoning chain, resulting in extremely high information density. Ultimately, the champion model achieved a median error of 0.5500 on the validation set, and the cosine similarity between the student and teacher output vectors reached approximately 0.9976—a small model can learn the teacher’s behavior almost perfectly.
The takeaway: A few hundred to a few thousand high-quality, high-coverage domain samples are more effective than tens of thousands of generic samples scraped from the web. The key is coverage—your samples must cover the various question phrasings and edge cases within your domain first.
A typical distillation sample looks like this:
{"question": "Specific domain question...","reasoning": "Complete reasoning chain generated by the teacher...","answer": "Final answer provided by the teacher..."}
3. Define, Lock, and Do Not Modify the Evaluation Set
The project’s 401-row validation set remained fixed from start to finish. All parameter tuning and model selection relied exclusively on it. Fine-tuning without a fixed evaluation set is like driving blindfolded: you might think the model is improving, but it could simply be overfitting the training distribution. The evaluation set should share the same distribution as the training set but remain isolated. Once established, it must not be modified during training, or the evaluation results will become systematically distorted.
4. A Minimal Runnable Training Example
The following pseudocode illustrates the skeleton of distillation training (using a common syntax found in popular deep learning frameworks):
# 1. Load distillation data generated by the teachertrain_set = load_dataset("teacher_outputs.jsonl") # approx 1869 rowsval_set = load_dataset("val_fixed.jsonl") # 401 rows, locked and unmodified# 2. Load a small model as the studentstudent = load_student_model(small_size=True)# 3. Train: fit the teacher's outputsfor epoch in range(epochs):for batch in train_set:logits = student(batch.input_ids)loss = distillation_loss(logits, batch.teacher_output)loss.backward(); optimizer.step()# 4. Select the model based only on the fixed validation setbest = select_best_by_val(val_set, metric="median_error")print(evaluate(best, val_set)) # median error, cosine similarity with teacher outputs
5. Summary
Transforming an LLM into a domain expert boils down to a three-step decision chain: First, choose between distillation and fine-tuning based on whether you possess a “teacher capable of batch inference” or “only labeled data.” Second, strictly control data quality—sample teacher outputs first and prioritize sample coverage over sheer volume. Third, fix your evaluation set early and base all model selections on it. Domain expertise is not achieved by simply copying a large model; it results from the combined effort of a small model, high-quality domain data, and a rigorous evaluation loop.
