Views
No views yet
peft.1from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
2from peft import PeftModel
3import torch
4
5base_model_id = "unsloth/Qwen3-VL-2B-Instruct-bnb-4bit"
6adapter_id = "minhduc168/Qwen3-VL-2B-Instruct-Vietnamese-LoRA"
7
8# 1️⃣ Load base model
9model = Qwen2VLForConditionalGeneration.from_pretrained(
10 base_model_id,
11 device_map="auto"
12)
13
14# 2️⃣ Load LoRA adapter
15model = PeftModel.from_pretrained(model, adapter_id)
16
17# 3️⃣ Load processor
18processor = AutoProcessor.from_pretrained(base_model_id)
19
20model.eval()
21print("Model và LoRA adapter đã sẵn sàng!")pip install peft transformers bitsandbytes1{
2 "id": "bill_f18b567055ed4c5d85143770499b2f65",
3 "image": "bill_001.jpg",
4 "conversations": [
5 {
6 "from": "human",
7 "value": "<image>\n[BILL_OCR] Trích xuất danh sách dịch vụ và thông tin liên quan từ bảng trong ảnh.\nKhông suy đoán hoặc bổ sung thông tin không có trong ảnh."
8 },
9 {
10 "from": "gpt",
11 "value": "[
12 {
13 "stt": 1,
14 "ten_dich_vu": "STTOMET 1000mg + 50mg",
15 "so_luong": "56",
16 "don_vi_tinh": "Viên",
17 "don_gia": "5.390",
18 "thanh_tien": "301.840"
19 },
20 {
21 "stt": 2,
22 "ten_dich_vu": "JARDIANCE DUO 12.5mg + 1000mg",
23 "so_luong": "56",
24 "don_vi_tinh": "Viên",
25 "don_gia": "17.976",
26 "thanh_tien": "1.006.656"
27 },
28 {
29 "stt": 3,
30 "ten_dich_vu": "Atovze* 20mg+10mg",
31 "so_luong": "56",
32 "don_vi_tinh": "Viên",
33 "don_gia": "6.409",
34 "thanh_tien": "358.921"
35 },
36 {
37 "stt": 4,
38 "ten_dich_vu": "SADAPRON 300mg",
39 "so_luong": "28",
40 "don_vi_tinh": "Viên",
41 "don_gia": "2.750",
42 "thanh_tien": "77.000"
43 }
44 ]"
45 }
46 ]
47}1{
2 "id": "diag_db2888ccc0de4c4b8e9d39c3e08c104a",
3 "image": "diag_001.jpg",
4 "conversations": [
5 {
6 "from": "human",
7 "value": "<image>\n[DIAGNOSIS_EXTRACT] Hãy trích xuất và cho biết chẩn đoán trong hình này."
8 },
9 {
10 "from": "gpt",
11 "value": "Răng 28: [K07 4] Răng mọc lệch"
12 }
13 ]
14}