Skip to content

Commit 6f7623f

Browse files
committed
Update examples
1 parent 77a1e2c commit 6f7623f

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

examples/chat_prompts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ def subs_prompt(self):
494494
def stop_conditions(self, tokenizer):
495495
return \
496496
[tokenizer.eos_token_id,
497-
"""</s>""",
498-
"""<end_of_turn>""",
497+
tokenizer.single_id("<end_of_turn>"),
498+
tokenizer.single_id("<start_of_turn>"),
499499
]
500500

501501
def encoding_options(self):

examples/multimodal.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,34 @@
2929
# Qwen2-VL:
3030
# https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct
3131
# 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
3235

3336
# mode = "pixtral"
34-
mode = "qwen2"
37+
# mode = "qwen2"
38+
mode = "gemma3"
3539

3640
streaming = True
3741
greedy = True
3842

3943
if mode == "pixtral":
4044
model_directory = "/mnt/str/models/pixtral-12b-exl2/6.0bpw"
4145
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"
4349

4450
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="},
4854
# {"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"},
4955
# {"url": "https://images.fineartamerica.com/images-medium-large-5/metal-household-objects-trevor-clifford-photography.jpg"}
5056
]
5157

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."
5460
# instruction = "Find the alarm clock." # Qwen2 seems to support this but unsure of how to prompt correctly
5561

5662
# Initialize model
@@ -122,6 +128,7 @@ def get_image(file = None, url = None):
122128
instruction +
123129
"[/INST]"
124130
)
131+
stop_conditions = [tokenizer.eos_token_id]
125132

126133
elif mode == "qwen2":
127134
prompt = (
@@ -133,6 +140,18 @@ def get_image(file = None, url = None):
133140
"<|im_end|>\n" +
134141
"<|im_start|>assistant\n"
135142
)
143+
stop_conditions = [tokenizer.eos_token_id]
144+
145+
elif mode == "gemma3":
146+
prompt = (
147+
"<start_of_turn>user\nYou 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>")]
136155

137156
# Generate
138157

@@ -149,7 +168,7 @@ def get_image(file = None, url = None):
149168
input_ids = input_ids,
150169
max_new_tokens = 500,
151170
decode_special_tokens = True,
152-
stop_conditions = [tokenizer.eos_token_id],
171+
stop_conditions = stop_conditions,
153172
gen_settings = ExLlamaV2Sampler.Settings.greedy() if greedy else None,
154173
embeddings = image_embeddings,
155174
)

0 commit comments

Comments
 (0)