# legacy

Python API: `luxonis_train.strategies.legacy`

The adapter for a strategy of the previous `configure_optimizers` API.

## Classes

### LegacyStrategyAdapter

An adapter for a strategy of the deprecated `configure_optimizers` API.

[luxonis_train.lightning.utils.build_training_strategy](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/lightning/utils.md)
logs a deprecation warning and wraps such a strategy in this adapter. The optimizers and schedulers that `configure_optimizers` of
the legacy strategy returns become extra inner optimizers of the plan.

The parameters of these optimizers stay out of the rule partition. The node `finetuning` entries and the default rule claim every
parameter that the legacy optimizers leave out, frozen parameters included. Such a parameter therefore trains after its node
unfreezes.

#### Methods

##### init

```python
def __init__(legacy: Any):
```

Wrap a legacy strategy.

The constructor does not call `configure_optimizers`. The first call of
[opaque_parameter_ids](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/strategies/legacy.md)
or
[opaque_inners](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/strategies/legacy.md)
calls it once, and the adapter keeps the result.

Parameters

 * `legacy` (`Any`): The legacy strategy. It must have the methods `configure_optimizers` and `update_parameters`, and can have
   `get_base_configs`. `configure_optimizers` returns a sequence of optimizers and a sequence of schedulers.

##### get_base_configs

```python
def get_base_configs(self) -> tuple[OptimizerConfig, SchedulerConfig]:
```

Return the base configs of the legacy strategy.

[luxonis_train.lightning.utils.build_training_strategy](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/lightning/utils.md)
gives a legacy class without `get_base_configs` a stub that raises `NotImplementedError`. When this method raises that error,
[resolve_training_plan](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/lightning/training_plan.md)
uses `trainer.optimizer` and `trainer.scheduler`.

Returns

 * `tuple[OptimizerConfig, SchedulerConfig]`: The result of `get_base_configs()` of the legacy strategy.

Raises

 * `NotImplementedError`: If the legacy strategy has no `get_base_configs` attribute.

##### opaque_inners

```python
def opaque_inners(self) -> list[tuple[Optimizer, Any]]:
```

Return the optimizers of the legacy strategy with their schedulers.

Returns

 * `list[tuple[Optimizer, Any]]`: One pair for each optimizer, in order. The scheduler at the same position completes the pair.
   When the legacy strategy returns fewer schedulers than optimizers, the last optimizers get `None`.

Raises

 * `ValueError`: If the legacy strategy returns more schedulers than optimizers.

##### opaque_parameter_ids

```python
def opaque_parameter_ids(self) -> set[int]:
```

Return the parameters of the optimizers of the legacy strategy.

Returns

 * `set[int]`: The `id()` of each parameter in the `param_groups` of each legacy optimizer.

##### rules

```python
def rules(self) -> list[StrategyRule]:
```

Return no rules, because the legacy strategy has none.

Returns

 * `list[StrategyRule]`: An empty list.

##### update_parameters

```python
def update_parameters(self):
```

Call `update_parameters()` of the legacy strategy.

#### Attributes

##### legacy_name

The class name of the legacy strategy.

[resolve_training_plan](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/lightning/training_plan.md)
names the strategy with it when the legacy optimizers hold a parameter that a `finetuning` entry claims.

## Attributes

### DEPRECATION_MESSAGE
