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

Sacred logger #656

Closed

Conversation

expectopatronum
Copy link
Contributor

@expectopatronum expectopatronum commented Jan 2, 2020

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos, doc improvements)
  • Did you read the contributor guideline?
  • Did you make sure to update the docs? -> I updated the documentation directly in sacred.py. Please let me know if there is documentation somewhere else
  • Did you write any new necessary tests? -> I wrote similar tests as for other loggers and I am testing/using it in my own project successfully. Please let me know if I should write more tests.

What does this PR do?

Fixes #438.

Did you have fun?

Yes, and I learned a lot :)

Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

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

nice work, just add documentation and tests

pytorch_lightning/logging/sacred.py Outdated Show resolved Hide resolved
pytorch_lightning/logging/sacred.py Outdated Show resolved Hide resolved
pytorch_lightning/logging/sacred.py Show resolved Hide resolved
pytorch_lightning/logging/sacred.py Outdated Show resolved Hide resolved
@expectopatronum
Copy link
Contributor Author

@Borda It's just a draft pull request, I am aware of the things that need to be done ...

@CarloLucibello
Copy link

If not planned already in this PR, it would be nice for lightning to intercept the Sacred observer created by command line arguments as in

python script.py -F runs/     # FileObserver
python script.py -m dbruns  # MongodbObserver

Not sure how this would work though

@expectopatronum
Copy link
Contributor Author

@CarloLucibello I can think about it but I have only used MongoObserver so far. I also don't really know how the options -F and -m work. I think I'll first make it work with MongoObserver and later extend it (or someone else).

@expectopatronum
Copy link
Contributor Author

expectopatronum commented Jan 3, 2020

EDIT: I think I figured it out, should be easy to use hyperparams like in pytorch lightning and store them in a sacred way 🥳

I am currently a bit unsure how to implement log_hyperparams. As far as I can see, sacred takes care of more stuff than the other loggers that are currently implemented. It does not really allow logging hyperparamters/parameters, since it is designed to take care of that itself. I see a few options:

  1. Using sacred's config and it will take care of logging those parameters itself (but then I probably can't make use of pytorch lightnings grid search anymore)
  2. Use lightnings hparams, log each individually using log_scalar which is not the intended use of this method.
  3. Use lightning hparams, use some other functionality of sacred to log them, e.g. using observer.queued_event like [here](python train_midi_guitar_piano_classifier.py --experiment_name test --batch_size 16)

Maybe I am just making things too complicated but I'd appreciate it if someone had an idea 😅

I found some resources that might go in the right direction (maybe we can use lightning's hparams and pass them to run()):

@expectopatronum
Copy link
Contributor Author

Alright, after I finish implementing the test cases, I think this is ready for review. I have still a few questions left, maybe someone can answer them in the meantime:

  • Do I need to add a link in README.md?
  • Do I need to add somewhere else besides in sacred.py?
  • I always get "The Travis CI build failed" - the only error I can see in the logs is "ImportError: cannot import name 'PILLOW_VERSION'". This seems to be some issue with the installation of Pillow and it seems other current pull requests are also affected. Can/will this be fixed?

@Borda
Copy link
Member

Borda commented Jan 5, 2020

#661 (comment)

@expectopatronum
Copy link
Contributor Author

#661 (comment)

Ah, I am very sorry! Must have made some mistake, because I was actually searching for an issue before commenting, but I couldn't find it.

@expectopatronum
Copy link
Contributor Author

This pull request is ready imo, but Travis disappeared? I'd like to see if the tests run here before making it "Ready for review".

@Borda
Copy link
Member

Borda commented Jan 6, 2020

@expectopatronum can you move it from Draft to normal PR status so we can see CI build?

@expectopatronum expectopatronum marked this pull request as ready for review January 6, 2020 09:26
@williamFalcon
Copy link
Contributor

@expectopatronum awesome work! @Borda is this ready?

@expectopatronum
Copy link
Contributor Author

@williamFalcon Last time I checked the two tests were failing but I couldn't figure out (didn't have time) why. But it's probably a problem with my tests and not the code itself, because I am using it in my project and everything I expect, works. I don't see Travis now anymore, so I don't know what the status of the tests is.

@Borda
Copy link
Member

Borda commented Jan 14, 2020

@williamFalcon rebase is needed... and it seems that our master is failing so I would fix the master first...

@expectopatronum
Copy link
Contributor Author

