Instructions to use kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT
- SGLang
How to use kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT 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 "kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT" \ --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": "kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT", "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 "kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT" \ --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": "kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT with Docker Model Runner:
docker model run hf.co/kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT
Fine-tuning Phi-4-reasoning-plus on FinQA Dataset
This project fine-tunes the microsoft/Phi-4-reasoning-plus model using a medical reasoning dataset (TheFinAI/Fino1_Reasoning_Path_FinQA).
Setup
- Install the required libraries:
pip install -U datasets accelerate peft trl bitsandbytes
pip install -U transformers
pip install huggingface_hub[hf_xet]
- Authenticate with Hugging Face Hub:
Make sure your Hugging Face token is stored in an environment variable:
export HF_TOKEN=your_huggingface_token
The notebook will automatically log you in using this token.
How to Run
Load the Model and Tokenizer
The script downloads the full Phi-4-reasoning-plus model.Prepare the Dataset
- The notebook uses
TheFinAI/Fino1_Reasoning_Path_FinQA(first 1000 samples). - It formats each example into an instruction-following prompt with step-by-step chain-of-thought reasoning.
- The notebook uses
Fine-tuning
- Fine-tuning is set up with PEFT (LoRA / Adapter Tuning style) to modify a small subset of model parameters.
- TRL (Transformer Reinforcement Learning) is used to fine-tune efficiently.
Push Fine-tuned Model
- After training, the fine-tuned model and tokenizer are pushed back to your Hugging Face account.
Here is the training notebook: Fine_tuning_Phi-4-Reasoning-Plus
Model Configuration
- Base Model:
microsoft/Phi-4-reasoning-plus - Training: PEFT + TRL
- Dataset: 1000 examples FinQA reasoning dataset
Notes
- GPU Required: Make sure you have access to 1X A100s. Get it from RunPod for an hours. Training took only 7 minutes.
- Environment: The notebook expects an environment where NVIDIA CUDA drivers are available (
nvidia-smicheck is included).
Example Prompt Format
<|im_start|>system<|im_sep|>
Below is an instruction that describes a task, paired with an input that provides further context.
Write a response that appropriately completes the request.
Before answering, think carefully about the question and create a step-by-step chain of thoughts to ensure a logical and accurate response.
<|im_end|>
<|im_start|>user<|im_sep|>
{}<|im_end|>
<|im_start|>assistant<|im_sep|>
<think>
{}
</think>
{}
Usage Script (not-tested)
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
# Base model (original model from Meta)
base_model_id = "microsoft/Phi-4-reasoning-plus"
# Your fine-tuned LoRA adapter repository
lora_adapter_id = "kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT"
# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
base_model_id,
device_map="auto",
torch_dtype=torch.bfloat16,
trust_remote_code=True,
)
# Attach the LoRA adapter
model = PeftModel.from_pretrained(
base_model,
lora_adapter_id,
device_map="auto",
trust_remote_code=True,
)
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
# Inference example
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=1200)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)