29
29
# Qwen2-VL:
30
30
# https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct
31
31
# https://huggingface.co/turboderp/Qwen2-VL-7B-Instruct-exl2
32
+ # Gemma3:
33
+ # https://huggingface.co/google/gemma-3-27b-it
34
+ # https://huggingface.co/turboderp/gemma-3-27b-it-exl2
32
35
33
36
# mode = "pixtral"
34
- mode = "qwen2"
37
+ # mode = "qwen2"
38
+ mode = "gemma3"
35
39
36
40
streaming = True
37
41
greedy = True
38
42
39
43
if mode == "pixtral" :
40
44
model_directory = "/mnt/str/models/pixtral-12b-exl2/6.0bpw"
41
45
elif mode == "qwen2" :
42
- model_directory = "/mnt/str/models/qwen2-vl-7b-instruct-exl2/6.0bpw"
46
+ model_directory = "/mnt/str/models/qwen2.5-vl-7b-instruct-exl2/6.0bpw"
47
+ elif mode == "gemma3" :
48
+ model_directory = "/mnt/str/models/gemma3-27b-it-exl2/5.0bpw"
43
49
44
50
images = [
45
- {"file" : "media/test_image_1.jpg" },
46
- {"file" : "media/test_image_2.jpg" },
47
- # {"url": "https://media.istockphoto.com/id/1212540739/photo/mom-cat-with-kitten.jpg?s=612x612&w=0&k=20&c=RwoWm5-6iY0np7FuKWn8FTSieWxIoO917FF47LfcBKE="},
51
+ # {"file": "media/test_image_1.jpg"},
52
+ # {"file": "media/test_image_2.jpg"},
53
+ {"url" : "https://media.istockphoto.com/id/1212540739/photo/mom-cat-with-kitten.jpg?s=612x612&w=0&k=20&c=RwoWm5-6iY0np7FuKWn8FTSieWxIoO917FF47LfcBKE=" },
48
54
# {"url": "https://i.dailymail.co.uk/1s/2023/07/10/21/73050285-12283411-Which_way_should_I_go_One_lady_from_the_US_shared_this_incredibl-a-4_1689019614007.jpg"},
49
55
# {"url": "https://images.fineartamerica.com/images-medium-large-5/metal-household-objects-trevor-clifford-photography.jpg"}
50
56
]
51
57
52
- instruction = "Compare and contrast the two experiments."
53
- # instruction = "Describe the image."
58
+ # instruction = "Compare and contrast the two experiments."
59
+ instruction = "Describe the image."
54
60
# instruction = "Find the alarm clock." # Qwen2 seems to support this but unsure of how to prompt correctly
55
61
56
62
# Initialize model
@@ -122,6 +128,7 @@ def get_image(file = None, url = None):
122
128
instruction +
123
129
"[/INST]"
124
130
)
131
+ stop_conditions = [tokenizer .eos_token_id ]
125
132
126
133
elif mode == "qwen2" :
127
134
prompt = (
@@ -133,6 +140,18 @@ def get_image(file = None, url = None):
133
140
"<|im_end|>\n " +
134
141
"<|im_start|>assistant\n "
135
142
)
143
+ stop_conditions = [tokenizer .eos_token_id ]
144
+
145
+ elif mode == "gemma3" :
146
+ prompt = (
147
+ "<start_of_turn>user\n You are a helpful assistant.\n \n \n \n " +
148
+ placeholders +
149
+ "\n " +
150
+ instruction +
151
+ "<end_of_turn>\n " +
152
+ "<start_of_turn>model\n "
153
+ )
154
+ stop_conditions = [tokenizer .single_id ("<end_of_turn>" )]
136
155
137
156
# Generate
138
157
@@ -149,7 +168,7 @@ def get_image(file = None, url = None):
149
168
input_ids = input_ids ,
150
169
max_new_tokens = 500 ,
151
170
decode_special_tokens = True ,
152
- stop_conditions = [ tokenizer . eos_token_id ] ,
171
+ stop_conditions = stop_conditions ,
153
172
gen_settings = ExLlamaV2Sampler .Settings .greedy () if greedy else None ,
154
173
embeddings = image_embeddings ,
155
174
)
0 commit comments