Qwen3-0.6B — MiniZinc Code Generation (LoRA)

A fine-tuned version of Qwen3-0.6B for generating MiniZinc constraint programming code from natural language optimization problem descriptions.

Model Description

This model translates plain-English optimization problems into executable MiniZinc code. It was fine-tuned with LoRA on the learn2zinc dataset using the Unsloth library.

Attribute Value
Base model unsloth/Qwen3-0.6B
Parameters 0.6B
Fine-tuning method LoRA (rank 64)
Chat template qwen-2.5
Max sequence length 4096

Training Details

Hyperparameter Value
LoRA rank (r) 64
LoRA alpha 64
LoRA dropout 0
Target modules q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
Learning rate 2e-4
LR scheduler Cosine
Warmup steps 50
Epochs 3
Optimizer AdamW 8-bit
Weight decay 0.01
Precision bf16
Seed 42
Training Response-only (SFTTrainer with train_on_responses_only)

Usage

Installation

pip install unsloth torch transformers

Inference

from unsloth import FastLanguageModel
from unsloth.chat_templates import get_chat_template

# Load model
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="skadio/learn2zinc-Qwen3-0.6B"
    max_seq_length=4096,
    dtype=None,
    load_in_4bit=False,
)
FastLanguageModel.for_inference(model)

# Apply chat template
tokenizer = get_chat_template(tokenizer, chat_template="qwen-2.5")

# Define the problem
problem = """A farmer needs to decide how many cows, sheep, and chickens to raise in order to achieve maximum profit. The farmer can sell cows, sheep, and chickens for $500, $200, and $8 each, respectively. The feed costs for each cow, sheep, and chicken are $100, $80, and $5, respectively. The profit is the difference between the selling price and the feed cost. Each cow, sheep, and chicken produces 10, 5, and 3 units of manure per day, respectively. Due to the limited time the farm staff has for cleaning the farm each day, they can handle up to 800 units of manure. Additionally, because of the limited farm size, the farmer can raise at most 50 chickens. Furthermore, the farmer must have at least 10 cows to meet customer demand. The farmer must also raise at least 20 sheep. Finally, the total number of animals cannot exceed 100."""

# Format messages
messages = [
    {"role": "system", "content": "Generate MiniZinc code for the following optimization problem."},
    {"role": "user", "content": problem},
]

inputs = tokenizer.apply_chat_template(
    messages, add_generation_prompt=True, return_tensors="pt", return_dict=True,
).to(model.device)

# Generate
outputs = model.generate(
    **inputs,
    max_new_tokens=4096,
    do_sample=False,
    pad_token_id=tokenizer.eos_token_id,
)

response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(response)

Extracting MiniZinc Code

The model wraps its output in a fenced code block. To extract the code:

import re

def extract_minizinc_code(text):
    match = re.search(r'```(?:\w+)?\n(.*?)\n```', text, re.DOTALL | re.IGNORECASE)
    return match.group(1).strip() if match else None

code = extract_minizinc_code(response)

Evaluation

Models were evaluated on the IndustryOR subset of learn2zinc (cardinal_operations_industryor). Generated MiniZinc code was executed with the HiGHS solver (120 s timeout). All generations used temperature = 0 for reproducibility.

Metrics: Execution Success Rate (code compiles and runs) and Solution Correctness (objective matches expected value within 1e-6).

For full evaluation details, see learn2zinc.

Dataset

Training data comes from skadio/learn2zinc-augmented, which pairs natural language optimization problem descriptions with corresponding MiniZinc code.

Framework

Downloads last month
12
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for skadio/learn2zinc-Qwen3-0.6B

Finetuned
Qwen/Qwen3-0.6B
Adapter
(26)
this model

Dataset used to train skadio/learn2zinc-Qwen3-0.6B