microsoft / phi-4-mini-instruct

Overview

Description:

Phi-4-Mini is a lightweight open model built upon synthetic data and filtered publicly available websites - with a focus on high-quality, reasoning dense data. The model belongs to the Phi-4 model family and supports 128K token context length. The model underwent an enhancement process, incorporating both supervised fine-tuning and direct preference optimization to support precise instruction adherence and robust safety measures.

This model is ready for commercial/non-commercial use.

Third-Party Community Consideration

This model is not owned or developed by NVIDIA. This model has been developed and built to a third-party’s requirements for this application and use case; see link to Non-NVIDIA Phi-4-Mini.

License/Terms of Use:

GOVERNING TERMS: This trial service is governed by the NVIDIA API Trial Terms of Service. Use of this model is governed by the NVIDIA Community Model License. Additional Information: MIT License.

Deployment Geography:

Global

Release Date:

February 2025

Reference(s):

Phi-4-Mini Model Card

Intended Use

Primary use cases:

The model is intended for broad multilingual commercial and research use. The model provides uses for general purpose AI systems and applications which require 1) memory/compute constrained environments; 2) latency bound scenarios; 3) strong reasoning (especially math and logic).

The model is designed to accelerate research on language and multimodal models, for use as a building block for generative AI powered features.

Out-of-scope use cases

The model is not specifically designed or evaluated for all downstream purposes. Developers should consider common limitations of language models, as well as performance differences across languages, as they select use cases, and evaluate and mitigate for accuracy, safety, and fairness before using within a specific downstream use case, particularly for high-risk scenarios. Developers should be aware of and adhere to applicable laws or regulations (including but not limited to privacy, trade compliance laws, etc.) that are relevant to their use case.

Nothing contained in this Model Card should be interpreted as or deemed a restriction or modification to the license the model is released under.

Release Notes

This release of Phi-4-Mini is based on valuable user feedback from the Phi-3 series. The Phi-4-Mini model employed new architecture for efficiency, larger vocabulary for multilingual multimodal support, and better post-training techniques were used for instruction following, function calling, as well as additional data leading to substantial gains on key capabilities. It is anticipated that most use cases will benefit from this release, but users are encouraged to test in their particular AI applications. The enthusiastic support for the Phi-4 series is greatly appreciated. Feedback on Phi-4-Mini is welcomed and crucial to the model’s evolution and improvement.

Model Architecture:

Architecture Type: Dense decoder-only Transformer model

Phi-4-Mini has 3.8B parameters. When compared with Phi-3.5-Mini, the major changes with Phi-4-Mini are 200K vocabulary, grouped-query attention, and shared embedding.<br

Input:

Input Type(s): Text

Input Format(s): String

Input Parameters: 1D

Other Properties Related to Input: 128K token context length. Best suited for chat-completion format prompts.

  • Supported Languages: Arabic, Chinese, Czech, Danish, Dutch, English, Finnish, French, German, Hebrew, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Russian, Spanish, Swedish, Thai, Turkish, Ukrainian

Output:

Output Type(s): Text

Output Format(s): String

Output Parameters: 1D

Supported Hardware Microarchitecture Compatibility:

  • NVIDIA Jetson
  • NVIDIA Volta

[Preferred/Supported] Operating System(s):

  • Linux

Model Version(s):

Phi-3.5-Mini v1.0

Training, Testing, and Evaluation Datasets:

Data Collection Methods: [Hybrid: Automated, Human, Synthetic]
GPUS: 1024 A100-80G

Training Time: 14 days

Training Data: Text in response to the input

Training Dates: Trained between November and December 2024

Status: This is a static model trained on an offline dataset with the cutoff date of June 2024 for publicly available data.

Languages in training data: Arabic, Chinese, Czech, Danish, Dutch, English, Finnish, French, German, Hebrew, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Russian, Spanish, Swedish, Thai, Turkish, Ukrainian

Data Overview

Phi-4-Mini’s training data includes a wide variety of sources, totaling 5 trillion tokens, and is a combination of 1) publicly available documents filtered for quality, selected high-quality educational data, and code; 2) newly created synthetic, “textbook-like” data for the purpose of teaching math, coding, common sense reasoning, general knowledge of the world (e.g., science, daily activities, theory of mind, etc.); 3) high quality chat format supervised data covering various topics to reflect human preferences on different aspects such as instruct-following, truthfulness, honesty and helpfulness.

