Skip to content
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

Merged
merged 7 commits into from
Oct 9, 2020

Conversation

mthrok
Copy link
Collaborator

@mthrok mthrok commented Oct 2, 2020

Update documentation for backend. This includes,

  • Documentation for the new interface of "soundfile" backend.
  • The timeline for the change of default backend and deprecation of "sox" backend and "soundfile" backend with the legacy interface.
  • Deprecation warnings to the classes removed as part of backend removals.

@mthrok mthrok requested a review from mruberry October 2, 2020 19:20
docs/source/backend.rst Outdated Show resolved Hide resolved
: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.
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Collaborator Author

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 Show resolved Hide resolved

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.
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Collaborator Author

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.

* :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.
Copy link
Contributor

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?

Copy link
Contributor

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?


``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`.
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "torhcaudio" -> "torchaudio"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs/source/backend.rst Outdated Show resolved Hide resolved
docs/source/backend.rst Outdated Show resolved Hide resolved
docs/source/backend.rst Outdated Show resolved Hide resolved
docs/source/backend.rst Outdated Show resolved Hide resolved
docs/source/backend.rst Outdated Show resolved Hide resolved
docs/source/backend.rst Outdated Show resolved Hide resolved
docs/source/backend.rst Outdated Show resolved Hide resolved

.. 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.
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

docs/source/backend.rst Outdated Show resolved Hide resolved
docs/source/backend.rst Outdated Show resolved Hide resolved
docs/source/backend.rst Outdated Show resolved Hide resolved
docs/source/backend.rst Outdated Show resolved Hide resolved
docs/source/backend.rst Outdated Show resolved Hide resolved
docs/source/backend.rst Outdated Show resolved Hide resolved
@@ -210,6 +210,10 @@ def load_wav(
) -> Tuple[torch.Tensor, int]:
"""Load wave file.

Warnings:
Copy link
Contributor

@cpuhrsch cpuhrsch Oct 9, 2020

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.

@@ -72,6 +89,10 @@ def __init__(self,

_LOAD_DOCSTRING = r"""Loads an audio file from disk into a tensor

Warnings:
Copy link
Contributor

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.

@@ -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:
Copy link
Contributor

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.

@@ -135,6 +161,10 @@ def __init__(self,

_SAVE_DOCSTRING = r"""Saves a Tensor on file as an audio file

Warnings:
Copy link
Contributor

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.

@@ -149,6 +179,10 @@ def __init__(self,

_INFO_DOCSTRING = r"""Gets metadata from an audio file without loading the signal.

Warnings:
Copy link
Contributor

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.

@@ -184,6 +184,9 @@ def load_wav(
) -> Tuple[torch.Tensor, int]:
"""Load wave file.

Warnings:
Copy link
Contributor

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.

Comment on lines 16 to +18
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.
Copy link
Contributor

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

Copy link
Contributor

@vincentqb vincentqb left a 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 :)

@mthrok mthrok changed the title Update backend docstring/documentation [doc] Update backend docstring/documentation Oct 9, 2020
@mthrok mthrok merged commit e17c263 into pytorch:master Oct 9, 2020
@mthrok mthrok deleted the doc-backend branch October 9, 2020 18:05
mpc001 pushed a commit to mpc001/audio that referenced this pull request Aug 4, 2023
 word_language_model/generate.py reads a model file trained with CUDA, into CPU if CUDA is not available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants