# Training Modes

Source: https://docs.surogate.ai/engine/getting-started/training-modes/

Surogate gives you five ways to adapt a model. This page explains each one so you can pick the right starting point:

1) **Pretraining / Continued Pretraining (PT)**
2) **Full Fine-Tuning**
3) **LoRA / QLoRA (Adapter Fine-Tuning)**
4) **RL Fine-Tuning (GRPO)**
5) **Preference Fine-Tuning (DPO)**

They differ in which parameters get updated, how much data you need, and how much compute and VRAM you will spend. If you already know your goal, the table below points you to a mode.

---

## Quick decision guide

| Goal | Recommended mode |
| --- | --- |
| Train a base model from scratch on large text | **Pretraining** |
| Continue training a base model on more text (domain adaptation) | **Continued pretraining** |
| Maximize quality for a specific task/domain and you can afford it | **Full fine-tuning** |
| Fast adaptation, smaller GPU, cheaper runs, easy iteration | **LoRA** |
| Same as LoRA but you’re VRAM-limited | **QLoRA** |
| Improve reasoning, math, coding via reward-based training | **GRPO** |
| Compress a larger model into a smaller one from the same family | **SFT + [Knowledge Distillation](/engine/guides/distillation/)** |
| Steer behavior from chosen-vs-rejected preference pairs (offline) | **DPO** |

---

## 1) Pretraining / Continued Pretraining (PT)

### How it works
**Pretraining** updates all (or nearly all) model weights by predicting the next token on large amounts of raw text.

- **What updates?** Base model weights (full model training)
- **Typical data:** Raw text corpora (`type: text` datasets)
- **Typical run shape:** Lots of tokens, long runs, throughput-focused

You usually run PT with:

```bash
surogate pt path/to/config.yaml
```

### When to use it
- You are training a new base model.
- You want domain adaptation through continued pretraining (for example on legal, medical or finance corpora).
- You care about general capabilities and learning a broad distribution.

### Tradeoffs
- Highest compute cost and longest wall-clock time.
- Needs the most data.

---

## 2) Full Fine-Tuning (update all weights)

### How it works
**Full fine-tuning** starts from a pretrained checkpoint and updates every parameter on a task or domain dataset.

- **What updates?** Base model weights (and optionally embeddings / lm_head depending on your config)
- **Typical data:** Instruction or conversation datasets
- **Typical run shape:** Fewer tokens than PT, but still heavy VRAM/compute

You usually run full fine-tuning through the SFT workflow with LoRA turned off:

```yaml
lora: false
```

Then run it with `surogate sft ...`.

### When to use it
- You need the best possible performance on a task or domain.
- You can afford the VRAM and compute to update all weights.
- You don't need to swap adapters across many downstream tasks.

### Tradeoffs
- Costs more and needs more memory than LoRA.
- Harder to maintain several downstream variants, since each run produces a full checkpoint.

---

## 3) LoRA / QLoRA (adapter fine-tuning)

### How LoRA works
**LoRA** freezes the base model weights and trains small low-rank adapter matrices inserted into selected linear layers.

- **What updates?** Only LoRA adapter parameters
- **Base weights:** Frozen (unchanged)
- **Typical data:** Instruction / conversation / task datasets

