Skip to content

Commit

Permalink
[TTS][refactor] Part 2 - nemo.colletions.tts.parts
Browse files Browse the repository at this point in the history
Signed-off-by: Xuesong Yang <[email protected]>
  • Loading branch information
XuesongYang committed Feb 24, 2023
1 parent 7b36e62 commit b9dd766
Show file tree
Hide file tree
Showing 55 changed files with 138 additions and 136 deletions.
2 changes: 1 addition & 1 deletion examples/tts/aligner_heteronym_disambiguation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import torch

from nemo.collections.tts.models import AlignerModel
from nemo.collections.tts.torch.helpers import general_padding
from nemo.collections.tts.parts.utils.tts_dataset_utils import general_padding


"""
Expand Down
58 changes: 0 additions & 58 deletions nemo/collections/tts/data/data_utils.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from nemo.collections.nlp.metrics.classification_report import ClassificationReport
from nemo.collections.nlp.modules.common import TokenClassifier
from nemo.collections.nlp.parts.utils_funcs import tensor2list
from nemo.collections.tts.g2p.data.data_utils import get_heteronym_spans, get_wordid_to_phonemes, read_wordids
from nemo.collections.tts.g2p.data.heteronym_classification_data import HeteronymClassificationDataset
from nemo.collections.tts.parts.utils.g2p_utils import get_heteronym_spans, get_wordid_to_phonemes, read_wordids
from nemo.core.classes.common import PretrainedModelInfo
from nemo.utils import logging

Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/g2p/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
english_word_tokenize,
normalize_unicode_text,
)
from nemo.collections.tts.g2p.data.data_utils import GRAPHEME_CASE_MIXED, GRAPHEME_CASE_UPPER, set_grapheme_case
from nemo.collections.tts.parts.utils.g2p_utils import GRAPHEME_CASE_MIXED, GRAPHEME_CASE_UPPER, set_grapheme_case
from nemo.utils import logging
from nemo.utils.decorators import experimental
from nemo.utils.get_rank import is_global_rank_zero
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/losses/radttsloss.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import torch
from torch.nn import functional as F

from nemo.collections.tts.helpers.helpers import get_mask_from_lengths
from nemo.collections.tts.losses.aligner_loss import ForwardSumLoss
from nemo.collections.tts.parts.utils.helpers import get_mask_from_lengths
from nemo.core.classes import Loss


Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/losses/spectrogram_enhancer_losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from einops import rearrange
from torch.autograd import grad as torch_grad

from nemo.collections.tts.helpers.helpers import mask_sequence_tensor
from nemo.collections.tts.parts.utils.helpers import mask_sequence_tensor


class GradientPenaltyLoss(torch.nn.Module):
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/losses/tacotron2loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import torch

from nemo.collections.tts.helpers.helpers import get_mask_from_lengths
from nemo.collections.tts.parts.utils.helpers import get_mask_from_lengths
from nemo.core.classes import Loss, typecheck
from nemo.core.neural_types.elements import LengthsType, LogitsType, LossType, MelSpectrogramType
from nemo.core.neural_types.neural_type import NeuralType
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/models/aligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from pytorch_lightning.loggers import WandbLogger
from torch import nn

from nemo.collections.tts.helpers.helpers import binarize_attention, get_mask_from_lengths, plot_alignment_to_numpy
from nemo.collections.tts.losses.aligner_loss import BinLoss, ForwardSumLoss
from nemo.collections.tts.parts.utils.helpers import binarize_attention, get_mask_from_lengths, plot_alignment_to_numpy
from nemo.core.classes import ModelPT
from nemo.core.classes.common import PretrainedModelInfo
from nemo.utils import logging, model_utils
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import torch

from nemo.collections.tts.helpers.helpers import OperationMode
from nemo.collections.tts.parts.utils.helpers import OperationMode
from nemo.core.classes import ModelPT
from nemo.core.classes.common import PretrainedModelInfo, typecheck
from nemo.core.neural_types.elements import AudioSignal
Expand Down
10 changes: 5 additions & 5 deletions nemo/collections/tts/models/fastpitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
from pytorch_lightning.loggers import TensorBoardLogger

from nemo.collections.common.parts.preprocessing import parsers
from nemo.collections.tts.helpers.helpers import (
from nemo.collections.tts.losses.aligner_loss import BinLoss, ForwardSumLoss
from nemo.collections.tts.losses.fastpitchloss import DurationLoss, EnergyLoss, MelLoss, PitchLoss
from nemo.collections.tts.models.base import SpectrogramGenerator
from nemo.collections.tts.modules.fastpitch import FastPitchModule
from nemo.collections.tts.parts.utils.helpers import (
batch_from_ragged,
plot_alignment_to_numpy,
plot_spectrogram_to_numpy,
process_batch,
sample_tts_input,
)
from nemo.collections.tts.losses.aligner_loss import BinLoss, ForwardSumLoss
from nemo.collections.tts.losses.fastpitchloss import DurationLoss, EnergyLoss, MelLoss, PitchLoss
from nemo.collections.tts.models.base import SpectrogramGenerator
from nemo.collections.tts.modules.fastpitch import FastPitchModule
from nemo.core.classes import Exportable
from nemo.core.classes.common import PretrainedModelInfo, typecheck
from nemo.core.neural_types.elements import (
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/models/fastpitch_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
from pytorch_lightning import Trainer
from pytorch_lightning.loggers import TensorBoardLogger

from nemo.collections.tts.helpers.helpers import plot_multipitch_to_numpy, plot_spectrogram_to_numpy
from nemo.collections.tts.losses.fastpitchloss import DurationLoss, MelLoss, PitchLoss
from nemo.collections.tts.modules.fastpitch import FastPitchSSLModule, average_features
from nemo.collections.tts.modules.transformer import mask_from_lens
from nemo.collections.tts.parts.utils.helpers import plot_multipitch_to_numpy, plot_spectrogram_to_numpy
from nemo.core.classes import ModelPT
from nemo.core.classes.common import PretrainedModelInfo
from nemo.utils import logging, model_utils
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/models/hifigan.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
from omegaconf import DictConfig, OmegaConf, open_dict
from pytorch_lightning.loggers.wandb import WandbLogger

from nemo.collections.tts.helpers.helpers import get_batch_size, get_num_workers, plot_spectrogram_to_numpy
from nemo.collections.tts.losses.hifigan_losses import DiscriminatorLoss, FeatureMatchingLoss, GeneratorLoss
from nemo.collections.tts.models.base import Vocoder
from nemo.collections.tts.modules.hifigan_modules import MultiPeriodDiscriminator, MultiScaleDiscriminator
from nemo.collections.tts.parts.utils.helpers import get_batch_size, get_num_workers, plot_spectrogram_to_numpy
from nemo.core.classes import Exportable
from nemo.core.classes.common import PretrainedModelInfo, typecheck
from nemo.core.neural_types.elements import AudioSignal, MelSpectrogramType
Expand Down
8 changes: 4 additions & 4 deletions nemo/collections/tts/models/mixer_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
EnglishCharsTokenizer,
EnglishPhonemesTokenizer,
)
from nemo.collections.tts.helpers.helpers import (
from nemo.collections.tts.losses.aligner_loss import BinLoss, ForwardSumLoss
from nemo.collections.tts.models.base import SpectrogramGenerator
from nemo.collections.tts.modules.fastpitch import average_features, regulate_len
from nemo.collections.tts.parts.utils.helpers import (
binarize_attention_parallel,
get_mask_from_lengths,
plot_pitch_to_numpy,
plot_spectrogram_to_numpy,
)
from nemo.collections.tts.losses.aligner_loss import BinLoss, ForwardSumLoss
from nemo.collections.tts.models.base import SpectrogramGenerator
from nemo.collections.tts.modules.fastpitch import average_features, regulate_len
from nemo.core import Exportable
from nemo.core.classes.common import PretrainedModelInfo, typecheck
from nemo.core.neural_types.elements import (
Expand Down
7 changes: 3 additions & 4 deletions nemo/collections/tts/models/radtts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import contextlib
import random

import torch
from hydra.utils import instantiate
Expand All @@ -21,14 +20,14 @@
from pytorch_lightning.loggers import TensorBoardLogger

from nemo.collections.common.tokenizers.text_to_speech.tts_tokenizers import BaseTokenizer
from nemo.collections.tts.helpers.helpers import (
from nemo.collections.tts.losses.radttsloss import AttentionBinarizationLoss, RADTTSLoss
from nemo.collections.tts.models.base import SpectrogramGenerator
from nemo.collections.tts.parts.utils.helpers import (
batch_from_ragged,
plot_alignment_to_numpy,
regulate_len,
sample_tts_input,
)
from nemo.collections.tts.losses.radttsloss import AttentionBinarizationLoss, RADTTSLoss
from nemo.collections.tts.models.base import SpectrogramGenerator
from nemo.core.classes import Exportable
from nemo.core.classes.common import typecheck
from nemo.core.neural_types.elements import (
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/models/spectrogram_enhancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
from pytorch_lightning.loggers import TensorBoardLogger, WandbLogger
from torch.utils.tensorboard.writer import SummaryWriter

from nemo.collections.tts.helpers.helpers import mask_sequence_tensor, to_device_recursive
from nemo.collections.tts.losses.spectrogram_enhancer_losses import (
ConsistencyLoss,
GeneratorLoss,
GradientPenaltyLoss,
HingeLoss,
)
from nemo.collections.tts.parts.utils.helpers import mask_sequence_tensor, to_device_recursive
from nemo.core import Exportable, ModelPT, typecheck
from nemo.core.neural_types import LengthsType, MelSpectrogramType, NeuralType
from nemo.core.neural_types.elements import BoolType
Expand Down
6 changes: 3 additions & 3 deletions nemo/collections/tts/models/tacotron2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
from torch import nn

from nemo.collections.common.parts.preprocessing import parsers
from nemo.collections.tts.helpers.helpers import (
from nemo.collections.tts.losses.tacotron2loss import Tacotron2Loss
from nemo.collections.tts.models.base import SpectrogramGenerator
from nemo.collections.tts.parts.utils.helpers import (
get_mask_from_lengths,
tacotron2_log_to_tb_func,
tacotron2_log_to_wandb_func,
)
from nemo.collections.tts.losses.tacotron2loss import Tacotron2Loss
from nemo.collections.tts.models.base import SpectrogramGenerator
from nemo.core.classes.common import PretrainedModelInfo, typecheck
from nemo.core.neural_types.elements import (
AudioSignal,
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/models/two_stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from hydra.utils import instantiate
from omegaconf import MISSING, DictConfig, OmegaConf

from nemo.collections.tts.helpers.helpers import OperationMode, griffin_lim
from nemo.collections.tts.models.base import MelToSpec, Vocoder
from nemo.collections.tts.parts.utils.helpers import OperationMode, griffin_lim
from nemo.core.classes.common import PretrainedModelInfo
from nemo.core.neural_types.elements import AudioSignal, MelSpectrogramType
from nemo.core.neural_types.neural_type import NeuralType
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/models/univnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
from omegaconf import DictConfig, open_dict
from pytorch_lightning.loggers.wandb import WandbLogger

from nemo.collections.tts.helpers.helpers import get_batch_size, get_num_workers, plot_spectrogram_to_numpy
from nemo.collections.tts.losses.hifigan_losses import DiscriminatorLoss, GeneratorLoss
from nemo.collections.tts.losses.stftlosses import MultiResolutionSTFTLoss
from nemo.collections.tts.models.base import Vocoder
from nemo.collections.tts.modules.univnet_modules import MultiPeriodDiscriminator, MultiResolutionDiscriminator
from nemo.collections.tts.parts.utils.helpers import get_batch_size, get_num_workers, plot_spectrogram_to_numpy
from nemo.core import Exportable
from nemo.core.classes.common import PretrainedModelInfo, typecheck
from nemo.core.neural_types.elements import AudioSignal, MelSpectrogramType
Expand Down
3 changes: 1 addition & 2 deletions nemo/collections/tts/models/vits.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@

import omegaconf
import torch
import wandb
from hydra.utils import instantiate
from omegaconf import DictConfig, OmegaConf
from pytorch_lightning import Trainer
from pytorch_lightning.loggers import WandbLogger
from torch.cuda.amp import autocast
from torch.nn import functional as F

from nemo.collections.tts.helpers.helpers import clip_grad_value_, plot_spectrogram_to_numpy, slice_segments
from nemo.collections.tts.losses.vits_losses import DiscriminatorLoss, FeatureMatchingLoss, GeneratorLoss, KlLoss
from nemo.collections.tts.models.base import TextToWaveform
from nemo.collections.tts.modules.vits_modules import MultiPeriodDiscriminator
from nemo.collections.tts.parts.utils.helpers import clip_grad_value_, plot_spectrogram_to_numpy, slice_segments
from nemo.collections.tts.torch.data import DistributedBucketSampler
from nemo.collections.tts.torch.tts_data_types import SpeakerID
from nemo.core.classes.common import PretrainedModelInfo, typecheck
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/models/waveglow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
from omegaconf import DictConfig, open_dict
from pytorch_lightning.loggers import TensorBoardLogger

from nemo.collections.tts.helpers.helpers import OperationMode, waveglow_log_to_tb_func
from nemo.collections.tts.losses.waveglowloss import WaveGlowLoss
from nemo.collections.tts.models.base import GlowVocoder
from nemo.collections.tts.parts.utils.helpers import OperationMode, waveglow_log_to_tb_func
from nemo.core.classes import Exportable
from nemo.core.classes.common import PretrainedModelInfo, typecheck
from nemo.core.neural_types.elements import (
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/modules/aligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import torch
from torch import nn

from nemo.collections.tts.helpers.helpers import binarize_attention_parallel
from nemo.collections.tts.modules.submodules import ConvNorm
from nemo.collections.tts.parts.utils.helpers import binarize_attention_parallel


class AlignmentEncoder(torch.nn.Module):
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/modules/attribute_prediction_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import torch.nn as nn
import torch.nn.functional as F

from nemo.collections.tts.helpers.helpers import get_mask_from_lengths
from nemo.collections.tts.modules.common import ConvLSTMLinear
from nemo.collections.tts.modules.submodules import ConvNorm, MaskedInstanceNorm1d
from nemo.collections.tts.modules.transformer import FFTransformer
from nemo.collections.tts.parts.utils.helpers import get_mask_from_lengths


def get_attribute_prediction_model(config):
Expand Down
7 changes: 3 additions & 4 deletions nemo/collections/tts/modules/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
from torch.cuda import amp
from torch.cuda.amp import autocast as autocast
from torch.nn import functional as F
from torch.nn.utils.rnn import PackedSequence

from nemo.collections.tts.helpers.helpers import get_mask_from_lengths, sort_tensor, unsort_tensor
from nemo.collections.tts.helpers.splines import (
from nemo.collections.tts.modules.submodules import ConvNorm, LinearNorm, MaskedInstanceNorm1d
from nemo.collections.tts.parts.utils.helpers import get_mask_from_lengths, sort_tensor, unsort_tensor
from nemo.collections.tts.parts.utils.splines import (
piecewise_linear_inverse_transform,
piecewise_linear_transform,
unbounded_piecewise_quadratic_transform,
)
from nemo.collections.tts.modules.submodules import ConvNorm, LinearNorm, MaskedInstanceNorm1d


@torch.jit.script
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/modules/fastpitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

import torch

from nemo.collections.tts.helpers.helpers import binarize_attention_parallel, regulate_len
from nemo.collections.tts.parts.utils.helpers import binarize_attention_parallel, regulate_len
from nemo.core.classes import NeuralModule, typecheck
from nemo.core.neural_types.elements import (
EncodedRepresentation,
Expand Down
6 changes: 3 additions & 3 deletions nemo/collections/tts/modules/radtts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
import torch.nn.functional as F
from torch import nn

from nemo.collections.tts.helpers.helpers import get_mask_from_lengths
from nemo.collections.tts.helpers.helpers import mas_width1 as mas
from nemo.collections.tts.helpers.helpers import regulate_len
from nemo.collections.tts.modules.attribute_prediction_model import get_attribute_prediction_model
from nemo.collections.tts.modules.common import (
AffineTransformationLayer,
Expand All @@ -29,6 +26,9 @@
LinearNorm,
get_radtts_encoder,
)
from nemo.collections.tts.parts.utils.helpers import get_mask_from_lengths
from nemo.collections.tts.parts.utils.helpers import mas_width1 as mas
from nemo.collections.tts.parts.utils.helpers import regulate_len
from nemo.core.classes import Exportable, NeuralModule
from nemo.core.neural_types.elements import Index, LengthsType, MelSpectrogramType, TokenDurationType, TokenIndex
from nemo.core.neural_types.neural_type import NeuralType
Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/tts/modules/spectrogram_enhancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from einops import rearrange
from kornia.filters import filter2d

from nemo.collections.tts.helpers.helpers import mask_sequence_tensor
from nemo.collections.tts.parts.utils.helpers import mask_sequence_tensor


class Blur(torch.nn.Module):
Expand Down
Loading

0 comments on commit b9dd766

Please sign in to comment.