> ## Documentation Index
> Fetch the complete documentation index at: https://docs.together.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Supervised fine-tuning quickstart

> Run your first post-training session with supervised fine-tuning on instruction-following data, then download the trained weights.

[Supervised fine-tuning (SFT)](https://docs.together.ai/docs/post-training/sft.md) trains a model to imitate example responses. Each example pairs a prompt with the response you want, and training makes the model more likely to produce that response.

In this tutorial, you use a ready-made recipe from the [post-training cookbook](https://docs.together.ai/docs/post-training/cookbook-overview.md) to train a low-rank adapter (LoRA) for Qwen3.8 27B on the [No Robots](https://huggingface.co/datasets/HuggingFaceH4/no_robots) instruction-following dataset, then download the trained weights. Training takes about 10 minutes on a trainer-only model resource. The resource bills [per GPU-minute](https://docs.together.ai/docs/post-training/pricing.md) from when it's ready until it stops, at about \$48 per hour.

> [!TIP]
>
> For more control over the training loop, [write it yourself](https://docs.together.ai/docs/post-training/training-loop.md) with the Python SDK.

## Requirements

Before you begin, make sure you have:

* Python 3.11 or later and [uv](https://docs.astral.sh/uv/getting-started/installation/).
* The [Together CLI](https://docs.together.ai/reference/cli/getting-started.md), version 3.0.0 or later, to download the trained model. Install or upgrade it with `uv tool install "together[cli]" --upgrade`.
* A [Together AI account](https://api.together.ai/) with enough credit to run your model resource for four hours, the [minimum for creating one](https://docs.together.ai/docs/post-training/pricing.md#minimum-credit-balance).
* Your API key exported as `TOGETHER_API_KEY`. Get one from [API keys](https://api.together.ai/settings/api-keys) in the Together AI console.
* A Weights & Biases API key exported as `WANDB_API_KEY`. Most cookbook recipes log to Weights & Biases, including the one in this quickstart. To run without an account, export `WANDB_MODE=offline` instead.
* Optionally, a Hugging Face token exported as `HF_TOKEN` for gated models or datasets.

```bash theme={null}
export TOGETHER_API_KEY=<your_key>
export WANDB_API_KEY=<your_wandb_key>     # or: export WANDB_MODE=offline
export HF_TOKEN=<your_huggingface_token>  # gated models and datasets only
```

## Step 1: Clone the cookbook

Clone the cookbook and install its dependencies, including the Together Python SDK:

```bash theme={null}
git clone https://github.com/togethercomputer/post-training-cookbook.git
cd post-training-cookbook
uv sync --locked
```

## Step 2: Review the recipe

Open `recipes/sft/no_robots.py`. The recipe defines a config object and passes it to the cookbook's SFT training loop:

```python recipes/sft/no_robots.py theme={null}
from post_training_cookbook.sft.config import SFTConfig
from post_training_cookbook.sft.train import TRAIN_ON_LAST, train

config = SFTConfig(
    model="Qwen/Qwen3.8-27B",
    enable_thinking=False,
    dataset_name="HuggingFaceH4/no_robots",
    dataset_split="train",
    batch_size=8,
    learning_rate=1e-4,
    max_length=4096,
    max_steps=50,
    train_on_what=TRAIN_ON_LAST,
    training_checkpoint_interval=50,
    wandb_project="sft-no-robots",
)

if __name__ == "__main__":
    train(config)
```

Each No Robots example is a conversation with a user message and a human-written assistant response. The recipe trains the model to produce the assistant response from the conversation that precedes it.

The `train` function provisions a trainer-only model resource and attaches a session to it. For each batch, it runs `forward_backward` with the [cross-entropy loss](https://docs.together.ai/docs/post-training/sft.md#how-together-post-training-runs-sft), then `optim_step`.

These settings shape the run:

| Setting | What it does |
| - | - |
| `model="Qwen/Qwen3.8-27B"` | Selects the base model to train from the [catalog](https://docs.together.ai/docs/post-training/supported-models.md). |
| `enable_thinking=False` | Turns off the `<think>` output that Qwen3.8 27B's chat template enables by default. With thinking on, the template renders each prompt differently from the full conversation, so the recipe skips every row and the run ends with nothing trained. |
| `train_on_what=TRAIN_ON_LAST` | Trains on the final assistant turn only. `TRAIN_ON_ALL` trains on every assistant turn. |
| `max_length=4096` | Leaves room for the longer multi-turn conversations in the dataset. |
| `max_steps=50` | Keeps the run short enough to finish in minutes. Without a cap, `train` makes a full pass over the dataset. |
| `training_checkpoint_interval=50` | Saves a training checkpoint at the last step, which you need to [continue training this adapter](#continue-with-grpo) with group relative policy optimization (GRPO). |

## Step 3: Run training

Run the recipe:

```bash theme={null}
uv run python recipes/sft/no_robots.py
```

The recipe prints status lines while it waits for the model resource and the session to become ready. That usually takes a few minutes, or longer when GPUs are scarce. While the resource is queued, the status lines show its queue position, and the recipe keeps waiting until it gets GPUs. If you interrupt the recipe with Ctrl+C, the SDK [stops the resource](https://docs.together.ai/docs/post-training/model-resources.md#create-a-resource) before exiting.

Once the session is ready, the recipe prints one line per step. The first step takes longer than the rest, and saving the inference checkpoint at the end can take several minutes. You should see output like this:

```text theme={null}
[model-resources:3b9d6e2c-8f41-4a7e-b5d0-9e2c7a1f4d63] created, waiting for READY status...
[model-resources:3b9d6e2c-8f41-4a7e-b5d0-9e2c7a1f4d63] status=MODEL_RESOURCES_STATUS_PENDING elapsed=0.1s
...
[model-resources:3b9d6e2c-8f41-4a7e-b5d0-9e2c7a1f4d63] ready in 122.6s
[session:7c2e9f1a-4b3d-4e8a-9c21-0f6d2a8b5e47] created, waiting for RUNNING status...
...
[session:7c2e9f1a-4b3d-4e8a-9c21-0f6d2a8b5e47] ready in 61.2s
Session ready: 7c2e9f1a-4b3d-4e8a-9c21-0f6d2a8b5e47
Run artifacts: runs/Qwen3.8-27B_sft-no-robots_1.00e-04_8_20261001T153000Z
[step 1] loss=1.8907 (loss_sum=4985.7 over 2637 slots) lr=0.0001 samples=8 elapsed=117.2s (fb=116.4s optim=0.8s)
[step 2] loss=1.8073 (loss_sum=2665.8 over 1475 slots) lr=9.8e-05 samples=8 elapsed=122.2s (fb=4.1s optim=0.8s)
...
[step 50] loss=1.6347 (loss_sum=2468.4 over 1510 slots) lr=2e-06 samples=8 elapsed=316.9s (fb=4.2s optim=0.5s)
[step 50] training checkpoint: <training_checkpoint_id>
[step 50] inference checkpoint: <inference_checkpoint_id>
Training completed in 606.9s
```

`loss` is the mean cross-entropy per trained token, so it stays comparable across steps even as the batch's token count changes. Each batch holds different examples, so `loss` varies from step to step. Watch its trend rather than single steps. `lr` decays linearly toward zero over the run.

The recipe also logs each step to Weights & Biases and to `metrics.jsonl` in the run directory shown on the `Run artifacts` line.

## Step 4: Retrieve the trained model

The final inference checkpoint is registered in your project's model registry. To find its registry ID, look up the session that produced it. The `Session ready` line of the recipe's output shows the session ID, and the run's manifest records it too:

```bash theme={null}
cat runs/*/manifest.json | grep session_id
```

Pass the session ID to `tg training ls-checkpoints` to list its inference checkpoints:

```bash theme={null}
tg training ls-checkpoints --type inference --session <SESSION_ID>
```

The **Registry artifact** column holds the trained adapter's registry ID and revision ID, as `ml_...@rv_...`. Download the adapter with it:

```bash theme={null}
tg models download <MODEL_ID> ./sft_adapter
```

The CLI downloads only the adapter weights, in SGLang's multi-LoRA layout, which PEFT and Hugging Face Transformers can't load. For the [base model with the adapter merged in](https://docs.together.ai/docs/post-training/checkpoints.md#download-the-weights), ready for any inference framework, pass the ID on the recipe's `inference checkpoint` line to the SDK's `download_checkpoint` function.

> [!TIP]
>
> You trained a LoRA on No Robots and downloaded its weights.

## Stop the model resource

The run stops the session and the model resource when it exits, so billing has already ended. To confirm, list the model resources you created most recently:

```bash theme={null}
tg training ls-resources --created-by me --limit 5
```

You should see this run's resource first, with the status `stopped`. If the run was interrupted, its resource can still be active. A `ready` resource is billing, and a `pending` or `creating` one starts billing once it's ready. Stop the resource with its ID from the list:

```python theme={null}
from together import Together

client = Together()
client.post_training.model_resources.stop("<MODEL_RESOURCES_ID>", force=True)
```

`force=True` also stops any session that's still attached. Without it, the API refuses to stop a resource while a session is active.

You can also stop the resource from the **Model resources** tab under [Post-Training](https://api.together.ai/post-training/resources) in the console. [Manage model resources](https://docs.together.ai/docs/post-training/model-resources.md) covers stopping, idle timers, and what a resource costs while it runs.

## Continue with GRPO

A common pattern is to teach the model a format with SFT, then optimize it for task accuracy with GRPO. The GRPO run [continues the same adapter](https://docs.together.ai/docs/post-training/sft-recipes.md#chain-sft-and-grpo) from the training checkpoint your SFT run saved in Step 3.

## Next steps

> [card] [GRPO quickstart](https://docs.together.ai/docs/post-training/quickstart-rl.md)
>
> Train a model with GRPO and an exact-match reward on grade-school math.

> [card] [SFT recipes](https://docs.together.ai/docs/post-training/sft-recipes.md)
>
> Prepare your own data, set loss masks, and chain SFT into GRPO.

> [card] [Concepts](https://docs.together.ai/docs/post-training/concepts.md)
>
> See how work splits between your code and Together AI GPUs, and what model resources, sessions, and checkpoints do.

> [card] [Deploy a checkpoint](https://docs.together.ai/docs/post-training/deployment.md)
>
> Deploy the trained model on dedicated model inference.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.