pytorch_lightning.utilities.exceptions.MisconfigurationException: You requested GPUs: [1] But…

报错

pytorch_lightning.utilities.exceptions.MisconfigurationException: You requested GPUs: [1] But your machine only has: [0]

笔者的报错代码:

trainer = Trainer(
                        max_epochs= config.max_epochs,  
                        gpus= [fix_config.hparams.gpus],   
                        distributed_backend= fix_config.hparams.distributed_backend,  
                        benchmark= fix_config.hparams.benchmark,  
                        deterministic= fix_config.hparams.deterministic,  
                        logger=logger,
                        callbacks=[
                            early_stop_callback,
                            checkpoint_callback
                        ]
                      )

if __name__ == "__main__":
    # 创建解析器
    parser = ArgumentParser()  #编写命令行接口
	parser.add_argument("--gpus", default=1, type=int)  # 报错根源
	...

这是使用pytorch_lightning框架时遇到的错误。报错说,你想要的GPUs数量为[1],但是你的机器只有[0]个。

看到这个,相信大多数人的第一反应是:

  • 欸!报错说我没有gpu!
  • 接着去检查一下cuda
    在这里插入图片描述
    注:如果显示cuda为Flase,则表示你没有装cuda或者torch装的是cpu版本,需要重新装一下。笔者在这篇笔记里介绍了配置cuda与相应gpu版本的pytorch、torchvision、torchaudio的辛酸历程,可以作为参考。
  • cuda是可以用的!所以它为什么说我只有[0]呢?

笔者最开始也想不通,查阅了少得可怜的资料后,发现这个作者的猜想可能是对的:也就是说,gpu数量是从0开始计数的!

这样一来,重新翻译一下错误:你想要2个GPU,但是你的机器只有1个GPU。

解决办法

把上述代码中,gpu数量改为0

...
parser.add_argument("--gpus", default=0, type=int)

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
扎眼的阳光的头像扎眼的阳光普通用户
上一篇 2023年2月26日 上午11:29
下一篇 2023年2月26日 上午11:31

相关推荐