update format

This commit is contained in:
jhqxxx
2025-09-22 23:58:08 +08:00
parent fdfdfedeb4
commit ec989f397f
8 changed files with 31 additions and 23 deletions
+7 -3
View File
@@ -1,7 +1,9 @@
pub mod qwen2_5vl; pub mod qwen2_5vl;
use anyhow::Result; use anyhow::Result;
use candle_core::{DType, Device}; use candle_core::{DType, Device};
use openai_dive::v1::resources::chat::{ChatCompletionChunkResponse, ChatCompletionParameters, ChatCompletionResponse}; use openai_dive::v1::resources::chat::{
ChatCompletionChunkResponse, ChatCompletionParameters, ChatCompletionResponse,
};
use rocket::futures::Stream; use rocket::futures::Stream;
pub trait GenerateModel { pub trait GenerateModel {
@@ -9,6 +11,8 @@ pub trait GenerateModel {
where where
Self: Sized; Self: Sized;
fn generate(&mut self, mes: ChatCompletionParameters) -> Result<ChatCompletionResponse>; fn generate(&mut self, mes: ChatCompletionParameters) -> Result<ChatCompletionResponse>;
fn generate_stream(&mut self, mes: ChatCompletionParameters) -> Result<impl Stream<Item = Result<ChatCompletionChunkResponse, anyhow::Error>>>; fn generate_stream(
&mut self,
mes: ChatCompletionParameters,
) -> Result<impl Stream<Item = Result<ChatCompletionChunkResponse, anyhow::Error>>>;
} }
+1 -1
View File
@@ -1,4 +1,4 @@
pub mod config; pub mod config;
pub mod generate;
pub mod model; pub mod model;
pub mod processor; pub mod processor;
pub mod generate;
+1 -1
View File
@@ -1 +1 @@
pub mod tokenizer; pub mod tokenizer;
+1
View File
@@ -0,0 +1 @@
+2 -2
View File
@@ -1,4 +1,4 @@
pub mod img_utils;
pub mod tensor_utils; pub mod tensor_utils;
pub mod utils; pub mod utils;
pub mod img_utils; pub mod video_utils;
pub mod video_utils;
+3 -1
View File
@@ -3,7 +3,9 @@ use candle_core::{DType, Device};
use candle_transformers::generation::LogitsProcessor; use candle_transformers::generation::LogitsProcessor;
use openai_dive::v1::resources::{ use openai_dive::v1::resources::{
chat::{ chat::{
ChatCompletionChoice, ChatCompletionChunkChoice, ChatCompletionChunkResponse, ChatCompletionResponse, ChatMessage, ChatMessageContent, DeltaChatMessage, DeltaFunction, DeltaToolCall, Function, ToolCall ChatCompletionChoice, ChatCompletionChunkChoice, ChatCompletionChunkResponse,
ChatCompletionResponse, ChatMessage, ChatMessageContent, DeltaChatMessage, DeltaFunction,
DeltaToolCall, Function, ToolCall,
}, },
shared::FinishReason, shared::FinishReason,
}; };
+2 -2
View File
@@ -1,5 +1,5 @@
use anyhow::Result;
use aha::models::qwen2_5vl::config::Config; use aha::models::qwen2_5vl::config::Config;
use anyhow::Result;
#[test] #[test]
fn qwen2_5vl_config() -> Result<()> { fn qwen2_5vl_config() -> Result<()> {
@@ -9,4 +9,4 @@ fn qwen2_5vl_config() -> Result<()> {
let config: Config = serde_json::from_slice(&std::fs::read(config_path)?)?; let config: Config = serde_json::from_slice(&std::fs::read(config_path)?)?;
println!("{:?}", config); println!("{:?}", config);
Ok(()) Ok(())
} }
+14 -13
View File
@@ -1,12 +1,14 @@
use std::{pin::pin, time::Instant}; use std::{pin::pin, time::Instant};
use aha::{models::{qwen2_5vl::generate::Qwen2_5VLGenerateModel, GenerateModel}, ModelType}; use aha::{
use anyhow::{Result}; ModelType,
models::{GenerateModel, qwen2_5vl::generate::Qwen2_5VLGenerateModel},
};
use anyhow::Result;
use candle_core::{DType, Device}; use candle_core::{DType, Device};
use openai_dive::v1::resources::chat::ChatCompletionParameters; use openai_dive::v1::resources::chat::ChatCompletionParameters;
use rocket::futures::StreamExt; use rocket::futures::StreamExt;
#[test] #[test]
fn qwen2_5vl_generate() -> Result<()> { fn qwen2_5vl_generate() -> Result<()> {
// test with cpu :(太慢了, : RUST_BACKTRACE=1 cargo test qwen2_5vl_generate -- --nocapture // test with cpu :(太慢了, : RUST_BACKTRACE=1 cargo test qwen2_5vl_generate -- --nocapture
@@ -16,7 +18,7 @@ fn qwen2_5vl_generate() -> Result<()> {
let dtype = DType::BF16; let dtype = DType::BF16;
let model_path = "/home/jhq/huggingface_model/Qwen/Qwen2.5-VL-3B-Instruct/"; let model_path = "/home/jhq/huggingface_model/Qwen/Qwen2.5-VL-3B-Instruct/";
let message = r#" let message = r#"
{ {
"model": "qwen2.5vl", "model": "qwen2.5vl",
@@ -40,7 +42,7 @@ fn qwen2_5vl_generate() -> Result<()> {
] ]
} }
"#; "#;
let mes:ChatCompletionParameters = serde_json::from_str(message)?; let mes: ChatCompletionParameters = serde_json::from_str(message)?;
let i_start = Instant::now(); let i_start = Instant::now();
// let mut model = Qwen2_5VLGenerateModel::init(model_path, &device, dtype)?; // let mut model = Qwen2_5VLGenerateModel::init(model_path, &device, dtype)?;
let mut model = ModelType::init(ModelType::Qwen2_5VL, model_path, None, None)?; let mut model = ModelType::init(ModelType::Qwen2_5VL, model_path, None, None)?;
@@ -49,10 +51,9 @@ fn qwen2_5vl_generate() -> Result<()> {
let i_start = Instant::now(); let i_start = Instant::now();
let result = model.generate(mes)?; let result = model.generate(mes)?;
println!("generate: \n {:?}", result); println!("generate: \n {:?}", result);
let i_duration = i_start.elapsed(); let i_duration = i_start.elapsed();
println!("Time elapsed in generate is: {:?}", i_duration); println!("Time elapsed in generate is: {:?}", i_duration);
Ok(()) Ok(())
} }
@@ -64,7 +65,7 @@ async fn qwen2_5vl_stream() -> Result<()> {
let dtype = DType::BF16; let dtype = DType::BF16;
let model_path = "/home/jhq/huggingface_model/Qwen/Qwen2.5-VL-3B-Instruct/"; let model_path = "/home/jhq/huggingface_model/Qwen/Qwen2.5-VL-3B-Instruct/";
let message = r#" let message = r#"
{ {
"model": "qwen2.5vl", "model": "qwen2.5vl",
@@ -88,7 +89,7 @@ async fn qwen2_5vl_stream() -> Result<()> {
] ]
} }
"#; "#;
let mes:ChatCompletionParameters = serde_json::from_str(message)?; let mes: ChatCompletionParameters = serde_json::from_str(message)?;
let i_start = Instant::now(); let i_start = Instant::now();
// let mut model = Qwen2_5VLGenerateModel::init(model_path, &device, dtype)?; // let mut model = Qwen2_5VLGenerateModel::init(model_path, &device, dtype)?;
let mut model = ModelType::init(ModelType::Qwen2_5VL, model_path, None, None)?; let mut model = ModelType::init(ModelType::Qwen2_5VL, model_path, None, None)?;
@@ -98,11 +99,11 @@ async fn qwen2_5vl_stream() -> Result<()> {
let i_start = Instant::now(); let i_start = Instant::now();
let mut stream = pin!(model.generate_stream(mes)?); let mut stream = pin!(model.generate_stream(mes)?);
while let Some(item) = stream.next().await { while let Some(item) = stream.next().await {
println!("generate: \n {:?}", item); println!("generate: \n {:?}", item);
} }
let i_duration = i_start.elapsed(); let i_duration = i_start.elapsed();
println!("Time elapsed in generate is: {:?}", i_duration); println!("Time elapsed in generate is: {:?}", i_duration);
Ok(()) Ok(())
} }