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

Bug Fix [Issue #355] #356

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

SHAO-Jiaqi757
Copy link

@SHAO-Jiaqi757 SHAO-Jiaqi757 commented Oct 20, 2023

Description

How has this been tested?

Types of changes

  • To make consistent_clients usable, set self.consistent_clients = Config().data.consistent_clients.
    If the configuration has consistent_clients, then consistent_client_size is useless since it is only used for randomly sampling a set of consistent_clients.

Changes:

    if hasattr(Config().data, "consistent_clients"):
        self.consistent_clients = Config().data.consistent_clients
    else:
        consistent_clients_size = Config().data.consistent_clients_size
        self.consistent_clients = np.random.choice(
        list(range(total_clients)), size=consistent_clients_size, replace=False
    )
  • To make client_id consistent (the original code used client_id for the client index), there are some modifications for client_id to client_idx.
    The consistent_clients in configuration can be set with a list of client ids.

  • Testing

client = Client(trainer=trainer)
sampler = client.sampler.get()
indices = sampler.indices
labels = [client.trainset[i][1] for i in indices]
counter = Counter(labels)
print(f"client id # {client.client_id} has trainsets stats {counter}")

Output:

  • Note that the consistent_clients = [1, 2] and anchor_classes = [3, 4, 9]
    For the index based clients_contain_classes, key = client_id -1
clients_contain_classes:  {0: [3, 4, 9], 1: [3, 4, 9], 2: [2, 5, 3], 3: [3, 6, 8], 4: [4, 0, 5], 5: [5, 7, 0], 6: [6, 7, 1], 7: [7, 5, 1], 8: [0, 7, 1], 9: [1, 8, 0]}
client id # 1 has trainsets stats Counter({9: 2975, 4: 1948, 3: 1533})
client id # 2 has trainsets stats Counter({9: 2974, 4: 1947, 3: 1533})
client id # 3 has trainsets stats Counter({2: 5958, 3: 1533, 5: 1356})
client id # 4 has trainsets stats Counter({6: 2959, 8: 2926, 3: 1532})
client id # 5 has trainsets stats Counter({4: 1947, 0: 1481, 5: 1355})
client id # 6 has trainsets stats Counter({7: 1567, 0: 1481, 5: 1355})
client id # 7 has trainsets stats Counter({6: 2959, 1: 1686, 7: 1566})
client id # 8 has trainsets stats Counter({1: 1686, 7: 1566, 5: 1355})
client id # 9 has trainsets stats Counter({1: 1685, 7: 1566, 0: 1481})
client id # 10 has trainsets stats Counter({8: 2925, 1: 1685, 0: 1480})

Checklist:

  • My code has been formatted using Black and checked using PyLint.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

The documentation may not need to change according to comments, where the client is labeled by client_id rather than client_idx.

@netlify
Copy link

netlify bot commented Oct 20, 2023

Deploy Preview for platodocs canceled.

Name Link
🔨 Latest commit 0a6af60
🔍 Latest deploy log https://app.netlify.com/sites/platodocs/deploys/65373e63cf72250008f0c287

Copy link
Collaborator

@CSJDeveloper CSJDeveloper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, the reported Issue#355 is not a bug because the mixed_label_quantity_noniid.py is designed to only accept consistent_clients_size and choose the "consistent_clients" randomly.

Thus, what the author did in the PR was to add a new feature to mixed_label_quantity_noniid.py by also including the consistent_clients in the configuration.

Therefore, you may need to change the label to be the enhancement.

Second, I, personally, do not think such an 'enhancement' is a good idea because when there are 1000 clients, why does a user want to set the "consistent_clients" (maybe 100 clients) one by one in the configuration file?

@SHAO-Jiaqi757
Copy link
Author

According to file description, consistent_clients can be configured.
However, there seems to be a lack of alignment between the file's description and its actual usage. This discrepancy can lead to confusion for users and developers alike.

Furthermore, the primary objective of this configuration is to simulate research scenarios, especially with a limited number of clients. In such cases, having precise control over specific clients becomes crucial. Instead, randomly selecting 30 out of 100 clients to be consistent_clients may not effectively capture the desired impact, which might not be suitable in a research setting where the focus is on understanding the nuances of specific client behaviors.

It would be beneficial to provide a more deterministic way of selecting consistent_clients or allowing users to specify which clients they want to be consistent. This would offer more flexibility and precision in research simulations.

@CSJDeveloper
Copy link
Collaborator

According to file description, consistent_clients can be configured. However, there seems to be a lack of alignment between the file's description and its actual usage. This discrepancy can lead to confusion for users and developers alike.

Furthermore, the primary objective of this configuration is to simulate research scenarios, especially with a limited number of clients. In such cases, having precise control over specific clients becomes crucial. Instead, randomly selecting 30 out of 100 clients to be consistent_clients may not effectively capture the desired impact, which might not be suitable in a research setting where the focus is on understanding the nuances of specific client behaviors.

It would be beneficial to provide a more deterministic way of selecting consistent_clients or allowing users to specify which clients they want to be consistent. This would offer more flexibility and precision in research simulations.

I get your point, and we reached an agreement that the current adjustment is more like an enhancement. Right?

If so, it would be great to accept your revision on consistent_clients.

I noticed that you also adjusted the 'client_id' or 'client_idx' to make it clear. My suggestion is that could you please change it back as if we want to change some code under samplers/, all samplers should be revised or tested accordingly.

Therefore, in this PR, it would be great to only maintain the enhancement. But for the change made on client_id, we can move it to another PR if you want.

@SHAO-Jiaqi757
Copy link
Author

According to file description, consistent_clients can be configured. However, there seems to be a lack of alignment between the file's description and its actual usage. This discrepancy can lead to confusion for users and developers alike.
Furthermore, the primary objective of this configuration is to simulate research scenarios, especially with a limited number of clients. In such cases, having precise control over specific clients becomes crucial. Instead, randomly selecting 30 out of 100 clients to be consistent_clients may not effectively capture the desired impact, which might not be suitable in a research setting where the focus is on understanding the nuances of specific client behaviors.
It would be beneficial to provide a more deterministic way of selecting consistent_clients or allowing users to specify which clients they want to be consistent. This would offer more flexibility and precision in research simulations.

I get your point, and we reached an agreement that the current adjustment is more like an enhancement. Right?

If so, it would be great to accept your revision on consistent_clients.

I noticed that you also adjusted the 'client_id' or 'client_idx' to make it clear. My suggestion is that could you please change it back as if we want to change some code under samplers/, all samplers should be revised or tested accordingly.

Therefore, in this PR, it would be great to only maintain the enhancement. But for the change made on client_id, we can move it to another PR if you want.

I agree that this change can be viewed as "feature enhancement" and I will check other client_idx in sampler for further clarity.
Could you please help me to know what should we do next for this PR?

@CSJDeveloper
Copy link
Collaborator

According to file description, consistent_clients can be configured. However, there seems to be a lack of alignment between the file's description and its actual usage. This discrepancy can lead to confusion for users and developers alike.
Furthermore, the primary objective of this configuration is to simulate research scenarios, especially with a limited number of clients. In such cases, having precise control over specific clients becomes crucial. Instead, randomly selecting 30 out of 100 clients to be consistent_clients may not effectively capture the desired impact, which might not be suitable in a research setting where the focus is on understanding the nuances of specific client behaviors.
It would be beneficial to provide a more deterministic way of selecting consistent_clients or allowing users to specify which clients they want to be consistent. This would offer more flexibility and precision in research simulations.

I get your point, and we reached an agreement that the current adjustment is more like an enhancement. Right?
If so, it would be great to accept your revision on consistent_clients.
I noticed that you also adjusted the 'client_id' or 'client_idx' to make it clear. My suggestion is that could you please change it back as if we want to change some code under samplers/, all samplers should be revised or tested accordingly.
Therefore, in this PR, it would be great to only maintain the enhancement. But for the change made on client_id, we can move it to another PR if you want.

I agree that this change can be viewed as "feature enhancement" and I will check other client_idx in sampler for further clarity. Could you please help me to know what should we do next for this PR?

Thank you very much for your work!

For this PR, could you please just remove your changes in sampler_utils.py? By doing so, this PR can contain the enhancement.

If you want to have more work on the 'client_id' of the sampler, you can create a PR specific for this. Thus, we can have more discussion there when necessary.

CSJDeveloper and others added 4 commits October 24, 2023 11:28
…e slight changes to base Plato (TL-System#358)

* removed the second assert in check_hyper_parameters.

* removed unncessary int () in initialize_personalization.

* moved check_hyper_parameters after choose_clients().

* fixed a pylint error, using f-string.

* fixed a pylint error.

* Changed the name of client type

* fixed a pylint error.

* Fixed one pylint issue in fedavg_partial

* Addressed the issue of PyTorch errors related to CIFAR-10 dataset downloading when clients:do_test is True.

* Removed the duplicated _path loading

* Improved the data downloading code.

* Revised the data downloading code.

* Removed all code related to personalized metrics logging

* Rewrote the test_model by adding the support for personalized accuracy

* Removed all unnecessary operations in the server for personalization

* Moved the checkpoint operator to pflbases

* Redesigned the personalized client by removing invalid or unnecessary code

* Added the random seed setting

* Removed all unnecessary code under personalized trainer

* Removed all unnecessary training logging

* Added the load weights and set it to be False for partial aggregation

* Removed unnecessary componenets

* Fixed some issues in the client and the trainer

* Changed the FedRep in response to the code revision

* Added more descriptions in the README.md file

* Fixed a typo

* Removed useless sentences in README.md

* Set default personalized model name to the model name under trainer block

* Revised a typo

* Added the accuracy std in the logging of Plato

* Added more loggins; Cleaned the code to make it more readable

* Revised the fedrep example based on the latest update

* Moved the personalization indicators to the client part

* Revised the fedavg with finetune based on the latest update

* Revised the fedrep based on the latest update

* Made the clients accuracy recoding as optional

* Improved one more checking to make the code more robust

---------

Co-authored-by: Dixi Yao <[email protected]>
Co-authored-by: Baochun Li <[email protected]>
…llbacks functions as APIs for split learning. (TL-System#357)

* moved split learning configuration to config/

* moved split_learning from examples to code_base.

* added cut_layer into resnet model.

* added split learning in configuration.md

* added two callback functions for APIS.

* added callback function on_server_forward_from.

* added APIs for using callback functions for test model.

* added split learning callbacks.

* resent the callback for splitlearning callbacks.

* added split learning into registry.py.

* fixed pylint errors.

* added configuration file for split_learning resnet18.

* fixed bugs in call back function on_serveR_forward_from.

* redesigned the callback API of test model.

* revised the configuration file.

* revised the comments.

* Delete split_learning_lenet5.yml

* changed callbacks into functions. The users can override these API functions if necessary.

* removed split learning callback.

* Fixed spelling mistakes.

---------

Co-authored-by: Baochun Li <[email protected]>
* fixed a pylint error.

* fixed a pylint errir in trainer_utils.py.

* fixed a typo in local_completion_callbacks.py.

* Revised a typo

* Uploaded a new README.md file with more detailed descriptions

* Fixed some comments

* Fixed FedBABU algo based on the latest pflbases

* Revised the apfl for the latest pflbases

* Added an illustration of pflbases in the README.md

* Updated the fedper algorithm

* Revised the perfedavg

* Revised lgfedavg

* Revised the hermes algorithm

* Revised Ditto based on the latest pflbases

* fixed a pylint error.

* fixed a pylint error in hermes_pruning.py

* fixed pylint error of considering merging.

* Removed send mask from Plato and added it to the Hermes

* Replaced the send mask with a new callback

---------

Co-authored-by: Dixi Yao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants