Views
No views yet
bf16_q8_0, f16_q4_K) – Best of Both Worldsbf16_q8_0 (meaning full-precision BF16 core layers + quantized Q8_0 other layers).| Model Format | Precision | Memory Usage | Device Requirements | Best Use Case |
|---|---|---|---|---|
| BF16 | Very High | High | BF16-supported GPU/CPU | High-speed inference with reduced memory |
| F16 | High | High | FP16-supported GPU/CPU | Inference when BF16 isn’t available |
| Q4_K | Medium-Low | Low | CPU or Low-VRAM devices | Memory-constrained inference |
| Q6_K | Medium | Moderate | CPU with more memory | Better accuracy with quantization |
| Q8_0 | High | Moderate | GPU/CPU with moderate VRAM | Highest accuracy among quantized models |
| IQ3_XS | Low | Very Low | Ultra-low-memory devices | Max memory efficiency, low accuracy |
| IQ3_S | Low | Very Low | Low-memory devices | Slightly more usable than IQ3_XS |
| IQ3_M | Low-Medium | Low | Low-memory devices | Better accuracy than IQ3_S |
| Q4_0 | Low | Low | ARM-based/embedded devices | Llama.cpp automatically optimizes for ARM inference |
| Ultra Low-Bit (IQ1/2_*) | Very Low | Extremely Low | Tiny edge/embedded devices | Fit models in extremely tight memory; low accuracy |
Hybrid (e.g., bf16_q8_0) | Medium–High | Medium | Mixed-precision capable hardware | Balanced performance and memory, near-FP accuracy in critical layers |

