Susant-Achary commited on
Commit
4052ac9
·
verified ·
1 Parent(s): a746521

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +100 -10
README.md CHANGED
@@ -7,31 +7,56 @@ tags:
7
  - lora
8
  - transformers
9
  model-index:
10
- - name: SmolVLM2-500M-Video-Instruct-vqav2
11
- results: []
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ---
13
 
14
- <!-- This model card has been generated automatically according to the information the Trainer had access to. You
15
- should probably proofread and complete it, then remove this comment. -->
16
 
17
  # SmolVLM2-500M-Video-Instruct-vqav2
18
 
19
- This model is a fine-tuned version of [HuggingFaceTB/SmolVLM2-500M-Video-Instruct](https://huggingface.co/HuggingFaceTB/SmolVLM2-500M-Video-Instruct) on an unknown dataset.
20
 
21
  ## Model description
22
 
23
- More information needed
24
 
25
  ## Intended uses & limitations
26
 
27
- More information needed
 
 
 
 
 
28
 
29
  ## Training and evaluation data
30
 
31
- More information needed
32
 
33
  ## Training procedure
34
 
 
 
 
 
 
 
 
 
 
35
  ### Training hyperparameters
36
 
37
  The following hyperparameters were used during training:
@@ -44,8 +69,73 @@ The following hyperparameters were used during training:
44
  - lr_scheduler_warmup_steps: 50
45
  - num_epochs: 1
46
 
47
- ### Training results
48
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
 
51
  ### Framework versions
 
7
  - lora
8
  - transformers
9
  model-index:
10
+ - name: Susant-Achary/SmolVLM2-500M-Video-Instruct-VQA2
11
+ results:
12
+ - task:
13
+ type: visual-question-answering
14
+ dataset:
15
+ type: jinaai/table-vqa
16
+ name: jinaai/table-vqa
17
+ metrics:
18
+ - type: training_loss
19
+ value: 0.7473664236068726
20
+ datasets:
21
+ - jinaai/table-vqa
22
+ language:
23
+ - en
24
+ pipeline_tag: visual-question-answering
25
  ---
26
 
 
 
27
 
28
  # SmolVLM2-500M-Video-Instruct-vqav2
29
 
30
+ This model is a fine-tuned version of [HuggingFaceTB/SmolVLM2-500M-Video-Instruct](https://huggingface.co/HuggingFaceTB/SmolVLM2-500M-Video-Instruct) on the [jinaai/table-vqa](https://huggingface.co/datasets/jinaai/table-vqa) dataset.
31
 
32
  ## Model description
33
 
34
+ This model is a SmolVLM2-500M-Video-Instruct model fine-tuned for Visual Question Answering on table images using the jinaai/table-vqa dataset. It was fine-tuned using QLoRA for efficient training on consumer GPUs.
35
 
36
  ## Intended uses & limitations
37
 
38
+ This model is intended for Visual Question Answering tasks specifically on images containing tables. It can be used to answer questions about the content of tables within images.
39
+
40
+ Limitations:
41
+ - Performance may vary on different types of images or questions outside of the table VQA domain.
42
+ - The model was fine-tuned on a small subset of the dataset for demonstration purposes.
43
+ - The model's performance is dependent on the quality and nature of the jinaai/table-vqa dataset.
44
 
45
  ## Training and evaluation data
46
 
47
+ The model was trained on a subset of the [jinaai/table-vqa](https://huggingface.co/datasets/jinaai/table-vqa) dataset. The training dataset size is 800 examples, and the test dataset size is 200 examples.
48
 
49
  ## Training procedure
50
 
51
+ The model was fine-tuned using the QLoRA method with the following configuration:
52
+ - `r=8`
53
+ - `lora_alpha=8`
54
+ - `lora_dropout=0.1`
55
+ - `target_modules=['down_proj','o_proj','k_proj','q_proj','gate_proj','up_proj','v_proj']`
56
+ - `use_dora=False`
57
+ - `init_lora_weights="gaussian"`
58
+ - 4-bit quantization (`bnb_4bit_use_double_quant=True`, `bnb_4bit_quant_type="nf4"`, `bnb_4bit_compute_dtype=torch.bfloat16`)
59
+
60
  ### Training hyperparameters
61
 
62
  The following hyperparameters were used during training:
 
69
  - lr_scheduler_warmup_steps: 50
70
  - num_epochs: 1
71
 
72
+ ### Direct Use
73
+ ```python
74
+ import torch
75
+ from peft import PeftModel, PeftConfig
76
+ from transformers import AutoProcessor, Idefics3ForConditionalGeneration, BitsAndBytesConfig
77
+ from PIL import Image
78
+ import requests
79
+
80
+ # Define the base model and the fine-tuned adapter repository
81
+ base_model_id = "HuggingFaceTB/SmolVLM2-500M-Video-Instruct"
82
+ adapter_model_id = "Susant-Achary/SmolVLM2-500M-Video-Instruct-vqav2"
83
+
84
+ # Load the processor from the base model
85
+ processor = AutoProcessor.from_pretrained(base_model_id)
86
+
87
+ # Load the base model with quantization
88
+ bnb_config = BitsAndBytesConfig(
89
+ load_in_4bit=True,
90
+ bnb_4bit_use_double_quant=True,
91
+ bnb_4bit_quant_type="nf4",
92
+ bnb_4bit_compute_dtype=torch.bfloat16
93
+ )
94
+
95
+ model = Idefics3ForConditionalGeneration.from_pretrained(
96
+ base_model_id,
97
+ quantization_config=bnb_config,
98
+ _attn_implementation="flash_attention_2",
99
+ device_map="auto"
100
+ )
101
+
102
+ # Load the adapter and add it to the base model
103
+ model = PeftModel.from_pretrained(model, adapter_model_id)
104
+
105
+ # Prepare an example image and question
106
+ # You can replace this with your own image and question
107
+ url = "https://www.gstatic.com/webp/gallery/2.jpg"
108
+ image = Image.open(requests.get(url, stream=True).raw)
109
+ question = "What is in the image?"
110
+
111
+ # Prepare the input for the model
112
+ messages = [
113
+ {
114
+ "role": "user",
115
+ "content": [
116
+ {"type": "text", "text": "Answer briefly."},
117
+ {"type": "image"},
118
+ {"type": "text", "text": question}
119
+ ]
120
+ },
121
+ {
122
+ "role": "assistant",
123
+ "content": [
124
+ {"type": "text", "text": None}
125
+ ]
126
+ }
127
+ ]
128
+
129
+ prompt = processor.apply_chat_template(messages, add_generation_prompt=False)
130
+ inputs = processor(text=[prompt], images=[image], return_tensors="pt").to(model.device) # Move inputs to model device
131
+
132
+ # Generate a response
133
+ generated_ids = model.generate(**inputs, max_new_tokens=100)
134
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
135
+
136
+ # Print the generated response
137
+ print(generated_text)
138
+ ```
139
 
140
 
141
  ### Framework versions