Training and Fine-tuning in Practice
The theory of how weights move lives in Chapter 17 (supervised fine-tuning and parameter-efficient methods) and Chapter 10 (sharding an optimizer across many accelerators). Practice asks a narrower question: in mid-2026, with a task and a budget, which tools should change a model's weights, how should they wire into the rest of the stack, and should the team be training at all? The answer is opinionated and dated. Lead with the categories and trade-offs, which are durable, and treat every version number, price, and ranking as a snapshot to re-check.
Frameworks, prices, GitHub star counts, and revenue figures below are a June 2026 snapshot, each attributed to a source. Per-token prices show the shape of pricing, not a canonical quote. Treat anything called uncertain as needing a fresh check before you commit a budget. The categories and the "how to choose" logic age slowly; the specifics age in months.
The layer and what it contains
Training and fine-tuning is the layer where you change weights, as opposed to the serving layer where you only run forward passes (Chapter 82) or the agent and retrieval layers where you steer a frozen model with context (Chapter 85, Chapter 86), though that frozen model can itself be trained to act and not only to answer (Chapter 37). In a real 2026 stack it splits into three sub-layers that are easy to conflate and behave very differently.
- Distributed engines. The heavy systems that shard a model and its optimizer state across many accelerators: PyTorch FSDP2 and TorchTitan, NVIDIA Megatron-Core, Microsoft DeepSpeed (ZeRO), and the JAX/XLA stack (MaxText) on TPUs. This is where 4D and 5D parallelism, FP8 training, and trillion-parameter scale live. Chapter 10 explains the mechanics.
- Post-training toolkits. Higher-level libraries that wrap those engines for supervised fine-tuning (SFT), preference optimization (DPO, which tunes directly on preferred-versus-rejected answer pairs, and ORPO), and reinforcement learning (GRPO, which scores groups of sampled answers, alongside GSPO and PPO): Hugging Face TRL, Axolotl, Unsloth, LLaMA-Factory. This is what most teams actually touch.
- Parameter-efficient methods and managed services. low-rank adaptation (LoRA), quantized low-rank adaptation (QLoRA), DoRA, carried by the PEFT library, plus hosted fine-tuning APIs that hide the accelerators entirely.
Two 2026 themes tie this layer to the rest of the book. FP8 training has gone mainstream: Google's Ironwood TPU has native FP8 in its matrix units, Megatron-Core ships FP8 training, and Unsloth does FP8 reinforcement learning (Google Cloud, 2026). More important for an infrastructure book, RL post-training has fused training with inference serving: modern RL toolkits embed an inference engine, almost always vLLM, to generate rollouts (sampled model attempts at a task), so the training box now contains a serving box. That is the wiring story at the end of this chapter.
The first fork: should you train at all?
Before tooling, answer the harder question. In 2026 the realistic default for many tasks is do not train weights. Prompt engineering, few-shot examples, retrieval (Chapter 86), and structured outputs cover much of what fine-tuning used to be reached for. OpenAI, while winding down its self-serve fine-tuning product, points users to prompt caching, smaller base models, and RAG instead (explainx.ai, secondary).
Fine-tune when you need a durable behavior change the context window cannot carry cheaply:
- a consistent output format or house style the prompt keeps drifting from,
- a narrow domain with vocabulary or conventions absent from the base model,
- a latency or cost win from distilling a large model's behavior into a small specialized one (this is the constraint arrow below),
- a capability shaped by reinforcement learning against a verifiable reward, the reasoning and agentic case from Chapter 28.
If none of these holds, spend the week on better prompts and retrieval, not on a training run.
The serving layer reaches up and justifies the most common reason to fine-tune. A small model that you have specialized costs far less per token to serve (Chapter 82) than a large general model behind an API. When you serve a high volume, the training run pays for itself in inference savings, which is the same over-training-for-inference logic from Chapter 5 applied one level up. Fine-tuning here is a serving-cost decision wearing a training costume.
Change the numbers (the one-time fine-tune cost and the two serving prices, all illustrative) and watch where the two cost lines cross: below the break-even volume the big API model is cheaper, above it the fine-tuned small model wins.
import numpy as np
import matplotlib.pyplot as plt
# Illustrative only: shape of the trade-off, not a quote.
finetune_cost = 50.0 # one-time fine-tune run, USD
big_price = 5.0 # large API model, USD per 1M tokens served
small_price = 0.5 # fine-tuned small model, USD per 1M tokens served
vol = np.linspace(0, 40, 200) # millions of tokens served
big_total = big_price * vol # no training, pay per token
small_total = finetune_cost + small_price * vol
break_even = finetune_cost / (big_price - small_price)
print(f"break-even at {break_even:.1f}M tokens served")
plt.plot(vol, big_total, label="big API model")
plt.plot(vol, small_total, label="fine-tuned small model")
plt.axvline(break_even, ls="--", color="gray")
plt.xlabel("tokens served (millions)"); plt.ylabel("total cost (USD)")
plt.legend(); plt.title("When does a fine-tune pay for itself?")
plt.show()
Key players (mid-2026)
The tables below are dated and source-attributed.
Distributed engines
| Name | What it is | License | Best for | Note (mid-2026) |
|---|---|---|---|---|
| PyTorch FSDP2 | Native fully-sharded data parallel; shards params, grads, optimizer state as DTensor | BSD | PyTorch-native sharded training without a heavy framework | FSDP2 is current; FSDP1 deprecated from PyTorch 2.11+. Adds per-param freezing, mixed FP8/BF16 (PyTorch tutorial) |
| TorchTitan | PyTorch-native pre-training platform on FSDP2; composable 4D parallelism | BSD | Production pre-training / continued pre-training on PyTorch | Reported speedups on Llama 3.1 recipes at 128 to 512 GPU scale (arXiv 2410.06511); foundation under torchforge |
| NVIDIA Megatron-Core | GPU-optimized tensor/pipeline/expert/context parallelism; product-supported | Apache-2.0-style + NVIDIA support | Large dense, MoE, and multimodal training on NVIDIA GPUs | Jan 2026 added dynamic context parallelism (reported up to ~1.48x on variable-length seqs); FP8 training (docs, roadmap) |
| NeMo / Megatron Bridge | Higher-level orchestration over Megatron-Core; recipes, export, alignment | Open source + NVIDIA support | Teams standardizing on the NVIDIA stack end to end | Bridge 0.4.0 (Apr 2026) added Kimi 2.5, Nemotron 3, Qwen 3.5 VL, FP8 export (docs) |
| DeepSpeed (ZeRO) | ZeRO sharding, CPU/NVMe offload, training optimizations | Apache-2.0 / MIT | Memory-constrained training, offload, very large models | Latest release v0.19.2 (Jun 2026); v0.19.x includes Muon-related ZeRO-3 updates (releases) |
| JAX + MaxText | Decoder-only LLM reference on JAX/XLA, tuned for TPU | Apache-2.0 | Foundation-model training on Cloud TPU | Ironwood TPU FP8; Qwen3-Next and DeepSeek features (Mar 2026). Pairs with Tunix for RL (docs, Cloud TPU + JAX) |
Post-training toolkits (what most teams touch)
| Name | What it is | License | Best for | Note (mid-2026) |
|---|---|---|---|---|
| Hugging Face TRL | Official HF post-training: SFT, DPO, GRPO, reward modeling | Apache-2.0 | The reference; building blocks others wrap | De-facto standard trainers; integrates PEFT, accelerate, FSDP/DeepSpeed (docs) |
| Axolotl | Config-driven (YAML) wrapper over TRL/PEFT; LoRA, QLoRA, full FT, multimodal | Apache-2.0 | Reproducible config-as-code runs on a few GPUs | Multimodal since 2025; "edit a YAML, get a run" (repo) |
| Unsloth | Custom Triton kernels for faster, lower-VRAM SFT and RL on 1 to 2 GPUs | Apache-2.0 core; paid Pro | Single-GPU efficiency; long-context GRPO | OSS is effectively single-GPU; robust multi-GPU is Pro (uncertain, status evolving). GRPO on a 24GB GPU; FP8 RL ~1.4x vs BF16 (docs) |
| LLaMA-Factory | Broad toolkit + web UI (LlamaBoard); widest model support | Apache-2.0 | Many model families, low-code UI, breadth over peak speed | ~68k GitHub stars; can use an Unsloth backend reportedly within ~6% of native speed (secondary) |
| torchtune | PyTorch-native post-training (SFT/DPO/PPO/GRPO/QAT), minimal abstraction | BSD | Hackable recipes on PyTorch | Maintenance only: active dev stopped Jul 15, 2025; an unnamed PyTorch-native successor is in development (issue #2883) |
| torchforge | PyTorch-native RL + agentic post-training on Monarch + TorchTitan + vLLM | Open source, experimental | Scalable RL post-training without writing distributed infra | Announced Oct 2025. Not the torchtune successor; sits on TorchTitan (training) and vLLM (rollouts) (PyTorch blog) |
| verl | Hybrid-controller RL post-training (the HybridFlow design, EuroSys'25): PPO/GRPO/GSPO/DAPO/REINFORCE++ over FSDP or Megatron trainers with vLLM/SGLang rollouts | Apache-2.0 | Production multi-node RL post-training | ByteDance-initiated, community-maintained; the de-facto multi-node RL framework. vLLM's own vime (Jun 2026) repeats the pattern, wiring Megatron and vLLM into one RL pipeline (repo, vime) |
| HF PEFT | Library implementing LoRA, QLoRA, DoRA, rsLoRA | Apache-2.0 | The adapter layer under TRL/Axolotl/LLaMA-Factory | Where the LoRA-family methods live (docs) |
Managed services (no accelerators of your own)
| Name | What it is | Best for | Note (mid-2026) |
|---|---|---|---|
| OpenAI fine-tuning | Hosted SFT/RFT on GPT models | (Winding down) | Self-serve fine-tuning is being wound down. No new orgs since May 7, 2026; all new jobs end Jan 6, 2027 (deprecations) |
| Tinker (Thinking Machines) | Managed LoRA SFT and RL over open weights, including large MoE (e.g. Qwen 235B-A22B); you write the training loop in Python, they run the distributed GPUs | Research-grade control without GPU operations | Launched Oct 2025; the counterpoint to OpenAI's self-serve wind-down: managed FT is consolidating, not dying (Tinker) |
| Together AI | Managed SFT, DPO, LoRA on open weights; per-training-token billing | Cheap LoRA/SFT on open weights + dedicated serving | E.g. LoRA SFT ~$0.48/M tokens (16B), full FT ~$3.20/M (70 to 100B), DPO ~$8/M; serving endpoint billed separately (secondary) |
| Fireworks AI | Self-serve post-training + fast serving in one place | Tune-and-serve together | Reported ~$800M ARR (May 2026), up from ~$305M (end 2025) (secondary) |
| AWS Bedrock | Managed SFT + RFT, including open weights, OpenAI-compatible APIs | AWS-native shops; RFT on open weights | RFT for open-weight + OpenAI-compatible FT added Feb 2026 (what's-new) |
| Modal | Serverless GPU compute; run torchtune/Unsloth/Axolotl yourself | Bring-your-own-recipe on on-demand GPUs | Not fully managed FT; you write the training code (ref) |
| Azure AI Foundry / Google Vertex | Cloud-native managed fine-tuning (Azure OpenAI, Gemini tuning) | Enterprises on Azure/GCP | Azure has FT cost-management tooling (Microsoft Learn) |
Parameter-efficient methods
These are techniques, not products; they live inside PEFT, Unsloth, and TRL. See Chapter 17 for the theory of why a low-rank update suffices.
- LoRA. Low-rank adapters; the default. Zero added inference latency once merged into the base weights.
- QLoRA. A 4-bit NF4 (a number format for weights) frozen base plus LoRA; the single-GPU sweet spot for roughly 1K to 50K examples.
- DoRA. Weight-decomposed LoRA (magnitude plus direction); better convergence, worth it at larger data, roughly 50K to 500K examples.
- rsLoRA. Rank-stabilized LoRA for high ranks.
- Newer arXiv variants (RandLoRA, activation-space methods) exist but are not defaults. Treat as frontier, unverified in production (AppScale 2026).
How to choose
Once you have decided you genuinely need to train weights, four questions settle the tool.
Scale of the run. One consumer or single GPU points to Unsloth for its kernels and low VRAM. A few GPUs with config-as-code call for Axolotl or LLaMA-Factory. Multi-node pre-training or continued pre-training is the territory of TorchTitan/FSDP2, Megatron-Core, or MaxText on TPUs.
Ecosystem you live in. NVIDIA GPUs plus a desire for vendor support point to Megatron-Core/NeMo. If you want PyTorch-native and hackable, that is FSDP2/TorchTitan + TRL; on TPUs it is JAX/MaxText. Pure Hugging Face muscle memory needs only TRL directly.
Method. Style or format with small data points to QLoRA. A deeper domain shift, with more data behind it, wants DoRA or high-rank LoRA. For a structural domain change with 500K or more examples, the answer is full fine-tuning. Reasoning or agentic behavior against a reward belongs to GRPO/GSPO: Unsloth on a single GPU, verl for multi-node production runs, TRL or the experimental torchforge on plain PyTorch (Chapter 28).
Self-host versus managed. Managed wins on time-to-first-run, no GPU operations, and elastic cost, with predictable per-training-token pricing. Self-host wins on data residency and IP control, unusual recipes, repeated or large runs where you amortize hardware, and avoiding vendor lock-in or sudden deprecation. Note the convenience tax: Together prices LoRA per training token plus a separate hourly dedicated endpoint to serve the result, so the cheap headline number is not the full bill.
Concrete picks:
- Pick Unsloth when you are on one 24 to 80GB GPU and want the fastest, lowest-VRAM SFT or long-context GRPO.
- Pick Axolotl when you want reproducible YAML-configured runs across a few GPUs and value config-as-code in CI.
- Pick LLaMA-Factory when you need breadth of model support or a low-code UI for non-experts.
- Pick TRL directly when you are writing custom post-training logic and want the canonical trainers.
- Pick TorchTitan/FSDP2 or Megatron-Core when you are doing real multi-node pre-training or continued pre-training.
- Pick MaxText when you are on TPUs.
- Pick a managed service when you have no GPU operations appetite and a standard SFT/LoRA/DPO/RFT workload, but design an export path given 2026's deprecation precedent.
A sensible default (mid-2026)
For a typical product team that has decided it genuinely needs to fine-tune an open-weight model, as of June 2026:
Default: Axolotl (YAML config) on top of TRL + PEFT, doing QLoRA, on
rented GPUs (Modal, Runpod, or your own cloud). It is reproducible,
config-as-code fits CI and eval (Chapter 87), QLoRA keeps it single-
or few-GPU, and you keep your weights and data. A starting recipe is r=16,
DoRA on, target_modules="all-linear", and you raise the rank for harder
tasks
(AppScale 2026).
- Alternative A, maximum single-GPU efficiency or RL: Unsloth, especially for consumer GPUs or long-context GRPO.
- Alternative B, no GPU operations at all: a managed service. Together for cheap open-weight LoRA/SFT, Fireworks if you want tune-and-serve in one place, Bedrock if you are AWS-native, Tinker if you want to keep writing the loop yourself and rent only the distributed GPUs. Build an export and portability path; do not assume a managed FT product is permanent. OpenAI's self-serve wind-down, announced May 2026, is the cautionary tale.
For multi-node pre-training rather than fine-tuning, the default shifts to TorchTitan/FSDP2 or Megatron-Core, or MaxText on TPUs.
Wiring it into the stack
The defining 2026 wiring fact is that RL post-training now embeds the inference layer. A GRPO or PPO loop generates rollouts from the current policy, scores them with a reward, then updates the weights. Generation is the bottleneck, so toolkits delegate it to a fast inference engine, almost always vLLM. Unsloth drives vLLM for rollouts; torchforge runs vLLM for generation and TorchTitan for training, shuttling weights between them through an RDMA tensor store (PyTorch blog); verl, the production multi-node case, schedules vLLM or SGLang rollout workers and FSDP or Megatron trainers under one hybrid controller, the same pattern vLLM's own vime adopted in June 2026. So the training box in your architecture diagram contains a serving box. This is the same vLLM from Chapter 82, now used as a training subcomponent, a clean instance of the book's thesis that these layers are one infrastructure. The architectural patterns that split that loop, colocated versus disaggregated, and the asynchronous-versus-on-policy trade, are the subject of Chapter 37.
After training you merge the adapter, or serve it directly with an adapter-aware engine, hand the weights to the serving layer behind your gateway (Chapter 82), and route an eval harness against it before promotion (Chapter 87). The retrieval and agent layers then consume the served model. Adapter-aware serving, many LoRAs over one base, is where managed adapter platforms historically fit. The whole flow assembles into the end-to-end stack of Chapter 88.
A config and a launch you can adapt
A minimal Axolotl QLoRA config, illustrative and meant to be edited:
# qlora.yml
base_model: Qwen/Qwen3-8B
load_in_4bit: true # QLoRA: 4-bit NF4 frozen base
adapter: lora
lora_r: 16
lora_alpha: 32
lora_target_modules: all-linear
datasets:
- path: ./data/sft.jsonl
type: chat_template
gradient_checkpointing: true
sequence_len: 4096
micro_batch_size: 2
num_epochs: 3
# distributed backend (FSDP2 or DeepSpeed) configured via accelerate
Launch it, then merge the adapter for serving:
# train (single or few GPUs via accelerate)
accelerate launch -m axolotl.cli.train qlora.yml
# merge the LoRA adapter back into the base for adapter-free serving
python -m axolotl.cli.merge_lora qlora.yml --lora_model_dir ./out
The merged weights are then handed to the serving stack. Keep the config in version control so a training run is a reviewable diff, the same discipline you apply to the rest of the infrastructure.
What fine-tuning really buys
Fine-tuning is first a capability lever, the durable behavior change a prompt cannot carry. Increasingly it doubles as an efficiency lever, distilling a large model into a small cheap-to-serve one, which is why the serving-cost constraint arrow points up so often. It also opens a trust surface: a fine-tuned model has absorbed your data, so data residency, reproducible config-as-code, and an eval gate before promotion are not niceties but the controls that let you ship the weights at all. The 2026 default is still to reach for prompting and retrieval first, and to train only when the behavior change has to live in the weights.
The unstable decision is whether fine-tuning is a capability investment or an expensive way to encode a brittle workflow. Small adapters can be cheap and reversible, but they can also hide data leakage, weaken general behavior, or move policy into weights where it is harder to inspect. Full training gives more control and more risk. The operational test is therefore narrow: train only when the desired behavior is frequent, measurable, hard to carry in context, and valuable enough to justify a separate evaluation and rollback path.
Further reading
First-hand sources first.
- PyTorch, “Getting Started with Fully Sharded Data Parallel (FSDP2),” n.d.. docs.pytorch.orgPyTorch tutorial introducing FSDP2, the updated fully sharded data parallel API for training large models across multiple GPUs.
- Liang et al., “TorchTitan: One-stop PyTorch Native Solution for Production-Ready LLM Pre-training,” 2024. arXiv:2410.06511TorchTitan is a PyTorch-native open-source LLM pretraining system that unifies composable 4D parallelism (DP, TP, PP, CP), Float8 training, and production-grade checkpointing, achieving up to 65
- PyTorch, “torchtitan,” n.d.. github.comTorchTitan is a PyTorch-native reference platform for training large-scale generative AI models, demonstrating FSDP, TP, and PP parallelism techniques.
- NVIDIA, “Megatron-Core documentation,” n.d.. docs.nvidia.comMegatron-Core is a PyTorch library that packages composable, modular GPU optimization APIs for training large-scale transformers at scale on NVIDIA infrastructure.
- NVIDIA, “Megatron-LM roadmap #4003,” n.d.. github.comNVIDIA's Megatron Core 2026 Q1 roadmap outlines planned features across parallelism (FSDP, MoE, PP), FP4/FP8 precision, multimodal training, RL, and inference for large-scale model training.
- NVIDIA, “NeMo Megatron Bridge documentation,” n.d.. docs.nvidia.comNeMo Megatron Bridge is a PyTorch-native library providing bidirectional checkpoint conversion between Hugging Face and Megatron Core, with pretraining and SFT support using TP, PP, and mixed-precision (FP8, BF16).
- Microsoft, “DeepSpeed releases,” n.d.. github.comDeepSpeed is Microsoft's open-source deep learning optimization library for efficient distributed training and inference of large models.
- Google, “MaxText documentation,” n.d.. maxtext.readthedocs.ioMaxText is Google's open-source, high-performance LLM library written in pure Python/JAX, targeting TPUs and GPUs for pretraining, SFT, and RL-based post-training.
- Google, “Training large models on Ironwood TPUs,” 2026. cloud.google.comGoogle's blog post describes techniques for training large models on the seventh-generation Ironwood TPU, covering FP8 precision, Tokamax kernels, SparseCore offloading, and parallelism strategies in JAX and MaxText.
- Google, “Cloud TPU + JAX AI stack,” n.d.. docs.cloud.google.comGoogle Cloud documentation page explaining how to build and run production AI workloads on Cloud TPUs using JAX and the JAX AI stack.
- Hugging Face, “TRL documentation,” n.d.. huggingface.coTRL is a Hugging Face library providing trainers for post-training transformer language models via SFT, GRPO, DPO, PPO, RLOO, reward modeling, and knowledge distillation.
- Hugging Face, “PEFT documentation,” n.d.. huggingface.coHugging Face PEFT is a library that adapts large pretrained models to downstream tasks by fine-tuning only a small subset of parameters, reducing compute and storage costs while matching full fine-tuning performance.
- Axolotl AI, “Axolotl,” n.d.. github.comAxolotl is an open-source fine-tuning framework for LLMs that supports SFT, PEFT methods such as LoRA and QLoRA, and multiple model architectures.
- Unsloth, “Unsloth documentation,” n.d.. unsloth.aiUnsloth is an open-source framework that provides optimized tools for running and fine-tuning LLMs, with support for LoRA and QLoRA training.
- Unsloth, “GRPO long-context guide,” n.d.. unsloth.aiUnsloth's documentation page describes how to run GRPO reinforcement learning fine-tuning with up to 7x longer context windows on consumer hardware.
- PyTorch, “torchtune future direction, issue #2883,” n.d.. github.comThe torchtune team announces it is halting active development on the library and will build a new PyTorch-native end-to-end post-training product in a separate repository.
- PyTorch, “Introducing torchforge,” 2025. pytorch.org
- PyTorch, “forge,” n.d.. github.comtorchforge is Meta's PyTorch-native open-source library for post-training (fine-tuning, alignment, RLHF) at scale.
- verl project, “verl: a flexible and efficient RL post-training framework” (HybridFlow (EuroSys'25); FSDP/Megatron training, vLLM/SGLang rollouts), n.d.. github.com
- vLLM, “Announcing vime: a simple, stable, and efficient RL framework for LLMs” (2026-06-09; Megatron + vLLM in one RL pipeline), 2026. vllm.ai
- Thinking Machines Lab, “Tinker” (managed LoRA SFT/RL over open weights; user-written training loops), 2025. thinkingmachines.ai
- OpenAI, “Deprecations” (fine-tuning wind-down), n.d.. developers.openai.com
- AWS, “Reinforcement fine-tuning for open-weight models on Bedrock,” 2026. aws.amazon.comAmazon Bedrock extends reinforcement fine-tuning (RFT) to open-weight models (Qwen, GPT-OSS) via OpenAI-compatible APIs, letting customers define reward functions without large labeled datasets.
- Microsoft, “Fine-tuning cost management,” n.d.. learn.microsoft.comMicrosoft Learn reference page explaining the training and hosting costs associated with fine-tuning models in Azure AI Foundry (Microsoft Foundry).
- AppScale, “LoRA, QLoRA, full fine-tuning compared,” 2026. appscale.blogA practical production guide comparing LoRA, QLoRA, DoRA, and full fine-tuning for LLMs, covering hardware sizing, hyperparameters, evaluation, and deployment patterns including multi-LoRA serving.
- CloudZero, “Together AI pricing,” n.d.. cloudzero.comA CloudZero pricing guide covering Together AI's per-token rates (0.10–9 per 1M tokens), GPU dedicated pricing, free tier, and cost optimization strategies across 200+ hosted models.
- Sacra, “Fireworks AI,” n.d.. sacra.comSacra's company profile for Fireworks AI, a cloud platform for running, fine-tuning, and scaling open-source LLMs and multimodal models with low-latency inference.
- UltraDune AI, “Fine-tuning in 2026: Axolotl vs Unsloth vs TRL vs LLaMA-Factory,” 2026. dev.toA practitioner comparison of four LLM fine-tuning frameworks, Axolotl, Unsloth, TRL, and LLaMA-Factory, as of 2026.
- All Things Open, “LLM fine-tuning as an open-source developer workflow,” n.d.. allthingsopen.org
Comments
Log in to comment