From 8cb04f1dcb145ddef9771689523bd5f92769abed Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 26 Apr 2023 04:25:43 -0700 Subject: [PATCH] huggingface+nltk caches --- .../so_vits_svc_inference_command.rs | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/crates/service/job/inference_job/src/job/job_types/vc/so_vits_svc/so_vits_svc_inference_command.rs b/crates/service/job/inference_job/src/job/job_types/vc/so_vits_svc/so_vits_svc_inference_command.rs index 881c7d0c1a..9b166ca25e 100644 --- a/crates/service/job/inference_job/src/job/job_types/vc/so_vits_svc/so_vits_svc_inference_command.rs +++ b/crates/service/job/inference_job/src/job/job_types/vc/so_vits_svc/so_vits_svc_inference_command.rs @@ -1,3 +1,4 @@ +use std::ffi::OsString; use container_common::anyhow_result::AnyhowResult; use filesys::path_to_string::path_to_string; use log::info; @@ -13,19 +14,18 @@ pub struct SoVitsSvcInferenceCommand { /// Where the so-vits-svc code lives so_vits_svc_root_code_directory: PathBuf, - // /// The name of the check/process script, eg. `export_ts.py` - // inference_script_name: PathBuf, - + /// A single executable script or a much larger bash command. + /// eg. `infer.py` vs `python3 -m so_vits_svc_fork.__main__` executable_or_command: ExecutableOrCommand, /// eg. `source python/bin/activate` maybe_virtual_env_activation_command: Option, - ///// eg. `python3` - //maybe_override_python_interpreter: Option, - /// If this is run under Docker (eg. in development), these are the options. maybe_docker_options: Option, + + maybe_huggingface_cache_dir: Option, + maybe_nltk_cache_dir: Option, } #[derive(Clone)] @@ -65,12 +65,16 @@ impl SoVitsSvcInferenceCommand { executable_or_command: ExecutableOrCommand, maybe_virtual_env_activation_command: Option<&str>, maybe_docker_options: Option, + maybe_huggingface_cache_dir: Option

, + maybe_nltk_cache_dir: Option

, ) -> Self { Self { 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_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()), } } @@ -98,8 +102,11 @@ impl SoVitsSvcInferenceCommand { let maybe_virtual_env_activation_command = easyenv::get_env_string_optional( "SO_VITS_SVC_INFERENCE_MAYBE_VENV_COMMAND"); - //let maybe_override_python_interpreter = easyenv::get_env_string_optional( - // "SO_VITS_SVC_MODEL_CHECK_MAYBE_PYTHON_INTERPRETER"); + let maybe_huggingface_cache_dir = + easyenv::get_env_pathbuf_optional("HF_DATASETS_CACHE"); + + let maybe_nltk_cache_dir = + easyenv::get_env_pathbuf_optional("NLTK_DATA"); let maybe_docker_options = easyenv::get_env_string_optional( "SO_VITS_SVC_INFERENCE_MAYBE_DOCKER_IMAGE") @@ -117,6 +124,8 @@ impl SoVitsSvcInferenceCommand { executable_or_command, maybe_virtual_env_activation_command, maybe_docker_options, + maybe_huggingface_cache_dir, + maybe_nltk_cache_dir, }) } @@ -186,9 +195,29 @@ impl SoVitsSvcInferenceCommand { &command ]; - let mut p = Popen::create(&command_parts, PopenConfig { - ..Default::default() - })?; + let mut maybe_cache_dirs = Vec::new(); + + if let Some(cache_dir) = self.maybe_huggingface_cache_dir.as_deref() { + maybe_cache_dirs.push(( + OsString::from("HF_DATASETS_CACHE"), + OsString::from(cache_dir), + )); + } + + if let Some(cache_dir) = self.maybe_nltk_cache_dir.as_deref() { + maybe_cache_dirs.push(( + OsString::from("NLTK_DATA"), + OsString::from(cache_dir), + )); + } + + let mut config = PopenConfig::default(); + + if !maybe_cache_dirs.is_empty() { + config.env = Some(maybe_cache_dirs); + } + + let mut p = Popen::create(&command_parts, config)?; info!("Subprocess PID: {:?}", p.pid());