From 1771e1dffe73da67ee142e6614fd709471be6e72 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 16 Jan 2024 20:52:11 -0500 Subject: [PATCH] fix lint/test failures --- .../inference_model_type.rs | 2 +- crates/cli/dev-database-seed/src/main.rs | 3 +- crates/cli/migration-tool/src/cli_args.rs | 47 +++++++++++++++++++ crates/cli/migration-tool/src/main.rs | 16 ++++++- .../tts/styletts2/model_downloaders.rs | 7 +-- .../tts/styletts2/process_job_create_voice.rs | 2 +- .../styletts2/process_job_inference_voice.rs | 2 +- 7 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 crates/cli/migration-tool/src/cli_args.rs diff --git a/crates/_types/enums/src/by_table/generic_inference_jobs/inference_model_type.rs b/crates/_types/enums/src/by_table/generic_inference_jobs/inference_model_type.rs index 48d7de9dce..a779157b7e 100644 --- a/crates/_types/enums/src/by_table/generic_inference_jobs/inference_model_type.rs +++ b/crates/_types/enums/src/by_table/generic_inference_jobs/inference_model_type.rs @@ -139,7 +139,7 @@ mod tests { fn all_variants() { // Static check let mut variants = InferenceModelType::all_variants(); - assert_eq!(variants.len(), 8); + assert_eq!(variants.len(), 9); assert_eq!(variants.pop_first(), Some(InferenceModelType::RvcV2)); assert_eq!(variants.pop_first(), Some(InferenceModelType::SadTalker)); assert_eq!(variants.pop_first(), Some(InferenceModelType::SoVitsSvc)); diff --git a/crates/cli/dev-database-seed/src/main.rs b/crates/cli/dev-database-seed/src/main.rs index 12d16ddd0b..6450f5c052 100644 --- a/crates/cli/dev-database-seed/src/main.rs +++ b/crates/cli/dev-database-seed/src/main.rs @@ -8,12 +8,11 @@ use errors::AnyhowResult; use crate::bucket_clients::get_bucket_clients; use crate::cli_args::parse_cli_args; use crate::seeding::model_weights::seed_weights; // V1 -use crate::seeding::seed_model_weights::seed_weights_files; // V2 v3 will come later on when everything is more conslidated and clear. use crate::seeding::seed_media_files::seed_media_files; +use crate::seeding::seed_model_weights::seed_weights_files; // V2 v3 will come later on when everything is more conslidated and clear. use crate::seeding::tts_tacotron2::seed_tts_tacotron2; use crate::seeding::users::seed_user_accounts; use crate::seeding::voice_conversion::seed_voice_conversion; -use crate::seeding::zero_shot_tts::seed_zero_shot_tts; pub mod bucket_clients; diff --git a/crates/cli/migration-tool/src/cli_args.rs b/crates/cli/migration-tool/src/cli_args.rs new file mode 100644 index 0000000000..0d39c15587 --- /dev/null +++ b/crates/cli/migration-tool/src/cli_args.rs @@ -0,0 +1,47 @@ +use std::str::FromStr; + +use clap::Parser; +use strum::{EnumCount, EnumString, IntoEnumIterator}; +use strum::EnumIter; + +use errors::{anyhow, AnyhowResult}; + +pub struct ParsedArgs { + pub action: Action, +} + +#[derive(Clone, Copy, Debug, EnumIter, EnumCount, EnumString, strum::Display)] +#[strum(serialize_all = "snake_case")] +pub enum Action { + /// Migrate VC + MigrateVoiceConversion, + /// Migrate TTS + MigrateTts, +} + +#[derive(Parser, Debug)] +#[command(name="migration-tool")] +pub struct Args { + #[arg(name="action", long="action", help="action to take", required=true)] + action: String, +} + +pub fn parse_cli_args() -> AnyhowResult { + let args = Args::parse(); + + Ok(ParsedArgs { + action: action_from_str(&args.action)?, + }) +} + + +fn action_from_str(value: &str) -> AnyhowResult { + let action = Action::from_str(value) + .map_err(|err| { + let choices = Action::iter() + .map(|e| e.to_string()) + .collect::>(); + anyhow!("parse error: {:?}, provided: \"{}\" choices: {:?}", err, value, choices) + })?; + Ok(action) +} diff --git a/crates/cli/migration-tool/src/main.rs b/crates/cli/migration-tool/src/main.rs index 79ac3a11a7..71a4270e68 100644 --- a/crates/cli/migration-tool/src/main.rs +++ b/crates/cli/migration-tool/src/main.rs @@ -14,8 +14,12 @@ use cloud_storage::bucket_client::BucketClient; use config::shared_constants::DEFAULT_RUST_LOG; use errors::AnyhowResult; +use crate::cli_args::{Action, parse_cli_args}; use crate::deps::Deps; +use crate::migrations::tts_models_to_weights::migrate::migrate_tts_to_weights; +use crate::migrations::voice_conversion_to_weights::migrate::migrate_voice_conversion_to_weights; +pub mod cli_args; pub mod deps; pub mod migrations; @@ -40,10 +44,20 @@ pub async fn main() -> AnyhowResult<()> { bucket_production_private: get_bucket_client("PRODUCTION_PRIVATE")?, }; - //migrate_voice_conversion_to_weights(&deps).await?; + let args = parse_cli_args()?; + + match args.action { + Action::MigrateVoiceConversion => { + migrate_voice_conversion_to_weights(&deps).await?; + } + Action::MigrateTts => { + migrate_tts_to_weights(&deps).await?; + } + } Ok(()) } + async fn get_mysql(env_var_name: &str) -> AnyhowResult> { info!("Connecting to MySQL {env_var_name}..."); diff --git a/crates/service/job/inference_job/src/job/job_types/tts/styletts2/model_downloaders.rs b/crates/service/job/inference_job/src/job/job_types/tts/styletts2/model_downloaders.rs index 242811b95d..fd32b2b2f8 100644 --- a/crates/service/job/inference_job/src/job/job_types/tts/styletts2/model_downloaders.rs +++ b/crates/service/job/inference_job/src/job/job_types/tts/styletts2/model_downloaders.rs @@ -1,8 +1,9 @@ use crate::util::model_downloader::ModelDownloader; -pub struct StyleTTS2Downloaders { - // pub styletts2: StyleTTS2ModelMapping, -} +pub struct StyleTTS2Downloaders; +//{ +// pub styletts2: StyleTTS2ModelMapping, +//} impl StyleTTS2Downloaders { // TODO(KS): All checkpoints are in the container, so we don't need to download them here. diff --git a/crates/service/job/inference_job/src/job/job_types/tts/styletts2/process_job_create_voice.rs b/crates/service/job/inference_job/src/job/job_types/tts/styletts2/process_job_create_voice.rs index f6ef449880..92b36939f8 100644 --- a/crates/service/job/inference_job/src/job/job_types/tts/styletts2/process_job_create_voice.rs +++ b/crates/service/job/inference_job/src/job/job_types/tts/styletts2/process_job_create_voice.rs @@ -160,7 +160,7 @@ pub async fn process_create_voice( // TODO(KS): This is a hack to get only the first file to download // Ideally we could have improved logic to pick the "best" media file from a dataset - if (index >= 0) { + if downloaded_dataset.len() >= 1 { break; } } diff --git a/crates/service/job/inference_job/src/job/job_types/tts/styletts2/process_job_inference_voice.rs b/crates/service/job/inference_job/src/job/job_types/tts/styletts2/process_job_inference_voice.rs index b602d04fbf..199181d6f1 100644 --- a/crates/service/job/inference_job/src/job/job_types/tts/styletts2/process_job_inference_voice.rs +++ b/crates/service/job/inference_job/src/job/job_types/tts/styletts2/process_job_inference_voice.rs @@ -102,7 +102,7 @@ pub async fn process_inference_voice( .new_tempdir(&work_temp_dir) .map_err(|e| ProcessSingleJobError::from_io_error(e))?; - let workdir = work_temp_dir.path().to_path_buf(); + let _workdir = work_temp_dir.path().to_path_buf(); let filename = "style.npz".to_string(); let mut downloaded_weights_path = work_temp_dir.path().to_path_buf();