Model reference · open weights

phi-2

LLMs microsoft Text gen 1 build Open weights 1.5M dl/mo

phi-2 is an open-weight language model from microsoft. phi-2 (FP16) weighs 5.6 GB; the smallest configuration that runs it is RTX 3060 12 GB.

  • Phi-2 is a 2.8B parameter Transformer model developed by Microsoft for text generation tasks.
  • It supports a context length of 2048 tokens and is primarily designed for standard English.
  • The model is released under the MIT license.

Summary of the microsoft/phi-2 model card, 2026-10-01

What it is

Released bymicrosoft
Released2023-12-13
Parameters2.8B
VRAM5.6 GB for the weights

What it runs on

Memory and cards for phi-2 (FP16)

5.6 GBweights, file size
328 MBcache per 1K tokens
608 MBruntime overhead, at least
2,048 tokenscontext max
CardRequests at onceContext maxMemory
2K each
RTX 3060 12 GB8all 2K11.6 GB
RTX 4060 Ti 16 GB13all 2K15.4 GB
RTX 3090 24 GB25all 2K23.4 GB
RTX 4090 24 GB25all 2K23.4 GB
RTX 5090 32 GB37all 2K31.0 GB
L40S 48 GB56all 2K44.0 GB
A100 80 GB107all 2K78.2 GB
H100 80 GB102all 2K78.1 GB
RTX PRO 6000 Blackwell 96 GB126all 2K93.8 GB
DGX Spark (GB10) 128 GB unified146all 2K107 GB
H200 141 GB191all 2K138 GB
B200 180 GB248all 2K176 GB
Memory needed at each load
Requests at once2K tokens each
16.8 GB
59.5 GB
811.5 GB
1616.9 GB
3227.6 GB
6449.1 GB

One card, with vLLM's small-card settings.

From the model card

What microsoft says about phi-2

Read the model card

Model Summary

Phi-2 is a Transformer with 2.7 billion parameters. It was trained using the same data sources as Phi-1.5, augmented with a new data source that consists of various NLP synthetic texts and filtered websites (for safety and educational value). When assessed against benchmarks testing common sense, language understanding, and logical reasoning, Phi-2 showcased a nearly state-of-the-art performance among models with less than 13 billion parameters.

Our model hasn't been fine-tuned through reinforcement learning from human feedback. The intention behind crafting this open-source model is to provide the research community with a non-restricted small model to explore vital safety challenges, such as reducing toxicity, understanding societal biases, enhancing controllability, and more.

How to Use

Phi-2 has been integrated in the transformers version 4.37.0, please ensure that you are using a version equal or higher than it.

Phi-2 is known for having an attention overflow issue (with FP16). If you are facing this issue, please enable/disable autocast on the PhiAttention.forward() function.

Intended Uses

Given the nature of the training data, the Phi-2 model is best suited for prompts using the QA format, the chat format, and the code format.

QA Format:

You can provide the prompt as a standalone question as follows:

Write a detailed analogy between mathematics and a lighthouse.

where the model generates the text after "." . To encourage the model to write more concise answers, you can also try the following QA format using "Instruct: \nOutput:"

Instruct: Write a detailed analogy between mathematics and a lighthouse.
Output: Mathematics is like a lighthouse. Just as a lighthouse guides ships safely to shore, mathematics provides a guiding light in the world of numbers and logic. It helps us navigate through complex problems and find solutions. Just as a lighthouse emits a steady beam of light, mathematics provides a consistent framework for reasoning and problem-solving. It illuminates the path to understanding and helps us make sense of the world around us.

where the model generates the text after "Output:".

Chat Format:

Alice: I don't know why, I'm struggling to maintain focus while studying. Any suggestions?
Bob: Well, have you tried creating a study schedule and sticking to it?
Alice: Yes, I have, but it doesn't seem to help much.
Bob: Hmm, maybe you should try studying in a quiet environment, like the library.
Alice: ...

where the model generates the text after the first "Bob:".

Code Format:

def print_prime(n):
   """
   Print all primes between 1 and n
   """
   primes = []
   for num in range(2, n+1):
       is_prime = True
       for i in range(2, int(math.sqrt(num))+1):
           if num % i == 0:
               is_prime = False
               break
       if is_prime:
           primes.append(num)
   print(primes)

where the model generates the text after the comments.

Notes:

  • Phi-2 is intended for QA, chat, and code purposes. The model-generated text/code should be treated as a starting point rather than a definitive solution for potential use cases. Users should be cautious when employing these models in their applications.

  • Direct adoption for production tasks without evaluation is out of scope of this project. As a result, the Phi-2 model has not been tested to ensure that it performs adequately for any production-level application. Please refer to the limitation sections of this document for more details.

  • If you are using transformers<4.37.0, always load the model with trust_remote_code=True to prevent side-effects.

Sample Code

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

torch.set_default_device("cuda")

model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype="auto", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2", trust_remote_code=True)

inputs = tokenizer('''def print_prime(n):
   """
   Print all primes between 1 and n
   """''', return_tensors="pt", return_attention_mask=False)

outputs = model.generate(**inputs, max_length=200)
text = tokenizer.batch_decode(outputs)[0]
print(text)

Limitations of Phi-2

  • Generate Inaccurate Code and Facts: The model may produce incorrect code snippets and statements. Users should treat these outputs as suggestions or starting points, not as definitive or accurate solutions.

  • Limited Scope for code: Majority of Phi-2 training data is based in Python and use 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, we strongly recommend users manually verify all API uses.

  • Unreliable Responses to Instruction: The model has not undergone instruction fine-tuning. As a result, it may struggle or fail to adhere to intricate or nuanced instructions provided by users.

  • Language Limitations: The model is primarily designed to understand standard English. Informal English, slang, or any other languages might pose challenges to its comprehension, leading to potential misinterpretations or errors in response.

  • Potential Societal Biases: Phi-2 is not entirely free from societal biases despite efforts in assuring training data safety. There's a possibility it may generate content that mirrors these societal biases, particularly if prompted or instructed to do so. We urge users to be aware of this and to exercise caution and critical thinking when interpreting model outputs.

  • Toxicity: Despite being trained with carefully selected data, the model can still produce harmful content if explicitly prompted or instructed to do so. We chose to rel

Quoted from the model card on Hugging Face. The full card is behind the Hugging Face link above.

© 2026 AxForge · EU-hosted AI infrastructure Pricing Docs Trust Privacy Terms