[BUG] cannot assign the custom trainer to Algorithm, Client, and Server simultaneously.
CSJDeveloper opened this issue · 0 comments
Describe the bug
If the users want to implement their own Algorithm class, Trainer class, and Server class, there is no way to instantiate these three classes following the old ways:
trainer = fedrep_trainer.Trainer
algorithm = fedrep_algorithm.Algorithm(trainer=trainer)
client = fedrep_client.Client(algorithm=algorithm, trainer=trainer)
server = fedrep_server.Server(algorithm=algorithm, trainer=trainer)
or
trainer = fedrep_trainer.Trainer()
algorithm = fedrep_algorithm.Algorithm(trainer=trainer)
client = fedrep_client.Client(algorithm=algorithm, trainer=trainer)
server = fedrep_server.Server(algorithm=algorithm, trainer=trainer)
To Reproduce
Steps to reproduce the behavior:
Three methods, which implemented their own algorithms, generate this bug.
- See the
examples/adaptive_freezing
orexamples/split_learning
in the main branch orexamples/fedrep
in the personalizedFL branch - Run the code, for example in fedrep method,
python examples/fedrep/fedrep.py -c examples/fedrep/fedrep_MNIST_lenet5.yml
- See error
AttributeError: type object 'Trainer' has no attribute 'model'
Expected behavior
The code is expected to run smoothly without this error at the starting point.
Additional context
This bug is easy to be located as the Algorithm receives the instantiated trainer as the parameter and then extracts the trainer's model. However, the Client class and Server class receive the Trainer class as the parameter to further define the self.trainer inside, as shown by line 120 self.trainer = self.custom_trainer(model=self.model)
of servers/fedavg.py.