Mindket

phi-2

Newversion 1 · updated

Overview

A small text generation model that answers questions, continues chat dialogue and completes code. Made for researchers and developers who want a compact open model for safety studies and experiments.

phi-2 is a kit in the Developer category, listed by Mindket. It is free. This is version 1, last updated on . Download it on this page, a zip of its files. Nothing in it runs by itself.

At a glance

You need
  • Python with a recent transformers library and torch
  • About 5.6 GB of disk space for the F16 weights, or about 1.4 GB at 4-bit as an estimate
  • A GPU for the card's sample code
Runs in
  • Python scripts using the transformers library, version 4.37.0 or higher
  • Windows, macOS and Linux
  • A GPU, since the card's sample code sets cuda as the default device
Start with
pip install -U huggingface_hub
hf download microsoft/phi-2

Platform

WindowsOperating system
macOSOperating system
LinuxOperating system

About

What it is

Phi-2 is a small Transformer language model from Microsoft with about 2.7 billion parameters. It writes text from a prompt, in question and answer, chat or code layouts. It was trained on the same data as Phi-1.5 plus synthetic NLP texts and filtered websites. It has not been tuned with reinforcement learning from human feedback.

Who it suits

It suits researchers and developers who want a small, unrestricted model to study toxicity, bias and controllability, or to test ideas on modest hardware.

IndustryWho uses itHow they use itExample
AI safety researchResearch teamsStudy toxicity, societal bias and controllability on a small open modelProbing how the model reacts to risky prompts
EducationTeachers and studentsRun a small model locally to see how prompting worksTrying question, chat and code prompts side by side
SoftwareDevelopersPrototype code completion or question answeringCompleting a Python function from its comment

Skip it for production work, since the card says it was not tested for any production-level application.

Where to use it

  • Python scripts using the transformers library, version 4.37.0 or higher
  • Windows, macOS and Linux
  • A GPU, since the card's sample code sets cuda as the default device
Use caseWhoWhat they get back
Question answeringResearchersA written answer after the question
Chat continuationDevelopersThe next reply in a dialogue
Code completionDevelopersA function body after the comment

How to set it up

  • Python with a recent transformers library and torch
  • About 5.6 GB of disk space for the F16 weights, or about 1.4 GB at 4-bit as an estimate
  • A GPU for the card's sample code
  1. Install the Hugging Face tools.
  2. Download the model files, or let the sample code fetch them.
  3. Run the sample code, or write your own prompt in one of the three formats.
pip install -U huggingface_hub
hf download microsoft/phi-2

How to use it

You write a prompt in the question, chat or code layout, and the model continues the text. For shorter answers, use the Instruct and Output layout. The card warns that an FP16 attention overflow can occur, and says older transformers versions need trust_remote_code set to True.

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)

outputs = model.generate(**inputs, max_length=200)
text = tokenizer.batch_decode(outputs)[0]
print(text)
FormatWhat it does
QuestionA standalone question, with the answer written after it
Instruct and OutputAsks for a more concise answer after the Output label
ChatNames like Alice and Bob, and the model writes the next reply
CodeA function signature and comment, and the model writes the body

Example

You ask the model to compare mathematics to a lighthouse, using the Instruct line and an empty Output line. It continues after the Output label with a short written comparison. Treat the result as a starting point and check it yourself.

For newcomers and experts

Phi-2 is a small model that continues whatever text you start. A good first try is the card's lighthouse prompt, and then a short chat between two named people to see how it carries on.

If you know the field, this is a base-style Transformer without reinforcement learning from human feedback. That makes it a plain research subject for safety work. Expect the FP16 attention overflow the card describes, and expect its limits on accuracy for both code and facts.

  1. Write a prompt in one of three formats
  2. Tokenizer turns it into input
  3. The model generates new tokens
  4. Decode the tokens into text
  5. Check the result yourself

Good to know

  • Accuracy: the model can produce wrong code and wrong statements, so treat output as a starting point.
  • Production: the card puts direct production use without evaluation out of scope.
  • Version: the card says transformers 4.37.0 or higher.
  • License: MIT.
  • Cost to run: none named.
  • Data it reaches: it downloads model files from Hugging Face and works on the text you give it.
  • Not for: production use without evaluation, or any reliance on its answers as definitive.

README and files

README

phi-2

