【问题标题】:where should I change the code to tell PyTorch not to use the GPU?我应该在哪里更改代码以告诉 PyTorch 不要使用 GPU?
【发布时间】:2021-06-24 02:19:01
【问题描述】:

How to tell PyTorch to not use the GPU? 中所述,为了告诉 PyTorch 不使用 GPU,您应该更改 PyTorch 代码中的几行代码。 我应该在哪里进行更改? 需要修改的代码行在哪里? 我试图找到它,但找不到...

【问题讨论】:

    标签: python pytorch


    【解决方案1】:

    在任何张量或 pytorch 模块上使用方法 .cpu() 将组件传输到 cpu 以便使用它进行计算。

    另一个方向是使用方法.to("cpu")。或者,您可以将“cpu”更改为其他设备的名称,例如“cuda”。

    例子:

    一)

    model = MyModel().cpu()  # move the model to the cpu
    x = data.cpu()  # move the input to the cpu
    y = model(x)
    

    b)

    model = MyModel().to('cpu')  # move the model to the cpu
    x = data.to('cpu')  # move the input to the cpu
    y = model(x)
    

    【讨论】:

      猜你喜欢
      • 2021-06-08
      • 2015-07-25
      • 2021-11-29
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多