強化学習で作成した学習モデルを、別の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環境なので性能は落ちるかもしれないが、これでひとまず動くので評価はできそう。
参考