pytorch terminate called after throwing an instance of ‘c10::HIPError‘

今天在跑PPO程序的时候,出现了下面的错误:

terminate called after throwing an instance of 'c10::HIPError'
  what():  HIP error: hipErrorNoDevice
HIP kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing HIP_LAUNCH_BLOCKING=1.
Exception raised from deviceCount at /pytorch/aten/src/ATen/hip/impl/HIPGuardImplMasqueradingAsCUDA.h:102 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::string) + 0x42 (0x7f839e38ec72 in /root/anaconda3/lib/python3.7/site-packages/torch/lib/libc10.so)
frame #1: <unknown function> + 0x4b3eaa (0x7f82bb4c2eaa in /root/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_hip.so)
frame #2: torch::autograd::Engine::start_device_threads() + 0x21a (0x7f83082beafa in /root/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #3: <unknown function> + 0xf907 (0x7f83c61fe907 in /lib/x86_64-linux-gnu/libpthread.so.0)
......

我的torch版本是:

torch                              1.11.0+rocm4.5.2
cuda 10.2

解决方法

回退torch版本到1.5

pip install torch==1.5

然后就可以运行了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
根据提供的引用内容,当出现"terminate called after throwing an instance of 'c10::Error'"错误时,通常是由于在使用Libtorch或PyTorch时出现了问题。这个错误通常表示在代码中发生了一个内部断言失败。 解决这个问题的方法有以下几种: 1. 检查代码中是否存在错误:首先,你需要检查你的代码是否存在语法错误、逻辑错误或其他错误。确保你的代码没有任何问题,并且正确地使用了Libtorch或PyTorch的函数和方法。 2. 检查输入数据的格式:有时,这个错误可能是由于输入数据的格式不正确导致的。确保你的输入数据符合Libtorch或PyTorch的要求,并且正确地进行了预处理。 3. 检查Libtorch或PyTorch的版本:这个错误可能与你使用的Libtorch或PyTorch的版本有关。确保你使用的是最新版本,并且与你的代码兼容。 4. 查找相关文档和讨论:如果以上方法都没有解决你的问题,你可以查找Libtorch或PyTorch的官方文档、论坛或社区,寻找类似的问题和解决方案。你可以在这些资源中找到其他用户遇到类似问题的讨论和解决方法。 下面是一个例子,演示了如何使用Libtorch加载和运行一个简单的神经网络模型: ```cpp #include <torch/torch.h> int main() { // 定义一个简单的神经网络模型 struct Net : torch::nn::Module { Net() { fc1 = register_module("fc1", torch::nn::Linear(10, 5)); fc2 = register_module("fc2", torch::nn::Linear(5, 1)); } torch::Tensor forward(torch::Tensor x) { x = torch::relu(fc1->forward(x)); x = fc2->forward(x); return x; } torch::nn::Linear fc1{nullptr}, fc2{nullptr}; }; // 创建一个模型实例 Net net; // 创建一个随机输入张量 torch::Tensor input = torch::rand({1, 10}); // 运行模型 torch::Tensor output = net.forward(input); // 打印输出结果 std::cout << output << std::endl; return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

农民小飞侠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值