Aekanun commited on
Commit
7f5869c
·
1 Parent(s): 1daa8cd

rev app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -22
app.py CHANGED
@@ -28,37 +28,38 @@ def load_model_and_processor():
28
  global model, processor
29
  print("กำลังโหลดโมเดลและ processor...")
30
  try:
 
 
 
 
31
  # Model paths
32
- base_model_path = "meta-llama/Llama-3.2-11B-Vision-Instruct"
33
- adapter_path = "Aekanun/Llama-3.2-11B-Vision-Instruct-XRay"
34
 
35
  # Load processor from base model
36
  print("กำลังโหลด processor...")
37
- processor = AutoProcessor.from_pretrained(
38
- base_model_path,
39
- use_auth_token=True
40
- )
41
 
42
- # Load base model
43
- print("กำลังโหลด base model...")
44
- base_model = AutoModelForVision2Seq.from_pretrained(
45
- base_model_path,
46
- device_map="auto",
47
- torch_dtype=torch.float16, # เปลี่ยนกลับเป็น float16
48
- trust_remote_code=True,
49
- use_auth_token=True
50
  )
51
 
52
- # Load adapter
53
- print("กำลังโหลด adapter...")
54
- model = PeftModel.from_pretrained(
55
- base_model,
56
- adapter_path,
57
- device_map="auto", # ให้จัดการ device map อัตโนมัติ
58
- torch_dtype=torch.float16,
59
- use_auth_token=True
 
60
  )
61
 
 
62
  print("โหลดโมเดลสำเร็จ!")
63
  return True
64
  except Exception as e:
 
28
  global model, processor
29
  print("กำลังโหลดโมเดลและ processor...")
30
  try:
31
+ ###
32
+ from unsloth import FastVisionModel
33
+ from transformers import AutoModelForVision2Seq, TextStreamer
34
+ ###
35
  # Model paths
36
+ ### base_model_path = "meta-llama/Llama-3.2-11B-Vision-Instruct"
37
+ ### adapter_path = "Aekanun/Llama-3.2-11B-Vision-Instruct-XRay"
38
 
39
  # Load processor from base model
40
  print("กำลังโหลด processor...")
41
+ ###processor = AutoProcessor.from_pretrained(
42
+ ### base_model_path,
43
+ ### use_auth_token=True
44
+ ###)
45
 
46
+ base_model, tokenizer = FastVisionModel.from_pretrained(
47
+ "unsloth/Llama-3.2-11B-Vision-Instruct",
48
+ use_gradient_checkpointing = "unsloth"
 
 
 
 
 
49
  )
50
 
51
+ print("โหลด base model และ tokenizer สำเร็จ กำลังโหลดโมเดลที่ fine-tune...")
52
+
53
+ # ปิด FastVisionModel และโหลด model โดยตรง
54
+ from transformers import AutoModelForVision2Seq
55
+ model = AutoModelForVision2Seq.from_pretrained(
56
+ "Aekanun/Llama-3.2-11B-Vision-Instruct-XRay",
57
+ load_in_4bit = True,
58
+ device_map = {'': torch.cuda.current_device()},
59
+ torch_dtype = torch.float16
60
  )
61
 
62
+ FastVisionModel.for_inference(model)
63
  print("โหลดโมเดลสำเร็จ!")
64
  return True
65
  except Exception as e: