Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused code #172

Merged
merged 25 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1b6d3eb
refactor(xtts): remove duplicate hifigan generator
eginhard Nov 20, 2024
1f27f99
refactor(utils): remove duplicate set_partial_state_dict
eginhard Nov 20, 2024
66701e1
refactor(xtts): reuse functions/classes from tortoise
eginhard Nov 21, 2024
4ba83f4
chore(tortoise): remove unused AudioMiniEncoder
eginhard Nov 21, 2024
705551c
refactor(tortoise): remove unused do_checkpoint arguments
eginhard Nov 21, 2024
5ffc054
refactor(bark): remove custom layer norm
eginhard Nov 21, 2024
490c973
refactor(xtts): use position embedding from tortoise
eginhard Nov 21, 2024
33ac0d6
refactor(xtts): use build_hf_gpt_transformer from tortoise
eginhard Nov 21, 2024
7cdfde2
refactor: move amp_to_db/db_to_amp into torch_transforms
eginhard Nov 22, 2024
6f25c2b
refactor(delightful_tts): remove unused classes
eginhard Nov 21, 2024
e63962c
refactor(losses): move shared losses into losses.py
eginhard Nov 21, 2024
2e5f68d
refactor(wavernn): remove duplicate Stretch2d
eginhard Nov 22, 2024
69a599d
refactor(freevc): remove duplicate code
eginhard Nov 22, 2024
6ecf473
refactor(xtts): use tortoise conditioning encoder
eginhard Nov 22, 2024
0f69d31
refactor(vocoder): remove duplicate function
eginhard Nov 22, 2024
fa844e0
refactor(tacotron): remove duplicate function
eginhard Nov 22, 2024
b45a7a4
refactor: move exists() and default() into generic_utils
eginhard Nov 22, 2024
54f4228
refactor(xtts): use existing cleaners
eginhard Nov 22, 2024
b1ac884
refactor: move shared function into dataset.py
eginhard Nov 22, 2024
2c82477
ci: merge integration tests back into unit tests
eginhard Nov 22, 2024
76df642
refactor: move more audio processing into torch_transforms
eginhard Nov 23, 2024
8bf288e
test: move test_helpers.py to fast unit tests
eginhard Nov 24, 2024
7330ad8
refactor: move duplicate alignment functions into helpers
eginhard Nov 24, 2024
170d3da
refactor: remove duplicate to_camel
eginhard Nov 24, 2024
63625e7
refactor: import get_last_checkpoint from trainer.io
eginhard Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/actions/setup-uv/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ runs:
using: 'composite'
steps:
- name: Install uv
uses: astral-sh/setup-uv@v3
uses: astral-sh/setup-uv@v4
with:
version: "0.5.1"
version: "0.5.4"
enable-cache: true
cache-dependency-glob: "**/pyproject.toml"
82 changes: 0 additions & 82 deletions .github/workflows/integration-tests.yml

This file was deleted.

51 changes: 48 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: unit
name: test

on:
push:
Expand All @@ -17,7 +17,7 @@ on:
required: false
default: "main"
jobs:
test:
unit:
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -62,9 +62,54 @@ jobs:
name: coverage-data-${{ matrix.subset }}-${{ matrix.python-version }}
path: .coverage.*
if-no-files-found: ignore
integration:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.12"]
subset: ["test_tts", "test_tts2", "test_vocoder", "test_xtts", "test_zoo0", "test_zoo1", "test_zoo2"]
steps:
- uses: actions/checkout@v4
- name: Setup uv
uses: ./.github/actions/setup-uv
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install Espeak
if: contains(fromJSON('["test_tts", "test_tts2", "test_xtts", "test_zoo0", "test_zoo1", "test_zoo2"]'), matrix.subset)
run: |
sudo apt-get update
sudo apt-get install espeak espeak-ng
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends git make gcc
make system-deps
- name: Install custom Trainer and/or Coqpit if requested
run: |
if [[ -n "${{ github.event.inputs.trainer_branch }}" ]]; then
uv add git+https://github.com/idiap/coqui-ai-Trainer --branch ${{ github.event.inputs.trainer_branch }}
fi
if [[ -n "${{ github.event.inputs.coqpit_branch }}" ]]; then
uv add git+https://github.com/idiap/coqui-ai-coqpit --branch ${{ github.event.inputs.coqpit_branch }}
fi
- name: Integration tests
run: |
resolution=highest
if [ "${{ matrix.python-version }}" == "3.9" ]; then
resolution=lowest-direct
fi
uv run --resolution=$resolution --extra server --extra languages make ${{ matrix.subset }}
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: coverage-data-${{ matrix.subset }}-${{ matrix.python-version }}
path: .coverage.*
if-no-files-found: ignore
coverage:
if: always()
needs: test
needs: [unit, integration]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion TTS/bin/compute_attention_masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
num_chars = len(phonemes) if C.use_phonemes else len(symbols)
# TODO: handle multi-speaker
model = setup_model(C)
model, _ = load_checkpoint(model, args.model_path, args.use_cuda, True)
model, _ = load_checkpoint(model, args.model_path, use_cuda=args.use_cuda, eval=True)

