fl4health.utils.snapshotter module

class AbstractSnapshotter[source]

Bases: ABC, Generic[T]

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

abstract save_attribute(attribute)[source]

Abstract method used 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 BytesSnapshotter[source]

Bases: AbstractSnapshotter[bytes]

load_attribute(attribute_snapshot, attribute)[source]

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

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

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

Return type:

None

save_attribute(attribute)[source]

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

Parameters:

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

Returns:

A dictionary containing the state of the bytes.

Return type:

dict[str, Any]

class EnumSnapshotter[source]

Bases: AbstractSnapshotter[Enum]

load_attribute(attribute_snapshot, attribute)[source]

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

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

  • attribute (dict[str, Enum]) – The enum to be loaded

Return type:

None

save_attribute(attribute)[source]

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

Parameters:

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

Returns:

A dictionary containing the state of the enum.

Return type:

dict[str, Any]

class HistorySnapshotter[source]

Bases: AbstractSnapshotter[History]

load_attribute(attribute_snapshot, attribute)[source]

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

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

  • attribute (dict[str, History]) – The history to be loaded

Return type:

None

save_attribute(attribute)[source]

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

Parameters:

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

Returns:

A dictionary containing the state of the history.

Return type:

dict[str, Any]

class LRSchedulerSnapshotter[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 OptimizerSnapshotter[source]

Bases: AbstractSnapshotter[Optimizer]

load_attribute(attribute_snapshot, attribute)[source]

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

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 optimizers.

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[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 SingletonSnapshotter[source]

Bases: AbstractSnapshotter[int | float | bool]

load_attribute(attribute_snapshot, attribute)[source]

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

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

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

Return type:

None

save_attribute(attribute)[source]

Save the state of a singleton which could be a number or a boolean (either single or dictionary of them).

Parameters:

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

Returns:

A dictionary containing the state of the singletons.

Return type:

dict[str, Any]

class StringSnapshotter[source]

Bases: AbstractSnapshotter[str]

load_attribute(attribute_snapshot, attribute)[source]

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

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

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

Return type:

None

save_attribute(attribute)[source]

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

Parameters:

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

Returns:

A dictionary containing the state of the strings.

Return type:

dict[str, Any]

class TorchModuleSnapshotter[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]