Views
No views yet

Qwen2-VL-2B-Instruct architecture, it is designed to accurately transcribe complex, unstructured Arabic handwriting into digital text.Hatim2221/Mubsir-vl-arabic-htr-adapter.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.expandable_segments for strict memory management, coupled with dynamic image resolution capping and tailored batch sizing to bypass standard Out-Of-Memory (OOM) failures during multimodal processing.
pip install -q -U transformers accelerate qwen-vl-utils torchvision torchao1import torch
2from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
3from qwen_vl_utils import process_vision_info
4
5model_id = "Hatim2221/Mubsir-Qwen-2B-VL"
6
7# Load the model and processor in native FP16 precision
8model = Qwen2VLForConditionalGeneration.from_pretrained(
9 model_id,
10 torch_dtype=torch.float16,
11 device_map="auto"
12)
13processor = AutoProcessor.from_pretrained(model_id)
14
15# Define the multimodal input payload
16messages = [
17 {
18 "role": "user",
19 "content": [
20 {"type": "image", "image": "path_to_your_arabic_handwriting_image.jpg"},
21 {"type": "text", "text": "Transcribe this Arabic handwriting:"}
22 ]
23 }
24]
25
26# Process text and vision inputs using the Qwen utility
27text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
28image_inputs, video_inputs = process_vision_info(messages)
29
30inputs = processor(
31 text=[text],
32 images=image_inputs,
33 videos=video_inputs,
34 padding=True,
35 return_tensors="pt"
36).to("cuda")
37
38# Generate the transcription
39with torch.no_grad():
40 generated_ids = model.generate(**inputs, max_new_tokens=128)
41
42# Isolate the generated output from the input tokens
43generated_ids_trimmed = [
44 out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
45]
46
47output_text = processor.batch_decode(
48 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
49)
50
51print("Transcription Result:")
52print(output_text[0])