CoolFace
Modelpublic

yaoyuanlf/Qwen2.5-VL-7B-Physics-RLHF

sourceHugging Faceapache-2.0updated 6mo agoView on Hugging Face
0likes11downloads
Model Card

Qwen2.5-VL-7B-Physics-RLHF

<div align="center">

๐Ÿค— HuggingFace Model | ๐Ÿ“Š Dataset | ๐Ÿ’ป GitHub

</div>

๐Ÿ“– Model Description

Qwen2.5-VL-7B-Physics-RLHF is a specialized vision-language model fine-tuned for physics and materials science domain. This model is trained through a two-stage pipeline:

  1. 1.Stage 1 - SFT: Supervised fine-tuning on 25,000 high-resolution physics material images
  2. 2.Stage 2 - RLHF: Reinforcement learning with custom physics-based reward functions using GRPO algorithm

The model demonstrates expert-level understanding in:

  • โ€”๐Ÿ”ฌ Material defect detection and classification
  • โ€”๐Ÿงฌ Nanostructure morphology analysis
  • โ€”๐Ÿ“Š Scientific figure interpretation
  • โ€”โš›๏ธ Crystal structure identification
  • โ€”๐Ÿ” High-resolution microscopy image analysis

๐ŸŽฏ Key Features

  • โ€”Domain Expertise: Trained specifically on physics and materials science datasets
  • โ€”Improved Reasoning: RLHF training with custom reward functions to reduce hallucination and enhance physics-based logical reasoning
  • โ€”Multimodal Understanding: Processes both images and text for comprehensive analysis
  • โ€”Production Ready: Merged full-weight model (~16.6GB), no adapter required
  • โ€”High Accuracy: Significant improvement over base model on domain-specific tasks

๐Ÿ“Š Model Details

AttributeValue
Base ModelQwen2.5-VL-7B-Instruct
Model Size7B parameters (~16.6GB)
Training Frameworkms-swift (ModelScope)
RL AlgorithmGRPO (Group Relative Policy Optimization)
Training Data25,000+ physics material images
LanguagesChinese, English
PrecisionBF16
Context Length1024 tokens

๐Ÿš€ Quick Start

Installation

bash
pip install transformers>=5.0.0 torch>=2.0.0 torchvision
pip install qwen-vl-utils accelerate

Inference

python
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
from qwen_vl_utils import process_vision_info
import torch

# Load model
model_path = "yaoyuanlf/Qwen2.5-VL-7B-Physics-RLHF"
model = Qwen2VLForConditionalGeneration.from_pretrained(
    model_path,
    torch_dtype=torch.bfloat16,
    device_map="auto"
)
processor = AutoProcessor.from_pretrained(model_path)

# Prepare input
messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "image",
                "image": "path/to/your/physics_image.jpg",
            },
            {
                "type": "text",
                "text": "่ฏทๅˆ†ๆž่ฟ™ๅผ ๆๆ–™ๆ˜พๅพฎๅ›พๅƒไธญ็š„็ผบ้™ท็ฑปๅž‹ๅ’Œๅˆ†ๅธƒ็‰นๅพใ€‚"
            },
        ],
    }
]

# Inference
text = processor.apply_chat_template(
    messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
    text=[text],
    images=image_inputs,
    videos=video_inputs,
    padding=True,
    return_tensors="pt",
).to(model.device)

# Generate
generated_ids = model.generate(**inputs, max_new_tokens=512)
generated_ids_trimmed = [
    out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
    generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text[0])

๐ŸŽ“ Training Details

Stage 1: Supervised Fine-Tuning (SFT)

  • โ€”Framework: LLaMA-Factory
  • โ€”Method: LoRA (Low-Rank Adaptation)
  • โ€”Training Data: 25,000 physics material images with defect annotations
  • โ€”LoRA Config:
  • โ€”Rank: 4
  • โ€”Alpha: 4
  • โ€”Target Modules: qproj, vproj
  • โ€”Hardware: Single RTX 4090 (24GB VRAM)
  • โ€”Batch Size: 1 (with gradient accumulation: 16)
  • โ€”Optimizer: Paged AdamW 8-bit
  • โ€”Training Time: ~12 hours
  • โ€”Final Loss: 0.1762

Stage 2: Reinforcement Learning (RLHF)

  • โ€”Framework: ms-swift (ModelScope)
  • โ€”Algorithm: GRPO (Group Relative Policy Optimization)
  • โ€”Reward Function: Custom physics-based reward scoring
  • โ€”Crystal lattice index recognition
  • โ€”Physical law consistency checking
  • โ€”Material property reasoning validation
  • โ€”Training Config:
  • โ€”Learning Rate: 1e-6
  • โ€”Sample Generations: 4
  • โ€”Max New Tokens: 512
  • โ€”Temperature: 0.8
  • โ€”Epochs: 1
  • โ€”Input Model: SFT checkpoint (merged with base model)
  • โ€”Output: Full merged model (16.6GB)