A small text generation model that answers questions, continues chat dialogue and completes code. Made for researchers and developers who want a compact open model for safety studies and experiments.

Made by microsoft on Hugging Face. These notes are Mindket's, written from its model page and model card; the model's own files and license are on Hugging Face.

About

What it is: Phi-2 is a small Transformer language model from Microsoft with about 2.7 billion parameters. It writes text from a prompt, in question and answer, chat or code layouts. It was trained on the same data as Phi-1.5 plus synthetic NLP texts and filtered websites. It has not been tuned with reinforcement learning from human feedback.

Who it suits: It suits researchers and developers who want a small, unrestricted model to study toxicity, bias and controllability, or to test ideas on modest hardware.

Industry | Who uses it | How they use it | Example
AI safety research | Research teams | Study toxicity, societal bias and controllability on a small open model | Probing how the model reacts to risky prompts
Education | Teachers and students | Run a small model locally to see how prompting works | Trying question, chat and code prompts side by side
Software | Developers | Prototype code completion or question answering | Completing a Python function from its comment

Skip it for production work, since the card says it was not tested for any production-level application.

Where to use it:

  • Python scripts using the transformers library, version 4.37.0 or higher
  • Windows, macOS and Linux
  • A GPU, since the card's sample code sets cuda as the default device
Use case | Who | What they get back
Question answering | Researchers | A written answer after the question
Chat continuation | Developers | The next reply in a dialogue
Code completion | Developers | A function body after the comment

How to set it up:

  • Python with a recent transformers library and torch
  • About 5.6 GB of disk space for the F16 weights, or about 1.4 GB at 4-bit as an estimate
  • A GPU for the card's sample code
  1. Install the Hugging Face tools.
  2. Download the model files, or let the sample code fetch them.
  3. Run the sample code, or write your own prompt in one of the three formats.
pip install -U huggingface_hub
hf download microsoft/phi-2

How to use it: You write a prompt in the question, chat or code layout, and the model continues the text. For shorter answers, use the Instruct and Output layout. The card warns that an FP16 attention overflow can occur, and says older transformers versions need trust_remote_code set to True.

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)

outputs = model.generate(**inputs, max_length=200)
text = tokenizer.batch_decode(outputs)[0]
print(text)
Format | What it does
Question | A standalone question, with the answer written after it
Instruct and Output | Asks for a more concise answer after the Output label
Chat | Names like Alice and Bob, and the model writes the next reply
Code | A function signature and comment, and the model writes the body

Example: You ask the model to compare mathematics to a lighthouse, using the Instruct line and an empty Output line. It continues after the Output label with a short written comparison. Treat the result as a starting point and check it yourself.

For newcomers and experts: Phi-2 is a small model that continues whatever text you start. A good first try is the card's lighthouse prompt, and then a short chat between two named people to see how it carries on.

If you know the field, this is a base-style Transformer without reinforcement learning from human feedback. That makes it a plain research subject for safety work. Expect the FP16 attention overflow the card describes, and expect its limits on accuracy for both code and facts.

Write a prompt in one of three formats
Tokenizer turns it into input
The model generates new tokens
Decode the tokens into text
Check the result yourself

Good to know:

  • Accuracy: the model can produce wrong code and wrong statements, so treat output as a starting point.
  • Production: the card puts direct production use without evaluation out of scope.
  • Version: the card says transformers 4.37.0 or higher.
  • License: MIT.
  • Cost to run: none named.
  • Data it reaches: it downloads model files from Hugging Face and works on the text you give it.
  • Not for: production use without evaluation, or any reliance on its answers as definitive.

On Hugging Face, 13 November 2026

  • Task: text generation
  • Library: transformers
  • Parameters: 2.8B
  • Weights: about 5.6 GB in F16; about 1.4 GB at 4-bit (estimate)
  • Formats: Safetensors
  • Downloads in the last 30 days: 182,126
  • Likes: 3,536
  • License: mit
  • Languages: en
  • Quantized versions: 64
  • Fine-tunes: 416
  • Tags: transformers, safetensors, text-generation, code

Links

Get the model

Download its files with Hugging Face's command line:

pip install -U huggingface_hub
hf download microsoft/phi-2

Then follow the usage in its model card. Nothing in this kit runs by itself.

Files
README.md  5 KB

1 file, 5 KB, downloaded as a zip.

What’s new

  • Version 1 · 2026-11-13

