Skip to content

Commit 25df055

Browse files
Merge pull request #46 from msakande/phi-3-5-vision-serverless
add serverless support for phi 3-5 vision
2 parents c9c1d91 + f60c57c commit 25df055

File tree

5 files changed

+435
-8
lines changed

5 files changed

+435
-8
lines changed

articles/ai-studio/how-to/deploy-models-phi-3-5-vision.md

Lines changed: 216 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to use Phi-3.5 chat model with vision with Azure AI Studi
55
ms.service: azure-ai-studio
66
manager: scottpolly
77
ms.topic: how-to
8-
ms.date: 08/19/2024
8+
ms.date: 08/29/2024
99
ms.reviewer: kritifaujdar
1010
reviewer: fkriti
1111
ms.author: mopeakande
@@ -41,6 +41,15 @@ To use Phi-3.5 chat model with vision with Azure AI Studio, you need the followi
4141

4242
### A model deployment
4343

44+
**Deployment to serverless APIs**
45+
46+
Phi-3.5 chat model with vision can be deployed to serverless API endpoints with pay-as-you-go billing. This kind of deployment provides a way to consume models as an API without hosting them on your subscription, while keeping the enterprise security and compliance that organizations need.
47+
48+
Deployment to a serverless API endpoint doesn't require quota from your subscription. If your model isn't deployed already, use the Azure AI Studio, Azure Machine Learning SDK for Python, the Azure CLI, or ARM templates to [deploy the model as a serverless API](deploy-models-serverless.md).
49+
50+
> [!div class="nextstepaction"]
51+
> [Deploy the model to serverless API endpoints](deploy-models-serverless.md)
52+
4453
**Deployment to a self-hosted managed compute**
4554

4655
Phi-3.5 chat model with vision can be deployed to our self-hosted managed inference solution, which allows you to customize and control all the details about how the model is served.
@@ -103,6 +112,9 @@ client = ChatCompletionsClient(
103112
)
104113
```
105114

115+
> [!NOTE]
116+
> Currently, serverless API endpoints do not support using Microsoft Entra ID for authentication.
117+
106118
### Get the model's capabilities
107119

108120
The `/info` route returns information about the model that is deployed to the endpoint. Return the model's information by calling the following method:
@@ -215,7 +227,7 @@ print_stream(result)
215227
Explore other parameters that you can specify in the inference client. For a full list of all the supported parameters and their corresponding documentation, see [Azure AI Model Inference API reference](https://aka.ms/azureai/modelinference).
216228

217229
```python
218-
from azure.ai.inference.models import ChatCompletionsResponseFormatText
230+
from azure.ai.inference.models import ChatCompletionsResponseFormat
219231

220232
response = client.complete(
221233
messages=[
@@ -228,7 +240,7 @@ response = client.complete(
228240
stop=["<|endoftext|>"],
229241
temperature=0,
230242
top_p=1,
231-
response_format=ChatCompletionsResponseFormatText(),
243+
response_format={ "type": ChatCompletionsResponseFormat.TEXT },
232244
)
233245
```
234246

@@ -266,6 +278,42 @@ The following extra parameters can be passed to Phi-3.5 chat model with vision:
266278
| `n` | How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. | `int` |
267279

268280

281+
### Apply content safety
282+
283+
The Azure AI model inference API supports [Azure AI content safety](https://aka.ms/azureaicontentsafety). When you use deployments with Azure AI content safety turned on, inputs and outputs pass through an ensemble of classification models aimed at detecting and preventing the output of harmful content. The content filtering system detects and takes action on specific categories of potentially harmful content in both input prompts and output completions.
284+
285+
The following example shows how to handle events when the model detects harmful content in the input prompt and content safety is enabled.
286+
287+
288+
```python
289+
from azure.ai.inference.models import AssistantMessage, UserMessage, SystemMessage
290+
291+
try:
292+
response = client.complete(
293+
messages=[
294+
SystemMessage(content="You are an AI assistant that helps people find information."),
295+
UserMessage(content="Chopping tomatoes and cutting them into cubes or wedges are great ways to practice your knife skills."),
296+
]
297+
)
298+
299+
print(response.choices[0].message.content)
300+
301+
except HttpResponseError as ex:
302+
if ex.status_code == 400:
303+
response = ex.response.json()
304+
if isinstance(response, dict) and "error" in response:
305+
print(f"Your request triggered an {response['error']['code']} error:\n\t {response['error']['message']}")
306+
else:
307+
raise
308+
raise
309+
```
310+
311+
> [!TIP]
312+
> To learn more about how you can configure and control Azure AI content safety settings, check the [Azure AI content safety documentation](https://aka.ms/azureaicontentsafety).
313+
314+
> [!NOTE]
315+
> Azure AI content safety is only available for models deployed as serverless API endpoints.
316+
269317
## Use chat completions with images
270318

271319
Phi-3.5-vision-Instruct can reason across text and images and generate text completions based on both kinds of input. In this section, you explore the capabilities of Phi-3.5-vision-Instruct for vision in a chat fashion:
@@ -361,6 +409,15 @@ To use Phi-3.5 chat model with vision with Azure AI Studio, you need the followi
361409

362410
### A model deployment
363411

412+
**Deployment to serverless APIs**
413+
414+
Phi-3.5 chat model with vision can be deployed to serverless API endpoints with pay-as-you-go billing. This kind of deployment provides a way to consume models as an API without hosting them on your subscription, while keeping the enterprise security and compliance that organizations need.
415+
416+
Deployment to a serverless API endpoint doesn't require quota from your subscription. If your model isn't deployed already, use the Azure AI Studio, Azure Machine Learning SDK for Python, the Azure CLI, or ARM templates to [deploy the model as a serverless API](deploy-models-serverless.md).
417+
418+
> [!div class="nextstepaction"]
419+
> [Deploy the model to serverless API endpoints](deploy-models-serverless.md)
420+
364421
**Deployment to a self-hosted managed compute**
365422

366423
Phi-3.5 chat model with vision can be deployed to our self-hosted managed inference solution, which allows you to customize and control all the details about how the model is served.
@@ -421,6 +478,9 @@ const client = new ModelClient(
421478
);
422479
```
423480

481+
> [!NOTE]
482+
> Currently, serverless API endpoints do not support using Microsoft Entra ID for authentication.
483+
424484
### Get the model's capabilities
425485

426486
The `/info` route returns information about the model that is deployed to the endpoint. Return the model's information by calling the following method:
@@ -603,6 +663,48 @@ The following extra parameters can be passed to Phi-3.5 chat model with vision:
603663
| `n` | How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. | `int` |
604664
605665
666+
### Apply content safety
667+
668+
The Azure AI model inference API supports [Azure AI content safety](https://aka.ms/azureaicontentsafety). When you use deployments with Azure AI content safety turned on, inputs and outputs pass through an ensemble of classification models aimed at detecting and preventing the output of harmful content. The content filtering system detects and takes action on specific categories of potentially harmful content in both input prompts and output completions.
669+
670+
The following example shows how to handle events when the model detects harmful content in the input prompt and content safety is enabled.
671+
672+
673+
```javascript
674+
try {
675+
var messages = [
676+
{ role: "system", content: "You are an AI assistant that helps people find information." },
677+
{ role: "user", content: "Chopping tomatoes and cutting them into cubes or wedges are great ways to practice your knife skills." },
678+
];
679+
680+
var response = await client.path("/chat/completions").post({
681+
body: {
682+
messages: messages,
683+
}
684+
});
685+
686+
console.log(response.body.choices[0].message.content);
687+
}
688+
catch (error) {
689+
if (error.status_code == 400) {
690+
var response = JSON.parse(error.response._content);
691+
if (response.error) {
692+
console.log(`Your request triggered an ${response.error.code} error:\n\t ${response.error.message}`);
693+
}
694+
else
695+
{
696+
throw error;
697+
}
698+
}
699+
}
700+
```
701+
702+
> [!TIP]
703+
> To learn more about how you can configure and control Azure AI content safety settings, check the [Azure AI content safety documentation](https://aka.ms/azureaicontentsafety).
704+
705+
> [!NOTE]
706+
> Azure AI content safety is only available for models deployed as serverless API endpoints.
707+
606708
## Use chat completions with images
607709
608710
Phi-3.5-vision-Instruct can reason across text and images and generate text completions based on both kinds of input. In this section, you explore the capabilities of Phi-3.5-vision-Instruct for vision in a chat fashion:
@@ -704,6 +806,15 @@ To use Phi-3.5 chat model with vision with Azure AI Studio, you need the followi
704806
705807
### A model deployment
706808
809+
**Deployment to serverless APIs**
810+
811+
Phi-3.5 chat model with vision can be deployed to serverless API endpoints with pay-as-you-go billing. This kind of deployment provides a way to consume models as an API without hosting them on your subscription, while keeping the enterprise security and compliance that organizations need.
812+
813+
Deployment to a serverless API endpoint doesn't require quota from your subscription. If your model isn't deployed already, use the Azure AI Studio, Azure Machine Learning SDK for Python, the Azure CLI, or ARM templates to [deploy the model as a serverless API](deploy-models-serverless.md).
814+
815+
> [!div class="nextstepaction"]
816+
> [Deploy the model to serverless API endpoints](deploy-models-serverless.md)
817+
707818
**Deployment to a self-hosted managed compute**
708819
709820
Phi-3.5 chat model with vision can be deployed to our self-hosted managed inference solution, which allows you to customize and control all the details about how the model is served.
@@ -779,6 +890,9 @@ client = new ChatCompletionsClient(
779890
);
780891
```
781892

893+
> [!NOTE]
894+
> Currently, serverless API endpoints do not support using Microsoft Entra ID for authentication.
895+
782896
### Get the model's capabilities
783897
784898
The `/info` route returns information about the model that is deployed to the endpoint. Return the model's information by calling the following method:
@@ -958,6 +1072,48 @@ The following extra parameters can be passed to Phi-3.5 chat model with vision:
9581072
| `n` | How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. | `int` |
9591073
9601074
1075+
### Apply content safety
1076+
1077+
The Azure AI model inference API supports [Azure AI content safety](https://aka.ms/azureaicontentsafety). When you use deployments with Azure AI content safety turned on, inputs and outputs pass through an ensemble of classification models aimed at detecting and preventing the output of harmful content. The content filtering system detects and takes action on specific categories of potentially harmful content in both input prompts and output completions.
1078+
1079+
The following example shows how to handle events when the model detects harmful content in the input prompt and content safety is enabled.
1080+
1081+
1082+
```csharp
1083+
try
1084+
{
1085+
requestOptions = new ChatCompletionsOptions()
1086+
{
1087+
Messages = {
1088+
new ChatRequestSystemMessage("You are an AI assistant that helps people find information."),
1089+
new ChatRequestUserMessage(
1090+
"Chopping tomatoes and cutting them into cubes or wedges are great ways to practice your knife skills."
1091+
),
1092+
},
1093+
};
1094+
1095+
response = client.Complete(requestOptions);
1096+
Console.WriteLine(response.Value.Choices[0].Message.Content);
1097+
}
1098+
catch (RequestFailedException ex)
1099+
{
1100+
if (ex.ErrorCode == "content_filter")
1101+
{
1102+
Console.WriteLine($"Your query has trigger Azure Content Safety: {ex.Message}");
1103+
}
1104+
else
1105+
{
1106+
throw;
1107+
}
1108+
}
1109+
```
1110+
1111+
> [!TIP]
1112+
> To learn more about how you can configure and control Azure AI content safety settings, check the [Azure AI content safety documentation](https://aka.ms/azureaicontentsafety).
1113+
1114+
> [!NOTE]
1115+
> Azure AI content safety is only available for models deployed as serverless API endpoints.
1116+
9611117
## Use chat completions with images
9621118
9631119
Phi-3.5-vision-Instruct can reason across text and images and generate text completions based on both kinds of input. In this section, you explore the capabilities of Phi-3.5-vision-Instruct for vision in a chat fashion:
@@ -1044,6 +1200,15 @@ To use Phi-3.5 chat model with vision with Azure AI Studio, you need the followi
10441200

10451201
### A model deployment
10461202

1203+
**Deployment to serverless APIs**
1204+
1205+
Phi-3.5 chat model with vision can be deployed to serverless API endpoints with pay-as-you-go billing. This kind of deployment provides a way to consume models as an API without hosting them on your subscription, while keeping the enterprise security and compliance that organizations need.
1206+
1207+
Deployment to a serverless API endpoint doesn't require quota from your subscription. If your model isn't deployed already, use the Azure AI Studio, Azure Machine Learning SDK for Python, the Azure CLI, or ARM templates to [deploy the model as a serverless API](deploy-models-serverless.md).
1208+
1209+
> [!div class="nextstepaction"]
1210+
> [Deploy the model to serverless API endpoints](deploy-models-serverless.md)
1211+
10471212
**Deployment to a self-hosted managed compute**
10481213

10491214
Phi-3.5 chat model with vision can be deployed to our self-hosted managed inference solution, which allows you to customize and control all the details about how the model is served.
@@ -1073,6 +1238,9 @@ First, create the client to consume the model. The following code uses an endpoi
10731238
10741239
When you deploy the model to a self-hosted online endpoint with **Microsoft Entra ID** support, you can use the following code snippet to create a client.
10751240
1241+
> [!NOTE]
1242+
> Currently, serverless API endpoints do not support using Microsoft Entra ID for authentication.
1243+
10761244
### Get the model's capabilities
10771245

10781246
The `/info` route returns information about the model that is deployed to the endpoint. Return the model's information by calling the following method:
@@ -1323,6 +1491,47 @@ The following extra parameters can be passed to Phi-3.5 chat model with vision:
13231491
| `n` | How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. | `int` |
13241492

13251493

1494+
### Apply content safety
1495+
1496+
The Azure AI model inference API supports [Azure AI content safety](https://aka.ms/azureaicontentsafety). When you use deployments with Azure AI content safety turned on, inputs and outputs pass through an ensemble of classification models aimed at detecting and preventing the output of harmful content. The content filtering system detects and takes action on specific categories of potentially harmful content in both input prompts and output completions.
1497+
1498+
The following example shows how to handle events when the model detects harmful content in the input prompt and content safety is enabled.
1499+
1500+
1501+
```json
1502+
{
1503+
"messages": [
1504+
{
1505+
"role": "system",
1506+
"content": "You are an AI assistant that helps people find information."
1507+
},
1508+
{
1509+
"role": "user",
1510+
"content": "Chopping tomatoes and cutting them into cubes or wedges are great ways to practice your knife skills."
1511+
}
1512+
]
1513+
}
1514+
```
1515+
1516+
1517+
```json
1518+
{
1519+
"error": {
1520+
"message": "The response was filtered due to the prompt triggering Microsoft's content management policy. Please modify your prompt and retry.",
1521+
"type": null,
1522+
"param": "prompt",
1523+
"code": "content_filter",
1524+
"status": 400
1525+
}
1526+
}
1527+
```
1528+
1529+
> [!TIP]
1530+
> To learn more about how you can configure and control Azure AI content safety settings, check the [Azure AI content safety documentation](https://aka.ms/azureaicontentsafety).
1531+
1532+
> [!NOTE]
1533+
> Azure AI content safety is only available for models deployed as serverless API endpoints.
1534+
13261535
## Use chat completions with images
13271536

13281537
Phi-3.5-vision-Instruct can reason across text and images and generate text completions based on both kinds of input. In this section, you explore the capabilities of Phi-3.5-vision-Instruct for vision in a chat fashion:
@@ -1413,6 +1622,10 @@ For more examples of how to use Phi-3 family models, see the following examples
14131622
| LiteLLM | Python | [Link](https://aka.ms/phi-3/litellm-sample) |
14141623
14151624
1625+
## Cost and quota considerations for Phi-3 family models deployed as serverless API endpoints
1626+
1627+
Quota is managed per deployment. Each deployment has a rate limit of 200,000 tokens per minute and 1,000 API requests per minute. However, we currently limit one deployment per model per project. Contact Microsoft Azure Support if the current rate limits aren't sufficient for your scenarios.
1628+
14161629
## Cost and quota considerations for Phi-3 family models deployed to managed compute
14171630
14181631
Phi-3 family models deployed to managed compute are billed based on core hours of the associated compute instance. The cost of the compute instance is determined by the size of the instance, the number of instances running, and the run duration.

articles/ai-studio/how-to/model-catalog-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Llama family models | Llama-2-7b <br> Llama-2-7b-chat <br> Llama-2-13b <br> Llam
6868
Mistral family models | mistralai-Mixtral-8x22B-v0-1 <br> mistralai-Mixtral-8x22B-Instruct-v0-1 <br> mistral-community-Mixtral-8x22B-v0-1 <br> mistralai-Mixtral-8x7B-v01 <br> mistralai-Mistral-7B-Instruct-v0-2 <br> mistralai-Mistral-7B-v01 <br> mistralai-Mixtral-8x7B-Instruct-v01 <br> mistralai-Mistral-7B-Instruct-v01 | Mistral-large (2402) <br> Mistral-large (2407) <br> Mistral-small <br> Mistral-NeMo
6969
Cohere family models | Not available | Cohere-command-r-plus <br> Cohere-command-r <br> Cohere-embed-v3-english <br> Cohere-embed-v3-multilingual <br> Cohere-rerank-v3-english <br> Cohere-rerank-v3-multilingual
7070
JAIS | Not available | jais-30b-chat
71-
Phi-3 family models | Phi-3-mini-4k-Instruct <br> Phi-3-mini-128k-Instruct <br> Phi-3-small-8k-Instruct <br> Phi-3-small-128k-Instruct <br> Phi-3-medium-4k-instruct <br> Phi-3-medium-128k-instruct <br> Phi-3-vision-128k-Instruct <br> Phi-3.5-mini-Instruct <br> Phi-3.5-vision-Instruct <br> Phi-3.5-MoE-Instruct | Phi-3-mini-4k-Instruct <br> Phi-3-mini-128k-Instruct <br> Phi-3-small-8k-Instruct <br> Phi-3-small-128k-Instruct <br> Phi-3-medium-4k-instruct <br> Phi-3-medium-128k-instruct <br> <br> Phi-3.5-mini-Instruct
71+
Phi-3 family models | Phi-3-mini-4k-Instruct <br> Phi-3-mini-128k-Instruct <br> Phi-3-small-8k-Instruct <br> Phi-3-small-128k-Instruct <br> Phi-3-medium-4k-instruct <br> Phi-3-medium-128k-instruct <br> Phi-3-vision-128k-Instruct <br> Phi-3.5-mini-Instruct <br> Phi-3.5-vision-Instruct <br> Phi-3.5-MoE-Instruct | Phi-3-mini-4k-Instruct <br> Phi-3-mini-128k-Instruct <br> Phi-3-small-8k-Instruct <br> Phi-3-small-128k-Instruct <br> Phi-3-medium-4k-instruct <br> Phi-3-medium-128k-instruct <br> <br> Phi-3.5-mini-Instruct <br> Phi-3.5-vision-Instruct
7272
Nixtla | Not available | TimeGEN-1
7373
Other models | Available | Not available
7474

articles/ai-studio/includes/region-availability-maas.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Llama 3.1 405B Instruct | [Microsoft Managed Countries](/partner-center/marketp
4444

4545
|Model |Offer Availability Region | Hub/Project Region for Deployment | Hub/Project Region for Fine tuning |
4646
|---------|---------|---------|---------|
47+
Phi-3.5-vision-Instruct | Not applicable | East US 2 <br> Sweden Central | Not available |
4748
Phi-3.5-Mini-Instruct | Not applicable | East US 2 <br> Sweden Central | Not available |
4849
Phi-3-Mini-4k-Instruct <br> Phi-3-Mini-128K-Instruct | Not applicable | East US 2 <br> Sweden Central | East US 2 |
4950
Phi-3-Small-8K-Instruct <br> Phi-3-Small-128K-Instruct | Not applicable | East US 2 <br> Sweden Central | Not available |

0 commit comments

Comments
 (0)