_once_ feature and documentation to instantiate #3063
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Sometimes we want to ensure a subtree of the config is instantiated only ONCE. Making unnecessary copies, in these cases, can hammer resources or even break code.
Take this example:
Instantiating this config will, in fact, instantiate three separate instances of 'dataset', which is undesirable, because each one takes up memory. Even worse, calling instantiate a second time will create 3 more instances!
Pitch
I'd like this to be a built in feature of hydra (requiring just a minor version bump), using this syntax instead:
This change is fully backwards compatible, and this PR passes all tests. It can be introduced initially beta in a patch release, or in a minor release.
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
No special set up. Several tests added to tests/instantiate.py that verify correct behaivior. No existing tests fail. No existing behavior changes.
Related Issues and PRs
See feature request here: #3062