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

Issue1416 #1533

Merged
merged 13 commits into from
Jan 27, 2020
Merged

Issue1416 #1533

merged 13 commits into from
Jan 27, 2020

Conversation

ptrcklv
Copy link
Contributor

@ptrcklv ptrcklv commented Jan 17, 2020

Description of proposed changes

save() and load() method for Trainer to serialize the optimizer + trainer config (dependent on whether model has been fitted with that Trainer instance)

Related issue(s)

1416
Fixes # (issue)
1416

Test plan

test_trainer.py adapted save_load_test()

Checklist

Need help on these? Just ask!

  • I have read the CONTRIBUTING document.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have run tox -e complex and/or tox -e spark if appropriate.
  • All new and existing tests passed.

@codecov
Copy link

codecov bot commented Jan 17, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@a84e10b). Click here to learn what that means.
The diff coverage is 69.23%.

@@            Coverage Diff            @@
##             master    #1533   +/-   ##
=========================================
  Coverage          ?   97.11%           
=========================================
  Files             ?       55           
  Lines             ?     2077           
  Branches          ?      341           
=========================================
  Hits              ?     2017           
  Misses            ?       31           
  Partials          ?       29
Impacted Files Coverage Δ
snorkel/labeling/lf/nlp.py 100% <100%> (ø)
snorkel/preprocess/nlp.py 86.66% <33.33%> (ø)
snorkel/classification/training/trainer.py 89.83% <75%> (ø)

@ptrcklv ptrcklv marked this pull request as ready for review January 17, 2020 11:04
@henryre
Copy link
Member

henryre commented Jan 19, 2020

@ptrcklv thanks for taking this on! One of the maintainers will take a look soon!

Copy link
Member

@vincentschen vincentschen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ptrcklv — thanks so much for this contribution and great documentation!!

left a few formatting comments / requests for additional docs. please re-request a review once you've made changes!

Comment on lines 241 to 242
trainer1.optimizer.state_dict()["state"][k]["exp_avg"],
trainer2.optimizer.state_dict()["state"][k]["exp_avg"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we only checking equivalence of these fields? could we check the entire state_dict's values?

@@ -216,6 +216,35 @@ def test_warmup(self):
trainer.fit(model, [dataloaders[0]])
self.assertEqual(trainer.warmup_steps, 1)

def test_save_load(self):
fd, checkpoint_path = tempfile.mkstemp()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we put this in a try/except/finally or use a context with tempfile.NamedTemporaryFile() as f: to ensure proper cleanup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put a NamedTemporaryFile, however, the tempfile.mkstemp() I copied from test_save_load() from test_multitask_classifier.py. Maybe you want to update it there, too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it — yes, we likely need to clean up other parts of the codebase as well. :)


Parameters
----------
trainer_path :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -216,6 +216,35 @@ def test_warmup(self):
trainer.fit(model, [dataloaders[0]])
self.assertEqual(trainer.warmup_steps, 1)

def test_save_load(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tested this with resuming training for a saved checkpoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I have included it in the test now

Comment on lines 547 to 551
trainer_path :
The path to the saved trainer config to be loaded
model :
MultitaskClassifier for which the optimizer has been set. Parameters of optimizer must fit to model parameters. This model
shall be the model which was fit by the stored Trainer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no : for parameters (see above)

snorkel/classification/training/trainer.py Show resolved Hide resolved
Copy link
Member

@vincentschen vincentschen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fantastic, lgtm! thank you for the contribution!!

@vincentschen vincentschen merged commit e878d48 into snorkel-team:master Jan 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants