Microsoft's new Phi-4 reasoning models are now supported in Unsloth. The 'plus' variant performs on par with OpenAI's o1-mini, o3-mini and Sonnet 3.7. The 'plus' and standard reasoning models are 14B parameters while the 'mini' has 4B parameters.
All Phi-4 reasoning uploads use our methodology.
Phi-4 reasoning - Unsloth Dynamic 2.0 uploads:
Dynamic 2.0 GGUF (to run)
Dynamic 4-bit Safetensor (to finetune/deploy)
🖥️ Running Phi-4 reasoning
Official Recommended Settings
According to Microsoft, these are the recommended settings for inference:
Temperature = 0.8
Top_P = 0.95
Phi-4 reasoning Chat templates
Please ensure you use the correct chat template as the 'mini' variant has a different one.
Phi-4-mini:
<|system|>Your name is Phi, an AI math expert developed by Microsoft.<|end|><|user|>How to solve 3*x^2+4*x+5=1?<|end|><|assistant|>
Phi-4-reasoning and Phi-4-reasoning-plus:
This format is used for general conversation and instructions:
<|im_start|>system<|im_sep|>You are Phi, a language model trained by Microsoft to help users. Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} </think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:<|im_end|><|im_start|>user<|im_sep|>What is 1+1?<|im_end|><|im_start|>assistant<|im_sep|>
Yes, the chat template/prompt format is this long!
Run the model! Note you can call ollama servein another terminal if it fails. We include all our fixes and suggested parameters (temperature etc) in params in our Hugging Face upload.
ollama run hf.co/unsloth/Phi-4-mini-reasoning-GGUF:Q4_K_XL
📖 Llama.cpp: Run Phi-4 reasoning Tutorial
You must use --jinja in llama.cpp to enable reasoning for the models, expect for the 'mini' variant. Otherwise no token will be provided.
Run the model in conversational mode in llama.cpp. You must use --jinja in llama.cpp to enable reasoning for the models. This is however not needed if you're using the 'mini' variant.
Obtain the latest llama.cpp on . You can follow the build instructions below as well. Change -DGGML_CUDA=ON to -DGGML_CUDA=OFF if you don't have a GPU or just want CPU inference.
for the models are also now supported in Unsloth. To fine-tune for free on Google Colab, just change the model_name of 'unsloth/Phi-4' to 'unsloth/Phi-4-mini-reasoning' etc.