add Qwen3.5 model

This commit is contained in:
jhqxxx
2026-03-05 21:57:03 +08:00
parent a61b899741
commit 4ae8b0b2f4
31 changed files with 1930 additions and 121 deletions
+17 -6
View File
@@ -5,7 +5,7 @@
// use std::io::{Read, Seek};
// use std::{io::Cursor, time::Instant};
use aha::utils::interpolate::interpolate_nearest_2d;
// use aha::utils::tensor_utils::repeat_interleave;
// use aha_openai_dive::v1::resources::chat::ChatCompletionParameters;
use anyhow::Result;
// use byteorder::{LittleEndian, ReadBytesExt};
@@ -15,12 +15,23 @@ use candle_core::Tensor;
#[test]
fn messy_test() -> Result<()> {
// RUST_BACKTRACE=1 cargo test -F cuda messy_test -r -- --nocapture
// RUST_BACKTRACE=1 cargo test -F cuda --test messy_test messy_test -r -- --nocapture
let device = &candle_core::Device::Cpu;
let input = Tensor::arange(0.0f32, 25.0f32, device)?.reshape((1, 1, 5, 5))?;
println!("input: {}", input);
let x_nearest = interpolate_nearest_2d(&input, (10, 10))?;
println!("x_nearest: {}", x_nearest);
let t1 = Tensor::randn(0.0, 1.0, (16, 9, 64, 128), device)?;
let t2 = Tensor::randn(0.0, 1.0, (16, 9, 128, 64), device)?;
let out = t1.matmul(&t2)?;
println!("out shape: {:?}", out);
// let input = Tensor::arange(0.0f32, 25.0f32, device)?.reshape((5, 5))?;
// println!("input: {}", input);
// // let input = input.unsqueeze(D::Minus1)?;
// // let input = input.repeat((1, 1, 2))?;
// // let input = input.flatten(D::Minus2, D::Minus1)?;
// let output = repeat_interleave(&input, 2, 1)?;
// println!("output: {}", output);
// let x_nearest = interpolate_nearest_2d(&input, (10, 10))?;
// println!("x_nearest: {}", x_nearest);
// let input = Tensor::arange(0.0f32, 25.0f32, device)?.reshape((1, 5, 5))?;
// println!("input: {}", input);
// let x_nearest = interpolate_nearest_1d(&input, 10)?;
+1 -1
View File
@@ -6,7 +6,7 @@ use anyhow::Result;
use rocket::futures::StreamExt;
#[test]
fn fun_asr_nano_generate() -> Result<()> {
// RUST_BACKTRACE=1 cargo test -F cuda fun_asr_nano_generate -r -- --nocapture
// RUST_BACKTRACE=1 cargo test -F cuda --test test_fun_asr_nano fun_asr_nano_generate -r -- --nocapture
let save_dir =
aha::utils::get_default_save_dir().ok_or(anyhow::anyhow!("Failed to get save dir"))?;
let model_path = format!("{}/FunAudioLLM/Fun-ASR-Nano-2512/", save_dir);
+1 -1
View File
@@ -7,7 +7,7 @@ use rocket::futures::StreamExt;
#[test]
fn glm_asr_nano_generate() -> Result<()> {
// RUST_BACKTRACE=1 cargo test -F cuda glm_asr_nano_generate -r -- --nocapture
// RUST_BACKTRACE=1 cargo test -F cuda --test test_glm_asr_nano glm_asr_nano_generate -r -- --nocapture
let save_dir =
aha::utils::get_default_save_dir().ok_or(anyhow::anyhow!("Failed to get save dir"))?;
let model_path = format!("{}/ZhipuAI/GLM-ASR-Nano-2512/", save_dir);
+105
View File
@@ -0,0 +1,105 @@
use std::{pin::pin, time::Instant};
use aha::models::{GenerateModel, qwen3_5::generate::Qwen3_5GenerateModel};
use aha_openai_dive::v1::resources::chat::ChatCompletionParameters;
use anyhow::Result;
use rocket::futures::StreamExt;
#[test]
fn qwen3_5_generate() -> Result<()> {
// test with cuda: RUST_BACKTRACE=1 cargo test -F cuda --test test_qwen3_5 qwen3_5_generate -r -- --nocapture
let save_dir =
aha::utils::get_default_save_dir().ok_or(anyhow::anyhow!("Failed to get save dir"))?;
let model_path = format!("{}/Qwen/Qwen3.5-0.8B/", save_dir);
let message = r#"
{
"model": "qwen3.5",
"messages": [
{
"role": "user",
"content": [
{
"type": "image",
"image_url":
{
"url": "file:///home/jhq/Downloads/gougou1.jpg"
}
},
{
"type": "text",
"text": "描述这张图片."
}
]
}
],
"metadata": {"enable_thinking": "true"}
}
"#;
let mes: ChatCompletionParameters = serde_json::from_str(message)?;
let i_start = Instant::now();
let mut qwen3vl = Qwen3_5GenerateModel::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 res = qwen3vl.generate(mes)?;
let i_duration = i_start.elapsed();
println!("generate: \n {:?}", res);
if res.usage.is_some() {
let num_token = res.usage.as_ref().unwrap().total_tokens;
let duration_secs = i_duration.as_secs_f64();
let tps = num_token as f64 / duration_secs;
println!("Tokens per second (TPS): {:.2}", tps);
}
println!("Time elapsed in generate is: {:?}", i_duration);
Ok(())
}
#[tokio::test]
async fn qwen3_5_stream() -> Result<()> {
// test with cuda: RUST_BACKTRACE=1 cargo test -F cuda --test test_qwen3_5 qwen3_5_stream -r -- --nocapture
let save_dir =
aha::utils::get_default_save_dir().ok_or(anyhow::anyhow!("Failed to get save dir"))?;
let model_path = format!("{}/Qwen/Qwen3.5-0.8B/", save_dir);
let message = r#"
{
"model": "qwen3.5",
"messages": [
{
"role": "user",
"content": [
{
"type": "image",
"image_url":
{
"url": "file:///home/jhq/Downloads/gougou1.jpg"
}
},
{
"type": "text",
"text": "描述这张图片."
}
]
}
]
}
"#;
let mes: ChatCompletionParameters = serde_json::from_str(message)?;
let i_start = Instant::now();
let mut qwen3_5 = Qwen3_5GenerateModel::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 mut stream = pin!(qwen3_5.generate_stream(mes)?);
while let Some(item) = stream.next().await {
println!("generate: \n {:?}", item);
}
let i_duration = i_start.elapsed();
println!("Time elapsed in generate is: {:?}", i_duration);
Ok(())
}
+6 -6
View File
@@ -59,7 +59,7 @@ fn qwen3vl_thinking_generate() -> Result<()> {
#[test]
fn qwen3vl_generate() -> Result<()> {
// test with cuda: RUST_BACKTRACE=1 cargo test -F cuda,ffmpeg qwen3vl_generate -r -- --nocapture
// test with cuda: RUST_BACKTRACE=1 cargo test -F cuda --test test_qwen3vl qwen3vl_generate -r -- --nocapture
let save_dir =
aha::utils::get_default_save_dir().ok_or(anyhow::anyhow!("Failed to get save dir"))?;
@@ -73,15 +73,15 @@ fn qwen3vl_generate() -> Result<()> {
"role": "user",
"content": [
{
"type": "video",
"video_url":
"type": "image",
"image_url":
{
"url": "./assets/video/video_test.mp4"
"url": "file:///home/jhq/Downloads/gougou1.jpg"
}
},
},
{
"type": "text",
"text": "视频中发生了什么?"
"text": "描述这张图片."
}
]
}