Skip to content

Commit

Permalink
refactor: apply unsafe automatic ruff lint fixes
Browse files Browse the repository at this point in the history
Manually checked and adjusted after generating with:
uv run ruff check tests/ TTS/ notebooks/ recipes/ --fix --unsafe-fixes
  • Loading branch information
eginhard committed Jan 11, 2025
1 parent 63fd577 commit 5b3e40a
Show file tree
Hide file tree
Showing 34 changed files with 98 additions and 104 deletions.
2 changes: 1 addition & 1 deletion TTS/bin/train_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def main(args): # pylint: disable=redefined-outer-name
criterion, args.restore_step = model.load_checkpoint(
c, args.restore_path, eval=False, use_cuda=use_cuda, criterion=criterion
)
print(" > Model restored from step %d" % args.restore_step, flush=True)
print(f" > Model restored from step {args.restore_step}", flush=True)
else:
args.restore_step = 0

Expand Down
4 changes: 2 additions & 2 deletions TTS/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
import re
from typing import Any, Dict, Union
from typing import Any, Union

import fsspec
import yaml
Expand Down Expand Up @@ -58,7 +58,7 @@ def _process_model_name(config_dict: dict) -> str:
"""Format the model name as expected. It is a band-aid for the old `vocoder` model names.
Args:
config_dict (Dict): A dictionary including the config fields.
config_dict (dict): A dictionary including the config fields.
Returns:
str: Formatted modelname.
Expand Down
4 changes: 2 additions & 2 deletions TTS/encoder/models/base_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BaseEncoder(nn.Module):

# pylint: disable=W0102
def __init__(self):
super(BaseEncoder, self).__init__()
super().__init__()

def get_torch_mel_spectrogram_class(self, audio_config):
return torch.nn.Sequential(
Expand Down Expand Up @@ -107,7 +107,7 @@ def get_criterion(self, c: Coqpit, num_classes=None):
elif c.loss == "softmaxproto":
criterion = SoftmaxAngleProtoLoss(c.model_params["proj_dim"], num_classes)
else:
raise Exception("The %s not is a loss supported" % c.loss)
raise Exception(f"The {c.loss} not is a loss supported")
return criterion

def load_checkpoint(
Expand Down
6 changes: 3 additions & 3 deletions TTS/encoder/models/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class SELayer(nn.Module):
def __init__(self, channel, reduction=8):
super(SELayer, self).__init__()
super().__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.fc = nn.Sequential(
nn.Linear(channel, channel // reduction),
Expand All @@ -27,7 +27,7 @@ class SEBasicBlock(nn.Module):
expansion = 1

def __init__(self, inplanes, planes, stride=1, downsample=None, reduction=8):
super(SEBasicBlock, self).__init__()
super().__init__()
self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
self.bn1 = nn.BatchNorm2d(planes)
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, padding=1, bias=False)
Expand Down Expand Up @@ -73,7 +73,7 @@ def __init__(
use_torch_spec=False,
audio_config=None,
):
super(ResNetSpeakerEncoder, self).__init__()
super().__init__()

self.encoder_type = encoder_type
self.input_dim = input_dim
Expand Down
12 changes: 6 additions & 6 deletions TTS/encoder/utils/prepare_voxceleb.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,30 @@ def download_and_extract(directory, subset, urls):
continue
logger.info("Downloading %s to %s", url, zip_filepath)
subprocess.call(
"wget %s --user %s --password %s -O %s" % (url, USER["user"], USER["password"], zip_filepath),
"wget {} --user {} --password {} -O {}".format(url, USER["user"], USER["password"], zip_filepath),
shell=True,
)

statinfo = os.stat(zip_filepath)
logger.info("Successfully downloaded %s, size(bytes): %d" % (url, statinfo.st_size))
logger.info("Successfully downloaded %s, size(bytes): %d", url, statinfo.st_size)

# concatenate all parts into zip files
if ".zip" not in zip_filepath:
zip_filepath = "_".join(zip_filepath.split("_")[:-1])
subprocess.call("cat %s* > %s.zip" % (zip_filepath, zip_filepath), shell=True)
subprocess.call(f"cat {zip_filepath}* > {zip_filepath}.zip", shell=True)
zip_filepath += ".zip"
extract_path = zip_filepath.strip(".zip")

# check zip file md5sum
with open(zip_filepath, "rb") as f_zip:
md5 = hashlib.md5(f_zip.read()).hexdigest()
if md5 != MD5SUM[subset]:
raise ValueError("md5sum of %s mismatch" % zip_filepath)
raise ValueError(f"md5sum of {zip_filepath} mismatch")

with zipfile.ZipFile(zip_filepath, "r") as zfile:
zfile.extractall(directory)
extract_path_ori = os.path.join(directory, zfile.infolist()[0].filename)
subprocess.call("mv %s %s" % (extract_path_ori, extract_path), shell=True)
subprocess.call(f"mv {extract_path_ori} {extract_path}", shell=True)
finally:
# os.remove(zip_filepath)
pass
Expand Down Expand Up @@ -193,7 +193,7 @@ def convert_audio_and_make_label(input_dir, subset, output_dir, output_file):
writer.writerow(["wav_filename", "wav_length_ms", "speaker_id", "speaker_name"])
for wav_file in files:
writer.writerow(wav_file)
logger.info(f"Successfully generated csv file {csv_file_path}")
logger.info("Successfully generated csv file %s", csv_file_path)


def processor(directory, subset, force_process):
Expand Down
9 changes: 4 additions & 5 deletions TTS/tts/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from collections import Counter
from collections.abc import Callable
from pathlib import Path
from typing import Dict, List, Tuple, Union

import numpy as np

Expand All @@ -18,7 +17,7 @@ def split_dataset(items, eval_split_max_size=None, eval_split_size=0.01):
"""Split a dataset into train and eval. Consider speaker distribution in multi-speaker training.
Args:
items (List[List]):
items (list[list]):
A list of samples. Each sample is a list of `[audio_path, text, speaker_id]`.
eval_split_max_size (int):
Expand Down Expand Up @@ -76,12 +75,12 @@ def load_tts_samples(
eval_split_max_size=None,
eval_split_size=0.01,
) -> tuple[list[list], list[list]]:
"""Parse the dataset from the datasets config, load the samples as a List and load the attention alignments if provided.
"""Parse the dataset from the datasets config, load the samples as a list and load the attention alignments if provided.
If `formatter` is not None, apply the formatter to the samples else pick the formatter from the available ones based
on the dataset name.
Args:
datasets (List[Dict], Dict): A list of datasets or a single dataset dictionary. If multiple datasets are
datasets (list[dict], dict): A list of datasets or a single dataset dictionary. If multiple datasets are
in the list, they are all merged.
eval_split (bool, optional): If true, create a evaluation split. If an eval split provided explicitly, generate
Expand All @@ -100,7 +99,7 @@ def load_tts_samples(
If > 1, represents the absolute number of evaluation samples. Defaults to 0.01 (1%).
Returns:
Tuple[List[List], List[List]: training and evaluation splits of the dataset.
tuple[list[list], list[list]: training and evaluation splits of the dataset.
"""
meta_data_train_all = []
meta_data_eval_all = [] if eval_split else None
Expand Down
4 changes: 2 additions & 2 deletions TTS/tts/layers/delightful_tts/conv_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(
w_init_gain="linear",
use_weight_norm=False,
):
super(ConvNorm, self).__init__() # pylint: disable=super-with-arguments
super().__init__()
if padding is None:
assert kernel_size % 2 == 1
padding = int(dilation * (kernel_size - 1) / 2)
Expand Down Expand Up @@ -92,7 +92,7 @@ def __init__(
lstm_type="bilstm",
use_linear=True,
):
super(ConvLSTMLinear, self).__init__() # pylint: disable=super-with-arguments
super().__init__()
self.out_dim = out_dim
self.lstm_type = lstm_type
self.use_linear = use_linear
Expand Down
4 changes: 2 additions & 2 deletions TTS/tts/layers/delightful_tts/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(
kernel_size=3,
use_partial_padding=False, # pylint: disable=unused-argument
):
super(BottleneckLayer, self).__init__() # pylint: disable=super-with-arguments
super().__init__()

self.reduction_factor = reduction_factor
reduced_dim = int(in_dim / reduction_factor)
Expand Down Expand Up @@ -194,7 +194,7 @@ class STL(nn.Module):
"""

def __init__(self, n_hidden: int, token_num: int):
super(STL, self).__init__() # pylint: disable=super-with-arguments
super().__init__()

num_heads = 1
E = n_hidden
Expand Down
4 changes: 2 additions & 2 deletions TTS/tts/layers/tortoise/diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def p_sample_loop_progressive(
"""
if device is None:
device = next(model.parameters()).device
assert isinstance(shape, (tuple, list))
assert isinstance(shape, tuple | list)
if noise is not None:
img = noise
else:
Expand Down Expand Up @@ -805,7 +805,7 @@ def ddim_sample_loop_progressive(
"""
if device is None:
device = next(model.parameters()).device
assert isinstance(shape, (tuple, list))
assert isinstance(shape, tuple | list)
if noise is not None:
img = noise
else:
Expand Down
4 changes: 2 additions & 2 deletions TTS/tts/layers/tortoise/vocoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def __init__(
hop_length=256,
n_mel_channels=100,
):
super(UnivNetGenerator, self).__init__()
super().__init__()
self.mel_channel = n_mel_channels
self.noise_dim = noise_dim
self.hop_length = hop_length
Expand Down Expand Up @@ -344,7 +344,7 @@ def forward(self, c, z):
return z

def eval(self, inference=False):
super(UnivNetGenerator, self).eval()
super().eval()
# don't remove weight norm while validation in training loop
if inference:
self.remove_weight_norm()
Expand Down
Loading

0 comments on commit 5b3e40a

Please sign in to comment.