美文网首页
(9)指定GPU

(9)指定GPU

作者: 顽皮的石头7788121 | 来源:发表于2018-12-04 10:06 被阅读0次

PyTorch默认使用从0开始的GPU,如果GPU0正在运行程序,需要指定其他GPU。

    有如下两种方法来指定需要使用的GPU。

    1. 类似tensorflow指定GPU的方式,使用CUDA_VISIBLE_DEVICES。

            1.1 直接终端中设定:

            CUDA_VISIBLE_DEVICES=1python my_script.py

    1.2 python代码中设定:

            importosos.environ["CUDA_VISIBLE_DEVICES"] ="2"

            见网址:http://www.cnblogs.com/darkknightzh/p/6591923.html

    2. 使用函数set_device

        import torch

        torch.cuda.set_device(id)

        该函数见 pytorch-master\torch\cuda\__init__.py。

        不过官方建议使用CUDA_VISIBLE_DEVICES,不建议使用set_device 函数。

相关文章

网友评论

      本文标题:(9)指定GPU

      本文链接:https://www.haomeiwen.com/subject/ictmcqtx.html