add LFM2.5-VL-1.6B|LFM2-VL-1.6B
This commit is contained in:
+12
-3
@@ -1,5 +1,13 @@
|
||||
use aha::models::{
|
||||
deepseek_ocr::config::DeepseekOCRConfig, hunyuan_ocr::config::HunYuanVLConfig, lfm2::config::Lfm2Config, lfm2vl::config::{Lfm2ProcessorConfig, Lfm2VLConfig}, minicpm4::config::MiniCPM4Config, paddleocr_vl::config::PaddleOCRVLConfig, qwen2_5vl::config::Qwen2_5VLConfig, qwen3vl::config::Qwen3VLConfig, voxcpm::config::VoxCPMConfig
|
||||
deepseek_ocr::config::DeepseekOCRConfig,
|
||||
hunyuan_ocr::config::HunYuanVLConfig,
|
||||
lfm2::config::Lfm2Config,
|
||||
lfm2vl::config::{Lfm2ProcessorConfig, Lfm2VLConfig},
|
||||
minicpm4::config::MiniCPM4Config,
|
||||
paddleocr_vl::config::PaddleOCRVLConfig,
|
||||
qwen2_5vl::config::Qwen2_5VLConfig,
|
||||
qwen3vl::config::Qwen3VLConfig,
|
||||
voxcpm::config::VoxCPMConfig,
|
||||
};
|
||||
use anyhow::Result;
|
||||
|
||||
@@ -104,7 +112,8 @@ fn lfm2vl_config() -> Result<()> {
|
||||
let config: Lfm2VLConfig = serde_json::from_slice(&std::fs::read(config_path)?)?;
|
||||
println!("{:?}", config);
|
||||
let processor_config_path = model_path.to_string() + "/processor_config.json";
|
||||
let processor_config: Lfm2ProcessorConfig = serde_json::from_slice(&std::fs::read(processor_config_path)?)?;
|
||||
let processor_config: Lfm2ProcessorConfig =
|
||||
serde_json::from_slice(&std::fs::read(processor_config_path)?)?;
|
||||
println!("{:?}", processor_config);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ fn test_model_type_classification() {
|
||||
// Since get_model_type and get_model_id are private to api.rs,
|
||||
// we document the expected behavior here for reference:
|
||||
//
|
||||
// LLM models: MiniCPM4_0_5B, Qwen2_5vl3B, Qwen2_5vl7B, Qwen3_0_6B,
|
||||
// Qwen3vl2B, Qwen3vl4B, Qwen3vl8B, Qwen3vl32B
|
||||
// LLM models: MiniCPM4_0_5B, Qwen2_5VL3B, Qwen2_5VL7B, Qwen3_0_6B,
|
||||
// Qwen3VL2B, Qwen3VL4B, Qwen3VL8B, Qwen3VL32B
|
||||
// OCR models: DeepSeekOCR, HunyuanOCR, PaddleOCRVL
|
||||
// ASR models: Qwen3ASR0_6B, Qwen3ASR1_7B, GlmASRNano2512, FunASRNano2512
|
||||
// Image models: RMBG2_0, VoxCPM, VoxCPM1_5
|
||||
@@ -17,13 +17,13 @@ fn test_model_type_classification() {
|
||||
// This test documents the expected model type classification
|
||||
let llm_models = [
|
||||
WhichModel::MiniCPM4_0_5B,
|
||||
WhichModel::Qwen2_5vl3B,
|
||||
WhichModel::Qwen2_5vl7B,
|
||||
WhichModel::Qwen2_5VL3B,
|
||||
WhichModel::Qwen2_5VL7B,
|
||||
WhichModel::Qwen3_0_6B,
|
||||
WhichModel::Qwen3vl2B,
|
||||
WhichModel::Qwen3vl4B,
|
||||
WhichModel::Qwen3vl8B,
|
||||
WhichModel::Qwen3vl32B,
|
||||
WhichModel::Qwen3VL2B,
|
||||
WhichModel::Qwen3VL4B,
|
||||
WhichModel::Qwen3VL8B,
|
||||
WhichModel::Qwen3VL32B,
|
||||
];
|
||||
|
||||
let ocr_models = [
|
||||
|
||||
+3
-4
@@ -9,19 +9,18 @@ use std::{pin::pin, time::Instant};
|
||||
#[test]
|
||||
fn lfm2_generate() -> Result<()> {
|
||||
// test with cuda: RUST_BACKTRACE=1 cargo test -F cuda --test test_lfm2 lfm2_generate -r -- --nocapture
|
||||
// test with cuda+flash-attn: RUST_BACKTRACE=1 cargo test -F cuda,flash-attn qwen3_0_6b_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!("{}/LiquidAI/LFM2-1.2B/", save_dir);
|
||||
let model_path = format!("{}/LiquidAI/LFM2.5-1.2B-Instruct/", save_dir);
|
||||
let model_path = format!("{}/LiquidAI/LFM2-1.2B/", save_dir);
|
||||
// let model_path = format!("{}/LiquidAI/LFM2.5-1.2B-Instruct/", save_dir);
|
||||
let message = r#"
|
||||
{
|
||||
"model": "lfm2",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "你如何看待AI"
|
||||
"content": "你是谁,你如何看待AI"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+68
-13
@@ -1,13 +1,71 @@
|
||||
use std::time::Instant;
|
||||
use std::{pin::pin, time::Instant};
|
||||
|
||||
use aha::{chat::ChatCompletionParameters, models::lfm2vl::generate::Lfm2VLGenerateModel};
|
||||
use aha::{
|
||||
chat::ChatCompletionParameters,
|
||||
models::{GenerateModel, lfm2vl::generate::Lfm2VLGenerateModel},
|
||||
};
|
||||
use anyhow::Result;
|
||||
use rocket::futures::StreamExt;
|
||||
#[test]
|
||||
fn lfm2vl_generate() -> Result<()> {
|
||||
// test with cuda: RUST_BACKTRACE=1 cargo test -F cuda --test test_lfm2vl lfm2vl_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!("{}/LiquidAI/LFM2.5-VL-1.6B/", save_dir);
|
||||
let model_path = format!("{}/LiquidAI/LFM2-VL-1.6B/", save_dir);
|
||||
let message = r#"
|
||||
{
|
||||
"model": "lfm2vl",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "image",
|
||||
"image_url":
|
||||
{
|
||||
"url": "file://./assets/img/ocr_test1.png"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"text": "图片里面是什么"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
"#;
|
||||
let mes: ChatCompletionParameters = serde_json::from_str(message)?;
|
||||
let i_start = Instant::now();
|
||||
let mut model = Lfm2VLGenerateModel::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 result = model.generate(mes)?;
|
||||
let i_duration = i_start.elapsed();
|
||||
println!("generate: \n {:?}", result);
|
||||
if let Some(usage) = &result.usage {
|
||||
let num_token = usage.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 lfm2vl_stream() -> Result<()> {
|
||||
// test with cuda: RUST_BACKTRACE=1 cargo test -F cuda --test test_lfm2vl lfm2vl_stream -r -- --nocapture
|
||||
// test with cuda+flash-attn: RUST_BACKTRACE=1 cargo test -F cuda,flash-attn qwen3_0_6b_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!("{}/LiquidAI/LFM2-1.2B/", save_dir);
|
||||
let model_path = format!("{}/LiquidAI/LFM2.5-VL-1.6B/", save_dir);
|
||||
let message = r#"
|
||||
{
|
||||
@@ -39,16 +97,13 @@ fn lfm2vl_generate() -> Result<()> {
|
||||
println!("Time elapsed in load model is: {:?}", i_duration);
|
||||
|
||||
let i_start = Instant::now();
|
||||
let result = model.generate(mes)?;
|
||||
// let result = model.generate(mes)?;
|
||||
let mut stream = pin!(model.generate_stream(mes)?);
|
||||
let i_duration = i_start.elapsed();
|
||||
// println!("generate: \n {:?}", result);
|
||||
// if let Some(usage) = &result.usage {
|
||||
// let num_token = usage.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);
|
||||
while let Some(token) = stream.next().await {
|
||||
println!("generate: \n {:?}", token);
|
||||
}
|
||||
println!("Time elapsed in generate is: {:?}", i_duration);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,3 +287,26 @@ fn lfm2_weight() -> Result<()> {
|
||||
println!("model_list: {:?}", model_list);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lfm2vl_weight() -> Result<()> {
|
||||
// cargo test -F cuda --test weight_test lfm2vl_weight -r -- --nocapture
|
||||
let save_dir =
|
||||
aha::utils::get_default_save_dir().ok_or(anyhow::anyhow!("Failed to get save dir"))?;
|
||||
// let model_path = format!("{}/LiquidAI/LFM2.5-VL-1.6B/", save_dir);
|
||||
let model_path = format!("{}/LiquidAI/LFM2-VL-1.6B/", save_dir);
|
||||
let model_list = find_type_files(&model_path, "safetensors")?;
|
||||
|
||||
let device = Device::Cpu;
|
||||
for m in &model_list {
|
||||
let weights = safetensors::load(m, &device)?;
|
||||
for (key, tensor) in weights.iter() {
|
||||
// if key.contains("lm_head") {
|
||||
// println!("=== {} === {:?}", key, tensor.shape());
|
||||
// }
|
||||
println!("=== {} === {:?}", key, tensor.shape());
|
||||
}
|
||||
}
|
||||
println!("model_list: {:?}", model_list);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user