diff --git a/.idea/dictionaries/bt.xml b/.idea/dictionaries/bt.xml index f4bade4273..5dc526baaf 100644 --- a/.idea/dictionaries/bt.xml +++ b/.idea/dictionaries/bt.xml @@ -17,6 +17,7 @@ hanashi hifigan hparams + huggingface replayable retryably scrollback diff --git a/crates/service/job/inference_job/src/job/job_types/tts/vits/vits_inference_command.rs b/crates/service/job/inference_job/src/job/job_types/tts/vits/vits_inference_command.rs index 670a427704..af657347c1 100644 --- a/crates/service/job/inference_job/src/job/job_types/tts/vits/vits_inference_command.rs +++ b/crates/service/job/inference_job/src/job/job_types/tts/vits/vits_inference_command.rs @@ -1,3 +1,4 @@ +use std::ffi::{OsStr, OsString}; use crate::AnyhowResult; use filesys::path_to_string::path_to_string; use log::info; @@ -20,6 +21,9 @@ pub struct VitsInferenceCommand { /// eg. `python3` maybe_override_python_interpreter: Option, + /// The directory huggingface should cache models + maybe_huggingface_cache_dir: Option, + /// If this is run under Docker (eg. in development), these are the options. maybe_docker_options: Option, } @@ -55,12 +59,14 @@ impl VitsInferenceCommand { inference_script_name: P, maybe_override_python_interpreter: Option<&str>, maybe_virtual_env_activation_command: Option<&str>, + maybe_huggingface_cache_directory: Option<&str>, maybe_docker_options: Option, ) -> Self { Self { vits_root_code_directory: vits_root_code_directory.as_ref().to_path_buf(), inference_script_name: inference_script_name.as_ref().to_path_buf(), maybe_virtual_env_activation_command: maybe_virtual_env_activation_command.map(|s| s.to_string()), + maybe_huggingface_cache_dir: maybe_huggingface_cache_directory.map(|s| s.to_string()), maybe_override_python_interpreter: maybe_override_python_interpreter.map(|s| s.to_string()), maybe_docker_options, } @@ -128,6 +134,14 @@ impl VitsInferenceCommand { &command ]; + let mut config = PopenConfig::default(); + + if let Some(cache_dir) = self.maybe_huggingface_cache_dir.as_deref() { + let name = OsString::from("HF_DATASETS_CACHE"); + let value = OsString::from(cache_dir); + config.env = Some(vec![(name, value)]) + } + let mut p = Popen::create(&command_parts, PopenConfig { ..Default::default() })?; diff --git a/crates/service/job/inference_job/src/main.rs b/crates/service/job/inference_job/src/main.rs index c2df632338..156d8a92f0 100644 --- a/crates/service/job/inference_job/src/main.rs +++ b/crates/service/job/inference_job/src/main.rs @@ -304,6 +304,9 @@ fn vits_inference_command() -> AnyhowResult { let maybe_python_interpreter = easyenv::get_env_string_optional( "VITS_INFERENCE_MAYBE_PYTHON_INTERPRETER"); + let maybe_huggingface_dataset_cache = easyenv::get_env_string_optional( + "HF_DATASETS_CACHE"); + let maybe_docker_options = easyenv::get_env_string_optional( "VITS_INFERENCE_MAYBE_DOCKER_IMAGE_SHA") .map(|image_name| { @@ -319,6 +322,7 @@ fn vits_inference_command() -> AnyhowResult { inference_script, maybe_python_interpreter.as_deref(), maybe_venv_command.as_deref(), + maybe_huggingface_dataset_cache.as_deref(), maybe_docker_options, )) } \ No newline at end of file