Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type issue with dict returned by client fit function #3951

Open
Abhaygoya opened this issue Aug 1, 2024 · 0 comments
Open

Type issue with dict returned by client fit function #3951

Abhaygoya opened this issue Aug 1, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@Abhaygoya
Copy link

Describe the bug

I believe there is a type issue with the client fit function returns. In particular, the third return is a dict which contains metrics that will be passed to the server. The dict has limits on which types of variables can be values, and an error is thrown when the wrong type is included in the dict (such as ndarray). However, a list is indicated as an allowed value in the error message, but the client script fails when there is a list value in the dict.

Steps/Code to Reproduce

For example, using sklearn, I attempted to return a metrics dict of the following format:

metrics = {}
metrics["model_updates"] = (final_coef - initial_coef)
...
return utils.get_model_parameters(model), len(X_train), metrics

and received this error message:

Message: Not all values are of valid type. Expected `typing.Union[int, float, str, bytes, bool, typing.List[int], typing.List[float], typing.List[str], typing.List[bytes], typing.List[bool]]` but `<class 'numpy.ndarray'>` was passed.

This indicates that ndarrays are not a valid format, which is fine. However, upon converting this to a list, the client function fails without an error message. Specifically, I modified the above to:

metrics = {}
metrics["model_updates"] = (final_coef - initial_coef).tolist()
...
return utils.get_model_parameters(model), len(X_train), metrics

As indicated in the error message, List[float] is a valid return type, and no error message was created after this update. However, the client function fails and the server does not receive the model updates.

Further, if the list is broken up into scalar values there is no issue.

metrics = {}
for i in range(len(initial_coef)):
            metrics[f"model_updates_{i}"] = (final_coef[i] - initial_coef[i])
...
return utils.get_model_parameters(model), len(X_train), metrics

With this change, the dict contains several float values, rather than a singular List[float]. While the error message implied that either should be fine, the client only successfully executes when the dict contains scalar float values.

Expected Results

Based on the error message, I would expect this to work:

metrics = {}
metrics["model_updates"] = (final_coef - initial_coef).tolist()
...
return utils.get_model_parameters(model), len(X_train), metrics

Actual Results

There is no error message, but all client scripts end in failure.

[ROUND 1]
INFO :      configure_fit: strategy sampled 5 clients (out of 5)
INFO :      aggregate_fit: received 0 results and 5 failures
@Abhaygoya Abhaygoya added the bug Something isn't working label Aug 1, 2024
@jafermarq jafermarq self-assigned this Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants