Views
No views yet
1from transformers import AutoTokenizer
2from benchmark_prompt_utils import benchmark_gurobi_prompts
3from utils import extract_code_block, extract_obj
4from vllm import SamplingParams, LLM
5from langchain_core.prompts import PromptTemplate
6import subprocess
7
8# Load model and parameters
9model = LLM("chenyitian-shanshu/Qwen3-SIRL-4B",
10 tensor_parallel_size=1,
11 trust_remote_code=True)
12tokenizer = AutoTokenizer.from_pretrained("chenyitian-shanshu/Qwen3-SIRL-4B")
13sampling_params = SamplingParams(
14 n=1,
15 temperature=0.5,
16 top_p=0.95,
17 max_tokens=8192,
18 repetition_penalty=1.02
19 )
20
21# Load question. Here is just an example. Users can replace this with datasets they want to test
22question = "An industrial tire company delivers large tires for equipment to remote engineering sites either by cargo planes or ultrawide trucks. Each cargo plane can transport 10 tires per trip and costs $1000. Each ultrawide truck can transport 6 tires per trip and costs $700. The company needs to transport at least 200 tires and has available $22000. Because most remote sites don't have proper airports, the number of plane trips cannot exceed the number of ultrawide truck trips. How many trips of each should be done to minimize the total number of trips?"
23
24# Load prompt templete
25TIR_prompt_user = PromptTemplate.from_template(benchmark_gurobi_prompts['zeroshot_q2mc_en'])
26prompt =[ {"role": "user",
27 "content": TIR_prompt_user.format(Question=question).strip() }]
28
29# Generate Response
30text = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True)
31response = model.generate(text,sampling_params)
32response_text = response[0].outputs[0].text
33code_snippet = extract_code_block(response_text,'gurobi')
34result = subprocess.run(['python3', '-c', code_snippet], capture_output=True, text=True, timeout=100)
35obj = extract_obj(result.stdout,'gurobi')
36print(response_text)
37print('optimal value is', obj)1@article{chen2026opt,
2 title={OPT-Engine: Benchmarking the Limits of LLMs in Optimization Modeling via Complexity Scaling},
3 author={Chen, Yitian and Cheng, Cheng and Sun, Yinan and Ling, Zi and Ge, Dongdong},
4 journal={arXiv preprint arXiv:2601.19924},
5 year={2026}
6}