flox.logic.base_controller.FloxControllerLogic

class FloxControllerLogic[source]

Bases: object

Abstract base class for FLoX Controller logic

Methods

on_model_aggregate

Aggregates weights.

on_model_broadcast

Sends the model and config to endpoints for FL training.

on_model_evaluate

Evaluates the given model using test_data

on_model_init

Does initial Controller setup before running the main Federated Learning loop

on_model_receive

Processes returned tasks from on_model_broadcast.

on_model_update

Updates the model's weights with new weights

on_model_aggregate(ins)[source]

Aggregates weights.

Return type:

List[ndarray[Any, dtype[Any]]]

Parameters

ins: list

FL results extracted from the list of futures, formatted as a dictionary. For example: results = {

“model_weights”: model_weights, “samples_count”: samples_count, “bias_weights”: fractions,

}

Returns

NDArrays

ML model weights for a single model in the form of Numpy Arrays.

on_model_broadcast()[source]

Sends the model and config to endpoints for FL training.

Return type:

list

Returns

list

A list of tasks/futures with results of the FL training returned from the endpoints. If using FuncXExecutor, this would most likely be a list of futures funcX returns after you submit functions to endpoints.

on_model_evaluate(test_data, model=None)[source]

Evaluates the given model using test_data

Return type:

dict

Parameters

test_data

data for evaluating the model. This can take different forms depending on the ML framework you use. For Tensorflow, it would look as x_test and y_test, while for PyTorch, it would look as a single DataLoader instance.

model

The machine learning model for evaluation. Whether you pass it as a parameter would depend on the ML framework. With Tensorflow, we cannot save and transfer the model as a class attribute, while for PyTorch it was possible so we do not need to pass it as a parameter.

Returns

dict
A dictionary showing the evaluation metrics, such as loss and accuracy:
dict = {

“loss”: float, “metrics”: Dict[str, Scalar] }

on_model_init()[source]

Does initial Controller setup before running the main Federated Learning loop

Return type:

None

on_model_receive(ins)[source]

Processes returned tasks from on_model_broadcast.

Return type:

dict

Parameters

ins: list

A list of tasks/futures with results of the FL training returned from the endpoints. If using FuncXExecutor, this would most likely be a list of futures funcX returns after you submit functions to endpoints.

Returns

results: dict

FL results extracted from the list of futures, formatted as a dictionary. For example: resykts = {

“model_weights”: model_weights, “samples_count”: samples_count, “bias_weights”: fractions,

}

on_model_update(weights)[source]

Updates the model’s weights with new weights

Return type:

None

Parameters

weights: NDArrays

ML model weights for a single model in the form of Numpy Arrays.