Instructions to use RobinMillford/phi-4-math-reasoning-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use RobinMillford/phi-4-math-reasoning-lora with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="RobinMillford/phi-4-math-reasoning-lora") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("RobinMillford/phi-4-math-reasoning-lora", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use RobinMillford/phi-4-math-reasoning-lora with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "RobinMillford/phi-4-math-reasoning-lora" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "RobinMillford/phi-4-math-reasoning-lora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/RobinMillford/phi-4-math-reasoning-lora
- SGLang
How to use RobinMillford/phi-4-math-reasoning-lora with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "RobinMillford/phi-4-math-reasoning-lora" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "RobinMillford/phi-4-math-reasoning-lora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "RobinMillford/phi-4-math-reasoning-lora" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "RobinMillford/phi-4-math-reasoning-lora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio new
How to use RobinMillford/phi-4-math-reasoning-lora with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for RobinMillford/phi-4-math-reasoning-lora to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for RobinMillford/phi-4-math-reasoning-lora to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for RobinMillford/phi-4-math-reasoning-lora to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="RobinMillford/phi-4-math-reasoning-lora", max_seq_length=2048, ) - Docker Model Runner
How to use RobinMillford/phi-4-math-reasoning-lora with Docker Model Runner:
docker model run hf.co/RobinMillford/phi-4-math-reasoning-lora
🧮 Phi-4 Math Reasoning Model (LoRA Finetuned)
📌 Model Overview
This model is a LoRA fine-tuned version of unsloth/phi-4-unsloth-bnb-4bit.
It has been fine-tuned specifically for math reasoning tasks, capable of solving step-by-step arithmetic, algebra, and logic problems.
The base model is Phi-4, a 14B-parameter LLaMA variant optimized with Unsloth for 2x faster training using Hugging Face’s TRL library.
This version uses bnb-4bit quantization, making it memory efficient and suitable for single-GPU setups such as Tesla T4 (16GB) or consumer GPUs.
⚡ Key Features
- 🧠 Fine-tuned for math reasoning and step-by-step solutions
- ⚡ Efficient: 4-bit quantized, runs on a single GPU or even CPU (slower)
- 🚀 Trained with Unsloth + TRL for fast and memory-efficient fine-tuning
- 📚 Based on Phi-4 (14B LLaMA model)
📥 Installation
Ensure you have the latest versions of the required libraries:
pip install unsloth transformers accelerate bitsandbytes
🖥️ Usage (Colab / Local GPU)
import torch
from unsloth import FastLanguageModel
from transformers import TextStreamer
# Load the LoRA fine-tuned model
model_name = "RobinMillford/phi-4-math-reasoning-lora"
model, tokenizer = FastLanguageModel.from_pretrained(
model_name=model_name,
max_seq_length=2048,
dtype=torch.float16, # fp16 recommended for GPU
load_in_4bit=True, # load in 4-bit quantized mode
device_map="auto" # automatically place layers on GPU/CPU
)
# Prepare for inference
FastLanguageModel.for_inference(model)
# Example: Generate a step-by-step solution
streamer = TextStreamer(tokenizer)
inputs = tokenizer(
"Solve step by step: Q: What is 24 * 17 ? A:",
return_tensors="pt"
).to("cuda")
_ = model.generate(**inputs, streamer=streamer, max_new_tokens=500)
📊 Example Output
Prompt:
Solve step by step: Q: What is 45 + 67 ?
Response:
Step 1: Add the ones digits: 5 + 7 = 12. Write down 2 and carry over 1. Step 2: Add the tens digits plus carry: 4 + 6 + 1 = 11. Step 3: Combine the results: 112. Answer: 112
⚠️ Disclaimer
This model is intended for research and educational purposes only.
It may not be fully accurate for complex math reasoning tasks. Always verify critical calculations independently.
docker model run hf.co/RobinMillford/phi-4-math-reasoning-lora