What it does
Trained on 56,253 instruction samples: 70% ECInstruct (generic e-commerce) + 30% synthetic Magento-schema data generated from the Magento Luma sample catalog (products fully disjoint between train and eval). Four task shapes:
Attribute extraction — product text (or a raw Magento custom_attributes payload) → JSON:
target attribute: sizeproduct title: Puma Suede green sneakers size 43→ [{"attribute": "size", "value": "43"}]
Absent attributes are reported as "None" rather than hallucinated.
Product QA — a question answered strictly from given product data.
Relevance classification — query + product → graded relevance option (ESCI-style A–D).
Relevance ranking — query + lettered product list → ranked letters (B,A,C).
Usage — adapter (unsloth / peft)
from unsloth import FastLanguageModel model, tokenizer = FastLanguageModel.from_pretrained( "gabrielgts/phi4-3b-ec-magento", max_seq_length=2048, load_in_4bit=True)FastLanguageModel.for_inference(model) # No system message — the model was trained without one (Phi's template# injects nothing by default). Greedy decoding recommended.messages = [{"role": "user", "content": "Extract the value of the target attribute from the given product information " "and output it as JSON. If the attribute is not present, output None as the value.\n\n" "target attribute: size\nproduct title: Puma Suede green sneakers size 43"}]text = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)inputs = tokenizer(text=text, return_tensors="pt").to("cuda")out = model.generate(**inputs, max_new_tokens=64, do_sample=False)print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))# [{"attribute": "size", "value": "43"}]
Plain peft also works: PeftModel.from_pretrained(base_model, "gabrielgts/phi4-3b-ec-magento").
Usage — GGUF / Ollama
hf download gabrielgts/phi4-3b-ec-magento --include 'gguf/*' --local-dir .cd gguf && ollama create phi4-3b-ec-magento -f Modelfileollama run phi4-3b-ec-magento "target attribute: color ..."
Gotchas (learned the hard way)
- Fine-tune from the unsloth repo, not microsoft's: microsoft's tokenizer config sets
eos=<|endoftext|>, which the model rarely emits — generation does not stop at <|end|> and rambles past answers. The unsloth export fixes eos=<|end|>. Unsloth also silently remaps the microsoft id to its dynamic-quant repo; pin the plain -bnb-4bit id for standard NF4.
- Fused projections: phi3 fuses
qkv_proj/gate_up_proj. LoRA target names q_proj/k_proj/v_proj/gate_proj/up_proj silently match nothing (peft skips without erroring) — target qkv_proj, o_proj, gate_up_proj, down_proj.
- Quantization sensitivity: at plain Q4_K_M the tied 200k-vocab embedding degrades outputs (wrong attributes extracted with perfect JSON formatting). The shipped GGUF uses
--token-embedding-type q8_0 --output-tensor-type q8_0.
Training recipe
Table with columns: Parameter, Value| Parameter | Value |
|---|
| Method | QLoRA (4-bit NF4 base, bf16 compute) via Unsloth |
| LoRA | r=8, alpha=16, targets qkv_proj/o_proj/gate_up_proj/down_proj (fused) |
| Trainable params | 11.5M of 3,836M (0.30%) |
| Batch | 1 × grad_accum 16 (effective 16), max_seq_length 2048 |
| Optimizer / LR | paged_adamw_8bit, 2e-4 cosine, 1 epoch, seed 42 |
| Data | 56,253 samples: 39,377 ECInstruct + 16,876 Magento-synthetic |
| System prompt | none at train and eval |
Evaluation
Greedy decoding, identical prompts across all models; base models evaluated zero-shot with the same harness. Siblings: qwen3.5-4b-ec-magento (4.55B params), ministral3-3b-ec-magento (3.85B text params) — Phi-4-mini (3.84B) and Ministral are size-matched; Qwen is ~18% larger.
Magento held-out set (2,969 samples, 475 products never seen in training):
Table with columns: Task · metric, Base, this model, ministral3-3b, qwen3.5-4b| Task · metric | Base | this model | ministral3-3b | qwen3.5-4b |
|---|
| Attribute extraction · F1 | 0.000 | 0.946 | 0.945 | 0.938 |
| Attribute extraction · parse failures | 96.3% | 0.3% | 0.1% | 0% |
| Product QA · token-F1 | 0.013 | 0.950 | 0.954 | 0.943 |
| Relevance classification · accuracy | 0.396 | 0.959 | 0.972 | 0.962 |
| Relevance rank · top-1 | 0.280 | 0.783 | 0.793 | 0.799 |
ECInstruct held-out set (2,000 samples):
Table with columns: Task · metric, Base, this model, ministral3-3b, qwen3.5-4b| Task · metric | Base | this model | ministral3-3b | qwen3.5-4b |
|---|
| Attribute extraction · F1 | 0.000 | 0.616 | 0.654 | 0.646 |
| Query→product rank · top-1 | 0.000 | 0.645 | 0.632 | 0.650 |
| Relevance classification · accuracy | 0.570 | 0.650 | 0.655 | 0.685 |
| Answerability · accuracy | 0.555 | 0.733 | 0.735 | 0.780 |
Limitations — read before relying on the numbers
- The Magento eval is synthetic-on-synthetic. Eval tasks were generated with the same templates as training data (products fully disjoint). It validly measures schema adherence — JSON format, Magento attribute vocabularies, the None-when-absent rule — but overstates production quality on real catalogs and real user queries.
- The base model's near-zero extraction scores are dominated by format non-adherence; they understate its underlying capability.
- The fused-projection LoRA shares one rank-8 subspace across q/k/v — a small ECInstruct deficit vs the siblings may reflect this structural difference rather than model quality.
- English only; fine-tuned on structured data — expect degraded general chat vs the base (drop the adapter to recover it).
- Use greedy decoding (
do_sample=False / temperature 0) — that's how it was evaluated.
Provenance
Table | |
|---|
| Training run | phi4-mini-r8-mix56k-e1 (2026-07-14) |
| Adapter sha256 | f856fa953ae099762bbf91e6410f90902432bd23776266323366941dfeaa29a3 |
| Train set sha256 | afb7e664cda4490597c1914db6aff94933991a56d2175435666f8f6b7a726532 (mixture_train.jsonl, 56,253 rows) |
| Eval set sha256 | 8feafdb2… (magento_eval.jsonl) · 2583a61e… (ecinstruct_eval.jsonl) |
| GGUF | adapter merged into microsoft/Phi-4-mini-instruct bf16, Q4_K_M + q8_0 embeddings, sha256 9fcd955e… |
| Stack | torch 2.6.0+cu124 · transformers 5.5.0 · unsloth 2026.6.9 |
References