Views
No views yet
| Attribute | Value |
|---|---|
| Base model | unsloth/Llama-3.2-3B-Instruct |
| Parameters | 3B |
| Fine-tuning method | LoRA (rank 64) |
| Chat template | llama-3.1 |
| Max sequence length | 4096 |
| 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) |
pip install unsloth torch transformers1from unsloth import FastLanguageModel
2from unsloth.chat_templates import get_chat_template
3
4# Load model
5model, tokenizer = FastLanguageModel.from_pretrained(
6 model_name="skadio/learn2zinc-Llama-3.2-3B"
7 max_seq_length=4096,
8 dtype=None,
9 load_in_4bit=False,
10)
11FastLanguageModel.for_inference(model)
12
13# Apply chat template
14tokenizer = get_chat_template(tokenizer, chat_template="llama-3.1")
15
16# Define the problem
17problem = """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."""
18
19# Format messages
20messages = [
21 {"role": "system", "content": "Generate MiniZinc code for the following optimization problem."},
22 {"role": "user", "content": problem},
23]
24
25inputs = tokenizer.apply_chat_template(
26 messages, add_generation_prompt=True, return_tensors="pt", return_dict=True,
27).to(model.device)
28
29# Generate
30outputs = model.generate(
31 **inputs,
32 max_new_tokens=4096,
33 do_sample=False,
34 pad_token_id=tokenizer.eos_token_id,
35)
36
37response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
38print(response)1import re
2
3def extract_minizinc_code(text):
4 match = re.search(r'```(?:\w+)?\n(.*?)\n```', text, re.DOTALL | re.IGNORECASE)
5 return match.group(1).strip() if match else None
6
7code = extract_minizinc_code(response)cardinal_operations_industryor). Generated MiniZinc code was executed with the HiGHS solver (120 s timeout). All generations used temperature = 0 for reproducibility.