mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-16 01:06:56 +08:00
add map_location to torch.load to make it work when cuda is unavailable (#782)
This commit is contained in:
@@ -257,7 +257,7 @@ class DNNModelPytorch(Model):
|
||||
self.scheduler.step(cur_loss_val)
|
||||
|
||||
# restore the optimal parameters after training
|
||||
self.dnn_model.load_state_dict(torch.load(save_path))
|
||||
self.dnn_model.load_state_dict(torch.load(save_path, map_location=self.device))
|
||||
if self.use_gpu:
|
||||
torch.cuda.empty_cache()
|
||||
|
||||
@@ -296,7 +296,7 @@ class DNNModelPytorch(Model):
|
||||
]
|
||||
_model_path = os.path.join(model_dir, _model_name)
|
||||
# Load model
|
||||
self.dnn_model.load_state_dict(torch.load(_model_path))
|
||||
self.dnn_model.load_state_dict(torch.load(_model_path, map_location=self.device))
|
||||
self.fitted = True
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user