begin handling hubert

This commit is contained in:
Brandon Thomas committed 2023-07-19 22:35:42 -04:00
1 parent 97a6f6e4ff
commit 20e32ff3e3
3 files changed
+16 -59

No files matched your search

@@ -31,6 +31,10 @@ pub async fn process_rvc_v2_model<'a, 'b>(
info!("Processing model file...");
redis_logger.log_status("checking rvc (v2) model")?;
// ==================== DOWNLOAD HUBERT ==================== //
let hubert_path = PathBuf::from("/home/bt/models/hubert_rvc_v2/hubert_base.pt");
// ==================== DETERMINE FILE CONTENTS ==================== //
let original_download_file_path = PathBuf::from(download_filename.clone());
@@ -65,6 +69,7 @@ pub async fn process_rvc_v2_model<'a, 'b>(
let model_check_result = job_state.sidecar_configs.rvc_v2_model_check_command.execute_check(CheckArgs {
model_path: &original_model_file_path,
maybe_model_index_path: maybe_original_model_index_file_path.as_deref(),
hubert_path: &hubert_path,
maybe_input_path: None,
output_path: &output_wav_path,
});
@@ -12,9 +12,6 @@ pub struct RvcV2ModelCheckCommand {
/// Where the python model code lives
rvc_v2_root_code_directory: PathBuf,
// /// The name of the check/process script, eg. `export_ts.py`
// check_script_name: PathBuf,
executable_or_command: ExecutableOrCommand,
/// eg. `source python/bin/activate`
@@ -29,11 +26,6 @@ pub struct RvcV2ModelCheckCommand {
/// If this is run under Docker (eg. in development), these are the options.
maybe_docker_options: Option<DockerOptions>,
// /// Supposedly where HF caches models it downloads (have not verified this!)
// maybe_huggingface_cache_dir: Option<PathBuf>,
// /// Supposedly where NLTK caches models it downloads (have not verified this!)
// maybe_nltk_cache_dir: Option<PathBuf>,
}
#[derive(Clone)]
@@ -45,11 +37,6 @@ pub enum ExecutableOrCommand {
Command(String),
}
//pub enum Device {
// Cuda,
// Cpu,
//}
pub struct CheckArgs<P: AsRef<Path>, Q: AsRef<Path>> {
/// --model_path: model path
pub model_path: P,
@@ -57,15 +44,15 @@ pub struct CheckArgs<P: AsRef<Path>, Q: AsRef<Path>> {
/// --model_index_path: model index path
pub maybe_model_index_path: Option<Q>,
/// --hubert_model_path: path to the hubert model on the filesystem
pub hubert_path: P,
/// --input_audio_filename: input wav path
/// If absent, we'll use a default test wav file
pub maybe_input_path: Option<P>,
/// --output_audio_filename: output path of wav file.
pub output_path: P,
// /// --device: cpu or cuda
// pub device: Device,
}
impl RvcV2ModelCheckCommand {
@@ -76,8 +63,6 @@ impl RvcV2ModelCheckCommand {
maybe_default_config_path: Option<P>,
maybe_default_test_wav_path: Option<P>,
maybe_docker_options: Option<DockerOptions>,
//maybe_huggingface_cache_dir: Option<P>,
//maybe_nltk_cache_dir: Option<P>,
) -> Self {
Self {
rvc_v2_root_code_directory: rvc_v2_root_code_directory.as_ref().to_path_buf(),
@@ -86,8 +71,6 @@ impl RvcV2ModelCheckCommand {
maybe_default_config_path: maybe_default_config_path.map(|p| p.as_ref().to_path_buf()),
maybe_default_test_wav_path: maybe_default_test_wav_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()),
}
}
@@ -119,11 +102,11 @@ impl RvcV2ModelCheckCommand {
let maybe_default_test_wav_path = easyenv::get_env_pathbuf_optional(
"RVC_V2_MODEL_CHECK_MAYBE_DEFAULT_TEST_WAV_PATH");
//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");
// NB: For now rvc-v2 is all that uses this hubert, but other models
// may (re)use it in the future.
let pretrained_hubert_bucket_path = easyenv::get_env_string_or_default(
"RVC_V2_PRETRAINED_HUBERT_BUCKET_PATH",
"/vocodes-private-uploads/hubert_pretrained/rvc_v2_hubert_base.pt");
let maybe_docker_options = easyenv::get_env_string_optional(
"RVC_V2_MODEL_CHECK_MAYBE_DOCKER_IMAGE")
@@ -143,8 +126,6 @@ impl RvcV2ModelCheckCommand {
maybe_docker_options,
maybe_default_config_path,
maybe_default_test_wav_path,
//maybe_huggingface_cache_dir,
//maybe_nltk_cache_dir,
})
}
@@ -162,14 +143,11 @@ impl RvcV2ModelCheckCommand {
command.push_str(" ");
}
// NB: We can't use `onnx` for model integrity checking (that might take long anyway), so
// we'll just run inference instead. That's flexible and works.
command.push_str(" && ");
match self.executable_or_command {
ExecutableOrCommand::Executable(ref executable) => {
command.push_str(&path_to_string(executable));
command.push_str(" infer ");
}
ExecutableOrCommand::Command(ref cmd) => {
command.push_str(cmd);
@@ -187,6 +165,9 @@ impl RvcV2ModelCheckCommand {
command.push_str(&path_to_string(model_index_path));
}
command.push_str(" --hubert_model_path ");
command.push_str(&path_to_string(args.hubert_path));
command.push_str(" --output_audio_filename ");
command.push_str(&path_to_string(args.output_path));
@@ -215,36 +196,8 @@ impl RvcV2ModelCheckCommand {
&command
];
//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),
// ));
// maybe_cache_dirs.push((
// OsString::from("HF_HOME"),
// 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),
// ));
// maybe_cache_dirs.push((
// OsString::from("NLTK_DATA_PATH"),
// OsString::from(cache_dir),
// ));
//}
let 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());
@@ -335,7 +335,6 @@ async fn main() -> AnyhowResult<()> {
).await;
});
let job_state = JobState {
download_temp_directory: temp_directory,
mysql_pool,