Built a resource-efficient Vision-Language Model (VLM) for VQA by fine-tuning a 1.3B-parameter LLaMA model using QLoRA and 4-bit quantization, achieving functional VQA on low-spec hardware.
0
stars
3
commits
Jupyter Notebook
primary language
Dec 2, 2025
updated
This project implements a compact and efficient Vision-Language Model (VLM) for multimodal tasks such as:
Unlike traditional cross-attention VLMs, this design treats image content as a sequence of discrete semantic visual tokens using a pre-trained tokenizer (e.g., DualViTok). These tokens are processed jointly with natural language by a lightweight Causal Language Model (LLaMA).
| Feature | Description |
|---|---|
| Model | LLaMA-3.2-1B (1.3B parameters) |
| Efficiency | QLoRA (Quantized LoRA) + 4-bit quantization for low-resource training |
| Visual Core | Semantic Visual Tokenizer (e.g., DualViTok) converts images into discrete token sequences |
| Main Tasks | VQA & Caption Generation |
| Advanced Task | Autoregressive Image Inpainting using token prediction |
git clone https://github.com/aman050504/Set-Covering-Using-Genetic-Algorithm.git # Replace if different cd Set-Covering-Using-Genetic-Algorithm
It is recommended to use a virtual environment:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 pip install transformers peft accelerate bitsandbytes sentencepiece pandas pillow tqdm tensorboard
This project supports standard VQA / captioning datasets: Flickr8k MS COCO Captions / VQA
/root/nlp/NLP_Project_Data/Flickr8k/ ├── Images/ │ ├── 1000092795.jpg │ └── ... ├── Flickr8k.token.txt └── ...
Main training script: train_vlm.py Update the following in script before training: LLaMA model path (e.g., meta-llama/LLaMA-3.2-1B) Visual tokenizer checkpoint
python train_vlm.py
--data_dir /path/to/Flickr8k
--output_dir /path/to/checkpoints
--epochs 5
--batch_size 4
--learning_rate 2e-4
--qlora_rank 16
--qlora_alpha 32
--grad_clip 1.0
TensorBoard logs are saved in --log_dir.
Inference Inference script: inference_vlm.py
python inference_vlm.py
--checkpoint_path /path/to/best_model
--image /path/to/image.jpg
--question "Generate a descriptive caption for this image."
python inference_vlm.py
--checkpoint_path /path/to/best_model
--image /path/to/image.jpg
--question "What activity are the children doing?"
--max_tokens 30
--temperature 0.7
This advanced mode uses the LLM to predict masked visual tokens:
Mask image region → [MASK] token insertion Encode image as visual tokens LLM autoregressively predicts missing tokens Reconstruct final image using decoder
Full implementation is included in: vlm_training_inference.ipynb
QLoRA: Low-resource fine-tuning with quantization DualViTok / VQ-GAN style discrete visual encoding
3 commits
Jupyter Notebook
98.4%
Python
1.6%
Built a resource-efficient Vision-Language Model (VLM) for VQA by fine-tuning a 1.3B-parameter LLaMA model using QLoRA and 4-bit quantization, achieving functional VQA on low-spec hardware.
0
stars
3
commits
Jupyter Notebook
primary language
Dec 2, 2025
updated
This project implements a compact and efficient Vision-Language Model (VLM) for multimodal tasks such as:
Unlike traditional cross-attention VLMs, this design treats image content as a sequence of discrete semantic visual tokens using a pre-trained tokenizer (e.g., DualViTok). These tokens are processed jointly with natural language by a lightweight Causal Language Model (LLaMA).
| Feature | Description |
|---|---|
| Model | LLaMA-3.2-1B (1.3B parameters) |
| Efficiency | QLoRA (Quantized LoRA) + 4-bit quantization for low-resource training |
| Visual Core | Semantic Visual Tokenizer (e.g., DualViTok) converts images into discrete token sequences |
| Main Tasks | VQA & Caption Generation |
| Advanced Task | Autoregressive Image Inpainting using token prediction |
git clone https://github.com/aman050504/Set-Covering-Using-Genetic-Algorithm.git # Replace if different cd Set-Covering-Using-Genetic-Algorithm
It is recommended to use a virtual environment:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 pip install transformers peft accelerate bitsandbytes sentencepiece pandas pillow tqdm tensorboard
This project supports standard VQA / captioning datasets: Flickr8k MS COCO Captions / VQA
/root/nlp/NLP_Project_Data/Flickr8k/ ├── Images/ │ ├── 1000092795.jpg │ └── ... ├── Flickr8k.token.txt └── ...
Main training script: train_vlm.py Update the following in script before training: LLaMA model path (e.g., meta-llama/LLaMA-3.2-1B) Visual tokenizer checkpoint
python train_vlm.py
--data_dir /path/to/Flickr8k
--output_dir /path/to/checkpoints
--epochs 5
--batch_size 4
--learning_rate 2e-4
--qlora_rank 16
--qlora_alpha 32
--grad_clip 1.0
TensorBoard logs are saved in --log_dir.
Inference Inference script: inference_vlm.py
python inference_vlm.py
--checkpoint_path /path/to/best_model
--image /path/to/image.jpg
--question "Generate a descriptive caption for this image."
python inference_vlm.py
--checkpoint_path /path/to/best_model
--image /path/to/image.jpg
--question "What activity are the children doing?"
--max_tokens 30
--temperature 0.7
This advanced mode uses the LLM to predict masked visual tokens:
Mask image region → [MASK] token insertion Encode image as visual tokens LLM autoregressively predicts missing tokens Reconstruct final image using decoder
Full implementation is included in: vlm_training_inference.ipynb
QLoRA: Low-resource fine-tuning with quantization DualViTok / VQ-GAN style discrete visual encoding
3 commits
Jupyter Notebook
98.4%
Python
1.6%