pcuenq HF staff commited on
Commit
3e85ad4
1 Parent(s): f485460

Model card suggestions

Browse files
Files changed (1) hide show
  1. README.md +22 -20
README.md CHANGED
@@ -5,45 +5,42 @@ datasets:
5
  - HuggingFaceM4/the_cauldron
6
  - HuggingFaceM4/Docmatix
7
  pipeline_tag: image-text-to-text
 
 
8
  ---
9
 
10
- # Model Card for Model ID
11
 
12
  SmolVLM is a compact open multimodal model that accepts arbitrary sequences of image and text inputs to produce text outputs. Designed for efficiency, SmolVLM can answer questions about images, describe visual content, create stories grounded on multiple images, or function as a pure language model without visual inputs. Its lightweight architecture makes it suitable for on-device applications while maintaining strong performance on multimodal tasks.
13
 
14
- ## Model Details
15
-
16
- ### Model Description
17
-
18
- <!-- Provide a longer summary of what this model is. -->
19
-
20
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
21
 
22
  - **Developed by:** Hugging Face 🤗
23
  - **Model type:** Multi-modal model (image+text)
24
  - **Language(s) (NLP):** English
25
  - **License:** Apache 2.0
 
26
 
27
- ### Model Sources [optional]
28
-
29
- <!-- Provide the basic links for the model. -->
30
 
