Fine-Tuning Large Language Models: A Practical Guide from Data to Evaluation

    This guide walks through the full fine-tuning workflow for large language models: running a prompt-based feasibility check before training, building a clean and well-distributed dataset, choosing hyperparameters by order of magnitude, and evaluating with checkpoints and business metrics instead of training loss. It also includes a deployment checklist to turn fine-tuning into a reproducible engineering process.

    1. Start with a Prompt-Based Feasibility Check

    Many beginners jump straight into labeling data and writing training scripts, only to burn a large amount of compute before realizing the model never had the baseline capability to perform the task. A safer order is the reverse: get the prompt reasonably mature first, then use it to decide whether fine-tuning is worth the effort.

    The approach is straightforward. Pick a few dozen representative samples from the test set, let the base model answer using the prompt alone, and measure accuracy or the human-acceptable rate. A useful rule of thumb: if accuracy stays below 20% over time, the odds of fine-tuning turning things around are low. This usually means the task falls outside the base model’s capability boundary, and switching to a more capable base model is a better investment than piling on more data. Conversely, if a few prompt tweaks already produce decent results, the task is within the model’s reach. In that case the prompt does not need to be extremely elaborate—overly complex instructions dilute the key constraints and make it harder for the model to focus on what matters.

    The output of this step is not “a usable prompt” but a clear conclusion: proceed with fine-tuning, switch the base model, or redefine the task boundary.

    2. Data Construction: Data Sets the Ceiling

    2.1 Generate with a Strong Model, Label with Cross-Model Review

    When human resources are limited, a common practice is to have a more capable model generate candidate question-answer pairs, then bring in several different models to review them independently. Only samples that pass with a majority vote and consistent reasoning make it into the training set. This “generate—cross-review—filter” pipeline significantly reduces noise. If there is a human budget, spot-checking remains worthwhile, especially for boundary and long-tail samples, where human judgment delivers the highest marginal return.

    2.2 Consistent Style Is the Foundation of Not Learning the Wrong Pattern

    Models are extremely sensitive to format consistency. If the task requires structured output, every entry in the training set should use the same wrapping format—not half wrapped in code block markers and half as raw text:

    1. ```json
    2. {"name": "example", "score": 0.93}
    1. Likewise, if the goal is to generate queries and the training set consistently uses explicit column names, implicit column-name shorthand should not be mixed in. Inconsistent style teaches the model the wrong rule—that format is random—and output becomes unstable at inference time. It is worth defining a format specification document for the dataset and running an automated script check before ingestion to block non-compliant samples outright.
    2. ### 2.3 Distribution Coverage: The Training Set Must Cover the Test Set's Distribution
    3. This is the point beginners most often overlook, and it carries the highest cost. Poor test-set results alongside good training-set metrics are often not overfitting; rather, some category of problem in the test set has no corresponding form in the training set at all. To diagnose this, segment the test set by intent, difficulty, input length, output structure, and other dimensions, then check each segment's share in the training set. When you find a gap, add targeted data—start with 5 to 10 samples for a small-scale validation, watch whether metrics recover, and then decide whether to scale up. This incremental approach saves more time than adding thousands of samples at once.
    4. ### 2.4 Skip Chain-of-Thought and Few-Shot Examples in the Fine-Tuning Stage
    5. Chain-of-thought and few-shot examples do improve a base model's direct performance, but they are expensive and slow to label, and they lengthen the input and raise inference cost. Once you move into fine-tuning, the right strategy is to compress knowledge into the weights: provide enough clean samples in the exact target form so the model learns to produce the final answer in one pass. Trading data volume for prompt-engineering complexity is a plain but effective method.
    6. ## 3. Hyperparameters: Go from Large to Small
    7. There is no need for a fine-grained search at the start; try values by order of magnitude. Start with a learning rate of 1e-4 and a weight decay of 0.25, first confirm training is in a reasonable range, then narrow down. A practical sequence: fix the other parameters and vary only the learning rate until the loss decreases steadily; then adjust weight decay and observe the difference in generalization; finally tune batch size and number of epochs. Larger models typically have a higher ceiling. If GPU memory is insufficient, enable sharding and memory-optimization approaches to split state that does not fit on a single card across multiple devices.
    8. ## 4. Evaluation: Don't Treat Training Loss as the Judge
    9. This is the most important mindset shift in the whole process. In mid-to-late training, a decreasing loss does not mean better results, and it is not unusual for loss on the training set to drop and then rise. Loss is only a coarse signal of whether learning is proceeding normally.
    10. A more reliable approach is to save checkpoints at small step intervals from early in training, evaluate each one with accuracy or real business metrics, and watch whether the curve converges as training progresses. An example flow:
    11. ```python
    12. for step in range(total_steps):
    13. train_one_step()
    14. if step % save_every == 0:
    15. ckpt = save_checkpoint(step)
    16. metrics = evaluate(ckpt, eval_set) # prioritize business metrics
    17. log(step, metrics)

    An additional benefit is that you can select the checkpoint with the best metrics rather than the last step, avoiding degradation from overtraining.

    5. Deployment Checklist

    • Did prompt-stage accuracy reach above 20%? If not, switch the base model first.
    • Is the training set aligned with the test set distribution layer by layer, and have gaps been filled with targeted data?
    • Is the output format fully consistent, with automated checks blocking dirty samples?
    • Have the learning rate and weight decay been set by order of magnitude and then narrowed down?
    • Are checkpoints saved at small step intervals and selected by business metrics?
    • Have chain-of-thought and few-shot examples been removed on the inference side to keep inputs lean?

    Follow this chain and fine-tuning turns from luck into a reproducible engineering process. If you need elastic compute and a training environment, you can build the pipeline on general-purpose capabilities such as Baidu AI Cloud’s container platform, object storage, and monitoring and alerting, chaining data validation, training, and evaluation into an automated loop.