We focused on the quality of data that could potentially improve the reasoning ability for the model, and the publicly available documents were filtered to contain a preferred level of knowledge. As an example, the result of a game in premier league on a particular day might be good training data for frontier models, but such information was removed to leave more model capacity for reasoning for the model’s small size. More details about data can be found in the Phi-4-Mini technical report.

The decontamination process involved normalizing and tokenizing the dataset, then generating and comparing n-grams between the target dataset and benchmark datasets. Samples with matching n-grams above a threshold were flagged as contaminated and removed from the dataset. A detailed contamination report was generated, summarizing the matched text, matching ratio, and filtered results for further analysis.

Safety Approach

The Phi-4 family of models has adopted a robust safety post-training approach. This approach leverages a variety of both open-source and in-house generated datasets. The overall technique employed to do the safety alignment is a combination of SFT (Supervised Fine-Tuning), DPO (Direct Preference Optimization), and RLHF (Reinforcement Learning from Human Feedback) approaches by utilizing human-labeled and synthetic English-language datasets, including publicly available datasets focusing on helpfulness and harmlessness as well as various questions and answers targeted to multiple safety categories. For non-English languages, the existing datasets were extended via machine translation.

Safety Evaluation and Red-Teaming

Various evaluation techniques including red teaming, adversarial conversation simulations, and multilingual safety evaluation benchmark datasets were leveraged to evaluate Phi-4 models’ propensity to produce undesirable outputs across multiple languages and risk categories. Several approaches were used to compensate for the limitations of one approach alone. Findings across the various evaluation methods indicate that safety post-training that was done as detailed in the Phi 3 Safety Post-Training paper had a positive impact across multiple languages and risk categories as observed by refusal rates (refusal to output undesirable outputs) and robustness to jailbreak techniques. Details on prior red team evaluations across Phi models can be found in the Phi 3 Safety Post-Training paper.

For this release, initial insights from red teaming indicate that the models may at times be mistaken about which company created them; ad-hoc training data were added to correct this behavior. Another insight was that with function calling scenarios, the models could sometimes hallucinate function names or URL’s. Models may also be more susceptible to longer multi-turn jailbreak techniques across both English and non-English languages. These findings highlight the need for industry-wide investment in the development of high-quality safety evaluation datasets across multiple languages, including low resource languages, and risk areas that account for cultural nuances where those languages are spoken.

Model Quality

To understand the capabilities, the 3.8B parameters Phi-4-Mini model was compared with a set of models over a variety of benchmarks using an internal benchmark platform (See Appendix A for benchmark methodology). A high-level overview of the model quality is as follows:

Popular Aggregated Benchmarks

Phi-4 Mini-InsPhi-3.5-Mini-InsLlama-3.2-3B-InsMinistral-3BQwen2.5-3B-InsQwen2.5-7B-InsMinistral-8B-2410Llama-3.1-8B-InsLlama-3.1-Tulu-3-8BGemma 2-9B-ItGPT-4o-mini-2024-07-18
Arena Hard32.834.41726.93255.537.325.742.743.775
BigBench Hard CoT (0-shot)70.463.155.451.256.272.453.363.455.565.780.4
MMLU (5-shot)67.365.561.860.86572.66368.16571.377.2
MMLU-Pro (0-shot, CoT)52.834.439.235.344.756.236.64440.950.162.8

Reasoning

Phi-4 Mini-InsPhi-3.5-Mini-InsLlama-3.2-3B-InsMinistral-3BQwen2.5-3B-InsQwen2.5-7B-InsMinistral-8B-2410Llama-3.1-8B-InsLlama-3.1-Tulu-3-8BGemma 2-9B-ItGPT-4o-mini-2024-07-18
ARC Challenge (10-shot)83.747.476.180.382.690.182.783.179.489.893.5
BoolQ (2-shot)81.284.671.479.465.48080.582.87985.788.7
GPQA (0-shot, CoT)30.477.726.624.324.330.626.326.329.93141.1
HellaSwag (5-shot)69.125.26977.274.680.180.973.572.880.987.1
OpenBook QA (10-shot)79.272.272.679.877.68680.284.879.889.690
PIQA (5-shot)77.681.268.278.377.280.876.281.283.283.788.7
Social IQA (5-shot)72.578.268.373.975.375.377.671.873.474.782.9
TruthfulQA (MC2) (10-shot)66.475.159.262.964.369.46369.264.176.678.2
WinoGrande (5-shot)6765.653.259.863.371.163.164.765.47476.9

Multilingual