31
- - **Repository:** [More Information Needed]
32
- - **Paper [optional]:** [More Information Needed]
33
  - **Demo:** [SmolVLM Demo](https://huggingface.co/spaces/HuggingFaceTB/SmolVLM)
 
 
 
34
 
35
  ## Uses
36
 
37
  SmolVLM can be used for inference on multimodal (image + text) tasks where the input comprises text queries along with one or more images. Text and images can be interleaved arbitrarily, enabling tasks like image captioning, visual question answering, and storytelling based on visual content. The model does not support image generation.
38
 
39
  To fine-tune SmolVLM on a specific task, you can follow the fine-tuning tutorial.
 
40
 
41
  ### Technical Summary
42
 
43
- SmolVLM leverages the lightweight SmolLM2 language model to provide a compact yet powerful multimodal experience. It introduces several changes compared to previous models:
44
 
45
  - **Image compression:** We introduce a more radical image compression compared to Idefics3 to enable the model to infer faster and use less RAM.
46
- - **Visual Token Encoding:** It uses 81 visual tokens to encode image patches of size 384*384. Larger images are divided into patches, each encoded separately, enhancing efficiency without compromising performance.
47
 
48
  More details about the training and architecture are available in our technical report.
49
 
@@ -67,7 +64,8 @@ image2 = load_image("https://huggingface.co/spaces/merve/chameleon-7b/resolve/ma
67
  # Initialize processor and model
68
  processor = AutoProcessor.from_pretrained("HuggingFaceTB/SmolVLM-Instruct")
69
  model = AutoModelForVision2Seq.from_pretrained(
70
- "HuggingFaceTB/SmolVLM-Instruct", torch_dtype=torch.bfloat16
 
71
  ).to(DEVICE)
72
 
73
  # Create input messages
@@ -97,11 +95,14 @@ messages = [
97
  # Prepare inputs
98
  prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
99
  inputs = processor(text=prompt, images=[image1, image2], return_tensors="pt")
100
- inputs = {k: v.to(DEVICE) for k, v in inputs.items()}
101
 
102
  # Generate outputs
103
  generated_ids = model.generate(**inputs, max_new_tokens=500)
104
- generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)
 
 
 
105
 
106
  print(generated_texts[0])
107
  ```
@@ -130,11 +131,12 @@ import torch
130
  quantization_config = BitsAndBytesConfig(load_in_8bit=True)
131
  model = AutoModelForVision2Seq.from_pretrained(
132
  "HuggingFaceTB/SmolVLM-Instruct",
133
- quantization_config=quantization_config
134
  )
135
  ```
136
 
137
- **Vision Encoder Efficiency**: Adjust the image resolution by setting `size={"longest_edge": N*384}` when initializing the processor, where N is your desired value. The default `N=4` works well, but for documents, `N=5` might be beneficial. Decreasing N can save GPU memory for lower-resolution images. This is also useful if you want to fine-tune on videos.
 
138
 
139
 
140
  ## Misuse and Out-of-scope Use
 
5
  - HuggingFaceM4/the_cauldron
6
  - HuggingFaceM4/Docmatix
7
  pipeline_tag: image-text-to-text
8
+ language:
9
+ - en
10
  ---
11
 
12
+ # SmolVLM Instruct
13
 
14
  SmolVLM is a compact open multimodal model that accepts arbitrary sequences of image and text inputs to produce text outputs. Designed for efficiency, SmolVLM can answer questions about images, describe visual content, create stories grounded on multiple images, or function as a pure language model without visual inputs. Its lightweight architecture makes it suitable for on-device applications while maintaining strong performance on multimodal tasks.
15
 
16
+ ## Model Summary
 
 
 
 
 
 
17
 
18
  - **Developed by:** Hugging Face 🤗
19
  - **Model type:** Multi-modal model (image+text)
20
  - **Language(s) (NLP):** English
21
  - **License:** Apache 2.0
22
+ - **Architecture:** Based on [Idefics3](https://huggingface.co/HuggingFaceM4/Idefics3-8B-Llama3) (see more details below)
23
 
24
+ ## Resources
 
 
25
 
 
 
26
  - **Demo:** [SmolVLM Demo](https://huggingface.co/spaces/HuggingFaceTB/SmolVLM)
27
+ - **Blog:** [More Information Needed]
28
+ - **Technical Report:** [More Information Needed]
29
+ - **Repository:** [More Information Needed]
30
 
31
  ## Uses
32
 
33
  SmolVLM can be used for inference on multimodal (image + text) tasks where the input comprises text queries along with one or more images. Text and images can be interleaved arbitrarily, enabling tasks like image captioning, visual question answering, and storytelling based on visual content. The model does not support image generation.
34
 
35
  To fine-tune SmolVLM on a specific task, you can follow the fine-tuning tutorial.
36
+ <!-- todo: add link to fine-tuning tutorial -->
37
 
38
  ### Technical Summary
39
 
40
+ SmolVLM leverages the lightweight SmolLM2 language model to provide a compact yet powerful multimodal experience. It introduces several changes compared to previous Idefics models:
41
 
42
  - **Image compression:** We introduce a more radical image compression compared to Idefics3 to enable the model to infer faster and use less RAM.
43
+ - **Visual Token Encoding:** SmolVLM uses 81 visual tokens to encode image patches of size 384×384. Larger images are divided into patches, each encoded separately, enhancing efficiency without compromising performance.
44
 
45
  More details about the training and architecture are available in our technical report.
46
 
 
64
  # Initialize processor and model
65
  processor = AutoProcessor.from_pretrained("HuggingFaceTB/SmolVLM-Instruct")
66
  model = AutoModelForVision2Seq.from_pretrained(
67
+ "HuggingFaceTB/SmolVLM-Instruct",
68
+ torch_dtype=torch.bfloat16,
69
  ).to(DEVICE)
70
 
71
  # Create input messages
 
95
  # Prepare inputs
96
  prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
97
  inputs = processor(text=prompt, images=[image1, image2], return_tensors="pt")
98
+ inputs = inputs.to(DEVICE)
99
 
100
  # Generate outputs
101
  generated_ids = model.generate(**inputs, max_new_tokens=500)
102
+ generated_texts = processor.batch_decode(
103
+ generated_ids,
104
+ skip_special_tokens=True,
105
+ )
106
 
107
  print(generated_texts[0])
108
  ```
 
131
  quantization_config = BitsAndBytesConfig(load_in_8bit=True)
132
  model = AutoModelForVision2Seq.from_pretrained(
133
  "HuggingFaceTB/SmolVLM-Instruct",
134
+ quantization_config=quantization_config,
135
  )
136
  ```
137
 
138
+ **Vision Encoder Efficiency**: Adjust the image resolution by setting `size={"longest_edge": N*384}` when initializing the processor, where N is your desired value. The default `N=4` works well, which results in input images of
139
+ size 1536×1536. For documents, `N=5` might be beneficial. 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.
140
 
141
 
142
  ## Misuse and Out-of-scope Use