Merge branch 'voxcpm1.5'

This commit is contained in:
jhqxxx
2025-12-11 23:15:05 +08:00
10 changed files with 190 additions and 58 deletions
+12 -2
View File
@@ -28,8 +28,8 @@ fn minicpm4_config() -> Result<()> {
#[test]
fn voxcpm_config() -> Result<()> {
// cargo test -F cuda,flash-attn minicpm4_config -r -- --nocapture
// cargo test -F cuda minicpm4_config -- --nocapture
// cargo test -F cuda,flash-attn voxcpm_config -r -- --nocapture
// cargo test -F cuda voxcpm_config -r -- --nocapture
let model_path = "/home/jhq/huggingface_model/openbmb/VoxCPM-0.5B/";
let config_path = model_path.to_string() + "/config.json";
let config: VoxCPMConfig = serde_json::from_slice(&std::fs::read(config_path)?)?;
@@ -37,6 +37,16 @@ fn voxcpm_config() -> Result<()> {
Ok(())
}
#[test]
fn voxcpm1_5_config() -> Result<()> {
// cargo test -F cuda voxcpm1_5_config -r -- --nocapture
let model_path = "/home/jhq/huggingface_model/OpenBMB/VoxCPM1.5/";
let config_path = model_path.to_string() + "/config.json";
let config: VoxCPMConfig = serde_json::from_slice(&std::fs::read(config_path)?)?;
println!("{:?}", config);
Ok(())
}
#[test]
fn qwen3vl_config() -> Result<()> {
// cargo test -F cuda qwen3vl_config -r -- --nocapture
+5 -5
View File
@@ -20,10 +20,10 @@ fn voxcpm_generate() -> Result<()> {
// let generate = voxcpm_generate.generate_simple("太阳当空照,花儿对我笑,小鸟说早早早".to_string())?;
let generate = voxcpm_generate.generate(
"太阳当空照,花儿对我笑,小鸟说早早早".to_string(),
// Some("啥子小师叔,打狗还要看主人,你再要继续,我,就是你的对手".to_string()),
// Some("./assets/audio/voice_01.wav".to_string()),
Some("一定被灰太狼给吃了,我已经为他准备好了花圈了".to_string()),
Some("./assets/audio/voice_05.wav".to_string()),
Some("啥子小师叔,打狗还要看主人,你再要继续,我,就是你的对手".to_string()),
Some("./assets/audio/voice_01.wav".to_string()),
// Some("一定被灰太狼给吃了,我已经为他准备好了花圈了".to_string()),
// Some("./assets/audio/voice_05.wav".to_string()),
2,
100,
10,
@@ -50,7 +50,7 @@ fn voxcpm_generate() -> Result<()> {
let i_duration = i_start.elapsed();
println!("Time elapsed in generate is: {:?}", i_duration);
save_wav(&generate, "voxcpm.wav")?;
save_wav(&generate, "voxcpm.wav", 16000)?;
Ok(())
}
+65
View File
@@ -0,0 +1,65 @@
use std::time::Instant;
use aha::{
models::voxcpm::{generate::VoxCPMGenerate, tokenizer::SingleChineseTokenizer},
utils::audio_utils::save_wav,
};
use anyhow::{Ok, Result};
#[test]
fn voxcpm1_5_generate() -> Result<()> {
// RUST_BACKTRACE=1 cargo test -F cuda voxcpm1_5_generate -r -- --nocapture
let model_path = "/home/jhq/huggingface_model/OpenBMB/VoxCPM1.5/";
let i_start = Instant::now();
let mut voxcpm_generate = VoxCPMGenerate::init(model_path, None, None)?;
let i_duration = i_start.elapsed();
println!("Time elapsed in load model is: {:?}", i_duration);
let i_start = Instant::now();
// let generate = voxcpm_generate.generate_simple("太阳当空照,花儿对我笑,小鸟说早早早".to_string())?;
let generate = voxcpm_generate.generate(
"太阳当空照,花儿对我笑,小鸟说早早早".to_string(),
Some("啥子小师叔,打狗还要看主人,你再要继续,我就是你的对手".to_string()),
Some("./assets/audio/voice_01.wav".to_string()),
// Some("一定被灰太狼给吃了,我已经为他准备好了花圈了".to_string()),
// Some("./assets/audio/voice_05.wav".to_string()),
2,
4096,
10,
2.0,
false,
6.0,
)?;
// 创建prompt_cache
// let _ = voxcpm_generate.build_prompt_cache(
// "啥子小师叔,打狗还要看主人,你再要继续,我,就是你的对手".to_string(),
// "./assets/audio/voice_01.wav".to_string(),
// )?;
// // 使用prompt_cache生成语音
// let generate = voxcpm_generate.generate_use_prompt_cache(
// "太阳当空照,花儿对我笑,小鸟说早早早".to_string(),
// 2,
// 100,
// 10,
// 2.0,
// false,
// 6.0,
// )?;
let i_duration = i_start.elapsed();
println!("Time elapsed in generate is: {:?}", i_duration);
save_wav(&generate, "voxcpm1_5.wav", 44100)?;
Ok(())
}
#[test]
fn voxcpm1_5_tokenizer() -> Result<()> {
// RUST_BACKTRACE=1 cargo test -F cuda voxcpm1_5_tokenizer -r -- --nocapture
let model_path = "/home/jhq/huggingface_model/OpenBMB/VoxCPM1.5/";
let tokenizer = SingleChineseTokenizer::new(model_path)?;
let ids = tokenizer.encode("你好啊,你吃饭了吗".to_string())?;
println!("ids: {:?}", ids);
Ok(())
}
+20
View File
@@ -46,6 +46,26 @@ fn voxcpm_weight() -> Result<()> {
Ok(())
}
#[test]
fn voxcpm1_5_weight() -> Result<()> {
let model_path = "/home/jhq/huggingface_model/OpenBMB/VoxCPM1.5/";
let model_list = find_type_files(model_path, "pth")?;
println!("model_list: {:?}", model_list);
let dev = get_device(None);
let mut dict_to_hashmap = HashMap::new();
let mut dtype = candle_core::DType::F32;
for m in model_list {
let dict = read_all_with_key(m, Some("state_dict"))?;
dtype = dict[0].1.dtype();
for (k, v) in dict {
println!("key: {}, tensor shape: {:?}", k, v);
dict_to_hashmap.insert(k, v);
}
}
Ok(())
}
#[test]
fn qwen3vl_weight() -> Result<()> {
let model_path = "/home/jhq/huggingface_model/Qwen/Qwen3-VL-4B-Instruct/";