internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: pytorch/audio

Issue:
flanger incompatible with GPU
flanger torchscript test is failing on CUDA master branch.

See: https://app.circleci.com/pipelines/github/pytorch/audio?branch=master
Device mismatch happening at: https://github.com/pytorch/audio/pull/651/files#diff-292a2ef33b3ecf4c40cda1a4afe58760R1486

cc @bhargavkathivarapu 


Discussion:

Resolving patch:
diff --git a/torchaudio/functional.py b/torchaudio/functional.py
--- a/torchaudio/functional.py
+++ b/torchaudio/functional.py
@@ -1317,7 +1317,6 @@ def phaser(
     delay_buf = torch.zeros(waveform.shape[0], delay_buf_len, dtype=dtype, device=device)
 
     mod_buf_len = int(sample_rate / mod_speed + .5)
-    mod_buf = torch.zeros(mod_buf_len, dtype=dtype, device=device)
 
     if sinusoidal:
         wave_type = 'SINE'
@@ -1329,7 +1328,8 @@ def phaser(
                                    table_size=mod_buf_len,
                                    min=1.,
                                    max=float(delay_buf_len),
-                                   phase=math.pi / 2)
+                                   phase=math.pi / 2,
+                                   device=device)
 
     delay_pos = 0
     mod_pos = 0
@@ -1353,7 +1353,8 @@ def _generate_wave_table(
         table_size: int,
         min: float,
         max: float,
-        phase: float
+        phase: float,
+        device: torch.device
 ) -> Tensor:
     r"""A helper fucntion for phaser. Generates a table with given parameters
 
@@ -1364,18 +1365,18 @@ def _generate_wave_table(
         min (float): desired min value
         max (float): desired max value
         phase (float): desired phase
-
+        device (torch.device): Torch device on which table must be generated
     Returns:
         Tensor: A 1D tensor with wave table values
     """
 
     phase_offset = int(phase / math.pi / 2 * table_size + 0.5)
 
-    t = torch.arange(table_size).to(torch.int32)
+    t = torch.arange(table_size, device=device, dtype=torch.int32)
 
     point = (t + phase_offset) % table_size
 
-    d = torch.zeros_like(point).to(torch.float64)
+    d = torch.zeros_like(point, device=device, dtype=torch.float64)
 
     if wave_type == 'SINE':
         d = (torch.sin(point.to(torch.float64) / table_size * 2 * math.pi) + 1) / 2
@@ -1487,8 +1488,6 @@ def flanger(
 
     lfo_length = int(sample_rate / speed)
 
-    lfo = torch.zeros(lfo_length, dtype=dtype, device=device)
-
     table_min = math.floor(delay_min * sample_rate + 0.5)
     table_max = delay_buf_length - 2.
 
@@ -1497,13 +1496,14 @@ def flanger(
                                table_size=lfo_length,
                                min=float(table_min),
                                max=float(table_max),
-                               phase=3 * math.pi / 2)
+                               phase=3 * math.pi / 2,
+                               device=device)
 
     output_waveform = torch.zeros_like(waveform, dtype=dtype, device=device)
 
     delay_buf_pos = 0
     lfo_pos = 0
-    channel_idxs = torch.arange(0, n_channels)
+    channel_idxs = torch.arange(0, n_channels, device=device)
 
     for i in range(waveform.shape[-1]):
 


Test patch:
Repository: pytorch/audio

Issue:
Fix integer division in test
Integer division started to fail. 

https://app.circleci.com/pipelines/github/pytorch/audio/2197/workflows/6b973b19-99bf-4479-9ba3-369e0631b353/jobs/56963/steps


Discussion:

