# train_utils

Python API: `luxonis_train.core.utils.train_utils`

The construction of the Lightning trainer from the config.

## Functions

| Name | Description |
| --- | --- |
| [`create_trainer`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/core/utils/train_utils.md#train_utils-Functions-create_trainer) | Create a Lightning trainer from the `trainer` config section. |

### function `create_trainer`

```python
def create_trainer(cfg: TrainerConfig, **kwargs: Any) -> pl.Trainer
```

Create a Lightning trainer from the `trainer` config section.

The function passes these fields of `cfg` to the trainer:

 * `accelerator`, `devices`, `strategy`, `profiler`, `deterministic`, `gradient_clip_val`, `gradient_clip_algorithm`, and
   `overfit_batches` under the same names;
 * `epochs` as `max_epochs`;
 * `validation_interval` as `check_val_every_n_epoch`;
 * `n_sanity_val_steps` as `num_sanity_val_steps`.

The other fields, such as `precision`, do not reach the trainer through this function. The main trainer of
[LuxonisModel](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/core/core.md#core-Classes-LuxonisModel)
gets `precision` through `kwargs`.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `cfg` | `TrainerConfig` | The `trainer` section of the config. | required |
| `**kwargs` | `Any` | More keyword arguments for the trainer, such as `logger`, `callbacks`, or `precision`. A key that the function already sets from `cfg` raises `TypeError`. |  |

Returns

| Type | Description |
| --- | --- |
| `pl.Trainer` | The trainer. |
