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

Move ag space to common #3192

Merged
merged 19 commits into from
May 5, 2023
Merged

Move ag space to common #3192

merged 19 commits into from
May 5, 2023

Conversation

yinweisu
Copy link
Collaborator

@yinweisu yinweisu commented May 3, 2023

Issue #, if available:

Description of changes:

  • Move ag space to common so it could be consumed by cloud module
  • Also making the way to use search space in our source code more consistent now. Now all usage would be 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.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@yinweisu yinweisu requested review from Innixma and shchur May 3, 2023 00:17
@@ -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
Copy link
Collaborator

@shchur shchur May 3, 2023

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()

Copy link
Collaborator Author

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

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, this is nice

Copy link
Collaborator Author

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

Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Collaborator Author

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))

@github-actions
Copy link

github-actions bot commented May 4, 2023

Job PR-3192-2a68a30 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-3192/2a68a30/index.html

Comment on lines 19 to 22
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."
)
Copy link
Contributor

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.

Copy link
Contributor

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 )

Copy link
Collaborator Author

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

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

core/src/autogluon/core/hpo/executors.py Outdated Show resolved Hide resolved
core/src/autogluon/core/hpo/ray_hpo.py Outdated Show resolved Hide resolved
core/src/autogluon/core/hpo/space_converter.py Outdated Show resolved Hide resolved
core/src/autogluon/core/searcher/local_grid_searcher.py Outdated Show resolved Hide resolved
Weisu Yin added 2 commits May 4, 2023 19:24
@github-actions
Copy link

github-actions bot commented May 4, 2023

Job PR-3192-a086431 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-3192/a086431/index.html

@github-actions
Copy link

github-actions bot commented May 5, 2023

Job PR-3192-f6b8d32 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-3192/f6b8d32/index.html

Copy link
Collaborator

@shchur shchur left a 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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

Copy link
Collaborator

@shchur shchur May 5, 2023

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.

core/src/autogluon/core/__init__.py Outdated Show resolved Hide resolved
Weisu Yin and others added 3 commits May 5, 2023 18:08
Co-authored-by: Oleksandr Shchur <oleks.shchur@gmail.com>
@github-actions
Copy link

github-actions bot commented May 5, 2023

Job PR-3192-4ed8edb is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-3192/4ed8edb/index.html

Copy link
Contributor

@Innixma Innixma left a 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
Copy link
Contributor

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 ...?

@yinweisu yinweisu merged commit 9bf29c0 into autogluon:master May 5, 2023
3 checks passed
@github-actions
Copy link

github-actions bot commented May 6, 2023

Job PR-3192-168ea98 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-3192/168ea98/index.html

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

Successfully merging this pull request may close these issues.

None yet

3 participants