Spaces:
Runtime error
Runtime error
rev app
Browse files
app.py
CHANGED
@@ -76,33 +76,55 @@ def load_model():
|
|
76 |
print("กำลังโหลดโมเดล...")
|
77 |
try:
|
78 |
# โหลด tokenizer จาก base model
|
79 |
-
from unsloth import FastVisionModel
|
80 |
-
from transformers import AutoTokenizer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
print("กำลังโหลด tokenizer...")
|
82 |
-
|
83 |
-
"
|
84 |
-
|
85 |
-
device_map="auto" ### เพิ่มตรงนี้
|
86 |
)
|
87 |
-
|
88 |
-
tokenizer = _tokenizer # กำหนดค่าให้ตัวแปร global โดยตรง
|
89 |
print(f"2. ประเภทของ tokenizer: {type(tokenizer)}")
|
90 |
print(f"3. เมธอดที่มีใน tokenizer: {dir(tokenizer)}")
|
91 |
-
print("4. Global tokenizer after assignment:", type(tokenizer))
|
92 |
-
|
93 |
-
print("โหลด base model และ tokenizer สำเร็จ กำลังโหลดโมเดลที่ fine-tune...")
|
94 |
-
|
95 |
-
# โหลดโมเดล fine-tuned
|
96 |
-
from transformers import AutoModelForVision2Seq
|
97 |
print("กำลังโหลดโมเดล fine-tuned...")
|
98 |
model = AutoModelForVision2Seq.from_pretrained(
|
99 |
"Aekanun/Llama-3.2-11B-Vision-Instruct-XRay",
|
100 |
-
device_map="auto",
|
101 |
-
###load_in_4bit=True,
|
102 |
torch_dtype=torch.float16
|
103 |
).to('cuda')
|
104 |
-
|
105 |
-
FastVisionModel.for_inference(model)
|
106 |
print("โหลดโมเดลสำเร็จ!")
|
107 |
return True
|
108 |
|
|
|
76 |
print("กำลังโหลดโมเดล...")
|
77 |
try:
|
78 |
# โหลด tokenizer จาก base model
|
79 |
+
# from unsloth import FastVisionModel
|
80 |
+
# from transformers import AutoTokenizer
|
81 |
+
# print("กำลังโหลด tokenizer...")
|
82 |
+
# base_model, _tokenizer = FastVisionModel.from_pretrained(
|
83 |
+
# "unsloth/Llama-3.2-11B-Vision-Instruct",
|
84 |
+
# use_gradient_checkpointing = "unsloth",
|
85 |
+
# device_map="auto" ### เพิ่มตรงนี้
|
86 |
+
# )
|
87 |
+
|
88 |
+
# tokenizer = _tokenizer # กำหนดค่าให้ตัวแปร global โดยตรง
|
89 |
+
# print(f"2. ประเภทของ tokenizer: {type(tokenizer)}")
|
90 |
+
# print(f"3. เมธอดที่มีใน tokenizer: {dir(tokenizer)}")
|
91 |
+
# print("4. Global tokenizer after assignment:", type(tokenizer)) # เช็คค่า
|
92 |
+
|
93 |
+
# print("โหลด base model และ tokenizer สำเร็จ กำลังโหลดโมเดลที่ fine-tune...")
|
94 |
+
|
95 |
+
# # โหลดโมเดล fine-tuned
|
96 |
+
# from transformers import AutoModelForVision2Seq
|
97 |
+
# print("กำลังโหลดโมเดล fine-tuned...")
|
98 |
+
# model = AutoModelForVision2Seq.from_pretrained(
|
99 |
+
# "Aekanun/Llama-3.2-11B-Vision-Instruct-XRay",
|
100 |
+
# device_map="auto", ### เพิ่มตรงนี้
|
101 |
+
# ###load_in_4bit=True,
|
102 |
+
# torch_dtype=torch.float16
|
103 |
+
# ).to('cuda')
|
104 |
+
|
105 |
+
# FastVisionModel.for_inference(model)
|
106 |
+
# print("โหลดโมเดลสำเร็จ!")
|
107 |
+
# return True
|
108 |
+
from transformers import AutoModelForVision2Seq, AutoTokenizer
|
109 |
+
import torch
|
110 |
+
|
111 |
print("กำลังโหลด tokenizer...")
|
112 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
113 |
+
"Aekanun/Llama-3.2-11B-Vision-Instruct-XRay",
|
114 |
+
trust_remote_code=True
|
|
|
115 |
)
|
116 |
+
|
|
|
117 |
print(f"2. ประเภทของ tokenizer: {type(tokenizer)}")
|
118 |
print(f"3. เมธอดที่มีใน tokenizer: {dir(tokenizer)}")
|
119 |
+
print("4. Global tokenizer after assignment:", type(tokenizer))
|
120 |
+
|
|
|
|
|
|
|
|
|
121 |
print("กำลังโหลดโมเดล fine-tuned...")
|
122 |
model = AutoModelForVision2Seq.from_pretrained(
|
123 |
"Aekanun/Llama-3.2-11B-Vision-Instruct-XRay",
|
124 |
+
device_map="auto",
|
|
|
125 |
torch_dtype=torch.float16
|
126 |
).to('cuda')
|
127 |
+
|
|
|
128 |
print("โหลดโมเดลสำเร็จ!")
|
129 |
return True
|
130 |
|