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

Drop Python 3.9 support #255

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions .github/actions/setup-uv/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ runs:
using: 'composite'
steps:
- name: Install uv
uses: astral-sh/setup-uv@v4
uses: astral-sh/setup-uv@v5
with:
version: "0.5.4"
version: "0.5.17"
enable-cache: true
cache-dependency-glob: "**/pyproject.toml"
python-version: ${{ matrix.python-version }}
6 changes: 0 additions & 6 deletions .github/workflows/style_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ on:
jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [3.9]
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: Lint check
run: make lint
14 changes: 4 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9, "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]
subset: ["data_tests", "inference_tests", "test_aux", "test_text"]
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('["inference_tests", "test_text"]'), matrix.subset)
run: |
Expand All @@ -50,7 +48,7 @@ jobs:
- name: Unit tests
run: |
resolution=highest
if [ "${{ matrix.python-version }}" == "3.9" ]; then
if [ "${{ matrix.python-version }}" == "3.10" ]; then
resolution=lowest-direct
fi
uv run --resolution=$resolution --extra server --extra languages make ${{ matrix.subset }}
Expand All @@ -66,14 +64,12 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.12"]
python-version: ["3.10", "3.12"]
subset: ["test_tts", "test_tts2", "test_vocoder", "test_xtts"]
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"]'), matrix.subset)
run: |
Expand All @@ -94,7 +90,7 @@ jobs:
- name: Integration tests
run: |
resolution=highest
if [ "${{ matrix.python-version }}" == "3.9" ]; then
if [ "${{ matrix.python-version }}" == "3.10" ]; then
resolution=lowest-direct
fi
uv run --resolution=$resolution --extra server --extra languages make ${{ matrix.subset }}
Expand All @@ -116,8 +112,6 @@ jobs:
- 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
run: |
sudo apt-get update
Expand Down
8 changes: 2 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: "https://github.com/psf/black"
rev: 24.2.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
rev: v0.9.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ curl -LsSf https://astral.sh/uv/install.sh | sh
uv run make test_all # run all the tests, report all the errors
```

9. Format your code. We use ```black``` for code formatting.
9. Format your code. We use ```ruff``` for code formatting.

```bash
make style
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ test_failed: ## only run tests failed the last time.
coverage run -m pytest -x -v --last-failed tests

style: ## update code style.
uv run --only-dev black ${target_dirs}
uv run --only-dev ruff format ${target_dirs}

lint: ## run linters.
uv run --only-dev ruff check ${target_dirs}
uv run --only-dev black ${target_dirs} --check
uv run --only-dev ruff format ${target_dirs} --check

system-deps: ## install linux system deps
sudo apt-get install -y libsndfile1-dev
Expand Down
37 changes: 18 additions & 19 deletions TTS/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import tempfile
import warnings
from pathlib import Path
from typing import Optional

from torch import nn

Expand All @@ -22,15 +21,15 @@ def __init__(
self,
model_name: str = "",
*,
model_path: Optional[str] = None,
config_path: Optional[str] = None,
vocoder_name: Optional[str] = None,
vocoder_path: Optional[str] = None,
vocoder_config_path: Optional[str] = None,
encoder_path: Optional[str] = None,
encoder_config_path: Optional[str] = None,
speakers_file_path: Optional[str] = None,
language_ids_file_path: Optional[str] = None,
model_path: str | None = None,
config_path: str | None = None,
vocoder_name: str | None = None,
vocoder_path: str | None = None,
vocoder_config_path: str | None = None,
encoder_path: str | None = None,
encoder_config_path: str | None = None,
speakers_file_path: str | None = None,
language_ids_file_path: str | None = None,
progress_bar: bool = True,
gpu: bool = False,
) -> None:
Expand Down Expand Up @@ -156,8 +155,8 @@ def list_models() -> list[str]:
return ModelManager(models_file=TTS.get_models_file_path(), progress_bar=False).list_models()

