alpemreacar / feddyn Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Current way loss of feddyn is calculated (in utils_general):
loss_algo = alpha_coef * torch.sum(local_par_list * (-avg_mdl_param + local_grad_vector))
I think what you wanted to do (unless I'm missing something) is:
loss_algo = alpha_coef * torch.sum(local_par_list * (0.5*local_par_list - avg_mdl_param + local_grad_vector))
Maybe is much clearer (match paper equation) to write something like:
loss_algo = alpha_coef * torch.sum(local_par_list * local_grad_vector) + 0.5*alpha_coef*(local_par_list - avg_mdl_param)**2
Feel free to correct me if I'm wrong.
Thanks for your awesome works. I'm trying to re-implement your algorithm. But when I read the source code, I cannot find where is the server state
If I understand correctly, in this line https://github.com/alpemreacar/FedDyn/blob/48a19fac440ef079ce563da8e0c2896f8256fef9/utils_methods.py#L389, the local_param_list_curr is the local grad
In this line https://github.com/alpemreacar/FedDyn/blob/48a19fac440ef079ce563da8e0c2896f8256fef9/utils_methods.py#L397, the cld_mdl_param is the new global model parameter
Thus, the code means that
in which here I ignore the
So here the actual
Current way loss of fedprox is calculated (in utils_general):
loss_algo = mu/2 * torch.sum(local_par_list * local_par_list)
loss_algo = -mu * torch.sum(local_par_list * avg_model_param_)
I think what you wanted to do (unless I'm missing something) is:
loss_algo = mu/2 * torch.sum(local_par_list * local_par_list)
loss_algo = loss_algo - mu * torch.sum(local_par_list * avg_model_param_)
Cheers,
F. Varno
Subject: I find that the order of {Horizontal flip, Random cropping} and {normalize} is somewhat different from the typical operation order, which I think will not affect the experimental conclusion, yet is interesting here.
Detail: Take CIFAR-10 (iid and FedAvg) as an example.
{Normalize.} In utils_dataset.py's lines 32-41. We generate trn_load
with normalized, which then is used to generate self.trn_x
and self.trn_y
(lines 61-65) and then further affect clnt_x
, clnt_y
(lines 204-205 when self.rule == 'iid'
). This means that clnt_x
, clnt_y
contain the normalized data samples.
transform = transforms.Compose([transforms.ToTensor(),
transforms.Normalize(mean=[0.491, 0.482, 0.447], std=[0.247, 0.243, 0.262])])
trnset = torchvision.datasets.CIFAR10(root='%s/Raw' %self.data_path,
train=True , download=True, transform=transform)
tstset = torchvision.datasets.CIFAR10(root='%s/Raw' %self.data_path,
train=False, download=True, transform=transform)
trn_load = torch.utils.data.DataLoader(trnset, batch_size=50000, shuffle=False, num_workers=1)
tst_load = torch.utils.data.DataLoader(tstset, batch_size=10000, shuffle=False, num_workers=1)
{Horizontal flip, Random cropping.} For each client, we train the model with the local data (i.e., trn_x
, trn_y
, lines 78-79 in utils_methods.py). Then we will generate the data loader with Dataset()
on trn_x
, trn_y
(line 79 in utils_general.py).
trn_gen = data.DataLoader(Dataset(trn_x, trn_y, train=True, dataset_name=dataset_name), batch_size=batch_size, shuffle=True)
Then turning back to utils_dataset.py, we do {Horizontal flip, Random cropping.} on the local data if train=True
. This means that we train the model with the {Horizontal flip, Random crop} data samples.
if self.train:
img = np.flip(img, axis=2).copy() if (np.random.rand() > .5) else img # Horizontal flip
if (np.random.rand() > .5):
# Random cropping
pad = 4
extended_img = np.zeros((3,32 + pad *2, 32 + pad *2)).astype(np.float32)
extended_img[:,pad:-pad,pad:-pad] = img
dim_1, dim_2 = np.random.randint(pad * 2 + 1, size=2)
img = extended_img[:,dim_1:dim_1+32,dim_2:dim_2+32]
Conclusion. In summary, the preprocess order is 1) normalize and 2) {random crop, random horizontal flip} in the code. In contrast, the typical order is 1) {random crop, random horizontal flip} and 2) normalized. To the best of our knowledge, the typical order matches our intuition (I guess it would be better?). At last, I think it will not affect the experimental conclusion, yet is interesting here.
Hoping for your reply.
Best regards.
To further clarify, here are the algorithm steps and their corresponding updates in the code.
local_param_list_curr
or local_grad_vector
corresponds to A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.