# legacy

Python API: `luxonis_train.strategies.legacy`

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

## Classes

| Name | Description |
| --- | --- |
| [`LegacyStrategyAdapter`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/strategies/legacy.md#legacy-Classes-LegacyStrategyAdapter) | An adapter for a strategy of the deprecated `configure_optimizers` API. |

### class `LegacyStrategyAdapter`

```python
class LegacyStrategyAdapter(BaseTrainingStrategy)
```

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#utils-Functions-build_training_strategy)
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.

Properties

| Name | Type | Description |
| --- | --- | --- |
| [`legacy_name`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/strategies/legacy.md#legacy-Classes-LegacyStrategyAdapter-legacy_name) | `str` | The class name of the legacy strategy. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/strategies/legacy.md#legacy-Classes-LegacyStrategyAdapter-__init__) | Wrap a legacy strategy. |
| [`get_base_configs`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/strategies/legacy.md#legacy-Classes-LegacyStrategyAdapter-get_base_configs) | Return the base configs of the legacy strategy. |
| [`opaque_inners`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/strategies/legacy.md#legacy-Classes-LegacyStrategyAdapter-opaque_inners) | Return the optimizers of the legacy strategy with their schedulers. |
| [`opaque_parameter_ids`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/strategies/legacy.md#legacy-Classes-LegacyStrategyAdapter-opaque_parameter_ids) | Return the parameters of the optimizers of the legacy strategy. |
| [`rules`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/strategies/legacy.md#legacy-Classes-LegacyStrategyAdapter-rules) | Return no rules, because the legacy strategy has none. |
| [`update_parameters`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/strategies/legacy.md#legacy-Classes-LegacyStrategyAdapter-update_parameters) | Call `update_parameters()` of the legacy strategy. |

#### property `legacy_name`

```python
legacy_name: str
```

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#training_plan-Functions-resolve_training_plan)
names the strategy with it when the legacy optimizers hold a parameter that a `finetuning` entry claims.

#### method `__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#legacy-Classes-LegacyStrategyAdapter-opaque_parameter_ids)
or
[opaque_inners](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/strategies/legacy.md#legacy-Classes-LegacyStrategyAdapter-opaque_inners)
calls it once, and the adapter keeps the result.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `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. | required |

#### method `get_base_configs`

```python
def get_base_configs() -> 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#utils-Functions-build_training_strategy)
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#training_plan-Functions-resolve_training_plan)
uses `trainer.optimizer` and `trainer.scheduler`.

Returns

| Type | Description |
| --- | --- |
| `tuple[OptimizerConfig, SchedulerConfig]` | The result of `get_base_configs()` of the legacy strategy. |

Raises

| Type | Description |
| --- | --- |
| `NotImplementedError` | If the legacy strategy has no `get_base_configs` attribute. |

#### method `opaque_inners`

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

Return the optimizers of the legacy strategy with their schedulers.

Returns

| Type | Description |
| --- | --- |
| `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

| Type | Description |
| --- | --- |
| `ValueError` | If the legacy strategy returns more schedulers than optimizers. |

#### method `opaque_parameter_ids`

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

Return the parameters of the optimizers of the legacy strategy.

Returns

| Type | Description |
| --- | --- |
| `set[int]` | The `id()` of each parameter in the `param_groups` of each legacy optimizer. |

#### method `rules`

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

Return no rules, because the legacy strategy has none.

Returns

| Type | Description |
| --- | --- |
| `list[StrategyRule]` | An empty list. |

#### method `update_parameters`

```python
def update_parameters()
```

Call `update_parameters()` of the legacy strategy.

## Module Attributes

| Name | Type | Description |
| --- | --- | --- |
| [`DEPRECATION_MESSAGE`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-train/luxonis-train-api-reference/strategies/legacy.md#legacy-Module-Attributes-DEPRECATION_MESSAGE) | `str` |  |

### constant `DEPRECATION_MESSAGE`

```python
DEPRECATION_MESSAGE: str = "Training strategy '{
    name,
}' implements the deprecated strategy API (`configure_optimizers`/`update_parameters`). It has been mounted in compatibility mode and will keep working until the next minor release. Port it to the new API: implement `rules()` returning parameter-group rules and (optionally) `update_parameters()` using the group handles passed to `attach()`."
```
