Views
No views yet
1import os
2from datetime import datetime, timedelta
3import torch
4
5from huggingface_hub import hf_hub_download
6from transformers import AutoProcessor, Mistral3ForConditionalGeneration, AutoTokenizer
7
8
9def load_system_prompt(repo_id: str, filename: str) -> str:
10 if os.path.isdir(repo_id):
11 file_path = os.path.join(repo_id, filename)
12 else:
13 file_path = hf_hub_download(repo_id=repo_id, filename=filename)
14 with open(file_path, "r") as file:
15 system_prompt = file.read()
16 today = datetime.today().strftime("%Y-%m-%d")
17 yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
18 model_name = repo_id.split("/")[-1]
19 return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
20
21
22model_id = "Intel/Mistral-Small-3.2-24B-Instruct-2506-int4-AutoRound"
23SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
24
25processor = AutoProcessor.from_pretrained(model_id)
26tokenizer = AutoTokenizer.from_pretrained(model_id)
27
28model = Mistral3ForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
29
30url = "https://huggingface.co/datasets/patrickvonplaten/random_img/resolve/main/europe.png"
31
32prompt = "Which of the depicted countries has the best food? Which the second and third and fourth? Name the country, its color on the map and one its city that is visible on the map, but is not the capital. Make absolutely sure to only name a city that can be seen on the map."
33
34messages = [
35 {"role": "system", "content": SYSTEM_PROMPT},
36 {
37 "role": "user",
38 "content": [
39 {
40 "type": "text",
41 "text": prompt,
42 },
43 {"type": "image"}
44 ],
45 },
46]
47inputs = processor.apply_chat_template(
48 messages, add_generation_prompt=True, tokenize=False,
49 return_dict=True
50)
51inputs =processor(images=url,
52 text=inputs,
53 add_special_tokens=False,
54 return_tensors="pt").to(model.device).to(torch.bfloat16)
55
56input_len = inputs["input_ids"].shape[-1]
57
58with torch.inference_mode():
59 generation = model.generate(**inputs, max_new_tokens=512, do_sample=True)
60 generation = generation[0][input_len:]
61
62decoded = processor.decode(generation, skip_special_tokens=True)
63print(decoded)
64
65"""
66To determine which countries have the best food, I'll consider popular opinions and rankings. Here are the top four countries known for their cuisine, along with their color on the map and a visible city (that is not the capital):
67
681. **Italy (Green)**
69 - City: Naples
70
712. **France (Brown)**
72 - City: Lyon
73
743. **Spain (Yellow)**
75 - City: Barcelona
76
774. **Greece (Light Green)**
78 - City: Thessaloniki
79
80These countries are renowned for their unique and delicious cuisines, and the cities mentioned are visible on the map.
81"""auto_round --mllm --model /models/Mistral-Small-3.2-24B-Instruct-2506/ --iters 200 --seqlen 1024 --output_dir tmp_autoround