def download_model_by_name(
self, model_name: str, vocoder_name: Optional[str] = None
) -> tuple[Optional[Path], Optional[Path], Optional[Path]]:
self, model_name: str, vocoder_name: str | None = None
) -> tuple[Path | None, Path | None, Path | None]:
model_path, config_path, model_item = self.manager.download_model(model_name)
if "fairseq" in model_name or (model_item is not None and isinstance(model_item["model_url"], list)):
# return model directory if there are multiple files
Expand All @@ -174,7 +173,7 @@ def download_model_by_name(
self.vocoder_config_path = vocoder_config_path
return model_path, config_path, None

def load_model_by_name(self, model_name: str, vocoder_name: Optional[str] = None, *, gpu: bool = False) -> None:
def load_model_by_name(self, model_name: str, vocoder_name: str | None = None, *, gpu: bool = False) -> None:
"""Load one of the 🐸TTS models by name.

Args:
Expand All @@ -196,7 +195,7 @@ def load_vc_model_by_name(self, model_name: str, *, gpu: bool = False) -> None:
vc_checkpoint=model_path, vc_config=config_path, model_dir=model_dir, use_cuda=gpu
)

def load_tts_model_by_name(self, model_name: str, vocoder_name: Optional[str] = None, *, gpu: bool = False) -> None:
def load_tts_model_by_name(self, model_name: str, vocoder_name: str | None = None, *, gpu: bool = False) -> None:
"""Load one of 🐸TTS models by name.

Args:
Expand Down Expand Up @@ -250,11 +249,11 @@ def load_tts_model_by_path(self, model_path: str, config_path: str, *, gpu: bool

def _check_arguments(
self,
speaker: Optional[str] = None,
language: Optional[str] = None,
speaker_wav: Optional[str] = None,
emotion: Optional[str] = None,
speed: Optional[float] = None,
speaker: str | None = None,
language: str | None = None,
speaker_wav: str | None = None,
emotion: str | None = None,
speed: float | None = None,
**kwargs,
) -> None:
"""Check if the arguments are valid for the model."""
Expand Down
6 changes: 2 additions & 4 deletions TTS/bin/compute_statistics.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import argparse
import glob
import logging
import os
import sys
from typing import Optional

import numpy as np
from tqdm import tqdm
Expand All @@ -18,7 +16,7 @@
from TTS.utils.generic_utils import ConsoleFormatter, setup_logger


def parse_args(arg_list: Optional[list[str]]) -> tuple[argparse.Namespace, list[str]]:
def parse_args(arg_list: list[str] | None) -> tuple[argparse.Namespace, list[str]]:
parser = argparse.ArgumentParser(description="Compute mean and variance of spectrogtram features.")
parser.add_argument("config_path", type=str, help="TTS config file path to define audio processin parameters.")
parser.add_argument("out_path", type=str, help="save path (directory and filename).")
Expand All @@ -31,7 +29,7 @@ def parse_args(arg_list: Optional[list[str]]) -> tuple[argparse.Namespace, list[
return parser.parse_known_args(arg_list)


def main(arg_list: Optional[list[str]] = None):
def main(arg_list: list[str] | None = None):
"""Run preprocessing process."""
setup_logger("TTS", level=logging.INFO, stream=sys.stderr, formatter=ConsoleFormatter())
args, overrides = parse_args(arg_list)
Expand Down
5 changes: 2 additions & 3 deletions TTS/bin/extract_tts_spectrograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import sys
from pathlib import Path
from typing import Optional

import numpy as np
import torch
Expand All @@ -27,7 +26,7 @@
use_cuda = torch.cuda.is_available()


def parse_args(arg_list: Optional[list[str]]) -> argparse.Namespace:
def parse_args(arg_list: list[str] | None) -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument("--config_path", type=str, help="Path to config file for training.", required=True)
parser.add_argument("--checkpoint_path", type=str, help="Model file to be restored.", required=True)
Expand Down Expand Up @@ -244,7 +243,7 @@ def extract_spectrograms(
f.write(f"{data[0] / data[1]}.npy\n")


def main(arg_list: Optional[list[str]] = None) -> None:
def main(arg_list: list[str] | None = None) -> None:
setup_logger("TTS", level=logging.INFO, stream=sys.stdout, formatter=ConsoleFormatter())
args = parse_args(arg_list)
config = load_config(args.config_path)
Expand Down
5 changes: 2 additions & 3 deletions TTS/bin/find_unique_phonemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import multiprocessing
import sys
from argparse import RawTextHelpFormatter
from typing import Optional

from tqdm.contrib.concurrent import process_map

Expand All @@ -21,7 +20,7 @@ def compute_phonemes(item: dict) -> set[str]:
return set(ph)


def parse_args(arg_list: Optional[list[str]]) -> argparse.Namespace:
def parse_args(arg_list: list[str] | None) -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="""Find all the unique characters or phonemes in a dataset.\n\n"""
"""
Expand All @@ -35,7 +34,7 @@ def parse_args(arg_list: Optional[list[str]]) -> argparse.Namespace:
return parser.parse_args(arg_list)


def main(arg_list: Optional[list[str]] = None) -> None:
def main(arg_list: list[str] | None = None) -> None:
setup_logger("TTS", level=logging.INFO, stream=sys.stdout, formatter=ConsoleFormatter())
global phonemizer
args = parse_args(arg_list)
Expand Down
5 changes: 2 additions & 3 deletions TTS/bin/synthesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import logging
import sys
from argparse import RawTextHelpFormatter
from typing import Optional

# pylint: disable=redefined-outer-name, unused-argument
from TTS.utils.generic_utils import ConsoleFormatter, setup_logger
Expand Down Expand Up @@ -135,7 +134,7 @@
"""


def parse_args(arg_list: Optional[list[str]]) -> argparse.Namespace:
def parse_args(arg_list: list[str] | None) -> argparse.Namespace:
"""Parse arguments."""
parser = argparse.ArgumentParser(
description=description.replace(" ```\n", ""),
Expand Down Expand Up @@ -310,7 +309,7 @@ def parse_args(arg_list: Optional[list[str]]) -> argparse.Namespace:
return args


def main(arg_list: Optional[list[str]] = None) -> None:
def main(arg_list: list[str] | None = None) -> None:
"""Entry point for `tts` command line interface."""
args = parse_args(arg_list)
stream = sys.stderr if args.pipe_out else sys.stdout
Expand Down
19 changes: 7 additions & 12 deletions TTS/bin/train_encoder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import logging
import os
Expand Down Expand Up @@ -219,10 +218,8 @@ def train(model, optimizer, scheduler, criterion, data_loader, eval_data_loader,

if global_step % c.print_step == 0:
print(
" | > Step:{} Loss:{:.5f} GradNorm:{:.5f} "
"StepTime:{:.2f} LoaderTime:{:.2f} AvGLoaderTime:{:.2f} LR:{:.6f}".format(
global_step, loss.item(), grad_norm, step_time, loader_time, avg_loader_time, current_lr
),
f" | > Step:{global_step} Loss:{loss.item():.5f} GradNorm:{grad_norm:.5f} "
f"StepTime:{step_time:.2f} LoaderTime:{loader_time:.2f} AvGLoaderTime:{avg_loader_time:.2f} LR:{current_lr:.6f}",
flush=True,
)

Expand All @@ -236,10 +233,8 @@ def train(model, optimizer, scheduler, criterion, data_loader, eval_data_loader,

print("")
print(
">>> Epoch:{} AvgLoss: {:.5f} GradNorm:{:.5f} "
"EpochTime:{:.2f} AvGLoaderTime:{:.2f} ".format(
epoch, tot_loss / len(data_loader), grad_norm, epoch_time, avg_loader_time
),
f">>> Epoch:{epoch} AvgLoss: {tot_loss / len(data_loader):.5f} GradNorm:{grad_norm:.5f} "
f"EpochTime:{epoch_time:.2f} AvGLoaderTime:{avg_loader_time:.2f} ",
flush=True,
)
# evaluation
Expand All @@ -249,7 +244,7 @@ def train(model, optimizer, scheduler, criterion, data_loader, eval_data_loader,
print("\n\n")
print("--> EVAL PERFORMANCE")
print(
" | > Epoch:{} AvgLoss: {:.5f} ".format(epoch, eval_loss),
f" | > Epoch:{epoch} AvgLoss: {eval_loss:.5f} ",
flush=True,
)
# save the best checkpoint
Expand Down Expand Up @@ -301,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 All @@ -311,7 +306,7 @@ def main(args): # pylint: disable=redefined-outer-name
scheduler = None

num_params = count_parameters(model)
print("\n > Model has {} parameters".format(num_params), flush=True)
print(f"\n > Model has {num_params} parameters", flush=True)

if use_cuda:
model = model.cuda()
Expand Down
3 changes: 1 addition & 2 deletions TTS/bin/train_vocoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import sys
from dataclasses import dataclass, field
from typing import Optional

from trainer import Trainer, TrainerArgs

Expand All @@ -18,7 +17,7 @@ class TrainVocoderArgs(TrainerArgs):
config_path: str = field(default=None, metadata={"help": "Path to the config file."})


def main(arg_list: Optional[list[str]] = None):
def main(arg_list: list[str] | None = None):
"""Run `tts` model training directly by a `config.json` file."""
setup_logger("TTS", level=logging.INFO, stream=sys.stdout, formatter=ConsoleFormatter())

Expand Down
Loading
Loading