Skip to content

Commit

Permalink
refactor: switch steps back to option
Browse files Browse the repository at this point in the history
remove named configurations
  • Loading branch information
roedoejet committed Sep 16, 2023
1 parent 8d4755b commit d30c847
Show file tree
Hide file tree
Showing 33 changed files with 77 additions and 809 deletions.
39 changes: 7 additions & 32 deletions everyvoice/base_cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,26 @@


def load_config_base_command(
name: Enum,
model_config: Union[
DFAlignerConfig, EveryVoiceConfig, FastSpeech2Config, HiFiGANConfig
],
configs,
# Must include the above in model-specific command
config_args: List[str],
config_path: Path,
):
from everyvoice.utils import update_config_from_cli_args

if config_path:
config = model_config.load_config_from_path(config_path)
elif name:
config = model_config.load_config_from_path(configs[name.value])
else:
logger.error(
"You must either choose a <NAME> of a preconfigured dataset, or provide a <CONFIG_PATH> to a preprocessing configuration file."
)
exit()
config = model_config.load_config_from_path(config_path)

Check warning on line 47 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L47

Added line #L47 was not covered by tests

config = update_config_from_cli_args(config_args, config)
return config


def preprocess_base_command(
name: Enum,
model_config: Union[
DFAlignerConfig, EveryVoiceConfig, FastSpeech2Config, HiFiGANConfig
],
configs,
steps,
preprocess_categories,
steps: List[str],
# Must include the above in model-specific command
config_args: List[str],
config_path: Path,
Expand All @@ -78,34 +65,24 @@ def preprocess_base_command(
):
from everyvoice.preprocessor import Preprocessor

config = load_config_base_command(
name, model_config, configs, config_args, config_path
)
to_process = [x.name for x in steps]
config = load_config_base_command(model_config, config_args, config_path)

Check warning on line 68 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L68

Added line #L68 was not covered by tests
preprocessor = Preprocessor(config)
if not steps:
logger.info(
f"No specific preprocessing data requested, processing everything from dataset '{name}'"
)
to_process = list(preprocess_categories.__members__.keys())
if isinstance(config, FastSpeech2Config) and config.model.use_phonological_feats:
to_process.append("pfs")
steps.append("pfs")

Check warning on line 71 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L71

Added line #L71 was not covered by tests
preprocessor.preprocess(
output_path=output_path,
cpus=cpus,
overwrite=overwrite,
to_process=to_process,
to_process=steps,
debug=debug,
)
return preprocessor, config, to_process
return preprocessor, config, steps

Check warning on line 79 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L79

Added line #L79 was not covered by tests


def train_base_command(
name: Enum,
model_config: Union[
DFAlignerConfig, EveryVoiceConfig, FastSpeech2Config, HiFiGANConfig
],
configs,
data_module: Union[
AlignerDataModule, E2EDataModule, FastSpeech2DataModule, HiFiGANDataModule
],
Expand All @@ -119,9 +96,7 @@ def train_base_command(
nodes: int,
strategy: str,
):
config = load_config_base_command(
name, model_config, configs, config_args, config_path
)
config = load_config_base_command(model_config, config_args, config_path)

Check warning on line 99 in everyvoice/base_cli/helpers.py

View check run for this annotation

Codecov / codecov/patch

everyvoice/base_cli/helpers.py#L99

Added line #L99 was not covered by tests
logger.info("Loading modules for training...")
pbar = tqdm(range(4))
pbar.set_description("Loading pytorch and friends")
Expand Down
38 changes: 30 additions & 8 deletions everyvoice/base_cli/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,44 @@ def load_config_base_command_interface(


def preprocess_base_command_interface(
config_args: List[str] = typer.Option(None, "--config-args", "-c"),
config_path: Path = typer.Option(
None, "--config-path", "-p", exists=True, dir_okay=False, file_okay=True
config_path: Path = typer.Argument(
...,
exists=True,
dir_okay=False,
file_okay=True,
help="The path to your model configuration file.",
),
config_args: List[str] = typer.Option(
None, "-c", "--config-args", help="Overwrite the configuration"
),
output_path: Optional[Path] = typer.Option(
"filelist.psv",
"-o",
"--output",
help="The path to where the processed data filelist should be written",
),
cpus: Optional[int] = typer.Option(
min(4, mp.cpu_count()),
"-C",
"--cpus",
help="How many CPUs to use when preprocessing",
),
output_path: Optional[Path] = typer.Option("filelist.psv", "-o", "--output"),
cpus: Optional[int] = typer.Option(min(4, mp.cpu_count()), "-C", "--cpus"),
overwrite: bool = typer.Option(False, "-O", "--overwrite"),
debug: bool = typer.Option(False, "-D", "--debug"),
):
pass


def train_base_command_interface(
config_args: List[str] = typer.Option(None, "--config", "-c"),
config_path: Path = typer.Option(
None, "--config-path", "-p", exists=True, dir_okay=False, file_okay=True
config_path: Path = typer.Argument(
...,
exists=True,
dir_okay=False,
file_okay=True,
help="The path to your model configuration file.",
),
config_args: List[str] = typer.Option(
None, "-c", "--config-args", help="Overwrite the configuration"
),
accelerator: str = typer.Option(
"auto",
Expand Down
16 changes: 3 additions & 13 deletions everyvoice/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import typer

from everyvoice.config import CONFIGS
from everyvoice.model.feature_prediction.FastSpeech2_lightning.fs2.cli import (
preprocess as preprocess_fs2,
)
Expand Down Expand Up @@ -101,7 +100,7 @@ def new_dataset():
This command will preprocess all of the data you need for use with EveryVoice.
By default every step of the preprocessor will be done, but you can run specific commands by adding them as arguments for example: **everyvoice preprocess energy pitch**
By default every step of the preprocessor will be done, but you can run specific commands by adding them as options for example: **everyvoice preprocess path/to/config.yaml -s energy -s pitch**
""",
)(preprocess_fs2)

Expand Down Expand Up @@ -145,22 +144,18 @@ def new_dataset():
help="""
# Synthesize Help
- **text-to-spec** --- this is the most common model to run
- **text-to-spec** --- this is the most common model to run for performing normal speech synthesis.
- **spec-to-wav** --- this is the model that turns your spectral features into audio. It is also known as a 'vocoder'. You will typically not need to train your own version. Please refer to [https://pathtocheckpoints](https://pathtocheckpoints) for more information.
- **spec-to-wav** --- this is the model that turns your spectral features into audio. this type of synthesis is also known as copy synthesis and unless you know what you are doing, you probably don't want to do this.
""",
)

synthesize_group.command(
name="text-to-wav",
short_help="Given some text and a trained model, generate some audio",
help="Given some text and a trained model, generate some audio.",
)(synthesize_fs2)

synthesize_group.command(
name="spec-to-wav",
short_help="Given some Mel spectrograms and a trained model, generate some audio",
help="Given some Mel spectrograms and a trained model, generate some audio.",
)(synthesize_hfg)

app.add_typer(
Expand All @@ -170,11 +165,6 @@ def new_dataset():
)


_config_keys = {k: k for k in CONFIGS.keys()}

CONFIGS_ENUM = Enum("CONFIGS", _config_keys) # type: ignore


class TestSuites(str, Enum):
all = "all"
configs = "configs"
Expand Down
16 changes: 0 additions & 16 deletions everyvoice/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +0,0 @@
from pathlib import Path
from typing import Dict

from everyvoice.config import __file__ as everyvoice_file

CONFIGS: Dict[str, Path] = {
"base": Path(everyvoice_file).parent / "base" / "base_composed.yaml",
"lj": Path(everyvoice_file).parent / "lj" / "lj.yaml",
"istft": Path(everyvoice_file).parent / "lj" / "lj_istft.yaml",
"openslr": Path(everyvoice_file).parent / "openslr" / "openslr.yaml",
}


class ConfigError(Exception):
def __init__(self, msg):
super().__init__(msg)
4 changes: 0 additions & 4 deletions everyvoice/config/base/base_composed.yaml

This file was deleted.

Loading

0 comments on commit d30c847

Please sign in to comment.