from typing import Anyimport torch from huggingface_hub import hf_hub_downloadfrom transformers import AutoModelForCausalLM, AutoTokenizer TEMP = 0.7TOP_P = 0.95MAX_TOK = 40_960 def load_system_prompt(repo_id: str, filename: str) -> dict[str, Any]: file_path = hf_hub_download(repo_id=repo_id, filename=filename) with open(file_path, "r") as file: system_prompt = file.read() index_begin_think = system_prompt.find("[THINK]") index_end_think = system_prompt.find("[/THINK]") return { "role": "system", "content": [ {"type": "text", "text": system_prompt[:index_begin_think]}, { "type": "thinking", "thinking": system_prompt[ index_begin_think + len("[THINK]") : index_end_think ], "closed": True, }, { "type": "text", "text": system_prompt[index_end_think + len("[/THINK]") :], }, ], } model_id = "mistralai/Magistral-Small-2507"SYSTEM_PROMPT = load_system_prompt(model_id, "SYSTEM_PROMPT.txt")query = "Think about 5 random numbers. Verify if you can combine them with addition, multiplication, subtraction or division to 133."# or try out other queries# query = "Exactly how many days ago did the French Revolution start? Today is June 4th, 2025."# query = "Write 4 sentences, each with at least 8 words. Now make absolutely sure that every sentence has exactly one word less than the previous sentence."# query = "If it takes 30 minutes to dry 12 T-shirts in the sun, how long does it take to dry 33 T-shirts?" tokenizer = AutoTokenizer.from_pretrained(model_id, tokenizer_type="mistral", use_fast=False)model = AutoModelForCausalLM.from_pretrained( model_id, torch_dtype=torch.bfloat16, device_map="auto") input_ids = tokenizer.apply_chat_template( [ SYSTEM_PROMPT, {"role": "user", "content": query}, ],) output = model.generate( input_ids=torch.tensor([input_ids], device=model.device), pad_token_id=tokenizer.pad_token_id, eos_token_id=tokenizer.eos_token_id, temperature=TEMP, top_p=TOP_P, do_sample=True, max_new_tokens=MAX_TOK,)[0] decoded_output = tokenizer.decode(output[len(input_ids) :])print(decoded_output) # [THINK]Alright, I need to think of 5 random numbers first. Let's say I pick the numbers 5, 10, 2, 7, and 3.# # Now, I need to see if I can combine these numbers using addition, multiplication, subtraction, or division to get 133.# ...# ...# ...# But if we're to find any five numbers that can be combined to make 133, then yes, such sets exist, like the one demonstrated above.[/THINK]Yes, it is possible to combine some sets of five random numbers to make 133 using basic arithmetic operations. For example, the numbers 13, 10, 1, 2, and 3 can be combined as follows to make 133:# # \[ (13 \times 10) + (3 \times (2 - 1)) = 130 + 3 = 133 \]# # However, not all sets of five random numbers can be combined in this way to make 133. For instance, with the numbers 5, 10, 2, 7, and 3, it is not possible to combine them using the allowed operations to get exactly 133.# # Therefore, the ability to combine five random numbers to make 133 depends on the specific numbers chosen.# # $133 = (13 \times 10) + (3 \times (2 - 1))$</s>