PacktPublishing / Deep-Reinforcement-Learning-Hands-On

Hands-on Deep Reinforcement Learning, published by Packt
MIT License
2.81k stars 1.28k forks source link

Cannot start cuda GPU mode in Jupyter Notebook. 03_atari_gan.py #93

Closed philippwulff closed 3 years ago

philippwulff commented 3 years ago

I am currently reading the chapter regarding the Atari-GAN-Project. This is the corresponding code: Deep-Reinforcement-Learning-Hands-On/Chapter03/03_atari_gan.py.

I wanted to follow along in a Jupyter Notebook and would basically just copy the code as I read it. However that leads to this error:

---------------------------------------------------------------------------
SystemExit                                Traceback (most recent call last)
<ipython-input-7-26c989fdc6f0> in <module>
      1 parser = argparse.ArgumentParser()
      2 parser.add_argument("--cuda", default=False, action="store_true", help="Enable cuda computation")
----> 3 args = parser.parse_args()
      4 
      5 device = torch.device("cuda" if args.cuda else "cpu")

~/anaconda3/envs/sumo_rl/lib/python3.8/argparse.py in parse_args(self, args, namespace)
   1769         if argv:
   1770             msg = _('unrecognized arguments: %s')
-> 1771             self.error(msg % ' '.join(argv))
   1772         return args
   1773 

~/anaconda3/envs/sumo_rl/lib/python3.8/argparse.py in error(self, message)
   2519         self.print_usage(_sys.stderr)
   2520         args = {'prog': self.prog, 'message': message}
-> 2521         self.exit(2, _('%(prog)s: error: %(message)s\n') % args)

~/anaconda3/envs/sumo_rl/lib/python3.8/argparse.py in exit(self, status, message)
   2506         if message:
   2507             self._print_message(message, _sys.stderr)
-> 2508         _sys.exit(status)
   2509 
   2510     def error(self, message):

SystemExit: 2

usage: ipykernel_launcher.py [-h] [--cuda]
ipykernel_launcher.py: error: unrecognized arguments: -f /home/philipp/.local/share/jupyter/runtime/kernel-46443f22-af17-4453-8fc7-bc0795cd4ab1.json

An exception has occurred, use %tb to see the full traceback.

SystemExit: 2

Do you know what this is about? Because running the pure Python script in the terminal worked for me just fine.

philippwulff commented 3 years ago

I am not sure, why one needs to check for cuda in the terminal in the first place and ended up with the following code.

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

torch.cuda.is_available() returns True for me, so I think, I am using my GPU =).