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

First run problem #5

Open
gestefane opened this issue Dec 6, 2022 · 1 comment
Open

First run problem #5

gestefane opened this issue Dec 6, 2022 · 1 comment

Comments

@gestefane
Copy link

gestefane commented Dec 6, 2022

Hello!
I think it maybe a little problem around understanding overall execution process.
I follow instructions to prepare and run data on README file.
I am using the parameters:
export DATASET=mnist
export SEED=10
export K=5
export B=4
export NET=2nn
export T=5
export E=5

and receiving this result:

python3 main.py --dataset $DATASET --clients_per_round $K --num_round $T --num_epoch $E --batch_size $B --seed $SEED --model $NET   --noaverage --noprint
>>> Arguments:
	             algo : fedavg4
	       batch_size : 4
	clients_per_round : 5
	          dataset : mnist
	           device : 0
	              dis : 
	       eval_every : 5
	              gpu : False
	      input_shape : 784
	               lr : 0.1
	            model : 2nn
	        noaverage : True
	          noprint : True
	        num_class : 10
	        num_epoch : 5
	        num_round : 5
	             seed : 10
	               wd : 0.001
>>> Read data from:
     ./data/mnist/data/train/all_data_0_equal_niid.pkl
     ./data/mnist/data/train/all_data_1_random_niid.pkl
     ./data/mnist/data/test/all_data_0_equal_niid.pkl
     ./data/mnist/data/test/all_data_1_random_niid.pkl
>>> Don not use gpu
>>> Model statistic per layer
TwoHiddenLayerFc(
  198.8 KMac, 100.000% MACs, 
  (fc1): Linear(156.8 KMac, 78.873% MACs, in_features=784, out_features=200, bias=True)
  (fc2): Linear(40.0 KMac, 20.121% MACs, in_features=200, out_features=200, bias=True)
  (fc3): Linear(2.0 KMac, 1.006% MACs, in_features=200, out_features=10, bias=True)
)
>>> Activate a worker for training
>>> Initialize 100 clients in total
>>> Weigh updates by sample numbers
>>> Select 5 clients per round 

Traceback (most recent call last):
  File "/home/user/fedavgpy/main.py", line 131, in <module>
    main()
  File "/home/user/fedavgpy/main.py", line 127, in main
    trainer.train()
  File "/home/user/fedavgpy/src/trainers/fedavg4.py", line 35, in train
    self.test_latest_model_on_traindata(round_i)
  File "/home/user/fedavgpy/src/trainers/base.py", line 155, in test_latest_model_on_traindata
    stats_from_train_data = self.local_test(use_eval_data=False)
  File "/home/user/fedavgpy/src/trainers/base.py", line 211, in local_test
    tot_correct, num_sample, loss = c.local_test(use_eval_data=use_eval_data)
  File "/home/user/fedavgpy/src/models/client.py", line 89, in local_test
    tot_correct, loss = self.worker.local_test(dataloader)
  File "/home/user/fedavgpy/src/models/worker.py", line 131, in local_test
    pred = self.model(x)
  File "/home/user/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/user/fedavgpy/src/models/model.py", line 25, in forward
    out = F.relu(self.fc1(x))
  File "/home/user/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/user/.local/lib/python3.10/site-packages/torch/nn/modules/linear.py", line 114, in forward
    return F.linear(input, self.weight, self.bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (112x28 and 784x200)

@lx10077
Copy link
Owner

lx10077 commented Dec 6, 2022

The solution is to flatten the input data before we feed data into networks.

For MNIST, the data batch is of the size [batch_size, 1, 28, 28], while the input dimension for the used networks is 784.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants