AshwinRJ / Federated-Learning-PyTorch

Implementation of Communication-Efficient Learning of Deep Networks from Decentralized Data
MIT License
1.26k stars 440 forks source link

AttributeError: 'Namespace' object has no attribute 'gpu_id' #22

Open askia318 opened 3 years ago

askia318 commented 3 years ago

Hello: I ran 'python src/federated_main.py --model=cnn --dataset=mnist --iid=0 --epochs=10 --gpu=1' But keep receiving error message: Traceback (most recent call last): File "src/federated_main.py", line 34, in if args.gpu_id: AttributeError: 'Namespace' object has no attribute 'gpu_id'

I am using Windows 10 and make sure I have GPU and GPU 1 in my task manager. Thanks

FrancescoNegri commented 3 years ago

Hi, gpu_id parameter does not exist anymore. In the args_parser() method it is said that the gpu parameter is set to None when you intend to use CPU, while you have to specify the id of your GPU if you intend to use that. However, this change is not reflected into the /src/federated_main.py file. You need to change the interested lines with the following:

if args.gpu:
        torch.cuda.set_device(args.gpu)
    device = 'cuda' if args.gpu else 'cpu'

Hopefully, @AshwinRJ will fix this, since is not a big deal :)

lalopark commented 2 years ago

@AshwinRJ Can you please fix this? :)

cgh2797 commented 2 years ago

if args.gpu: torch.cuda.set_device(args.gpu) device = 'cuda' if args.gpu else 'cpu'

If you have a gpu, change that part to the following

device = torch.device('cuda:0')

Sisivi commented 1 year ago

Hello: I ran 'python src/federated_main.py --model=cnn --dataset=mnist --iid=0 --epochs=10 --gpu=1' But keep receiving error message: Traceback (most recent call last): File "src/federated_main.py", line 34, in if args.gpu_id: AttributeError: 'Namespace' object has no attribute 'gpu_id'

I am using Windows 10 and make sure I have GPU and GPU 1 in my task manager.

Sisivi commented 1 year ago

if args.gpu: torch.cuda.set_device(args.gpu) device = 'cuda' if args.gpu else 'cpu'

You can modify the above lines of code to the following :

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

I successfully solved the error in this way. Hope this helps you!