Skip to content

Commit fa51429

Browse files
authored
Fix pre-commit and enable Lint CI workflow. (#4099)
* Fix pre-commit and enable Lint CI workflow. * Switch to python 3.11. Remove mypy section.
1 parent 27fc249 commit fa51429

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+265
-259
lines changed

.github/workflows/lint.yml

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
# name: Lint
1+
name: Lint
22

3-
# on:
4-
# pull_request:
5-
# push:
6-
# branches:
7-
# - nightly
8-
# - main
9-
# - release/*
10-
# workflow_dispatch:
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
117

12-
# jobs:
13-
# python-source-and-configs:
14-
# uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
15-
# permissions:
16-
# id-token: write
17-
# contents: read
18-
# with:
19-
# repository: pytorch/audio
20-
# script: |
21-
# set -euo pipefail
8+
concurrency:
9+
group: unit-test${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_number || github.ref }}
10+
cancel-in-progress: true
2211

23-
# echo '::group::Setup environment'
24-
# eval "$("$(which conda)" shell.bash hook)"
25-
# # libcst does not have 3.11 pre-built binaries yet. Use python 3.10
26-
# conda create -y --name env python=3.10
27-
# conda activate env
28-
# pip3 install --progress-bar=off pre-commit
29-
# echo '::endgroup::'
12+
defaults:
13+
run:
14+
shell: bash -l -eo pipefail {0}
3015

31-
# set +e
32-
# pre-commit run --all-files --show-diff-on-failure
33-
# status=$?
34-
35-
# echo '::group::Add Summry'
36-
# if [ $status -ne 0 ]; then
37-
# echo '### Lint failure' >> $GITHUB_STEP_SUMMARY
38-
# echo '```diff' >> $GITHUB_STEP_SUMMARY
39-
# git --no-pager diff >> $GITHUB_STEP_SUMMARY
40-
# echo '```' >> $GITHUB_STEP_SUMMARY
41-
# fi
42-
# echo '::endgroup::'
43-
# exit $status
16+
jobs:
17+
pre-commit-checks:
18+
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
python-version: ['3.11']
23+
steps:
24+
- name: Check out repo
25+
uses: actions/checkout@v3
26+
- name: Setup conda env
27+
uses: conda-incubator/setup-miniconda@v2
28+
with:
29+
auto-update-conda: true
30+
miniconda-version: "latest"
31+
activate-environment: test
32+
python-version: ${{ matrix.python-version }}
33+
- name: Update pip
34+
run: python -m pip install --upgrade pip
35+
- name: Install pre-commit
36+
run: |
37+
python -m pip install pre-commit
38+
- name: Run pre-commit checks
39+
run: |
40+
pre-commit run --all-files
41+
- name: Check to see what files pre-commit modified
42+
run: |
43+
git diff

cmake/LoadHIP.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,3 @@ if(HIP_FOUND)
267267
set(roctracer_INCLUDE_DIRS ${ROCTRACER_PATH}/include)
268268
endif()
269269
endif()
270-

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
nbsphinx_requirejs_path = ""
6060

6161
autodoc_member_order = "bysource"
62-
autodoc_mock_imports = ['torchaudio.models.decoder']
62+
autodoc_mock_imports = ["torchaudio.models.decoder"]
6363

6464
# katex options
6565
#

examples/tutorials/audio_feature_augmentation_tutorial.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
def _get_sample(path):
3737
return torchaudio.load(path)
3838

39+
3940
def get_speech_sample():
4041
return _get_sample(SAMPLE_WAV_SPEECH_PATH)
4142

examples/tutorials/audio_resampling_tutorial.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import math
2727
import timeit
2828

29-
import matplotlib.colors as mcolors
3029
import matplotlib.pyplot as plt
3130
from IPython.display import Audio
3231
import numpy as np
@@ -427,7 +426,7 @@ def plot(data, cols, rows):
427426
x_data = np.arange(len(rows))
428427
bar_width = 0.8 / len(cols)
429428
for (i, (c, d)) in enumerate(zip(cols, data.T)):
430-
x_pos = x_data + (i - len(cols)/2 + 0.5) * bar_width
429+
x_pos = x_data + (i - len(cols) / 2 + 0.5) * bar_width
431430
ax.bar(x_pos, d, bar_width, label=c)
432431
ax.legend()
433432
ax.set_xticks(x_data)

examples/tutorials/mvdr_tutorial.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def generate_mixture(waveform_clean, waveform_noise, target_snr):
128128
waveform_noise *= 10 ** (-(target_snr - current_snr) / 20)
129129
return waveform_clean + waveform_noise
130130

