# ml-training

> A small PyTorch model trained on CPU to predict delivery minutes, and its recording.

A PyTorch model, trained on CPU, that predicts the minutes a delivery takes from four features: distance, number of parcels, hour of the day and a weekend flag. The data is made by the script, the same every time. Each batch of 8 rows is standardized, the model takes one Adam step per batch, and a batch whose loss is not a finite number is left out. The weights are saved to `model.pt`. The loss can differ in the last digits from one build of torch to another.

- Source: [`ormaos-examples/use-cases/ml-training`](https://github.com/ormaos/ormaos-examples/tree/6e27be59220856263a6a5905400d8630dafe73dd/use-cases/ml-training)
- Guide: [ML training](/python/guides/ml-training.md)

## Run it

```bash
python train.py
```

```console
$ python train.py
trained 40 steps, last loss 379.2, checkpoint model.pt
```

## Recorded

```bash
ormaos run -- python train.py
```

```console
$ ormaos run -- python train.py
trained 40 steps, last loss 379.2, checkpoint model.pt
ormaos: r1 exit 0 in …: 1 Python process, 203 calls, 0 exceptions, 10 io
ormaos: not collected: logs with no line of user code: 5 logging records were asked for with no frame of user code waiting (library threads, the end of the interpreter): they are counted here and not recorded; the first loggers: torch._dynamo.eval_frame, torch._dynamo.utils, torch._subclasses.fake_tensor
ormaos: saved in .ormaos/r1, next: ormaos tree r1:c1
```

```console
$ ormaos show
r1 exit 0 in …: 1 Python process, 203 calls, 0 exceptions (0 swallowed, 0 uncaught)
command: python train.py
code: git commit not read (the working directory is not inside a git repository)
io: 10 events (file 10)
tensors: an array or a tensor was an argument or a result 400 times, 10 with NaN or inf: return of standardize at train.py:32  [r1:c56]
not collected: logs with no line of user code: 5 logging records were asked for with no frame of user code waiting (library threads, the end of the interpreter): they are counted here and not recorded; the first loggers: torch._dynamo.eval_frame, torch._dynamo.utils, torch._subclasses.fake_tensor
never recorded: values, and 20 more kinds of things (`ormaos show --full` lists them with the reason)
next: ormaos tree r1:c1 | ormaos io r1 | ormaos tree r1:c56
```

---

Source: https://docs.ormaos.com/examples/ml-training/ · ormaos 0.0.1 · ormaos-python 968f69776c · ormaos-examples 6e27be5922
