preethamvj commited on
Commit
f7a35b6
·
verified ·
1 Parent(s): 6371ac9

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,130 +1,206 @@
 
 
 
 
 
 
 
 
1
 
2
- # chart-vision-qwen
3
 
4
- **Qwen2-VL-2B-Instruct fine-tuned on ChartQA** using LoRA adapters for chart question answering.
5
 
6
- *This is Submitted as a deliverable for Orange Problem, for NLP with DL course (UE23AM343BB1)
7
 
8
- **Team:** Langrangers (PES University)
9
- - Aaron Thomas Mathew — PES1UG23AM005
10
- - Aman Kumar Mishra — PES1UG23AM040
11
- - Preetham VJ — PES1UG23AM913
12
 
13
- **GitHub Repository:** [Aman-K-Mishra/orange-chartqa-slm](https://github.com/Aman-K-Mishra/orange-chartqa-slm)
14
 
15
- ---
16
 
17
- ## Model Description
18
 
19
- Given a chart image (bar chart, line chart, pie chart, etc.) and a natural language question, this model predicts the answer. It was fine-tuned from [Qwen/Qwen2-VL-2B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-2B-Instruct) using LoRA (Low-Rank Adaptation) on the full ChartQA training split (28,299 samples).
20
 
21
- | Property | Value |
22
- |---|---|
23
- | Base model | Qwen2-VL-2B-Instruct |
24
- | Fine-tuning method | LoRA (PEFT) |
25
- | Dataset | HuggingFaceM4/ChartQA |
26
- | Training samples | 28,299 |
27
- | Trainable parameters | 4.36M (0.20% of 2.21B) |
28
- | Hardware | Tesla T4 (15.6 GB VRAM) |
29
- | Epochs | 1 |
30
 
31
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  ## Training Details
34
 
35
- ### LoRA Configuration
36
- | Parameter | Value | Reason |
37
- |---|---|---|
38
- | Rank (`r`) | 16 | rank=8 too small for chart reasoning; rank=32 risks OOM |
39
- | Alpha | 32 | Standard `alpha = 2×rank` rule |
40
- | Dropout | 0.05 | Light regularisation to prevent adapter overfitting |
41
- | Target modules | q_proj, k_proj, v_proj, o_proj | Most impactful attention projections for VLMs |
42
-
43
- ### Training Hyperparameters
44
- | Parameter | Value | Reason |
45
- |---|---|---|
46
- | Batch size | 1 | OOM fix for T4 with max_length=768 |
47
- | Gradient accumulation | 16 steps | Effective batch = 16 |
48
- | Learning rate | 2e-4 | Standard for LoRA fine-tuning |
49
- | Max sequence length | 768 | Compromise: 512 too short, 1024 causes OOM |
50
- | Quantization | 8-bit (BitsAndBytes) | Full precision ≈ 16 GB; 8-bit ≈ 8 GB, safe for T4 |
51
- | Image resolution | 256–512 patches (28×28) | Matches Qwen2-VL patch size; T4-safe |
52
- | LR scheduler | Cosine annealing | Smooth decay over full epoch |
53
 
54
- ---
55
 
56
- ## How to Use
57
 
58
- ### Installation
59
 
60
- ```bash
61
- pip install transformers peft bitsandbytes accelerate datasets pillow
62
- ```
63
 
64
- ### Load Adapters and Run Inference
65
 
66
- ```python
67
- from transformers import AutoProcessor, Qwen2VLForConditionalGeneration, BitsAndBytesConfig
68
- from peft import PeftModel
69
- from PIL import Image
70
- import torch
71
 
72
- BASE_MODEL_ID = "Qwen/Qwen2-VL-2B-Instruct"
73
- ADAPTER_REPO = "preethamvj/chart-vision-qwen"
74
 
75
- # Load base model in 8-bit
76
- bnb_config = BitsAndBytesConfig(load_in_8bit=True)
77
- model = Qwen2VLForConditionalGeneration.from_pretrained(
78
- BASE_MODEL_ID,
79
- quantization_config=bnb_config,
80
- device_map="auto",
81
- torch_dtype=torch.float16
82
- )
83
 
84
- # Load LoRA adapters
85
- model = PeftModel.from_pretrained(model, ADAPTER_REPO)
86
 
87
- # Optional: merge adapters into base weights for faster inference
88
- model = model.merge_and_unload()
89
 
90
- processor = AutoProcessor.from_pretrained(
91
- BASE_MODEL_ID,
92
- min_pixels=256 * 28 * 28,
93
- max_pixels=512 * 28 * 28
94
- )
95
 
96
- # Inference
97
- image = Image.open("your_chart.png").convert("RGB")
98
- question = "What is the highest value in the chart?"
99
 
100
- messages = [{
101
- "role": "user",
102
- "content": [
103
- {"type": "image", "image": image},
104
- {"type": "text", "text": question}
105
- ]
106
- }]
107
 
108
- text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
109
- inputs = processor(text=[text], images=[image], return_tensors="pt").to("cuda")
110
 
111
- with torch.no_grad():
112
- output = model.generate(**inputs, max_new_tokens=64)
113
 
114
- answer = processor.decode(output[0], skip_special_tokens=True)
115
- print("Answer:", answer.split("assistant")[-1].strip())
116
- ```
117
 
118
- ---
119
 
120
- ## Intended Use
121
 
122
- This model is intended for chart question answering tasks — reading values, trends, comparisons, and facts from chart images. It is not designed for general visual question answering outside the chart domain.
123
 
124
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
- ## Limitations
 
127
 
128
- - Trained for only 1 epoch due to compute constraints (T4 GPU)
129
- - Loss shows high variance across steps, suggesting the learning rate may benefit from tuning in future runs
130
- - Performance may degrade on chart types not well-represented in ChartQA (e.g., highly complex infographics)
 
1
+ ---
2
+ base_model: Qwen/Qwen2-VL-2B-Instruct
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - base_model:adapter:Qwen/Qwen2-VL-2B-Instruct
7
+ - lora
8
+ ---
9
 
10
+ # Model Card for Model ID
11
 
12
+ <!-- Provide a quick summary of what the model is/does. -->
13
 
 
14
 
 
 
 
 
15
 
16
+ ## Model Details
17
 
18
+ ### Model Description
19
 
20
+ <!-- Provide a longer summary of what this model is. -->
21
 
 
22
 
 
 
 
 
 
 
 
 
 
23
 
24
+ - **Developed by:** [More Information Needed]
25
+ - **Funded by [optional]:** [More Information Needed]
26
+ - **Shared by [optional]:** [More Information Needed]
27
+ - **Model type:** [More Information Needed]
28
+ - **Language(s) (NLP):** [More Information Needed]
29
+ - **License:** [More Information Needed]
30
+ - **Finetuned from model [optional]:** [More Information Needed]
31
+
32
+ ### Model Sources [optional]
33
+
34
+ <!-- Provide the basic links for the model. -->
35
+
36
+ - **Repository:** [More Information Needed]
37
+ - **Paper [optional]:** [More Information Needed]
38
+ - **Demo [optional]:** [More Information Needed]
39
+
40
+ ## Uses
41
+
42
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
43
+
44
+ ### Direct Use
45
+
46
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
47
+
48
+ [More Information Needed]
49
+
50
+ ### Downstream Use [optional]
51
+
52
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
53
+
54
+ [More Information Needed]
55
+
56
+ ### Out-of-Scope Use
57
+
58
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
59
+
60
+ [More Information Needed]
61
+
62
+ ## Bias, Risks, and Limitations
63
+
64
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
65
+
66
+ [More Information Needed]
67
+
68
+ ### Recommendations
69
+
70
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
71
+
72
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
73
+
74
+ ## How to Get Started with the Model
75
+
76
+ Use the code below to get started with the model.
77
+
78
+ [More Information Needed]
79
 
80
  ## Training Details
81
 
82
+ ### Training Data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
85
 
86
+ [More Information Needed]
87
 
88
+ ### Training Procedure
89
 
90
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
 
91
 
92
+ #### Preprocessing [optional]
93
 
94
+ [More Information Needed]
 
 
 
 
95
 
 
 
96
 
97
+ #### Training Hyperparameters
 
 
 
 
 
 
 
98
 
99
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
 
100
 
101
+ #### Speeds, Sizes, Times [optional]
 
102
 
103
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
 
 
 
 
104
 
105
+ [More Information Needed]
 
 
106
 
107
+ ## Evaluation
 
 
 
 
 
 
108
 
109
+ <!-- This section describes the evaluation protocols and provides the results. -->
 
110
 
111
+ ### Testing Data, Factors & Metrics
 
112
 
113
+ #### Testing Data
 
 
114
 
115
+ <!-- This should link to a Dataset Card if possible. -->
116
 
117
+ [More Information Needed]
118
 
119
+ #### Factors
120
 
121
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
122
+
123
+ [More Information Needed]
124
+
125
+ #### Metrics
126
+
127
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
128
+
129
+ [More Information Needed]
130
+
131
+ ### Results
132
+
133
+ [More Information Needed]
134
+
135
+ #### Summary
136
+
137
+
138
+
139
+ ## Model Examination [optional]
140
+
141
+ <!-- Relevant interpretability work for the model goes here -->
142
+
143
+ [More Information Needed]
144
+
145
+ ## Environmental Impact
146
+
147
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
148
+
149
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
150
+
151
+ - **Hardware Type:** [More Information Needed]
152
+ - **Hours used:** [More Information Needed]
153
+ - **Cloud Provider:** [More Information Needed]
154
+ - **Compute Region:** [More Information Needed]
155
+ - **Carbon Emitted:** [More Information Needed]
156
+
157
+ ## Technical Specifications [optional]
158
+
159
+ ### Model Architecture and Objective
160
+
161
+ [More Information Needed]
162
+
163
+ ### Compute Infrastructure
164
+
165
+ [More Information Needed]
166
+
167
+ #### Hardware
168
+
169
+ [More Information Needed]
170
+
171
+ #### Software
172
+
173
+ [More Information Needed]
174
+
175
+ ## Citation [optional]
176
+
177
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
178
+
179
+ **BibTeX:**
180
+
181
+ [More Information Needed]
182
+
183
+ **APA:**
184
+
185
+ [More Information Needed]
186
+
187
+ ## Glossary [optional]
188
+
189
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
190
+
191
+ [More Information Needed]
192
+
193
+ ## More Information [optional]
194
+
195
+ [More Information Needed]
196
+
197
+ ## Model Card Authors [optional]
198
+
199
+ [More Information Needed]
200
+
201
+ ## Model Card Contact
202
 
203
+ [More Information Needed]
204
+ ### Framework versions
205
 
206
+ - PEFT 0.18.1
 
 
adapter_config.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "Qwen/Qwen2-VL-2B-Instruct",
7
+ "bias": "none",
8
+ "corda_config": null,
9
+ "ensure_weight_tying": false,
10
+ "eva_config": null,
11
+ "exclude_modules": null,
12
+ "fan_in_fan_out": false,
13
+ "inference_mode": true,
14
+ "init_lora_weights": true,
15
+ "layer_replication": null,
16
+ "layers_pattern": null,
17
+ "layers_to_transform": null,
18
+ "loftq_config": {},
19
+ "lora_alpha": 32,
20
+ "lora_bias": false,
21
+ "lora_dropout": 0.05,
22
+ "megatron_config": null,
23
+ "megatron_core": "megatron.core",
24
+ "modules_to_save": null,
25
+ "peft_type": "LORA",
26
+ "peft_version": "0.18.1",
27
+ "qalora_group_size": 16,
28
+ "r": 16,
29
+ "rank_pattern": {},
30
+ "revision": null,
31
+ "target_modules": [
32
+ "o_proj",
33
+ "k_proj",
34
+ "q_proj",
35
+ "v_proj"
36
+ ],
37
+ "target_parameters": null,
38
+ "task_type": "CAUSAL_LM",
39
+ "trainable_token_indices": null,
40
+ "use_dora": false,
41
+ "use_qalora": false,
42
+ "use_rslora": false
43
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:12da95933985d3e564831a7ee15f976b966def3691c3bb8fbf62ad3e8022e381
3
+ size 17469600
chat_template.jinja ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>system
2
+ You are a helpful assistant.<|im_end|>
3
+ {% endif %}<|im_start|>{{ message['role'] }}
4
+ {% if message['content'] is string %}{{ message['content'] }}<|im_end|>
5
+ {% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}<|vision_start|><|image_pad|><|vision_end|>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_start|><|video_pad|><|vision_end|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>
6
+ {% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant
7
+ {% endif %}
processor_config.json ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_processor": {
3
+ "data_format": "channels_first",
4
+ "do_convert_rgb": true,
5
+ "do_normalize": true,
6
+ "do_rescale": true,
7
+ "do_resize": true,
8
+ "image_mean": [
9
+ 0.48145466,
10
+ 0.4578275,
11
+ 0.40821073
12
+ ],
13
+ "image_processor_type": "Qwen2VLImageProcessorFast",
14
+ "image_std": [
15
+ 0.26862954,
16
+ 0.26130258,
17
+ 0.27577711
18
+ ],
19
+ "merge_size": 2,
20
+ "patch_size": 14,
21
+ "resample": 3,
22
+ "rescale_factor": 0.00392156862745098,
23
+ "size": {
24
+ "longest_edge": 401408,
25
+ "shortest_edge": 200704
26
+ },
27
+ "temporal_patch_size": 2
28
+ },
29
+ "processor_class": "Qwen2VLProcessor",
30
+ "video_processor": {
31
+ "data_format": "channels_first",
32
+ "default_to_square": true,
33
+ "do_convert_rgb": true,
34
+ "do_normalize": true,
35
+ "do_rescale": true,
36
+ "do_resize": true,
37
+ "do_sample_frames": false,
38
+ "image_mean": [
39
+ 0.48145466,
40
+ 0.4578275,
41
+ 0.40821073
42
+ ],
43
+ "image_processor_type": "Qwen2VLImageProcessor",
44
+ "image_std": [
45
+ 0.26862954,
46
+ 0.26130258,
47
+ 0.27577711
48
+ ],
49
+ "max_frames": 768,
50
+ "max_pixels": 401408,
51
+ "merge_size": 2,
52
+ "min_frames": 4,
53
+ "min_pixels": 200704,
54
+ "patch_size": 14,
55
+ "resample": 3,
56
+ "rescale_factor": 0.00392156862745098,
57
+ "return_metadata": false,
58
+ "size": {
59
+ "longest_edge": 12845056,
60
+ "shortest_edge": 3136
61
+ },
62
+ "temporal_patch_size": 2,
63
+ "video_processor_type": "Qwen2VLVideoProcessor"
64
+ }
65
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ff8cce547abc110590d19c6b5b6e0c6a7b4c8d1012d78b9c42131bae7f494a02
3
+ size 11420367
tokenizer_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": false,
24
+ "max_pixels": 401408,
25
+ "min_pixels": 200704,
26
+ "model_max_length": 32768,
27
+ "pad_token": "<|endoftext|>",
28
+ "padding_side": "left",
29
+ "processor_class": "Qwen2VLProcessor",
30
+ "split_special_tokens": false,
31
+ "tokenizer_class": "Qwen2Tokenizer",
32
+ "unk_token": null
33
+ }