refactor: reorganize imports and improve code formatting across multiple modules
This commit is contained in:
@@ -5,14 +5,13 @@ use std::time::Instant;
|
|||||||
use anyhow::{Ok, Result};
|
use anyhow::{Ok, Result};
|
||||||
|
|
||||||
use crate::exec::ExecModel;
|
use crate::exec::ExecModel;
|
||||||
|
use crate::models::GenerateModel;
|
||||||
use crate::models::qwen3_asr::generate::Qwen3AsrGenerateModel;
|
use crate::models::qwen3_asr::generate::Qwen3AsrGenerateModel;
|
||||||
use crate::models::{GenerateModel};
|
|
||||||
|
|
||||||
pub struct Qwen3ASRExec;
|
pub struct Qwen3ASRExec;
|
||||||
|
|
||||||
impl ExecModel for Qwen3ASRExec {
|
impl ExecModel for Qwen3ASRExec {
|
||||||
fn run(input: &[String], output: Option<&str>, weight_path: &str) -> Result<()> {
|
fn run(input: &[String], output: Option<&str>, weight_path: &str) -> Result<()> {
|
||||||
|
|
||||||
let i_start = Instant::now();
|
let i_start = Instant::now();
|
||||||
let mut model = Qwen3AsrGenerateModel::init(weight_path, None, None)?;
|
let mut model = Qwen3AsrGenerateModel::init(weight_path, None, None)?;
|
||||||
let i_duration = i_start.elapsed();
|
let i_duration = i_start.elapsed();
|
||||||
|
|||||||
@@ -25,7 +25,11 @@ impl Shortcut {
|
|||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let conv_0 = get_conv2d(vb.pp("0"), in_c, out_c, ks, padding, 1, 1, 1, bias)?;
|
let conv_0 = get_conv2d(vb.pp("0"), in_c, out_c, ks, padding, 1, 1, 1, bias)?;
|
||||||
let bn_1 = get_batch_norm(vb.pp("1"), 1e-5, out_c, true)?;
|
let bn_1 = get_batch_norm(vb.pp("1"), 1e-5, out_c, true)?;
|
||||||
Ok(Self { conv_0, bn_1, stride })
|
Ok(Self {
|
||||||
|
conv_0,
|
||||||
|
bn_1,
|
||||||
|
stride,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn forward(&self, x: &Tensor) -> Result<Tensor> {
|
pub fn forward(&self, x: &Tensor) -> Result<Tensor> {
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
pub mod seamless_m4t_feature_extractor;
|
|
||||||
pub mod feature_extraction_whisper;
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
pub mod feature_extraction_whisper;
|
||||||
|
pub mod seamless_m4t_feature_extractor;
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ pub struct GlmAsrNanoProcessorConfig {
|
|||||||
pub max_audio_len: usize,
|
pub max_audio_len: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||||
pub struct GlmAsrNanoConfig {
|
pub struct GlmAsrNanoConfig {
|
||||||
pub audio_config: GlmAsrAudioConfig,
|
pub audio_config: GlmAsrAudioConfig,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
use aha_openai_dive::v1::resources::chat::ChatCompletionParameters;
|
use aha_openai_dive::v1::resources::chat::ChatCompletionParameters;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use candle_core::{D, DType, Device, IndexOp, Tensor};
|
use candle_core::{D, DType, Device, IndexOp, Tensor};
|
||||||
|
|||||||
@@ -5,13 +5,16 @@ use candle_nn::VarBuilder;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
models::{
|
models::{
|
||||||
campplus::CAMPPlus, feature_extractor::seamless_m4t_feature_extractor::SeamlessM4TFeatureExtractor, index_tts2::config::{IndexTTS2Config, PreprocessParams}, mask_gct::model::RepCodec, w2v_bert_2_0::model::W2VBert2_0Model
|
campplus::CAMPPlus,
|
||||||
|
feature_extractor::seamless_m4t_feature_extractor::SeamlessM4TFeatureExtractor,
|
||||||
|
index_tts2::config::{IndexTTS2Config, PreprocessParams},
|
||||||
|
mask_gct::model::RepCodec,
|
||||||
|
w2v_bert_2_0::model::W2VBert2_0Model,
|
||||||
},
|
},
|
||||||
utils::{
|
utils::{
|
||||||
audio_utils::{
|
audio_utils::{
|
||||||
create_hann_window, extract_audio_url, get_waveform_and_window_properties, kaldi_fbank,
|
create_hann_window, extract_audio_url, get_waveform_and_window_properties, kaldi_fbank,
|
||||||
kaldi_get_mel_banks, load_audio, mel_filter_bank, resample_simple,
|
kaldi_get_mel_banks, load_audio, mel_filter_bank, resample_simple, torch_stft,
|
||||||
torch_stft,
|
|
||||||
},
|
},
|
||||||
get_vb_model_path,
|
get_vb_model_path,
|
||||||
tensor_utils::pad_reflect_last_dim,
|
tensor_utils::pad_reflect_last_dim,
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
pub mod model;
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
pub mod model;
|
||||||
|
|||||||
@@ -116,10 +116,28 @@ impl FactorizedVectorQuantize {
|
|||||||
use_l2_normlize: bool,
|
use_l2_normlize: bool,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let (in_project, out_project) = if input_dim != codebook_dim {
|
let (in_project, out_project) = if input_dim != codebook_dim {
|
||||||
let in_project =
|
let in_project = WNConv1d::new(
|
||||||
WNConv1d::new(vb.pp("in_project"), input_dim, codebook_dim, 1, 1, 0, 1, 1, true)?;
|
vb.pp("in_project"),
|
||||||
let out_project =
|
input_dim,
|
||||||
WNConv1d::new(vb.pp("out_project"), codebook_dim, input_dim, 1, 1, 0, 1, 1, true)?;
|
codebook_dim,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
)?;
|
||||||
|
let out_project = WNConv1d::new(
|
||||||
|
vb.pp("out_project"),
|
||||||
|
codebook_dim,
|
||||||
|
input_dim,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
)?;
|
||||||
(Some(in_project), Some(out_project))
|
(Some(in_project), Some(out_project))
|
||||||
} else {
|
} else {
|
||||||
(None, None)
|
(None, None)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
use aha_openai_dive::v1::resources::chat::{
|
use aha_openai_dive::v1::resources::chat::{
|
||||||
ChatCompletionChunkResponse, ChatCompletionParameters, ChatCompletionResponse,
|
ChatCompletionChunkResponse, ChatCompletionParameters, ChatCompletionResponse,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,9 +7,7 @@ use candle_nn::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
models::{
|
models::{
|
||||||
common::{
|
common::{GLU, TwoLinearMLP, eager_attention_forward, get_conv1d, get_layer_norm},
|
||||||
GLU, TwoLinearMLP, eager_attention_forward, get_conv1d, get_layer_norm,
|
|
||||||
},
|
|
||||||
w2v_bert_2_0::config::W2VBert2_0Config,
|
w2v_bert_2_0::config::W2VBert2_0Config,
|
||||||
},
|
},
|
||||||
position_embed::rope::{RoPE, apply_rotary_pos_emb},
|
position_embed::rope::{RoPE, apply_rotary_pos_emb},
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ use symphonia::core::meta::MetadataOptions;
|
|||||||
use symphonia::core::probe::Hint;
|
use symphonia::core::probe::Hint;
|
||||||
|
|
||||||
use crate::utils::get_default_save_dir;
|
use crate::utils::get_default_save_dir;
|
||||||
use crate::utils::tensor_utils::{linspace, log10, pad_reflect_last_dim, pad_replicate_last_dim, split_tensor};
|
use crate::utils::tensor_utils::{
|
||||||
|
linspace, log10, pad_reflect_last_dim, pad_replicate_last_dim, split_tensor,
|
||||||
|
};
|
||||||
|
|
||||||
// 重采样方法枚举
|
// 重采样方法枚举
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
|||||||
+6
-3
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use aha::utils::{tensor_utils::interpolate_nearest_1d};
|
use aha::utils::tensor_utils::interpolate_nearest_1d;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use candle_core::{Tensor};
|
use candle_core::Tensor;
|
||||||
// use symphonia::core::io::MediaSourceStream;
|
// use symphonia::core::io::MediaSourceStream;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -16,7 +16,10 @@ fn messy_test() -> Result<()> {
|
|||||||
let i_start = Instant::now();
|
let i_start = Instant::now();
|
||||||
let t_inter = interpolate_nearest_1d(&t, 20)?;
|
let t_inter = interpolate_nearest_1d(&t, 20)?;
|
||||||
let i_duration = i_start.elapsed();
|
let i_duration = i_start.elapsed();
|
||||||
println!("Time elapsed in interpolate_nearest_1d is: {:?}", i_duration);
|
println!(
|
||||||
|
"Time elapsed in interpolate_nearest_1d is: {:?}",
|
||||||
|
i_duration
|
||||||
|
);
|
||||||
println!("t_inter: {}", t_inter);
|
println!("t_inter: {}", t_inter);
|
||||||
// let url = "https://sis-sample-audio.obs.cn-north-1.myhuaweicloud.com/16k16bit.mp3";
|
// let url = "https://sis-sample-audio.obs.cn-north-1.myhuaweicloud.com/16k16bit.mp3";
|
||||||
// let client = reqwest::blocking::Client::new();
|
// let client = reqwest::blocking::Client::new();
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use anyhow::Result;
|
|
||||||
|
|
||||||
use aha::models::index_tts2::{generate::IndexTTS2Generate, utils::download_index_tts2_need_model};
|
use aha::models::index_tts2::{generate::IndexTTS2Generate, utils::download_index_tts2_need_model};
|
||||||
use aha_openai_dive::v1::resources::chat::ChatCompletionParameters;
|
use aha_openai_dive::v1::resources::chat::ChatCompletionParameters;
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn index_tts2_generate() -> Result<()> {
|
async fn index_tts2_generate() -> Result<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user