Generative AI and Large Language Models

Chapter 5
Adaptation, Fine-Tuning, and Alignment

Post Graduate Program in AI and ML
Generative AI and Large Language Models   •   Post Graduate

5. Adaptation, Fine-Tuning, and Alignment

Introduction and Context

A pretrained large language model (LLM) is not a finished application. Pretraining gives a model broad statistical knowledge of language, code, facts, styles, and patterns by exposing it to large collections of data. However, a pretrained model may not reliably follow instructions, respect organizational policies, use a specialized vocabulary, produce a desired output format, or behave safely in sensitive situations. Adaptation is the set of methods used to transform a general-purpose model into one that is useful for a particular task, domain, organization, or social context.

Adaptation includes supervised fine-tuning, instruction tuning, transfer learning, and parameter-efficient fine-tuning. Alignment addresses a related but broader question: how can a model’s behavior be made consistent with human intentions, institutional requirements, safety expectations, and legitimate user goals? Alignment methods include preference optimization, reinforcement learning from human feedback (RLHF), direct preference optimization (DPO), constitutional approaches, refusal training, and extensive evaluation.

These techniques are not interchangeable. Fine-tuning primarily changes what a model knows or how it performs a task. Alignment focuses more strongly on how the model chooses among possible responses and how it handles competing objectives such as helpfulness, truthfulness, harmlessness, privacy, and user autonomy. In practice, a production system commonly combines several methods rather than relying on one universal procedure.

Learning Objectives

After studying this chapter, the learner should be able to:

1. Explain the purposes and differences among continued pretraining, supervised fine-tuning, instruction tuning, and alignment.

2. Design a transfer-learning and fine-tuning workflow for a domain-specific LLM.

3. Compare full-parameter fine-tuning with parameter-efficient methods such as LoRA and adapters.

4. Describe preference optimization, RLHF, constitutional AI, and related alignment approaches.

5. Select evaluation metrics and identify risks such as overfitting, data leakage, reward hacking, and catastrophic forgetting.

6. Recommend technically and ethically defensible adaptation strategies for organizational applications.

From a General Model to a Specialized System

The adaptation problem can be represented as follows. Let a pretrained model with parameters θ generate a response y given a prompt x. Adaptation seeks new parameters θ′ or an additional parameter set φ such that the resulting model performs well on a target distribution of tasks, users, and contexts. The target distribution is usually narrower than the pretraining distribution, but it may impose stricter requirements concerning correctness, style, latency, privacy, and safety.

A useful distinction is between knowledge adaptation and behavioral adaptation. Knowledge adaptation attempts to improve performance on a domain, such as medicine, law, financial analysis, or enterprise procedures. Behavioral adaptation teaches the model how to respond: follow instructions, cite evidence, ask for clarification, decline unsafe requests, or return valid JSON. Retrieval-augmented generation can supply current or private information without modifying model parameters, whereas fine-tuning changes the model itself. These approaches can be combined, but they solve different problems.

The adaptation pipeline generally involves:

  • defining the target behavior and acceptance criteria;
  • collecting, licensing, cleaning, and labeling data;
  • selecting a base model and adaptation method;
  • training with carefully chosen objectives;
  • evaluating capability, robustness, safety, and generalization;
  • deploying with monitoring, rollback, and periodic reassessment.

The most expensive error is often not an inadequate optimizer but an unclear objective. “Make the model better” is not an operational specification. A useful objective states which users, tasks, constraints, failure costs, and evaluation measures matter.

Supervised Fine-Tuning and Instruction Tuning

Supervised Fine-Tuning

In supervised fine-tuning (SFT), the model is trained on examples of desired inputs and outputs. For a dataset D consisting of prompt-response pairs, the common objective minimizes the negative log-likelihood of the target response:

L(θ) = −Σ log pθ(y_t | x, y_<t)

where y_t is the next target token and y_<t denotes preceding target tokens. In conversational datasets, loss is often applied primarily to assistant tokens rather than to the user prompt. This focuses learning on the desired response and avoids treating the prompt as a prediction target.

SFT is effective when high-quality demonstrations are available. Examples may teach classification, summarization, code generation, structured extraction, domain terminology, or dialogue behavior. However, the model learns statistical regularities in the demonstrations, not an abstract guarantee of correctness. Poor demonstrations can teach verbosity, unsupported confidence, undesirable formatting, or systematic bias.

