shall维 2022-07-20 16:15 采纳率: 0%
浏览 1755
已结题

Attempted to set the storage of a tensor on device "cpu" to a storage on different device "cuda:0".

问题遇到的现象和发生背景

pytorch 1.12.0
载入pt的时候,原本保存的是在cpu上面,现在我想载入cuda:0上,使用map_location报错

问题相关代码

net.load_state_dict(torch.load(model_weight_path, map_location=torch.device('cuda:0')))

运行结果及报错内容

RuntimeError: Attempted to set the storage of a tensor on device "cpu" to a storage on different device "cuda:0". This is no longer allowed; the devices must match.

我的解答思路和尝试过的方法

github上有人问出类似问题,但国内这边没有结果,pytorch官网也没给出load的特殊变化,无法定位根本问题

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 7月28日
    • 修改了问题 7月20日
    • 创建了问题 7月20日

    悬赏问题

    • ¥15 岛津txt格式文件转nirs格式
    • ¥15 石墨烯磁表面等离子体
    • ¥15 angular 项目无法启动
    • ¥15 安装wampserver,图标绿色,但是无法进入软件
    • ¥15 C++ MFC 标准库 加密解密解惑
    • ¥15 两条数据合并成一条数据
    • ¥15 Ubuntu虚拟机设置
    • ¥15 comsol三维模型中磁场为什么没有“速度(洛伦兹项)”这一选项
    • ¥15 electron 如何实现自定义安装界面
    • ¥15 关于#linux#的问题:子进程C运行“ls –l”命令,且显示“C运行ls-l命令”(语言-c语言)