-
Notifications
You must be signed in to change notification settings - Fork 360
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
chore: deprecation warnings for determined.common.experimental
imports
#7103
Conversation
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 like this implementation! And thanks for chasing down the parts of the CLI where the old path was used.
@@ -5,3 +5,13 @@ | |||
from determined.common.experimental.experiment import ExperimentReference | |||
from determined.common.experimental.trial import TrialReference, TrialSortBy, TrialOrderBy | |||
from determined.common.experimental.model import Model, ModelOrderBy, ModelSortBy, ModelVersion | |||
|
|||
import warnings |
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.
How did this get by isort
? Though warnings
is only needed in the subsequent warnings.warn
call, I don't think it's necessary to delay its import until its use.
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 can move it. Not sure, maybe there are exceptional cases for __init__
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.
__init__
is ignored by isort because the way we do our code layout sometimes requires explicit dependency resolution in __init__.py
files... meaning it's often not safe to let isort touch them.
import warnings | ||
|
||
warnings.warn( | ||
"The 'determined.common.experimental' module is deprecated and will be removed " |
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.
@rb-determined-ai: could you please comment on this message and expected plan in particular? I continue to add code to the SDK, which itself is entirely contained within determined.common.experimental
. I know (hope?) that the code won't live in experimental forever, but maybe it's more accurate to say that (currently) calls into determined.common.experimental
from outside are deprecated?
Or should I also add "migrate the SDK away from d.c.e" to the roadmap for the project?
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.
determined.common
is 100% internal and no end-users should ever use it, ever.
There is a boring legacy reason why this code was originally where it was.
The reason I didn't deprecate it the symbols in d.c.e when I added the experimental.client
module was because I expected that we'd be promoting the python sdk out of experiment like... years ago... so I figured I'd do all the breaking changes in one go, no need for waves of deprecation.
In reality, the python sdk has always been half-baked until we put real engineering resources on it this quarter, so it wasn't ever promoted.
My conclusion is: external users running really old code might be using d.c.e and it's worth having a warning.
Internal users can write in d.c.e today and move it tomorrow without any warning and that's fine. External users of today should be accessing all these symbols from det.experimental.client
and in the future from det.client
regardless of where new symbols are added.
) | ||
import warnings | ||
|
||
with warnings.catch_warnings(record=True): |
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 do you think of adding a category=FutureWarning
to the function call?
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 see that on my warnings module? The init on the version I have is as such:
class catch_warnings(object):
"""A context manager that copies and restores the warnings filter upon
exiting the context.
The 'record' argument specifies whether warnings should be captured by a
custom implementation of warnings.showwarning() and be appended to a list
returned by the context manager. Otherwise None is returned by the context
manager. The objects appended to the list are arguments whose attributes
mirror the arguments to showwarning().
The 'module' argument is to specify an alternative module to the module
named 'warnings' and imported under that name. This argument is only useful
when testing the warnings module itself.
"""
def __init__(self, *, record=False, module=None):
"""Specify whether to record warnings and if an alternative module
should be used other than sys.modules['warnings'].
For compatibility with Python 3.0, please consider all arguments to be
keyword-only.
"""
self._record = record
self._module = sys.modules['warnings'] if module is None else module
self._entered = False
When I try:
with warnings.catch_warnings(category=FutureWarning, record=True):
I get this error:
>>> from determined.experimental import Checkpoint
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/taylor/git/determined/harness/determined/experimental/__init__.py", line 3, in <module>
with warnings.catch_warnings(category=FutureWarning, record=True):
TypeError: __init__() got an unexpected keyword argument 'category'
I like the idea but I'm not seeing how it could actually be used
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.
Aw, dang.
Changed in version 3.11: Added the action, category, lineno, and append parameters.
"in future versions. Please import from 'determined.experimental' instead. " | ||
"Example: `from determined.experimental import Determined`", | ||
FutureWarning, | ||
stacklevel=3, |
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.
It's all hard for me to conceptualize, but does stacklevel=2
localize the warning better (to the importer, rather than to the grand-importer)?
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.
2 might be better, I think I left it at 3 from a previous iteration of where I had this warning. I had it actually inside the files themselves.
From a raw python shell:
>>> from determined.common.experimental.checkpoint import Checkpoint
<stdin>:1: FutureWarning: The 'determined.common.experimental' module is deprecated and will be removed in future versions. Please import from 'determined.experimental' instead. Example: `from determined.experimental import Determined`
From a python file:
python3 a.py
a.py:1: FutureWarning: The 'determined.common.experimental' module is deprecated and will be removed in future versions. Please import from 'determined.experimental' instead. Example: `from determined.experimental import Determined`
from determined.common.experimental.checkpoint import Checkpoint
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
Could you please add a short description / test plan before merging?
MLG-381
Description
Adds deprecation warnings for users who try to import externally from
determined.common.experimental
. You should be importing fromdetermined.experimental
insteadTest Plan
Reset Terminal
Commentary (optional)
Checklist
docs/release-notes/
.See Release Note for details.
Ticket