Resolving patch:
diff --git a/torchaudio/functional.py b/torchaudio/functional.py
--- a/torchaudio/functional.py
+++ b/torchaudio/functional.py
@@ -1382,7 +1382,7 @@ def _generate_wave_table(
         d = (torch.sin(point.to(torch.float64) / table_size * 2 * math.pi) + 1) / 2
     elif wave_type == 'TRIANGLE':
         d = point.to(torch.float64) * 2 / table_size
-        value = 4 * point / table_size
+        value = 4 * point // table_size
         d[value == 0] = d[value == 0] + 0.5
         d[value == 1] = 1.5 - d[value == 1]
         d[value == 2] = 1.5 - d[value == 2]


Test patch:
diff --git a/test/test_functional.py b/test/test_functional.py
--- a/test/test_functional.py
+++ b/test/test_functional.py
@@ -381,7 +381,7 @@ def test_mask_along_axis(specgram, mask_param, mask_value, axis):
 
     masked_columns = (mask_specgram == mask_value).sum(other_axis)
     num_masked_columns = (masked_columns == mask_specgram.size(other_axis)).sum()
-    num_masked_columns /= mask_specgram.size(0)
+    num_masked_columns //= mask_specgram.size(0)
 
     assert mask_specgram.size() == specgram.size()
     assert num_masked_columns < mask_param
Repository: pytorch/audio

Issue:
torchaudio.transforms.GriffinLim does not allow backpropagation
## 🐛 Bug

I cannot backpropagate through GriffinLim due to in-place operations being used.

## To Reproduce

Minimal example:
```
import torch
import torchaudio.transforms

x = torch.rand(1, 16000)
spec = torch.stft(x, n_fft=512, hop_length=160, win_length=320)
mag = spec.pow(2).sum(-1).transpose(1, -1)
model = torch.nn.Linear(257, 257)
out = model(mag).transpose(1, -1)
resyn = torchaudio.transforms.GriffinLim(n_fft=512, hop_length=160, win_length=320)
wav = resyn(out)
optimizer = torch.optim.Adam(model.parameters(), lr=0.0001)
loss = torch.nn.functional.mse_loss(wav, x)
loss.backward()
optimizer.step()
```
Results in:
```
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [1, 257, 101, 2]], which is output 0 of SubBackward0, is at version 1; expected version 0 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).
```
When using the suggested `torch.autograd.set_detect_anomaly(True)`, the last few items on the call stack:
```
  File "/network/home/plantinp/pytorch/lib/python3.7/site-packages/torchaudio/transforms.py", line 161, in forward
    self.normalized, self.n_iter, self.momentum, self.length, self.rand_init)
  File "/network/home/plantinp/pytorch/lib/python3.7/site-packages/torchaudio/functional.py", line 373, in griffinlim
    angles = angles.div_(complex_norm(angles).add_(1e-16).unsqueeze(-1).expand_as(angles))
  File "/network/home/plantinp/pytorch/lib/python3.7/site-packages/torchaudio/functional.py", line 581, in complex_norm
    return torch.norm(complex_tensor, 2, -1)
  File "/network/home/plantinp/pytorch/lib/python3.7/site-packages/torch/functional.py", line 882, in norm
    return _VF.norm(input, p, _dim, keepdim=keepdim)
 (print_stack at /pytorch/torch/csrc/autograd/python_anomaly_mode.cpp:60)
```

## Expected behavior

Should allow backprop. Removing in-place ops in line 373 of `functional.py` seems to do the trick:

```
angles = angles.div(complex_norm(angles).add(1e-16).unsqueeze(-1).expand_as(angles))
```

## Environment

 - PyTorch Version (e.g., 1.0): 1.5
 - OS (e.g., Linux): Linux
 - How you installed PyTorch (`conda`, `pip`, source): pip
 - Python version: 3.8
 - CUDA/cuDNN version: 10.1



Discussion:

Resolving patch:
diff --git a/torchaudio/functional.py b/torchaudio/functional.py
--- a/torchaudio/functional.py
+++ b/torchaudio/functional.py
@@ -265,7 +265,7 @@ def griffinlim(
         angles = rebuilt
         if momentum:
             angles = angles - tprev.mul_(momentum / (1 + momentum))
-        angles = angles.div_(complex_norm(angles).add_(1e-16).unsqueeze(-1).expand_as(angles))
+        angles = angles.div(complex_norm(angles).add(1e-16).unsqueeze(-1).expand_as(angles))
 
     # Return the final phase estimates
     waveform = istft(specgram * angles,


Test patch:
Repository: pytorch/audio

Issue:
Out of date link to librosa
https://pytorch.org/audio/transforms.html

There is a link in the description of AmplitudeToDB

https://librosa.github.io/librosa/_modules/librosa/core/spectrum.html

This link no longer works


Discussion:
@AngledLuffa 

Thanks for reporting this. We will address this, but if you are interested in contributing, we welcome you to make a PR for the fix. I think this is the new link. https://librosa.org/doc/latest/generated/librosa.amplitude_to_db.html
Thank you for the offer, but I would be happy just to see it fixed!


Resolving patch:
diff --git a/torchaudio/transforms.py b/torchaudio/transforms.py
--- a/torchaudio/transforms.py
+++ b/torchaudio/transforms.py
@@ -198,7 +198,8 @@ def __init__(self, stype: str = 'power', top_db: Optional[float] = None) -> None
 
     def forward(self, x: Tensor) -> Tensor:
         r"""Numerically stable implementation from Librosa.
-        https://librosa.github.io/librosa/_modules/librosa/core/spectrum.html
+
+        https://librosa.org/doc/latest/generated/librosa.amplitude_to_db.html
 
         Args:
             x (Tensor): Input tensor before being converted to decibel scale.


Test patch:
Repository: pytorch/audio

Issue:
`noise_down_time` is not correctly passed in T.Vad
## 🐛 Bug

`noise_down_time` argument in `T.Vad` is not passed to `F.vad`

https://github.com/pytorch/audio/blob/076052f12eef6c2c64be85ca9c89054167cc1f24/torchaudio/transforms.py#L1005



Discussion:
also 

https://github.com/pytorch/audio/blob/076052f12eef6c2c64be85ca9c89054167cc1f24/torchaudio/transforms.py#L1030

Resolving patch:
diff --git a/torchaudio/transforms.py b/torchaudio/transforms.py
--- a/torchaudio/transforms.py
+++ b/torchaudio/transforms.py
@@ -1002,7 +1002,7 @@ def __init__(self,
         self.pre_trigger_time = pre_trigger_time
         self.boot_time = boot_time
         self.noise_up_time = noise_up_time
-        self.noise_down_time = noise_up_time
+        self.noise_down_time = noise_down_time
         self.noise_reduction_amount = noise_reduction_amount
         self.measure_freq = measure_freq
         self.measure_duration = measure_duration
@@ -1027,7 +1027,7 @@ def forward(self, waveform: Tensor) -> Tensor:
             pre_trigger_time=self.pre_trigger_time,
             boot_time=self.boot_time,
             noise_up_time=self.noise_up_time,
-            noise_down_time=self.noise_up_time,
+            noise_down_time=self.noise_down_time,
             noise_reduction_amount=self.noise_reduction_amount,
             measure_freq=self.measure_freq,
             measure_duration=self.measure_duration,


Test patch:
Repository: pytorch/audio

Issue:
`normalized` argument in griffinlim is not used
## 🐛 Bug

`F.griffinlim`'s `normalized` func arg is not used. It should be removed or used.
If removing it, it should also be removed from `T.GriffinLim`.


Discussion:
I'd suggest we add a warning if it is changed from the default value, and we can remove it in a subsequent version.
I would like to work on this. Would something like the below be okay?

```
if normalized:
warnings.warn("griffinlim normalized arg is not used. This will be removed in v0.8.0 release")
```

Added [here](https://github.com/pytorch/audio/blob/master/torchaudio/functional/functional.py#L193)
We should give one release of warning. We've just released 0.7, so this message will be visible in 0.8. We can then remove in 0.9 :)

Let's put the warning at the beginning of the function call, [here](https://github.com/pytorch/audio/blob/master/torchaudio/functional/functional.py#L141). And we should also provide instructions on how to suppress the warning. I suggest something like this:

```
if normalized:
    warnings.warn("The argument normalized is not used in Griffin-Lim, and will be removed in v0.9.0 release. To suppress this warning, please use `normalized=False`.")
```

Please feel free to open a pull request for this, thanks! :)

Resolving patch:
diff --git a/torchaudio/functional/functional.py b/torchaudio/functional/functional.py
--- a/torchaudio/functional/functional.py
+++ b/torchaudio/functional/functional.py
@@ -139,6 +139,12 @@ def griffinlim(
     assert momentum < 1, 'momentum={} > 1 can be unstable'.format(momentum)
     assert momentum >= 0, 'momentum={} < 0'.format(momentum)
 
+    if normalized:
+        warnings.warn(
+            "The argument normalized is not used in Griffin-Lim, "
+            "and will be removed in v0.9.0 release. To suppress this warning, "
+            "please use `normalized=False`.")
+
     # pack batch
     shape = specgram.size()
     specgram = specgram.reshape([-1] + list(shape[-2:]))


Test patch:
Repository: pytorch/audio

Issue:
Python 2 Deprecated
The 0.4.0 release of torchaudio was the last one supporting python 2, and master no longer officially supports python 2. We're looking to strip the code of python 2 references.
- [x] No longer use package `six` and `backports` for cross-compatibility
- [x] Convert to inline type hinting
- [x] No `__future__` import
- [x] ~~Change string formatting style~~
- [x] Remove mention of python 2.7 in `setup.py`
- [x] Remove older code path in [_check_module_exists](https://github.com/pytorch/audio/blob/master/torchaudio/common_utils.py#L26) and no longer need to check python 3 is not used [at the end of the file](https://github.com/pytorch/audio/blob/master/torchaudio/common_utils.py#L38)
- [x] Update `unicode_decoder` to python 3 only, [here](https://github.com/pytorch/audio/blob/master/torchaudio/datasets/utils.py#L22).
- [x] Replace calls to [makedir_exist_ok](https://github.com/pytorch/audio/blob/master/torchaudio/datasets/utils.py#L51) to `os.makedirs(.., exist_ok=True)`


Discussion:
I can take care of type hinting tomorrow :)
Do you need an extra hand with this or is everything covered?
For completeness, I did a quick grep through files, and I see the following reference to python 2. 

```
setup.py:        "Programming Language :: Python :: 2.7",
test/test_librosa_compatibility.py:    # Using a decorator here causes parametrize to fail on Python 2
torchaudio/common_utils.py:    if not PY3:  # Python 2
torchaudio/common_utils.py:    elif not PY34:  # Python [3, 3.4)
torchaudio/common_utils.py:    else:  # Python >= 3.4
torchaudio/common_utils.py:# On Py2, importing librosa 0.6.1 triggers a TypeError (if using newest joblib)
torchaudio/common_utils.py:# TODO: allow Py2 when librosa 0.6.2 releases
torchaudio/datasets/utils.py:    r"""Since the standard csv library does not handle unicode in Python 2, we need a wrapper.
torchaudio/datasets/utils.py:    Python2 support for os.makedirs(.., exist_ok=True)
torchaudio/datasets/utils.py:    # Required for Python 2.7 compatibility
```

In here, I also added a reference to Python <= 3.5 which is no longer supported on master, as mentioned [here](https://github.com/pytorch/audio/pull/538#issuecomment-613468667). 

Let us know if you find other references in code :)
https://github.com/pytorch/audio/pull/625 addressed `setup.py`. 
> #625 addressed `setup.py`.

Not [this one](https://github.com/pytorch/audio/blob/master/setup.py#L77) :)

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -73,8 +73,9 @@ def run(self):
         "Operating System :: Microsoft :: Windows",
         "Operating System :: POSIX",
         "Programming Language :: C++",
-        "Programming Language :: Python :: 2.7",
-        "Programming Language :: Python :: 3",
+        "Programming Language :: Python :: 3.6",
+        "Programming Language :: Python :: 3.7",
+        "Programming Language :: Python :: 3.8",
         "Programming Language :: Python :: Implementation :: CPython",
         "Topic :: Multimedia :: Sound/Audio",
         "Topic :: Scientific/Engineering :: Artificial Intelligence"


Test patch:
Repository: pytorch/audio

Issue:
New features missing from documentation
## 📚 Documentation

The following newly added functions are missing from the documentation. Anyone who can help adding these to documentation, please open a PR. I am swamped by the last-minute release work, so contributions from anyone is welcomed. 

```
functional.spectral_centroid
functional.apply_codec
transforms.SpectralCentroid
```

Please make two PR, one for `release/0.8` and `master`.
New features missing from documentation
## 📚 Documentation

The following newly added functions are missing from the documentation. Anyone who can help adding these to documentation, please open a PR. I am swamped by the last-minute release work, so contributions from anyone is welcomed. 

```
functional.spectral_centroid
functional.apply_codec
transforms.SpectralCentroid
```

Please make two PR, one for `release/0.8` and `master`.


Discussion:

Resolving patch:
diff --git a/torchaudio/functional/functional.py b/torchaudio/functional/functional.py
--- a/torchaudio/functional/functional.py
+++ b/torchaudio/functional/functional.py
@@ -1011,24 +1011,25 @@ def apply_codec(
     bits_per_sample: Optional[int] = None,
 ) -> Tensor:
     r"""
-    Applies codecs as a form of augmentation
+    Apply codecs as a form of augmentation.
+
     Args:
-        waveform (Tensor): Audio data. Must be 2 dimensional. See also ```channels_first```
-        sample_rate (int): Sample rate of the audio waveform
-        format (str): file format
+        waveform (Tensor): Audio data. Must be 2 dimensional. See also ```channels_first```.
+        sample_rate (int): Sample rate of the audio waveform.
+        format (str): File format.
         channels_first (bool):
             When True, both the input and output Tensor have dimension ``[channel, time]``.
             Otherwise, they have dimension ``[time, channel]``.
         compression (float): Used for formats other than WAV.
-            For mor details see :py:func:`torchaudio.backend.sox_io_backend.save`
+            For mor details see :py:func:`torchaudio.backend.sox_io_backend.save`.
         encoding (str, optional): Changes the encoding for the supported formats.
-            For more details see :py:func:`torchaudio.backend.sox_io_backend.save`
+            For more details see :py:func:`torchaudio.backend.sox_io_backend.save`.
         bits_per_sample (int, optional): Changes the bit depth for the supported formats.
-            For more details see :py:func:`torchaudio.backend.sox_io_backend.save`
+            For more details see :py:func:`torchaudio.backend.sox_io_backend.save`.
 
     Returns:
         torch.Tensor: Resulting Tensor.
-        If ``channels_first=True``, it has ``[channel, time]`` else ``[time, channel]``
+        If ``channels_first=True``, it has ``[channel, time]`` else ``[time, channel]``.
     """
     bytes = io.BytesIO()
     torchaudio.backend.sox_io_backend.save(bytes,


Test patch:
Repository: pytorch/audio

Issue:
New features missing from documentation
## 📚 Documentation

The following newly added functions are missing from the documentation. Anyone who can help adding these to documentation, please open a PR. I am swamped by the last-minute release work, so contributions from anyone is welcomed. 

```
functional.spectral_centroid
functional.apply_codec
transforms.SpectralCentroid
```

Please make two PR, one for `release/0.8` and `master`.


Discussion:

Resolving patch:
diff --git a/torchaudio/functional/functional.py b/torchaudio/functional/functional.py
--- a/torchaudio/functional/functional.py
+++ b/torchaudio/functional/functional.py
@@ -1011,24 +1011,25 @@ def apply_codec(
     bits_per_sample: Optional[int] = None,
 ) -> Tensor:
     r"""
-    Applies codecs as a form of augmentation
+    Apply codecs as a form of augmentation.
+
     Args:
-        waveform (Tensor): Audio data. Must be 2 dimensional. See also ```channels_first```
-        sample_rate (int): Sample rate of the audio waveform
-        format (str): file format
+        waveform (Tensor): Audio data. Must be 2 dimensional. See also ```channels_first```.
+        sample_rate (int): Sample rate of the audio waveform.
+        format (str): File format.
         channels_first (bool):
             When True, both the input and output Tensor have dimension ``[channel, time]``.
             Otherwise, they have dimension ``[time, channel]``.
         compression (float): Used for formats other than WAV.
-            For mor details see :py:func:`torchaudio.backend.sox_io_backend.save`
+            For mor details see :py:func:`torchaudio.backend.sox_io_backend.save`.
         encoding (str, optional): Changes the encoding for the supported formats.
-            For more details see :py:func:`torchaudio.backend.sox_io_backend.save`
+            For more details see :py:func:`torchaudio.backend.sox_io_backend.save`.
         bits_per_sample (int, optional): Changes the bit depth for the supported formats.
-            For more details see :py:func:`torchaudio.backend.sox_io_backend.save`
+            For more details see :py:func:`torchaudio.backend.sox_io_backend.save`.
 
     Returns:
         torch.Tensor: Resulting Tensor.
-        If ``channels_first=True``, it has ``[channel, time]`` else ``[time, channel]``
+        If ``channels_first=True``, it has ``[channel, time]`` else ``[time, channel]``.
     """
     bytes = io.BytesIO()
     torchaudio.backend.sox_io_backend.save(bytes,


Test patch:
Repository: pytorch/audio

Issue:
Making `AudioMetaData` print friendly
`AudioMetaData` class reports meta-data of audio source. It is however not print friendly.

```python
print(torchaudio.info(src))
>>> <torchaudio.backend.common.AudioMetaData object at 0x7f1bc5cd2890>
```

It is nice if we can simply print the attributes like `dataclass` objects do.

```python
print(torchaudio.info(src))
>>> AudioMetaData(sample_rate=900, encoding="PCM", ...)
```

## Steps

There are two approaches I can think of
1. Add `__str__` method.
2. Use `dataclasses.dataclass`

For 2, the `info` function has to be TorchScript-compatible. This means that its return type `AudioMetaData` has to be TorchScript-able. For this reason, `dataclass` might not be applicable. This can be checked with the following test;

```bash
(cd test && pytest torchaudio_unittest/backend/sox_io/torchscript_test.py)
```

## Build and test

Please refer to the [contribution guide](https://github.com/pytorch/audio/blob/master/CONTRIBUTING.md) for how to setup development environment.

To test, 

```bash
(cd test && pytest torchaudio_unittest/backend/sox_io/torchscript_test.py torchaudio_unittest/backend/sox_io/info_test.py torchaudio_unittest/backend/soundfile_io/info_test.py)
```


Discussion:
Hi. I want to work on this issue.

Resolving patch:
diff --git a/torchaudio/backend/common.py b/torchaudio/backend/common.py
--- a/torchaudio/backend/common.py
+++ b/torchaudio/backend/common.py
@@ -38,3 +38,14 @@ def __init__(
         self.num_channels = num_channels
         self.bits_per_sample = bits_per_sample
         self.encoding = encoding
+
+    def __str__(self):
+        return (
+            f"AudioMetaData("
+            f"sample_rate={self.sample_rate}, "
+            f"num_frames={self.num_frames}, "
+            f"num_channels={self.num_channels}, "
+            f"bits_per_sample={self.bits_per_sample}, "
+            f"encoding={self.encoding}"
+            f")"
+        )


Test patch: