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

Import SGDSerialClientTrainer in qfedavg #349

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions fedlab/contrib/algorithm/qfedavg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .basic_server import SyncServerHandler
from .basic_client import SGDClientTrainer
from .basic_client import SGDSerialClientTrainer


##################
Expand Down Expand Up @@ -40,7 +41,7 @@ def uplink_package(self):
def setup_optim(self, epochs, batch_size, lr, q):
super().setup_optim(epochs, batch_size, lr)
self.q = q

def train(self, model_parameters, train_loader) -> None:
"""Client trains its local model on local dataset.
Args:
Expand Down Expand Up @@ -72,11 +73,12 @@ def train(self, model_parameters, train_loader) -> None:
ret_loss + 1e-10, self.q - 1) * grad.norm(
)**2 + 1.0 / self.lr * np.float_power(ret_loss + 1e-10, self.q)


class qFedAvgSerialClientTrainer(SGDSerialClientTrainer):
def setup_optim(self, epochs, batch_size, lr, q):
super().setup_optim(epochs, batch_size, lr)
self.q = q

def train(self, model_parameters, train_loader) -> None:
"""Client trains its local model on local dataset.
Args:
Expand Down
Loading