From 362ba2dce73244443a97deb66587e1e8cf53f567 Mon Sep 17 00:00:00 2001 From: Jim O'Regan Date: Wed, 2 Oct 2024 08:38:28 +0000 Subject: [PATCH 01/14] C0209 --- matcha/text/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matcha/text/__init__.py b/matcha/text/__init__.py index 8c75d6b..a842a73 100644 --- a/matcha/text/__init__.py +++ b/matcha/text/__init__.py @@ -48,6 +48,6 @@ def _clean_text(text, cleaner_names): for name in cleaner_names: cleaner = getattr(cleaners, name) if not cleaner: - raise Exception("Unknown cleaner: %s" % name) + raise Exception(f"Unknown cleaner: {name}") text = cleaner(text) return text From bd058a68f7c8cf61e3e402126f3bca18ee60dda0 Mon Sep 17 00:00:00 2001 From: Jim O'Regan Date: Wed, 2 Oct 2024 13:21:00 +0000 Subject: [PATCH 02/14] R0402 --- matcha/hifigan/models.py | 2 +- matcha/models/components/decoder.py | 2 +- matcha/models/components/text_encoder.py | 4 ++-- matcha/models/components/transformer.py | 2 +- matcha/models/matcha_tts.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/matcha/hifigan/models.py b/matcha/hifigan/models.py index d209d9a..4d2c7fd 100644 --- a/matcha/hifigan/models.py +++ b/matcha/hifigan/models.py @@ -1,7 +1,7 @@ """ from https://github.com/jik876/hifi-gan """ import torch -import torch.nn as nn +from torch import nn import torch.nn.functional as F from torch.nn import AvgPool1d, Conv1d, Conv2d, ConvTranspose1d from torch.nn.utils import remove_weight_norm, spectral_norm, weight_norm diff --git a/matcha/models/components/decoder.py b/matcha/models/components/decoder.py index 1137cd7..a82762e 100644 --- a/matcha/models/components/decoder.py +++ b/matcha/models/components/decoder.py @@ -2,7 +2,7 @@ import math from typing import Optional import torch -import torch.nn as nn +from torch import nn import torch.nn.functional as F from conformer import ConformerBlock from diffusers.models.activations import get_activation diff --git a/matcha/models/components/text_encoder.py b/matcha/models/components/text_encoder.py index a388d05..eb0c113 100644 --- a/matcha/models/components/text_encoder.py +++ b/matcha/models/components/text_encoder.py @@ -3,10 +3,10 @@ import math import torch -import torch.nn as nn +from torch import nn from einops import rearrange -import matcha.utils as utils +from matcha import utils from matcha.utils.model import sequence_mask log = utils.get_pylogger(__name__) diff --git a/matcha/models/components/transformer.py b/matcha/models/components/transformer.py index dd1afa3..db5dee3 100644 --- a/matcha/models/components/transformer.py +++ b/matcha/models/components/transformer.py @@ -1,7 +1,7 @@ from typing import Any, Dict, Optional import torch -import torch.nn as nn +from torch import nn from diffusers.models.attention import ( GEGLU, GELU, diff --git a/matcha/models/matcha_tts.py b/matcha/models/matcha_tts.py index 07f95ad..4aedf99 100644 --- a/matcha/models/matcha_tts.py +++ b/matcha/models/matcha_tts.py @@ -4,7 +4,7 @@ import random import torch -import matcha.utils.monotonic_align as monotonic_align +from matcha.utils import monotonic_align from matcha import utils from matcha.models.baselightningmodule import BaseLightningClass from matcha.models.components.flow_matching import CFM From c2569a101836a867a51a65eafc7594e4d4f62046 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:21:37 +0000 Subject: [PATCH 03/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- matcha/hifigan/models.py | 2 +- matcha/models/components/decoder.py | 2 +- matcha/models/components/text_encoder.py | 2 +- matcha/models/components/transformer.py | 2 +- matcha/models/matcha_tts.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/matcha/hifigan/models.py b/matcha/hifigan/models.py index 4d2c7fd..46abaf4 100644 --- a/matcha/hifigan/models.py +++ b/matcha/hifigan/models.py @@ -1,8 +1,8 @@ """ from https://github.com/jik876/hifi-gan """ import torch -from torch import nn import torch.nn.functional as F +from torch import nn from torch.nn import AvgPool1d, Conv1d, Conv2d, ConvTranspose1d from torch.nn.utils import remove_weight_norm, spectral_norm, weight_norm diff --git a/matcha/models/components/decoder.py b/matcha/models/components/decoder.py index a82762e..aca5da1 100644 --- a/matcha/models/components/decoder.py +++ b/matcha/models/components/decoder.py @@ -2,11 +2,11 @@ import math from typing import Optional import torch -from torch import nn import torch.nn.functional as F from conformer import ConformerBlock from diffusers.models.activations import get_activation from einops import pack, rearrange, repeat +from torch import nn from matcha.models.components.transformer import BasicTransformerBlock diff --git a/matcha/models/components/text_encoder.py b/matcha/models/components/text_encoder.py index eb0c113..21cc7d4 100644 --- a/matcha/models/components/text_encoder.py +++ b/matcha/models/components/text_encoder.py @@ -3,8 +3,8 @@ import math import torch -from torch import nn from einops import rearrange +from torch import nn from matcha import utils from matcha.utils.model import sequence_mask diff --git a/matcha/models/components/transformer.py b/matcha/models/components/transformer.py index db5dee3..eaf0270 100644 --- a/matcha/models/components/transformer.py +++ b/matcha/models/components/transformer.py @@ -1,7 +1,6 @@ from typing import Any, Dict, Optional import torch -from torch import nn from diffusers.models.attention import ( GEGLU, GELU, @@ -12,6 +11,7 @@ from diffusers.models.attention import ( from diffusers.models.attention_processor import Attention from diffusers.models.lora import LoRACompatibleLinear from diffusers.utils.torch_utils import maybe_allow_in_graph +from torch import nn class SnakeBeta(nn.Module): diff --git a/matcha/models/matcha_tts.py b/matcha/models/matcha_tts.py index 4aedf99..93d9689 100644 --- a/matcha/models/matcha_tts.py +++ b/matcha/models/matcha_tts.py @@ -4,11 +4,11 @@ import random import torch -from matcha.utils import monotonic_align from matcha import utils from matcha.models.baselightningmodule import BaseLightningClass from matcha.models.components.flow_matching import CFM from matcha.models.components.text_encoder import TextEncoder +from matcha.utils import monotonic_align from matcha.utils.model import ( denormalize, duration_loss, From 0000f9302100948a7f1cccf9fc85e04226046784 Mon Sep 17 00:00:00 2001 From: Jim O'Regan Date: Wed, 2 Oct 2024 13:25:02 +0000 Subject: [PATCH 04/14] R1732 + W1514 --- matcha/utils/generate_data_statistics.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/matcha/utils/generate_data_statistics.py b/matcha/utils/generate_data_statistics.py index 49ed3c1..305d806 100644 --- a/matcha/utils/generate_data_statistics.py +++ b/matcha/utils/generate_data_statistics.py @@ -102,10 +102,8 @@ def main(): log.info("Dataloader loaded! Now computing stats...") params = compute_data_statistics(data_loader, cfg["n_feats"]) print(params) - json.dump( - params, - open(output_file, "w"), - ) + with open(output_file, "w", encoding="utf-8") as dumpfile: + json.dump(params, dumpfile) if __name__ == "__main__": From 8b1284993a59172e9371026301daa81197ef240f Mon Sep 17 00:00:00 2001 From: Jim O'Regan Date: Wed, 2 Oct 2024 13:31:57 +0000 Subject: [PATCH 05/14] W1514 + R1732 --- matcha/utils/rich_utils.py | 4 ++-- setup.py | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/matcha/utils/rich_utils.py b/matcha/utils/rich_utils.py index f602f6e..1f1d6fe 100644 --- a/matcha/utils/rich_utils.py +++ b/matcha/utils/rich_utils.py @@ -72,7 +72,7 @@ def print_config_tree( # save config tree to file if save_to_file: - with open(Path(cfg.paths.output_dir, "config_tree.log"), "w") as file: + with open(Path(cfg.paths.output_dir, "config_tree.log"), "w", encoding="utf-8") as file: rich.print(tree, file=file) @@ -97,5 +97,5 @@ def enforce_tags(cfg: DictConfig, save_to_file: bool = False) -> None: log.info(f"Tags: {cfg.tags}") if save_to_file: - with open(Path(cfg.paths.output_dir, "tags.log"), "w") as file: + with open(Path(cfg.paths.output_dir, "tags.log"), "w", encoding="utf-8") as file: rich.print(cfg.tags, file=file) diff --git a/setup.py b/setup.py index a49c2cc..f9fd37e 100644 --- a/setup.py +++ b/setup.py @@ -16,9 +16,14 @@ with open("README.md", encoding="utf-8") as readme_file: README = readme_file.read() cwd = os.path.dirname(os.path.abspath(__file__)) -with open(os.path.join(cwd, "matcha", "VERSION")) as fin: +with open(os.path.join(cwd, "matcha", "VERSION"), encoding="utf-8") as fin: version = fin.read().strip() +def get_requires(): + requirements = os.path.join(os.path.dirname(__file__), "requirements.txt") + with open(requirements, encoding="utf-8") as reqfile: + return [str(r).strip() for r in reqfile] + setup( name="matcha-tts", version=version, @@ -28,7 +33,7 @@ setup( author="Shivam Mehta", author_email="shivam.mehta25@gmail.com", url="https://shivammehta25.github.io/Matcha-TTS", - install_requires=[str(r) for r in open(os.path.join(os.path.dirname(__file__), "requirements.txt"))], + install_requires=get_requires(), include_dirs=[numpy.get_include()], include_package_data=True, packages=find_packages(exclude=["tests", "tests/*", "examples", "examples/*"]), From c8178bf2cd5dca820dd5e061dc6149e7de950762 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:32:44 +0000 Subject: [PATCH 06/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f9fd37e..5375723 100644 --- a/setup.py +++ b/setup.py @@ -19,10 +19,12 @@ cwd = os.path.dirname(os.path.abspath(__file__)) with open(os.path.join(cwd, "matcha", "VERSION"), encoding="utf-8") as fin: version = fin.read().strip() + def get_requires(): requirements = os.path.join(os.path.dirname(__file__), "requirements.txt") with open(requirements, encoding="utf-8") as reqfile: - return [str(r).strip() for r in reqfile] + return [str(r).strip() for r in reqfile] + setup( name="matcha-tts", From a83fd29829c7bb9a5860f5180d756f5cea9964f5 Mon Sep 17 00:00:00 2001 From: Jim O'Regan Date: Wed, 2 Oct 2024 13:45:27 +0000 Subject: [PATCH 07/14] C0209 --- matcha/text/cleaners.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matcha/text/cleaners.py b/matcha/text/cleaners.py index 36776e3..f45ece8 100644 --- a/matcha/text/cleaners.py +++ b/matcha/text/cleaners.py @@ -38,7 +38,7 @@ _whitespace_re = re.compile(r"\s+") # List of (regular expression, replacement) pairs for abbreviations: _abbreviations = [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ ("mrs", "misess"), ("mr", "mister"), From 7cfae6bed4a46fc47bcc333c149d52d6a86a807d Mon Sep 17 00:00:00 2001 From: Jim O'Regan Date: Wed, 2 Oct 2024 13:49:47 +0000 Subject: [PATCH 08/14] add dummy exception (W0719) --- matcha/text/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/matcha/text/__init__.py b/matcha/text/__init__.py index a842a73..50d7b90 100644 --- a/matcha/text/__init__.py +++ b/matcha/text/__init__.py @@ -7,6 +7,10 @@ _symbol_to_id = {s: i for i, s in enumerate(symbols)} _id_to_symbol = {i: s for i, s in enumerate(symbols)} # pylint: disable=unnecessary-comprehension +class UnknownCleanerException(Exception): + pass + + def text_to_sequence(text, cleaner_names): """Converts a string of text to a sequence of IDs corresponding to the symbols in the text. Args: @@ -48,6 +52,6 @@ def _clean_text(text, cleaner_names): for name in cleaner_names: cleaner = getattr(cleaners, name) if not cleaner: - raise Exception(f"Unknown cleaner: {name}") + raise UnknownCleanerException(f"Unknown cleaner: {name}") text = cleaner(text) return text From 404b045b656d487312b39d655d8d73b6eef725b8 Mon Sep 17 00:00:00 2001 From: Jim O'Regan Date: Wed, 2 Oct 2024 13:51:17 +0000 Subject: [PATCH 09/14] add dummy exception (W0719) --- matcha/hifigan/denoiser.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/matcha/hifigan/denoiser.py b/matcha/hifigan/denoiser.py index 9fd3331..452be6a 100644 --- a/matcha/hifigan/denoiser.py +++ b/matcha/hifigan/denoiser.py @@ -4,6 +4,10 @@ import torch +class ModeException(Exception): + pass + + class Denoiser(torch.nn.Module): """Removes model bias from audio produced with waveglow""" @@ -20,7 +24,7 @@ class Denoiser(torch.nn.Module): elif mode == "normal": mel_input = torch.randn((1, 80, 88), dtype=dtype, device=device) else: - raise Exception(f"Mode {mode} if not supported") + raise ModeException(f"Mode {mode} if not supported") def stft_fn(audio, n_fft, hop_length, win_length, window): spec = torch.stft( From 1df73ef43e9edc8da97fee2031a52cca90c505d0 Mon Sep 17 00:00:00 2001 From: Jim O'Regan Date: Wed, 2 Oct 2024 13:55:44 +0000 Subject: [PATCH 10/14] disable global-variable-not-assigned --- matcha/hifigan/meldataset.py | 2 +- matcha/utils/audio.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/matcha/hifigan/meldataset.py b/matcha/hifigan/meldataset.py index 8b43ea7..d1b3a90 100644 --- a/matcha/hifigan/meldataset.py +++ b/matcha/hifigan/meldataset.py @@ -55,7 +55,7 @@ def mel_spectrogram(y, n_fft, num_mels, sampling_rate, hop_size, win_size, fmin, if torch.max(y) > 1.0: print("max value is ", torch.max(y)) - global mel_basis, hann_window # pylint: disable=global-statement + global mel_basis, hann_window # pylint: disable=global-statement,global-variable-not-assigned if fmax not in mel_basis: mel = librosa_mel_fn(sampling_rate, n_fft, num_mels, fmin, fmax) mel_basis[str(fmax) + "_" + str(y.device)] = torch.from_numpy(mel).float().to(y.device) diff --git a/matcha/utils/audio.py b/matcha/utils/audio.py index 0bcd74d..d257f0d 100644 --- a/matcha/utils/audio.py +++ b/matcha/utils/audio.py @@ -48,7 +48,7 @@ def mel_spectrogram(y, n_fft, num_mels, sampling_rate, hop_size, win_size, fmin, if torch.max(y) > 1.0: print("max value is ", torch.max(y)) - global mel_basis, hann_window # pylint: disable=global-statement + global mel_basis, hann_window # pylint: disable=global-statement,global-variable-not-assigned if f"{str(fmax)}_{str(y.device)}" not in mel_basis: mel = librosa_mel_fn(sr=sampling_rate, n_fft=n_fft, n_mels=num_mels, fmin=fmin, fmax=fmax) mel_basis[str(fmax) + "_" + str(y.device)] = torch.from_numpy(mel).float().to(y.device) From a220f283e3b253f95897ffaf822a2302247b08c9 Mon Sep 17 00:00:00 2001 From: Jim O'Regan Date: Wed, 2 Oct 2024 13:57:12 +0000 Subject: [PATCH 11/14] disable consider-using-generator --- matcha/data/text_mel_datamodule.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matcha/data/text_mel_datamodule.py b/matcha/data/text_mel_datamodule.py index e10dfcb..48f8266 100644 --- a/matcha/data/text_mel_datamodule.py +++ b/matcha/data/text_mel_datamodule.py @@ -234,9 +234,9 @@ class TextMelBatchCollate: def __call__(self, batch): B = len(batch) - y_max_length = max([item["y"].shape[-1] for item in batch]) + y_max_length = max([item["y"].shape[-1] for item in batch]) # pylint: disable=consider-using-generator y_max_length = fix_len_compatibility(y_max_length) - x_max_length = max([item["x"].shape[-1] for item in batch]) + x_max_length = max([item["x"].shape[-1] for item in batch]) # pylint: disable=consider-using-generator n_feats = batch[0]["y"].shape[-2] y = torch.zeros((B, n_feats, y_max_length), dtype=torch.float32) From b0ba920dc10105af712822da4bf8e3a420761233 Mon Sep 17 00:00:00 2001 From: Jim O'Regan Date: Wed, 2 Oct 2024 14:29:06 +0000 Subject: [PATCH 12/14] disable consider-using-from-import instead --- matcha/hifigan/models.py | 2 +- matcha/models/components/decoder.py | 2 +- matcha/models/components/text_encoder.py | 2 +- matcha/models/components/transformer.py | 2 +- matcha/models/matcha_tts.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/matcha/hifigan/models.py b/matcha/hifigan/models.py index 46abaf4..94b0ce9 100644 --- a/matcha/hifigan/models.py +++ b/matcha/hifigan/models.py @@ -2,7 +2,7 @@ import torch import torch.nn.functional as F -from torch import nn +import torch.nn as nn # pylint: disable=consider-using-from-import from torch.nn import AvgPool1d, Conv1d, Conv2d, ConvTranspose1d from torch.nn.utils import remove_weight_norm, spectral_norm, weight_norm diff --git a/matcha/models/components/decoder.py b/matcha/models/components/decoder.py index aca5da1..504f88b 100644 --- a/matcha/models/components/decoder.py +++ b/matcha/models/components/decoder.py @@ -2,11 +2,11 @@ import math from typing import Optional import torch +import torch.nn as nn # pylint: disable=consider-using-from-import import torch.nn.functional as F from conformer import ConformerBlock from diffusers.models.activations import get_activation from einops import pack, rearrange, repeat -from torch import nn from matcha.models.components.transformer import BasicTransformerBlock diff --git a/matcha/models/components/text_encoder.py b/matcha/models/components/text_encoder.py index 21cc7d4..36fc65a 100644 --- a/matcha/models/components/text_encoder.py +++ b/matcha/models/components/text_encoder.py @@ -3,8 +3,8 @@ import math import torch +import torch.nn as nn # pylint: disable=consider-using-from-import from einops import rearrange -from torch import nn from matcha import utils from matcha.utils.model import sequence_mask diff --git a/matcha/models/components/transformer.py b/matcha/models/components/transformer.py index eaf0270..4d604f5 100644 --- a/matcha/models/components/transformer.py +++ b/matcha/models/components/transformer.py @@ -1,6 +1,7 @@ from typing import Any, Dict, Optional import torch +import torch.nn as nn # pylint: disable=consider-using-from-import from diffusers.models.attention import ( GEGLU, GELU, @@ -11,7 +12,6 @@ from diffusers.models.attention import ( from diffusers.models.attention_processor import Attention from diffusers.models.lora import LoRACompatibleLinear from diffusers.utils.torch_utils import maybe_allow_in_graph -from torch import nn class SnakeBeta(nn.Module): diff --git a/matcha/models/matcha_tts.py b/matcha/models/matcha_tts.py index 93d9689..092fa27 100644 --- a/matcha/models/matcha_tts.py +++ b/matcha/models/matcha_tts.py @@ -4,11 +4,11 @@ import random import torch +import matcha.utils.monotonic_align as monotonic_align # pylint: disable=consider-using-from-import from matcha import utils from matcha.models.baselightningmodule import BaseLightningClass from matcha.models.components.flow_matching import CFM from matcha.models.components.text_encoder import TextEncoder -from matcha.utils import monotonic_align from matcha.utils.model import ( denormalize, duration_loss, From d56f40765cbefffcf2597ac90c9e13b236a4f36c Mon Sep 17 00:00:00 2001 From: Jim O'Regan Date: Wed, 2 Oct 2024 14:30:18 +0000 Subject: [PATCH 13/14] disable consider-using-from-import instead (missed one) --- matcha/models/components/text_encoder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matcha/models/components/text_encoder.py b/matcha/models/components/text_encoder.py index 36fc65a..66e7164 100644 --- a/matcha/models/components/text_encoder.py +++ b/matcha/models/components/text_encoder.py @@ -6,7 +6,7 @@ import torch import torch.nn as nn # pylint: disable=consider-using-from-import from einops import rearrange -from matcha import utils +import matcha.utils as utils # pylint: disable=consider-using-from-import from matcha.utils.model import sequence_mask log = utils.get_pylogger(__name__) From a3fea22988f958c74feef7a9a705b7657eb5d287 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:31:10 +0000 Subject: [PATCH 14/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- matcha/hifigan/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matcha/hifigan/models.py b/matcha/hifigan/models.py index 94b0ce9..57305ef 100644 --- a/matcha/hifigan/models.py +++ b/matcha/hifigan/models.py @@ -1,8 +1,8 @@ """ from https://github.com/jik876/hifi-gan """ import torch -import torch.nn.functional as F import torch.nn as nn # pylint: disable=consider-using-from-import +import torch.nn.functional as F from torch.nn import AvgPool1d, Conv1d, Conv2d, ConvTranspose1d from torch.nn.utils import remove_weight_norm, spectral_norm, weight_norm