Model guide
Phi-4 Mini Flash Reasoning
Phi-4 Mini Flash Reasoning uses a different hybrid architecture from ordinary Phi-4 Mini. Consider it for an application that supports its published native workflow, not as a drop-in GGUF chat download. Its focus is mathematical reasoning; validate a small problem before planning longer inputs or adapting the runtime.
At a glance
- Parameters
- 3.8B
- Accepts
- Text
- Returns
- Text
- Published context limit
- 64,000 tokens
- Model format
- safetensors
- Model-weight download
- 7.71 GB of BF16 weights · native workflow
- Languages
- English
- License
- MIT
The recorded BF16 weights are about 7.71 GB. Measure peak GPU memory with the publisher’s example at the input length you need.
Best for
- Use Microsoft’s SambaY example when you already have its CUDA development setup. Compare its final math answer and elapsed time on that hardware.
Choose something else when
- Choose a different checkpoint for a desktop chat app or a CPU-only machine.
First setup
Microsoft's SambaY math-reasoning workflow requires a CUDA development environment and custom model code. It is not a native beginner Windows chat-app installation. Use a separate Linux/CUDA Python environment; the publisher lists these dependencies:
python -m pip install torch==2.6.0 transformers==4.46.1 accelerate==1.4.0
python -m pip install flash_attn==2.7.4.post1
python -m pip install mamba-ssm==2.2.4 causal-conv1d==1.5.0.post8 --no-build-isolation
Read the repository's custom Python before enabling trust_remote_code=True. Then try a short English math prompt:
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "microsoft/Phi-4-mini-flash-reasoning"
model = AutoModelForCausalLM.from_pretrained(repo, device_map="cuda", torch_dtype="auto", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(repo)
inputs = tokenizer.apply_chat_template([{"role":"user", "content":"Solve 2*x + 3 = 11."}], add_generation_prompt=True, return_dict=True, return_tensors="pt")
output = model.generate(**inputs.to(model.device), max_new_tokens=512, temperature=0.6, top_p=0.95, do_sample=True)
print(tokenizer.decode(output[0, inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
Check any final answer by substituting it into the equation (x = 4). The 512-token cap may stop the reasoning before an answer; that is an interrupted result, not a failed arithmetic check. Kernel/build failures need a compatible CUDA toolchain and publisher dependencies. A CPU fallback is not established by this example.
Save the Python example as example.py, then run python example.py in the environment where you installed its packages. The first run downloads model files; later local execution still needs the cached files. Start with these short inputs and batch size 1. If loading runs out of memory, close other model processes or use a smaller model; treat missing or unfinished output as an interrupted answer. See the publisher model card for the full workflow.
Load the model, start a fresh chat and time your usual prompt. Record time until the first useful word and time until the full answer. Note the processor, context and output length when comparing another run. Time the final answer as well as the first generated token.