Hi,
at this point I don't know how to proceed. I fixed the conflicts with the base branch as suggested by @Borda. You also mentioned a rebase, is this still necessary after fixing those issues? If yes, please let me know how this should be done.

My test case is working now locally, but Travis still fails with an error related to the TensorboardLogger.
tensorboardlogger

I previously implemented two test functions:

  • test_sacred_logger (which is fixed now)
  • test_sacred_pickle (doesn't work and I removed it for now)

The reason for removing it is that I saw that the wandb logger only tests very, very basic stuff.

Maybe you can clarify what functionality needs to be working & tested, since not all loggers seem to be tested the same way.

I am sorry for taking so long to finish this pull request but it's the first time I am working with Travis and at first I wasn't able to reproduce the tests locally (many more were failing bc. pytest didn't take care of the test requirements).

Best regards
Verena

@Borda
Copy link
Member

Borda commented Jan 16, 2020

@expectopatronum we have fixed master, could you rebase it, pls

@expectopatronum
Copy link
Contributor Author

@Borda I did a rebase (took me some time to figure out how that works). Is there a reason why you suggest a rebase rather than merging the changes? (from what I read while figuring out how rebase works, I got the impression merging would make more sense since I already pushed my commits to the remote).

Now it fails with the error ERROR: torchvision 0.4.2 has requirement torch==1.3.1, but you'll have torch 1.4.0 which is incompatible. I guess this is something that has to be fixed in your master?

@Borda
Copy link
Member

Borda commented Jan 18, 2020

If you do just merge, sometimes the PR diff shows master comits as part of this PR so it is not clear what is the new addition...
Another option is creating new brach from master with the same name, do cherry-picking from the past branch and push it force.. This usually has conflicts to resolve but it is harder to explain =)
Let me see, yesterday the Master was passing with torch 1.4 I check it just I ll get to computer...

@expectopatronum
Copy link
Contributor Author

expectopatronum commented Jan 18, 2020

If you do just merge, sometimes the PR diff shows master comits as part of this PR so it is not clear what is the new addition...

Thanks for the explanation, makes sense :)

@williamFalcon
Copy link
Contributor

@expectopatronum rebase master or add sacred to tests/requirements.txt?

Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

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

test the logger

@@ -0,0 +1,78 @@
"""
Log using `sacred <https://sacred.readthedocs.io/en/stable/index.html>'_
Copy link
Member

Choose a reason for hiding this comment

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

pls check the dos visage

def __init__(self, sacred_experiment):
"""Initialize a sacred logger.

:param sacred.experiment.Experiment sacred_experiment: Required. Experiment object with desired observers
Copy link
Member

Choose a reason for hiding this comment

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

use the updated docs formating
:param sacred_experiment (sacred.experiment.Experiment): ...

"""Verify that basic functionality of sacred logger works."""
tutils.reset_seed()

try:
Copy link
Member

Choose a reason for hiding this comment

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

this should not be here, the logger shall be tested

Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

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

tests shall not be tolerant of the missing package...

@Borda Borda mentioned this pull request Jan 23, 2020
return self._run_id

@rank_zero_only
def log_hyperparams(self, params):
Copy link
Contributor

@ozen ozen Jan 24, 2020

Choose a reason for hiding this comment

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

I just wanted to share my workflow for your consideration. I use Sacred for general configuration, then Ax for hyperparameter optimization. There is one Sacred experiment and one logger during the whole process, but trainer.fit() is called many times by Ax with different hyperparameters. Logging these in log_hyperparams somehow may be beneficial.

@Borda
Copy link
Member

Borda commented Jan 30, 2020

by #767 we will do all logger imports at the beginning of the test suit...

@Borda Borda added the feature Is an improvement or enhancement label Jan 31, 2020
@Borda Borda added this to the 0.6.1 milestone Jan 31, 2020
@williamFalcon
Copy link
Contributor

@expectopatronum hi! mind rebasing and getting the tests to pass? otherwise we should close this PR until it's ready to be worked on

@expectopatronum
Copy link
Contributor Author

Hi, I am sorry, I don't have the time right now and I'm also not using pytorch lightning for my experiments anymore. I hoped to finish this two weeks ago but there are too many changes for me to keep track.

@sheiksadique
Copy link

Is there still a chance if this PR making it through?

@williamFalcon
Copy link
Contributor

mind adding it to bolts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add sacred logger
6 participants