Skip to content

Commit

Permalink
fixed LoadTorchMLP CPU issue in torch_mlp.py (#12)
Browse files Browse the repository at this point in the history
* fixed LoadTorchMLP CPU issue in torch_mlp.py

* blackify

* updated run_tests.yml

* blackify w/ 24.x

* linting error fixed
  • Loading branch information
krishnbera authored Apr 7, 2024
1 parent b652d15 commit b1dd808
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lanfactory/trainers/torch_mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,13 @@ def __init__(self, model_file_path=None, network_config=None, input_dim=None):
input_shape=self.input_dim,
generative_model_id=None,
)
self.net.load_state_dict(torch.load(self.model_file_path))
# self.net.load_state_dict(torch.load(self.model_file_path))
if not torch.cuda.is_available():
self.net.load_state_dict(
torch.load(self.model_file_path, map_location=torch.device("cpu"))
)
else:
self.net.load_state_dict(torch.load(self.model_file_path))
self.net.to(self.dev)
self.net.eval()

Expand Down Expand Up @@ -768,7 +774,13 @@ def __init__(self, model_file_path=None, network_config=None, input_dim=None):
input_shape=self.input_dim,
generative_model_id=None,
)
self.net.load_state_dict(torch.load(self.model_file_path))
# self.net.load_state_dict(torch.load(self.model_file_path))
if not torch.cuda.is_available():
self.net.load_state_dict(
torch.load(self.model_file_path, map_location=torch.device("cpu"))
)
else:
self.net.load_state_dict(torch.load(self.model_file_path))
self.net.to(self.dev)

# AF-TODO: Seemingly LoadTorchMLPInfer is still not callable !
Expand Down

0 comments on commit b1dd808

Please sign in to comment.