delete some use

This commit is contained in:
jhqxxx
2025-10-14 20:42:03 +08:00
parent 165acf7550
commit 0fd3c7d935
6 changed files with 35 additions and 42 deletions
+1 -1
View File
@@ -453,7 +453,7 @@ impl CausalDecoder {
}
pub fn forward(&self, x: &Tensor) -> Result<Tensor> {
let x = self.model0.forward(x)?;
let x = self.model0.forward(x)?;
let mut x = self.model1.forward(&x)?;
for model_i in &self.model2_5 {
x = model_i.forward(&x)?;
+7 -6
View File
@@ -203,9 +203,9 @@ impl UnifiedCFM {
estimator: VoxCPMLocDiT,
mean_mode: bool,
) -> Result<Self> {
let solver = cfm_params.solver;
let sigma_min = cfm_params.sigma_min;
let t_scheduler = cfm_params.t_scheduler;
// let solver = cfm_params.solver;
// let sigma_min = cfm_params.sigma_min;
// let t_scheduler = cfm_params.t_scheduler;
Ok(Self {
// solver,
// sigma_min,
@@ -305,9 +305,9 @@ impl UnifiedCFM {
st_star = st_star.reshape(vec_shape)?;
}
let cfg = cfg_dphi_dt.broadcast_mul(&st_star)?;
dphi_dt = cfg.add(&dphi_dt.sub(&cfg)?.affine(cfg_value, 0.0)?)?;
dphi_dt = cfg.add(&dphi_dt.sub(&cfg)?.affine(cfg_value, 0.0)?)?; // step步的预测噪声
}
x = x.broadcast_sub(&dphi_dt.broadcast_mul(&dt)?)?;
x = x.broadcast_sub(&dphi_dt.broadcast_mul(&dt)?)?; // 逐步去噪
t = t.sub(&dt)?;
sol.push(x.clone());
if step < t_span_len - 1 {
@@ -598,10 +598,12 @@ impl VoxCPMModel {
inference_timesteps,
cfg_value,
)?;
println!("laten_pred: {}", latent_pred);
let decode_audio = self
.audio_vae
.decode(&latent_pred.to_dtype(DType::F32)?)?
.squeeze(1)?;
println!("decode_audio: {}", decode_audio);
let decode_audio_len = decode_audio.dim(D::Minus1)? - 640 - 640;
let decode_audio = decode_audio.narrow(D::Minus1, 640, decode_audio_len)?;
Ok(decode_audio)
@@ -661,7 +663,6 @@ impl VoxCPMModel {
let dit_hidden_2 = self.res_to_dit_proj.forward(&residual_hidden)?; // [b, h_dit]
let dit_hidden = dit_hidden_1.add(&dit_hidden_2)?;
let cond = prefix_feat_cond.transpose(1, 2)?.contiguous()?;
let pred_feat = self
.feat_decoder
.forward(
+1 -2
View File
@@ -1,5 +1,4 @@
use anyhow::{Ok, Result, anyhow};
use candle_core::Tensor;
use tokenizers::Tokenizer;
pub struct SingleChineseTokenizer {
@@ -48,7 +47,7 @@ impl SingleChineseTokenizer {
// println!("tokens: {:?}", tokens);
let mut split_character = Vec::new();
for token in tokens {
let clean_token = token.replace("", "to");
let clean_token = token.replace("", "");
if self.multichar_tokens.contains(&clean_token) {
let chars: Vec<String> = clean_token.chars().map(|c| c.to_string()).collect();
split_character.extend(chars);
+5 -11
View File
@@ -1,9 +1,8 @@
use anyhow::{Result, anyhow};
use candle_core::{D, DType, Device, Tensor};
use candle_nn::{Conv1d, Conv1dConfig, Module, conv1d_no_bias};
use candle_core::{D, Device, Tensor};
use candle_nn::{Conv1d, Conv1dConfig, Module};
use hound::{SampleFormat, WavReader};
use rocket::futures::future::ok;
use num::integer::gcd;
use std::f64::consts::PI;
use std::path::Path;
@@ -14,10 +13,6 @@ pub enum ResamplingMethod {
SincInterpKaiser,
}
// 计算最大公约数
fn gcd(a: i64, b: i64) -> i64 {
if b == 0 { a } else { gcd(b, a % b) }
}
// 零阶修正贝塞尔函数 I0
fn i0(x: f32) -> f32 {
@@ -65,12 +60,12 @@ pub fn get_sinc_resample_kernel(
let width_f = (lowpass_filter_width as f64) * (orig_freq as f64) / base_freq;
let width = width_f.ceil() as i64;
// 创建索引数组 [1, 1, 2*width + orig_freq_reduced]
// 创建索引数组 [1, 1, 2*width + orig_freq]
let idx = Tensor::arange(-width as f32, (width + orig_freq) as f32, device)?
.affine(1.0 / orig_freq as f64, 0.0)?
.unsqueeze(0)?
.unsqueeze(0)?;
// 创建时间数组 t [new_freq_reduced, 1, idx_len]
// 创建时间数组 t [new_freq, 1, idx_len]
let t = Tensor::arange_step(0.0, -new_freq as f32, -1.0, device)?
.affine(1.0 / new_freq as f64, 0.0)?
.unsqueeze(D::Minus1)?
@@ -270,7 +265,6 @@ pub fn load_audio<P: AsRef<Path>>(path: P, device: Device) -> Result<(Tensor, us
&device,
)?
.t()?;
// println!("audio channels: {}", spec.channels);
if spec.channels > 1 {
// 对channel通道求平均, channel维度变为1
audio_tensor = audio_tensor.mean_keepdim(0)?;