alt.freeweights.phi / phi-2-pytdml
From: microsoft <huggingface.co/microsoft>Newsgroups: alt.freeweights.phiSubject:

phi-2-pytdml

Date: 2026-11-15Commit: 87836f0Signed: 2DC28CC7B26A283B ✓

Text generation model with 2.8B parameters. Safetensors weights, 11.1 GB in all. Published by microsoft under MIT.

2.8B params11.1GBphi-2-pytdmlsafetensorspermissive
FactsParams2.8BSize11.1 GBFormatssafetensorsTasktext generationLicenseMITFrom sourcepermissive
$ fw get microsoft/phi-2-pytdml
# manifest sha256 b845cdbe9bfe… · 11.1 GB · 18 files
$ fw verify ./phi-2-pytdml microsoft/phi-2-pytdml
From sourceHosted (signed)microsoft/phi-2-pytdmlLast check: 2026-11-15 03:56 UTC

Get help: custom fine-tune or private deploy. We review your setup before we quote.

Works with

Overview

Size
11.1 GB
Weights
5.56 GB (safetensors)
Parameters
2.8B
Formats
safetensors
Task
text generation
License
MIT (permissive)
Files
18, each with a sha256
Publisher
microsoft
Added
2026-11-15
Section
alt.freeweights.phi
Lineage

Original release from the publisher.

Where these bytes come from
Publisher at the pinned commit→You

Sources are tried in order. A file counts only when its size and sha256 match the manifest. Sources are checked when you ask for them, not on a timer.

Sources
BadgeHostLast checkResult
From sourcehuggingface.co2026-11-15 03:56 UTCpassed

Model card

From the publisher at commit 87836f0. Shown as plain text with links; images open at the publisher.

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.

PyTorch DirectML Changes#

This model has been optimized by refining the scripts for enhanced DirectML (DML) performance. The optimization process includes simplifying the implementation and incorporating operator fusions to accelerate model inference. These optimized versions are hosted in the samples on the DirectML GitHub. Despite the changes, the original model checkpoints remain compatible, though some weights need updates to align with the new transformations.

Fused Operators for DML#
  • apply_rotary_position_emb
  • multi_head_attention
  • mlp_phi2

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: \<prompt\>\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 release the model to help the open-source community develop the most effective ways to reduce the toxicity of a model directly after pretraining.
  • Verbosity: Phi-2 being a base model often produces irrelevant or extra text and responses following its first answer to user prompts within a single turn. This is due to its training dataset being primarily textbooks, which results in textbook-like responses.

Training#

Model#
  • Architecture: a Transformer-based model with next-word prediction objective
  • Context length: 2048 tokens
  • Dataset size: 250B tokens, combination of NLP synthetic data created by AOAI GPT-3.5 and filtered web data from Falcon RefinedWeb and SlimPajama, which was assessed by AOAI GPT-4.
  • Training tokens: 1.4T tokens
  • GPUs: 96xA100-80G
  • Training time: 14 days
Software#
License#

The model is licensed under the MIT license.

Trademarks#

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft’s Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party’s policies.

Files

18 files · 11.1 GBWeights 5.56 GB (safetensors). Sizes and sha256 from the signed manifest.
Hide all 18 files with their sha256
FileSizesha256
.gitattributes1.52 KB11ad7efa24975ee4b0c3c3a38ed18737f0658a5f75a0a96787b576a78a023361
CODE_OF_CONDUCT.md444 B9daeae709a0bd71bcfd1c96dc5822ecec5210327eff929da64b0ae7f8faf1444
LICENSE1.08 KBfa8235e5b48faca34e3ca98cf4f694ef08bd216d28b58071a1f85b1d50cb814d
NOTICE.md1.77 KB6ac541192c253d21cd16a597ce69c515868e031db3f32f75d996b993b5aca216
README.md8.37 KB3a4e20a11cc526e5cbc712b25a9404a905aa30436d23762dda38aa248af6368e
SECURITY.md2.66 KB7b6976eec43edfa68b79a459dd089c56b7a395916dbf1a01bd11e6d86e12128f
added_tokens.json1.08 KBeca8e90d1be6af3afeb1a37f070f9492645c551a9fb2e1ce2a4a8b21f04ffc8b
config.json735 Bfbd955b298fdbd35fb81b3350a0d68d12616da7b7e9d81397ef632038ccc1111
generation_config.json124 Bff2cfaa2f4c36c6ef17614096093e3b49c9efe6ddfd6cf20a50de5104ee2d1ed
merges.txt456 KB1ce1664773c50f3e0cc8842619a93edc4624525b728b188a9e0be33b7726adc5
model-00001-of-00002.safetensors5.00 GB7fbcdefa72edf7527bf5da40535b57d9f5bd3d16829b94a9d25d2b457df62e84
model-00002-of-00002.safetensors564 MB17b98759e4b7953cbcf63ec49be7edbc9b863b57c207d84a52f5d2f5bcfcf6b4
model.pth5.56 GBba97c47bf9dd8f44244f12f8b46ff26f57351f930860f6304395bfa8f7bbba16
model.safetensors.index.json35.7 KB0c77ac4c30d55a7ef763fd224cbc0073c0d808562fa682ba439265c2f3fea730
special_tokens_map.json99 B6f50ab5a5a509a1c309d6171f339b196a900dc9c99ad0408ff23bb615fdae7ad
tokenizer.json2.11 MB337da36be7a71a6e88aa9148967a7bc8736f4b47c7de8e19ba92b89e80734cfc
tokenizer_config.json7.34 KB1906c7514a738bd743a05d7d95c8e9aeddb4d8c9ffdda4fb6ee05653fb6b97c4
vocab.json798 KB3ba3c3109ff33976c4bd966589c11ee14fcaa1f4c9e5e154c2ed7f99d80709e7
VersionsEach time the pinned upstream commit or file list changed in this repo. Newest first.
Upstream commitDateContents
87836f04b7 pinned now2026-11-15 03:56 UTC18 files · 11.1 GB

