pythonscikit-learndata-scienceflowerfederated-learning

I'm getting an **NumPyClient.fit did not return a tuple with 3 elements.** error when I run client.py file. What could be the problem?


I am using the Flower code example to try POC of Federated Learning but I keep getting the error below when I run the client.py file:

INFO flower 2022-07-04 15:27:37,301 | connection.py:102 | Opened insecure gRPC connection (no certificates were passed)
DEBUG flower 2022-07-04 15:27:37,323 | connection.py:39 | ChannelConnectivity.IDLE
DEBUG flower 2022-07-04 15:27:37,389 | connection.py:39 | ChannelConnectivity.CONNECTING
DEBUG flower 2022-07-04 15:27:37,708 | connection.py:39 | ChannelConnectivity.READY
Training finished for round 5
DEBUG flower 2022-07-04 15:27:41,178 | connection.py:121 | gRPC channel closed
Traceback (most recent call last):
File "C:\Users\HP\Development\Federated-Learning-sklearn\sklearnff\client.py", line 52, in
fl.client.start_numpy_client(
File "C:\Users\HP.virtualenvs\sklearnff-UZKgGLZy\lib\site-packages\flwr\client\app.py", line 173, in start_numpy_client
start_client(
File "C:\Users\HP.virtualenvs\sklearnff-UZKgGLZy\lib\site-packages\flwr\client\app.py", line 94, in start_client
client_message, sleep_duration, keep_going = handle(
File "C:\Users\HP.virtualenvs\sklearnff-UZKgGLZy\lib\site-packages\flwr\client\grpc_client\message_handler.py", line 61, in handle
return _fit(client, server_msg.fit_ins), 0, True
File "C:\Users\HP.virtualenvs\sklearnff-UZKgGLZy\lib\site-packages\flwr\client\grpc_client\message_handler.py", line 117, in _fit
fit_res = client.fit(fit_ins)
File "C:\Users\HP.virtualenvs\sklearnff-UZKgGLZy\lib\site-packages\flwr\client\numpy_client.py", line 203, in fit
raise Exception(EXCEPTION_MESSAGE_WRONG_RETURN_TYPE_FIT)
Exception:
NumPyClient.fit did not return a tuple with 3 elements.
The returned values should have the following type signature:

Tuple[List[np.ndarray], int, Dict[str, Scalar]]
Example
model.get_weights(), 10, {"accuracy": 0.95}

Solution

  • I solved it by changing the return type of get_model_parameters from tuple to list.

    def get_model_parameters(model: LogisticRegression) -> LogRegParams:
        """Returns the paramters of a sklearn LogisticRegression model."""
        if model.fit_intercept:
            params = [model.coef_, model.intercept_]
        else:
            params = [model.coef_, ]
        return params