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 crate::exec::ExecModel;
|
||||
use crate::models::GenerateModel;
|
||||
use crate::models::qwen3_asr::generate::Qwen3AsrGenerateModel;
|
||||
use crate::models::{GenerateModel};
|
||||
|
||||
pub struct Qwen3ASRExec;
|
||||
|
||||
impl ExecModel for Qwen3ASRExec {
|
||||
fn run(input: &[String], output: Option<&str>, weight_path: &str) -> Result<()> {
|
||||
|
||||
let i_start = Instant::now();
|
||||
let mut model = Qwen3AsrGenerateModel::init(weight_path, None, None)?;
|
||||
let i_duration = i_start.elapsed();
|
||||
|
||||
@@ -25,7 +25,11 @@ impl Shortcut {
|
||||
) -> Result<Self> {
|
||||
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)?;
|
||||
Ok(Self { conv_0, bn_1, stride })
|
||||
Ok(Self {
|
||||
conv_0,
|
||||
bn_1,
|
||||
stride,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn forward(&self, x: &Tensor) -> Result<Tensor> {
|
||||
@@ -36,7 +40,7 @@ impl Shortcut {
|
||||
let indices = Tensor::arange(0u32, half_h as u32, x.device())?.affine(2.0, 0.0)?;
|
||||
x = x.index_select(&indices, 2)?;
|
||||
}
|
||||
x = self.bn_1.forward_t(&x, false)?;
|
||||
x = self.bn_1.forward_t(&x, false)?;
|
||||
Ok(x)
|
||||
}
|
||||
}
|
||||
@@ -106,7 +110,7 @@ impl BasicResBlock {
|
||||
} else {
|
||||
xs = xs.add(&residual)?;
|
||||
}
|
||||
xs = xs.relu()?;
|
||||
xs = xs.relu()?;
|
||||
Ok(xs)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,4 @@ pub struct FeatureExtractor {
|
||||
|
||||
fn default_sampling_rate() -> usize {
|
||||
16000
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
pub mod seamless_m4t_feature_extractor;
|
||||
pub mod config;
|
||||
pub mod feature_extraction_whisper;
|
||||
pub mod config;
|
||||
pub mod seamless_m4t_feature_extractor;
|
||||
|
||||
@@ -11,8 +11,6 @@ pub struct GlmAsrNanoProcessorConfig {
|
||||
pub max_audio_len: usize,
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
pub struct GlmAsrNanoConfig {
|
||||
pub audio_config: GlmAsrAudioConfig,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
use aha_openai_dive::v1::resources::chat::ChatCompletionParameters;
|
||||
use anyhow::Result;
|
||||
use candle_core::{D, DType, Device, IndexOp, Tensor};
|
||||
|
||||
@@ -19,7 +19,7 @@ impl IndexTTS2Generate {
|
||||
let device = get_device(device);
|
||||
let dtype = get_dtype(dtype, "bf16");
|
||||
let processor = IndexTTS2Processor::new(path, &save_dir, &config, &device, dtype)?;
|
||||
|
||||
|
||||
Ok(Self { config, processor })
|
||||
}
|
||||
pub fn generate(&mut self, mes: ChatCompletionParameters) -> Result<()> {
|
||||
|
||||
@@ -2,4 +2,4 @@ pub mod config;
|
||||
pub mod generate;
|
||||
pub mod model;
|
||||
pub mod processor;
|
||||
pub mod utils;
|
||||
pub mod utils;
|
||||
|
||||
@@ -5,13 +5,16 @@ use candle_nn::VarBuilder;
|
||||
|
||||
use crate::{
|
||||
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::{
|
||||
audio_utils::{
|
||||
create_hann_window, extract_audio_url, get_waveform_and_window_properties, kaldi_fbank,
|
||||
kaldi_get_mel_banks, load_audio, mel_filter_bank, resample_simple,
|
||||
torch_stft,
|
||||
kaldi_get_mel_banks, load_audio, mel_filter_bank, resample_simple, torch_stft,
|
||||
},
|
||||
get_vb_model_path,
|
||||
tensor_utils::pad_reflect_last_dim,
|
||||
|
||||
@@ -7,12 +7,12 @@ pub async fn download_index_tts2_need_model(save_dir: Option<&str>) -> anyhow::R
|
||||
};
|
||||
|
||||
let w2v_bert2_0 = "facebook/w2v-bert-2.0";
|
||||
let mask_gct= "amphion/MaskGCT";
|
||||
let mask_gct = "amphion/MaskGCT";
|
||||
// let campplus= "funasr/campplus"; // huggingface
|
||||
let campplus = "iic/speech_campplus_sv_zh-cn_16k-common"; // modelscope
|
||||
let campplus = "iic/speech_campplus_sv_zh-cn_16k-common"; // modelscope
|
||||
download_model(w2v_bert2_0, &save_dir, 3).await?;
|
||||
download_model(mask_gct, &save_dir, 3).await?;
|
||||
download_model(campplus, &save_dir, 3).await?;
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,4 @@ fn default_num_quantizers() -> usize {
|
||||
|
||||
fn default_downsample_scale() -> usize {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
pub mod config;
|
||||
pub mod model;
|
||||
pub mod config;
|
||||
@@ -116,10 +116,28 @@ impl FactorizedVectorQuantize {
|
||||
use_l2_normlize: bool,
|
||||
) -> Result<Self> {
|
||||
let (in_project, out_project) = if input_dim != codebook_dim {
|
||||
let in_project =
|
||||
WNConv1d::new(vb.pp("in_project"), input_dim, 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)?;
|
||||
let in_project = WNConv1d::new(
|
||||
vb.pp("in_project"),
|
||||
input_dim,
|
||||
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))
|
||||
} else {
|
||||
(None, None)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
use aha_openai_dive::v1::resources::chat::{
|
||||
ChatCompletionChunkResponse, ChatCompletionParameters, ChatCompletionResponse,
|
||||
};
|
||||
|
||||
@@ -58,4 +58,4 @@ pub struct W2VBert2_0Config {
|
||||
pub use_weighted_layer_sum: bool,
|
||||
pub vocab_size: Option<usize>,
|
||||
pub xvector_output_dim: usize,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
pub mod config;
|
||||
pub mod model;
|
||||
pub mod model;
|
||||
|
||||
@@ -7,9 +7,7 @@ use candle_nn::{
|
||||
|
||||
use crate::{
|
||||
models::{
|
||||
common::{
|
||||
GLU, TwoLinearMLP, eager_attention_forward, get_conv1d, get_layer_norm,
|
||||
},
|
||||
common::{GLU, TwoLinearMLP, eager_attention_forward, get_conv1d, get_layer_norm},
|
||||
w2v_bert_2_0::config::W2VBert2_0Config,
|
||||
},
|
||||
position_embed::rope::{RoPE, apply_rotary_pos_emb},
|
||||
@@ -488,7 +486,7 @@ impl Wav2Vec2BertEncoder {
|
||||
for (i, layer) in (&self.layers).iter().enumerate() {
|
||||
if output_hidden_states {
|
||||
hidden_states.push(xs.clone());
|
||||
}
|
||||
}
|
||||
if let Some(id) = layer_id
|
||||
&& id == i
|
||||
{
|
||||
@@ -500,7 +498,7 @@ impl Wav2Vec2BertEncoder {
|
||||
sin.as_ref(),
|
||||
attention_mask.as_ref(),
|
||||
conv_attention_mask,
|
||||
)?;
|
||||
)?;
|
||||
}
|
||||
let hidden_states = if hidden_states.len() > 0 {
|
||||
Some(hidden_states)
|
||||
|
||||
@@ -350,7 +350,7 @@ impl Qwen3VLTextRotaryEmbedding {
|
||||
|
||||
// for dim in 1..3 {
|
||||
for (dim, offset) in (1..3).enumerate() {
|
||||
let dim = dim +1;
|
||||
let dim = dim + 1;
|
||||
let length = mrope_section[dim];
|
||||
let idx = Tensor::arange_step(offset as u32, length as u32, 3, freqs.device())?;
|
||||
let src = freqs.i(dim)?.contiguous()?; // (bs, seq_len, head_dim //2)
|
||||
|
||||
@@ -32,7 +32,9 @@ use symphonia::core::meta::MetadataOptions;
|
||||
use symphonia::core::probe::Hint;
|
||||
|
||||
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)]
|
||||
|
||||
@@ -111,7 +111,7 @@ pub fn split_tensor_with_size<D: Dim>(
|
||||
// "input tensor dim size % splits_size must be equal to 0"
|
||||
// );
|
||||
for (i, split) in (0..dim_size).step_by(splits_size).enumerate() {
|
||||
let size = splits_size.min(dim_size - i*splits_size);
|
||||
let size = splits_size.min(dim_size - i * splits_size);
|
||||
split_res.push(t.narrow(dim, split, size)?);
|
||||
}
|
||||
Ok(split_res)
|
||||
|
||||
Reference in New Issue
Block a user