update fmt

This commit is contained in:
jhqxxx
2026-03-23 22:09:20 +08:00
parent 9224593b78
commit 7d3cd50e35
9 changed files with 58 additions and 41 deletions
+1 -1
View File
@@ -8,6 +8,7 @@ pub mod fun_asr_nano;
pub mod glm_asr_nano; pub mod glm_asr_nano;
pub mod glm_ocr; pub mod glm_ocr;
pub mod hunyuan_ocr; pub mod hunyuan_ocr;
pub mod lfm2;
pub mod minicpm4; pub mod minicpm4;
pub mod paddleocr_vl; pub mod paddleocr_vl;
pub mod qwen2_5vl; pub mod qwen2_5vl;
@@ -18,7 +19,6 @@ pub mod qwen3vl;
pub mod rmbg2_0; pub mod rmbg2_0;
pub mod voxcpm; pub mod voxcpm;
pub mod voxcpm1_5; pub mod voxcpm1_5;
pub mod lfm2;
use anyhow::Result; use anyhow::Result;
+6 -5
View File
@@ -1,5 +1,5 @@
use anyhow::{Result, anyhow};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use anyhow::{anyhow, Result};
#[derive(Debug, PartialEq, Deserialize, Serialize)] #[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct Lfm2Config { pub struct Lfm2Config {
pub architectures: Vec<String>, pub architectures: Vec<String>,
@@ -43,7 +43,6 @@ pub struct Lfm2Config {
pub tie_embedding: Option<bool>, pub tie_embedding: Option<bool>,
} }
impl Lfm2Config { impl Lfm2Config {
pub fn full_attn_idx2layer_type(&mut self) { pub fn full_attn_idx2layer_type(&mut self) {
if self.layer_types.is_none() if self.layer_types.is_none()
@@ -75,7 +74,9 @@ impl Lfm2Config {
} }
Ok(layer_types) Ok(layer_types)
} else { } else {
Err(anyhow!("layer_types full_attn_idxs cannot be none at the same time")) Err(anyhow!(
"layer_types full_attn_idxs cannot be none at the same time"
))
} }
} }
} }
@@ -84,5 +85,5 @@ impl Lfm2Config {
pub struct Lfm2GenerateConfig { pub struct Lfm2GenerateConfig {
pub bos_token_id: u32, pub bos_token_id: u32,
pub eos_token_id: u32, pub eos_token_id: u32,
pub pad_token_id: u32 pub pad_token_id: u32,
} }
+23 -18
View File
@@ -1,15 +1,18 @@
use crate::utils::build_completion_chunk_response;
use crate::{ use crate::{
chat_template::ChatTemplate, chat_template::ChatTemplate,
models::{GenerateModel, lfm2::{ models::{
config::{Lfm2Config, Lfm2GenerateConfig}, GenerateModel,
model::Lfm2Model, lfm2::{
}}, config::{Lfm2Config, Lfm2GenerateConfig},
model::Lfm2Model,
},
},
tokenizer::TokenizerModel, tokenizer::TokenizerModel,
utils::{ utils::{
build_completion_response, find_type_files, get_device, get_dtype, get_logit_processor, build_completion_response, find_type_files, get_device, get_dtype, get_logit_processor,
}, },
}; };
use crate::utils::build_completion_chunk_response;
use aha_openai_dive::v1::resources::chat::{ChatCompletionParameters, ChatCompletionResponse}; use aha_openai_dive::v1::resources::chat::{ChatCompletionParameters, ChatCompletionResponse};
use anyhow::Result; use anyhow::Result;
use candle_core::{DType, Device, Tensor}; use candle_core::{DType, Device, Tensor};
@@ -59,8 +62,6 @@ impl<'a> Lfm2GenerateModel<'a> {
model_name, model_name,
}) })
} }
} }
impl<'a> GenerateModel for Lfm2GenerateModel<'a> { impl<'a> GenerateModel for Lfm2GenerateModel<'a> {
@@ -103,16 +104,20 @@ impl<'a> GenerateModel for Lfm2GenerateModel<'a> {
} }
fn generate_stream( fn generate_stream(
&mut self, &mut self,
mes: ChatCompletionParameters, mes: ChatCompletionParameters,
) -> Result< ) -> Result<
Box< Box<
dyn rocket::futures::Stream<Item = Result<aha_openai_dive::v1::resources::chat::ChatCompletionChunkResponse, anyhow::Error>> dyn rocket::futures::Stream<
+ Send Item = Result<
+ Unpin aha_openai_dive::v1::resources::chat::ChatCompletionChunkResponse,
+ '_, anyhow::Error,
>, >,
> { > + Send
+ Unpin
+ '_,
>,
> {
let mes_render = self.chat_template.apply_chat_template(&mes)?; let mes_render = self.chat_template.apply_chat_template(&mes)?;
let mut logits = get_logit_processor( let mut logits = get_logit_processor(
mes.temperature, mes.temperature,
@@ -160,4 +165,4 @@ impl<'a> GenerateModel for Lfm2GenerateModel<'a> {
}; };
Ok(Box::new(Box::pin(stream))) Ok(Box::new(Box::pin(stream)))
} }
} }
+1 -1
View File
@@ -1,3 +1,3 @@
pub mod config; pub mod config;
pub mod generate;
pub mod model; pub mod model;
pub mod generate;
+4 -7
View File
@@ -70,7 +70,7 @@ impl Lfm2ShortConv {
bx.narrow(D::Minus1, pad_num.unsigned_abs(), self.l_cache)? bx.narrow(D::Minus1, pad_num.unsigned_abs(), self.l_cache)?
}; };
self.cache = Some(conv_state); self.cache = Some(conv_state);
let bx = bx.pad_with_zeros(D::Minus1, self.l_cache-1, self.l_cache-1)?; let bx = bx.pad_with_zeros(D::Minus1, self.l_cache - 1, self.l_cache - 1)?;
let bx = conv1d_depthwise(&bx, self.conv.weight(), self.conv.bias())?; let bx = conv1d_depthwise(&bx, self.conv.weight(), self.conv.bias())?;
bx.narrow(D::Minus1, 0, seq_len)? bx.narrow(D::Minus1, 0, seq_len)?
} else { } else {
@@ -145,9 +145,8 @@ impl Lfm2DecoderLayer {
let intermediate_size = if config.block_auto_adjust_ff_dim { let intermediate_size = if config.block_auto_adjust_ff_dim {
let inter_size = 2 * config.block_ff_dim / 3; let inter_size = 2 * config.block_ff_dim / 3;
let inter_size = (config.block_ffn_dim_multiplier * inter_size as f64) as usize; let inter_size = (config.block_ffn_dim_multiplier * inter_size as f64) as usize;
let inter_size = config.block_multiple_of config.block_multiple_of
* ((inter_size + config.block_multiple_of - 1) / config.block_multiple_of); * ((inter_size + config.block_multiple_of - 1) / config.block_multiple_of)
inter_size
} else { } else {
config.block_ff_dim config.block_ff_dim
}; };
@@ -291,9 +290,7 @@ impl Lfm2Model {
); );
match linear { match linear {
Ok(linear) => linear, Ok(linear) => linear,
Err(_) => { Err(_) => Linear::new(model.embed_tokens.embeddings().clone(), None),
Linear::new(model.embed_tokens.embeddings().clone(), None)
}
} }
}; };
Ok(Self { model, lm_head }) Ok(Self { model, lm_head })
+12 -3
View File
@@ -7,6 +7,7 @@ pub mod fun_asr_nano;
pub mod glm_asr_nano; pub mod glm_asr_nano;
pub mod glm_ocr; pub mod glm_ocr;
pub mod hunyuan_ocr; pub mod hunyuan_ocr;
pub mod lfm2;
pub mod mask_gct; pub mod mask_gct;
pub mod minicpm4; pub mod minicpm4;
pub mod paddleocr_vl; pub mod paddleocr_vl;
@@ -19,7 +20,6 @@ pub mod qwen3vl;
pub mod rmbg2_0; pub mod rmbg2_0;
pub mod voxcpm; pub mod voxcpm;
pub mod w2v_bert_2_0; pub mod w2v_bert_2_0;
pub mod lfm2;
use aha_openai_dive::v1::resources::chat::{ use aha_openai_dive::v1::resources::chat::{
ChatCompletionChunkResponse, ChatCompletionParameters, ChatCompletionResponse, ChatCompletionChunkResponse, ChatCompletionParameters, ChatCompletionResponse,
@@ -28,7 +28,15 @@ use anyhow::{Result, anyhow};
use rocket::futures::Stream; use rocket::futures::Stream;
use crate::models::{ use crate::models::{
deepseek_ocr::generate::DeepseekOCRGenerateModel, fun_asr_nano::generate::FunAsrNanoGenerateModel, glm_asr_nano::generate::GlmAsrNanoGenerateModel, glm_ocr::generate::GlmOcrGenerateModel, hunyuan_ocr::generate::HunyuanOCRGenerateModel, lfm2::generate::Lfm2GenerateModel, minicpm4::generate::MiniCPMGenerateModel, paddleocr_vl::generate::PaddleOCRVLGenerateModel, qwen2_5vl::generate::Qwen2_5VLGenerateModel, qwen3::generate::Qwen3GenerateModel, qwen3_5::generate::Qwen3_5GenerateModel, qwen3_asr::generate::Qwen3AsrGenerateModel, qwen3vl::generate::Qwen3VLGenerateModel, rmbg2_0::generate::RMBG2_0Model, voxcpm::generate::VoxCPMGenerate deepseek_ocr::generate::DeepseekOCRGenerateModel,
fun_asr_nano::generate::FunAsrNanoGenerateModel,
glm_asr_nano::generate::GlmAsrNanoGenerateModel, glm_ocr::generate::GlmOcrGenerateModel,
hunyuan_ocr::generate::HunyuanOCRGenerateModel, lfm2::generate::Lfm2GenerateModel,
minicpm4::generate::MiniCPMGenerateModel, paddleocr_vl::generate::PaddleOCRVLGenerateModel,
qwen2_5vl::generate::Qwen2_5VLGenerateModel, qwen3::generate::Qwen3GenerateModel,
qwen3_5::generate::Qwen3_5GenerateModel, qwen3_asr::generate::Qwen3AsrGenerateModel,
qwen3vl::generate::Qwen3VLGenerateModel, rmbg2_0::generate::RMBG2_0Model,
voxcpm::generate::VoxCPMGenerate,
}; };
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)] #[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
@@ -130,7 +138,8 @@ impl WhichModel {
pub fn model_type(self) -> &'static str { pub fn model_type(self) -> &'static str {
match self { match self {
// LLM models // LLM models
WhichModel::MiniCPM4_0_5B | WhichModel::Qwen3_0_6B WhichModel::MiniCPM4_0_5B
| WhichModel::Qwen3_0_6B
| WhichModel::LFM2_1_2B | WhichModel::LFM2_1_2B
| WhichModel::LFM2_5_1_2BInstruct => "llm", | WhichModel::LFM2_5_1_2BInstruct => "llm",
WhichModel::Qwen2_5vl3B WhichModel::Qwen2_5vl3B
+4 -1
View File
@@ -1,5 +1,8 @@
use aha::models::{ use aha::models::{
deepseek_ocr::config::DeepseekOCRConfig, hunyuan_ocr::config::HunYuanVLConfig, lfm2::config::Lfm2Config, 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, minicpm4::config::MiniCPM4Config,
paddleocr_vl::config::PaddleOCRVLConfig, qwen2_5vl::config::Qwen2_5VLConfig,
qwen3vl::config::Qwen3VLConfig, voxcpm::config::VoxCPMConfig,
}; };
use anyhow::Result; use anyhow::Result;
+1 -1
View File
@@ -43,7 +43,7 @@ fn messy_test() -> Result<()> {
// aha::utils::get_default_save_dir().ok_or(anyhow::anyhow!("Failed to get save dir"))?; // aha::utils::get_default_save_dir().ok_or(anyhow::anyhow!("Failed to get save dir"))?;
// let model_path = format!("{}/deepseek-ai/DeepSeek-OCR-2/", save_dir); // let model_path = format!("{}/deepseek-ai/DeepSeek-OCR-2/", save_dir);
// let stem = std::path::Path::new(&model_path) // let stem = std::path::Path::new(&model_path)
// .file_name() // .file_name()
// .and_then(|s| s.to_str()) // .and_then(|s| s.to_str())
// .unwrap_or("qwen3.5"); // .unwrap_or("qwen3.5");
// println!("stem: {:?}", stem); // println!("stem: {:?}", stem);
+6 -4
View File
@@ -1,7 +1,10 @@
use std::{pin::pin, time::Instant}; use aha::{
chat::ChatCompletionParameters,
models::{GenerateModel, lfm2::generate::Lfm2GenerateModel},
};
use anyhow::Result; use anyhow::Result;
use aha::{chat::ChatCompletionParameters, models::{GenerateModel, lfm2::generate::Lfm2GenerateModel}};
use rocket::futures::StreamExt; use rocket::futures::StreamExt;
use std::{pin::pin, time::Instant};
#[test] #[test]
fn lfm2_generate() -> Result<()> { fn lfm2_generate() -> Result<()> {
@@ -44,7 +47,6 @@ fn lfm2_generate() -> Result<()> {
Ok(()) Ok(())
} }
#[tokio::test] #[tokio::test]
async fn lfm2_stream() -> Result<()> { async fn lfm2_stream() -> Result<()> {
// test with cuda: RUST_BACKTRACE=1 cargo test -F cuda --test test_lfm2 lfm2_stream -r -- --nocapture // test with cuda: RUST_BACKTRACE=1 cargo test -F cuda --test test_lfm2 lfm2_stream -r -- --nocapture
@@ -88,4 +90,4 @@ async fn lfm2_stream() -> Result<()> {
println!("Time elapsed in generate is: {:?}", i_duration); println!("Time elapsed in generate is: {:?}", i_duration);
Ok(()) Ok(())
} }