-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Automatic seeding when using the LightningCLI #12804
Comments
I think it would be best that we have it as Are you interested in opening a PR with this change? |
I knew that seed_everything() had this logic already implemented, but I didn't know it returned the seed. This is of course a possibility. However, seed_everything() is called after the ArgumentParser parsing in the If I should re-use code, I could use Regarding the Optional flag in the argument, for most features that are deprecated, Lightning throws a LightningDeprecationWarning ( ".. is deprecated and will be removed in version 1.X ..."), which could be done here. So completely removing the Optional should be done at a later stage? Hopefully the textblock made sense. |
I didn't know about the seed range. Instead of having in the type from jsonargparse.typing import restricted_number_type
int32 = restricted_number_type('int32', int, [('>=', np.iinfo(np.int32).min), ('<=', np.iinfo(np.int32).max)]) Then in the
I think it would be fine to insert the value in the config after the parsing. I don't think there is a need for a deprecation warning for removing the |
I agree with @mauvilsa's thoughts. You can incorporate both his and my suggestions in the same PR.
Yes |
🚀 Feature
Currently the LightningCLI offers the argument
seed_everything_default: Optional[int] = None
.As it is good practice in scientific research to provide reproducible experiments, I propose to have an option to automatically set a randomly chosen seed at runtime. This then has the advantage that every experiment with the CLI is automatically reproducible as the seed is logged in the config.yaml via the
SafeConfigCallback
.Pitch
I propose to extend the signature to
seed_everything_default: Optional[Union[bool,int]] = False
, with the Optional being kept for backwards compatibility. Here the argument None is then equivalent to False.In this case, setting seed_everything_default to
True
, automatically generate's a seed that is logged to the argumentseed_everything
, which like before is then saved to the config.yaml by theSafeConfigCallback
.The code change could be as following:
to
This change also has the advantage that it prevents passing an int greater than pytorchs
int32.max
, which results, without raising a warning, in using a different random seed (same behaviour for numpy).If you enjoy Lightning, check out our other projects! ⚡
Metrics: Machine learning metrics for distributed, scalable PyTorch applications.
Lite: enables pure PyTorch users to scale their existing code on any kind of device while retaining full control over their own loops and optimization logic.
Flash: The fastest way to get a Lightning baseline! A collection of tasks for fast prototyping, baselining, fine-tuning, and solving problems with deep learning.
Bolts: Pretrained SOTA Deep Learning models, callbacks, and more for research and production with PyTorch Lightning and PyTorch.
Lightning Transformers: Flexible interface for high-performance research using SOTA Transformers leveraging Pytorch Lightning, Transformers, and Hydra.
cc @Borda @tchaton @justusschock @awaelchli @carmocca @mauvilsa
The text was updated successfully, but these errors were encountered: