Downloads · 30 days
0
ShAIkespear/Phi-2_DPO_M3_Quantized_Alt_8bit
Phi-2_DPO_M3_Quantized_Alt_8bit is a machine learning model from ShAIkespear. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as mit.
A quantized (8-bit) LoRA-finetuned variant of microsoft/phi-2 targeting STEM multiple-choice question answering (MCQA). The model was first trained with SFT on mixed STEM MCQA datasets, then aligned via DPO using huma…
Downloads · 30 days
0
Access
Public
Updated Nov 1, 2025
Repo size
52.4 MB
Likes
0
Public
Click a slice to open those files.
.safetensors52.4 MB · 94%
From the Hugging Face model README
A quantized (8-bit) LoRA-finetuned variant of microsoft/phi-2 targeting STEM multiple-choice question answering (MCQA). The model was first trained with SFT on mixed STEM MCQA datasets, then aligned via DPO using human preference data (EPFL exam MCQAs). Finally, it was quantized to 8-bit to reduce memory and improve inference speed.
This model adapts Phi-2 (2.78B params, 2,048 ctx) for MCQA, especially STEM. Training used LoRA adapters (rank=16, α=16, dropout=0.05) and the TRL library for SFT and DPO; checkpoints focus on adapter weights for compactness. An 8-bit quantized deployment configuration (BitsAndBytes) is provided.
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
import torch
model_id = "ShAIkespear/Phi-2_DPO_M3_Quantized_Alt_8bit" # replace with your Hub ID
bnb_config = BitsAndBytesConfig(load_in_8bit=True)
tok = AutoTokenizer.from_pretrained(model_id, use_fast=True)
model = AutoModelForCausalLM.from_pretrained(
model_id, device_map="auto", quantization_config=bnb_config
)
prompt = "### Question: What is 2+2?\n### Explanation: Add the integers.\n### Answer:"
inputs = tok(prompt, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=10)
print(tok.decode(out[0], skip_special_tokens=True))
Mixed SFT on: MathQA, OpenBookQA, ScienceQA, TAL-SCQ5K, plus balanced/shuffled merged MCQA sets; DPO on HelpSteer and a student-curated EPFL preference dataset (~20–30k pairs; subsets for SFT/DPO). Long items (>512 tokens) dropped; large datasets clipped to 20k samples. Splits: train 50%, test_overfit 25%, test_comparison 10%, test_quantization 15%.
Unified MCQA schema. SFT format: id, subject, question, answer/answer_text, choices. DPO format: prompt, rejected, chosen. Prompts used a structured header:
### Question ... ### Explanation ... ### Answer
Per-dataset held-out test sets (see splits), plus MMLU formatted to the SFT schema.
Task domain (math vs. general science vs. open-domain), data balancing, order of SFT/DPO phases.
Accuracy for MCQA; DPO choice accuracy for preference pairs.
Among several training recipes, the balanced-then-DPO configuration (model 8) performed best overall.
Phi-2 transformer decoder LM (2.78B params) with next-token prediction objective; LoRA adapters for finetuning; DPO for preference alignment; 8-bit quantized runtime.
Hugging Face TRL, PEFT/LoRA, Transformers; BitsAndBytes for quantization.