Use it

$ fw get microsoft/phi-2-pytdml
# manifest sha256 b845cdbe9bfe… · 11.1 GB · 18 files
$ fw verify ./phi-2-pytdml microsoft/phi-2-pytdml
fw.pyChecks the signature and every sha256, tries each source in order, resumes.
$ python3 fw.py get https://freeweights.allternit.com/manifests/microsoft/phi-2-pytdml.json --dir ./phi-2-pytdml $ python3 fw.py verify ./phi-2-pytdml ./microsoft__phi-2-pytdml.json
hfThe Hugging Face CLI with one setting. Same repo id.
$ HF_ENDPOINT=https://freeweights.allternit.com hf download microsoft/phi-2-pytdml --revision 87836f04b732c91f2aeac0d94c6a6ad8ecd5f994 --local-dir ./phi-2-pytdml
transformersLoad the weights in Python.
import os os.environ["HF_ENDPOINT"] = "https://freeweights.allternit.com" from transformers import AutoModelForCausalLM, AutoTokenizer tok = AutoTokenizer.from_pretrained("microsoft/phi-2-pytdml", revision="87836f04b732c91f2aeac0d94c6a6ad8ecd5f994") model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2-pytdml", revision="87836f04b732c91f2aeac0d94c6a6ad8ecd5f994", device_map="auto")
vLLMServe an OpenAI-compatible API.
$ HF_ENDPOINT=https://freeweights.allternit.com vllm serve microsoft/phi-2-pytdml --revision 87836f04b732c91f2aeac0d94c6a6ad8ecd5f994

License

Name
MIT License
Id
MIT
Class
Permissive
Redistribution
yes
Listing
Hosted (signed)
Decided
License as declared by the publisher. No person read it. 2026-11-15
Text in
LICENSE
Text sha256
fa8235e5b48faca34e3ca98cf4f694ef08bd216d28b58071a1f85b1d50cb814d
Terms gate
No extra terms beyond the license.

Read the license text

Licenses are checked against the license table. A custom license passes only after a person reads it.

Provenance

From: microsoft <huggingface.co/microsoft>Newsgroups: alt.freeweights.phiSubject: phi-2-pytdmlDate: 2026-11-15Commit: 87836f0Signed: 2DC28CC7B26A283B ✓
Upstream
microsoft/phi-2-pytdml
Pinned commit
87836f04b732c91f2aeac0d94c6a6ad8ecd5f994
Manifest
phi-2-pytdml.json · .minisig
Manifest sha256
b845cdbe9bfe7f9a768f7c26afb3d537d0e3025d17f4d2ff2fc9d65818ee65c8
Signature
minisign, Ed25519, key 2DC28CC7B26A283B
Created
2026-11-15 03:56 UTC
Generator
freeweights-manifest/0.1.0
Takedowns
None.

How to verify

$ curl -O https://freeweights.allternit.com/manifests/microsoft/phi-2-pytdml.json $ curl -O https://freeweights.allternit.com/manifests/microsoft/phi-2-pytdml.json.minisig $ minisign -Vm phi-2-pytdml.json -P RWQ7KGqyx4zCLXtUFOqvfv8L3g+8fpKJ1FsuxPyOYMF+4KufbUxKq1Oq $ shasum -a 256 <file> # compare with the Files tab

A manifest whose signature fails must be rejected. A file whose size or sha256 does not match must be discarded. Verify a download

Model tree

No related models in this catalog.Nothing here lists this model as its parent, and it names no parent.
Get it
Download
$ HF_ENDPOINT=https://freeweights.allternit.com hf download microsoft/phi-2-pytdml
Open in Freeweights Studio

Pull, verify and run it in the Allternit app on Desktop, web or phone.

Signed manifest
minisign, key 2DC28CC7B26A283B. phi-2-pytdml.json. Provenance. Takedown history: none.
From: BAAI <huggingface.co/BAAI>Subject: bunny-phi-2-siglip-lora
From: microsoft <huggingface.co/microsoft>Subject: MediPhi
From: microsoft <huggingface.co/microsoft>Subject: MediPhi-Clinical
From: microsoft <huggingface.co/microsoft>Subject: MediPhi-Guidelines
From: microsoft <huggingface.co/microsoft>Subject: MediPhi-Instruct
From: microsoft <huggingface.co/microsoft>Subject: MediPhi-MedCode