# Run your training code

Start a training run from the Console under **Training**, or from the CLI or SDK.

```sh
nestor training runs create . --command 'python train.py --epochs 3' --wait
```

```python
from nestor import Nestor

client = Nestor()
run = client.training.run(".", command=["python", "train.py", "--epochs", "3"], wait=True)
print(run.id, run.state, run.failure_reason)
```

`--wait` returns when the run reaches a final state. Without it, the command
returns as soon as the run is accepted. Stopping the CLI never stops the run.

## What a run is made of

| Part | CLI | SDK | Notes |
| --- | --- | --- | --- |
| Source | path (default `.`) | `source` | A directory, or one `.py` file with its directory. |
| Command | `--command 'python train.py'` | `command=[…]` | Runs directly, without a shell. Use `bash -lc '…'` for pipes and `&&`. A `.py` source defaults to `python FILE`. |
| GPUs | `--accelerator FAMILY`, `--gpus N`, `--region R` | `accelerator=`, `gpus=`, `region=` | Default: Auto and one GPU. |
| Environment | `--image IMAGE@sha256:…` | `image=` | Default: managed Python 3.12. |
| Secrets | `--secret HF_TOKEN=sec_…` | `secrets={…}` | [Secrets](/inference/keys) as environment variables. |
| Inputs | `--input /data/train=nestor://data/dat_…` | `inputs=[{"path": …, "uri": …}]` | [Data](/data) items or earlier run files, read-only under `/data/`. |
| Limits | `--timeout-seconds`, `--grace-seconds` | `timeout_seconds=`, `termination_grace_seconds=` | Default 86400 s (24 hours) and 30 s. |
| Application | `--application app_…` | `application=` | Records which [Application](/applications) the run is for. |
| Retry safety | `--idempotency-key KEY` | `idempotency_key=` | The same key and request returns the same run. |

## Source and environment

Nestor packages your source as an immutable snapshot: up to 16 MiB compressed,
64 MiB unpacked and 10,000 files. These are always left out:

- `.git`, `.venv`, `venv`, `node_modules`, `__pycache__`, `.cache`, `.next`,
  `.local`, `.aws` and `.ssh` directories, and tool caches such as
  `.pytest_cache`;
- `.env` and `.env.*` files;
- files ending in `.pem`, `.key` or `.pyc`.

When the directory you upload is the top of a Git repository, its Git ignore
rules also apply. Patterns in a `.nestorignore` file at the top of the upload
exclude more.

**Everything else in the directory is uploaded**, including credentials with
other names, such as an SSH key called `id_ed25519` or a `credentials.json`.
Move secret files out of the directory or list them in `.nestorignore` before
you submit, and give the run credentials through [Secrets](/inference/keys)
instead.

The managed Python 3.12 environment installs dependencies from `uv.lock` with
`pyproject.toml`, then `pyproject.toml`, then `requirements.txt`. With
`--image`, your source runs inside your own digest-pinned public image instead.
A run whose dependencies fail to install ends `FAILED` with
`ENVIRONMENT_BUILD_FAILED`; the platform logs show why.

## GPUs and capacity

**Auto** selects any qualified GPU available within your allowance. Name a
family with `--accelerator` when your program needs it. Nestor operates a small
qualified fleet: when no qualified GPU is free, the request is refused with
503 `UNAVAILABLE` with `details.reason` `CAPACITY_UNAVAILABLE`. Retry later with the same idempotency key, or free
capacity by deleting an Endpoint you no longer need. Distributed multi-node
training is not available.

## Logs

```sh
nestor training runs logs tr_… --follow
nestor training runs logs tr_… --platform --timestamps   # include environment setup
nestor training runs events tr_…                         # state and stage history
```

```python
for record in client.training.runs.logs(run, follow=True):
    print(record.message, end="")
```

Logs are durable and capped at 32 MiB per run. Values of Secrets attached to the
run are removed before logs are stored.

## Failure reasons

| Reason | Meaning |
| --- | --- |
| `CUSTOMER_PROCESS_EXIT` | Your program exited non-zero; the exit code is recorded. |
| `ENVIRONMENT_BUILD_FAILED` | Dependencies could not be installed. |
| `TIME_LIMIT_EXCEEDED` | The run passed `--timeout-seconds`. |
| `INPUT_MATERIALIZATION_FAILED` | An input could not be delivered. |
| `SECRET_UNAVAILABLE` | A referenced Secret is missing or deleted. |
| `OUTPUT_PERSISTENCE_FAILED`, `CHECKPOINT_PERSISTENCE_FAILED` | Files could not be saved. |
| `CAPACITY_UNAVAILABLE` | No qualified GPU became available for the run. Submit it again later. |
| `INFRASTRUCTURE_FAILURE` | A platform problem; send the run ID to support. |

Nothing is restarted automatically. The CLI exits 0 for `SUCCEEDED`, 9 for any
other final state and 10 if its own `--timeout` passed first.

## Cancel, rerun and delete

```sh
nestor training runs cancel tr_…    # your program gets SIGTERM, then the grace period
nestor training runs rerun tr_…     # a new run with the same source, command and inputs
nestor training runs delete tr_…    # finished runs only
```

A rerun starts from scratch; to continue training, [resume from a
checkpoint](/training/checkpoints). Outputs published as Data stay available
after you delete the run.
