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
Add deprecation warning to initialize/shutdown_sox #709
Conversation
Codecov Report
@@ Coverage Diff @@
## master #709 +/- ##
==========================================
- Coverage 89.16% 89.03% -0.13%
==========================================
Files 27 27
Lines 2399 2417 +18
==========================================
+ Hits 2139 2152 +13
- Misses 260 265 +5
Continue to review full report at Codecov.
|
2a73754
to
9519310
Compare
torchaudio/_internal/module_utils.py
Outdated
@@ -33,3 +34,14 @@ def wrapped(*args, **kwargs): | |||
raise RuntimeError(f'{func.__module__}.{func.__name__} requires {req}') | |||
return wrapped | |||
return decorator | |||
|
|||
|
|||
def depricate(direction: str): |
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.
Does pytorch already have something like this? I imagine we'd want to match their format.
Also, nit, it's deprecate.
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.
Does pytorch already have something like this? I imagine we'd want to match their format.
Quick search reveals they do not have one. It's all manually annotated.
https://github.com/pytorch/pytorch/search?l=Python&q=deprecated
PyTorch's convention in deprecation I know is that they use warnings.warn
, which emits UserWarning
.
Also, nit, it's deprecate.
that's not nit, very important one. I'm gonna fix it.
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.
Let's replace initialize_sox
and shutdown_sox
in torchaudio/__init__.py
by functions that do not do anything but raise a warning. We then make init_sox_effects
and shutdown_sox_effects
in torchaudio.sox_effects
private. This way we send a clear signal that users no longer need them.
torchaudio/__init__.py
Outdated
"Use `torchaudio.sox_effects.init_sox_effects`, or simply remove the call. " | ||
"It is automatically handled." |
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:
sox_effects
is now automatically initialized and shutdown, and this function doesn't do anything. Please remove this function to suppress the warning, and seetorchaudio.sox_effects.init_sox_effects
for more information.
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 agree that recommending to remove the function call should be the first thing, instead of second option. but I argue this function doesn't do anything.
is not quite accurate and shutdown_sox_effects
allows user code to release the resources early.
torchaudio/__init__.py
Outdated
"Use `torchaudio.sox_effects.shutdown_sox`, or remove the call. " | ||
"It is automatically handled." |
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.
same as above
torchaudio/_internal/module_utils.py
Outdated
@@ -33,3 +34,19 @@ def wrapped(*args, **kwargs): | |||
raise RuntimeError(f'{func.__module__}.{func.__name__} requires {req}') | |||
return wrapped | |||
return decorator | |||
|
|||
|
|||
def deprecated(direction: str): |
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 does this decorator provide more than just adding the warning in the wrapping class?
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 give the consistent message format. We are going to deprecate a bunch of functions related to the current sox backend such as sox_signalinfo_t
so it will make it easier to do the job.
I am not sure about this. There could be some funky situations where user code needs to invoke init/shutdown manually. (such as multi-processing environment) in that case we want to have |
I see. Do you have an example that requires init/shutdown, and that the automatic init/shutdown fails? |
Nope. |
After I gave some more thoughts on this suggestion, I think this suggestion is going the opposite of what PR is proposing here.
I do not think it's a reasonable expectation that users read the source code and understand the intention in the code. We are issuing the message through warning and clearly stating that it's been deprieated. Changing the code to |
"pass" or "same as before with warning" are fine by me. We can go with the latter to avoid changing the behavior of current codes. That being said, init should already be a non-action since sox is initialized at import, no? shutdown isn't.
Since sox is automatically initialized at import, your concern might be that in some cases we have to shutdown sox manually for the code to continue without errors? |
yes |
Rebased on #714 |
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.
Since sox is automatically initialized at import, your concern might be that in some cases we have to shutdown sox manually for the code to continue without errors?
yes
This means we foresee rare events where a user may in fact need to shutdown sox. In that case, I don't see a reason to deprecate the function(s) at all. We could move it to torchaudio.sox_effects.shutdown_sox_effects.
, but then this adds friction.
[If we don't deprecate shutdown, then we could also not deprecate init.]
torchaudio/__init__.py
Outdated
@@ -34,6 +35,26 @@ | |||
pass | |||
|
|||
|
|||
@_mod_utils.deprecated( | |||
"Please remove the function call. Resource initialization is automatically handled") |
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: "Please remove the function call to initialize_sox
. Resource initialization is now automatically handled."
torchaudio/__init__.py
Outdated
|
||
|
||
@_mod_utils.deprecated( | ||
"Please remove the function call. Resource clean up is automatically handled") |
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: In case we would indeed move to deprecate this function: "Please remove the function call to torchaudio.shutdown_sox
. Resource clean up is now automatically handled. In the unlikely event that you need to manually shutdown sox, please use torchaudio.sox_effects.shutdown_sox_effects
."
For example of confusion; https://github.com/pytorch/audio/blob/master/test/test_sox_effects.py#L24-L25 |
Following of our offline discussion :)
|
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
Thanks! |
torchaudio.initialize_sox
(and correspondingtorchaudio.shutdown_sox
) is a confusing function because it sounds like this function has to be called to use any sox functionality though it is required only for SoX Effects. This PR proposes to deprecate these functions and direct users to usetorchaudio.sox_effects.init_sox_effects
(andtorchaudio.sox_effects.shutdown_sox_effects
), if necessary.