Skip to content

Commit 6e1c7fe

Browse files
authored
[Cherry-picks for 2.8] (#3976)
1 parent 01b3c45 commit 6e1c7fe

File tree

6 files changed

+853
-7
lines changed

6 files changed

+853
-7
lines changed

.github/scripts/unittest-linux/install.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ case $GPU_ARCH_TYPE in
7575
esac
7676
PYTORCH_WHEEL_INDEX="https://download.pytorch.org/whl/${UPLOAD_CHANNEL}/${GPU_ARCH_ID}"
7777
pip install --progress-bar=off --pre torch --index-url="${PYTORCH_WHEEL_INDEX}"
78+
pip install --progress-bar=off --pre torchcodec --index-url="https://download.pytorch.org/whl/nightly/cpu"
7879

7980

8081
# 2. Install torchaudio
@@ -86,6 +87,10 @@ python setup.py install
8687

8788
# 3. Install Test tools
8889
printf "* Installing test tools\n"
90+
# On this CI, for whatever reason, we're only able to install ffmpeg 4.
91+
conda install -y "ffmpeg<5"
92+
python -c "import torch; import torchaudio; import torchcodec; print(torch.__version__, torchaudio.__version__, torchcodec.__version__)"
93+
8994
NUMBA_DEV_CHANNEL=""
9095
if [[ "$(python --version)" = *3.9* || "$(python --version)" = *3.10* ]]; then
9196
# Numba isn't available for Python 3.9 and 3.10 except on the numba dev channel and building from source fails
@@ -94,7 +99,7 @@ if [[ "$(python --version)" = *3.9* || "$(python --version)" = *3.10* ]]; then
9499
fi
95100
(
96101
set -x
97-
conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} sox libvorbis parameterized 'requests>=2.20' 'ffmpeg>=6,<7'
102+
conda install -y -c conda-forge ${NUMBA_DEV_CHANNEL} sox libvorbis parameterized 'requests>=2.20'
98103
pip install kaldi-io SoundFile librosa coverage pytest pytest-cov scipy expecttest unidecode inflect Pillow sentencepiece pytorch-lightning 'protobuf<4.21.0' demucs tinytag pyroomacoustics flashlight-text git+https://github.com/kpu/kenlm
99104

100105
# TODO: might be better to fix the single call to `pip install` above

docs/source/torchaudio.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ torchaudio
77
Starting with version 2.8, we are refactoring TorchAudio to transition it
88
into a maintenance phase. As a result:
99

10-
- The APIs listed below are deprecated in 2.8 and will be removed in 2.9.
10+
- Most APIs listed below are deprecated in 2.8 and will be removed in 2.9.
1111
- The decoding and encoding capabilities of PyTorch for both audio and video
12-
are being consolidated into TorchCodec.
12+
are being consolidated into TorchCodec. For convenience, we provide
13+
:func:`~torchaudio.load_with_torchcodec` as a replacement for
14+
:func:`~torchaudio.load` and :func:`~torchaudio.save_with_torchcodec` as a
15+
replacement for :func:`~torchaudio.save`, but we recommend that you port
16+
your code to native torchcodec APIs.
1317

1418
Please see https://github.com/pytorch/audio/issues/3902 for more information.
1519

@@ -26,7 +30,9 @@ it easy to handle audio data.
2630

2731
info
2832
load
33+
load_with_torchcodec
2934
save
35+
save_with_torchcodec
3036
list_audio_backends
3137

3238
.. _backend:

src/torchaudio/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77
get_audio_backend as _get_audio_backend,
88
info as _info,
99
list_audio_backends as _list_audio_backends,
10-
load as _load,
11-
save as _save,
10+
load,
11+
save,
1212
set_audio_backend as _set_audio_backend,
1313
)
14+
from ._torchcodec import load_with_torchcodec, save_with_torchcodec
1415

