rahilsinghi commited on
Commit
7c73aff
·
verified ·
1 Parent(s): 4e9d1c3

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +245 -0
README.md ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ tags:
5
+ - vision
6
+ - vision-language
7
+ - knowledge-distillation
8
+ - egocentric-qa
9
+ - qwen2-vl
10
+ - edge-deployment
11
+ - model-compression
12
+ datasets:
13
+ - custom-egocentric-qa
14
+ metrics:
15
+ - latency
16
+ - throughput
17
+ - vram-usage
18
+ model-index:
19
+ - name: FirstSight-Qwen2-VL-2B-Distilled
20
+ results:
21
+ - task:
22
+ type: visual-question-answering
23
+ name: Egocentric Visual Question Answering
24
+ metrics:
25
+ - type: compression-ratio
26
+ value: 3.75
27
+ name: Model Compression
28
+ - type: speedup
29
+ value: 5.16
30
+ name: Inference Speedup
31
+ - type: vram-reduction
32
+ value: 67.9
33
+ name: VRAM Reduction (%)
34
+ ---
35
+
36
+ # FirstSight: Distilled Qwen2-VL-2B for Efficient Egocentric QA
37
+
38
+ ## Model Description
39
+
40
+ FirstSight is a **knowledge-distilled vision-language model** optimized for efficient egocentric question answering on edge devices. This model is distilled from [Qwen2-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct) using advanced distillation techniques, achieving **3.75× compression** with minimal performance degradation.
41
+
42
+ ### Key Highlights
43
+
44
+ - 🚀 **5.16× faster inference** than teacher model
45
+ - 💾 **67.9% VRAM reduction** (9.39 GB savings)
46
+ - 📦 **73.4% smaller model size** (2.21B vs 8.29B parameters)
47
+ - ⚡ **Optimized for edge deployment** on resource-constrained devices
48
+ - 🎯 **Specialized for egocentric scenarios** (first-person perspective)
49
+
50
+ ### Model Architecture
51
+
52
+ - **Base Model**: [Qwen2-VL-2B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-2B-Instruct)
53
+ - **Teacher Model**: [Qwen2-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct)
54
+ - **Student Parameters**: 2.21B
55
+ - **Precision**: BFloat16 mixed precision
56
+ - **Distillation Method**: Logit-based knowledge distillation with KL divergence
57
+
58
+ ## Training Details
59
+
60
+ ### Training Data
61
+
62
+ - **Dataset**: Synthetic egocentric QA dataset with 5,000 training samples
63
+ - **Validation Set**: 1,000 samples
64
+ - **Question Types**: Object recognition, spatial reasoning, action understanding, temporal queries, environment understanding
65
+ - **Scenarios**: Kitchen, living room, office, outdoor, workshop
66
+
67
+ ### Training Procedure
68
+
69
+ - **Framework**: PyTorch with Hugging Face Transformers
70
+ - **Epochs**: 10
71
+ - **Batch Size**: 2 per GPU with 4× gradient accumulation
72
+ - **Learning Rate**: 1e-5 (AdamW optimizer)
73
+ - **Scheduler**: Cosine annealing with 100 warmup steps
74
+ - **Loss Function**: Weighted combination of distillation loss (α=0.7) and hard label loss (α=0.3)
75
+ - **Temperature**: 2.0 for knowledge distillation
76
+ - **Hardware**: NVIDIA Quadro RTX 8000 (48GB)
77
+ - **Training Time**: ~4 hours
78
+
79
+ ### Training Hyperparameters
80
+
81
+ ```python
82
+ {
83
+ "learning_rate": 1e-5,
84
+ "optimizer": "AdamW",
85
+ "weight_decay": 0.01,
86
+ "gradient_accumulation_steps": 4,
87
+ "max_grad_norm": 1.0,
88
+ "warmup_steps": 100,
89
+ "temperature": 2.0,
90
+ "alpha": 0.7,
91
+ "epochs": 10
92
+ }
93
+ ```
94
+
95
+ ## Performance Metrics
96
+
97
+ ### Inference Speed
98
+
99
+ | Metric | Teacher (7B) | Student (2B) | Improvement |
100
+ |--------|-------------|-------------|-------------|
101
+ | **Avg Latency** | 1.260s | 0.244s | **5.16×** |
102
+ | **Throughput (samples/s)** | 0.79 | 4.10 | **5.16×** |
103
+ | **Throughput (tokens/s)** | 34.33 | 162.55 | **5.16×** |
104
+
105
+ ### Memory Usage
106
+
107
+ | Metric | Teacher (7B) | Student (2B) | Savings |
108
+ |--------|-------------|-------------|---------|
109
+ | **Model Size** | 8.29B params | 2.21B params | **73.4%** |
110
+ | **Peak VRAM** | 13.81 GB | 4.43 GB | **9.39 GB** |
111
+ | **VRAM Reduction** | - | - | **67.9%** |
112
+
113
+ ### Model Compression
114
+
115
+ - **Compression Ratio**: 3.75×
116
+ - **Parameter Reduction**: 73.4%
117
+ - **From**: 8.29B parameters
118
+ - **To**: 2.21B parameters
119
+
120
+ ## Usage
121
+
122
+ ### Installation
123
+
124
+ ```bash
125
+ pip install transformers torch pillow qwen-vl-utils
126
+ ```
127
+
128
+ ### Inference Example
129
+
130
+ ```python
131
+ from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
132
+ from PIL import Image
133
+ import torch
134
+
135
+ # Load model and processor
136
+ model_name = "YOUR_USERNAME/firstsight-qwen2-vl-2b-distilled"
137
+ model = Qwen2VLForConditionalGeneration.from_pretrained(
138
+ model_name,
139
+ torch_dtype=torch.bfloat16,
140
+ device_map="auto"
141
+ )
142
+ processor = AutoProcessor.from_pretrained(model_name)
143
+
144
+ # Prepare image and question
145
+ image = Image.open("egocentric_image.jpg")
146
+ question = "What object am I holding in my right hand?"
147
+
148
+ # Create conversation template
149
+ messages = [
150
+ {
151
+ "role": "system",
152
+ "content": "You are a helpful assistant."
153
+ },
154
+ {
155
+ "role": "user",
156
+ "content": [
157
+ {"type": "image", "image": image},
158
+ {"type": "text", "text": f"Question: {question}\nAnswer concisely:"}
159
+ ]
160
+ }
161
+ ]
162
+
163
+ # Prepare inputs
164
+ text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
165
+ inputs = processor(text=[text], images=[image], return_tensors="pt", padding=True)
166
+ inputs = inputs.to(model.device)
167
+
168
+ # Generate answer
169
+ with torch.no_grad():
170
+ outputs = model.generate(
171
+ **inputs,
172
+ max_new_tokens=128,
173
+ do_sample=False
174
+ )
175
+
176
+ # Decode response
177
+ response = processor.batch_decode(
178
+ outputs[:, inputs['input_ids'].shape[1]:],
179
+ skip_special_tokens=True,
180
+ clean_up_tokenization_spaces=False
181
+ )[0]
182
+
183
+ print(f"Answer: {response}")
184
+ ```
185
+
186
+ ## Intended Use
187
+
188
+ ### Primary Use Cases
189
+
190
+ - **Egocentric Visual Question Answering**: Answer questions about first-person perspective images/videos
191
+ - **Edge Device Deployment**: Run VLM inference on resource-constrained hardware (mobile, IoT, AR/VR)
192
+ - **Real-time Assistive Systems**: Power low-latency visual assistants for wearable cameras
193
+ - **Smart Glasses Applications**: Enable efficient VLM capabilities on AR/VR headsets
194
+
195
+ ### Supported Question Types
196
+
197
+ 1. **Object Recognition**: "What object did I just pick up?"
198
+ 2. **Spatial Reasoning**: "Where is the nearest door?"
199
+ 3. **Action Understanding**: "What action am I performing?"
200
+ 4. **Temporal Queries**: "What was I looking at 5 seconds ago?"
201
+ 5. **Environment Understanding**: "What room am I in?"
202
+ 6. **Counting**: "How many items are on the table?"
203
+ 7. **Attribute Recognition**: "What color is the object I'm holding?"
204
+
205
+ ## Limitations
206
+
207
+ - Model is specialized for **egocentric scenarios** and may perform worse on third-person images
208
+ - Trained on **synthetic data** - real-world performance may vary
209
+ - **No multimodal training** - relies solely on knowledge distillation
210
+ - May inherit biases from the teacher model (Qwen2-VL-7B)
211
+ - Limited to **short-form QA** - not optimized for long conversations
212
+
213
+ ## Ethical Considerations
214
+
215
+ - **Privacy**: Egocentric images often contain sensitive personal information. Ensure proper consent and data protection.
216
+ - **Bias**: Model may exhibit biases from training data and teacher model. Evaluate on diverse datasets.
217
+ - **Misuse**: Could be used for unauthorized surveillance. Deploy responsibly with user consent.
218
+
219
+ ## Citation
220
+
221
+ If you use this model in your research, please cite:
222
+
223
+ ```bibtex
224
+ @misc{firstsight2024,
225
+ title={FirstSight: Efficient Knowledge Distillation for Vision-Language Models on Edge Devices},
226
+ author={NYU HPML Project Team},
227
+ year={2024},
228
+ howpublished={\url{https://huggingface.co/YOUR_USERNAME/firstsight-qwen2-vl-2b-distilled}},
229
+ note={Distilled from Qwen2-VL-7B-Instruct for egocentric question answering}
230
+ }
231
+ ```
232
+
233
+ ## Model Card Authors
234
+
235
+ NYU High Performance Machine Learning (HPML) Project Team
236
+
237
+ ## Model Card Contact
238
+
239
+ For questions or feedback, please open an issue on the [GitHub repository](https://github.com/rahils/firstsight).
240
+
241
+ ---
242
+
243
+ **Training Date**: December 8-9, 2024
244
+ **Evaluation Date**: 2025-12-09T00:32:52.669538
245
+ **Framework**: PyTorch 2.3.0, Transformers 4.57.3, BitsAndBytes 0.48.2