Knowledge Base · Learning paths
Understanding Model Fine-Tuning: Key Concepts and Terminology Explained
Model fine-tuning is the process of taking a pretrained large language model and continuing its training on task-specific data. This comprehensive guide breaks down essential concepts including pre-training, SFT, instruction tuning, LoRA, QLoRA, and PEFT, showing how fine-tuning enables LLMs to adapt to personal writing styles, vertical industries, and consistent output formats.
Translated from Chinese by AI. Spotted an issue? Use the feedback button.
🔗 Original link: https://x.com/rwayne/status/209446459907...
Roland.W · X · @rwayne · 2026-09-01 00:37
📌 This article is reposted. All copyrights belong to the original author. Please refer to the original link for the full text.
Model fine-tuning means taking a already-trained model and continuing to train it with a new batch of data that is relevant to your specific task. The model already understands language, can answer questions, and generate text. Fine-tuning builds on this foundation, making it better suited to a particular style of expression, type of task, or way of working. In vertical domains such as healthcare, law, or finance, where terminology and expression habits differ significantly, fine-tuning helps ensure a consistent output style, makes the large language model (LLM) follow instructions more reliably, and reduces hallucinations.
For ordinary users, the most direct benefit is making the model closer to their own way of expression. Requirements that previously had to be repeatedly written into prompts can now be partially embedded into the training results. AI-style phrasing that you used to delete every time, fixed sentence patterns that needed changing, and formats you constantly had to supplement — after training, the need for these manual corrections can be greatly reduced. Whether you’re doing customer service, classification, information extraction, or rewriting, you can use fixed examples to teach the model exactly what output format to produce for a given input.
Local fine-tuning has another important use case. When dealing with personal chats, voice transcripts, work records, or internal documents that cannot be uploaded to the cloud, you can organize and train the model entirely on your own machine. The model can then learn industry-specific terminology, internal classification methods, and expressions commonly used by your team, reducing the need for repeated explanations when handling such content.
What fine-tuning changes is the model’s tendency — given a certain type of input, what kind of output it is more likely to produce. If the training data contains only continuous personal speech, the model mainly learns “what usually comes after this text.” Only when the training data includes the task, the original content, and the confirmed correct result together will the model directly practice how to complete that task. How you structure the data ultimately determines what the model is actually learning.
After a training run, whether the result meets your requirements must be tested on data that was not included in the training. If the goal is to make the output closer to your own style, the final test is whether those repetitive AI-style expressions you used to delete are gone, and whether the output feels like something you would write at first glance.
In today’s article, we provide a detailed explanation of the basic concepts and terminology related to model fine-tuning.
Where the Model Begins
Pre-training / Pre-training
Pre-training is the stage where the model first learns language on a massive scale. It reads vast amounts of text and predicts the next token based on the preceding ones. Through this process, it internalizes language patterns, common sense, and reusable representations. When you download Gemma to your DGX Spark, its ability to write sentences and answer questions already comes from pre-training.
Base Model / Base Model
The base model refers to the original model weights at the starting point of subsequent training. Fine-tuning continues from here. Before you load a LoRA onto Gemma, the Gemma weights stored on disk are the base model.
Post-training / Post-training
Post-training refers to all training that occurs after pre-training is complete. Fine-tuning, supervised fine-tuning, preference learning, RLHF, and DPO can all take place during this phase. They address different objectives. Continuing to train a model that can already speak using a batch of customer service Q&A data falls under post-training.
Fine-tuning / Fine-tuning
Fine-tuning is the process of letting an already-trained model continue learning from a smaller, more specific dataset, so that its outputs move closer to the patterns in that data. It leverages the capabilities the base model has already acquired and adjusts it with relatively few target examples. This is also a form of transfer learning. For example, continuing to train Gemma with rewritten results you have personally approved aims to make it produce outputs closer to those results when handling similar content.
How Data Tells the Model What to Learn
Supervised Fine-Tuning / SFT
Supervised fine-tuning provides the model with clear inputs and target answers. The training program compares the model’s generated output with the target answer and updates the parameters based on the difference. For example, the input is a set of meeting notes that need to be organized, and the target answer is a verified summary. The model practices generating this kind of summary from the meeting notes.
Instruction Tuning
Instruction tuning is a common form of supervised fine-tuning. Each training sample includes a task instruction, input content, and target response. The model learns how to complete tasks by following instructions. For instance, the instruction might say “Keep all the facts but rewrite them in everyday language,” followed by the original text and the verified version. The model sees a complete rewriting task.
Causal Language Modeling
Causal language modeling trains the model to predict the next token based on all previous text. It is well-suited for learning how a piece of text should continue, including word choice, tone, and sentence development. When a batch of personal spoken narratives is fed to the model as continuous text, it practices how such speech typically continues.
Next-Token Prediction
Next-token prediction is the actual operation a language model performs at every step. The model first calculates which tokens are more likely to follow the current text, then selects one. Repeating this process generates a complete sentence. Given the prefix “After training, first check,” the model uses learned patterns to decide whether the next word is more likely to be “results,” “files,” or something else.
Why Training Can Run on DGX Spark
PyTorch
PyTorch is the software framework used to build and train neural networks. It handles tensor computation, automatic gradient calculation, optimizer calls, and hands off the actual computation to the GPU. After a training script on DGX Spark reads a batch, PyTorch computes the loss and gradients, then updates the trainable parameters.
Training Framework
A training framework organizes the entire pipeline: model loading, data reading, backpropagation, saving, and evaluation. PyTorch usually performs the underlying computations, while libraries such as Transformers, PEFT, TRL, Datasets, and Accelerate handle model management, data processing, and distributed execution on top. A single training script can use Transformers to load Gemma, create a LoRA adapter with PEFT, and let PyTorch perform the parameter updates.
Recipe
A recipe is a pre-written set of training practices. It specifies the model, data format, fine-tuning method, hyperparameters, and launch procedure. It provides a ready-to-run starting point, but still needs to be adapted to your own data and objectives. NVIDIA’s PyTorch fine-tuning recipe can show you how to start the container, but customer-service classification and personal-expression training will require different data structures.
Ancillary Files
Ancillary files are not part of the core model weights but are used during training, resuming, and reproduction. This category includes configuration files, the tokenizer, chat templates, training state, logs, READMEs, and file manifests. If the adapter weights are present but the matching tokenizer and configuration are missing, loading later may cause format or dimension errors.
Docker / Container
A container packages PyTorch, CUDA dependencies, and Python packages into a relatively fixed runtime environment. It primarily solves the problem of keeping software versions and dependencies consistent across different machines. On DGX Spark, the NVIDIA PyTorch container is used, so the training script sees a fully configured PyTorch and CUDA environment.
Which Part of the Model Does LoRA Actually Modify?
PEFT / Parameter-Efficient Fine-Tuning
PEFT is the general term for parameter-efficient fine-tuning. It keeps most of the base model’s parameters frozen and only trains a small number of newly added parameters. For a multi-billion-parameter model, the final fine-tuning result that needs to be saved may be just a tiny fraction of the original model.
LoRA / Low-Rank Adaptation
LoRA adds low-rank matrices alongside certain linear layers of the model. During training, only these newly added matrices are updated, while the base model weights remain frozen. “Fine-tuning” refers to the act of continued training, whereas “LoRA” describes how the parameters are modified during that training. After adding LoRA to Gemma’s attention layers, what gets saved at the end of training are only these additional parameters — not another full copy of Gemma.
QLoRA
QLoRA loads the frozen base model in lower precision and then trains the LoRA parameters. This significantly reduces the GPU memory occupied by the base model, allowing a larger model to fit within limited VRAM. When a single DGX Spark cannot hold both a high-precision base model and the training optimizer states, you can quantize the base model and focus the training entirely on the LoRA parameters.
Adapter
An adapter is the set of incremental parameters saved after fine-tuning. It records how the base model should change. When using it, you typically need to load both the corresponding base model and the adapter together. Only after you attach a writing adapter to a matching Gemma will the model exhibit the behavioral changes brought by that training.
Fresh Adapter / New Adapter
A fresh adapter means the LoRA parameters are re-initialized and training starts from scratch. The base model still retains all the capabilities it gained during pre-training, so “starting from scratch” only applies to the newly added parameters. After deleting the old adapter and creating a new set of LoRA parameters, Gemma does not forget the language knowledge it learned in the pre-training phase.
Rank / LoRA Rank / r
Rank determines the dimensionality of the low-rank space LoRA uses to record changes. As the rank value increases, the number of trainable parameters, file size, and expressive capacity usually increase as well. Training resource consumption and the model’s ability to memorize training samples also change. Using rank 8 versus rank 64 on the same target modules will result in very different numbers of LoRA parameters.
LoRA Alpha
LoRA alpha controls how strongly the LoRA branch influences the model’s final output. While the learning rate decides how parameters are updated in each step, alpha decides how much the LoRA branch is scaled during forward computation. If two trainings use the same rank and learning rate but different alpha values, the strength with which LoRA updates affect the model output will differ.
LoRA Dropout
LoRA dropout randomly ignores part of the LoRA paths during training. The same input sample may go through different additional connections across different training steps.
Target Modules / Target Modules
Target modules determine which layers of the model LoRA will be applied to. Since attention layers and MLP layers perform different computations, the choice of target modules directly affects both the number of trainable parameters and which parts of the model can be adjusted. You can apply LoRA only to q_proj and v_proj, or you can also include k_proj, o_proj, gate_proj, up_proj, and down_proj.
Safetensors
Safetensors is a binary format for saving model or adapter weights. When you open adapter_model.safetensors in VS Code and see a large amount of symbols, it is because the file stores numerical tensors.
How Text Becomes Training Data
Corpus
A corpus is a collection of text that the model will eventually see. It can still retain the original files, sources, and context, and does not yet need to follow the specific field format required by the training program. Personal monologues, chat logs, and already-published articles can first be placed into separate corpus folders.
Dataset
A dataset consists of samples that have been organized into a format readable by the training program. Only after the corpus has gone through filtering, merging, deduplication, splitting, and format conversion does it become a training set, validation set, or test set. Once a batch of spoken text is organized into a JSONL file with one sample per line, the training script can read it by field.
Original Source
Original source refers to the speaker’s own unedited words or externally sourced text with a clear origin that has not been rewritten by AI. Keeping the original source allows future traceability of where derived data came from and helps determine whose style of expression the model has learned. Original audio transcriptions and the cleaned training files must be stored separately; cleaned files must not overwrite the original transcripts.
Derived Data
Derived data are files generated from the original source through merging, cleaning, annotation, or splitting. A single chat export can produce continuous utterances, a training set, and a validation set—all of which are derived data.
Context Merging
Context merging combines multiple messages that belong to the same expression into a single sample. Merging decisions usually consider the sender, whether anyone else interjected, and the time gap between messages. When one person sends three consecutive follow-up messages with no replies from others in between, merging them produces a sample much closer to the original complete utterance.
Deduplication
Deduplication identifies and removes text that is completely identical, differs only in formatting, or is largely the same, preventing the model from repeatedly seeing the same content. Exact duplicates can be removed directly, while near-duplicates require judgment on whether they represent emphasis, self-correction, or actual repetition. If the same article is imported twice, one copy can be removed. However, when the same person first says something and then adds a correction, the semantic change should be preserved.
Context-dependent Short Reply
Context-dependent short replies are difficult to understand without the original conversation. They may carry tonal value but cannot independently tell the model what the reply is responding to. Phrases like “Okay,” “Absolutely,” or “Let me check” make sense in a chat, but provide very little information when turned into standalone training samples.
Quality Tier
Quality tiering groups corpus items based on completeness, expressive value, and degree of context dependence. Shorter or more colloquial content can be kept, after which a decision is made on whether it is suitable for direct training, needs review, or should remain in the raw material. A complete monologue can enter the main candidate pool, while a reply consisting of only a pronoun can be kept in the audit files.
Tokenizer
The tokenizer converts text into token IDs and converts the model’s output token IDs back into text. The base model already used a specific tokenization rule during pre-training; fine-tuning and inference must continue using the matching tokenizer. Gemma text cannot be arbitrarily converted using another model’s tokenizer and then trained directly, as the meaning of the token IDs would no longer align.
Max Sequence Length
The maximum sequence length defines how many tokens the model can read at once. When a long monologue exceeds this length, the remaining content must be split into new training blocks.
Packing
Packing places multiple short texts into a single training block, reducing padding and wasted computation. Many chat fragments containing only a few dozen tokens can be combined to fully occupy one sequence.
Train / Validation / Test
The training set is used to update model parameters, the validation set is used to monitor the model’s performance on data not involved in the current update during training, and the test set is used for final evaluation. The validation and test sets must be kept separate from the training set. If a test set is repeatedly adjusted based on its results, it will gradually lose its independence. From 1,000 samples, a portion can first be set aside for validation and testing, with the training program computing gradients only on the remaining samples.
Data Mixing Ratio
The data mixing ratio specifies what proportion of tokens from each source the model sees during training. The number of files, paragraphs, or characters cannot directly substitute for token proportions, because text length varies across sources. When mixing long monologues and short chats at a 60% to 40% ratio, the decision should be based on the actual number of tokens the model reads, not on how many files are allocated to each side.
Oversampling
Oversampling makes a less-represented category of data visible to the model more times, thereby increasing its share of the training data. After repeated exposure, this type of expression becomes easier to learn—but also more prone to being memorized as fixed sentences. If long articles are few in number but you want them to account for half of the training data, some of those samples will need to be repeated.
How Parameters Control the Training Process
Batch Size
Batch size refers to the number of training samples the GPU processes in a single forward-backward pass. When DGX Spark processes two long training sequences at once, the batch size is 2.
Gradient Accumulation
Gradient accumulation allows the GPU to process several small batches sequentially, accumulate their gradients, and then perform a single parameter update. This enables a larger effective batch size when the GPU memory cannot hold a large batch directly. For example, with a batch size of 2 and 8 accumulation steps, the effective batch size becomes equivalent to 16 training samples.
Epoch
An epoch means the entire training dataset has been passed through the model once. Setting 2 epochs means the model will go through the defined training set twice.
Step / Training Step
A training step typically refers to one parameter update performed by the optimizer. It does not necessarily correspond to processing a single batch, because gradient accumulation combines gradients from multiple small batches into one update. If gradients are accumulated 8 times before updating, the global step in the logs will only increase by 1.
Max Steps
Max steps defines the maximum number of parameter updates the training will perform. Setting it to 10 means the training will stop after 10 optimization steps.
Learning Rate
The learning rate controls how large a step the model takes during each parameter update. If the value is too large, training may become unstable and damage the model’s existing capabilities. If it is too small, there may be little noticeable improvement within a limited number of training steps. Using the same data for two training runs but changing only the learning rate can result in different loss reduction speeds and final outputs.
Warmup
Warmup gradually increases the learning rate from a very small value at the beginning of training. For example, if the first 100 steps are used for warmup, the learning rate will ramp up to the target value during this period.
Seed / Random Seed
The random seed controls random processes such as data shuffling order, parameter initialization, and dropout, making it easier to compare results across different experiments. Using the same seed can reduce variability, although tiny numerical differences may still occur due to GPU computation. When comparing two model ranks, using the same seed eliminates differences caused by data order.
What Remains After Training Completes
trainer_state.json
trainer_state.json records the training progress of the Transformers Trainer. It commonly contains information such as global step, epoch, logs, and the best checkpoint. It is usually located in the checkpoint directory; a copy is not necessarily kept in the final adapter root directory. To determine from which step training should resume, check this file in the most recent checkpoint first.
training_args.bin
training_args.bin saves the training arguments object used by the Trainer. It is a binary file intended to be read by programs. Opening it directly with a text editor will not produce a clear parameter table. To review settings such as batch size or learning rate, load this file in a Python environment, or keep a text-based configuration alongside it.
Loss / Training Loss
Training loss represents the gap between the model’s predictions and the training targets. During training, we generally want this value to decrease, as it indicates the model is becoming more accurate at predicting the current batch of training data. In the context of continued writing from original text, a decreasing loss means the model is getting better at predicting the tokens that follow the original text.
Eval Loss / Validation Loss
Eval loss is the model’s prediction error on the validation set. The validation set does not participate in updating the current parameters. When training loss continues to drop while eval loss starts to worsen, the model may be fitting the training data too closely. Calculating eval loss on a fixed validation set at regular intervals allows you to observe whether continued training is still bringing new generalization benefits.
Overfitting
Overfitting occurs when a model performs increasingly well on the training data but becomes worse at handling new content. It commonly appears when the dataset is small, contains many repeated exposures, or when training runs for too long. If the model can recite training articles but cannot use similar expressions to handle a new topic, this is a sign that overfitting should be investigated.
Memorization / Memorizing Training Text
Memorization refers to the model directly reproducing segments from the training corpus rather than merely learning vocabulary and expression patterns. A moderate amount of repetition can aid learning, but when certain fixed sentences are repeated excessively, the model becomes more likely to generate them verbatim. During testing, if you input a new topic and the model continues with an entire paragraph copied from the training text, this is a memorization phenomenon worth recording.
Inference
Inference is the process in which the model receives input and generates output. At this stage, the parameters are no longer updated. Loading the base model and the adapter onto a DGX Spark for conversation is an example of performing inference.
vLLM
vLLM is an inference engine for deploying and serving large language models (LLMs). It handles model loading, memory management, and processing of generation requests. It is used in the serving phase after training is complete; parameter updates during training are still handled by the training framework. Once the adapter passes acceptance, vLLM can be used on DGX Spark to provide a local API, allowing other programs to call the model.
Smoke Test
A smoke test uses a small amount of data and very few steps to verify whether the entire training pipeline can run. Its purpose is to confirm that the model can be loaded, data can be read, gradients can be updated, and files can be saved. It is not intended to judge the quality of formal training. Run 10 steps, successfully save the adapter, and only then decide whether to launch the full training that may take several hours.
Evaluation
Evaluation compares the outputs of the base model and the fine-tuned model using fixed inputs. The evaluation criteria should align with the actual objectives: for writing-style training, focus on expression, rewriting, and paraphrasing; for classification training, examine classification accuracy. Test both models with several new materials that did not participate in training, then record which version requires less manual correction.
When there is a mismatch between training inputs and actual usage inputs, the relationship between training performance and real-world results weakens. If the training data consists only of continuous original text, but actual usage requires the model to read external materials and then perform rewriting, these represent fundamentally different tasks.
Why Are Foundational Concepts and Terminology So Important?
While tinkering with DGX Spark recently, I realized that over-relying on AI to operate for us often makes it very difficult to identify problems. It was during this process that I discovered the importance of truly understanding basic concepts and terminology. I don’t think this article needs to be fully absorbed immediately. It can be read repeatedly, understood gradually, and internalized through your own hands-on practice, eventually becoming your own digested knowledge.
The practice of model fine-tuning will soon become widespread.
About the Author
Roland|PhD ing @UQ |DGX SPARK & Max 395 Local AIPC Enthusiast|Creating Knowledge, Creating Value|@rwayne