Phi-4 Mini-InsPhi-3.5-Mini-InsLlama-3.2-3B-InsMinistral-3BQwen2.5-3B-InsQwen2.5-7B-InsMinistral-8B-2410Llama-3.1-8B-InsLlama-3.1-Tulu-3-8BGemma 2-9B-ItGPT-4o-mini-2024-07-18
Multilingual MMLU (5-shot)49.351.848.146.455.964.453.756.254.563.872.9
MGSM (0-shot CoT)63.94749.644.653.564.558.356.758.675.181.7

Math

Phi-4 Mini-InsPhi-3.5-Mini-InsLlama-3.2-3B-InsMinistral-3BQwen2.5-3B-InsQwen2.5-7B-InsMinistral-8B-2410Llama-3.1-8B-InsLlama-3.1-Tulu-3-8BGemma 2-9B-ItGPT-4o-mini-2024-07-18
GSM8K (8-shot, CoT)88.676.975.680.180.688.781.982.484.384.991.3
MATH (0-shot, CoT)6449.846.741.861.760.441.647.646.151.370.2

Long Context

Phi-4 Mini-InsPhi-3.5-Mini-InsLlama-3.2-3B-InsMinistral-3BQwen2.5-3B-InsQwen2.5-7B-InsMinistral-8B-2410Llama-3.1-8B-InsLlama-3.1-Tulu-3-8BGemma 2-9B-ItGPT-4o-mini-2024-07-18
Qasper40.441.933.435.332.138.137.437.235.413.939.8
SQuALITY22.825.325.725.525.323.824.926.226.723.623.8

Instruction Following

Phi-4 Mini-InsPhi-3.5-Mini-InsLlama-3.2-3B-InsMinistral-3BQwen2.5-3B-InsQwen2.5-7B-InsMinistral-8B-2410Llama-3.1-8B-InsLlama-3.1-Tulu-3-8BGemma 2-9B-ItGPT-4o-mini-2024-07-18
IFEval70.150.66847.55969.552.574.177.373.280.1

Function Calling

Phi-4 Mini-InsPhi-3.5-Mini-InsLlama-3.2-3B-InsMinistral-3BQwen2.5-3B-InsQwen2.5-7B-InsMinistral-8B-2410Llama-3.1-8B-InsLlama-3.1-Tulu-3-8BGemma 2-9B-ItGPT-4o-mini-2024-07-18
BFCL70.366.178.661.474.281.3747759.459.983.3

Code Generation

Phi-4 Mini-InsPhi-3.5-Mini-InsLlama-3.2-3B-InsMinistral-3BQwen2.5-3B-InsQwen2.5-7B-InsMinistral-8B-2410Llama-3.1-8B-InsLlama-3.1-Tulu-3-8BGemma 2-9B-ItGPT-4o-mini-2024-07-18
HumanEval (0-shot)74.470.162.872727570.766.562.863.486.6
MBPP (3-shot)65.37067.265.165.376.368.969.463.969.684.1
Overall63.560.556.256.960.167.960.262.360.965.075.5

Overall, the model with only 3.8B-param achieves a similar level of multilingual language understanding and reasoning ability as much larger models. However, it is still fundamentally limited by its size for certain tasks. The model simply does not have the capacity to store too much factual knowledge, therefore, users may experience factual incorrectness. However, it may be possible to resolve such weakness by augmenting Phi-4 with a search engine, particularly when using the model under RAG settings.

Usage

Input Formats

Given the nature of the training data, the Phi-4-Mini-Instruct model is best suited for prompts using specific formats. Below are the two primary formats:

  1. Chat Format

    This format is used for general conversation and instructions:
<|system|>You are a helpful assistant.<|end|><|user|>How to explain Internet for a medieval knight?<|end|><|assistant|>
  1. Tool-Enabled Function Call Format

    This format is used when the user wants the model to provide function calls based on the given tools. The user should provide the available tools in the system prompt, wrapped by <|tool|> and <|/tool|> tokens. The tools should be specified in JSON format, using a JSON dump structure. For example:
<|system|>You are a helpful assistant with some tools.<|tool|>
[{"name": "get_weather_updates", "description": "Fetches weather updates for a given city using the RapidAPI Weather API.", "parameters": {"city": {"description": "The name of the city for which to retrieve weather information.", "type": "str", "default": "London"}}}]
<|/tool|><|end|><|user|>What is the weather like in Paris today?<|end|><|assistant|>

Loading the Model Locally

After obtaining the Phi-4-Mini-Instruct model checkpoints, users can use this sample code for inference.

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

