theoretically TTS HTTP works with inference-job

This commit is contained in:
Brandon Thomas committed 2023-11-27 20:55:13 -05:00
1 parent 3d4a870190
commit cc1d7f6de1
8 files changed
+78 -45

No files matched your search

+1
View File
@@ -47,6 +47,7 @@
<w>vocoder</w>
<w>vocoders</w>
<w>vocodes</w>
<w>waveglow</w>
</words>
</dictionary>
</component>
@@ -81,7 +81,7 @@ SO_VITS_SVC_INFERENCE_MAYBE_DEFAULT_CONFIG_PATH="/models/voice_conversion/so-vit
TT2_LEGACY_ROOT_DIRECTORY="/models/tts"
TT2_LEGACY_MAYBE_PYTHON_INTERPRETER="python3.6"
TT2_LEGACY_MAYBE_DOCKER_IMAGE_SHA="9f1945388110"
TT2_LEGACY_MAYBE_DOCKER_IMAGE_SHA="0d29da13e2df"
# ================================= #
# #
@@ -6,3 +6,4 @@ pub mod tacotron2_dependencies;
pub mod tacotron2_inference_command;
pub mod tacotron2_inference_sidecar_client;
pub mod tacotron2_sidecar_health_check_client;
pub mod vocoder_option;
@@ -25,7 +25,8 @@ use crate::job::job_loop::job_success_result::{JobSuccessResult, ResultEntity};
use crate::job::job_loop::process_single_job_error::ProcessSingleJobError;
use crate::job::job_types::tts::tacotron2_v2_early_fakeyou::download_static_dependencies::download_static_dependencies;
use crate::job::job_types::tts::tacotron2_v2_early_fakeyou::seconds_to_decoder_steps::seconds_to_decoder_steps;
use crate::job::job_types::tts::tacotron2_v2_early_fakeyou::tacotron2_inference_command::{InferenceArgs, MelMultiplyFactor, VocoderForInferenceOption};
use crate::job::job_types::tts::tacotron2_v2_early_fakeyou::tacotron2_inference_command::{InferenceArgs, MelMultiplyFactor};
use crate::job::job_types::tts::tacotron2_v2_early_fakeyou::vocoder_option::VocoderForInferenceOption;
use crate::job_dependencies::JobDependencies;
use crate::util::maybe_download_file_from_bucket::maybe_download_file_from_bucket;
@@ -198,7 +199,6 @@ pub async fn process_job(args: ProcessJobArgs<'_>) -> Result<JobSuccessResult, P
// ==================== RUN INFERENCE SCRIPT ==================== //
let mut maybe_mel_multiply_factor = None;
if let Some(factor) = tts_model.maybe_custom_mel_multiply_factor {
@@ -207,19 +207,38 @@ pub async fn process_job(args: ProcessJobArgs<'_>) -> Result<JobSuccessResult, P
maybe_mel_multiply_factor = Some(MelMultiplyFactor::DefaultMultiplyFactor);
}
// TODO(bt,2023-11-27): Handle LRU cache on python side
let maybe_unload_model_path = None;
let inference_start_time = Instant::now();
let _r = model_dependencies.inference_command.execute_inference(InferenceArgs {
synthesizer_checkpoint_path: &tts_synthesizer_fs_path,
text_pipeline_type: text_pipeline_type_or_guess.to_str(),
vocoder: vocoder_option,
maybe_mel_multiply_factor,
max_decoder_steps,
input_text_filename: &text_input_fs_path,
output_audio_filename: &output_audio_fs_path,
output_spectrogram_filename: &output_spectrogram_fs_path,
output_metadata_filename: &output_metadata_fs_path,
});
if model_dependencies.sidecar.use_sidecar_instead_of_shell {
let _r = model_dependencies.sidecar.inference_client.request_inference(
&cleaned_inference_text,
max_decoder_steps,
&tts_synthesizer_fs_path,
&text_pipeline_type_or_guess.to_str(),
vocoder_option,
&output_audio_fs_path,
&output_spectrogram_fs_path,
&output_metadata_fs_path,
maybe_unload_model_path,
tts_model.use_default_mel_multiply_factor,
tts_model.maybe_custom_mel_multiply_factor,
).await.map_err(|e| ProcessSingleJobError::Other(e))?;
} else {
let _r = model_dependencies.inference_command.execute_inference(InferenceArgs {
synthesizer_checkpoint_path: &tts_synthesizer_fs_path,
text_pipeline_type: text_pipeline_type_or_guess.to_str(),
vocoder: vocoder_option,
maybe_mel_multiply_factor,
max_decoder_steps,
input_text_filename: &text_input_fs_path,
output_audio_filename: &output_audio_fs_path,
output_spectrogram_filename: &output_spectrogram_fs_path,
output_metadata_filename: &output_metadata_fs_path,
});
}
let inference_duration = Instant::now().duration_since(inference_start_time);
@@ -21,6 +21,7 @@ pub struct Tacotron2Dependencies {
}
pub struct SidecarDeps {
pub use_sidecar_instead_of_shell: bool,
pub inference_client: Tacotron2InferenceSidecarClient,
pub health_check_client: Tacotron2SidecarHealthCheckClient,
}
@@ -56,6 +57,7 @@ impl Tacotron2Dependencies {
hifigan_vocoder_model_filename,
hifigan_superres_vocoder_model_filename,
sidecar: SidecarDeps {
use_sidecar_instead_of_shell: true, // TODO: ENV VAR
inference_client,
health_check_client,
}
@@ -3,10 +3,11 @@ use std::path::{Path, PathBuf};
use log::info;
use subprocess::{Popen, PopenConfig};
use errors::AnyhowResult;
use filesys::path_to_string::path_to_string;
use subprocess_common::docker_options::{DockerFilesystemMount, DockerGpu, DockerOptions};
use crate::AnyhowResult;
use crate::job::job_types::tts::tacotron2_v2_early_fakeyou::vocoder_option::VocoderForInferenceOption;
/// This command is used to run tacotron2 (v1 "early fakeyou") inference
#[derive(Clone)]
@@ -27,17 +28,6 @@ pub struct Tacotron2InferenceCommand {
maybe_docker_options: Option<DockerOptions>,
}
#[derive(Clone)]
pub enum VocoderForInferenceOption<P: AsRef<Path>> {
Waveglow {
waveglow_vocoder_checkpoint_path: P,
},
HifiganSuperres {
hifigan_vocoder_checkpoint_path: P,
hifigan_superres_vocoder_checkpoint_path: P,
}
}
pub enum MelMultiplyFactor {
// NB: Default is typically "1.4"
DefaultMultiplyFactor,
@@ -6,8 +6,11 @@ use hyper::client::Client;
use log::info;
use container_common::anyhow_result::AnyhowResult;
use filesys::path_to_string::path_to_string;
use mysql_queries::column_types::vocoder_type::VocoderType;
use crate::job::job_types::tts::tacotron2_v2_early_fakeyou::vocoder_option::VocoderForInferenceOption;
/// This is used to talk to the TT2 Python HTTP sidecar (rather than shelling out over bash).
/// This keeps models loaded in memory and results in faster inference time.
@@ -67,11 +70,8 @@ impl Tacotron2InferenceSidecarClient {
raw_text: &str,
max_decoder_steps: u32,
synthesizer_checkpoint_path: P,
vocoder_type: VocoderType,
text_pipeline_type: &str,
hifigan_vocoder_checkpoint_path: P,
hifigan_superres_vocoder_checkpoint_path: P,
waveglow_vocoder_checkpoint_path: P,
vocoder_option: VocoderForInferenceOption<P>,
output_audio_filename: P,
output_spectrogram_filename: P,
output_metadata_filename: P,
@@ -80,23 +80,30 @@ impl Tacotron2InferenceSidecarClient {
maybe_custom_mel_multiply_factor: Option<f64>,
) -> AnyhowResult<()> {
let waveglow_vocoder_checkpoint_path = waveglow_vocoder_checkpoint_path
.as_ref()
.to_str()
.map(|s| s.to_string())
.ok_or(anyhow!("bad waveglow vocoder path"))?;
// TODO(bt,2023-11-26): Clean this mutability / multi-configuration up
let vocoder_type;
let hifigan_vocoder_checkpoint_path = hifigan_vocoder_checkpoint_path
.as_ref()
.to_str()
.map(|s| s.to_string())
.ok_or(anyhow!("bad hifigan vocoder path"))?;
let waveglow_vocoder_checkpoint_path;
let hifigan_vocoder_checkpoint_path;
let hifigan_superres_vocoder_checkpoint_path;
let hifigan_superres_vocoder_checkpoint_path = hifigan_superres_vocoder_checkpoint_path
.as_ref()
.to_str()
.map(|s| s.to_string())
.ok_or(anyhow!("bad hifigan super resolution vocoder path"))?;
match vocoder_option {
VocoderForInferenceOption::Waveglow { waveglow_vocoder_checkpoint_path : path } => {
vocoder_type = VocoderType::WaveGlow;
waveglow_vocoder_checkpoint_path = path_to_string(path.as_ref());
hifigan_vocoder_checkpoint_path = "BOGUS_NOT_USED".to_string();
hifigan_superres_vocoder_checkpoint_path = "BOGUS_NOT_USED".to_string();
}
VocoderForInferenceOption::HifiganSuperres {
hifigan_vocoder_checkpoint_path: path,
hifigan_superres_vocoder_checkpoint_path : super_res_path,
} => {
vocoder_type = VocoderType::HifiGanSuperResolution;
waveglow_vocoder_checkpoint_path = "BOGUS_NOT_USED".to_string();
hifigan_vocoder_checkpoint_path = path_to_string(path.as_ref());
hifigan_superres_vocoder_checkpoint_path = path_to_string(super_res_path.as_ref());
}
}
let synthesizer_checkpoint_path = synthesizer_checkpoint_path
.as_ref()
@@ -0,0 +1,13 @@
use std::path::Path;
#[derive(Clone)]
pub enum VocoderForInferenceOption<P: AsRef<Path>> {
Waveglow {
waveglow_vocoder_checkpoint_path: P,
},
HifiganSuperres {
hifigan_vocoder_checkpoint_path: P,
hifigan_superres_vocoder_checkpoint_path: P,
}
}