Views
No views yet
1from transformers import AutoProcessor, Mistral3ForConditionalGeneration, AutoTokenizer
2from huggingface_hub import hf_hub_download
3import torch
4from datetime import datetime, timedelta
5
6model_id = "OPEA/Mistral-Small-3.1-24B-Instruct-2503-int4-AutoRound-awq-sym"
7
8def load_system_prompt(repo_id: str, filename: str) -> str:
9 file_path = hf_hub_download(repo_id=repo_id, filename=filename)
10 with open(file_path, "r") as file:
11 system_prompt = file.read()
12 today = datetime.today().strftime("%Y-%m-%d")
13 yesterday = (datetime.today() - timedelta(days=1)).strftime("%Y-%m-%d")
14 model_name = repo_id.split("/")[-1]
15 return system_prompt.format(name=model_name, today=today, yesterday=yesterday)
16
17
18SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")
19
20model = Mistral3ForConditionalGeneration.from_pretrained(
21 model_id, torch_dtype=torch.float16, device_map="auto"
22).eval()
23
24processor = AutoProcessor.from_pretrained(model_id)
25tokenizer = AutoTokenizer.from_pretrained(model_id)
26url = "https://huggingface.co/datasets/patrickvonplaten/random_img/resolve/main/europe.png"
27
28prompt = "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."
29
30messages = [
31 {"role": "system", "content": SYSTEM_PROMPT},
32 {
33 "role": "user",
34 "content": [
35 {
36 "type": "text",
37 "text": prompt,
38 },
39 {"type": "image"}
40 ],
41 },
42]
43inputs = processor.apply_chat_template(
44 messages, add_generation_prompt=True, tokenize=False,
45 return_dict=True
46)
47inputs =processor(images=url,
48 text=inputs,
49 add_special_tokens=False,
50 return_tensors="pt").to(model.device).to(torch.float16)
51
52input_len = inputs["input_ids"].shape[-1]
53
54with torch.inference_mode():
55 generation = model.generate(**inputs, max_new_tokens=512, do_sample=True)
56 generation = generation[0][input_len:]
57
58decoded = processor.decode(generation, skip_special_tokens=True)
59print(decoded)
60"""
61Your question is subjective as the "best food" can vary greatly depending on personal preferences. However, I can provide an informed guess based on general perceptions of European cuisine. Let's break it down from the map:
62
631. **Italy (Green)** - Known for its diverse and rich culinary tradition. A non-capital city visible on the map is Rome.
642. **France (Light Brown)** - Famous for its fine dining and gourmet cuisine. A non-capital city visible on the map is Marseille.
653. **Spain (Yellow)** - Renowned for its vibrant and flavorful dishes. A non-capital city visible on the map is Barcelona.
664. **Germany (Orange)** - Known for its hearty and diverse cuisine. A non-capital city visible on the map is Munich.
67
68These rankings are based on general perceptions and do not reflect any objective measurement of culinary excellence. Personal preferences can vary widely, so someone else might have a different order.
69
70"""1pip install git+https://github.com/intel/auto-round.git@main
2auto-round-mllm \
3--model mistralai/Mistral-Small-3.1-24B-Instruct-2503 \
4--device 0 \
5--bits 4 \
6--format 'auto_awq,auto_gptq' \
7--output_dir "./tmp_autoround"