【发布时间】:2021-06-24 02:19:01
【问题描述】:
如How to tell PyTorch to not use the GPU? 中所述,为了告诉 PyTorch 不使用 GPU,您应该更改 PyTorch 代码中的几行代码。 我应该在哪里进行更改? 需要修改的代码行在哪里? 我试图找到它,但找不到...
【问题讨论】:
如How to tell PyTorch to not use the GPU? 中所述,为了告诉 PyTorch 不使用 GPU,您应该更改 PyTorch 代码中的几行代码。 我应该在哪里进行更改? 需要修改的代码行在哪里? 我试图找到它,但找不到...
【问题讨论】:
在任何张量或 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)
【讨论】: