Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
library_name: transformers
|
3 |
+
license: other
|
4 |
+
license_name: lfm1.0
|
5 |
+
license_link: LICENSE
|
6 |
+
language:
|
7 |
+
- en
|
8 |
+
pipeline_tag: image-text-to-text
|
9 |
+
tags:
|
10 |
+
- liquid
|
11 |
+
- lfm2
|
12 |
+
- lfm2-vl
|
13 |
+
- edge
|
14 |
+
base_model:
|
15 |
+
- LiquidAI/LFM2-VL-1.6B
|
16 |
+
---
|
17 |
+
<center>
|
18 |
+
<div style="text-align: center;">
|
19 |
+
<img
|
20 |
+
src="https://cdn-uploads.huggingface.co/production/uploads/61b8e2ba285851687028d395/7_6D7rWrLxp2hb6OHSV1p.png"
|
21 |
+
alt="Liquid AI"
|
22 |
+
style="width: 100%; max-width: 66%; height: auto; display: inline-block; margin-bottom: 0.5em; margin-top: 0.5em;"
|
23 |
+
/>
|
24 |
+
</div>
|
25 |
+
</center>
|
26 |
+
|
27 |
+
# LFM2‑VL
|
28 |
+
|
29 |
+
LFM2‑VL is [Liquid AI](https://www.liquid.ai/)'s first series of multimodal models, designed to process text and images with variable resolutions.
|
30 |
+
Built on the [LFM2](https://huggingface.co/collections/LiquidAI/lfm2-686d721927015b2ad73eaa38) backbone, it is optimized for low-latency and edge AI applications.
|
31 |
+
|
32 |
+
We're releasing the weights of two post-trained checkpoints with [450M](https://huggingface.co/LiquidAI/LFM2-VL-450M) (for highly constrained devices) and [1.6B](https://huggingface.co/LiquidAI/LFM2-VL-1.6B) (more capable yet still lightweight) parameters.
|
33 |
+
|
34 |
+
* **2× faster inference speed** on GPUs compared to existing VLMs while maintaining competitive accuracy
|
35 |
+
* **Flexible architecture** with user-tunable speed-quality tradeoffs at inference time
|
36 |
+
* **Native resolution processing** up to 512×512 with intelligent patch-based handling for larger images, avoiding upscaling and distortion
|
37 |
+
|
38 |
+
Find more about our vision-language model in the [LFM2-VL post](https://www.liquid.ai/blog/lfm2-vl-efficient-vision-language-models) and its language backbone in the [LFM2 blog post](https://www.liquid.ai/blog/liquid-foundation-models-v2-our-second-series-of-generative-ai-models).
|
39 |
+
|
40 |
+
## 📄 Model details
|
41 |
+
|
42 |
+
Due to their small size, **we recommend fine-tuning LFM2-VL models on narrow use cases** to maximize performance.
|
43 |
+
They were trained for instruction following and lightweight agentic flows.
|
44 |
+
Not intended for safety‑critical decisions.
|
45 |
+
|
46 |
+
| Property | [**LFM2-VL-450M**](https://huggingface.co/LiquidAI/LFM2-VL-450M) | [**LFM2-VL-1.6B**](https://huggingface.co/LiquidAI/LFM2-VL-1.6B) |
|
47 |
+
|---|---:|---:|
|
48 |
+
| **Parameters (LM only)** | 350M | 1.2B |
|
49 |
+
| **Vision encoder** | SigLIP2 NaFlex base (86M) | SigLIP2 NaFlex shape‑optimized (400M) |
|
50 |
+
| **Backbone layers** | hybrid conv+attention | hybrid conv+attention |
|
51 |
+
| **Context (text)** | 32,768 tokens | 32,768 tokens |
|
52 |
+
| **Image tokens** | dynamic, user‑tunable | dynamic, user‑tunable |
|
53 |
+
| **Vocab size** | 65,536 | 65,536 |
|
54 |
+
| **Precision** | bfloat16 | bfloat16 |
|
55 |
+
| **License** | LFM Open License v1.0 | LFM Open License v1.0 |
|
56 |
+
|
57 |
+
**Supported languages:** English
|
58 |
+
|
59 |
+
**Generation parameters**: We recommend the following parameters:
|
60 |
+
- Text: `temperature=0.1`, `min_p=0.15`, `repetition_penalty=1.05`
|
61 |
+
- Vision: `min_image_tokens=64` `max_image_tokens=256`, `do_image_splitting=True`
|
62 |
+
|
63 |
+
**Chat template**: LFM2-VL uses a ChatML-like chat template as follows:
|
64 |
+
|
65 |
+
```
|
66 |
+
<|startoftext|><|im_start|>system
|
67 |
+
You are a helpful multimodal assistant by Liquid AI.<|im_end|>
|
68 |
+
<|im_start|>user
|
69 |
+
<image>Describe this image.<|im_end|>
|
70 |
+
<|im_start|>assistant
|
71 |
+
This image shows a Caenorhabditis elegans (C. elegans) nematode.<|im_end|>
|
72 |
+
```
|
73 |
+
|
74 |
+
Images are referenced with a sentinel (`<image>`), which is automatically replaced with the image tokens by the processor.
|
75 |
+
|
76 |
+
You can apply it using the dedicated [`.apply_chat_template()`](https://huggingface.co/docs/transformers/en/chat_templating#applychattemplate) function from Hugging Face transformers.
|
77 |
+
|
78 |
+
**Architecture**
|
79 |
+
- **Hybrid backbone**: Language model tower (LFM2-1.2B or LFM2-350M) paired with SigLIP2 NaFlex vision encoders (400M shape-optimized or 86M base variant)
|
80 |
+
- **Native resolution processing**: Handles images up to 512×512 pixels without upscaling and preserves non-standard aspect ratios without distortion
|
81 |
+
- **Tiling strategy**: Splits large images into non-overlapping 512×512 patches and includes thumbnail encoding for global context (in 1.6B model)
|
82 |
+
- **Efficient token mapping**: 2-layer MLP connector with pixel unshuffle reduces image tokens (e.g., 256×384 image → 96 tokens, 1000×3000 → 1,020 tokens)
|
83 |
+
- **Inference-time flexibility**: User-tunable maximum image tokens and patch count for speed/quality tradeoff without retraining
|
84 |
+
|
85 |
+
**Training approach**
|
86 |
+
- Builds on the LFM2 base model with joint mid-training that fuses vision and language capabilities using a gradually adjusted text-to-image ratio
|
87 |
+
- Applies joint SFT with emphasis on image understanding and vision tasks
|
88 |
+
- Leverages large-scale open-source datasets combined with in-house synthetic vision data, selected for balanced task coverage
|
89 |
+
- Follows a progressive training strategy: base model → joint mid-training → supervised fine-tuning
|
90 |
+
|
91 |
+
## 🏃 How to run LFM2-VL
|
92 |
+
|
93 |
+
You can run LFM2-VL with Hugging Face [`transformers`](https://github.com/huggingface/transformers) v4.55 or more recent as follows:
|
94 |
+
|
95 |
+
```bash
|
96 |
+
pip install -U transformers pillow
|
97 |
+
```
|
98 |
+
|
99 |
+
Here is an example of how to generate an answer with transformers in Python:
|
100 |
+
|
101 |
+
```python
|
102 |
+
from transformers import AutoProcessor, AutoModelForImageTextToText
|
103 |
+
from transformers.image_utils import load_image
|
104 |
+
# Load model and processor
|
105 |
+
model_id = "LiquidAI/LFM2-VL-1.6B"
|
106 |
+
model = AutoModelForImageTextToText.from_pretrained(
|
107 |
+
model_id,
|
108 |
+
device_map="auto",
|
109 |
+
torch_dtype="bfloat16",
|
110 |
+
trust_remote_code=True
|
111 |
+
)
|
112 |
+
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
113 |
+
# Load image and create conversation
|
114 |
+
url = "https://www.ilankelman.org/stopsigns/australia.jpg"
|
115 |
+
image = load_image(url)
|
116 |
+
conversation = [
|
117 |
+
{
|
118 |
+
"role": "user",
|
119 |
+
"content": [
|
120 |
+
{"type": "image", "image": image},
|
121 |
+
{"type": "text", "text": "What is in this image?"},
|
122 |
+
],
|
123 |
+
},
|
124 |
+
]
|
125 |
+
# Generate Answer
|
126 |
+
inputs = processor.apply_chat_template(
|
127 |
+
conversation,
|
128 |
+
add_generation_prompt=True,
|
129 |
+
return_tensors="pt",
|
130 |
+
return_dict=True,
|
131 |
+
tokenize=True,
|
132 |
+
).to(model.device)
|
133 |
+
outputs = model.generate(**inputs, max_new_tokens=64)
|
134 |
+
processor.batch_decode(outputs, skip_special_tokens=True)[0]
|
135 |
+
# This image depicts a vibrant street scene in what appears to be a Chinatown or similar cultural area. The focal point is a large red stop sign with white lettering, mounted on a pole.
|
136 |
+
```
|
137 |
+
|
138 |
+
You can directly run and test the model with this [Colab notebook](https://colab.research.google.com/drive/11EMJhcVB6OTEuv--OePyGK86k-38WU3q?usp=sharing).
|
139 |
+
|
140 |
+
|
141 |
+
## 🔧 How to fine-tune
|
142 |
+
|
143 |
+
We recommend fine-tuning LFM2-VL models on your use cases to maximize performance.
|
144 |
+
|
145 |
+
| Notebook | Description | Link |
|
146 |
+
|-----------|----------------------------------------------------------------------|------|
|
147 |
+
| SFT (TRL) | Supervised Fine-Tuning (SFT) notebook with a LoRA adapter using TRL. | <a href="https://colab.research.google.com/drive/1csXCLwJx7wI7aruudBp6ZIcnqfv8EMYN?usp=sharing"><img src="https://cdn-uploads.huggingface.co/production/uploads/61b8e2ba285851687028d395/vlOyMEjwHa_b_LXysEu2E.png" width="110" alt="Colab link"></a> |
|
148 |
+
|
149 |
+
|
150 |
+
## 📈 Performance
|
151 |
+
|
152 |
+
| Model | RealWorldQA | MM-IFEval | InfoVQA (Val) | OCRBench | BLINK | MMStar | MMMU (Val) | MathVista | SEEDBench_IMG | MMVet | MME | MMLU |
|
153 |
+
|-------------------|-------------|-----------|---------------|----------|-------|--------|------------|-----------|---------------|-------|----------|-------|
|
154 |
+
| InternVL3-2B | 65.10 | 38.49 | 66.10 | 831 | 53.10 | 61.10 | 48.70 | 57.60 | 75.00 | 67.00 | 2186.40 | 64.80 |
|
155 |
+
| InternVL3-1B | 57.00 | 31.14 | 54.94 | 798 | 43.00 | 52.30 | 43.20 | 46.90 | 71.20 | 58.70 | 1912.40 | 49.80 |
|
156 |
+
| SmolVLM2-2.2B | 57.50 | 19.42 | 37.75 | 725 | 42.30 | 46.00 | 41.60 | 51.50 | 71.30 | 34.90 | 1792.50 | - |
|
157 |
+
| LFM2-VL-1.6B | 65.23 | 37.66 | 58.68 | 742 | 44.40 | 49.53 | 38.44 | 51.10 | 71.97 | 48.07 | 1753.04 | 50.99 |
|
158 |
+
| Model | RealWorldQA | MM-IFEval | InfoVQA (Val) | OCRBench | BLINK | MMStar | MMMU (Val) | MathVista | SEEDBench_IMG | MMVet | MME | MMLU |
|
159 |
+
|-------------------|-------------|-----------|---------------|----------|-------|--------|------------|-----------|---------------|-------|----------|-------|
|
160 |
+
| SmolVLM2-500M | 49.90 | 11.27 | 24.64 | 609 | 40.70 | 38.20 | 34.10 | 37.50 | 62.20 | 29.90 | 1448.30 | - |
|
161 |
+
| LFM2-VL-450M | 52.29 | 26.18 | 46.51 | 655 | 41.98 | 40.87 | 33.11 | 44.70 | 63.50 | 33.76 | 1239.06 | 40.16 |
|
162 |
+
|
163 |
+
We obtained MM-IFEval and InfoVQA (Val) scores for InternVL 3 and SmolVLM2 models using VLMEvalKit.
|
164 |
+
|
165 |
+
## 📬 Contact
|
166 |
+
|
167 |
+
If you are interested in custom solutions with edge deployment, please contact [our sales team](https://www.liquid.ai/contact).
|