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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
language:
|
| 5 |
+
- en
|
| 6 |
+
base_model:
|
| 7 |
+
- HuggingFaceTB/SmolVLM-Instruct
|
| 8 |
+
tags:
|
| 9 |
+
- openvino
|
| 10 |
+
- int4
|
| 11 |
+
- quantization
|
| 12 |
+
- edge-deployment
|
| 13 |
+
- optimization
|
| 14 |
+
- vision-language-model
|
| 15 |
+
- multimodal
|
| 16 |
+
- smolvlm
|
| 17 |
+
inference: false
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# SmolVLM INT4 OpenVINO
|
| 21 |
+
|
| 22 |
+
## 🚀 Optimized Vision-Language Model for Edge Deployment
|
| 23 |
+
|
| 24 |
+
This is an INT4 quantized version of [SmolVLM-Instruct](https://huggingface.co/HuggingFaceTB/SmolVLM-Instruct) using OpenVINO, designed for efficient multimodal inference on edge devices and CPUs.
|
| 25 |
+
|
| 26 |
+
## Model Overview
|
| 27 |
+
|
| 28 |
+
- **Base Model:** SmolVLM-Instruct (2.25B parameters)
|
| 29 |
+
- **Quantization:** INT4 via OpenVINO
|
| 30 |
+
- **Model Type:** Vision-Language Model (VLM)
|
| 31 |
+
- **Capabilities:** Image captioning, visual Q&A, multimodal reasoning
|
| 32 |
+
- **Target Hardware:** CPUs, Intel GPUs, NPUs
|
| 33 |
+
- **Use Cases:** On-device multimodal AI, edge vision applications
|
| 34 |
+
|
| 35 |
+
## 🔧 Technical Details
|
| 36 |
+
|
| 37 |
+
### Quantization Process
|
| 38 |
+
```python
|
| 39 |
+
# Quantized using OpenVINO NNCF
|
| 40 |
+
# INT4 symmetric quantization
|
| 41 |
+
# Applied to both vision encoder and language decoder
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
### Model Architecture
|
| 45 |
+
- Vision Encoder: Shape-optimized SigLIP (INT4)
|
| 46 |
+
- Text Decoder: SmolLM2 (INT4)
|
| 47 |
+
- Visual tokens: 81 per 384×384 patch
|
| 48 |
+
- Supports arbitrary image-text interleaving
|
| 49 |
+
|
| 50 |
+
## 📊 Performance (Experimental)
|
| 51 |
+
|
| 52 |
+
> ⚠️ **Note:** This is an experimental quantization. Formal benchmarks pending.
|
| 53 |
+
|
| 54 |
+
Expected benefits of INT4 quantization:
|
| 55 |
+
- Significantly reduced model size
|
| 56 |
+
- Faster inference on CPU/edge devices
|
| 57 |
+
- Lower memory requirements for multimodal tasks
|
| 58 |
+
- Maintained visual understanding capabilities
|
| 59 |
+
|
| 60 |
+
## 🛠️ How to Use
|
| 61 |
+
|
| 62 |
+
### Installation
|
| 63 |
+
```bash
|
| 64 |
+
pip install optimum[openvino] transformers pillow
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
### Basic Usage
|
| 68 |
+
```python
|
| 69 |
+
from optimum.intel import OVModelForVision2Seq
|
| 70 |
+
from transformers import AutoProcessor
|
| 71 |
+
from PIL import Image
|
| 72 |
+
import requests
|
| 73 |
+
|
| 74 |
+
# Load model and processor
|
| 75 |
+
model_id = "dev-bjoern/smolvlm-int4-ov"
|
| 76 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 77 |
+
model = OVModelForVision2Seq.from_pretrained(model_id)
|
| 78 |
+
|
| 79 |
+
# Load an image
|
| 80 |
+
url = "https://huggingface.co/spaces/merve/chameleon-7b/resolve/main/bee.jpg"
|
| 81 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 82 |
+
|
| 83 |
+
# Create conversation
|
| 84 |
+
messages = [
|
| 85 |
+
{
|
| 86 |
+
"role": "user",
|
| 87 |
+
"content": [
|
| 88 |
+
{"type": "image"},
|
| 89 |
+
{"type": "text", "text": "What do you see in this image?"}
|
| 90 |
+
]
|
| 91 |
+
}
|
| 92 |
+
]
|
| 93 |
+
|
| 94 |
+
# Process and generate
|
| 95 |
+
prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
|
| 96 |
+
inputs = processor(text=prompt, images=[image], return_tensors="pt")
|
| 97 |
+
generated_ids = model.generate(**inputs, max_new_tokens=200)
|
| 98 |
+
output = processor.batch_decode(generated_ids, skip_special_tokens=True)
|
| 99 |
+
print(output[0])
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
### Multiple Images
|
| 103 |
+
```python
|
| 104 |
+
# Load multiple images
|
| 105 |
+
image1 = Image.open("path/to/image1.jpg")
|
| 106 |
+
image2 = Image.open("path/to/image2.jpg")
|
| 107 |
+
|
| 108 |
+
messages = [
|
| 109 |
+
{
|
| 110 |
+
"role": "user",
|
| 111 |
+
"content": [
|
| 112 |
+
{"type": "image"},
|
| 113 |
+
{"type": "image"},
|
| 114 |
+
{"type": "text", "text": "Compare these two images"}
|
| 115 |
+
]
|
| 116 |
+
}
|
| 117 |
+
]
|
| 118 |
+
|
| 119 |
+
# Process with multiple images
|
| 120 |
+
inputs = processor(text=prompt, images=[image1, image2], return_tensors="pt")
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
## 🎯 Intended Use
|
| 124 |
+
|
| 125 |
+
- **Edge AI vision applications**
|
| 126 |
+
- **Local multimodal assistants**
|
| 127 |
+
- **Privacy-focused image analysis**
|
| 128 |
+
- **Resource-constrained deployment**
|
| 129 |
+
- **Real-time visual understanding**
|
| 130 |
+
|
| 131 |
+
## ⚡ Optimization Tips
|
| 132 |
+
|
| 133 |
+
1. **Image Resolution:** Adjust with `size={"longest_edge": N*384}` where N=3 or 4 for balance
|
| 134 |
+
2. **Batch Processing:** Process multiple images together when possible
|
| 135 |
+
3. **CPU Inference:** Leverage OpenVINO runtime optimizations
|
| 136 |
+
|
| 137 |
+
## 🧪 Experimental Status
|
| 138 |
+
|
| 139 |
+
This is my first experiment with OpenVINO INT4 quantization for vision-language models. Feedback welcome!
|
| 140 |
+
|
| 141 |
+
### Known Limitations
|
| 142 |
+
- No formal benchmarks yet
|
| 143 |
+
- Visual quality degradation not measured
|
| 144 |
+
- Optimal quantization settings still being explored
|
| 145 |
+
|
| 146 |
+
### Future Improvements
|
| 147 |
+
- [ ] Benchmark on standard VLM tasks
|
| 148 |
+
- [ ] Compare with original model performance
|
| 149 |
+
- [ ] Experiment with mixed precision
|
| 150 |
+
- [ ] Test on various hardware configurations
|
| 151 |
+
|
| 152 |
+
## 🤝 Contributing
|
| 153 |
+
|
| 154 |
+
Have suggestions or found issues? Please open a discussion!
|
| 155 |
+
|
| 156 |
+
## 📚 Resources
|
| 157 |
+
|
| 158 |
+
- [Original SmolVLM Model](https://huggingface.co/HuggingFaceTB/SmolVLM-Instruct)
|
| 159 |
+
- [SmolVLM Blog Post](https://huggingface.co/blog/smolvlm)
|
| 160 |
+
- [OpenVINO Documentation](https://docs.openvino.ai/)
|
| 161 |
+
- [Optimum Intel Guide](https://huggingface.co/docs/optimum/intel/index)
|
| 162 |
+
|
| 163 |
+
## 🙏 Acknowledgments
|
| 164 |
+
|
| 165 |
+
- HuggingFace team for SmolVLM
|
| 166 |
+
- Intel OpenVINO team for quantization tools
|
| 167 |
+
- Vision-language model community
|
| 168 |
+
|
| 169 |
+
## 📝 Citation
|
| 170 |
+
|
| 171 |
+
If you use this model, please cite both works:
|
| 172 |
+
|
| 173 |
+
```bibtex
|
| 174 |
+
@misc{smolvlm-int4-ov,
|
| 175 |
+
author = {Bjoern Bethge},
|
| 176 |
+
title = {SmolVLM INT4 OpenVINO},
|
| 177 |
+
year = {2024},
|
| 178 |
+
publisher = {Hugging Face},
|
| 179 |
+
howpublished = {\url{https://huggingface.co/dev-bjoern/smolvlm-int4-ov}}
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
@article{marafioti2025smolvlm,
|
| 183 |
+
title={SmolVLM: Redefining small and efficient multimodal models},
|
| 184 |
+
author={Andrés Marafioti and others},
|
| 185 |
+
journal={arXiv preprint arXiv:2504.05299},
|
| 186 |
+
year={2025}
|
| 187 |
+
}
|
| 188 |
+
```
|
| 189 |
+
|
| 190 |
+
---
|
| 191 |
+
|
| 192 |
+
**Status:** 🧪 Experimental | **Model Type:** Vision-Language | **License:** Apache 2.0
|