A Practical Guide to Building Small-Model Domain Experts: Fine-Tuning vs. Distillation

    This guide explains how to build a domain-expert small model by choosing between fine-tuning and distillation based on the assets you already have. It covers route selection, key distillation practices such as teacher output review, data coverage over volume, and a frozen evaluation set, plus alignment and task metrics, private deployment considerations, common failure modes, and a step-by-step implementation checklist.

    1. Define the Goal First: Fine-Tuning or Distillation?

    In engineering practice, many teams start by asking which model to use, how much GPU memory is needed, and how many days training will take. But the first question that actually determines project success is whether you want to change the model’s weights or its behavior.

    These two goals have completely different objective functions:

    • Fine-tuning: Continue training on existing parameters with domain-labeled data so the weights shift toward the domain distribution. It solves the problem of the model not having seen a certain type of task or expression.
    • Distillation: Have a small model (the student) imitate a large model’s (the teacher) output distribution or output text on specific inputs. It solves the problem of wanting a large model’s capabilities without being able to afford to deploy one.

    In short: fine-tuning changes weights; distillation learns behavior. Conflating the two is a common starting point for wasted resources and results that fall short.

    It is also necessary to clarify the real definition of a “domain expert”: it is not moving a large-parameter model wholesale to local infrastructure, but a combination of a small model + high-quality domain data + a sustainable evaluation loop. Without the evaluation loop, you cannot tell whether the model has genuinely improved or has just memorized the training set more thoroughly.

    2. How to Choose Between the Two Technical Routes

    The choice of route does not depend on technical preference, but on what assets you already have:

    What you already have Recommended route Reason
    A usable strong reasoning model that can generate high-quality outputs in batches Distillation The student aligns directly with teacher behavior, and the ceiling is determined by the teacher
    Only domain-labeled data, no usable teacher Fine-tuning No teacher inference cost, and the labeled signal is used directly
    Both a small footprint and strong reasoning performance are required Distillation + lightweight fine-tuning Learn behavior first, then correct with domain labels

    For models with long-chain reasoning capabilities (the strong reasoning model in the original text belongs to this category), building a domain expert usually involves stitching the two routes together:

    1. First, have the strong reasoning model generate answers with the complete reasoning process for domain questions, forming distillation corpus data;
    2. Then train the small model on this corpus so that it closely matches the teacher in reasoning format and answer quality;
    3. Optionally, use a small amount of high-quality manual labels to run a lightweight fine-tuning pass on the distilled small model to correct systematic bias.

    The cost structure of this route differs markedly from direct fine-tuning: the main costs of distillation are teacher inference and data construction, while the main costs of fine-tuning are labeling and training hyperparameter tuning.

    3. Three Practical Points for the Distillation Route

    3.1 Teacher Output Quality Sets the Student’s Ceiling

    The student learns not only the correct answers but also the teacher’s mistakes and style biases. If the teacher itself is inconsistent on domain questions, the student will only solidify that inconsistency.

    Therefore, teacher output spot checks must be done before distillation: randomly sample several hundred entries and evaluate their accuracy and consistency on domain questions manually or semi-automatically. A sample spot-check script:

    1. import random
    2. def sample_for_review(teacher_outputs, k=300, seed=42):
    3. random.seed(seed)
    4. return random.sample(teacher_outputs, min(k, len(teacher_outputs)))
    5. # Review dimensions: factual correctness / reasoning chain completeness / format stability / whether refusal on boundary questions is reasonable

    Empirical rule of thumb: if the teacher answers vaguely or contradicts itself on your domain questions, fix the teacher side first (prompt strategy, retrieval augmentation, domain material injection) rather than rushing to train the student.

    3.2 More Data Is Not Better; More “Right” Data Is Better

    A reference sense of scale: a domain distillation dataset with about two thousand training examples and about four hundred validation examples looks small at large-model scale, but since each entry is an answer with a complete reasoning process generated by the teacher for domain questions, its information density is far higher than general corpus data scraped from public sources.

    The conclusion is: in domain distillation, a few hundred to a few thousand highly relevant samples are usually more effective than tens of thousands of generalized samples. The key metric is coverage rather than total volume. Coverage should include at least:

    • Multiple phrasings of the same intent (colloquial, formal, abbreviations, typos);
    • Typical boundary cases (insufficient information, false premises, out-of-domain scope);
    • Scenarios requiring refusal or handoff to a human;
    • Scenarios with different output format requirements (conclusion first, bullet points, tables).

    Building a coverage matrix before adding samples avoids the false sufficiency of “many samples but a single scenario.”

    3.3 Define the Evaluation Set First, Freeze It, and Do Not Touch It

    A fixed, unchanging validation set is the referee for the entire process. Hyperparameter tuning, checkpoint selection, and comparing different data mixes are all based on it. Once the evaluation set is repeatedly adjusted, metric improvements lose their meaning—that is usually just a representation of overfitting to the training set.

    Practical advice: sample the evaluation set in a stratified way from real business questions, covering both high-frequency and long-tail cases; read only and never write to it throughout training; manage it with version control, and any change must go through review and leave a record.

    4. Engineering Practices to Make Distillation Measurable

    The goal of distillation training is to make the student’s output vectors or output text as consistent as possible with the teacher’s. Two types of signals are commonly used:

    1. # Illustration: output vector alignment (cosine similarity) + text-level alignment loss
    2. cos_sim = (student_vec * teacher_vec).sum() / (
    3. student_vec.norm() * teacher_vec.norm()
    4. )
    5. loss = text_align_loss(student_logits, teacher_outputs) - 0.1 * cos_sim

    In several public practices, the cosine similarity between student and teacher output vectors can reach above 0.99, showing that behavior-level alignment is feasible; but note that high similarity only means “resembling the teacher,” not “being correct.” Therefore, the evaluation system must include:

    • Alignment metrics: similarity, output format consistency rate;
    • Task metrics: domain accuracy, key field extraction accuracy;
    • Stability metrics: variance across multiple samples, long-tail question performance.

    5. Supporting Design for Private Deployment of Small Models

    The target model needs to run on a personal workstation or a cost-controlled server. Beyond the model itself, you also need to consider:

    • Quantization and inference optimization: reduce GPU memory usage within an acceptable range of precision loss;
    • External domain knowledge: use retrieval augmentation to keep literature, specifications, and case libraries outside the model, reducing parameter pressure;
    • Service encapsulation: a unified inference interface for easy canary release and rollback;
    • Observability: use logging services and monitoring alerts to track latency, failure rate, and output distribution drift;
    • Data and model hosting: keep corpus and checkpoints in object storage, and run training jobs on a container platform to ensure reproducibility.

    When deployed on the cloud, the above capabilities are usually provided as general categories (object storage, container platform, logging service, monitoring alerts, etc.). Baidu AI Cloud’s relevant product system also follows this general layering, making it easy for teams to combine them as needed without being locked into a single implementation.

    6. Common Failure Modes and How to Avoid Them

    1. Skipping teacher spot checks: fully inheriting the teacher’s systematic bias, which is hard to locate later.
    2. Padding with general corpus: total sample volume goes up, but domain coverage does not, and metrics do not move.
    3. Evaluation set drift: changing the validation set with every tuning round makes conclusions untrustworthy.
    4. Only looking at similarity: alignment metrics look good while task metrics collapse.
    5. Chasing a small footprint in one step: over-compression causes reasoning ability to collapse; determine the acceptable lower bound first, then compress.

    7. Implementation Checklist

    1. Define the goal: change weights or learn behavior, and whether private deployment is mandatory;
    2. Inventory assets: whether you have a teacher, labels, and real problem logs;
    3. Build a coverage matrix, write the evaluation set first and freeze it;
    4. Spot check teacher outputs, and fix the teacher side first if it does not meet the bar;
    5. Validate feasibility with a small-batch distillation, then scale up;
    6. Optionally run lightweight fine-tuning for correction;
    7. Quantization and compression + retrieval augmentation + service deployment;
    8. Establish monitoring and regression evaluation to form a continuous iteration loop.

    Following this order turns building a domain-expert model from “training by luck” into an engineering process that is measurable, reproducible, and iterable.