Open EzyHow opened 7 months ago
Hi @EzyHow, have you added that summary(self.model, input_size=(1, 28, 28))
somewhere else? maybe also in the evaluation in server.py
? I wonder if torchsummary
is adding something to the state_dict
...
Flower Simulation Step by Step Pytorch Part-II
Kindly check this repository for detailed code: Testing Flower Simulation
In this repository, please go through the main.log files for three different scenarios given in output directory.
Hello,
I encountered the same issue and found a solution. I noticed the ndarrays_to_model
function in src/model_utils.py
. The relevant code is:
def ndarrays_to_model(model: torch.nn.ModuleList, params: List[np.ndarray]):
"""Set model weights from a list of NumPy ndarrays."""
params_dict = zip(model.state_dict().keys(), params)
state_dict = OrderedDict({k: torch.from_numpy(np.copy(v)) for k, v in params_dict})
model.load_state_dict(state_dict, strict=True)
Therefore, I changed
state_dict = OrderedDict({k: torch.Tensor(v) for k, v in params_dict})
to
state_dict = OrderedDict({k: torch.from_numpy(np.copy(v)) for k, v in params_dict})
in set_parameters function on client.py and evaluate_fn in server.py. Please also import numpy:
import numpy as np
I hope it will work for you as well.
This worked for me. How did you come to this solution? I can't find a reason for it to work.
This worked for me. How did you come to this solution? I can't find a reason for it to work.
I am not sure but see one function use torch directly and another one using numpy. Maybe because of internal functions are different.
Describe the bug
I was trying a example project of Flower Simulation (Flower Simulation Step by Step Pytorch - Part II). Everything went very well until I tried to change the model to resnet18 as given below:
If I add
summary(self.model, input_size=(1, 28, 28))
at the end of__init__()
method, everything works. But when I remove it, I get error:input_param = input_param[0]
IndexError: index 0 is out of bounds for dimension 0 with size 0
inevaluate_fn
of server.py:Steps/Code to Reproduce
Clone the repository from Flower Simulation Step by Step Pytorch Part-II and follow instructions to setup the environment.
Then change the model to resnet18 in model.py file as given below:
Following is the list of packages installed in the conda environment:
requirement.txt file
Expected Results
Following is the output when it runs successfully (by adding line
summary(self.model, input_size=(1, 28, 28))
) :{'history': History (loss, distributed): round 1: 6.738090056180954 round 2: 3.8934330970048903 History (loss, centralized): round 0: 366.1482033729553 round 1: 97.4027541577816 round 2: 52.76616382226348 History (metrics, centralized): {'accuracy': [(0, 0.1086), (1, 0.8021), (2, 0.8959)]}
Actual Results
When I remove line
summary(self.model, input_size=(1, 28, 28))
, I get following error: