Phi-3 ONNX models are hosted on HuggingFace and you can run them with the ONNX Runtime generate() API.
The mini (3.3B) and medium (14B) versions available now, with support. Both mini and medium have a short (4k) context version and a long (128k) context version. The long context version can accept much longer prompts and produce longer output text, but it does consume more memory.
This tutorial downloads and runs the short context (4k) mini (3B) model variant. See the [model reference](#phi-3-onnx-model-reference) for download commands for the other variants.
HuggingFace uses `git` for version control. To download the ONNX models you need `git lfs` to be installed, if you do not already have it.
* Windows: `winget install -e --id GitHub.GitLFS` (If you don't have winget, download and run the `exe` from the [official source](https://docs.github.com/en/repositories/working-with-files/managing-large-files/installing-git-large-file-storage?platform=windows))
* Linux: `apt-get install git-lfs`
* MacOS: `brew install git-lfs`
Then run `git lfs install`
2. Install the HuggingFace CLI
```bash
pip install huggingface-hub[cli]
```
## Choose your platform
Are you on a Windows machine with GPU?
* I don't know → Review [this guide](https://www.microsoft.com/en-us/windows/learning-center/how-to-check-gpu) to see whether you have a GPU in your Windows machine.
* Yes → Follow the instructions for [DirectML](#run-with-directml).
* No → Do you have an NVIDIA GPU?
* I don't know → Review [this guide](https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html#verify-you-have-a-cuda-capable-gpu) to see whether you have a CUDA-capable GPU.
* Yes → Follow the instructions for [NVIDIA CUDA GPU](#run-with-nvidia-cuda).
* No → Follow the instructions for [CPU](#run-on-cpu).
**Note: Only one package and model is required based on your hardware. That is, only execute the steps for one of the following sections**
Once the script has loaded the model, it will ask you for input in a loop, streaming the output as it is produced the model. For example:
```bash
Input: Tell me a joke about GPUs
Certainly! Here\'s a light-hearted joke about GPUs:
Why did the GPU go to school? Because it wanted to improve its "processing power"!
This joke plays on the double meaning of "processing power," referring both to the computational abilities of a GPU and the idea of a student wanting to improve their academic skills.