Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CPU bug, overhaul model runner, and update to lightning >=2.0 #176

Merged
merged 18 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion casanovo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class Config:
train_from_scratch=bool,
save_model=bool,
model_save_folder_path=str,
save_weights_only=bool,
every_n_train_steps=int,
accelerator=str,
devices=int,
Expand Down
2 changes: 0 additions & 2 deletions casanovo/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ train_from_scratch: True
save_model: True
# Path to saved checkpoints
model_save_folder_path: ""
# Set to "False" to save the PyTorch model instance
save_weights_only: True
# Model validation and checkpointing frequency in training steps
every_n_train_steps: 50_000
# The hardware accelerator to use. Must be one of:
Expand Down
1 change: 1 addition & 0 deletions casanovo/denovo/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def __init__(
**kwargs: Dict,
):
super().__init__()
self.save_hyperparameters()

# Build the model.
if custom_encoder is not None:
Expand Down
21 changes: 3 additions & 18 deletions casanovo/denovo/model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def __init__(
pl.callbacks.ModelCheckpoint(
dirpath=config.model_save_folder_path,
save_top_k=-1,
save_weights_only=config.save_weights_only,
every_n_train_steps=config.every_n_train_steps,
)
]
Expand Down Expand Up @@ -247,23 +246,9 @@ def initialize_model(self, train: bool) -> None:
)
raise FileNotFoundError("Could not find the model weights file")

accelerator_class = str(type(self.trainer.accelerator))
if "CUDA" in accelerator_class:
map_location_device = "cuda"
elif "TPU" in accelerator_class:
map_location_device = "xla"
elif "HPU" in accelerator_class:
map_location_device = "hpu"
elif "IPU" in accelerator_class:
map_location_device = "ipu"
# FIXME: Handle the case for mps separately.
else:
map_location_device = "cpu"

self.model = Spec2Pep().load_from_checkpoint(
self.model = Spec2Pep.load_from_checkpoint(
self.model_filename,
map_location=torch.device(map_location_device),
**model_params,
wfondrie marked this conversation as resolved.
Show resolved Hide resolved
map_location=torch.empty(1).device, # Use the default device.
)

def initialize_data_module(
Expand All @@ -289,7 +274,7 @@ def initialize_data_module(
n_devices = self.trainer.num_devices
train_bs = self.config.train_batch_size // n_devices
eval_bs = self.config.predict_batch_size // n_devices
except AttributeError as err:
except AttributeError:
raise RuntimeError("Please use `initialize_trainer()` first.")

self.loaders = DeNovoDataModule(
Expand Down