Compare with similar

Listed Hugging Face models in the same category that share the most tags with this one.

ProductDownloads, last 30 daysLikesParametersLicenseLast change
phi-2 This page182,1263,5362.8Bmit
Qwen2.5-Coder-14B-InstructShares code · text-generation · transformers1,860,32721414.8Bapache-2.0
Qwen2.5-Coder-7B-InstructShares code · text-generation · transformers1,505,9998727.6Bapache-2.0
Qwen2.5-Coder-32B-InstructShares code · text-generation · transformers546,5832,21132.8Bapache-2.0
Qwen2.5-Coder-7BShares code · text-generation · transformers334,2462007.6Bapache-2.0
Phi-4-mini-instructShares code · text-generation · transformers332,4578883.8Bmit
Numbers as Mindket last read them, from 2026-11-12 to 2026-11-13.

Reviews

No ratings yet

Write a review

No reviews yet.

What people say

Posts and comments that name this project on Hacker News, Bluesky, X, Reddit, Facebook and YouTube, found by a weekly search and on Trendshift. Mindket doesn’t write or check them. Open one to read it where it was posted.

regularfryMicrosoft Phi-2 model changes licence to MIT240 points · 90 repliesgenai-podcast.bsky.social🎧 EP075: Microsoft Phi Beats Giants With Synthetic Textbooks 🔗 https://www.microsoft.com/en-us/research/blog/phi-2-the-surprising-power-of-small-language-models/ 🟢 https://podcasters.spotify.com/pod/show/yun-wu/episodes/EP075-Microsoft-Phi-Beats-Giants-With-Synthetic-Textbooks-e3fnllo #GenAI #AImjirvMicrosoft releases Phi-2, a small model that outperforms Llama 2, Mistral 7B20 points · 1 replytoshMicrosoft Releases Phi-27 points · 6 repliesthunderbongMicrosoft releases Phi-2, a powerful small language model AI2 points · 1 replywebmavenMicrosoft releases Phi-2, a small language model2 pointstaklaxbrShow HN: I'm 15. I built an offline AI Terminal Agent that fixes errorsHi HN I'm a 15 year old developer from Turkey. I previously shared an earlier version, but today I'm releasing ZAI Shell v7.0 (Agent Edition), which is a massive overhaul. I built this because I was frustrated with existing AI CLI tools that break easily or require complex setups. What makes v7.0…BramVanroyFietje: An open and efficient LLM for DutchFietje is an adapated version of microsoft/phi-2, tailored to Dutch text generation by training on 28B tokens. It is small and efficient with a size of 2.7 billion parameters while performing almost on par with more powerful Dutch LLMs of twice its size like GEITje 7B Ultra. In some benchmarks it…r-k-joLlm.c – LLM training in simple, pure C/CUDAYou can also target WASM. Depending on the model size, it can be really good. Here are some examples of quantized models. Vision Model https://huggingface.co/spaces/radames/Candle-Moondream-2 Blip Image Captioning https://huggingface.co/spaces/radames/Candle-BLIP-Image-Capt... Microsoft Phi 2…

Searched

More from Mindket

See all from Mindket

upscaler

uwg · Kit

Holds a set of image upscaling models gathered from the OpenModelDB community, for people who want to enlarge low-resolution pictures with AI on their own comp…

New

Pixel Art XL

nerijs · Kit

A pixel art style add-on for Stable Diffusion XL that turns text prompts into pixel-style images, with an optional LCM LoRA for faster runs. For game makers, d…

New

VibeVoice-1.5B

microsoft · Kit

Turns written conversations into spoken audio with up to four speakers and about 90 minutes of speech, an open Microsoft text-to-speech model for research on p…

New

Similar in Developer

See all in Developer

voicetut-egyptian-tashkeel

masterofaudio2077 · Kit

Reads Egyptian Arabic text aloud and follows the short vowel marks you write into it. A fine-tune of VoiceTut-TTS that keeps its 19 built-in voices and voice c…

New

Runs Meta's Llama 3.1 8B Instruct chat model in 4-bit AWQ form, so it fits on a GPU with about 4 GiB of free memory for the weights. For developers who want a…

New

Ru-Jev

besktech · Kit

Scores a Russian-first decision from a context and a list of options, giving a probability for yes/no, choice or rating questions. Runs on a plain CPU, for tea…

New