Instruction Tuning

Instruction tuning is SFT using examples in which a model is asked to perform explicit tasks, often across many domains. It improves instruction following and enables a model to generalize from observed tasks to new formulations. An instruction example typically contains a task description, optional context, and an ideal answer.

Instruction tuning should include variation in wording, difficulty, output format, and user intent. If all examples use the same template, the model may learn the template rather than the underlying task. High-quality instruction data should represent both positive and boundary cases: requests that can be answered, requests requiring clarification, ambiguous questions, and requests that should be refused or redirected.

Data Quality and Training Design

Data curation commonly includes deduplication, removal of personally identifiable information, toxicity screening, language and domain balancing, validation of labels, and separation of training and evaluation sets. Near-duplicate examples across these splits can produce inflated results. A domain dataset should also be checked for temporal coverage and representativeness; a model trained only on historical cases may perform poorly after policies, terminology, or regulations change.

Important training choices include learning rate, batch size, number of epochs, sequence length, optimizer, and checkpoint selection. More training is not necessarily better. Excessive epochs may cause memorization and catastrophic forgetting, in which general capabilities deteriorate. Early stopping and a validation set help identify the point at which specialization begins to harm generalization.

Transfer Learning and Adaptation Strategies

Transfer learning assumes that representations learned from a broad source task or corpus can support a related target task. In LLMs, the pretrained model supplies linguistic and conceptual structure; adaptation modifies that structure for a new objective. Three strategies are especially important.

Continued pretraining trains the model on unlabeled domain text using the original next-token objective. It is suitable when the target domain has substantial high-quality text and specialized language, such as scientific papers or source code. It can improve domain fluency but does not necessarily teach instruction following.

Supervised fine-tuning uses labeled demonstrations and is appropriate for task behavior, output conventions, and interaction patterns. It is often more data-efficient than continued pretraining when the target task is clearly defined.

Retrieval augmentation leaves the base parameters unchanged and supplies relevant documents at inference time. It is attractive for private, changing, or auditable knowledge. It does not, however, automatically teach the model how to reason over retrieved evidence or how to obey organizational policies; SFT or preference training may still be useful.

A mature system often uses continued pretraining for vocabulary, SFT for task behavior, retrieval for current knowledge, and preference optimization for response quality and safety.

Parameter-Efficient Fine-Tuning

Full fine-tuning updates most or all parameters of a model. It can provide strong specialization but requires substantial memory, storage, and operational effort. Maintaining separate complete model copies for many customers or tasks is costly. Parameter-efficient fine-tuning (PEFT) addresses this problem by freezing the base model and learning a comparatively small number of additional parameters.

LoRA

Low-Rank Adaptation (LoRA) represents an update to a weight matrix W as:

W′ = W + BA

where A and B are low-rank matrices and their rank is much smaller than the dimensions of W. During training, the original W remains frozen while A and B are learned. At inference, the adapter can be applied alongside the base model or merged into it.

LoRA reduces trainable parameters and makes it practical to maintain multiple task-specific adapters. Its effectiveness depends on where adapters are inserted, their rank, scaling, dropout, and the quality of training data. Very low rank may underfit a complex task; unnecessarily high rank increases cost and may encourage overfitting.

QLoRA combines LoRA with quantization of the frozen base model, reducing memory requirements while retaining a trainable low-rank update. Quantization can introduce numerical effects, so evaluation should compare the adapted quantized model with an appropriate full-precision baseline.

Other PEFT Methods

Adapters insert small trainable neural modules into selected layers. Prefix tuning and prompt tuning learn continuous vectors that influence the model without changing its main weights. These methods support modular deployment and can reduce storage, but their performance varies by task and model architecture. PEFT is not automatically safer than full fine-tuning: a small adapter can still encode privacy violations, bias, or undesirable behavior.

Preference Learning and Alignment

A supervised demonstration says, “For this input, produce this answer.” Preference data says, “Between these answers, this one is better.” The second formulation is useful because many responses may be acceptable, while quality depends on nuanced criteria such as relevance, truthfulness, tone, completeness, and safety.

Reward Modeling and RLHF

