Text Generation
Transformers
Safetensors
multilingual
phi3_v
nlp
code
vision
conversational
custom_code
Instructions to use microsoft/Phi-3-vision-128k-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Phi-3-vision-128k-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="microsoft/Phi-3-vision-128k-instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-3-vision-128k-instruct", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use microsoft/Phi-3-vision-128k-instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/Phi-3-vision-128k-instruct" # 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-vision-128k-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/microsoft/Phi-3-vision-128k-instruct
- SGLang
How to use microsoft/Phi-3-vision-128k-instruct 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-vision-128k-instruct" \ --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-vision-128k-instruct", "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-vision-128k-instruct" \ --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-vision-128k-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use microsoft/Phi-3-vision-128k-instruct with Docker Model Runner:
docker model run hf.co/microsoft/Phi-3-vision-128k-instruct
Commit ·
ff0d44e
1
Parent(s): bfc0c05
update readme regarding FA2
Browse files
README.md
CHANGED
|
@@ -105,7 +105,7 @@ from transformers import AutoProcessor
|
|
| 105 |
|
| 106 |
model_id = "microsoft/Phi-3-vision-128k-instruct"
|
| 107 |
|
| 108 |
-
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="cuda", trust_remote_code=True, torch_dtype="auto")
|
| 109 |
|
| 110 |
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
| 111 |
|
|
@@ -217,24 +217,6 @@ Note that by default, the Phi-3-Vision-128K model uses flash attention, which re
|
|
| 217 |
* NVIDIA A6000
|
| 218 |
* NVIDIA H100
|
| 219 |
|
| 220 |
-
### Running on Windows or without flash attention
|
| 221 |
-
To enable the model on these enviroment here are steps that you may consider to follow:
|
| 222 |
-
|
| 223 |
-
Step 1: comment flash attention import code in modeling_phi3_v.py from line 52 to line 56.
|
| 224 |
-
```python
|
| 225 |
-
# if is_flash_attn_2_available():
|
| 226 |
-
# from flash_attn import flash_attn_func, flash_attn_varlen_func
|
| 227 |
-
# from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input # noqa
|
| 228 |
-
|
| 229 |
-
# _flash_supports_window_size = "window_size" in list(inspect.signature(flash_attn_func).parameters)
|
| 230 |
-
```
|
| 231 |
-
|
| 232 |
-
Step 2: change _"_attn_implementation"_ from _"flash_attention_2"_ to _"eager"_ in config.json or disable flash attention when you create the model as below.
|
| 233 |
-
|
| 234 |
-
```python
|
| 235 |
-
model = AutoModelForCausalLM.from_pretrained('microsoft/Phi-3-vision-128k-instruct', device_map="cuda", trust_remote_code=True, torch_dtype="auto", _attn_implementation="eager")
|
| 236 |
-
```
|
| 237 |
-
|
| 238 |
## License
|
| 239 |
|
| 240 |
The model is licensed under the [MIT license](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct/resolve/main/LICENSE).
|
|
|
|
| 105 |
|
| 106 |
model_id = "microsoft/Phi-3-vision-128k-instruct"
|
| 107 |
|
| 108 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="cuda", trust_remote_code=True, torch_dtype="auto", attn_implementation='eager') # use attn_implementation='flash_attention_2' to enable flash attention
|
| 109 |
|
| 110 |
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
| 111 |
|
|
|
|
| 217 |
* NVIDIA A6000
|
| 218 |
* NVIDIA H100
|
| 219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
## License
|
| 221 |
|
| 222 |
The model is licensed under the [MIT license](https://huggingface.co/microsoft/Phi-3-vision-128k-instruct/resolve/main/LICENSE).
|