1import torch
2from PIL import Image
3from transformers import AutoProcessor, AutoModelForVision2Seq
4from transformers.image_utils import load_image
5
6DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
7
8# Load images
9image = load_image("https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg")
10
11# Initialize processor and model
12processor = AutoProcessor.from_pretrained("HuggingFaceTB/SmolVLM-256M-Instruct")
13model = AutoModelForVision2Seq.from_pretrained(
14 "HuggingFaceTB/SmolVLM-256M-Instruct",
15 torch_dtype=torch.bfloat16,
16 _attn_implementation="flash_attention_2" if DEVICE == "cuda" else "eager",
17).to(DEVICE)
18
19# Create input messages
20messages = [
21 {
22 "role": "user",
23 "content": [
24 {"type": "image"},
25 {"type": "text", "text": "Can you describe this image?"}
26 ]
27 },
28]
29
30# Prepare inputs
31prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
32inputs = processor(text=prompt, images=[image], return_tensors="pt")
33inputs = inputs.to(DEVICE)
34
35# Generate outputs
36generated_ids = model.generate(**inputs, max_new_tokens=500)
37generated_texts = processor.batch_decode(
38 generated_ids,
39 skip_special_tokens=True,
40)
41
42print(generated_texts[0])
43"""
44Assistant: The image depicts a large, historic statue of liberty, located in New York City. The statue is a green, cylindrical structure with a human figure at the top, holding a torch. The statue is situated on a pedestal that resembles the statue of liberty, which is located on a small island in the middle of a body of water. The water surrounding the island is calm, reflecting the blue sky and the statue.
45In the background, there are several tall buildings, including the Empire State Building, which is visible in the distance. These buildings are made of glass and steel, and they are positioned in a grid-like pattern, giving them a modern look. The sky is clear, with a few clouds visible, indicating fair weather.
46The statue is surrounded by trees, which are green and appear to be healthy. There are also some small structures, possibly houses or buildings, visible in the distance. The overall scene suggests a peaceful and serene environment, typical of a cityscape.
47The image is taken during the daytime, likely during the day of the statue's installation. The lighting is bright, casting a strong shadow on the statue and the water, which enhances the visibility of the statue and the surrounding environment.
48To summarize, the image captures a significant historical statue of liberty, situated on a small island in the middle of a body of water, surrounded by trees and buildings. The sky is clear, with a few clouds visible, indicating fair weather. The statue is green and cylindrical, with a human figure holding a torch, and is surrounded by trees, indicating a peaceful and well-maintained environment. The overall scene is one of tranquility and historical significance.
49"""1from transformers import AutoConfig, AutoProcessor
2from transformers.image_utils import load_image
3import onnxruntime
4import numpy as np
5
6# 1. Load models
7## Load config and processor
8model_id = "HuggingFaceTB/SmolVLM-256M-Instruct"
9config = AutoConfig.from_pretrained(model_id)
10processor = AutoProcessor.from_pretrained(model_id)
11
12## Load sessions
13## !wget https://huggingface.co/HuggingFaceTB/SmolVLM-256M-Instruct/resolve/main/onnx/vision_encoder.onnx
14## !wget https://huggingface.co/HuggingFaceTB/SmolVLM-256M-Instruct/resolve/main/onnx/embed_tokens.onnx
15## !wget https://huggingface.co/HuggingFaceTB/SmolVLM-256M-Instruct/resolve/main/onnx/decoder_model_merged.onnx
16vision_session = onnxruntime.InferenceSession("vision_encoder.onnx")
17embed_session = onnxruntime.InferenceSession("embed_tokens.onnx")
18decoder_session = onnxruntime.InferenceSession("decoder_model_merged.onnx")
19
20## Set config values
21num_key_value_heads = config.text_config.num_key_value_heads
22head_dim = config.text_config.head_dim
23num_hidden_layers = config.text_config.num_hidden_layers
24eos_token_id = config.text_config.eos_token_id
25image_token_id = config.image_token_id
26
27
28# 2. Prepare inputs
29## Create input messages
30messages = [
31 {
32 "role": "user",
33 "content": [
34 {"type": "image"},
35 {"type": "text", "text": "Can you describe this image?"}
36 ]
37 },
38]
39
40## Load image and apply processor
41image = load_image("https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg")
42prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
43inputs = processor(text=prompt, images=[image], return_tensors="np")
44
45## Prepare decoder inputs
46batch_size = inputs['input_ids'].shape[0]
47past_key_values = {
48 f'past_key_values.{layer}.{kv}': np.zeros([batch_size, num_key_value_heads, 0, head_dim], dtype=np.float32)
49 for layer in range(num_hidden_layers)
50 for kv in ('key', 'value')
51}
52image_features = None
53input_ids = inputs['input_ids']
54attention_mask = inputs['attention_mask']
55position_ids = np.cumsum(inputs['attention_mask'], axis=-1)
56
57
58# 3. Generation loop
59max_new_tokens = 1024
60generated_tokens = np.array([[]], dtype=np.int64)
61for i in range(max_new_tokens):
62 inputs_embeds = embed_session.run(None, {'input_ids': input_ids})[0]
63
64 if image_features is None:
65 ## Only compute vision features if not already computed
66 image_features = vision_session.run(
67 ['image_features'], # List of output names or indices
68 {
69 'pixel_values': inputs['pixel_values'],
70 'pixel_attention_mask': inputs['pixel_attention_mask'].astype(np.bool_)
71 }
72 )[0]
73
74 ## Merge text and vision embeddings
75 inputs_embeds[inputs['input_ids'] == image_token_id] = image_features.reshape(-1, image_features.shape[-1])
76
77 logits, *present_key_values = decoder_session.run(None, dict(
78 inputs_embeds=inputs_embeds,
79 attention_mask=attention_mask,
80 position_ids=position_ids,
81 **past_key_values,
82 ))
83
84 ## Update values for next generation loop
85 input_ids = logits[:, -1].argmax(-1, keepdims=True)
86 attention_mask = np.ones_like(input_ids)
87 position_ids = position_ids[:, -1:] + 1
88 for j, key in enumerate(past_key_values):
89 past_key_values[key] = present_key_values[j]
90
91 generated_tokens = np.concatenate([generated_tokens, input_ids], axis=-1)
92 if (input_ids == eos_token_id).all():
93 break
94
95 ## (Optional) Streaming
96 print(processor.decode(input_ids[0]), end='')
97print()
98
99# 4. Output result
100print(processor.batch_decode(generated_tokens)) The image depicts a large, historic statue of Liberty situated on a small island in a body of water. The statue is a green, cylindrical structure with a human figure at the top, which is the actual statue of Liberty. The statue is mounted on a pedestal that is supported by a cylindrical tower. The pedestal is rectangular and appears to be made of stone or a similar material. The statue is surrounded by a large, flat, rectangular area that is likely a base for the statue.
In the background, there is a cityscape with a variety of buildings, including skyscrapers and high-rise buildings. The sky is clear with a gradient of colors, transitioning from a pale blue at the top to a deeper blue at the bottom. The buildings are mostly modern, with a mix of glass and concrete. The buildings are densely packed, with many skyscrapers and high-rise buildings visible.
There are trees and greenery visible on the left side of the image, indicating that the statue is located near a park or a park area. The water in the foreground is calm, with small ripples indicating that the statue is in the water.
The overall scene suggests a peaceful and serene environment, likely a public park or a park area in a city. The statue is likely a representation of liberty, representing the city's commitment to freedom and democracy.
### Analysis and Description:
#### Statue of Liberty:
- **Location**: The statue is located on a small island in a body of water.
- **Statue**: The statue is a green cylindrical structure with a human figure at the top, which is the actual statue of Liberty.
- **Pedestal**: The pedestal is rectangular and supports the statue.
- **Pedestrian**: The pedestal is surrounded by a flat rectangular area.
- **Water**: The water is calm, with small ripples indicating that the statue is in the water.
#### Cityscape:
- **Buildings**: The buildings are modern, with a mix of glass and concrete.
- **Sky**: The sky is clear with a gradient of colors, transitioning from a pale blue at the top to a deeper blue at the bottom.
- **Trees**: There are trees and greenery visible on the left side of the image, indicating that the statue is located near a park or a park area.
#### Environment:
- **Water**: The water is calm, with small ripples indicating that the statue is in the water.
- **Sky**: The sky is clear with a gradient of colors, transitioning from a pale blue at the top to a deeper blue at the bottom.
### Conclusion:
The image depicts a peaceful and serene public park or park area in a city, with the statue of Liberty prominently featured. The cityscape in the background includes modern buildings and a clear sky, suggesting a well-maintained public space.<end_of_utterance>torch.bfloat16) if your hardware supports it.1from transformers import AutoModelForVision2Seq
2import torch
3
4model = AutoModelForVision2Seq.from_pretrained(
5 "HuggingFaceTB/SmolVLM-Instruct",
6 torch_dtype=torch.bfloat16
7).to("cuda")1from transformers import AutoModelForVision2Seq, BitsAndBytesConfig
2import torch
3
4quantization_config = BitsAndBytesConfig(load_in_8bit=True)
5model = AutoModelForVision2Seq.from_pretrained(
6 "HuggingFaceTB/SmolVLM-Instruct",
7 quantization_config=quantization_config,
8)size={"longest_edge": N*512} when initializing the processor, where N is your desired value. The default N=4 works well, which results in input images of
size 2048×2048. Decreasing N can save GPU memory and is appropriate for lower-resolution images. This is also useful if you want to fine-tune on videos.
| Size | Mathvista | MMMU | OCRBench | MMStar | AI2D | ChartQA_Test | Science_QA | TextVQA Val | DocVQA Val |
|---|---|---|---|---|---|---|---|---|---|
| 256M | 35.9 | 28.3 | 52.6 | 34.6 | 47 | 55.8 | 73.6 | 49.9 | 58.3 |
| 500M | 40.1 | 33.7 | 61 | 38.3 | 59.5 | 63.2 | 79.7 | 60.5 | 70.5 |
| 2.2B | 43.9 | 38.3 | 65.5 | 41.8 | 64 | 71.6 | 84.5 | 72.1 | 79.7 |
1@article{marafioti2025smolvlm,
2 title={SmolVLM: Redefining small and efficient multimodal models},
3 author={Andrés Marafioti and Orr Zohar and Miquel Farré and Merve Noyan and Elie Bakouch and Pedro Cuenca and Cyril Zakka and Loubna Ben Allal and Anton Lozhkov and Nouamane Tazi and Vaibhav Srivastav and Joshua Lochner and Hugo Larcher and Mathieu Morlon and Lewis Tunstall and Leandro von Werra and Thomas Wolf},
4 journal={arXiv preprint arXiv:2504.05299},
5 year={2025}
6}TurboLLM (GPT-4.1-mini)HugLLM (Hugginface Open-source models)TestLLM (Experimental CPU-only)"Give me info on my websites SSL certificate""Check if my server is using quantum safe encyption for communication""Run a comprehensive security audit on my server"