In the traditional RLHF pipeline, human annotators compare candidate responses to the same prompt. A reward model is trained to assign higher scores to preferred responses. The language model is then optimized to maximize this learned reward while remaining close to a reference model, often through a divergence penalty. Proximal Policy Optimization (PPO) has commonly been used for this reinforcement-learning stage.

The procedure involves:

1. generating multiple responses;

2. collecting rankings or pairwise preferences;

3. training a reward model;

4. optimizing the language model against the reward while constraining drift;

5. evaluating both desired capabilities and unintended effects.

RLHF can improve helpfulness and interaction quality, but it is operationally complex. Human preferences may be inconsistent, culturally narrow, or sensitive to superficial style. A reward model can be exploited by producing answers that sound convincing without being accurate. This is called reward hacking or specification gaming.

Direct Preference Optimization

Direct Preference Optimization (DPO) avoids separately training a reward model and running an online reinforcement-learning loop. It uses preferred and rejected responses to optimize the language model directly relative to a reference model. Conceptually, DPO increases the relative likelihood of preferred responses while reducing the likelihood of rejected ones, with a temperature or regularization parameter controlling the strength of the update.

DPO is often simpler and more stable to implement than PPO-based RLHF, but it remains dependent on preference-data quality. It may also inherit annotator bias and can overfit to the style of the comparison dataset. Other preference methods, including ranking-based and online optimization methods, make different trade-offs between simplicity, exploration, and control.

Constitutional Approaches

A constitutional approach specifies principles that guide model behavior, such as avoiding deception, protecting privacy, or explaining uncertainty. The model critiques and revises its own responses according to these principles, and the resulting comparisons can support preference training. This reduces dependence on direct human labeling for every example and makes normative assumptions more explicit.

A constitution is not a complete moral or legal authority. Principles can conflict, be underspecified, or reflect the assumptions of their authors. Human review remains important, particularly for high-impact uses and culturally sensitive decisions. Constitutional methods should therefore be treated as structured governance and data-generation tools, not as substitutes for evaluation and accountability.

Alignment as a Multi-Objective Engineering Problem

Alignment is frequently described as if it were a single property, but production systems must balance several objectives. A useful conceptual model is a constrained optimization problem:

maximize helpfulness and task performance,

subject to constraints on safety, privacy, legality, truthfulness, latency, and cost.

These objectives can conflict. A highly cautious model may refuse legitimate requests; a highly compliant model may provide dangerous instructions. A concise model may omit essential qualifications, while a highly detailed model may increase cognitive and computational burden. Alignment therefore requires explicit policy decisions and measurement of trade-offs.

Alignment is also layered. The base model may be trained for broad behavior; an organization may add policy-specific adapters; an application may use system instructions, tools, retrieval, filters, and human approval. Security testing must consider interactions across these layers. A well-written system prompt cannot reliably compensate for a model that has learned contradictory behavior, and a fine-tuned model cannot by itself guarantee secure tool execution.

Evaluation: Measuring Adaptation Without Being Misled

Evaluation should be designed before training. A useful test suite includes:

  • task performance: accuracy, F1 score, exact match, pass@k, or domain-specific measures;
  • generation quality: factuality, relevance, coherence, completeness, and style;
  • instruction following: adherence to constraints, formatting, and multi-step requirements;
  • robustness: paraphrases, distribution shifts, incomplete inputs, and adversarial prompts;
  • safety: harmful content, privacy leakage, discrimination, and unsafe tool use;
  • calibration: whether confidence or uncertainty corresponds to actual reliability;
  • operational measures: latency, throughput, memory, cost, and failure rates.

Automatic metrics are useful but incomplete. Human evaluation should use clear rubrics, blinded comparisons, multiple annotators, and adjudication for disagreement. Evaluation sets should include both ordinary and difficult cases, with separate slices for languages, user groups, topics, and risk levels. A single average score can conceal severe failures in a small but important population.

Before deployment, teams should compare the adapted model with the base model, a simpler baseline, and, where possible, retrieval-only or rules-based alternatives. Improvement on the fine-tuning dataset is not evidence of real-world benefit.

Applied Case: Adapting an Enterprise Policy Assistant

Background

A fictional organization, Meridian Utilities, wants an assistant that helps employees interpret internal procurement and safety policies. The organization has a general instruction-following LLM, a document repository containing current policies, and a requirement that answers cite source sections. The assistant must not approve purchases, invent policy, or disclose confidential employee information.

