Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-0.15] .onnx/.binファイルの読み込みを遅延させる #768

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 23 additions & 33 deletions crates/voicevox_core/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ impl ModelFileSet {
predict_intonation_model,
decode_model,
}| {
let predict_duration_model = ModelFile::new(&path(predict_duration_model))?;
let predict_intonation_model = ModelFile::new(&path(predict_intonation_model))?;
let decode_model = ModelFile::new(&path(decode_model))?;
let predict_duration_model = path(predict_duration_model);
let predict_intonation_model = path(predict_intonation_model);
let decode_model = path(decode_model);
Ok(TalkModel {
predict_duration_model,
predict_intonation_model,
Expand All @@ -121,10 +121,9 @@ impl ModelFileSet {
predict_sing_volume_model,
}| {
let predict_sing_consonant_length_model =
ModelFile::new(&path(predict_sing_consonant_length_model))?;
let predict_sing_f0_model = ModelFile::new(&path(predict_sing_f0_model))?;
let predict_sing_volume_model =
ModelFile::new(&path(predict_sing_volume_model))?;
path(predict_sing_consonant_length_model);
let predict_sing_f0_model = path(predict_sing_f0_model);
let predict_sing_volume_model = path(predict_sing_volume_model);
Ok(SingTeacherModel {
predict_sing_consonant_length_model,
predict_sing_f0_model,
Expand All @@ -137,7 +136,7 @@ impl ModelFileSet {
let sf_decode_models = model_file::SF_DECODE_MODEL_FILE_NAMES
.iter()
.map(|&SfDecodeModelFileNames { sf_decode_model }| {
let sf_decode_model = ModelFile::new(&path(sf_decode_model))?;
let sf_decode_model = path(sf_decode_model);
Ok(SfDecodeModel { sf_decode_model })
})
.collect::<anyhow::Result<_>>()?;
Expand Down Expand Up @@ -195,34 +194,19 @@ struct SfDecodeModelFileNames {
struct DecryptModelError;

struct TalkModel {
predict_duration_model: ModelFile,
predict_intonation_model: ModelFile,
decode_model: ModelFile,
predict_duration_model: PathBuf,
predict_intonation_model: PathBuf,
decode_model: PathBuf,
}

struct SingTeacherModel {
predict_sing_consonant_length_model: ModelFile,
predict_sing_f0_model: ModelFile,
predict_sing_volume_model: ModelFile,
predict_sing_consonant_length_model: PathBuf,
predict_sing_f0_model: PathBuf,
predict_sing_volume_model: PathBuf,
}

struct SfDecodeModel {
sf_decode_model: ModelFile,
}

struct ModelFile {
path: PathBuf,
content: Vec<u8>,
}

impl ModelFile {
fn new(path: &Path) -> anyhow::Result<Self> {
let content = fs_err::read(path)?;
Ok(Self {
path: path.to_owned(),
content,
})
}
sf_decode_model: PathBuf,
}

#[derive(Deserialize, Getters)]
Expand Down Expand Up @@ -421,12 +405,18 @@ impl Status {

fn new_session(
&self,
model_file: &ModelFile,
model_file: &Path,
session_options: &SessionOptions,
) -> Result<Session<'static>> {
self.new_session_from_bytes(|| model_file::decrypt(&model_file.content), session_options)
let model_bytes = &match fs_err::read(model_file) {
Ok(model_bytes) => model_bytes,
Err(err) => {
panic!("ファイルを読み込めなかったためクラッシュします: {err}");
}
};
self.new_session_from_bytes(|| model_file::decrypt(model_bytes), session_options)
.map_err(|source| Error::LoadModel {
path: model_file.path.clone(),
path: model_file.to_owned(),
source,
})
}
Expand Down
Loading