Views
No views yet
transformers and peft.1pip install torch transformers peft pillow datasets qwen-vl-utils
2# If you want to use Unsloth for faster inference, install it via:
3# pip install unsloth1from unsloth import FastVisionModel
2import torch
3from datasets import load_dataset
4
5# Load model and processor
6model, processor = FastVisionModel.from_pretrained(
7 model_name="GRAI-UNSTPB/Qwen2-VL-7B-Instruct-RoVQA-lora-v1",
8 load_in_4bit=True
9)
10FastVisionModel.for_inference(model)
11
12# Load a test sample directly from the Flickr30K-RoQA-v1 dataset
13dataset = load_dataset("GRAI-UNSTPB/Flickr30K-RoQA-v1", split="test")
14sample = dataset[0]
15image = sample["image"]
16question = sample["question"]
17
18messages = [
19 {
20 "role": "user",
21 "content": [
22 {"type": "image", "image": image},
23 {"type": "text", "text": f"Răspunde la întrebare: {question}"}
24 ]
25 }
26]
27
28input_text = processor.apply_chat_template(messages, add_generation_prompt=True)
29inputs = processor(images=image, text=input_text, return_tensors="pt").to("cuda")
30
31# Generate response
32outputs = model.generate(**inputs, max_new_tokens=64)
33# Decode only the generated response (excluding the prompt)
34prompt_len = inputs.input_ids.shape[1]
35response = processor.decode(outputs[0][prompt_len:], skip_special_tokens=True)
36print(response)1from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
2from peft import PeftModel
3import torch
4from PIL import Image
5
6# Load base model and processor
7base_model_id = "unsloth/qwen2-vl-7b-instruct-unsloth-bnb-4bit"
8processor = AutoProcessor.from_pretrained(base_model_id)
9
10model = Qwen2VLForConditionalGeneration.from_pretrained(
11 base_model_id,
12 torch_dtype=torch.bfloat16,
13 device_map="auto"
14)
15
16# Load LoRA adapter
17model = PeftModel.from_pretrained(model, "GRAI-UNSTPB/Qwen2-VL-7B-Instruct-RoVQA-lora-v1")
18
19# Inference setup follows the same structure as above...| Model | BERTScore F1 (%) | ROUGE-L F1 (%) | BLEU |
|---|---|---|---|
| Qwen2-VL-7B-Instruct (Base) | 75.09 | 45.14 | 14.30 |
| Qwen2-VL-7B-Instruct + RoVQA LoRA (Ours) | 77.38 | 53.54 | 34.79 |
| Model | BERTScore F1 (%) | ROUGE-L F1 (%) | BLEU |
|---|---|---|---|
| Qwen2-VL-7B-Instruct (Base) | 67.50 | 28.07 | 7.18 |
| Qwen2-VL-7B-Instruct + RoVQA LoRA (Ours) | 71.95 | 37.74 | 14.94 |
1@article{dima2025parameter,
2 title={Parameter-Efficient Multimodal Instruction Tuning for Romanian Vision--Language Models},
3 author={Dima, George-Andrei and Smădu, Răzvan-Alexandru and Cercel, Dumitru-Clementin},
4 journal={arXiv preprint arXiv:2512.14926},
5 year={2025}
6}