Skip to content

Commit

Permalink
Don't save the optimizer as part of the best F1 model
Browse files Browse the repository at this point in the history
  • Loading branch information
AngledLuffa committed Nov 7, 2023
1 parent b1eca27 commit e1d2c70
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions stanza/models/coref/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,14 @@ def run(self, # pylint: disable=too-many-locals

return res

def save_weights(self, save_path=None):
def save_weights(self, save_path=None, save_optimizers=True):
""" Saves trainable models as state dicts. """
to_save: List[Tuple[str, Any]] = \
[(key, value) for key, value in self.trainable.items()
if self.config.bert_finetune or key != "bert"]
to_save.extend(self.optimizers.items())
to_save.extend(self.schedulers.items())
if save_optimizers:
to_save.extend(self.optimizers.items())
to_save.extend(self.schedulers.items())

time = datetime.strftime(datetime.now(), "%Y.%m.%d_%H.%M")
if save_path is None:
Expand Down Expand Up @@ -380,7 +381,7 @@ def train(self):
# TODO: choose a different default save dir
save_path = os.path.join(self.config.data_dir,
f"{self.config.section}.pt")
self.save_weights(save_path)
self.save_weights(save_path, save_optimizers=False)
# TODO: make save_each an option here
self.save_weights()

Expand Down

0 comments on commit e1d2c70

Please sign in to comment.