Situation and Problem

An initial prototype uses retrieval augmentation and a system prompt. It retrieves relevant documents but sometimes gives uncited summaries, treats outdated policies as current, and answers ambiguous questions with unwarranted confidence. Management is considering full fine-tuning on historical help-desk conversations.

Analysis

The primary problem is not simply lack of domain knowledge. Current policy content belongs in retrieval because it changes and must be auditable. Historical conversations contain useful examples of intent and terminology, but they also contain inconsistent answers and personal information. Full fine-tuning could memorize sensitive material and make policy updates difficult to propagate.

The team defines acceptance criteria: accurate citation of current documents, explicit uncertainty when evidence is insufficient, refusal to make authorization decisions, correct handling of personal data, and valid structured metadata for auditing. A held-out evaluation set is constructed from recent policy questions, adversarial ambiguity cases, and privacy-sensitive prompts.

Approach and Solution

Meridian first cleans and classifies documents by effective date, access permission, and policy owner. Retrieval is restricted by user authorization and includes document version metadata. A small, carefully reviewed SFT dataset teaches the assistant to ask clarifying questions, cite passages, distinguish interpretation from approval, and produce a standard answer format.

A LoRA adapter is trained rather than a complete model copy. Preference pairs are then created from realistic responses: one response may be fluent but unsupported, while another is cautious, cited, and appropriately scoped. DPO is used to favor the latter. A short constitutional policy instructs evaluators to check privacy, non-deception, and respect for authorization boundaries.

The deployment includes a citation validator, retrieval logging, prompt-injection tests on documents, rate limits, human escalation for high-risk cases, and rollback to the base model plus retrieval if the adapter causes regression. Monitoring tracks unsupported claims, citation validity, refusal rates, and user corrections.

Outcome

In the illustrative case, the adapted system improves consistency of citation and clarification behavior while keeping current policy knowledge in the retrieval layer. The team rejects a proposal to measure success only through user satisfaction because confident but incorrect answers could receive positive ratings. Instead, release approval depends on a balanced scorecard and mandatory review of severe failure cases.

Learning Points

The case demonstrates that adaptation is an architectural decision, not merely a training decision. Retrieval, SFT, PEFT, preference optimization, access control, and evaluation address different risks. Data governance and deployment controls are as important as loss minimization.

Risks, Limitations, and Common Mistakes

Catastrophic forgetting occurs when specialization damages general capabilities. Mixing a portion of general instruction data, reducing update strength, using adapters, and evaluating broad capabilities can reduce this risk.

Data leakage and memorization are especially serious when datasets contain credentials, medical records, private conversations, or copyrighted material. Data minimization, redaction, access controls, and extraction testing are essential.

Distribution mismatch arises when training examples do not reflect actual users, languages, domains, or adversarial behavior. A model can perform well on curated prompts and fail in production.

Preference overoptimization can make a model excessively agreeable, verbose, evasive, or sycophantic. Preference datasets should reward evidence, calibrated uncertainty, and appropriate disagreement rather than pleasantness alone.

Reward hacking and specification gaming occur when the model finds shortcuts that score well without satisfying the real objective. Independent factuality tests and adversarial evaluation help expose these shortcuts.

Format overfitting occurs when a model learns superficial templates. Varying prompt forms and testing unseen formats are necessary.

Adapter interference can arise when multiple adapters are composed or when an adapter conflicts with system policies. Compatibility testing and controlled routing are required.

False confidence in alignment is a governance failure. No fine-tuning method proves that a model is safe in every context. Human oversight, least-privilege tool access, logging, incident response, and model replacement remain necessary.

Ethical, Governance, and Professional Considerations

Training data must have a lawful and ethically defensible provenance. Organizations should document data sources, consent or licensing conditions, annotation procedures, known exclusions, and intended use. Annotators should receive fair compensation, psychological support for exposure to disturbing content, and clear instructions for difficult cases.

Alignment policies should not conceal legitimate uncertainty or suppress lawful criticism. Safety rules must be proportionate, explainable, and tested across languages and user groups. High-impact domains such as employment, credit, health, education, and public services require stronger validation and human accountability.

