From a9502c183b07cab68b26604fa5e764106858bfbd Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 26 Apr 2023 10:17:49 -0700 Subject: [PATCH] flexible config path for inference job --- .../config/inference-job.development.env | 1 + .../job_types/vc/so_vits_svc/process_job.rs | 4 ++-- .../so_vits_svc_inference_command.rs | 22 +++++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/service/job/inference_job/config/inference-job.development.env b/crates/service/job/inference_job/config/inference-job.development.env index 6a9be299f5..cf1f20c78f 100644 --- a/crates/service/job/inference_job/config/inference-job.development.env +++ b/crates/service/job/inference_job/config/inference-job.development.env @@ -9,6 +9,7 @@ SO_VITS_SVC_INFERENCE_ROOT_DIRECTORY="/models/voice_conversion/so-vits-svc/src/s #SO_VITS_SVC_INFERENCE_MAYBE_DOCKER_IMAGE="88ff860dd428" SO_VITS_SVC_INFERENCE_COMMAND="python3 -m so_vits_svc_fork.fakeyou_infer" SO_VITS_SVC_INFERENCE_MAYBE_DOCKER_IMAGE="7818ae323c2b" +SO_VITS_SVC_MODEL_INFERENCE_DEFAULT_CONFIG_PATH="/models/voice_conversion/so-vits-svc/example_config.json" ## Old docker image #TACOTRON2_VOCODES_DOCKER_IMAGE_SHA=1ba08f70f2ba diff --git a/crates/service/job/inference_job/src/job/job_types/vc/so_vits_svc/process_job.rs b/crates/service/job/inference_job/src/job/job_types/vc/so_vits_svc/process_job.rs index 1ba31adc61..af781bc8d7 100644 --- a/crates/service/job/inference_job/src/job/job_types/vc/so_vits_svc/process_job.rs +++ b/crates/service/job/inference_job/src/job/job_types/vc/so_vits_svc/process_job.rs @@ -139,7 +139,7 @@ pub async fn process_job(args: SoVitsSvcProcessJobArgs<'_>) -> Result) -> Result, + /// Optional default config file to use + maybe_default_config_path: Option, + /// If this is run under Docker (eg. in development), these are the options. maybe_docker_options: Option, @@ -50,7 +53,8 @@ pub struct InferenceArgs> { pub input_path: P, /// --config-path: path of the hparams json file - pub config_path: P, + /// This can fall back to a default value set at construction. + pub maybe_config_path: Option

, /// --output_path: output path of converting model to onnx (which we use to test validity) pub output_path: P, @@ -64,6 +68,7 @@ impl SoVitsSvcInferenceCommand { so_vits_svc_root_code_directory: P, executable_or_command: ExecutableOrCommand, maybe_virtual_env_activation_command: Option<&str>, + maybe_default_config_path: Option

, maybe_docker_options: Option, maybe_huggingface_cache_dir: Option

, maybe_nltk_cache_dir: Option

, @@ -72,6 +77,7 @@ impl SoVitsSvcInferenceCommand { so_vits_svc_root_code_directory: so_vits_svc_root_code_directory.as_ref().to_path_buf(), executable_or_command, maybe_virtual_env_activation_command: maybe_virtual_env_activation_command.map(|s| s.to_string()), + maybe_default_config_path: maybe_default_config_path.map(|p| p.as_ref().to_path_buf()), maybe_docker_options, maybe_huggingface_cache_dir: maybe_huggingface_cache_dir.map(|s| s.as_ref().to_path_buf()), maybe_nltk_cache_dir: maybe_nltk_cache_dir.map(|s| s.as_ref().to_path_buf()), @@ -102,6 +108,9 @@ impl SoVitsSvcInferenceCommand { let maybe_virtual_env_activation_command = easyenv::get_env_string_optional( "SO_VITS_SVC_INFERENCE_MAYBE_VENV_COMMAND"); + let maybe_default_config_path = easyenv::get_env_pathbuf_optional( + "SO_VITS_SVC_INFERENCE_MAYBE_DEFAULT_CONFIG_PATH"); + let maybe_huggingface_cache_dir = easyenv::get_env_pathbuf_optional("HF_DATASETS_CACHE"); @@ -140,6 +149,7 @@ impl SoVitsSvcInferenceCommand { so_vits_svc_root_code_directory, executable_or_command, maybe_virtual_env_activation_command, + maybe_default_config_path, maybe_docker_options, maybe_huggingface_cache_dir, maybe_nltk_cache_dir, @@ -182,8 +192,16 @@ impl SoVitsSvcInferenceCommand { command.push_str(" --output-path "); command.push_str(&path_to_string(args.output_path)); + let config_path = match args.maybe_config_path { + Some(path) => path.as_ref().to_path_buf(), + None => match self.maybe_default_config_path.as_deref() { + Some(path) => path.to_path_buf(), + None => return Err(anyhow!("no config path supplied")), + } + }; + command.push_str(" --config-path "); - command.push_str(&path_to_string(args.config_path)); + command.push_str(&path_to_string(config_path)); let device = match args.device { Device::Cuda => "cuda",