torch.random.manual_seed(0)

model = AutoModelForCausalLM.from_pretrained(
    "microsoft/Phi-4-Mini-instruct", 
    device_map="cuda", 
    torch_dtype="auto", 
    trust_remote_code=True, 
)
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-4-Mini-instruct")

messages = [
    {"role": "system", "content": "You are a helpful AI assistant."},
    {"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"},
    {"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."},
    {"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"},
]

pipe = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
)

generation_args = {
    "max_new_tokens": 500,
    "return_full_text": False,
    "temperature": 0.0,
    "do_sample": False,
}

output = pipe(messages, **generation_args)
print(output[0]['generated_text'])

Inference:

Engine: vLLM

Test Hardware: NVIDIA L40S

Responsible AI Considerations

Like other language models, the Phi family of models can potentially behave in ways that are unfair, unreliable, or offensive. Some of the limiting behaviors to be aware of include:

  • Quality of Service: The Phi models are trained primarily on English text and some additional multilingual text. Languages other than English will experience worse performance as well as performance disparities across non-English. English language varieties with less representation in the training data might experience worse performance than standard American English.
  • Multilingual performance and safety gaps: We believe it is important to make language models more widely available across different languages, but the Phi 4 models still exhibit challenges common across multilingual releases. As with any deployment of LLMs, developers will be better positioned to test for performance or safety gaps for their linguistic and cultural context and customize the model with additional fine-tuning and appropriate safeguards.
  • Representation of Harms & Perpetuation of Stereotypes: These models can over- or under-represent groups of people, erase representation of some groups, or reinforce demeaning or negative stereotypes. Despite safety post-training, these limitations may still be present due to differing levels of representation of different groups, cultural contexts, or prevalence of examples of negative stereotypes in training data that reflect real-world patterns and societal biases.
  • Inappropriate or Offensive Content: These models may produce other types of inappropriate or offensive content, which may make it inappropriate to deploy for sensitive contexts without additional mitigations that are specific to the case.
  • Information Reliability: Language models can generate nonsensical content or fabricate content that might sound reasonable but is inaccurate or outdated.
  • Limited Scope for Code: The majority of Phi 4 training data is based in Python and uses common packages such as "typing, math, random, collections, datetime, itertools". If the model generates Python scripts that utilize other packages or scripts in other languages, it is strongly recommended that users manually verify all API uses.
  • Long Conversation: Phi 4 models, like other models, can in some cases generate responses that are repetitive, unhelpful, or inconsistent in very long chat sessions in both English and non-English languages. Developers are encouraged to place appropriate mitigations, like limiting conversation turns to account for the possible conversational drift.

Developers should apply responsible AI best practices, including mapping, measuring, and mitigating risks associated with their specific use case and cultural, linguistic context. Phi 4 family of models are general purpose models. As developers plan to deploy these models for specific use cases, they are encouraged to fine-tune the models for their use case and leverage the models as part of broader AI systems with language-specific safeguards in place. Important areas for consideration include:

  • Allocation: Models may not be suitable for scenarios that could have consequential impact on legal status or the allocation of resources or life opportunities (ex: housing, employment, credit, etc.) without further assessments and additional debiasing techniques.
  • High-Risk Scenarios: Developers should assess the suitability of using models in high-risk scenarios where unfair, unreliable or offensive outputs might be extremely costly or lead to harm. This includes providing advice in sensitive or expert domains where accuracy and reliability are critical (ex: legal or health advice). Additional safeguards should be implemented at the application level according to the deployment context.
  • Misinformation: Models may produce inaccurate information. Developers should follow transparency best practices and inform end-users they are interacting with an AI system. At the application level, developers can build feedback mechanisms and pipelines to ground responses in use-case specific, contextual information, a technique known as Retrieval Augmented Generation (RAG).
  • Generation of Harmful Content: Developers should assess outputs for their context and use available safety classifiers or custom solutions appropriate for their use case.
  • Misuse: Other forms of misuse such as fraud, spam, or malware production may be possible, and developers should ensure that their applications do not violate applicable laws and regulations.

Ethical Considerations:

Ethical considerations and guidelines. NVIDIA believes Trustworthy AI is a shared responsibility and we have established policies and practices to enable development for a wide array of AI applications. When downloaded or used in accordance with our terms of service, developers should work with their internal model team to ensure this model meets requirements for the relevant industry and use case and addresses unforeseen product misuse. Please report security vulnerabilities or NVIDIA AI Concerns here.