# Checkpoints and outputs

Your program writes files to two directories. Nestor saves them, records their
size and SHA-256 digest, and makes them available to download or to use in a
later run.

| Directory | Environment variable | Saved |
| --- | --- | --- |
| `/nestor/checkpoints` | `NESTOR_CHECKPOINTS` | While the run is active, as each file is completed. |
| `/nestor/outputs` | `NESTOR_OUTPUTS` | When the program stops, including after failure or cancellation. |

Use the environment variables rather than hard-coded paths, and write each file
under a temporary name and rename it when complete. Hidden files and names
ending in `.tmp` or `.partial` are skipped, so a half-written file is never
saved. Anything written elsewhere is discarded with the GPU.

```python
import os
from pathlib import Path

checkpoints = Path(os.environ["NESTOR_CHECKPOINTS"])
tmp = checkpoints / "step-1000.pt.tmp"
torch.save(state, tmp)
tmp.replace(checkpoints / "step-1000.pt")
```

## List and download

```sh
nestor training runs checkpoints tr_…       # saved versions, also while running
nestor training runs outputs tr_…
nestor training runs download tr_… tf_… ./adapter_model.safetensors
```

```python
for f in client.training.runs.outputs(run):
    client.training.runs.download(run, f, f"./results/{f.path}")
```

Downloads verify size and digest before replacing the destination. On a
mismatch the destination is left untouched and an error is raised.

Saved outputs and checkpoints are published as [Data](/data): they keep a
`nestor://` reference, count toward your Data storage, and remain available
after the run is deleted. Limits: 64 GiB per file, 256 files each time a
directory is saved and 4,096 files per run.

## Resume from a checkpoint

A rerun never resumes. To continue training, start a new run that mounts the
checkpoint as an input and tell your program where it is:

```sh
nestor training runs create . \
  --command 'python train.py --resume /data/state.pt' \
  --input /data/state.pt=nestor://training-runs/tr_old/files/tf_…
```

Use the exact reference that `checkpoints` returns. Whether a checkpoint is
compatible with the new run is up to your program.

## Use a result

To serve a fine-tuned model, package the weights with your serving code in a
[container Endpoint](/inference/containers) and mount them from Data. Nestor
does not deploy a training result automatically.
