-
-
Notifications
You must be signed in to change notification settings - Fork 647
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
Issue warning on outdated API usage #1603
Conversation
This pull request introduces 2 alerts when merging 4c73fab into 901fb39 - view on LGTM.com new alerts:
|
I approved #1581, can you land and rebase? I don't want to review it again in this diff. |
Thanks! Yea, once it's ready I will change the state from DRAFT to Ready to review :) |
This pull request introduces 2 alerts when merging 6f2cca1 into c6397d2 - view on LGTM.com new alerts:
|
rebase, also updated the issue description with what the warnings looks like for outdated Plugin. |
This pull request introduces 2 alerts when merging 78913fe into c6397d2 - view on LGTM.com new alerts:
|
This pull request introduces 2 alerts when merging 12049bd into c6397d2 - view on LGTM.com new alerts:
|
This pull request introduces 2 alerts when merging fbdbfc4 into c6397d2 - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging d2a4213 into 43cc401 - view on LGTM.com new alerts:
|
hydra/core/plugins.py
Outdated
|
||
param_keys = signature(plugin.setup).parameters.keys() | ||
|
||
if "config_loader" in param_keys: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More directly is better:
if "hydra_context" not in param_keys:
# backward compatibility
else:
# new flow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
tests/test_hydra_context_warnings.py
Outdated
def test_setup_plugin( | ||
config_loader: Optional[ConfigLoader], | ||
hydra_context: Optional[HydraContext], | ||
setup_method: Any, | ||
expected: Any, | ||
) -> None: | ||
plugin = Mock(spec=Sweeper) | ||
plugin.setup = setup_method | ||
config = Mock(spec=DictConfig) | ||
task_function = Mock(spec=TaskFunction) | ||
msg = ( | ||
"\n" | ||
"\tPlugin's setup() signature has changed in Hydra 1.1.\n" | ||
"\tSupport for the old style will be removed in Hydra 1.2.\n" | ||
"\tFor more info, check https://github.com/facebookresearch/hydra/pull/1581.\n" | ||
) | ||
if expected is None: | ||
plugins._setup_plugin( | ||
plugin, config, task_function, config_loader, hydra_context | ||
) | ||
elif isinstance(expected, UserWarning): | ||
with warns(expected_warning=UserWarning, match=re.escape(msg)): | ||
plugins._setup_plugin( | ||
plugin, task_function, config, config_loader, hydra_context | ||
) | ||
else: | ||
with raises(expected): | ||
plugins._setup_plugin( | ||
plugin, config, task_function, config_loader, hydra_context | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems very elaborate.
Why not test it more directly by using Plugins.instantiate_sweeper/instantiate_launcher
methods on a deliberately incompatible plugin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests updated!
This pull request introduces 1 alert when merging 2d4caf0 into ed267e0 - view on LGTM.com new alerts:
|
hydra/core/plugins.py
Outdated
if hydra_context is None: | ||
assert config_loader is not None | ||
hydra_context = HydraContext( | ||
config_loader=config_loader, callbacks=Callbacks() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when is hydra_context none here?
If this is just to support tests, have them instantiate the HydraContext.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hydra_context
could be None
in the case of an outdated Sweeper tried to instantiate an update to date Launcher.
I've added a comment here.
u$ python /Users/jieru/workspace/hydra-fork/hydra/plugins/hydra_ax_sweeper/example/banana.py -m
/Users/jieru/workspace/hydra-fork/hydra/hydra/core/plugins.py:131: UserWarning:
Plugin's setup() signature has changed in Hydra 1.1.
Support for the old style will be removed in Hydra 1.2.
For more info, check https://github.com/facebookresearch/hydra/pull/1581.
[2021-05-06 10:38:30,027][HYDRA] AxSweeper is optimizing the following parameters:
banana.x: range=[-5, 5]
banana.y: range=[-5.0, 10.1]
[INFO 05-06 10:38:30] ax.service.utils.instantiation: Inferred value type of ParameterType.INT for parameter banana.x. If that is not the expected value type, you can explicity specify 'value_type' ('int', 'float', 'bool' or 'str') in parameter dict.
[INFO 05-06 10:38:30] ax.service.utils.instantiation: Inferred value type of ParameterType.FLOAT for parameter banana.y. If that is not the expected value type, you can explicity specify 'value_type' ('int', 'float', 'bool' or 'str') in parameter dict.
[INFO 05-06 10:38:30] ax.modelbridge.dispatch_utils: Using Bayesian Optimization generation strategy: GenerationStrategy(name='Sobol+GPEI', steps=[Sobol for 5 trials, GPEI for subsequent trials]). Iterations after 5 will take longer to generate due to model-fitting.
[2021-05-06 10:38:30,130][HYDRA] AxSweeper is launching 5 jobs
Traceback (most recent call last):
File "/Users/jieru/workspace/hydra-fork/hydra/hydra/_internal/utils.py", line 212, in run_and_report
return func()
File "/Users/jieru/workspace/hydra-fork/hydra/hydra/_internal/utils.py", line 379, in <lambda>
lambda: hydra.multirun(
File "/Users/jieru/workspace/hydra-fork/hydra/hydra/_internal/hydra.py", line 139, in multirun
ret = sweeper.sweep(arguments=task_overrides)
File "/Users/jieru/opt/anaconda3/envs/pytest38/lib/python3.8/site-packages/hydra_plugins/hydra_ax_sweeper/ax_sweeper.py", line 29, in sweep
return self.sweeper.sweep(arguments)
File "/Users/jieru/opt/anaconda3/envs/pytest38/lib/python3.8/site-packages/hydra_plugins/hydra_ax_sweeper/_core.py", line 180, in sweep
self.sweep_over_batches(
File "/Users/jieru/opt/anaconda3/envs/pytest38/lib/python3.8/site-packages/hydra_plugins/hydra_ax_sweeper/_core.py", line 217, in sweep_over_batches
rets = self.launcher.launch(
File "/Users/jieru/workspace/hydra-fork/hydra/hydra/_internal/core_plugins/basic_launcher.py", line 55, in launch
assert self.hydra_context is not None
AssertionError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha.
This pull request introduces 1 alert when merging aa98b80 into cf23e4d - view on LGTM.com new alerts:
|
hydra/core/utils.py
Outdated
run_job's signature has changed in Hydra 1.1. | ||
Support for the old style will be removed in Hydra 1.2. | ||
For more info, check https://github.com/facebookresearch/hydra/pull/1581. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run_job's signature has changed in Hydra 1.1. | |
Support for the old style will be removed in Hydra 1.2. | |
For more info, check https://github.com/facebookresearch/hydra/pull/1581. | |
run_job's signature has changed in Hydra 1.1. Please pass hydra_context. | |
Support for the old style will be removed in Hydra 1.2. | |
For more info, check https://github.com/facebookresearch/hydra/pull/1581. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The info link #1581 should contain some TLDR for what people should do to migrate. Sending them to read a design doc does not feel right.
This can also include links to the updated example plugins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I've updated the PR's description to provide more info
#1581
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pro tip:
If you are linking to a specific line in master, that link will become wrong when the file changes later.
You can fix it by linking to a specific revision: while you are on the link to master, hit y
and the browser link will change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!! I've fixed the links in #1581
This pull request introduces 1 alert when merging 8a5da04 into cf23e4d - view on LGTM.com new alerts:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why, but somehow I can't reply to your other comments.
hydra/core/plugins.py
Outdated
) | ||
else: | ||
if hydra_context is None: | ||
# hydra_context could be None when an incompatible Sweeper tried to compatible Launcher |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# hydra_context could be None when an incompatible Sweeper tried to compatible Launcher | |
# hydra_context could be None when an incompatible Sweeper tried to use a compatible Launcher |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
This pull request introduces 1 alert when merging b4c277f into cf23e4d - view on LGTM.com new alerts:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. see last nit.
tests/test_hydra_context_warnings.py
Outdated
""" | ||
run_job's signature has changed in Hydra 1.1. Please pass in hydra_context. | ||
Support for the old style will be removed in Hydra 1.2. | ||
For more info, check https://github.com/facebookresearch/hydra/pull/1581. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why is this not aligned? (it's not the only case).
Look at how I use dedent in other places.
""" | |
run_job's signature has changed in Hydra 1.1. Please pass in hydra_context. | |
Support for the old style will be removed in Hydra 1.2. | |
For more info, check https://github.com/facebookresearch/hydra/pull/1581. | |
""" | |
""" | |
run_job's signature has changed in Hydra 1.1. Please pass in hydra_context. | |
Support for the old style will be removed in Hydra 1.2. | |
For more info, check https://github.com/facebookresearch/hydra/pull/1581. | |
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
black
auto-formatted like that. I moved the """
to the end of the string which seems to have stopped black
from moving the quotes around :)
This pull request introduces 1 alert when merging b9508c6 into cf23e4d - view on LGTM.com new alerts:
|
Closes #1589, #1604
running with an outdated sweeper
Running with outdated Launcher