3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

強化学習で作成した学習モデルを、別のPC環境で実行しようとしたときにエラー(`RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False...`)

Posted at

強化学習で作成した学習モデルを、別のPC環境で実行しようとしたときにエラー(RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False...

$ python do.py
...
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
...

エラーメッセージ記載の通り、
please use torch.load with map_location=torch.device('cpu') すればOK

before

def torch_load(file_name):
    with open(file_name, 'rb') as f:
        return torch.load(f)

after

def torch_load(file_name):
    with open(file_name, 'rb') as f:
        return torch.load(f, torch.device('cpu')) 

CPU環境なので性能は落ちるかもしれないが、これでひとまず動くので評価はできそう。

参考

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?