-
Notifications
You must be signed in to change notification settings - Fork 666
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
[doc] Update backend docstring/documentation #935
Conversation
:mod:`torchaudio.backend` module provides implementations for audio file I/O, using different backend libraries. | ||
To switch backend, use :py:func:`torchaudio.set_audio_backend`. To check the current backend use :py:func:`torchaudio.get_audio_backend`. | ||
|
||
.. warning:: | ||
Although ``sox`` backend is default for backward compatibility reason, it has a number of issues, therefore it is highly recommended to use ``sox_io`` backend instead. Note, however, that due to the interface refinement, functions defined in ``sox`` backend and those defined in ``sox_io`` backend do not have the same signatures. | ||
There are currently four implementations available. |
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'd mention which one is the default and whether users actually need to worry about this in most cases
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.
Also write out why you might care about reading this section and give an overview of its content.
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.
Okay, so the description here was basically duplications from description of each backend. So I removed the description here and made the list into links to the backends. That way, the list here will only give the necessary information (default/deprecated).
So the Overall
section will talk about stuff things across backends.
docs/source/backend.rst
Outdated
|
||
There are currently three implementations available. | ||
``"sox_io"`` backend is the new backend which is built on ``libsox``, and bound with ``TorchScript``. This backend requires C++ extension module and is not available on Windows system. Function calls to this backend are TorchScript-able. This backend will become the default backend in ``"0.8.0"`` release. |
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.
You use the word backend 4 times here
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.
"and bound with TorchScript
" doesn't mean much to most users I'd say. Instead write that this implies.
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.
"This backend requires C++ extension module" - Is this something I'd need to install or worry about in most cases? Or is it only something to worry about on Windows? If I'm on Windows, what can I do? (add this to the intro). You probably want to have a platform-specific suggestion or guidance in the intro (might simply be Windows vs. not-Windows) and also again whether the user needs to worry or more specifically when the user needs to worry (e.g. mp3 support).
Bonus points for mentioning we're working on resolving some of these issues, e.g. mp3 work in progress for Windows etc., and a link to the corresponding issue
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.
Addressed all the suggestions. I am hesitant to mention the new I/O work as it's very early phase and we do not know when it will be available.
docs/source/backend.rst
Outdated
* :ref:`sox<sox_backend>` | ||
* :ref:`sox_io<sox_io_backend>` | ||
* :ref:`soundfile<soundfile_backend>` | ||
``"soundfile"`` backend is built on ``PySoundFile``. You need to install ``PySoundFile`` separately. The current interface of this backend (legacy interface) will be changed in ``0.8.0`` (new interface) to match the ``"sox_io"`` backend. |
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.
"You need to install PySoundFile
separately." - how do I get 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.
"The current interface of this backend (legacy interface) will be changed in 0.8.0
(new interface) to match the "sox_io"
backend." - More detail in the corresponding issue? Which one is it?
docs/source/backend.rst
Outdated
|
||
``sox`` backend is the original backend which is built on ``libsox``. This module is currently default but is known to have number of issues, such as wrong handling of WAV files other than 16-bit signed integer. Users are encouraged to use ``sox_io`` backend. This backend requires C++ extension module and is not available on Windows system. | ||
.. note:: | ||
Instead of calling functions in :mod:`torchaudio.backend` directly, please use ``torchaudio.info``, ``torhcaudio.load``, ``torchaudio.load_wav`` and ``torchaudio.save`` with proper backend set with :func:`torchaudio.get_audio_backend`. |
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.
Ideally we'd even have a tutorial or some kind of example somewhere that illustrates this behavior.
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: "torhcaudio" -> "torchaudio"
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.
We probably want to redo https://pytorch.org/tutorials/beginner/audio_preprocessing_tutorial.html
docs/source/backend.rst
Outdated
|
||
.. code:: | ||
|
||
torchaudio.set_audio_backend("sox_io") | ||
|
||
The function call to this backend can be Torchsript-able. You can apply :func:`torch.jit.script` and dump the object to file, then call it from C++ application. | ||
The function calls to this backend are TorchSript-able. You can apply :func:`torch.jit.script` and dump the object toa file, then call it from C++ application. |
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.
Probably not for this PR, but this might be a good opportunity to elaborate with an example, or point the reader to another reference.
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 me work on this as a follow up. I have a internal presentation scheduled this Thursday on this topic, so you will have a better understanding of what it will be like too.
@@ -210,6 +210,10 @@ def load_wav( | |||
) -> Tuple[torch.Tensor, int]: | |||
"""Load wave file. | |||
|
|||
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.
I think this is unnecessary, because it's duplicated with the warning statement and because we don't do this in any other library.
torchaudio/backend/common.py
Outdated
@@ -72,6 +89,10 @@ def __init__(self, | |||
|
|||
_LOAD_DOCSTRING = r"""Loads an audio file from disk into a tensor | |||
|
|||
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.
I think this is unnecessary, because it's duplicated with the warning statement and because we don't do this in any other library.
torchaudio/backend/common.py
Outdated
@@ -124,6 +145,11 @@ def __init__(self, | |||
It assumes that the wav file uses 16 bit per sample that needs normalization by | |||
shifting the input right by 16 bits. | |||
|
|||
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.
I think this is unnecessary, because it's duplicated with the warning statement and because we don't do this in any other library.
torchaudio/backend/common.py
Outdated
@@ -135,6 +161,10 @@ def __init__(self, | |||
|
|||
_SAVE_DOCSTRING = r"""Saves a Tensor on file as an audio file | |||
|
|||
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.
I think this is unnecessary, because it's duplicated with the warning statement and because we don't do this in any other library.
torchaudio/backend/common.py
Outdated
@@ -149,6 +179,10 @@ def __init__(self, | |||
|
|||
_INFO_DOCSTRING = r"""Gets metadata from an audio file without loading the signal. | |||
|
|||
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.
I think this is unnecessary, because it's duplicated with the warning statement and because we don't do this in any other library.
torchaudio/backend/sox_io_backend.py
Outdated
@@ -184,6 +184,9 @@ def load_wav( | |||
) -> Tuple[torch.Tensor, int]: | |||
"""Load wave file. | |||
|
|||
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.
I think this is unnecessary, because it's duplicated with the warning statement and because we don't do this in any other library.
filepath (str or pathlib.Path): | ||
Path to audio file. This function also handles ``pathlib.Path`` objects, but is annotated as | ||
``str`` for TorchScript compiler compatibility. | ||
Path to audio file. This function also handles ``pathlib.Path`` objects, | ||
but is annotated as ``str`` for TorchScript compatibility. |
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.
looks like pathlib is the new standard, so could extend to where it also supported elsewhere
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, let's land this :)
word_language_model/generate.py reads a model file trained with CUDA, into CPU if CUDA is not available.
Update documentation for backend. This includes,
"soundfile"
backend."sox"
backend and"soundfile"
backend with the legacy interface.