Skip to content

fl_server_api.serializers.training

Classes:

Name Description
ClientAdministrationBody

A data class representing the body of a client administration request.

ClientAdministrationBodySchema

A schema for serializing and deserializing ClientAdministrationBody instances.

CreateTrainingRequest

A data class representing a request to create a training process.

CreateTrainingRequestSchema

A schema for serializing and deserializing CreateTrainingRequest instances.

Classes

ClientAdministrationBody dataclass

A data class representing the body of a client administration request.

Methods:

Name Description
__init__

Attributes:

Name Type Description
clients list[UUID]

A list of UUIDs representing the clients to be administered.

Source code in fl_server_api/serializers/training.py
@dataclass
class ClientAdministrationBody:
    """
    A data class representing the body of a client administration request.
    """

    clients: List[UUID]
    """A list of UUIDs representing the clients to be administered."""

Attributes

clients instance-attribute
clients: list[UUID]

A list of UUIDs representing the clients to be administered.

Functions

__init__
__init__(clients: list[UUID]) -> None

ClientAdministrationBodySchema

Bases: Schema


              flowchart TD
              fl_server_api.serializers.training.ClientAdministrationBodySchema[ClientAdministrationBodySchema]

              

              click fl_server_api.serializers.training.ClientAdministrationBodySchema href "" "fl_server_api.serializers.training.ClientAdministrationBodySchema"
            

A schema for serializing and deserializing ClientAdministrationBody instances.

Attributes:

Name Type Description
clients

A list of UUIDs representing the clients to be administered.

Source code in fl_server_api/serializers/training.py
class ClientAdministrationBodySchema(Schema):
    """
    A schema for serializing and deserializing `ClientAdministrationBody` instances.
    """

    clients = fields.List(fields.UUID, required=True)
    """A list of UUIDs representing the clients to be administered."""

    @post_load
    def _make_client_administration_body(self, data: Dict[str, Any], **kwargs):
        """
        Create a `ClientAdministrationBody` instance from the loaded data.

        This method is called after the data has been loaded and validated.

        Args:
            data (Dict[str, Any]): The loaded data.
            **kwargs: Additional keyword arguments.

        Returns:
            ClientAdministrationBody: The created `ClientAdministrationBody` instance.
        """
        return ClientAdministrationBody(**data)

Attributes

clients class-attribute instance-attribute
clients = List(UUID, required=True)

A list of UUIDs representing the clients to be administered.

CreateTrainingRequest dataclass

A data class representing a request to create a training process.

Attributes:

Name Type Description
model_id UUID

The ID of the model to be trained.

target_num_updates int

The target number of updates for the training process.

metric_names list[str]

The names of the metrics to be used in the training process.

aggregation_method AggregationMethod

The method to be used for aggregating updates. Defaults to FED_AVG.

uncertainty_method UncertaintyMethod

The method to be used for handling uncertainty. Defaults to NONE.

options dict[str, Any]

Additional options for the training process. Defaults to an empty dictionary.

clients list[UUID]

The clients participating in the training process. Defaults to an empty list.

Methods:

Name Description
__init__
Source code in fl_server_api/serializers/training.py
@dataclass
class CreateTrainingRequest:
    """
    A data class representing a request to create a training process.

    Attributes:
        model_id (UUID): The ID of the model to be trained.
        target_num_updates (int): The target number of updates for the training process.
        metric_names (list[str]): The names of the metrics to be used in the training process.
        aggregation_method (AggregationMethod): The method to be used for aggregating updates. Defaults to FED_AVG.
        uncertainty_method (UncertaintyMethod): The method to be used for handling uncertainty. Defaults to NONE.
        options (Dict[str, Any]): Additional options for the training process. Defaults to an empty dictionary.
        clients (List[UUID]): The clients participating in the training process. Defaults to an empty list.
    """
    model_id: UUID
    """ID of the model to be trained."""
    target_num_updates: int
    """Target number of updates for the training process."""
    metric_names: list[str]
    """Names of the metrics to be used in the training process."""
    aggregation_method: AggregationMethod = field(default=AggregationMethod.FED_AVG)  # type: ignore[assignment]
    """Method to be used for aggregating updates. Defaults to `FED_AVG`."""
    uncertainty_method: UncertaintyMethod = field(default=UncertaintyMethod.NONE)  # type: ignore[assignment]
    """Method to be used for handling uncertainty. Defaults to `NONE`."""
    options: Dict[str, Any] = field(default_factory=lambda: {})
    """Additional options for the training process. Defaults to an empty dictionary."""
    clients: List[UUID] = field(default_factory=lambda: [])
    """Clients participating in the training process. Defaults to an empty list."""

Attributes

