optimizer.step() 出现 Expected all tensors to be on the same device

在加载预训练模型进行训练时,在optimizer.step()行会出现

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 

因为加载预训练模型时,也加载优化器,如下所示

optimizer.load_state_dict(torch.load(optimizer_path))

可以尝试把模型先移动到GPU上,然后在加载optimizer.load_state_dict(...)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
This paper proposes a novel nature-inspired algorithm called Ant Lion Optimizer (ALO). The ALO algorithm mimics the hunting mechanism of antlions in nature. Five main steps of hunting prey such as the random walk of ants, building traps, entrapment of ants in traps, catching preys, and re-building traps are implemented. The proposed algorithm is benchmarked in three phases. Firstly, a set of 19 mathematical functions is employed to test different characteristics of ALO. Secondly, three classical engineering problems (three-bar truss design, cantilever beam design, and gear train design) are solved by ALO. Finally, the shapes of two ship propellers are optimized by ALO as challenging constrained real problems. In the first two test phases, the ALO algorithm is compared with a variety of algorithms in the literature. The results of the test functions prove that the proposed algorithm is able to provide very competitive results in terms of improved exploration, local optima avoidance, exploitation, and convergence. The ALO algorithm also finds superior optimal designs for the majority of classical engineering problems employed, showing that this algorithm has merits in solving constrained problems with diverse search spaces. The optimal shapes obtained for the ship propellers demonstrate the applicability of the proposed algorithm in solving real problems with unknown search spaces as well. Note that the source codes of the proposed ALO algorithm are publicly available at http://www.alimirjalili.com/ALO.html.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值