Qwen2.5-1.5B Formulador LP QLoRA
math optimization adapter
2 min readupdated
This adapter, built on Qwen2.5-1.5B-Instruct, is trained to translate natural language problem descriptions for linear programming (LP) and mixed-integer linear programming (MILP) in Spanish into a parametric formulation. The model outputs sets, parameters, variables with domains, the objective function, and constraints without solving the problem itself. The project was created as part of a generative AI course at the University of Concepción using a dataset of 1,050 pairs. The model is useful for engineers, researchers, and students studying optimization and automated mathematical modeling.
Key features
- Specialization: converting text into a strict LP/MILP mathematical model.
- Dataset: 1,050 example pairs covering 50 problem families (production, transport, logistics, knapsack problems, and more).
- Training method: QLoRA (a technique for efficient fine-tuning of large language models with reduced precision) with rank r=16 on Qwen2.5-1.5B.
- Metric improvement: outperforms the base model on optimization test benchmarks.
What you can do
- Pipeline integration: connect the adapter to the base Qwen2.5 model to automatically generate formulations in educational or engineering projects.
- Agent creation: use within multi-agent systems to automate the mathematical modeling stage of optimization tasks.
- Problem generation: test the model on your own text descriptions of problems in Spanish to get the variable structure and constraints.
Example
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base = "Qwen/Qwen2.5-1.5B-Instruct"
rev = "989aa7980e4cf806f80c7fef2b1adb7bc71aa306"
tok = AutoTokenizer.from_pretrained(base, revision=rev)
model = AutoModelForCausalLM.from_pretrained(base, revision=rev, torch_dtype="float16", device_map="auto")
model = PeftModel.from_pretrained(model, "sebastianmsl/qwen2.5-1.5b-formulador-lp-qlora")
messages = [{"role": "user", "content": ""}]
ids = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
print(tok.decode(model.generate(ids, max_new_tokens=1200, do_sample=False)[0, ids.shape[1]:], skip_special_tokens=True))Read more
DetailsBenchmarks (FOM-5 v2, scale 0–5): average score on 30 problems increased from 0.588 to 0.802.
Hardware: trained on an NVIDIA T4 in 982 seconds, requiring 9.04 GiB VRAM.
Limitations: trained in a single session with a single seed; may apply a template structure on rare combinations of conditions.










Comments