SMILELab-FL / FedLab

A flexible Federated Learning Framework based on PyTorch, simplifying your Federated Learning research.
https://fedlab.readthedocs.io
Apache License 2.0
740 stars 127 forks source link

Importing basic_client results in a NameError #348

Closed techwizrd closed 10 months ago

techwizrd commented 10 months ago

Describe the bug

Importing fedlab.contrib.algorithm.basic_client executes the __init__.py, which imports from qfedavg.py. This results in a

NameError: name 'SGDSerialClientTrainer' is not defined. Did you mean: 'SGDClientTrainer'?

The full stacktrace is below:

(.venv) ~/code/techwizrd-FedLab> python -c "from fedlab.contrib.algorithm.basic_client import SGDSerialClientTrainer"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/kunal/code/techwizrd-FedLab/fedlab/contrib/algorithm/__init__.py", line 13, in <module>
    from .qfedavg import qFedAvgClientTrainer, qFedAvgServerHandler
  File "/home/kunal/code/techwizrd-FedLab/fedlab/contrib/algorithm/qfedavg.py", line 75, in <module>
    class qFedAvgSerialClientTrainer(SGDSerialClientTrainer):
                                     ^^^^^^^^^^^^^^^^^^^^^^
NameError: name 'SGDSerialClientTrainer' is not defined. Did you mean: 'SGDClientTrainer'?

Environment Environment you use when bug appears:

  1. Python version: Python 3.11.4
  2. PyTorch Version: 2.2.0+cu121
  3. FedLab version: 1.3.0
  4. code you run:
    from fedlab.contrib.algorithm.basic_client import SGDSerialClientTrainer
  5. the detailed error:
    NameError: name 'SGDSerialClientTrainer' is not defined. Did you mean: 'SGDClientTrainer'?

Additional context

I believe this bug was introduced in 698746e62ab9c8454b22d1c4864489579e0c7da5 which introduced a dependency on SGDSerialClientTrainer in qfedavg.py, and can be fixed simply by adding an import of SGDSerialClientTrainer.

techwizrd commented 10 months ago

I've pushed a fix and created a pull request in SMILELab-FL/FedLab#349.