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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecate module #1416

Merged
merged 17 commits into from
Aug 30, 2023
Merged

Conversation

Louis-Dupont
Copy link
Contributor

@Louis-Dupont Louis-Dupont commented Aug 24, 2023

Breaking change fail will be fixed in #1420
Please review the PR above first, to fix breacking change test 馃檹

Motivation

Have a nicer decorator to deprecate functions. The idea is to easily deprecate any function, with nice logs

Answers to Ofri

I. Usage of warning vs logger.warning

With warnings, we get

  1. a nice DeprecationWarning built-in, which is standard in python, and which is also easy to catch (see tests)
  2. Option to show the line that raised the warning fully_configured_deprecated_func() in the example below. This is thanks to stacklevel in warnings.warn(message, DeprecationWarning, stacklevel=2)
/Users/Louis.Dupont/PycharmProjects/super-gradients/tests/unit_tests/deprecate.py:19: DeprecationWarning: Function `__main__.fully_configured_deprecated_func` is deprecated since version `3.2.0` and will be removed in version `4.0.0`.
Reason: Replaced for optimization.
Please update your code:
  [-] from `module` import `fully_configured_deprecated_func`
  [+] from `module` import `new_func`
  fully_configured_deprecated_func()

I think using this is cleaner than logger.warning, what do you think ?

II. Making sure that removed_in_v is enforced

After discussion with @shaydeci and @ofrimasad, we decided to enforce removed_in_v. Basically, using a function that is not supported (version > removed_in_v) will lead to an ImportError with a clear error message explaining how to fix it.

Should be something like

ImportError('Function `some_module.get_local_rank` was deprecated and has been removed. Deprecated since version `3.2.0`
        and will be removed in version `4.0.0`. Reason: `Replaced for optimization`.
        Please update your code:
          [-] from `some_module` import `get_local_rank`
          [+] from `new.module.path` import `new_get_local_rank`.')

I think it is eventually a nice way to remove a function and force people to move to the new one, while giving them a clear tip on how to do

Copy link
Collaborator

@ofrimasad ofrimasad left a comment

Choose a reason for hiding this comment

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

about the warning - ok
about the assert on version, that is incorrect.
before version release, we bump the __version__, at wich point the tests will fail.

src/super_gradients/common/deprecate.py Outdated Show resolved Hide resolved
@Louis-Dupont
Copy link
Contributor Author

Louis-Dupont commented Aug 27, 2023

Added

  • Test to make sure it works well with classes
  • Check the version + test
  • rename to deprecated

Question

The function was renamed to deprecated. Should the module also be renamed deprecated or still deprecate ?

about the assert on version, that is incorrect.
before version release, we bump the version, at wich point the tests will fail.

I changed the code accordingly, and I tested it - see added tests here a210e0a
But I am a bit uneasy with it. If, for some reason, we don't remove the deprecated function when we should, then it would crash all the code and make SG unusable.
This would be a major issue. Yes we should catch it because we bump the version before testing, but I'm still a bit afraid it would somehow happen.

I think this type of exception should be directly implemented/checked in the test, and not to the user code (similarly to what we did with breaking changes)

src/super_gradients/common/deprecate.py Outdated Show resolved Hide resolved
src/super_gradients/common/deprecate.py Outdated Show resolved Hide resolved
BloodAxe
BloodAxe previously approved these changes Aug 29, 2023
Copy link
Collaborator

@BloodAxe BloodAxe left a comment

Choose a reason for hiding this comment

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

LGTM
Left a minor comment on argument names. Not a big deal tho
Up to you whether to address or ignore if you disagree ;)

ofrimasad
ofrimasad previously approved these changes Aug 29, 2023
Copy link
Collaborator

@ofrimasad ofrimasad left a comment

Choose a reason for hiding this comment

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

LGTM
consider @BloodAxe comments about param names

@Louis-Dupont Louis-Dupont dismissed stale reviews from ofrimasad and BloodAxe via 65fc918 August 30, 2023 08:02
Copy link
Collaborator

@BloodAxe BloodAxe left a comment

Choose a reason for hiding this comment

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

LGTM

@ofrimasad ofrimasad merged commit 32fc041 into master Aug 30, 2023
6 of 7 checks passed
@ofrimasad ofrimasad deleted the hotfix/SG-000-add_deprecate_func_decorator branch August 30, 2023 11:03
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

4 participants