CoolFace
Modelpublic

parani01/Fine-tuned-physics-VLM-on-LoRA-and-QLoRA

sourceHugging Faceupdated 1y agoView on Hugging Face
3likes50downloads
Model Card

Fine-tuned Physics VLM: Qwen2-VL-7B with LoRA & QLoRA πŸ§ͺ⚑

Model Details

Model Description

A specialized vision-language model fine-tuned for physics problem solving, combining OCR capabilities with mathematical reasoning through an innovative multi-adapter training approach.

**Attribute****Details**
Developed byParanidharan
Model typeVision-Language Model (VLM) with LoRA/QLoRA adapters
Language(s) (NLP)English
LicenseApache 2.0 (inherited from base model)
Finetuned from modelQwen/Qwen2-VL-7B-Instruct
Fine-tuning FrameworkPEFT 0.17.1 + bitsandbytes (QLoRA)
Distributed Training & MonitoringDeepSpeed ZeRO-3 + Weights & Biases
Librarytransformers, peft
Tagslora, qlora, vision-language, physics, education, deepspeed

Model Sources

🎯 Model Overview

This model is a fine-tuned version of Qwen2-VL-7B-Instruct specifically optimized for physics education and problem-solving tasks. The model demonstrates excellent OCR capabilities with math-friendly reasoning, making it ideal for interpreting and solving physics problems from images.

Key Capabilities

  • β€”OCR Excellence: Accurate text extraction from physics diagrams and equations
  • β€”Mathematical Reasoning: Solid problem-solving capabilities for physics concepts
  • β€”Multi-modal Understanding: Seamless integration of visual and textual information
  • β€”Structured Output: JSON-formatted responses for auto-grading compatibility

Technical Architecture

Training Strategy

Our approach uses a hybrid multi-adapter fine-tuning strategy that optimizes different model components with specialized techniques:

  • β€”QLoRA (4-bit quantization) on LLM blocks using bitsandbytes + peft
  • β€”Tiny LoRA (r=4/8) on vision-language projector linear layers
  • β€”Frozen vision encoder to preserve pre-trained visual representations

Infrastructure & Scaling

Distributed Training Setup:

  • β€”Hardware: 4Γ—NVIDIA A6000 (24GB VRAM each) with H200 migration support
  • β€”Framework: DeepSpeed ZeRO-3 + Hugging Face Accelerate for distributed computing
  • β€”Precision: Mixed precision (bf16) with gradient accumulation
  • β€”Effective Batch Size: 32-64 sequences across distributed setup
  • β€”Total GPU Hours: 16 GPU hours (4 hours Γ— 4 GPUs)
  • β€”Distributed Strategy: DeepSpeed ZeRO-3 for memory optimization and model sharding
  • β€”Monitoring: Weights & Biases integration with tqdm progress tracking

Training Configuration

python
# Key Training Parameters
- Base Model: Qwen2-VL-7B-Instruct
- LoRA Rank: 4-8 (vision-language projector)
- QLoRA: 4-bit quantization (LLM blocks)
- Batch Size: 32-64 effective
- Precision: bf16 mixed precision
- Optimizer: AdamW with gradient accumulation
- Epochs: 3
- Training Duration: 4 hours wall-clock (16 GPU hours total)
- GPU Type: 4Γ—NVIDIA A6000 (24GB each)

πŸ“Š Training Details

Dataset

Trained on ScienceQA - a comprehensive multi-subject dataset with strong physics representation.

Data Format:

json
{
  "image": "path/to/physics_problem.jpg",
  "question": "Calculate the acceleration of the object...",
  "answer": "The acceleration is 9.8 m/sΒ² because..."
}

Training Metrics

Training Efficiency:

  • β€”Total Training Time: 4 hours wall-clock time
  • β€”Total GPU Hours: 16 GPU hours (4Γ—A6000 for 4 hours)
  • β€”GPU Type: NVIDIA A6000 (24GB VRAM each)
  • β€”Distributed Computing: DeepSpeed ZeRO-3 for efficient multi-GPU training
  • β€”GPU Utilization: Optimized with gradient accumulation and mixed precision
  • β€”Memory Efficiency: QLoRA reduces memory footprint by ~60%
  • β€”Convergence: Stable training with consistent loss reduction across 3 epochs
Add Image Here: GPU utilization and memory usage charts

Prompt Engineering

The model uses a specialized Physics-tutor system prompt with structured JSON output formatting for consistent response generation and auto-grading compatibility.

Quick Start

Installation

bash
pip install transformers torch peft bitsandbytes accelerate deepspeed wandb

Usage

python
from transformers import AutoModelForCausalLM, AutoProcessor
from peft import PeftModel
import torch

# Load base model and adapter
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2-VL-7B-Instruct")
model = PeftModel.from_pretrained(model, "parani01/Fine-tuned-physics-VLM-on-LoRA-and-QLoRA")
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-7B-Instruct")

# Process image and question
def solve_physics_problem(image_path, question):
    # Implementation here
    pass

πŸ“ˆ Performance & Results

