Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,27 @@
|
|
1 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
2 |
-
import torch
|
3 |
|
4 |
-
# Define the model path
|
5 |
MODEL_NAME = "RPW/NIH-1.2_Llama-3.2-11B-Vision-Instruct"
|
6 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
# Load the tokenizer and model
|
11 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
12 |
-
model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME).to(device)
|
13 |
|
14 |
-
#
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
image,
|
20 |
-
input_text,
|
21 |
-
add_special_tokens=False,
|
22 |
-
return_tensors="pt"
|
23 |
-
).to(device)
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
**inputs,
|
28 |
-
streamer=text_streamer,
|
29 |
-
max_new_tokens=128,
|
30 |
-
use_cache=True,
|
31 |
-
temperature=1.5,
|
32 |
-
min_p=0.1
|
33 |
-
)
|
|
|
1 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
|
2 |
|
|
|
3 |
MODEL_NAME = "RPW/NIH-1.2_Llama-3.2-11B-Vision-Instruct"
|
|
|
4 |
|
5 |
+
# โหลด tokenizer
|
|
|
|
|
6 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
|
|
7 |
|
8 |
+
# ตั้งค่า special tokens
|
9 |
+
special_tokens = {
|
10 |
+
"bos_token": "<|begin_of_text|>",
|
11 |
+
"eos_token": "<|end_of_text|>",
|
12 |
+
"additional_special_tokens": [
|
13 |
+
"<|reserved_special_token_0|>",
|
14 |
+
"<|reserved_special_token_1|>",
|
15 |
+
"<|finetune_right_pad_id|>",
|
16 |
+
"<|step_id|>",
|
17 |
+
"<|start_header_id|>",
|
18 |
+
"<|end_header_id|>"
|
19 |
+
]
|
20 |
+
}
|
21 |
+
tokenizer.add_special_tokens(special_tokens)
|
22 |
|
23 |
+
# โหลด model
|
24 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
# ปรับขนาด embedding เพื่อรองรับ special tokens
|
27 |
+
model.resize_token_embeddings(len(tokenizer))
|
|
|
|
|
|
|
|
|
|
|
|
|
|