Skip to content

Commit 0503ea8

Browse files
authored
Merge branch 'master' into autograd-phase-vocoder
2 parents 8ef832f + 20469cf commit 0503ea8

File tree

7 files changed

+95
-9
lines changed

7 files changed

+95
-9
lines changed

.circleci/regenerate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616

1717
import jinja2
18+
from jinja2 import select_autoescape
1819
import yaml
1920
import os.path
2021

@@ -213,7 +214,7 @@ def unittest_workflows(indentation=6):
213214
env = jinja2.Environment(
214215
loader=jinja2.FileSystemLoader(d),
215216
lstrip_blocks=True,
216-
autoescape=False,
217+
autoescape=select_autoescape(enabled_extensions=('html', 'xml')),
217218
)
218219

219220
with open(os.path.join(d, 'config.yml'), 'w') as f:

.github/workflows/bandit.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# GitHub Actions Bandit Workflow
2+
3+
name: Bandit
4+
5+
on:
6+
pull_request:
7+
branches: [ master ]
8+
9+
workflow_dispatch:
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
# Task will fail if any high-severity issues are found
19+
# Ignoring submodules
20+
- name: Run Bandit Security Analysis
21+
run: |
22+
python -m pip install bandit
23+
python -m bandit -r . -x ./third_party -lll

.github/workflows/codeql.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# GitHub Actions CodeQL Workflow
2+
3+
name: CodeQL
4+
5+
on:
6+
pull_request:
7+
branches: [ master ]
8+
9+
workflow_dispatch:
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Initialize CodeQL
19+
uses: github/codeql-action/init@v1
20+
with:
21+
languages: python, cpp
22+
23+
- name: Install Ninja
24+
run: |
25+
sudo apt-get update -y
26+
sudo apt-get install -y ninja-build
27+
28+
- name: Update submodules
29+
run: git submodule update --init --recursive
30+
31+
- name: Install Torch
32+
run: |
33+
python -m pip install cmake
34+
python -m pip install torch==1.8.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
35+
sudo ln -s /usr/bin/ninja /usr/bin/ninja-build
36+
37+
- name: Build TorchAudio
38+
run: BUILD_SOX=1 USE_CUDA=0 python setup.py develop --user
39+
40+
# If any code scanning alerts are found, they will be under Security -> CodeQL
41+
# Link: https://github.com/pytorch/audio/security/code-scanning
42+
- name: Perform CodeQL Analysis
43+
uses: github/codeql-action/analyze@v1

test/torchaudio_unittest/transforms/autograd_test_impl.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ def test_melspectrogram(self):
8080
waveform = get_whitenoise(sample_rate=sample_rate, duration=0.05, n_channels=2)
8181
self.assert_grad(transform, [waveform], nondet_tol=1e-10)
8282

