helios.plugins.plugin

Attributes

PLUGIN_REGISTRY

Global instance of the registry for plug-ins.

Classes

UniquePluginOverrides

Set of flags that determine the unique overrides a plug-in can have.

Plugin

Base class for plug-ins that extend the functionality of the Helios trainer.

Functions

create_plugin(→ Plugin)

Create the plug-in for the given type.

Module Contents

class helios.plugins.plugin.UniquePluginOverrides[source]

Set of flags that determine the unique overrides a plug-in can have.

In order to avoid conflicts, two plug-ins should not be able to perform the same action twice. For example, it shouldn’t be possible to have two distinct plug-ins perform processing on the training batch as that would cause undefined behaviour. This structure therefore holds all the possible overrides a plug-in might have that must remain unique.

Parameters:
  • training_batch – if true, the plug-in performs processing on the training batch.

  • validation_batch – if true, the plug-in performs processing on the validation batch.

  • testing_batch – if true, the plug-in performs processing on the testing batch.

  • should_training_stop – if true, the plug-in can arbitrarily stop training.

training_batch: bool = False
validation_batch: bool = False
testing_batch: bool = False
should_training_stop: bool = False
helios.plugins.plugin.PLUGIN_REGISTRY

Global instance of the registry for plug-ins.

By default, the registry contains the following plug-ins:

Plug-ins

Plugin

Name

helios.plugins.optuna.OptunaPlugin

OptunaPlugin

Note

The OptunaPlugin is only registered if the module is imported somewhere in the code. Otherwise it won’t be registered.

Example

import helios.plug-ins as hlp

# This automatically registers your plug-in
@hlp.PLUGIN_REGISTRY
class MyPlugin(hlp.Plugin):
    ...

# Alternatively, you can manually register a plug-in like this:
hlp.PLUGIN_REGISTRY.register(MyPlugin)
helios.plugins.plugin.create_plugin(type_name: str, *args: Any, **kwargs: Any) Plugin[source]

Create the plug-in for the given type.

Parameters:
  • type_name – the type of the plug-in to create.

  • args – positional arguments to pass into the plug-in.

  • kwargs – keyword arguments to pass into the plug-in.

Returns:

The plug-in.

class helios.plugins.plugin.Plugin(plug_id: str)[source]

Bases: abc.ABC

Base class for plug-ins that extend the functionality of the Helios trainer.

You can use this class to customize the behaviour of training to achieve a variety of objectives. The plug-ins have a similar API to the Model class. The only major difference is that the plug-in functions are called before the corresponding model functions, providing the ability to override the model if necessary.

Parameters:

plug_id – the string with which the plug-in will be registered in the trainer plug-in table.

property unique_overrides: UniquePluginOverrides

The set of unique overrides the plug-in uses.

property is_distributed: bool

Flag controlling whether distributed training is being used or not.

property map_loc: str | dict[str, str]

The location to map loaded weights from a checkpoint or pre-trained file.

property device: torch.device

The device on which the plug-in is running.

property rank: int

The local rank (device id) that the plug-in is running on.

property trainer: helios.trainer.Trainer

Reference to the trainer.

configure_trainer(trainer: helios.trainer.Trainer) None[source]

Configure the trainer before training or testing.

This function can be used to set certain properties of the trainer. For example, it can be used to assign valid exceptions that the plug-in requires.

Parameters:

trainer – the trainer instance.

configure_model(model: helios.model.Model) None[source]

Configure the model before training or testing.

This function can be used to set certain properties of the model. For example, it can be used to override the save name of the model.

abstractmethod setup() None[source]

Construct all required state for the plug-in.

on_training_start() None[source]

Perform any necessary actions when training starts.

process_training_batch(batch: Any, state: helios.trainer.TrainingState) Any[source]

Process the training batch.

This function can be used to perform any processing on the training batch prior to the call to train_step(). For example, this can be used to filter out elements in a batch to reduce its size, or it can be used to move all elements in the batch to a set device.

Parameters:
  • batch – the batch data returned from the dataset.

  • state – the current training state.

on_training_end() None[source]

Perform any necessary actions when training ends.

on_validation_start(validation_cycle: int) None[source]

Perform any necessary actions when validation starts.

Parameters:

validation_cycle – the validation cycle number.

process_validation_batch(batch: Any, step: int) Any[source]

Process the validation batch.

This function can be used to perform any processing on the validation batch prior to the call to valid_step(). For example, this can be used to filter out elements in a batch to reduce its size, or it can be used to move all elements in the batch to a set device.

Parameters:
  • batch – the batch data returned from the dataset.

  • step – the current validation batch.

on_validation_end(validation_cycle: int) None[source]

Perform any necessary actions when validation ends.

Parameters:

validation_cycle – the validation cycle number

should_training_stop() bool[source]

Determine whether training should stop or continue.

Returns:

False if training should continue, true otherwise.

load_state_dict(state_dict: dict[str, Any]) None[source]

Load the plug-in state from the given state dictionary.

Use this function to restore any state from a checkpoint.

Parameters:

state_dict – the state dictionary to load from.

state_dict() dict[str, Any][source]

Get the state dictionary of the plug-in.

Use this function to save any state that you require for checkpoints.

Returns:

The state dictionary of the plug-in.

on_testing_start() None[source]

Perform any actions when testing starts.

process_testing_batch(batch: Any, step: int) Any[source]

Process the testing batch.

This function can be used to perform any processing on the testing batch prior to the call to test_step(). For example, this can be used to filter out elements in a batch to reduce its size, or it can be used to move all elements in the batch to a set device.

Parameters:
  • batch – the batch data returned from the dataset.

  • step – the current testing batch number.

on_testing_end() None[source]

Perform any necessary actions when testing ends.