Overview

2 How to do model adaptation

This chapter frames model adaptation as a set of practical choices rather than a single “best” technique. It warns that teams often pick a method that is too heavy for the task, as in the opening example where full fine-tuning was used when retrieval over fresh documents was the real need. The central idea is an adaptation continuum: prompting, RAG, LoRA, full supervised fine-tuning, distillation, and preference optimization each add capability, but they also increase data needs, hardware requirements, timeline, cost, and operational complexity.

Most of the chapter is about matching the method to the problem. It explains that RAG is best when knowledge changes frequently, LoRA is often enough for voice, format, or domain behavior, full fine-tuning is reserved for harder reasoning or when LoRA plateaus, distillation helps when you want frontier-model quality at lower serving cost, and preference optimization is useful for refusal behavior, safety, and tone. The chapter also emphasizes that real production systems usually stack methods: a common pattern is a base model plus fine-tuning, retrieval, and guardrails, with telemetry and logging on top. It then walks through the buy-versus-build decision, showing when a managed API is the fastest and cheapest start and when self-hosting becomes necessary because of scale, privacy, or deeper customization needs.

The rest of the chapter gives the supporting infrastructure and operational guidance needed to make those choices work in practice. It reviews common training frameworks, the main categories of self-hosting infrastructure, and how to choose a base model based on task difficulty, latency, hardware, and ecosystem maturity. It then offers a small LoRA quickstart to show the full adaptation loop in miniature: prepare data, load a base model, train an adapter, generate outputs, and save the result. Finally, it stresses security and operations, noting that each adaptation method changes the attack surface and can weaken safety if not tested carefully, so teams should use regression checks, manifests, promotion lanes, canaries, rollback triggers, and monitoring from the start.

The hybrid production stack: each layer adds capability; requests travel down, responses come back up.
Managed-API cost scales with request volume; self-hosted cost is largely fixed.

Summary

  • The continuum is a menu to combine from, not a single rung to pick. Most production systems layer RAG for knowledge access, LoRA or SFT for behavioral specialization, and alignment for tone or refusal on top of a base model.
  • Half of the techniques on the continuum require fewer than a thousand examples, and the pair that is cheapest to build (prompting and RAG) ships in days and pays for its capability per call instead. Cost discipline argues for walking the continuum from cheapest to heaviest, not skipping straight to fine-tuning.
  • Buy versus build is upstream of any training decision. Managed APIs win on speed-to-prototype and operational simplicity. Self-hosting wins on customization depth, data privacy, and cost at scale once the volume crosses the break-even point.
  • Hard constraints decide the rung. Safety guarantees, latency budgets, data-residency requirements, and cost-per-call ceilings are what graduate a project from prompting to LoRA to full SFT, not enthusiasm for a heavier technique.
  • Each adaptation technique characteristically changes the attack surface. Fine-tuning erodes safety properties even on benign data; RAG opens a retrieval pipeline that can be poisoned; distillation transfers task behavior more reliably than refusal behavior. Mitigations are mostly operational rather than algorithmic.
  • A small set of operational disciplines (promotion lanes, artifact manifests, canary deployment, rollback triggers, traffic logging) belongs in the design from day one. Chapter 9 builds these out; this chapter establishes the floor.

FAQ

What is the “adaptation continuum” in this chapter?The adaptation continuum is the set of six main ways to adapt an LLM: prompting and in-context learning, RAG, LoRA/QLoRA, full supervised fine-tuning, distillation, and preference optimization. The chapter treats these as “rungs” that trade off capability, data needs, hardware, time, cost, and operational complexity.
How do I know which adaptation technique to choose first?Start with the cheapest approach that could solve the problem, usually prompting and then RAG. Only move to LoRA or heavier methods if the measured prompting baseline and retrieval-based approach still leave a meaningful gap. The chapter emphasizes that you should choose based on the shape of the task, not by defaulting to the most powerful technique.
Why can’t fine-tuning solve every knowledge problem?Fine-tuning changes the model’s behavior and style, but it does not update the model with fresh facts the way retrieval does. If the task requires current or fast-changing information, like yesterday’s earnings call or recent filings, RAG is usually the right tool because it injects live documents into the prompt at inference time.
What are the biggest trade-offs between prompting, RAG, and LoRA?Prompting is fastest and cheapest to try, but limited to what the base model already knows. RAG adds up-to-date knowledge and citations, but increases per-call token costs and adds retrieval complexity. LoRA changes the model’s weights, which gives more durable behavioral specialization, but requires training data, GPU time, and a training workflow.
What is a hybrid production stack, and why do teams use one?A hybrid stack combines multiple techniques, such as LoRA for domain behavior, RAG for fresh knowledge, and guardrails or system prompts for safe inference behavior. Teams use hybrids because different layers solve different problems: one layer changes what the model knows, another changes how it behaves, and another constrains outputs in production.
When should I buy a managed API instead of self-hosting?Buy a managed API when you are still exploring the problem, when a frontier model can already solve the task well enough, or when you do not want the operational burden of running GPU infrastructure. It is also the right choice when your usage volume is still below the point where self-hosting becomes cheaper.
When does self-hosting make more sense than a managed API?Self-hosting makes sense when data residency or privacy requirements prevent sending data to a vendor, when traffic volume is high enough that per-token pricing becomes too expensive, or when you need deep customization that managed APIs do not expose. It also gives you more control over latency, model choice, and the serving stack.
What infrastructure options are available for self-hosted models?The chapter highlights three main options: cloud GPU rental, on-premises GPU clusters, and cloud-managed inference services. Cloud GPU rental is the lowest-friction starting point, on-prem gives maximum control and lowest steady-state cost at scale, and cloud-managed inference sits between the two.
What tools does the chapter recommend for fine-tuning?The book uses TRL plus PEFT as its reference stack because they are flexible and widely used in the ecosystem. It also covers Unsloth for speed, Axolotl for YAML-driven reproducible recipes, LLaMA-Factory for a friendlier interface, and DeepSpeed for distributed scaling.
What security risks come with model adaptation?Each adaptation technique changes the attack surface. RAG can be vulnerable to prompt injection and corpus poisoning, fine-tuning can weaken safety behavior if training data is compromised, and distillation can fail to منتقل safety behaviors reliably. The chapter recommends safety benchmarks, provenance checks, red-teaming, and operational monitoring to catch regressions.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • LLM Customization and Fine-Tuning ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • LLM Customization and Fine-Tuning ebook for free