Instructions to use Hatim2221/Mubsir-Qwen-2B-VL with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Hatim2221/Mubsir-Qwen-2B-VL with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Hatim2221/Mubsir-Qwen-2B-VL") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("Hatim2221/Mubsir-Qwen-2B-VL") model = AutoModelForMultimodalLM.from_pretrained("Hatim2221/Mubsir-Qwen-2B-VL", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Hatim2221/Mubsir-Qwen-2B-VL with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Hatim2221/Mubsir-Qwen-2B-VL" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Hatim2221/Mubsir-Qwen-2B-VL", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/Hatim2221/Mubsir-Qwen-2B-VL
- SGLang
How to use Hatim2221/Mubsir-Qwen-2B-VL with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Hatim2221/Mubsir-Qwen-2B-VL" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Hatim2221/Mubsir-Qwen-2B-VL", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Hatim2221/Mubsir-Qwen-2B-VL" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Hatim2221/Mubsir-Qwen-2B-VL", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use Hatim2221/Mubsir-Qwen-2B-VL with Docker Model Runner:
docker model run hf.co/Hatim2221/Mubsir-Qwen-2B-VL
Mubsir-Qwen-2B-VL: Arabic Handwritten Text Recognition (HTR)
This repository contains a vision-language model fine-tuned specifically for Arabic Handwritten Text Recognition (HTR). Built on the Qwen2-VL-2B-Instruct architecture, it is designed to accurately transcribe complex, unstructured Arabic handwriting into digital text.
A standalone, unmerged parameter-efficient LoRA adapter for this model is also available at Hatim2221/Mubsir-vl-arabic-htr-adapter.
Model Details
- Base Architecture: Qwen/Qwen2-VL-2B-Instruct
- Task: Optical Character Recognition (OCR) / Handwritten Text Recognition (HTR) for Arabic text.
- Precision:
torch.float16. The trained LoRA weights were merged into the base model entirely in 16-bit precision. This avoids the mathematical rounding errors and accuracy degradation commonly associated with merging weights directly into 4-bit quantized base models. - Parameters: 2 Billion.
Training Data
The model was fine-tuned using the KHATT (KFUPM Handwritten Arabic TexT) dataset, a comprehensive collection of diverse Arabic handwritten text lines designed for training high-accuracy recognition systems.
Training Infrastructure & Methodology
- Hardware: 2x NVIDIA T4 GPUs (Kaggle cluster).
- Methodology: Parameter-Efficient Fine-Tuning (PEFT) via QLoRA.
- VRAM Optimization: The training pipeline utilized PyTorch
expandable_segmentsfor strict memory management, coupled with dynamic image resolution capping and tailored batch sizing to bypass standard Out-Of-Memory (OOM) failures during multimodal processing.
Usage and Inference
To run this model, ensure you have the required Hugging Face libraries installed, including the Qwen vision utilities.
Installation
pip install -q -U transformers accelerate qwen-vl-utils torchvision torchao
###Inference code
```python
import torch
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
from qwen_vl_utils import process_vision_info
model_id = "Hatim2221/Mubsir-Qwen-2B-VL"
# Load the model and processor in native FP16 precision
model = Qwen2VLForConditionalGeneration.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="auto"
)
processor = AutoProcessor.from_pretrained(model_id)
# Define the multimodal input payload
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "path_to_your_arabic_handwriting_image.jpg"},
{"type": "text", "text": "Transcribe this Arabic handwriting:"}
]
}
]
# Process text and vision inputs using the Qwen utility
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("cuda")
# Generate the transcription
with torch.no_grad():
generated_ids = model.generate(**inputs, max_new_tokens=128)
# Isolate the generated output from the input tokens
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("Transcription Result:")
print(output_text[0])
- Downloads last month
- 49
Model tree for Hatim2221/Mubsir-Qwen-2B-VL
Base model
Qwen/Qwen-VL