Turn on LoRA in your config with (all options under [LoRA Settings](/engine/reference/config/#lora-settings)):

```yaml
lora: true
lora_rank: 16
lora_alpha: 32
```

### When to use LoRA
- You want fast, cheap iterations.
- You want several downstream specializations (adapters are small to store, ship and swap).
- You are experimenting and want quick turnarounds.

### What is QLoRA?
**QLoRA** is LoRA with the frozen base model weights quantized to save VRAM.

- **What updates?** LoRA adapters (still)
- **Base weights:** Frozen and stored in a quantized format (FP8 / FP4 / NF4)
- **When to use it:** when VRAM is the bottleneck (see the [QLoRA guide](/engine/guides/qlora/))

Surogate supports three QLoRA formats:
- `qlora_fp8` (SM89+)
- `qlora_fp4` (SM100+ Blackwell)
- `qlora_bnb` (NF4 via BitsAndBytes, broad compatibility)

---

## 4) RL Fine-Tuning (GRPO)

### How it works
**GRPO** (Group Relative Policy Optimization) is a reinforcement learning method. The model generates rollouts, a reward function scores them, and the policy is updated to favor the higher-reward responses.

- **What updates?** LoRA adapter parameters (base model is frozen)
- **Typical data:** Prompts + reward environments (math, code, custom verifiers)
- **Typical run shape:** Iterative rollout → reward → gradient loop

One command runs all three GRPO components: the inference server, the orchestrator and the trainer.
On two or more GPUs, give inference and training their own GPUs:

```bash
surogate grpo --train train.yaml --infer infer.yaml --orch orch.yaml \
    --infer-gpus 0 --trainer-gpus 1
```

On a single GPU, co-locate them instead ([Single-GPU GRPO](/engine/guides/rl-colocate/)). They then share one resident copy of the base weights:

```bash
surogate grpo-colocate --train train.yaml --infer infer.yaml --orch orch.yaml
```

### When to use it
- You want better reasoning, math or coding than SFT gets you.
- You have a reward signal (a verifier, unit tests, reference answers), not only demonstration data.
- You want to optimize for the quality of outcomes instead of imitating a fixed dataset.

### Tradeoffs
- Needs a reward environment (built-in or custom; see [RL Environments](/engine/guides/rl-environments/)).
- The pipeline is more complex than SFT (inference server, orchestrator and trainer).
- Training dynamics are less predictable, so you need to watch importance ratios and masking fractions.

---

## 5) Preference Fine-Tuning (DPO)

### How it works
**DPO** (Direct Preference Optimization) teaches a model to prefer a *chosen* response over a *rejected* one for the same prompt. It works directly on the pairs, with no reward model and no rollouts. It is **offline**: you supply a static dataset of `{prompt, chosen, rejected}` triples, and the loss raises the implicit reward of `chosen` relative to `rejected`:

```
margin = β · [ (logπθ − logπref)(chosen) − (logπθ − logπref)(rejected) ]
loss   = −log σ(margin)
```

- **What updates?** LoRA adapter parameters (base model is frozen)
- **Reference model:** the frozen start checkpoint, evaluated inline with LoRA disabled
- **Typical data:** `type: preference` datasets (`{prompt, chosen, rejected}`)
- **Typical run shape:** a few hundred gradient steps over preference pairs

DPO runs from a single config (keys under [DPO Settings](/engine/reference/config/#dpo-settings)):

```bash
surogate dpo path/to/config.yaml
```

```yaml
loss:
  type: dpo
  dpo_beta: 0.1
  length_norm: false   # enable when chosen/rejected lengths differ a lot
  span_mask: false     # optionally score only differing token spans
datasets:
  - path: pairs.jsonl
    type: preference
```

### When to use it
- You have paired preferences (chosen vs rejected), not a reward function or plain demonstrations.
- You want to fix a specific behavior with small, targeted contrasts (for example correct vs incorrect word forms) without the cost and instability of RL.
- You want something simpler than GRPO, with no inference server and no orchestrator.

### Tradeoffs
- Needs preference pairs, and the result depends heavily on how you build them.
- `dpo_beta` controls how hard the policy is pushed away from the reference. Too high overfits; too low barely moves the model.
- Offline only: the pairs are fixed, with no on-policy regeneration.

---

## Practical recommendations

- Start with **LoRA (bf16 recipe)** unless you have a good reason not to.
- Use **QLoRA** when you can't fit the base model + activations comfortably.
- Use **Full fine-tuning** when you want maximum quality and have budget.
- Use **(Continued) pretraining** for domain adaptation on large raw text.
- Use **GRPO** when you have a reward signal and want to go beyond imitation learning.
- Use **DPO** when you have chosen-vs-rejected preference pairs and want offline preference steering without a reward model.

---

## See also

Picked a mode? Each quickstart gets you to a first run in a few minutes:

- [Quickstart: Pretraining](/engine/getting-started/quickstart-pretraining/)
- [Quickstart: Supervised Fine-Tuning](/engine/getting-started/quickstart-sft/): the usual starting point, with LoRA
- [Quickstart: GRPO](/engine/getting-started/quickstart-grpo/)
- [Quickstart: DPO](/engine/getting-started/quickstart-dpo/)
- [Configuration](/engine/guides/configuration/)
- [Precision & recipes](/engine/guides/precision-and-recipes/)
- [QLoRA](/engine/guides/qlora/)
- [Knowledge Distillation](/engine/guides/distillation/)
- [Config reference](/engine/reference/config/)
- [Back to docs index](/engine/)