aggregation_method class-attribute instance-attribute
aggregation_method: AggregationMethod = field(default=FED_AVG)

Method to be used for aggregating updates. Defaults to FED_AVG.

clients class-attribute instance-attribute
clients: list[UUID] = field(default_factory=lambda: [])

Clients participating in the training process. Defaults to an empty list.

metric_names instance-attribute
metric_names: list[str]

Names of the metrics to be used in the training process.

model_id instance-attribute
model_id: UUID

ID of the model to be trained.

options class-attribute instance-attribute
options: dict[str, Any] = field(default_factory=lambda: {})

Additional options for the training process. Defaults to an empty dictionary.

target_num_updates instance-attribute
target_num_updates: int

Target number of updates for the training process.

uncertainty_method class-attribute instance-attribute
uncertainty_method: UncertaintyMethod = field(default=NONE)

Method to be used for handling uncertainty. Defaults to NONE.

Functions

__init__
__init__(model_id: UUID, target_num_updates: int, metric_names: list[str], aggregation_method: AggregationMethod = FED_AVG, uncertainty_method: UncertaintyMethod = NONE, options: dict[str, Any] = (lambda: {})(), clients: list[UUID] = (lambda: [])()) -> None

CreateTrainingRequestSchema

Bases: Schema


              flowchart TD
              fl_server_api.serializers.training.CreateTrainingRequestSchema[CreateTrainingRequestSchema]

              

              click fl_server_api.serializers.training.CreateTrainingRequestSchema href "" "fl_server_api.serializers.training.CreateTrainingRequestSchema"
            

A schema for serializing and deserializing CreateTrainingRequest instances.

Attributes:

Name Type Description
aggregation_method

Method to be used for aggregating updates. Defaults to FED_AVG.

clients

Clients participating in the training process. Defaults to an empty list.

metric_names

Names of the metrics to be used in the training process.

model_id

ID of the model to be trained.

options

Additional options for the training process. Defaults to an empty dictionary.

target_num_updates

Target number of updates for the training process.

uncertainty_method

Method to be used for handling uncertainty. Defaults to NONE.

Source code in fl_server_api/serializers/training.py
class CreateTrainingRequestSchema(Schema):
    """
    A schema for serializing and deserializing `CreateTrainingRequest` instances.
    """

    model_id = fields.UUID()
    """ID of the model to be trained."""
    target_num_updates = fields.Integer()
    """Target number of updates for the training process."""
    metric_names = fields.List(fields.Str())
    """Names of the metrics to be used in the training process."""
    aggregation_method = fields.Enum(
        AggregationMethod,
        required=True,
        dump_default=AggregationMethod.FED_AVG,
        by_value=True
    )
    """Method to be used for aggregating updates. Defaults to `FED_AVG`."""
    uncertainty_method = fields.Enum(
        UncertaintyMethod,
        required=False,
        dump_default=UncertaintyMethod.NONE,
        by_value=True
    )
    """Method to be used for handling uncertainty. Defaults to `NONE`."""
    options = fields.Dict(required=False, dump_default={})
    """Additional options for the training process. Defaults to an empty dictionary."""
    clients = fields.List(fields.UUID(), dump_default=[])
    """Clients participating in the training process. Defaults to an empty list."""

    @post_load
    def _make_create_training_request(self, data: Dict[str, Any], **kwargs):
        """
        Create a `CreateTrainingRequest` instance from the loaded data.

        This method is called after the data has been loaded and validated.

        Args:
            data (Dict[str, Any]): The loaded data.
            **kwargs: Additional keyword arguments.

        Returns:
            CreateTrainingRequest: The created `CreateTrainingRequest` instance.
        """
        return CreateTrainingRequest(**data)

Attributes

aggregation_method class-attribute instance-attribute
aggregation_method = Enum(AggregationMethod, required=True, dump_default=FED_AVG, by_value=True)

Method to be used for aggregating updates. Defaults to FED_AVG.

clients class-attribute instance-attribute
clients = List(UUID(), dump_default=[])

Clients participating in the training process. Defaults to an empty list.

metric_names class-attribute instance-attribute
metric_names = List(Str())

Names of the metrics to be used in the training process.

model_id class-attribute instance-attribute
model_id = UUID()

ID of the model to be trained.

options class-attribute instance-attribute
options = Dict(required=False, dump_default={})

Additional options for the training process. Defaults to an empty dictionary.

target_num_updates class-attribute instance-attribute
target_num_updates = Integer()

Target number of updates for the training process.

uncertainty_method class-attribute instance-attribute
uncertainty_method = Enum(UncertaintyMethod, required=False, dump_default=NONE, by_value=True)

Method to be used for handling uncertainty. Defaults to NONE.