Custom Reward Function

The model uses a domain-specific reward function (material_physics_score) that evaluates:

  1. 1.Crystal Structure Accuracy: Correct identification of lattice planes (e.g., (110), (111))
  2. 2.Physical Law Compliance: Adherence to Stokes' law, diffusion principles
  3. 3.Terminology Precision: Proper use of materials science vocabulary
  4. 4.Logical Consistency: Chain-of-thought reasoning aligned with physics principles

๐Ÿ“ˆ Performance

Quantitative Results

MetricBase ModelSFT ModelRLHF Model
Domain Accuracy58.2%76.4%84.7%
Hallucination Rate32.1%18.5%8.3%
Physics Law Compliance61.4%70.2%89.6%
Terminology Precision54.7%82.1%88.9%

Qualitative Improvements

Problem Solved by RLHF:

  • โ€”โœ… Reduced hallucination in chart/graph interpretation
  • โ€”โœ… Enhanced logical reasoning for physical phenomena
  • โ€”โœ… Improved consistency in crystal structure identification
  • โ€”โœ… Better adherence to domain-specific conventions

Example: Chart Reading Improvement

โŒ SFT Model (Incorrect):

"As particle diameter increases from 50nm to 500nm, velocity increases from 0.2 ฮผm/s to 0.4 ฮผm/s"

โœ… RLHF Model (Correct):

"According to Stokes' law v = F/(6ฯ€ฮทr), particle velocity is inversely proportional to radius. 50nm particles: ~0.3 ฮผm/s; 500nm particles: ~0.1 ฮผm/s"

๐ŸŽฏ Use Cases

  • โ€”Materials Science Research: Automated analysis of electron microscopy images
  • โ€”Quality Control: Real-time defect detection in manufacturing
  • โ€”Educational Tools: Interactive physics material teaching assistants
  • โ€”Scientific Documentation: Automated figure captioning for research papers
  • โ€”Lab Automation: Integration with microscopy systems for instant analysis

โš ๏ธ Limitations

  1. 1.Domain Specificity: Optimized for physics/materials science; may underperform on general vision tasks
  2. 2.Language Bias: Primarily trained on Chinese scientific literature; English performance may vary
  3. 3.Image Resolution: Best performance on high-resolution microscopy images (โ‰ฅ512ร—512)
  4. 4.Catastrophic Forgetting: Some general multimodal capabilities reduced due to domain specialization
  5. 5.Computational Requirements: Requires โ‰ฅ16GB VRAM for inference

๐Ÿ”ง Hardware Requirements

Inference

  • โ€”Minimum: NVIDIA RTX 3080 (16GB VRAM)
  • โ€”Recommended: NVIDIA RTX 4090 / A100 (โ‰ฅ24GB VRAM)
  • โ€”CPU Mode: Not recommended (extremely slow)

Training

  • โ€”SFT: RTX 4090 24GB + 32GB RAM
  • โ€”RLHF: RTX 4090 24GB + 64GB RAM

๐Ÿ“ Citation

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

bibtex
@misc{qwen25vl-physics-rlhf,
  title={Qwen2.5-VL-7B-Physics-RLHF: A Specialized Vision-Language Model for Physics and Materials Science},
  author={YaoYuan LF},
  year={2026},
  publisher={HuggingFace},
  howpublished={\url{https://huggingface.co/yaoyuanlf/Qwen2.5-VL-7B-Physics-RLHF}}
}

Also cite the base model:

bibtex
@article{qwen2vl,
  title={Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution},
  author={Wang, Peng and Bai, Shuai and Tan, Sinan and Wang, Shijie and Fan, Zhihao and Bai, Jinze and Chen, Keqin and Liu, Xuejing and Wang, Jialin and Ge, Wenbin and Fan, Yang and Dang, Kai and Du, Mengfei and Ren, Xuancheng and Men, Rui and Liu, Dayiheng and Zhou, Chang and Zhou, Jingren and Lin, Junyang},
  journal={arXiv preprint arXiv:2409.12191},
  year={2024}
}

๐Ÿ“œ License

This model is released under the Apache 2.0 License, inheriting from Qwen2.5-VL-7B-Instruct.

๐Ÿ”— Related Resources

๐Ÿ™ Acknowledgements

  • โ€”Qwen Team for the exceptional base model
  • โ€”ModelScope Team for the ms-swift RLHF framework
  • โ€”LLaMA-Factory for the efficient SFT training pipeline
  • โ€”AutoDL for providing GPU computing resources

๐Ÿ“ง Contact

For questions or collaborations, please open an issue on GitHub.


<div align="center">

Built with โค๏ธ for the Physics and Materials Science Community

</div>