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

# Continue training from a checkpoint

> Start a new Loops run from saved training state, with or without its optimizer state, from the Python SDK or the Loops cookbook.

To continue training after a run ends or is preempted, start a new run from a training-state checkpoint. The new run uses the checkpoint's base model and LoRA configuration. Choose how much state it restores:

* **Weights and optimizer state:** restores the adapter, the optimizer state, and the step count. Use it to continue an interrupted run where it stopped.
* **Weights only:** restores the adapter and starts a fresh optimizer. Use it to begin a new training stage from saved weights.

To save training state, see [Save a checkpoint](https://docs.baseten.co/loops/save-checkpoints.md).

The Python SDK and the cookbook authenticate with `BASETEN_API_KEY`. Export your [API key](https://docs.baseten.co/organization/api-keys.md) first:

```sh theme={"system"}
export BASETEN_API_KEY="YOUR_API_KEY"
```

> [tab] Python SDK
>
> **To continue training from saved state**:
>
> Create a training client from the saved state's path with [`ServiceClient`](https://docs.baseten.co/reference/sdk/loops/service-client). Replace `<state_path>` with the `path` that [`save_state()`](https://docs.baseten.co/reference/sdk/loops/training-client) returned, then run:
>
> ```python theme={"system"}
> from baseten.loops import ServiceClient
>
> training_client = ServiceClient().create_training_client_from_state_with_optimizer("<state_path>")
> print(training_client.run_id)
> ```
>
> The script prints the new run's ID. To restore the weights with a fresh optimizer instead, call [`create_training_client_from_state()`](https://docs.baseten.co/reference/sdk/loops/service-client) with the same path.

> [tab] Loops cookbook
>
> **To continue a cookbook run that stopped**:
>
> Run the same config with `--resume`:
>
> ```bash theme={"system"}
> uv run loops run sft.toml --resume
> ```
>
> `--resume` takes the latest run of that config and continues from the last manifest it wrote: the weights, the optimizer state, and the run's position. Steps continue from the manifest's next step. The run logs the run directory it took, `Resuming the latest run of sft.toml: <run_dir>`, and then `Resumed trainer state from <path> at policy version <n>`.
>
> To continue from a specific manifest instead, pass `--training.resume_from`:
>
> ```bash theme={"system"}
> uv run loops run sft.toml --training.resume_from "runs/<run_name>-<time>-<id>/checkpoints/step-<N>.json"
> ```
>
> **To start a new cookbook run from trained weights**:
>
> In the new run's TOML config, set `init_from` under `[training]` to a trainer checkpoint's path, such as [`bt://loops:<run_id>/weights/step-<N>`](https://docs.baseten.co/loops/concepts#checkpoints). To also restore the optimizer state, set `init_from_optimizer`:
>
> ```toml theme={"system"}
> [training]
> init_from = "bt://loops:<run_id>/weights/step-<N>"
> init_from_optimizer = true
> ```
>
> Then start the run as you would any other cookbook run:
>
> ```bash theme={"system"}
> uv run loops run sft.toml
> ```
>
> The run logs the weights it loaded, `Loaded the weights at <path>`, before its first update. The new run's steps start at 0, and you can change the data, the loss, or the learning rate. The checkpoint must have the same base model and LoRA rank as the new run's config.

Use the new run's ID to [list its checkpoints](https://docs.baseten.co/loops/save-checkpoints.md#list-checkpoints) or [deactivate it](https://docs.baseten.co/loops/deactivate-a-run.md).

## Next steps

* [Save a checkpoint](https://docs.baseten.co/loops/save-checkpoints.md): Save training state during the new run.
* [Load a checkpoint into a new job](https://docs.baseten.co/training/loading.md#from-a-loops-run): Continue from a Loops checkpoint with your own training code.
