Skip to content

Commit ad164db

Browse files
authored
Deprecate more APIs (#3949)
1 parent c7841de commit ad164db

File tree

6 files changed

+62
-9
lines changed

6 files changed

+62
-9
lines changed

src/torchaudio/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44
from . import _extension # noqa # usort: skip
55
from ._backend import ( # noqa # usort: skip
66
AudioMetaData,
7-
get_audio_backend,
8-
info,
9-
list_audio_backends,
7+
get_audio_backend as _get_audio_backend,
8+
info as _info,
9+
list_audio_backends as _list_audio_backends,
1010
load as _load,
1111
save as _save,
12-
set_audio_backend,
12+
set_audio_backend as _set_audio_backend,
1313
)
1414

15+
AudioMetaData.__init__ = dropping_support(AudioMetaData.__init__)
16+
get_audio_backend = dropping_support(_get_audio_backend)
17+
info = dropping_support(_info)
18+
list_audio_backends = dropping_support(_list_audio_backends)
1519
load = dropping_support(_load)
1620
save = dropping_support(_save)
21+
set_audio_backend = dropping_support(_set_audio_backend)
1722

1823
from . import ( # noqa: F401
1924
compliance,

src/torchaudio/utils/download.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def _get_hash(path, hash, chunk_size=1028):
3030
data = file.read(chunk_size)
3131
return m.hexdigest()
3232

33+
from torchaudio._internal.module_utils import dropping_support
3334

35+
@dropping_support
3436
def download_asset(
3537
key: str,
3638
hash: str = "",

src/torchaudio/utils/sox_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
sox_ext = torchaudio._extension.lazy_import_sox_ext()
1010

11+
from torchaudio._internal.module_utils import dropping_support
1112

13+
@dropping_support
1214
def set_seed(seed: int):
1315
"""Set libsox's PRNG
1416
@@ -21,6 +23,7 @@ def set_seed(seed: int):
2123
sox_ext.set_seed(seed)
2224

2325

26+
@dropping_support
2427
def set_verbosity(verbosity: int):
2528
"""Set libsox's verbosity
2629
@@ -38,6 +41,7 @@ def set_verbosity(verbosity: int):
3841
sox_ext.set_verbosity(verbosity)
3942

4043

44+
@dropping_support
4145
def set_buffer_size(buffer_size: int):
4246
"""Set buffer size for sox effect chain
4347
@@ -50,6 +54,7 @@ def set_buffer_size(buffer_size: int):
5054
sox_ext.set_buffer_size(buffer_size)
5155

5256

57+
@dropping_support
5358
def set_use_threads(use_threads: bool):
5459
"""Set multithread option for sox effect chain
5560
@@ -63,6 +68,7 @@ def set_use_threads(use_threads: bool):
6368
sox_ext.set_use_threads(use_threads)
6469

6570

71+
@dropping_support
6672
def list_effects() -> Dict[str, str]:
6773
"""List the available sox effect names
6874
@@ -72,6 +78,7 @@ def list_effects() -> Dict[str, str]:
7278
return dict(sox_ext.list_effects())
7379

7480

81+
@dropping_support
7582
def list_read_formats() -> List[str]:
7683
"""List the supported audio formats for read
7784
@@ -81,6 +88,7 @@ def list_read_formats() -> List[str]:
8188
return sox_ext.list_read_formats()
8289

8390

91+
@dropping_support
8492
def list_write_formats() -> List[str]:
8593
"""List the supported audio formats for write
8694
@@ -90,6 +98,7 @@ def list_write_formats() -> List[str]:
9098
return sox_ext.list_write_formats()
9199

92100

101+
@dropping_support
93102
def get_buffer_size() -> int:
94103
"""Get buffer size for sox effect chain
95104

src/torio/io/_streaming_media_decoder.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ def decorator(obj):
437437
InputStreamTypes = TypeVar("InputStream", bound=SourceStream)
438438
OutputStreamTypes = TypeVar("OutputStream", bound=OutputStream)
439439

440-
441440
class StreamingMediaDecoder:
442441
"""Fetch and decode audio/video streams chunk by chunk.
443442

src/torio/utils/ffmpeg_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
ffmpeg_ext = torio._extension.lazy_import_ffmpeg_ext()
1010

1111

12+
from torchaudio._internal.module_utils import dropping_support
13+
14+
15+
@dropping_support
1216
def get_versions() -> Dict[str, Tuple[int]]:
1317
"""Get the versions of FFmpeg libraries
1418
@@ -19,6 +23,7 @@ def get_versions() -> Dict[str, Tuple[int]]:
1923
return ffmpeg_ext.get_versions()
2024

2125

26+
@dropping_support
2227
def get_log_level() -> int:
2328
"""Get the log level of FFmpeg.
2429
@@ -27,6 +32,7 @@ def get_log_level() -> int:
2732
return ffmpeg_ext.get_log_level()
2833

2934

35+
@dropping_support
3036
def set_log_level(level: int):
3137
"""Set the log level of FFmpeg (libavformat etc)
3238
@@ -63,6 +69,7 @@ def set_log_level(level: int):
6369
ffmpeg_ext.set_log_level(level)
6470

6571

72+
@dropping_support
6673
def get_demuxers() -> Dict[str, str]:
6774
"""Get the available demuxers.
6875
@@ -80,6 +87,7 @@ def get_demuxers() -> Dict[str, str]:
8087
return ffmpeg_ext.get_demuxers()
8188

8289

90+
@dropping_support
8391
def get_muxers() -> Dict[str, str]:
8492
"""Get the available muxers.
8593
@@ -98,6 +106,7 @@ def get_muxers() -> Dict[str, str]:
98106
return ffmpeg_ext.get_muxers()
99107

100108

109+
@dropping_support
101110
def get_audio_decoders() -> Dict[str, str]:
102111
"""Get the available audio decoders.
103112
@@ -116,6 +125,7 @@ def get_audio_decoders() -> Dict[str, str]:
116125
return ffmpeg_ext.get_audio_decoders()
117126

118127

128+
@dropping_support
119129
def get_audio_encoders() -> Dict[str, str]:
120130
"""Get the available audio encoders.
121131
@@ -135,6 +145,7 @@ def get_audio_encoders() -> Dict[str, str]:
135145
return ffmpeg_ext.get_audio_encoders()
136146

137147

148+
@dropping_support
138149
def get_video_decoders() -> Dict[str, str]:
139150
"""Get the available video decoders.
140151
@@ -154,6 +165,7 @@ def get_video_decoders() -> Dict[str, str]:
154165
return ffmpeg_ext.get_video_decoders()
155166

156167

168+
@dropping_support
157169
def get_video_encoders() -> Dict[str, str]:
158170
"""Get the available video encoders.
159171
@@ -174,6 +186,7 @@ def get_video_encoders() -> Dict[str, str]:
174186
return ffmpeg_ext.get_video_encoders()
175187

176188

189+
@dropping_support
177190
def get_input_devices() -> Dict[str, str]:
178191
"""Get the available input devices.
179192
@@ -189,6 +202,7 @@ def get_input_devices() -> Dict[str, str]:
189202
return ffmpeg_ext.get_input_devices()
190203

191204

205+
@dropping_support
192206
def get_output_devices() -> Dict[str, str]:
193207
"""Get the available output devices.
194208
@@ -203,6 +217,7 @@ def get_output_devices() -> Dict[str, str]:
203217
return ffmpeg_ext.get_output_devices()
204218

205219

220+
@dropping_support
206221
def get_input_protocols() -> List[str]:
207222
"""Get the supported input protocols.
208223
@@ -216,6 +231,7 @@ def get_input_protocols() -> List[str]:
216231
return ffmpeg_ext.get_input_protocols()
217232

218233

234+
@dropping_support
219235
def get_output_protocols() -> List[str]:
220236
"""Get the supported output protocols.
221237
@@ -229,6 +245,7 @@ def get_output_protocols() -> List[str]:
229245
return ffmpeg_ext.get_output_protocols()
230246

231247

248+
@dropping_support
232249
def get_build_config() -> str:
233250
"""Get the FFmpeg build configuration
234251
@@ -242,6 +259,7 @@ def get_build_config() -> str:
242259
return ffmpeg_ext.get_build_config()
243260

244261

262+
@dropping_support
245263
def clear_cuda_context_cache():
246264
"""Clear the CUDA context used by CUDA Hardware accelerated video decoding"""
247265
ffmpeg_ext.clear_cuda_context_cache()
Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
import pytest
22

3+
import torch
4+
35
from torchaudio._internal.module_utils import UNSUPPORTED
6+
from torchaudio.sox_effects import apply_effects_tensor
7+
8+
# Importing prototype modules is needed to trigger the registration of the
9+
# corresponding APIs in the UNSUPPORTED register.
10+
from torchaudio.prototype import datasets, functional, models, pipelines, transforms
11+
412

513
@pytest.mark.parametrize("func", UNSUPPORTED)
614
def test_deprecations(func):
715
with pytest.warns(UserWarning, match="deprecated"):
816
try:
917
func()
1018
except Exception as e:
11-
# Type or Runtime error because we call func() without proper parameters.
12-
# The deprecation warning is still properly raised, since it is emitted before
13-
# the underlying (deprecated) function is called.
14-
assert isinstance(e, (TypeError, RuntimeError))
19+
assert isinstance(e, (TypeError, RuntimeError, ValueError, ImportError))
20+
21+
22+
# It's not great, but the deprecation decorator we're using breaks torchscript
23+
# This test just illustrates this behavior. Ideally, we wouldn't break
24+
# torchscript users. But oh well, torchscript is supposed to have been
25+
# deprecated for years.
26+
@pytest.mark.parametrize("scripted", (True, False))
27+
def test_torchscript_fails(scripted):
28+
f = apply_effects_tensor
29+
if scripted:
30+
pytest.xfail("Deprecation decorator breaks torchscript")
31+
f = torch.jit.script(f)
32+
_, out_sample_rate = f(torch.rand(2, 1000), sample_rate=16_000, effects=[["rate", "8000"]])
33+
assert out_sample_rate == 8000
34+

0 commit comments

Comments
 (0)