A model card or system documentation should describe the base model, adaptation method, data characteristics, evaluation results, limitations, known failure modes, and intended uses. Versioning is essential because changing a dataset, adapter, retrieval index, or policy can alter behavior. Organizations should maintain audit trails and procedures for correction, appeal, and withdrawal.

Current Developments and Best Practices

Current adaptation practice is moving toward smaller specialized adapters, synthetic data verified by humans, preference optimization without expensive online reinforcement learning, multimodal instruction tuning, and models that can use external tools. Quantization and PEFT are making local and resource-constrained deployment more feasible. At the same time, evaluation is becoming more scenario-based, with greater attention to long-context behavior, agentic tool use, prompt injection, and model autonomy.

A defensible professional workflow follows these principles:

1. Define measurable behavior and risk thresholds before training.

2. Use the least invasive adaptation method that solves the problem.

3. Keep changing or private knowledge in controlled retrieval systems when appropriate.

4. Treat data provenance, privacy, and annotator quality as engineering requirements.

5. Compare the adapted model with strong baselines and inspect failure slices.

6. Evaluate capability, truthfulness, safety, fairness, robustness, and operational cost together.

7. Deploy gradually with monitoring, human escalation, rollback, and documented ownership.

8. Re-evaluate after policy, data, model, or user-population changes.

Chapter Summary

Adaptation converts a general pretrained model into a system suited to particular tasks, domains, and organizational requirements. Continued pretraining improves domain language, supervised fine-tuning teaches task behavior, instruction tuning improves general instruction following, and retrieval augmentation supplies current or private information without changing parameters. Full fine-tuning offers broad flexibility but is expensive and vulnerable to forgetting and memorization. PEFT methods, especially LoRA and QLoRA, provide modular and efficient specialization.

Alignment concerns the selection of behaviors under competing objectives. RLHF uses human preferences, reward modeling, and reinforcement learning; DPO directly optimizes preferred responses relative to a reference model; constitutional approaches make principles explicit and use critique and revision. None eliminates the need for careful data, independent evaluation, governance, and monitoring. Successful deployment treats adaptation as a socio-technical process involving objectives, data, models, infrastructure, users, and accountability.

Key Terms

Pretraining: Learning general language or multimodal representations from large-scale data before task specialization.

Adaptation: Modifying a model or its surrounding system for a target domain, task, user group, or policy.

Supervised Fine-Tuning (SFT): Training a pretrained model on labeled examples of desired inputs and outputs.

Instruction Tuning: SFT using explicit task instructions to improve instruction-following generalization.

Continued Pretraining: Further next-token training on domain-specific, generally unlabeled data.

Transfer Learning: Reusing knowledge learned from a source distribution for a related target problem.

Parameter-Efficient Fine-Tuning (PEFT): Adaptation that updates only a small fraction of model parameters.

LoRA: A PEFT method that represents weight updates using low-rank matrices.

QLoRA: LoRA combined with quantization of the frozen base model.

Catastrophic Forgetting: Loss of previously learned capabilities during specialization.

Preference Data: Comparisons, rankings, or judgments indicating which model outputs are better.

Reward Model: A model trained to predict preference-based quality scores.

RLHF: Reinforcement Learning from Human Feedback using preferences to guide model optimization.

DPO: Direct Preference Optimization, which trains directly on preferred and rejected responses.

Constitutional AI: An approach that uses explicit principles to critique, revise, and guide model behavior.

Reward Hacking: Optimizing a proxy reward while failing to achieve the intended objective.

Alignment: Making model behavior consistent with legitimate human goals, values, policies, and safety constraints.

Retrieval-Augmented Generation: Supplying retrieved external information to a model during generation.

Calibration: The degree to which confidence estimates correspond to actual correctness.

Model Card: Documentation describing a model’s purpose, data, evaluation, limitations, and risks.

Review Questions

Short Answer Questions

1. Why is supervised fine-tuning different from continued pretraining?

2. What problem does LoRA solve in model adaptation?

3. Define catastrophic forgetting in the context of LLM fine-tuning.

4. What is the purpose of a reward model in RLHF?

5. Why should changing organizational knowledge often be handled through retrieval?

Long Answer Questions

1. Explain the complete workflow for adapting a general LLM to a specialized enterprise task.

