Text Generation
Transformers.js
ONNX
Transformers
phi3
ONNX
ONNXRuntime
ONNXRuntimeWeb
nlp
conversational
custom_code
Instructions to use microsoft/Phi-3-mini-4k-instruct-onnx-web with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers.js
How to use microsoft/Phi-3-mini-4k-instruct-onnx-web with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('text-generation', 'microsoft/Phi-3-mini-4k-instruct-onnx-web'); - Transformers
How to use microsoft/Phi-3-mini-4k-instruct-onnx-web with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="microsoft/Phi-3-mini-4k-instruct-onnx-web", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct-onnx-web", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("microsoft/Phi-3-mini-4k-instruct-onnx-web", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use microsoft/Phi-3-mini-4k-instruct-onnx-web with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/Phi-3-mini-4k-instruct-onnx-web" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Phi-3-mini-4k-instruct-onnx-web", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/microsoft/Phi-3-mini-4k-instruct-onnx-web
- SGLang
How to use microsoft/Phi-3-mini-4k-instruct-onnx-web with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "microsoft/Phi-3-mini-4k-instruct-onnx-web" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Phi-3-mini-4k-instruct-onnx-web", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "microsoft/Phi-3-mini-4k-instruct-onnx-web" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Phi-3-mini-4k-instruct-onnx-web", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use microsoft/Phi-3-mini-4k-instruct-onnx-web with Docker Model Runner:
docker model run hf.co/microsoft/Phi-3-mini-4k-instruct-onnx-web
Fix typos in tags (case-sensitive)
Browse files
README.md
CHANGED
|
@@ -1,62 +1,62 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
pipeline_tag: text-generation
|
| 4 |
-
tags:
|
| 5 |
-
- ONNX
|
| 6 |
-
- ONNXRuntime
|
| 7 |
-
- ONNXRuntimeWeb
|
| 8 |
-
- phi3
|
| 9 |
-
-
|
| 10 |
-
-
|
| 11 |
-
- nlp
|
| 12 |
-
- conversational
|
| 13 |
-
- custom_code
|
| 14 |
-
inference: false
|
| 15 |
-
---
|
| 16 |
-
|
| 17 |
-
# Phi-3 Mini-4K-Instruct ONNX model for in-browser inference
|
| 18 |
-
|
| 19 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
| 20 |
-
Running Phi3-mini-4K entirely in the browser! Check out this [demo](https://guschmue.github.io/ort-webgpu/chat/index.html).
|
| 21 |
-
|
| 22 |
-
This repository hosts the optimized Web version of ONNX Phi-3-mini-4k-instruct model to accelerate inference in the browser with ONNX Runtime Web.
|
| 23 |
-
|
| 24 |
-
[The Phi-3-Mini-4K-Instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct) is a 3.8B parameters, lightweight, state-of-the-art open model trained with the Phi-3 datasets that includes both synthetic data and the filtered publicly available websites data with a focus on high-quality and reasoning dense properties. When assessed against benchmarks testing common sense, language understanding, math, code, long context and logical reasoning, Phi-3 Mini-4K-Instruct showcased a robust and state-of-the-art performance among models with less than 13 billion parameters.
|
| 25 |
-
|
| 26 |
-
## How to run
|
| 27 |
-
|
| 28 |
-
[ONNX Runtime Web](https://onnxruntime.ai/docs/tutorials/web/build-web-app.html) is a JavaScript library to enable web developers to deploy machine learning models directly in web browsers, offering multiple backends leveraging hardware acceleration. WebGPU backend is recommended to run Phi-3-mini efficiently.
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
Here is an [E2E example](https://github.com/microsoft/onnxruntime-inference-examples/tree/main/js/chat) for running this optimized Phi3-mini-4K for the web, with ONNX Runtime harnessing WebGPU.
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
**Supported devices and browser with WebGPU**: Chrome 113+ and Edge 113+ for Mac, Windows, ChromeOS, and Chrome 121+ for Android. Pls visit [here](https://github.com/gpuweb/gpuweb/wiki/Implementation-Status#safari-in-progress) for tracking WebGPU support in browsers
|
| 35 |
-
|
| 36 |
-
## Performance Metrics
|
| 37 |
-
Performance vary between GPUs. The more powerful the GPU, the faster the speed. On a NVIDIA GeForce RTX 4090: ~42 tokens/second
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
## Additional Details
|
| 41 |
-
|
| 42 |
-
To obtain other optimized Phi3-mini-4k ONNX models for server platforms, Windows, Linux, Mac desktops, and mobile, please visit [Phi-3-mini-4k-instruct onnx model](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx). The model differences in the web version compared to other versions:
|
| 43 |
-
|
| 44 |
-
1. the model is fp16 with int4 block quantization for weights
|
| 45 |
-
2. the 'logits' output is fp32
|
| 46 |
-
3. the model uses MHA instead of GQA
|
| 47 |
-
4. onnx and external data file need to stay below 2GB to be cacheable in chromium
|
| 48 |
-
|
| 49 |
-
To optimize a fine-tuned Phi3-mini-4k model to run with ONNX Runtime Web, please follow [this Olive example](https://github.com/microsoft/Olive/tree/main/examples/phi3). [Olive](https://github.com/microsoft/OLive) is an easy-to-use model optimization tool for generating an optimized ONNX model to efficiently run with ONNX Runtime across platforms.
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
## Model Description
|
| 53 |
-
|
| 54 |
-
- **Developed by:** Microsoft
|
| 55 |
-
- **Model type:** ONNX
|
| 56 |
-
- **Inference Language(s) (NLP):** JavaScript
|
| 57 |
-
- **License:** MIT
|
| 58 |
-
- **Model Description:** This is the web version of the Phi-3 Mini-4K-Instruct model for ONNX Runtime inference.
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
## Model Card Contact
|
| 62 |
-
guschmue, qining
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
pipeline_tag: text-generation
|
| 4 |
+
tags:
|
| 5 |
+
- ONNX
|
| 6 |
+
- ONNXRuntime
|
| 7 |
+
- ONNXRuntimeWeb
|
| 8 |
+
- phi3
|
| 9 |
+
- transformers.js
|
| 10 |
+
- transformers
|
| 11 |
+
- nlp
|
| 12 |
+
- conversational
|
| 13 |
+
- custom_code
|
| 14 |
+
inference: false
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Phi-3 Mini-4K-Instruct ONNX model for in-browser inference
|
| 18 |
+
|
| 19 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
| 20 |
+
Running Phi3-mini-4K entirely in the browser! Check out this [demo](https://guschmue.github.io/ort-webgpu/chat/index.html).
|
| 21 |
+
|
| 22 |
+
This repository hosts the optimized Web version of ONNX Phi-3-mini-4k-instruct model to accelerate inference in the browser with ONNX Runtime Web.
|
| 23 |
+
|
| 24 |
+
[The Phi-3-Mini-4K-Instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct) is a 3.8B parameters, lightweight, state-of-the-art open model trained with the Phi-3 datasets that includes both synthetic data and the filtered publicly available websites data with a focus on high-quality and reasoning dense properties. When assessed against benchmarks testing common sense, language understanding, math, code, long context and logical reasoning, Phi-3 Mini-4K-Instruct showcased a robust and state-of-the-art performance among models with less than 13 billion parameters.
|
| 25 |
+
|
| 26 |
+
## How to run
|
| 27 |
+
|
| 28 |
+
[ONNX Runtime Web](https://onnxruntime.ai/docs/tutorials/web/build-web-app.html) is a JavaScript library to enable web developers to deploy machine learning models directly in web browsers, offering multiple backends leveraging hardware acceleration. WebGPU backend is recommended to run Phi-3-mini efficiently.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Here is an [E2E example](https://github.com/microsoft/onnxruntime-inference-examples/tree/main/js/chat) for running this optimized Phi3-mini-4K for the web, with ONNX Runtime harnessing WebGPU.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
**Supported devices and browser with WebGPU**: Chrome 113+ and Edge 113+ for Mac, Windows, ChromeOS, and Chrome 121+ for Android. Pls visit [here](https://github.com/gpuweb/gpuweb/wiki/Implementation-Status#safari-in-progress) for tracking WebGPU support in browsers
|
| 35 |
+
|
| 36 |
+
## Performance Metrics
|
| 37 |
+
Performance vary between GPUs. The more powerful the GPU, the faster the speed. On a NVIDIA GeForce RTX 4090: ~42 tokens/second
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
## Additional Details
|
| 41 |
+
|
| 42 |
+
To obtain other optimized Phi3-mini-4k ONNX models for server platforms, Windows, Linux, Mac desktops, and mobile, please visit [Phi-3-mini-4k-instruct onnx model](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx). The model differences in the web version compared to other versions:
|
| 43 |
+
|
| 44 |
+
1. the model is fp16 with int4 block quantization for weights
|
| 45 |
+
2. the 'logits' output is fp32
|
| 46 |
+
3. the model uses MHA instead of GQA
|
| 47 |
+
4. onnx and external data file need to stay below 2GB to be cacheable in chromium
|
| 48 |
+
|
| 49 |
+
To optimize a fine-tuned Phi3-mini-4k model to run with ONNX Runtime Web, please follow [this Olive example](https://github.com/microsoft/Olive/tree/main/examples/phi3). [Olive](https://github.com/microsoft/OLive) is an easy-to-use model optimization tool for generating an optimized ONNX model to efficiently run with ONNX Runtime across platforms.
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
## Model Description
|
| 53 |
+
|
| 54 |
+
- **Developed by:** Microsoft
|
| 55 |
+
- **Model type:** ONNX
|
| 56 |
+
- **Inference Language(s) (NLP):** JavaScript
|
| 57 |
+
- **License:** MIT
|
| 58 |
+
- **Model Description:** This is the web version of the Phi-3 Mini-4K-Instruct model for ONNX Runtime inference.
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
## Model Card Contact
|
| 62 |
+
guschmue, qining
|