fix LiquidAI/LFM2.5-VL-450M chat_template load bug
This commit is contained in:
@@ -30,6 +30,8 @@ pub fn fix_template(chat_template: &str) -> String {
|
||||
"content.lstrip('\\n')",
|
||||
"content | lstrip('\\n')", // 使用自定义的过滤器替换
|
||||
)
|
||||
.replace("{%- generation -%}", "") // MiniJinja 不支持 generation 和 endgeneration
|
||||
.replace("{%- endgeneration -%}", "")
|
||||
}
|
||||
|
||||
pub fn get_template(path: String) -> Result<String> {
|
||||
@@ -104,6 +106,9 @@ impl<'a> ChatTemplate<'a> {
|
||||
Some(chars_str) => s.trim_end_matches(chars_str.as_str()).to_string(),
|
||||
None => s.trim_end().to_string(),
|
||||
});
|
||||
|
||||
// 添加 string filter
|
||||
env.add_filter("string", |v: MiniJinjaValue| -> String { format!("{}", v) });
|
||||
}
|
||||
pub fn init(path: &str) -> Result<Self> {
|
||||
let path: String = path.to_string();
|
||||
@@ -112,10 +117,12 @@ impl<'a> ChatTemplate<'a> {
|
||||
}
|
||||
let template = get_template(path.clone())?;
|
||||
let template = string_to_static_str(template);
|
||||
// println!("template: {}", template);
|
||||
// 加载jinjaenv处理chat_template
|
||||
let mut env = Environment::new();
|
||||
Self::setup_environment(&mut env);
|
||||
let _ = env.add_template("chat", template);
|
||||
env.add_template("chat", template)?;
|
||||
// println!("env: {:?}", env);
|
||||
|
||||
Ok(Self { env })
|
||||
}
|
||||
|
||||
+1
-1
@@ -247,7 +247,7 @@ pub(crate) fn run_run(args: RunArgs) -> anyhow::Result<()> {
|
||||
WhichModel::LFM2_1_2B | WhichModel::LFM2_5_1_2BInstruct => {
|
||||
lfm2::Lfm2Exec::run(&input, output.as_deref(), &weight_path)?;
|
||||
}
|
||||
WhichModel::LFM2_5VL1_6B | WhichModel::LFM2VL1_6B => {
|
||||
WhichModel::LFM2_5VL1_6B | WhichModel::LFM2VL1_6B | WhichModel::LFM2_5VL450M => {
|
||||
lfm2vl::Lfm2VLExec::run(&input, output.as_deref(), &weight_path)?;
|
||||
}
|
||||
WhichModel::Qwen2_5VL3B | WhichModel::Qwen2_5VL7B => {
|
||||
|
||||
@@ -10,6 +10,8 @@ pub enum WhichModel {
|
||||
LFM2_5_1_2BInstruct,
|
||||
#[value(name = "LiquidAI/LFM2.5-VL-1.6B")]
|
||||
LFM2_5VL1_6B,
|
||||
#[value(name = "LiquidAI/LFM2.5-VL-450M")]
|
||||
LFM2_5VL450M,
|
||||
#[value(name = "LiquidAI/LFM2-VL-1.6B")]
|
||||
LFM2VL1_6B,
|
||||
#[value(name = "OpenBMB/MiniCPM4-0.5B")]
|
||||
@@ -152,7 +154,8 @@ impl WhichModel {
|
||||
| WhichModel::Qwen3_5_9B
|
||||
| WhichModel::Qwen3_5Gguf
|
||||
| WhichModel::LFM2_5VL1_6B
|
||||
| WhichModel::LFM2VL1_6B => "vlm",
|
||||
| WhichModel::LFM2VL1_6B
|
||||
| WhichModel::LFM2_5VL450M => "vlm",
|
||||
// OCR models
|
||||
WhichModel::DeepSeekOCR
|
||||
| WhichModel::DeepSeekOCR2
|
||||
|
||||
+1
-1
@@ -218,7 +218,7 @@ pub fn load_model<'a>(
|
||||
let model = Lfm2GenerateModel::init(path, device, dtype)?;
|
||||
ModelInstance::Lfm2(model)
|
||||
}
|
||||
WhichModel::LFM2_5VL1_6B | WhichModel::LFM2VL1_6B => {
|
||||
WhichModel::LFM2_5VL1_6B | WhichModel::LFM2VL1_6B | WhichModel::LFM2_5VL450M => {
|
||||
let model = Lfm2VLGenerateModel::init(path, device, dtype)?;
|
||||
ModelInstance::Lfm2VL(model)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user