131+
131132
# If you have mir_eval installed, you can use it to evaluate the separation quality of the estimated sources.
132133
# You can also evaluate the intelligibility of the speech with the Short-Time Objective Intelligibility (STOI) metric
133134
# available in the `pystoi` package, or the Perceptual Evaluation of Speech Quality (PESQ) metric available in the `pesq` package.

examples/tutorials/squim_tutorial.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ def plot(waveform, title, sample_rate=16000):
284284
# ```
285285
# These values are precomputed and hard-coded below.
286286
print(f"Reference metrics for distorted speech at {snr_dbs[0]}dB are\n")
287-
print(f"STOI: 0.9670831113894452")
288-
print(f"PESQ: 2.7961528301239014")
287+
print("STOI: 0.9670831113894452")
288+
print("PESQ: 2.7961528301239014")
289289
si_sdr_ref = si_snr(WAVEFORM_DISTORTED[0:1], WAVEFORM_SPEECH)
290290
print(f"SI-SDR: {si_sdr_ref}")
291291

@@ -304,8 +304,8 @@ def plot(waveform, title, sample_rate=16000):
304304
si_sdr_ref = si_snr(WAVEFORM_DISTORTED[1:2], WAVEFORM_SPEECH)
305305
# STOI and PESQ metrics are precomputed and hardcoded below.
306306
print(f"Reference metrics for distorted speech at {snr_dbs[1]}dB are\n")
307-
print(f"STOI: 0.5743247866630554")
308-
print(f"PESQ: 1.1112866401672363")
307+
print("STOI: 0.5743247866630554")
308+
print("PESQ: 1.1112866401672363")
309309
print(f"SI-SDR: {si_sdr_ref}")
310310

311311

src/libtorchaudio/forced_align/cpu/compute.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include <torch/script.h>
2-
#include <torch/torch.h>
1+
#include <torch/csrc/inductor/aoti_torch/c/shim.h>
32
#include <torch/csrc/stable/library.h>
4-
#include <torch/csrc/stable/tensor.h>
53
#include <torch/csrc/stable/ops.h>
6-
#include <torch/csrc/inductor/aoti_torch/c/shim.h>
4+
#include <torch/csrc/stable/tensor.h>
5+
#include <torch/script.h>
6+
#include <torch/torch.h>
77

88
using namespace std;
99

@@ -81,18 +81,21 @@ void forced_align_impl(
8181
auto curIdxOffset = t % 2;
8282
auto prevIdxOffset = (t - 1) % 2;
8383
for (auto j = 0; j < S; ++j) {
84-
alphas_a[curIdxOffset * S + j] = -std::numeric_limits<scalar_t>::infinity(); // alphas_a[curIdxOffset][j]
84+
alphas_a[curIdxOffset * S + j] = -std::numeric_limits<
85+
scalar_t>::infinity(); // alphas_a[curIdxOffset][j]
8586
}
8687
if (start == 0) {
87-
alphas_a[curIdxOffset * S] =
88-
alphas_a[prevIdxOffset * S] + logProbs_a[batchIndex][t][blank]; // alphas_a[curIdxOffset][0]
88+
alphas_a[curIdxOffset * S] = alphas_a[prevIdxOffset * S] +
89+
logProbs_a[batchIndex][t][blank]; // alphas_a[curIdxOffset][0]
8990
backPtr_a[S * t] = 0; // backPtr_a[t][0] = 0
9091
startloop += 1;
9192
}
9293

9394
for (auto i = startloop; i < end; i++) {
9495
auto x0 = alphas_a[prevIdxOffset * S + i]; // alphas_a[prevIdxOffset][i];
95-
auto x1 = alphas_a[prevIdxOffset * S + i - 1]; // alphas_a[prevIdxOffset][i - 1];
96+
auto x1 =
97+
alphas_a[prevIdxOffset * S + i - 1]; // alphas_a[prevIdxOffset][i
98+
// - 1];
9699
auto x2 = -std::numeric_limits<scalar_t>::infinity();
97100

98101
auto labelIdx = (i % 2 == 0) ? blank : targets_a[batchIndex][i / 2];
@@ -103,7 +106,8 @@ void forced_align_impl(
103106
// (i != 1) just ensures we don't access targets[i - 2] if its i < 2
104107
if (i % 2 != 0 && i != 1 &&
105108
targets_a[batchIndex][i / 2] != targets_a[batchIndex][i / 2 - 1]) {
106-
x2 = alphas_a[prevIdxOffset * S + i - 2]; // alphas_a[prevIdxOffset][i - 2];
109+
x2 = alphas_a[prevIdxOffset * S + i - 2]; // alphas_a[prevIdxOffset][i -
110+
// 2];
107111
}
108112
scalar_t result = 0.0;
109113
if (x2 > x1 && x2 > x0) {
@@ -116,12 +120,14 @@ void forced_align_impl(
116120
result = x0;
117121
backPtr_a[t * S + i] = 0; // backPtr_a[t][i] = 0
118122
}
119-
alphas_a[curIdxOffset * S + i] = result + logProbs_a[batchIndex][t][labelIdx]; // alphas_a[curIdxOffset][i]
123+
alphas_a[curIdxOffset * S + i] = result +
124+
logProbs_a[batchIndex][t][labelIdx]; // alphas_a[curIdxOffset][i]
120125
}
121126
}
122127
auto idx1 = (T - 1) % 2;
123-
auto ltrIdx = alphas_a[S * idx1 + S - 1] >
124-
alphas_a[S * idx1 + S - 2] ? S - 1 : S - 2; // alphas_a[idx1][S - 1], alphas_a[idx1][S - 2]
128+
auto ltrIdx = alphas_a[S * idx1 + S - 1] > alphas_a[S * idx1 + S - 2]
129+
? S - 1
130+
: S - 2; // alphas_a[idx1][S - 1], alphas_a[idx1][S - 2]
125131
delete[] alphas_a;
126132
// path stores the token index for each time step after force alignment.
127133
for (auto t = T - 1; t > -1; t--) {
@@ -194,15 +200,9 @@ std::tuple<torch::Tensor, torch::Tensor> compute(
194200
logProbs, targets, blank, paths);
195201
}
196202
});
197-
return std::make_tuple(
198-
paths,
199-
logProbs
200-
);
203+
return std::make_tuple(paths, logProbs);
201204
}
202205

