fedn.network.combiner package
The FEDn Combiner package is responsible for combining models from multiple clients. It’s the acting gRPC server for the federated network.
Subpackages
Submodules
fedn.network.combiner.connect module
- class fedn.network.combiner.connect.ConnectorCombiner(host, port, myhost, fqdn, myport, token, name, secure=False, verify=False)[source]
Bases:
object
Connector for annnouncing combiner to the FEDn network.
- Parameters:
host (str) – host of discovery service
port (int) – port of discovery service
myhost (str) – host of combiner
fqdn (str) – fully qualified domain name of combiner
myport (int) – port of combiner
token (str) – token for authentication
name (str) – name of combiner
secure (bool) – True if https is used, False if http
verify (bool) – True if certificate is verified, False if not
fedn.network.combiner.interfaces module
- class fedn.network.combiner.interfaces.Channel(address, port, certificate=None)[source]
Bases:
object
Wrapper for a gRPC channel.
- Parameters:
- class fedn.network.combiner.interfaces.CombinerInterface(parent, name, address, fqdn, port, certificate=None, key=None, ip=None, config=None)[source]
Bases:
object
- Interface for the Combiner (aggregation server).
Abstraction on top of the gRPC server servicer.
- Parameters:
parent (
fedn.network.api.interfaces.API
) – The parent combiner (controller)name (str) – The name of the combiner.
address (str) – The address of the combiner.
fqdn (str) – The fully qualified domain name of the combiner.
port (int) – The port of the combiner.
certificate (str) – The certificate of the combiner (optional).
key (str) – The key of the combiner (optional).
ip (str) – The ip of the combiner (optional).
config (dict) – The configuration of the combiner (optional).
- allowing_clients()[source]
Check if the combiner is allowing additional client connections.
- Returns:
True if accepting, else False.
- Return type:
- classmethod from_json()[source]
Initialize the combiner config from a json document.
- Parameters:
combiner_config (dict) – The combiner configuration.
- Returns:
An instance of the combiner interface.
- Return type:
- get_certificate()[source]
Get combiner certificate.
- Returns:
The combiner certificate.
- Return type:
str, None if no certificate is set.
- get_key()[source]
Get combiner key.
- Returns:
The combiner key.
- Return type:
str, None if no key is set.
- get_model(id)[source]
Download a model from the combiner server.
- Parameters:
id (str) – The model id.
- Returns:
A file-like object containing the model.
- Return type:
io.BytesIO
, None if the model is not available.
- list_active_clients(queue=1)[source]
List active clients.
- Parameters:
queue – The channel (queue) to use (optional). Default is 1 = MODEL_UPDATE_REQUESTS channel. see
fedn.network.grpc.fedn_pb2.Channel
- Returns:
A list of active clients.
- Return type:
json
- submit(config)[source]
Submit a compute plan to the combiner.
- Parameters:
config (dict) – The job configuration.
- Returns:
Server ControlResponse object.
- Return type:
fedn.network.grpc.fedn_pb2.ControlResponse
Bases:
Exception
fedn.network.combiner.modelservice module
- class fedn.network.combiner.modelservice.ModelService[source]
Bases:
ModelServiceServicer
Service for handling download and upload of models to the server.
- Download(request, context)[source]
RPC endpoints for downloading a model.
- Parameters:
request (
fedn.network.grpc.fedn_pb2.ModelRequest
) – The model request object.context (
grpc._server._Context
) – The context object (unused)
- Returns:
A model response iterator.
- Return type:
fedn.network.grpc.fedn_pb2.ModelResponse
- Upload(request_iterator, context)[source]
RPC endpoints for uploading a model.
- Parameters:
request_iterator (
fedn.network.grpc.fedn_pb2.ModelRequest
) – The model request iterator.context (
grpc._server._Context
) – The context object (unused)
- Returns:
A model response object.
- Return type:
fedn.network.grpc.fedn_pb2.ModelResponse
- exist(model_id)[source]
Check if a model exists on the server.
- Parameters:
model_id – The model id.
- Returns:
True if the model exists, else False.
- get_model(id)[source]
Download model with id ‘id’ from server.
- Parameters:
id (str) – The model id.
- Returns:
A BytesIO object containing the model.
- Return type:
io.BytesIO
, None if model does not exist.
- load_model_from_BytesIO(model_bytesio, helper)[source]
Load a model from a BytesIO object.
- Parameters:
model_bytesio (
io.BytesIO
) – A BytesIO object containing the model.helper (
fedn.utils.helperbase.HelperBase
) – The helper object for the model.
- Returns:
The model object.
- Return type:
return type of helper.load
- serialize_model_to_BytesIO(model, helper)[source]
Serialize a model to a BytesIO object.
- Parameters:
model (return type of helper.load) – The model object.
helper (
fedn.utils.helperbase.HelperBase
) – The helper object for the model.
- Returns:
A BytesIO object containing the model.
- Return type:
- set_model(model, id)[source]
Upload model to server.
- Parameters:
model (
io.BytesIO
) – A model object (BytesIO)id (str) – The model id.
fedn.network.combiner.round module
- class fedn.network.combiner.round.RoundController(aggregator_name, storage, server, modelservice)[source]
Bases:
object
Round controller.
The round controller recieves round configurations from the global controller and coordinates model updates and aggregation, and model validations.
- Parameters:
aggregator_name (str) – The name of the aggregator plugin module.
storage (class: fedn.common.storage.s3.s3repo.S3ModelRepository) – Model repository for :class: fedn.network.combiner.Combiner
server (class: fedn.network.combiner.Combiner) – A handle to the Combiner class :class: fedn.network.combiner.Combiner
modelservice (class: fedn.network.combiner.modelservice.ModelService) – A handle to the model service :class: fedn.network.combiner.modelservice.ModelService
- execute_validation_round(round_config)[source]
Coordinate validation rounds as specified in config.
- Parameters:
round_config (dict) – The round config object.
- load_model_update(helper, model_id)[source]
Load model update in its native format.
- Parameters:
helper (class: fedn.utils.helpers.HelperBase) – An instance of :class: fedn.utils.helpers.HelperBase, ML framework specific helper, defaults to None
model_id (str) – The ID of the model update, UUID in str format
- load_model_update_str(model_id, retry=3)[source]
Load model update object and return it as BytesIO.
- run(polling_interval=1.0)[source]
Main control loop. Execute rounds based on round config on the queue.
- Parameters:
polling_interval (float) – The polling interval in seconds for checking if a new job/config is available.
- stage_model(model_id, timeout_retry=3, retry=2)[source]
Download a model from persistent storage and set in modelservice.
- waitforit(config, buffer_size=100, polling_interval=0.1)[source]
Defines the policy for how long the server should wait before starting to aggregate models.
- The policy is as follows:
Wait a maximum of time_window time until the round times out.
Terminate if a preset number of model updates (buffer_size) are in the queue.