You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

桌面端PyTorch 1.13.0加载.pth模型遇Legacy格式不支持错误

PyTorch模型加载错误排查与解决

我在torch==1.13.0环境中尝试加载sad_player2_model.pth格式的序列化PyTorch模型,但持续遇到以下错误:

RuntimeError: Legacy model format is not supported on mobile.
python: /usr/include/boost/fiber/condition_variable.hpp:56: boost::fibers::condition_variable_any::~condition_variable_any(): Assertion `wait_queue_.empty()' failed.
Aborted (core dumped)

据我所知这些模型并非使用PyTorch移动版训练,将文件重命名为.pt也无法解决问题。提取该归档文件后,模型包含如下内容:
提取后的.pth文件内容


可行解决思路

  • 重新导出兼容格式:若能获取模型训练代码,用torch==1.13.0重新导出模型,优先使用torch.save(model.state_dict(), "new_model.pt")或TorchScript格式torch.jit.save(torch.jit.trace(model, example_input), "new_model.pt"),规避旧版遗留格式问题。
  • 跨版本转格式:尝试用更低版本PyTorch(如1.8.x及更早)加载该模型,再重新保存为兼容1.13.0的格式。
  • 排查移动API调用:检查加载代码中是否误引入PyTorch Mobile相关逻辑(如torch.utils.mobile_optimizer),若有则移除后重试。

内容的提问来源于stack exchange,提问作者Purple

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 01:40:29