2. Compare full fine-tuning, LoRA, adapters, prompt tuning, and QLoRA in terms of resources and operational flexibility.

3. Describe the RLHF pipeline and discuss its principal technical and ethical limitations.

4. Explain how DPO and constitutional approaches address alignment, and why neither removes the need for evaluation.

5. Discuss a comprehensive evaluation framework for an adapted LLM, including capability, safety, robustness, calibration, and operational metrics.

Analytical / Application Questions

1. An organization has a large archive of private, frequently changing regulations and a small set of labeled question-answer examples. Should it use continued pretraining, SFT, retrieval, PEFT, or a combination? Justify the architecture.

2. A fine-tuned assistant receives high user-satisfaction scores but frequently provides confident unsupported claims. Diagnose the likely evaluation and preference-training problems and propose corrective measures.

3. Design an alignment and governance plan for an LLM that can access enterprise tools and make recommendations in a high-impact domain. Identify constraints, evaluation slices, escalation rules, and monitoring signals.

22. Multiple Choice Questions with Answers

Question 1

Which adaptation method is most appropriate for teaching a model a specialized vocabulary from a large unlabeled corpus?

A. Continued pretraining

B. DPO only

C. Human escalation

D. Output filtering

Correct Answer: A. Continued pretraining

Question 2

What is the central idea of LoRA?

A. Replacing the tokenizer with a larger one

B. Updating all model weights at full precision

C. Learning low-rank weight updates while freezing the base model

D. Using retrieval instead of a language model

Correct Answer: C. Learning low-rank weight updates while freezing the base model

Question 3

Why might retrieval augmentation be preferred for frequently changing organizational policies?

A. It guarantees that the model will never hallucinate

B. It allows current, auditable information to be supplied without retraining model parameters

C. It eliminates the need for access control

D. It always requires fewer tokens than fine-tuning

Correct Answer: B. It allows current, auditable information to be supplied without retraining model parameters

Question 4

In RLHF, what is the usual role of a reward model?

A. To tokenize user prompts

B. To predict which candidate responses humans prefer

C. To retrieve private documents

D. To quantize the base model

Correct Answer: B. To predict which candidate responses humans prefer

Question 5

A model produces fluent answers that annotators prefer, but many are factually unsupported. Which problem is most directly indicated?

A. Reward hacking or preference overoptimization

B. Insufficient tokenizer vocabulary only

C. Successful calibration

D. Excessive retrieval authorization

Correct Answer: A. Reward hacking or preference overoptimization

Question 6

What distinguishes DPO from the traditional PPO-based RLHF pipeline?

A. DPO directly optimizes preference pairs relative to a reference model without separately running an online RL stage

B. DPO uses no training data

C. DPO changes only the tokenizer

D. DPO guarantees factual accuracy

Correct Answer: A. DPO directly optimizes preference pairs relative to a reference model without separately running an online RL stage

Question 7

Which evaluation design best detects whether an adapted model has lost general capabilities?

A. Evaluating only on the fine-tuning dataset

B. Measuring only response length

C. Comparing performance on held-out target tasks and broad general-capability benchmarks

D. Counting the number of trainable parameters

Correct Answer: C. Comparing performance on held-out target tasks and broad general-capability benchmarks

Question 8

What is a principal governance risk of fine-tuning on historical help-desk conversations?

A. The model cannot learn formatting

B. The data may contain private information and inconsistent or outdated answers

C. The model will necessarily become multilingual

D. Retrieval will become impossible

Correct Answer: B. The data may contain private information and inconsistent or outdated answers

Question 9

What does a constitutional approach primarily add to alignment?

A. Explicit principles used to critique and revise behavior

B. A guarantee that all human disagreement disappears

C. A replacement for every form of human evaluation

D. A method for increasing context length only

Correct Answer: A. Explicit principles used to critique and revise behavior

Question 10

Which practice is most defensible before deploying a high-impact adapted LLM?

A. Relying on one average benchmark score

B. Removing all uncertainty statements from outputs

C. Using staged deployment, risk-based evaluation, monitoring, human escalation, and rollback

D. Training until the validation loss is zero

Correct Answer: C. Using staged deployment, risk-based evaluation, monitoring, human escalation, and rollback

Generative AI and Large Language Models
Chapter 5 of 14