# data loader
preprocessor = importlib.import_module("TTS.tts.datasets.formatters")
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 @@ -5,10 +5,10 @@
import torchaudio
from coqpit import Coqpit
from torch import nn
from trainer.generic_utils import set_partial_state_dict
from trainer.io import load_fsspec

from TTS.encoder.losses import AngleProtoLoss, GE2ELoss, SoftmaxAngleProtoLoss
from TTS.utils.generic_utils import set_init_dict

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -130,7 +130,7 @@ def load_checkpoint(

logger.info("Partial model initialization.")
model_dict = self.state_dict()
model_dict = set_init_dict(model_dict, state["model"], c)
model_dict = set_partial_state_dict(model_dict, state["model"], config)
self.load_state_dict(model_dict)
del model_dict

Expand Down
4 changes: 2 additions & 2 deletions TTS/encoder/utils/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from dataclasses import dataclass, field

from coqpit import Coqpit
from trainer import TrainerArgs, get_last_checkpoint
from trainer import TrainerArgs
from trainer.generic_utils import get_experiment_folder_path, get_git_branch
from trainer.io import copy_model_files
from trainer.io import copy_model_files, get_last_checkpoint
from trainer.logging import logger_factory
from trainer.logging.console_logger import ConsoleLogger

Expand Down
25 changes: 25 additions & 0 deletions TTS/tts/datasets/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ def get_audio_size(audiopath: Union[str, os.PathLike[Any]]) -> int:
raise RuntimeError(msg) from e


def get_attribute_balancer_weights(items: list, attr_name: str, multi_dict: Optional[dict] = None):
"""Create inverse frequency weights for balancing the dataset.

Use `multi_dict` to scale relative weights."""
attr_names_samples = np.array([item[attr_name] for item in items])
unique_attr_names = np.unique(attr_names_samples).tolist()
attr_idx = [unique_attr_names.index(l) for l in attr_names_samples]
attr_count = np.array([len(np.where(attr_names_samples == l)[0]) for l in unique_attr_names])
weight_attr = 1.0 / attr_count
dataset_samples_weight = np.array([weight_attr[l] for l in attr_idx])
dataset_samples_weight = dataset_samples_weight / np.linalg.norm(dataset_samples_weight)
if multi_dict is not None:
# check if all keys are in the multi_dict
for k in multi_dict:
assert k in unique_attr_names, f"{k} not in {unique_attr_names}"
# scale weights
multiplier_samples = np.array([multi_dict.get(item[attr_name], 1.0) for item in items])
dataset_samples_weight *= multiplier_samples
return (
torch.from_numpy(dataset_samples_weight).float(),
unique_attr_names,
np.unique(dataset_samples_weight).tolist(),
)


class TTSDataset(Dataset):
def __init__(
self,
Expand Down
10 changes: 2 additions & 8 deletions TTS/tts/layers/bark/hubert/kmeans_hubert.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from torchaudio.functional import resample
from transformers import HubertModel

from TTS.utils.generic_utils import exists


def round_down_nearest_multiple(num, divisor):
return num // divisor * divisor
Expand All @@ -26,14 +28,6 @@ def curtail_to_multiple(t, mult, from_left=False):
return t[..., seq_slice]


def exists(val):
return val is not None


def default(val, d):
return val if exists(val) else d


class CustomHubert(nn.Module):
"""
checkpoint and kmeans can be downloaded at https://github.com/facebookresearch/fairseq/tree/main/examples/hubert
Expand Down
18 changes: 3 additions & 15 deletions TTS/tts/layers/bark/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
from torch.nn import functional as F


class LayerNorm(nn.Module):
"""LayerNorm but with an optional bias. PyTorch doesn't support simply bias=False"""

def __init__(self, ndim, bias):
super().__init__()
self.weight = nn.Parameter(torch.ones(ndim))
self.bias = nn.Parameter(torch.zeros(ndim)) if bias else None

def forward(self, x):
return F.layer_norm(x, self.weight.shape, self.weight, self.bias, 1e-5)


class CausalSelfAttention(nn.Module):
def __init__(self, config):
super().__init__()
Expand Down Expand Up @@ -119,9 +107,9 @@ def forward(self, x):
class Block(nn.Module):
def __init__(self, config, layer_idx):
super().__init__()
self.ln_1 = LayerNorm(config.n_embd, bias=config.bias)
self.ln_1 = nn.LayerNorm(config.n_embd, bias=config.bias)
self.attn = CausalSelfAttention(config)
self.ln_2 = LayerNorm(config.n_embd, bias=config.bias)
self.ln_2 = nn.LayerNorm(config.n_embd, bias=config.bias)
self.mlp = MLP(config)
self.layer_idx = layer_idx

Expand Down Expand Up @@ -158,7 +146,7 @@ def __init__(self, config):
wpe=nn.Embedding(config.block_size, config.n_embd),
drop=nn.Dropout(config.dropout),
h=nn.ModuleList([Block(config, idx) for idx in range(config.n_layer)]),
ln_f=LayerNorm(config.n_embd, bias=config.bias),
ln_f=nn.LayerNorm(config.n_embd, bias=config.bias),
)
)
self.lm_head = nn.Linear(config.n_embd, config.output_vocab_size, bias=False)
Expand Down
Loading
Loading