fl4health.utils.snapshotter module

class AbstractSnapshotter(client)[source]

Bases: ABC, Generic[T]

__init__(client)[source]

Abstract class for saving and loading the state of the client’s attributes.

Parameters:

client (BasicClient) – The client to be monitored.

dict_wrap_attr(name, expected_type)[source]

Wrap the attribute in a dictionary if it is not already a dictionary.

Parameters:
  • name (str) – Name of the attribute.

  • expected_type (type[T]) – Expected type of the attribute.

Returns:

Wrapped attribute as a dictionary.

Return type:

dict[str, T]

load(snapshot, name, expected_type)[source]

Load the state of the attribute to the client.

Parameters:
  • snapshot (dict[str, Any]) – Snapshot containing the state of the attribute.

  • name (str) – Name of the attribute.

  • expected_type (type[T]) – Expected type of the attribute.

Return type:

None

abstract load_attribute(attribute_snapshot, attribute)[source]

Abstract method to load the state of the attribute. This method should be implemented based on the type of the attribute and the way it should be loaded.

Parameters:
  • attribute_snapshot (dict[str, Any]) – The snapshot containing the state of the attribute.

  • attribute (dict[str, T]) – The attribute to be loaded.

Return type:

None

save(name, expected_type)[source]

Save the state of the attribute.

Parameters:
  • name (str) – Name of the attribute.

  • expected_type (type[T]) – Expected type of the attribute.

Returns:

A dictionary containing the state of the attribute.

Return type:

dict[str, Any]

abstract save_attribute(attribute)[source]

Abstract method to save the state of the attribute. This method should be implemented based on the type of the attribute and the way it should be saved.

Parameters:

attribute (dict[str, T]) – The attribute to be saved.

Returns:

A dictionary containing the state of the attribute.

Return type:

dict[str, Any]

class LRSchedulerSnapshotter(client)[source]

Bases: AbstractSnapshotter[LRScheduler]

load_attribute(attribute_snapshot, attribute)[source]

Load the state of the learning rate schedulers.

Parameters:
  • attribute_snapshot (dict[str, Any]) – The snapshot containing the state of the learning rate schedulers.

  • attribute (dict[str, LRScheduler]) – The learning rate schedulers to be loaded.

Return type:

None

save_attribute(attribute)[source]

Save the state of the learning rate schedulers.

Parameters:

attribute (dict[str, LRScheduler]) – The learning rate schedulers to be saved.

Returns:

A dictionary containing the state of the learning rate schedulers.

Return type:

dict[str, Any]

class NumberSnapshotter(client)[source]

Bases: AbstractSnapshotter[int | float]

load_attribute(attribute_snapshot, attribute)[source]

Load the state of the numbers (either single or dictionary of them).

Parameters:
  • attribute_snapshot (dict[str, Any]) – The snapshot containing the state of the numbers.

  • attribute (dict[str, int | float]) – The numbers to be loaded

Return type:

None

save_attribute(attribute)[source]

Save the state of the numbers (either single or dictionary of them).

Parameters:

attribute (dict[str, int | float]) – The numbers to be saved.

Returns:

A dictionary containing the state of the numbers.

Return type:

dict[str, Any]

class OptimizerSnapshotter(client)[source]

Bases: AbstractSnapshotter[Optimizer]

load_attribute(attribute_snapshot, attribute)[source]

Load the state of the optimizers by loading “state” attribute of the optimizer

Parameters:
  • attribute_snapshot (dict[str, Any]) – The snapshot containing the state of the optimizers.

  • attribute (dict[str, Optimizer]) – The optimizers to be loaded.

Return type:

None

save_attribute(attribute)[source]

Save the state of the optimizers by saving “state” attribute of the optimizer.

Parameters:

attribute (dict[str, Optimizer]) – The optimizers to be saved.

Returns:

A dictionary containing the state of the optimizers.

Return type:

dict[str, Any]

class SerializableObjectSnapshotter(client)[source]

Bases: AbstractSnapshotter[MetricManager | LossMeter | ReportsManager]

load_attribute(attribute_snapshot, attribute)[source]

Load the state of the serializable objects (either single or dictionary of them).

Parameters:
Return type:

None

save_attribute(attribute)[source]

Save the state of the serializable objects (either single or dictionary of them).

Parameters:

attribute (dict[str, MetricManager | LossMeter | ReportsManager]) – The serializable objects to be saved.

Returns:

A dictionary containing the state of the serializable objects.

Return type:

dict[str, Any]

class TorchModuleSnapshotter(client)[source]

Bases: AbstractSnapshotter[Module]

load_attribute(attribute_snapshot, attribute)[source]

Load the state of the nn.Modules.

Parameters:
  • attribute_snapshot (dict[str, Any]) – The snapshot containing the state of the nn.Modules.

  • attribute (dict[str, nn.Module]) – The nn.Modules to be loaded

Return type:

None

save_attribute(attribute)[source]

Save the state of the nn.Modules.

Parameters:

attribute (dict[str, nn.Module]) – The nn.Modules to be saved.

Returns:

A dictionary containing the state of the nn.Modules.

Return type:

dict[str, Any]