-
Notifications
You must be signed in to change notification settings - Fork 861
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
Move ag space to common #3192
Move ag space to common #3192
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
@@ -1,6 +1,7 @@ | |||
from .version import __version__ | |||
|
|||
from .utils.log_utils import _add_stream_handler, fix_logging_if_kaggle as __fix_logging_if_kaggle | |||
from .space import Space, Categorical, Real, Int, Bool |
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.
Would it be possible to avoid a breaking change by keeping the spaces available in autogluon.core
for 1 more release with a deprecation warning?
For example, using something like the following code in autogluon/core/__init__.py
import warnings
class DeprecatedSpacesWrapper:
def __getattr__(self, attr: str) -> Any:
import autogluon.common as ag
if attr in ["Space", "Categorical", "Real", "Int", "Bool"]:
warnings.warn(
"Accessing search spaces as `autogluon.core.space` is deprecated as of v0.8 and won't be supported "
"in the next release. Please use `autogluon.common.space` instead."
)
return getattr(ag.space, attr)
else:
raise AttributeError
space = DeprecatedSpacesWrapper()
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 for bringing it up. I think this is a good idea
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.
+1, this is nice
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 moved the warning to the init of any Space
object and imported Space
related object from common in core instead.
The method @shchur provided wouldn't work if user try to do things like from autogluon.core import Real
, which is possible currently. After the change, the above usage would also give proper warning message
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.
Would this result in a warning always being produced when a Space
is used (e.g., as a part of the presets), even if the user didn't use the deprecated API?
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.
Oh yea... This is tricky. Need to think about how to cover all cases
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.
OK. Added this inside core.space.py
, and this plus the wrapper @shchur provided should cover all cases and not affect import from common
# TODO: Remove this file for v1.0 as space is moved to common
import warnings
import sys
from typing import Any
this_module = sys.modules[__name__]
spaces = ["Space", "Categorical", "Real", "Int", "Bool"]
class DeprecatedSpaceWrapper:
def __init__(self, common_space) -> None:
self.comomn_space = common_space
def __call__(self, *args, **kwargs) -> Any:
import autogluon.common as ag
warnings.warn(
"Accessing search spaces through `autogluon.core` is deprecated as of v0.8 and won't be supported "
f"in the next release. Please use `from autogluon.common import {self.comomn_space}` instead."
)
return getattr(ag.space, self.comomn_space)(*args, **kwargs)
for s in spaces:
setattr(this_module, s, DeprecatedSpaceWrapper(s))
Job PR-3192-2a68a30 is done. |
core/src/autogluon/core/__init__.py
Outdated
warnings.warn( | ||
"Accessing search spaces as `autogluon.core.space` is deprecated as of v0.8 and won't be supported " | ||
"in the next release. Please use `autogluon.common.space` instead." | ||
) |
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.
Unsure best practice, but I wonder if we should have a class/function specifically that checks __version__
and errors if __version__ >= 0.9
, else warn, as some kind of standardized logic across the repo. Currently we track the deprecations in a bunch of different ways, and can miss removing code / logic that was previously deprecated.
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 wouldn't be something added in this PR, but something we may want to think about (@yinweisu @tonyhoo @gradientsky )
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.
+1. I agree we should think about a general way to handle deprecation
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.
We introduced the deprecated
decorator for methods, but I came across a few cases where it is not applicable (e.g., when an argument to a method is renamed).
A simple approach that would cover these edge cases is to always check all the occurrences of the string deprecate
within the codebase as a part of the release checklist. Though, this is definitely not elegant or scalable.
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.
Yea I saw the deprecated decorator and I'm working on some improvement on it.
Job PR-3192-a086431 is done. |
Job PR-3192-f6b8d32 is done. |
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.
LGTM on the timeseries
side, a few minor suggestions only.
@@ -6,7 +6,7 @@ | |||
import pandas as pd | |||
import pytest | |||
|
|||
import autogluon.core as ag | |||
from autogluon.common.space import Bool, Categorical, Int, Real, Space |
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 think the following code would still work and require fewer changes.
import autogluon.common as ag
...
ag.space.Int(1, 3)
....
I personally also like ag.space.Categorical
more than Categorical
since this way it's always clear that this is a search space. This also would help to avoid potential clashes, e.g., with torch.distributions.Categorical
.
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.
What you describe makes sense. We are trying to unify the usage of the search space in our code base and we think it's not a good practice to import the whole common module while all we are using are search spaces. Maybe a better alternative would be from autogluon.common import space
then space.XXX
. And when there are potential other search namespace, we can do from autogluon.common import space as ag_space
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 for the clarification, this makes sense.
Co-authored-by: Oleksandr Shchur <oleks.shchur@gmail.com>
Job PR-3192-4ed8edb is done. |
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.
LGTM! Had 1 comment
@@ -1,6 +1,7 @@ | |||
from .version import __version__ | |||
|
|||
from .utils.log_utils import _add_stream_handler, fix_logging_if_kaggle as __fix_logging_if_kaggle | |||
from .space import Space, Categorical, Real, Int, Bool |
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.
Shall we remove these imports here since we want users to do from autogluon.common.space import ...
?
Job PR-3192-168ea98 is done. |
Issue #, if available:
Description of changes:
from autogluon.common.space import XXX
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.