{"id":13712771,"url":"https://github.com/AshwinRJ/Federated-Learning-PyTorch","last_synced_at":"2025-05-06T22:31:27.011Z","repository":{"id":37677855,"uuid":"157933925","full_name":"AshwinRJ/Federated-Learning-PyTorch","owner":"AshwinRJ","description":"Implementation of Communication-Efficient Learning of Deep Networks from Decentralized Data","archived":false,"fork":false,"pushed_at":"2024-05-07T14:34:34.000Z","size":214,"stargazers_count":1289,"open_issues_count":29,"forks_count":451,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-13T23:32:31.416Z","etag":null,"topics":["deep-learning","distributed-computing","federated-learning","python","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AshwinRJ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-16T23:51:14.000Z","updated_at":"2024-11-12T08:53:41.000Z","dependencies_parsed_at":"2024-01-12T02:43:41.114Z","dependency_job_id":"9492f054-c4d5-403b-9556-e4691a4c143e","html_url":"https://github.com/AshwinRJ/Federated-Learning-PyTorch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshwinRJ%2FFederated-Learning-PyTorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshwinRJ%2FFederated-Learning-PyTorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshwinRJ%2FFederated-Learning-PyTorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshwinRJ%2FFederated-Learning-PyTorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AshwinRJ","download_url":"https://codeload.github.com/AshwinRJ/Federated-Learning-PyTorch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252779077,"owners_count":21802877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","distributed-computing","federated-learning","python","pytorch"],"created_at":"2024-08-02T23:01:22.454Z","updated_at":"2025-05-06T22:31:26.635Z","avatar_url":"https://github.com/AshwinRJ.png","language":"Python","readme":"# Federated-Learning (PyTorch)\n\nImplementation of the vanilla federated learning paper : [Communication-Efficient Learning of Deep Networks from Decentralized Data](https://arxiv.org/abs/1602.05629).\n\n\nExperiments are produced on MNIST, Fashion MNIST and CIFAR10 (both IID and non-IID). In case of non-IID, the data amongst the users can be split equally or unequally.\n\nSince the purpose of these experiments are to illustrate the effectiveness of the federated learning paradigm, only simple models such as MLP and CNN are used.\n\n## Requirments\nInstall all the packages from requirments.txt\n* Python3\n* Pytorch\n* Torchvision\n\n## Data\n* Download train and test datasets manually or they will be automatically downloaded from torchvision datasets.\n* Experiments are run on Mnist, Fashion Mnist and Cifar.\n* To use your own dataset: Move your dataset to data directory and write a wrapper on pytorch dataset class.\n\n## Running the experiments\nThe baseline experiment trains the model in the conventional way.\n\n* To run the baseline experiment with MNIST on MLP using CPU:\n```\npython src/baseline_main.py --model=mlp --dataset=mnist --epochs=10\n```\n* Or to run it on GPU (eg: if gpu:0 is available):\n```\npython src/baseline_main.py --model=mlp --dataset=mnist --gpu=0 --epochs=10\n```\n-----\n\nFederated experiment involves training a global model using many local models.\n\n* To run the federated experiment with CIFAR on CNN (IID):\n```\npython src/federated_main.py --model=cnn --dataset=cifar --gpu=0 --iid=1 --epochs=10\n```\n* To run the same experiment under non-IID condition:\n```\npython src/federated_main.py --model=cnn --dataset=cifar --gpu=0 --iid=0 --epochs=10\n```\n\nYou can change the default values of other parameters to simulate different conditions. Refer to the options section.\n\n## Options\nThe default values for various paramters parsed to the experiment are given in ```options.py```. Details are given some of those parameters:\n\n* ```--dataset:```  Default: 'mnist'. Options: 'mnist', 'fmnist', 'cifar'\n* ```--model:```    Default: 'mlp'. Options: 'mlp', 'cnn'\n* ```--gpu:```      Default: None (runs on CPU). Can also be set to the specific gpu id.\n* ```--epochs:```   Number of rounds of training.\n* ```--lr:```       Learning rate set to 0.01 by default.\n* ```--verbose:```  Detailed log outputs. Activated by default, set to 0 to deactivate.\n* ```--seed:```     Random Seed. Default set to 1.\n\n#### Federated Parameters\n* ```--iid:```      Distribution of data amongst users. Default set to IID. Set to 0 for non-IID.\n* ```--num_users:```Number of users. Default is 100.\n* ```--frac:```     Fraction of users to be used for federated updates. Default is 0.1.\n* ```--local_ep:``` Number of local training epochs in each user. Default is 10.\n* ```--local_bs:``` Batch size of local updates in each user. Default is 10.\n* ```--unequal:```  Used in non-iid setting. Option to split the data amongst users equally or unequally. Default set to 0 for equal splits. Set to 1 for unequal splits.\n\n## Results on MNIST\n#### Baseline Experiment:\nThe experiment involves training a single model in the conventional way.\n\nParameters: \u003cbr /\u003e\n* ```Optimizer:```    : SGD \n* ```Learning Rate:``` 0.01\n\n```Table 1:``` Test accuracy after training for 10 epochs:\n\n| Model | Test Acc |\n| ----- | -----    |\n|  MLP  |  92.71%  |\n|  CNN  |  98.42%  |\n\n----\n\n#### Federated Experiment:\nThe experiment involves training a global model in the federated setting.\n\nFederated parameters (default values):\n* ```Fraction of users (C)```: 0.1 \n* ```Local Batch size  (B)```: 10 \n* ```Local Epochs      (E)```: 10 \n* ```Optimizer            ```: SGD \n* ```Learning Rate        ```: 0.01 \u003cbr /\u003e\n\n```Table 2:``` Test accuracy after training for 10 global epochs with:\n\n| Model |    IID   | Non-IID (equal)|\n| ----- | -----    |----            |\n|  MLP  |  88.38%  |     73.49%     |\n|  CNN  |  97.28%  |     75.94%     |\n\n\n## Further Readings\n### Papers:\n* [Federated Learning: Challenges, Methods, and Future Directions](https://arxiv.org/abs/1908.07873)\n* [Communication-Efficient Learning of Deep Networks from Decentralized Data](https://arxiv.org/abs/1602.05629)\n* [Deep Learning with Differential Privacy](https://arxiv.org/abs/1607.00133)\n\n### Blog Posts:\n* [CMU MLD Blog Post: Federated Learning: Challenges, Methods, and Future Directions](https://blog.ml.cmu.edu/2019/11/12/federated-learning-challenges-methods-and-future-directions/)\n* [Leaf: A Benchmark for Federated Settings (CMU)](https://leaf.cmu.edu/)\n* [TensorFlow Federated](https://www.tensorflow.org/federated)\n* [Google AI Blog Post](https://ai.googleblog.com/2017/04/federated-learning-collaborative.html)\n","funding_links":[],"categories":["Table of Contents","Projects"],"sub_categories":["2022"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAshwinRJ%2FFederated-Learning-PyTorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAshwinRJ%2FFederated-Learning-PyTorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAshwinRJ%2FFederated-Learning-PyTorch/lists"}