python - 我应该在哪里更改代码以告诉 PyTorch 不要使用 GPU?
问题描述
如如何告诉 PyTorch 不使用 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)
推荐阅读
- ionic3 - 离子3和离子4的主要区别是什么
- javascript - 使用 Math.max 和 Math.min 从数组中删除最高和最低数字
- unity3d - 如何在Unity中获得2个四元数的相对旋转
- google-maps - 用户分享位置时如何获取国家、城市、州和地区信息等参数...?
- python - 从文本中删除正则表达式数字
- openlayers - 在 OpenLayers 手绘边界框中显示 WFS 返回的特征
- c++ - 如何正确传递成员函数作为参数
- javascript - 对象拟合和图像映射 css
- javascript - 修复从 excel 导出的 html 表中的行
- sql - SQL语句select子句中的列顺序优化