fedn.network.clients package
The FEDn client package is responsible for executing the federated learning tasks, including ML model training and validation. It’s the acting gRPC client for the federated network.
The client first connacts the centralized controller to receive fedn.network.combiner.Combiner
assingment. The client then connects to the combiner and
sends requests to the combiner to receive model updates and send model updates.
Submodules
fedn.network.clients.client module
- class fedn.network.clients.client.Client(config)[source]
Bases:
object
FEDn Client. Service running on client/datanodes in a federation, recieving and handling model update and model validation requests.
- Parameters:
config (dict) – A configuration dictionary containing connection information for the discovery service (controller) and settings governing e.g. client-combiner assignment behavior.
- assign()[source]
Contacts the controller and asks for combiner assignment.
- Returns:
A configuration dictionary containing connection information for combiner.
- Return type:
- connect(combiner_config)[source]
Connect to combiner.
- Parameters:
combiner_config (dict) – connection information for the combiner.
- get_model_from_combiner(id, timeout=20)[source]
Fetch a model from the assigned combiner. Downloads the model update object via a gRPC streaming channel.
- Parameters:
id (str) – The id of the model update object.
- Returns:
The model update object.
- Return type:
BytesIO
- send_model_to_combiner(model, id)[source]
Send a model update to the assigned combiner. Uploads the model updated object via a gRPC streaming channel, Upload.
- Parameters:
model (BytesIO) – The model update object.
id (str) – The id of the model update object.
- Returns:
The model update object.
- Return type:
BytesIO
fedn.network.clients.connect module
- class fedn.network.clients.connect.ConnectorClient(host, port, token, name, remote_package, force_ssl=False, verify=False, combiner=None, id=None)[source]
Bases:
object
Connector for assigning client to a combiner in the FEDn network.
- Parameters:
host (str) – host of discovery service
port (int) – port of discovery service
token (str) – token for authentication
name (str) – name of client
remote_package (bool) – True if remote package is used, False if local
force_ssl (bool) – True if https is used, False if http
verify (bool) – True if certificate is verified, False if not
combiner (str) – name of preferred combiner
id – id of client
- assign()[source]
Connect client to FEDn network discovery service, ask for combiner assignment.
- Returns:
Tuple with assingment status, combiner connection information if sucessful, else None.
- Return type:
tuple(
fedn.network.clients.connect.Status
, str)
- refresh_token()[source]
Refresh client token.
- Returns:
Tuple with assingment status, combiner connection information if sucessful, else None.
- Return type:
tuple(
fedn.network.clients.connect.Status
, str)
fedn.network.clients.package module
- class fedn.network.clients.package.PackageRuntime(package_path)[source]
Bases:
object
PackageRuntime is used to download, validate and unpack compute packages.
- Parameters:
- dispatcher(run_path)[source]
Dispatch the compute package
- Parameters:
run_path (str) – path to dispatch the compute package
- Returns:
Dispatcher object
- Return type:
- download(host, port, token, force_ssl=False, secure=False, name=None)[source]
Download compute package from controller
- Parameters:
host – host of controller
port – port of controller
token – token for authentication
name – name of package
- Returns:
True if download was successful, None otherwise
- Return type:
fedn.network.clients.state module
- class fedn.network.clients.state.ClientState(value)[source]
Bases:
Enum
Enum for representing the state of a client.
- idle = 1
- training = 2
- validating = 3
- fedn.network.clients.state.ClientStateToString(state)[source]
Convert a ClientState to a string representation.
- Parameters:
state (
fedn.network.clients.state.ClientState
) – the state to convert- Returns:
string representation of the state
- Return type: