OptiLIR-Qwen3-8B
A LoRA adapter for Qwen/Qwen3-8B. It reads an optimization request (Korean, English or mixed; one turn, or three turns after a clarification question) in one of three domains (vehicle routing, nurse scheduling, retail inventory) and writes the request in OptiLIR (Optimization-oriented Language Intermediate Representation), one item per line. A deterministic grounder, which is not included here, maps the IR onto the optimization server's declared capabilities and decides whether to execute, ask the user (clarify), or decline (unsupported).
Training data and the IR format: omelet-ai/OptiLIR-Instruct-v1. Code (the IR parser and grammar, the grounder, training and evaluation): omelet-ai/OptiLIR. Terms (IR, frame, mark, hole, capability, ref, grounder, decision): see the Terms section of the dataset card.
Usage
The adapter expects the domain's system prompt from the dataset (prompts/<domain>.txt), unchanged,
followed by the conversation. Decode greedily (no sampling) with thinking disabled. The output is the IR
and nothing else.
import torch
from huggingface_hub import hf_hub_download
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
BASE, ADAPTER, DATASET = "Qwen/Qwen3-8B", "omelet-ai/OptiLIR-Qwen3-8B", "omelet-ai/OptiLIR-Instruct-v1"
tok = AutoTokenizer.from_pretrained(BASE)
model = AutoModelForCausalLM.from_pretrained(BASE, dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(model, ADAPTER).eval()
domain = "routing" # routing | nurse | retail
system = open(hf_hub_download(DATASET, f"prompts/{domain}.txt", repo_type="dataset"), encoding="utf-8").read()
messages = [
{"role": "system", "content": system},
{"role": "user", "content": "Minimize the total travel distance, and if possible keep every route under 80 km."},
]
prompt = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
inputs = tok(prompt, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=512, do_sample=False)
print(tok.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True).strip())
The chat template is applied as in training. In training, the vocabulary listing of the system prompt was
also shuffled per row (see the Input row under Training); at inference, use prompts/<domain>.txt unchanged.
The longest IRs in the dataset take about 400 tokens with the Gemma 4 tokenizer and 330 with the Qwen3
tokenizer, so keep the output limit at 512.
Grammar-constrained decoding (optional)
grammar/<domain>.ebnf in the dataset is an EBNF (xgrammar / GBNF style) for the domain's IR.
Constraining decoding with it keeps the output inside the IR syntax; it does not make the meaning correct.
With vLLM's OpenAI-compatible server:
vllm serve Qwen/Qwen3-8B --enable-lora --lora-modules ir=omelet-ai/OptiLIR-Qwen3-8B --max-lora-rank 32 --max-num-seqs 256
Checked with vLLM 0.28.0 on one 80 GB H100. If vLLM runs out of memory during start-up, lower
--max-num-seqs.
import requests
from huggingface_hub import hf_hub_download
grammar = open(hf_hub_download("omelet-ai/OptiLIR-Instruct-v1", "grammar/routing.ebnf", repo_type="dataset"), encoding="utf-8").read()
payload = {
"model": "ir",
"messages": messages, # as above
"temperature": 0,
"max_tokens": 512,
"structured_outputs": {"grammar": grammar},
"chat_template_kwargs": {"enable_thinking": False},
}
print(requests.post("http://localhost:8000/v1/chat/completions", json=payload).json()["choices"][0]["message"]["content"])
With transformers, the same grammar can be applied through an xgrammar logits processor.
Training
| Setting | Value |
|---|---|
| Method | LoRA, supervised fine-tuning with TRL SFTTrainer |
| Loss | completion-only (only the IR tokens are scored) |
| Input | prompts/<domain>.txt as the system turn, its vocabulary listing shuffled per row and seeded by the row id (system_prompt(domain, seed=id, forms=True); scripts/train_lora.py with SHUFFLE=1), then the conversation; chat template with enable_thinking=False. At inference, use the published file unchanged |
| Epochs | 3 |
| Learning rate | 1e-4, cosine schedule, 10 warmup steps |
| Effective batch size | 16 |
| Max sequence length | 4096 tokens |
| Precision | bf16, gradient checkpointing, SDPA attention |
| Seed | 41 |
| Training data | omelet-ai/OptiLIR-Instruct-v1, train split (validation for evaluation during training) |
| LoRA | r=32, alpha=64, dropout=0.05, bias=none |
| Target modules | down_proj, gate_proj, k_proj, o_proj, q_proj, up_proj, v_proj |
| Adapter parameters | 87,293,952 in 504 tensors (F32) |
| Frameworks | PEFT 0.20.0, TRL 1.12.0, Transformers 5.16.1, PyTorch 2.9.1+cu128, Accelerate 1.14.0, Datasets 5.0.1, Tokenizers 0.23.3 |
Known weakness: when a nurse request asks for an even workload without saying how evenness is measured, the correct output asks back (UNSPECIFIED). This adapter wrote the gap between the busiest and the least busy nurse (RANGE) instead on 8 of the 19 such validation rows (test: 20 of 21 right). The Gemma 4 12B adapter trained on the same data asked on all 40.
After training, the system's clarification question was reworded in 96 dataset rows (84 train, 6 validation, 6 test). Only that turn changed, and the IRs are the same. This adapter was trained, and the metrics below computed, on the earlier wording. Regenerating the 12 evaluation rows on the published text moves no cell of the table by more than 0.1 point.
Evaluation
| Evaluation set | n | Parse rate | IR match | Decision match |
|---|---|---|---|---|
| validation | 880 | 100.0% | 96.0% | 97.3% |
| test, all rows | 1916 | 100.0% | 95.9% | 96.8% |
| test, capabilities seen in training | 988 | 100.0% | 95.9% | 97.1% |
test, held-out capability constraint:max_duration |
928 | 100.0% | 96.0% | 96.4% |
Greedy decoding constrained by the domain grammar (grammar/<domain>.ebnf), at most 400 new tokens, with the same per-row shuffled system prompt as in training (scripts/evaluate.py --shuffle). Parse rate: share of outputs that parse as IR. IR match: share equal to the gold IR once both are in normal form (values in base units, so 80 km = 80000 m; the quantity on the left of a comparison; an upper bound on a MAX (or a lower bound on a MIN) written as the same bound under EACH; AND items flattened, sorted and deduplicated; TOGETHER/OVERLAPS arguments and EACH chains in a fixed order; binders renumbered). Frames must come in the same order with the same marks; the COMPOSE, NO_INTENT and CLARIFY(intent) lines must agree; UNEXPRESSED lines are compared regardless of order. Decision match: share whose grounded decision equals the gold decision; this is the main metric, since it is what the downstream system acts on. All three can be reproduced with the dataset and scripts/evaluate.py; for decision match, set EXECUTION_LLM_REGISTRY to the dataset's registry.json, the registry behind its gold decisions.
The dataset's test split holds both test sets. The held-out rows are the 928 routing rows whose IR
bounds duration from above (<= or <), per route or per round, scope holes included, for example
[SOFT] EACH(x1 in routes): duration(x1) <= 90 min; the other 988 rows cover capabilities seen in
training. Selecting rows by the constraint:max_duration ref in gold_decision gives 822 rows instead:
the unsupported rows and most clarify rows do not name it, and neither do the 16 execute rows whose bound is
UNDECIDED (the grounder leaves such a bound out).
Limitations
- The adapter covers only the three domains and the vocabularies in the dataset's prompts. Other domains, other prompts, or edited prompts are not supported.
- The adapter only writes IR. It does not decide whether a request can be executed; use a grounder that checks the IR against the server's declared capabilities before anything runs.
- It was trained on synthetic, LLM-written requests. Real requests (short, noisy, with typos or local jargon) may be parsed less accurately, and the Korean training text has naturalness gaps.
- A well-formed IR can still be wrong in meaning: a wrong measure, a missed or extra constraint, or a
wrong
[HARD]/[SOFT]mark grounds to a wrong decision. Grammar-constrained decoding fixes syntax only. - The base model's own license and limitations also apply; see the base model card.
Citation
@misc{OptiLIR-Qwen3-8B,
title = {OptiLIR-Qwen3-8B: a LoRA adapter for Qwen/Qwen3-8B that writes optimization requests in OptiLIR},
author = {omelet-ai},
year = {2026},
url = {https://huggingface.co/omelet-ai/OptiLIR-Qwen3-8B}
}