83+
@parameterized.expand([(0, ), (0.99, )])
84+
def test_griffinlim(self, momentum):
85+
n_fft = 400
86+
n_frames = 5
87+
n_iter = 3
88+
spec = torch.rand(n_fft // 2 + 1, n_frames) * n_fft
89+
transform = T.GriffinLim(n_fft=n_fft, n_iter=n_iter, momentum=momentum, rand_init=False)
90+
self.assert_grad(transform, [spec], nondet_tol=1e-10)
91+
8392
@parameterized.expand([(False, ), (True, )])
8493
def test_mfcc(self, log_mels):
8594
sample_rate = 8000
@@ -104,7 +113,13 @@ def test_fade(self, fade_shape):
104113
waveform = get_whitenoise(sample_rate=8000, duration=0.05, n_channels=2)
105114
self.assert_grad(transform, [waveform], nondet_tol=1e-10)
106115

107-
@nested_params(
116+
def test_spectral_centroid(self):
117+
sample_rate = 8000
118+
transform = T.SpectralCentroid(sample_rate=sample_rate)
119+
waveform = get_whitenoise(sample_rate=sample_rate, duration=0.05, n_channels=2)
120+
self.assert_grad(transform, [waveform], nondet_tol=1e-10)
121+
122+
@nested_params(
108123
[0.7, 0.8, 0.9, 1.0, 1.3],
109124
[True, False],
110125
)

torchaudio/datasets/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def stream_url(url: str,
2929

3030
# If we already have the whole file, there is no need to download it again
3131
req = urllib.request.Request(url, method="HEAD")
32-
url_size = int(urllib.request.urlopen(req).info().get("Content-Length", -1))
32+
with urllib.request.urlopen(req) as response:
33+
url_size = int(response.info().get("Content-Length", -1))
3334
if url_size == start_byte:
3435
return
3536

torchaudio/functional/functional.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def griffinlim(
203203
hop_length=hop_length,
204204
win_length=win_length,
205205
window=window,
206-
length=length).float()
206+
length=length)
207207

208208
# Rebuild the spectrogram
209209
rebuilt = torch.view_as_real(
@@ -793,7 +793,7 @@ def compute_deltas(
793793

794794
# pack batch
795795
shape = specgram.size()
796-
specgram = specgram.reshape(-1, 1, shape[-1])
796+
specgram = specgram.reshape(1, -1, shape[-1])
797797

798798
assert win_length >= 3
799799

@@ -804,9 +804,9 @@ def compute_deltas(
804804

805805
specgram = torch.nn.functional.pad(specgram, (n, n), mode=mode)
806806

807-
kernel = torch.arange(-n, n + 1, 1, device=device, dtype=dtype).view(1, 1, -1)
807+
kernel = torch.arange(-n, n + 1, 1, device=device, dtype=dtype).repeat(specgram.shape[1], 1, 1)
808808

809-
output = torch.nn.functional.conv1d(specgram, kernel) / denom
809+
output = torch.nn.functional.conv1d(specgram, kernel, groups=specgram.shape[1]) / denom
810810

811811
# unpack batch
812812
output = output.reshape(shape)

torchaudio/transforms.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class GriffinLim(torch.nn.Module):
155155
| "Signal estimation from modified short-time Fourier transform,"
156156
| IEEE Trans. ASSP, vol.32, no.2, pp.236–243, Apr. 1984.
157157
"""
158-
__constants__ = ['n_fft', 'n_iter', 'win_length', 'hop_length', 'power', 'normalized',
158+
__constants__ = ['n_fft', 'n_iter', 'win_length', 'hop_length', 'power',
159159
'length', 'momentum', 'rand_init']
160160

161161
def __init__(self,
@@ -172,7 +172,7 @@ def __init__(self,
172172
super(GriffinLim, self).__init__()
173173

174174
assert momentum < 1, 'momentum={} > 1 can be unstable'.format(momentum)
175-
assert momentum > 0, 'momentum={} < 0'.format(momentum)
175+
assert momentum >= 0, 'momentum={} < 0'.format(momentum)
176176

177177
self.n_fft = n_fft
178178
self.n_iter = n_iter
@@ -768,6 +768,7 @@ class Fade(torch.nn.Module):
768768
fade_shape (str, optional): Shape of fade. Must be one of: "quarter_sine",
769769
"half_sine", "linear", "logarithmic", "exponential". (Default: ``"linear"``)
770770
"""
771+
771772
def __init__(self,
772773
fade_in_len: int = 0,
773774
fade_out_len: int = 0,
@@ -877,6 +878,7 @@ class FrequencyMasking(_AxisMasking):
877878
example/channel in the batch. (Default: ``False``)
878879
This option is applicable only when the input tensor is 4D.
879880
"""
881+
880882
def __init__(self, freq_mask_param: int, iid_masks: bool = False) -> None:
881883
super(FrequencyMasking, self).__init__(freq_mask_param, 1, iid_masks)
882884

@@ -891,6 +893,7 @@ class TimeMasking(_AxisMasking):
891893
example/channel in the batch. (Default: ``False``)
892894
This option is applicable only when the input tensor is 4D.
893895
"""
896+
894897
def __init__(self, time_mask_param: int, iid_masks: bool = False) -> None:
895898
super(TimeMasking, self).__init__(time_mask_param, 2, iid_masks)
896899

0 commit comments

Comments
 (0)