203-
204-
205-
206206
TORCH_LIBRARY_IMPL(torchaudio, CPU, m) {
207207
m.impl("forced_align", &compute);
208208
}

src/libtorchaudio/lfilter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ void lfilter_core_generic_loop(
8282
auto coeff = a_coeff_flipped.unsqueeze(2);
8383
for (int64_t i_sample = 0; i_sample < n_samples_input; i_sample++) {
8484
auto windowed_output_signal =
85-
torch::narrow(padded_output_waveform, 2, i_sample, i_sample + n_order).transpose(0, 1);
86-
auto o0 =
87-
torch::select(input_signal_windows, 2, i_sample) -
85+
torch::narrow(padded_output_waveform, 2, i_sample, i_sample + n_order)
86+
.transpose(0, 1);
87+
auto o0 = torch::select(input_signal_windows, 2, i_sample) -
8888
at::matmul(windowed_output_signal, coeff).squeeze(2).transpose(0, 1);
8989
padded_output_waveform.index_put_(
9090
{torch::indexing::Slice(),

src/torchaudio/__init__.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
from torchaudio._internal.module_utils import dropping_io_support, dropping_class_io_support
2-
from typing import Union, BinaryIO, Optional, Tuple
31
import os
2+
from typing import BinaryIO, Optional, Tuple, Union
3+
44
import torch
5-
import sys
65

76
# Initialize extension and backend first
87
from . import _extension # noqa # usort: skip
8+
from . import compliance, datasets, functional, models, pipelines, transforms, utils # noqa: F401
99
from ._torchcodec import load_with_torchcodec, save_with_torchcodec
1010

11-
from . import ( # noqa: F401
12-
compliance,
13-
datasets,
14-
functional,
15-
models,
16-
pipelines,
17-
transforms,
18-
utils,
19-
)
20-
2111

2212
try:
2313
from .version import __version__, git_version # noqa: F401
@@ -100,9 +90,10 @@ def load(
10090
channels_first=channels_first,
10191
format=format,
10292
buffer_size=buffer_size,
103-
backend=backend
93+
backend=backend,
10494
)
10595

96+
10697
def save(
10798
uri: Union[str, os.PathLike],
10899
src: torch.Tensor,
@@ -182,14 +173,19 @@ def save(
182173
- The output format is determined by the file extension in the uri.
183174
- TorchCodec uses FFmpeg under the hood for encoding.
184175
"""
185-
return save_with_torchcodec(uri, src, sample_rate,
176+
return save_with_torchcodec(
177+
uri,
178+
src,
179+
sample_rate,
186180
channels_first=channels_first,
187181
format=format,
188182
encoding=encoding,
189183
bits_per_sample=bits_per_sample,
190184
buffer_size=buffer_size,
191185
backend=backend,
192-
compression=compression)
186+
compression=compression,
187+
)
188+
193189

194190
__all__ = [
195191
"load",

0 commit comments

Comments
 (0)