Evaluation Highlights

  • β€”OCR Accuracy: Significant improvement on mathematical expressions
  • β€”Reasoning Quality: Enhanced step-by-step problem solving
  • β€”Response Structure: Consistent JSON formatting for automated evaluation
  • β€”Multi-modal Coherence: Better integration of visual and textual information

Technical Specifications

Model Architecture

  • β€”Base: Qwen2-VL-7B-Instruct (7B parameters)
  • β€”Vision Encoder: Frozen (preserves pre-trained representations)
  • β€”Language Model: QLoRA fine-tuned (4-bit quantization)
  • β€”Projector: Tiny LoRA adapted (rank 4-8)

Compute Requirements

  • β€”Training Hardware: 4Γ—NVIDIA A6000 (24GB VRAM each)
  • β€”Training Time: 4 hours wall-clock (16 total GPU hours)
  • β€”Distributed Framework: DeepSpeed ZeRO-3 for memory-efficient multi-GPU training
  • β€”Inference: Single A6000/RTX 4090 compatible
  • β€”Memory: ~12GB VRAM for inference with quantization
  • β€”Scalability: H200 support planned for future training iterations

Framework Versions

  • β€”PEFT: 0.17.1
  • β€”Transformers: Latest compatible version
  • β€”DeepSpeed: ZeRO-3 configuration
  • β€”PyTorch: 2.0+ with CUDA support
  • β€”Weights & Biases: For training monitoring and logging

πŸŽ“ Use Cases

Direct Use

  • β€”Educational Physics Tutoring: Step-by-step problem solving assistance
  • β€”OCR + Reasoning: Extract and solve physics problems from images
  • β€”Auto-grading Systems: JSON structured outputs for automated evaluation

Downstream Use

  • β€”Physics Problem Analysis: Large-scale problem dataset processing
  • β€”Educational AI Research: Benchmark for vision-language physics understanding
  • β€”Homework Assistance Tools: Integration into educational platforms

Out-of-Scope Use

  • β€”Non-physics domains: Model is specifically optimized for physics problems
  • β€”Non-English languages: Training focused on English-language content
  • β€”Production without GPU: Requires GPU acceleration for optimal performance

⚠️ Bias, Risks, and Limitations

Limitations

  • β€”Domain Specificity: Optimized primarily for physics problems
  • β€”Language Support: English-focused training data
  • β€”Computational Requirements: Requires GPU for optimal performance
  • β€”Dataset Bias: Limited to ScienceQA dataset characteristics

Recommendations

Users should be aware of the physics-focused training and may need additional fine-tuning for other scientific domains. GPU acceleration is recommended for production use.

πŸš€ How to Get Started with the Model

Basic Usage

python
from transformers import AutoModelForCausalLM, AutoProcessor
from peft import PeftModel

# Load the fine-tuned model
base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2-VL-7B-Instruct")
model = PeftModel.from_pretrained(base_model, "parani01/Fine-tuned-physics-VLM-on-LoRA-and-QLoRA")
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-7B-Instruct")

# Your physics problem solving code here

πŸ“Š Training Details

Training Data

  • β€”Dataset: ScienceQA multi-subject dataset
  • β€”Format: JSONL with image, question, answer triplets
  • β€”Focus: Physics problems with visual components
  • β€”Size: Optimized subset for physics reasoning

Training Procedure

Training Hyperparameters
  • β€”Training regime: Mixed precision bf16 with gradient accumulation
  • β€”Batch Size: 32-64 effective batch size across 4 GPUs
  • β€”Learning Rate: Optimized for LoRA/QLoRA setup
  • β€”Epochs: 3 epochs
  • β€”Distributed: DeepSpeed ZeRO-3 across 4Γ—A6000
Speeds, Sizes, Times
  • β€”Training Time: 4 hours wall-clock
  • β€”Total GPU Hours: 16 hours (4Γ—A6000)
  • β€”Model Size: Base 7B + LoRA adapters
  • β€”Memory Usage: ~60% reduction with QLoRA quantization

Training Carbon Footprint

  • β€”Hardware Type: 4Γ—NVIDIA A6000 (24GB each)
  • β€”Hours used: 16 total GPU hours
  • β€”Training Duration: 4 hours wall-clock time
  • β€”Efficiency: QLoRA quantization reduces computational overhead
  • β€”Optimization: DeepSpeed ZeRO-3 for memory-efficient distributed training

Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute).

πŸ“š Citation

If you use this model in your research, please cite:

bibtex
@misc{physics-vlm-lora-qlora-2025,
  title={Fine-tuned Physics VLM: Multi-Adapter Training with LoRA and QLoRA for Enhanced Mathematical Reasoning},
  author={Paranidharan},
  year={2025},
  url={https://huggingface.co/parani01/Fine-tuned-physics-VLM-on-LoRA-and-QLoRA},
  note={Fine-tuned on ScienceQA using DeepSpeed ZeRO-3 distributed training}
}

πŸ”— Model Card Contact & Authors

Model Card Authors: Paranidharan Contact: Available through Hugging Face model repository

Related Resources


Model Type: Vision-Language Model with Multi-Adapter Fine-tuning Training Date: September 2025 Languages: English Domains: Physics, Mathematics, Science Education Hardware: 4Γ—NVIDIA A6000, DeepSpeed ZeRO-3 Distributed Training