1516
AudioMetaData = dropping_class_io_support(_AudioMetaData)
1617
get_audio_backend = dropping_io_support(_get_audio_backend)
1718
info = dropping_io_support(_info)
1819
list_audio_backends = dropping_io_support(_list_audio_backends)
19-
load = dropping_io_support(_load)
20-
save = dropping_io_support(_save)
2120
set_audio_backend = dropping_io_support(_set_audio_backend)
2221

2322
from . import ( # noqa: F401
@@ -45,6 +44,8 @@
4544
__all__ = [
4645
"AudioMetaData",
4746
"load",
47+
"load_with_torchcodec",
48+
"save_with_torchcodec",
4849
"info",
4950
"save",
5051
"io",

src/torchaudio/_backend/utils.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from functools import lru_cache
33
from typing import BinaryIO, Dict, Optional, Tuple, Type, Union
4+
import warnings
45

56
import torch
67

@@ -127,6 +128,14 @@ def load(
127128
) -> Tuple[torch.Tensor, int]:
128129
"""Load audio data from source.
129130
131+
.. warning::
132+
In 2.9, this function's implementation will be changed to use
133+
:func:`~torchaudio.load_with_torchcodec` under the hood. Some
134+
parameters like ``normalize``, ``format``, ``buffer_size``, and
135+
``backend`` will be ignored. We recommend that you port your code to
136+
rely directly on TorchCodec's decoder instead:
137+
https://docs.pytorch.org/torchcodec/stable/generated/torchcodec.decoders.AudioDecoder.html#torchcodec.decoders.AudioDecoder.
138+
130139
By default (``normalize=True``, ``channels_first=True``), this function returns Tensor with
131140
``float32`` dtype, and the shape of `[channel, time]`.
132141
@@ -201,6 +210,14 @@ def load(
201210
integer type, else ``float32`` type. If ``channels_first=True``, it has
202211
`[channel, time]` else `[time, channel]`.
203212
"""
213+
warnings.warn(
214+
"In 2.9, this function's implementation will be changed to use "
215+
"torchaudio.load_with_torchcodec` under the hood. Some "
216+
"parameters like ``normalize``, ``format``, ``buffer_size``, and "
217+
"``backend`` will be ignored. We recommend that you port your code to "
218+
"rely directly on TorchCodec's decoder instead: "
219+
"https://docs.pytorch.org/torchcodec/stable/generated/torchcodec.decoders.AudioDecoder.html#torchcodec.decoders.AudioDecoder."
220+
)
204221
backend = dispatcher(uri, format, backend)
205222
return backend.load(uri, frame_offset, num_frames, normalize, channels_first, format, buffer_size)
206223

@@ -235,6 +252,14 @@ def save(
235252
):
236253
"""Save audio data to file.
237254
255+
.. warning::
256+
In 2.9, this function's implementation will be changed to use
257+
:func:`~torchaudio.save_with_torchcodec` under the hood. Some
258+
parameters like format, encoding, bits_per_sample, buffer_size, and
259+
``backend`` will be ignored. We recommend that you port your code to
260+
rely directly on TorchCodec's decoder instead:
261+
https://docs.pytorch.org/torchcodec/stable/generated/torchcodec.encoders.AudioEncoder
262+
238263
Note:
239264
The formats this function can handle depend on the availability of backends.
240265
Please use the following functions to fetch the supported formats.
@@ -309,6 +334,14 @@ def save(
309334
Refer to http://sox.sourceforge.net/soxformat.html for more details.
310335
311336
"""
337+
warnings.warn(
338+
"In 2.9, this function's implementation will be changed to use "
339+
"torchaudio.save_with_torchcodec` under the hood. Some "
340+
"parameters like format, encoding, bits_per_sample, buffer_size, and "
341+
"``backend`` will be ignored. We recommend that you port your code to "
342+
"rely directly on TorchCodec's encoder instead: "
343+
"https://docs.pytorch.org/torchcodec/stable/generated/torchcodec.encoders.AudioEncoder"
344+
)
312345
backend = dispatcher(uri, format, backend)
313346
return backend.save(
314347
uri, src, sample_rate, channels_first, format, encoding, bits_per_sample, buffer_size, compression

0 commit comments

Comments
 (0)