You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/machine-learning/how-to-use-batch-model-openai-embeddings.md
+62-75Lines changed: 62 additions & 75 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,35 +125,19 @@ You can configure the identity of the compute instance to have access to the Azu
125
125
az role assignment create --role "Cognitive Services User" --assignee $PRINCIPAL_ID --scope $RESOURCE_ID
126
126
```
127
127
128
+
If you get an error message about not finding a user or service principal in the graph database for your principal, check your role assignments. You might need to assign yourself a Global Administrator or Application Administrator role.
129
+
128
130
# [Access keys](#tab/keys)
129
131
130
-
You can configure the batch deployment to use the OpenAI resource access key to get predictions. Copy the access key from your account, and keep it for later steps.
132
+
You can configure the batch deployment to use the access key of your OpenAI resource to get predictions. Copy the access key from your account, and keep it for later steps.
131
133
132
134
---
133
135
136
+
## Register the OpenAI model
134
137
135
-
### Register the OpenAI model
136
-
137
-
Model deployments in batch endpoints can only deploy registered models. You can use MLflow models with the flavor OpenAI to create a model in your workspace referencing a deployment in Azure OpenAI.
138
-
139
-
1. Create an MLflow model in the workspace's models registry pointing to your OpenAI deployment with the model you want to use. Use MLflow SDK to create the model:
140
-
141
-
> [!TIP]
142
-
> In the cloned repository in the folder **model** you already have an MLflow model to generate embeddings based on ADA-002 model in case you want to skip this step.
138
+
Model deployments in batch endpoints can deploy only registered models. You can use MLflow models with the flavor OpenAI to create a model in your workspace that references a deployment in Azure OpenAI.
1. First, let's create the endpoint that hosts the model. Decide on the name of the endpoint:
154
+
To deploy the OpenAI model, you need to create an endpoint, an environment, a scoring script, and a batch deployment. The following sections show you how to create these components.
155
+
156
+
### Create an endpoint
157
+
158
+
An endpoint is needed to host the model. Take the following steps to create an endpoint:
159
+
160
+
1. Set up a variable to store your endpoint name. Replace the name in the following code with one that's unique within the region of your resource group.
172
161
173
162
# [Azure CLI](#tab/cli)
174
163
@@ -178,14 +167,11 @@ Model deployments in batch endpoints can only deploy registered models. You can
1. Our scoring script uses some specific libraries that are not part of the standard OpenAI SDK so we need to create an environment that have them. Here, we configure an environment with a base image a conda YAML.
192
+
### Configure an environment
207
193
208
-
# [Azure CLI](#tab/cli)
194
+
The scoring script in this example uses some libraries that aren't part of the standard OpenAI SDK. Create an environment that contains a base image and also a conda YAML file to capture those dependencies:
1. Let's create a scoring script that performs the execution. In Batch Endpoints, MLflow models don't require a scoring script. However, in this case we want to extend a bit the capabilities of batch endpoints by:
212
+
### Create a scoring script
227
213
228
-
> [!div class="checklist"]
229
-
> * Allow the endpoint to read multiple data types, including `csv`, `tsv`, `parquet`, `json`, `jsonl`, `arrow`, and `txt`.
230
-
> * Add some validations to ensure the MLflow model used has an OpenAI flavor on it.
231
-
> * Format the output in `jsonl` format.
232
-
> * Add an environment variable `AZUREML_BI_TEXT_COLUMN` to control (optionally) which input field you want to generate embeddings for.
214
+
This example uses a scoring script that performs the execution. In batch endpoints, MLflow models don't require a scoring script. But this example extends the capabilities of batch endpoints by:
233
215
234
-
> [!TIP]
235
-
> By default, MLflow will use the first text column available in the input data to generate embeddings from. Use the environment variable `AZUREML_BI_TEXT_COLUMN` with the name of an existing column in the input dataset to change the column if needed. Leave it blank if the default behavior works for you.
236
-
237
-
The scoring script looks as follows:
216
+
- Allowing the endpoint to read multiple data types, including `csv`, `tsv`, `parquet`, `json`, `jsonl`, `arrow`, and `txt` formats.
217
+
- Adding some validations to ensure the MLflow model has an OpenAI flavor.
218
+
- Formatting the output in `jsonl` format.
219
+
- Adding an environment variable `AZUREML_BI_TEXT_COLUMN` to optionally control which input field you want to generate embeddings for.
238
220
239
-
__code/batch_driver.py__
221
+
> [!TIP]
222
+
> By default, MLflow generates embeddings from the first text column that's available in the input data. If you want to use a different column, set the environment variable `AZUREML_BI_TEXT_COLUMN` to the name of your preferred column. Leave that variable blank if the default behavior works for you.
The scoring script, *code/batch_driver.py*, contains the following lines:
242
225
243
-
1. One the scoring script is created, it's time to create a batch deployment for it. We use environment variables to configure the OpenAI deployment. Particularly we use the following keys:
* `OPENAI_API_BASE` is the URL of the Azure OpenAI resource to use.
246
-
* `OPENAI_API_VERSION` is the version of the API you plan to use.
247
-
* `OPENAI_API_TYPE` is the type of API and authentication you want to use.
228
+
### Create a batch deployment
248
229
249
-
# [Microsoft Entra authentication](#tab/ad)
230
+
To configure the OpenAI deployment, you use environment variables. Specifically, you use the following keys:
250
231
251
-
The environment variable `OPENAI_API_TYPE="azure_ad"` instructs OpenAI to use Active Directory authentication and hence no key is required to invoke the OpenAI deployment. The identity of the cluster is used instead.
252
-
253
-
# [Access keys](#tab/keys)
232
+
- `OPENAI_API_BASE` is the URL of your Azure OpenAI resource.
233
+
- `OPENAI_API_VERSION` is the version of the API that you plan to use.
234
+
- `OPENAI_API_TYPE` is the type of API and authentication that you want to use.
254
235
255
-
To use access keys instead of Microsoft Entra authentication, we need the following environment variables:
236
+
# [Microsoft Entra authentication](#tab/ad)
237
+
238
+
If you use the environment variable `OPENAI_API_TYPE` with a value of `azure_ad`, OpenAI uses Microsoft Entra authentication. No key is required to invoke the OpenAI deployment. Instead, the identity of the cluster is used.
239
+
240
+
# [Access keys](#tab/keys)
256
241
257
-
* Use `OPENAI_API_TYPE="azure"`
258
-
* Use `OPENAI_API_KEY="<YOUR_AZURE_OPENAI_KEY>"`
242
+
To use an access key instead of Microsoft Entra authentication, you use the following environment variables and values:
259
243
260
-
1. Once we decided on the authentication and the environment variables, we can use them in the deployment. The following example shows how to use Microsoft Entra authentication particularly:
244
+
* `OPENAI_API_TYPE: "azure"`
245
+
* `OPENAI_API_KEY: "<your-Azure-OpenAI-key>"`
246
+
247
+
---
248
+
249
+
1. Update the values of the authentication and environment variables in the deployment configuration. The following example uses Microsoft Entra authentication:
261
250
262
251
# [Azure CLI](#tab/cli)
263
252
264
-
__deployment.yml__
253
+
The *deployment.yml* file configures the deployment:
> Notice the `environment_variables` section where we indicate the configuration for the OpenAI deployment. The value for `OPENAI_API_BASE` will be set later in the creation command so you don't have to edit the YAML configuration file.
258
+
> The `environment_variables` section provides the configuration for the OpenAI deployment. The `OPENAI_API_BASE` value is set when the deployment is created, so you don't have to edit that value in the YAML configuration file.
1. At this point, our batch endpoint is ready to be used.
281
+
The batch endpoint is ready for use.
293
282
294
283
## Test the deployment
295
284
296
-
For testing our endpoint, we are going to use a sample of the dataset [BillSum: A Corpus for Automatic Summarization of US Legislation](https://arxiv.org/abs/1910.00523). This sample is included in the repository in the folder data.
285
+
For testing the endpoint, you use a sample of the dataset [BillSum: A Corpus for Automatic Summarization of US Legislation](https://arxiv.org/abs/1910.00523). This sample is included in the repository, in the *data* folder.
297
286
298
-
1. Create a data input for this model:
287
+
1. Set up the input data:
299
288
300
289
# [Azure CLI](#tab/cli)
301
290
@@ -350,12 +339,10 @@ For testing our endpoint, we are going to use a sample of the dataset [BillSum:
0 commit comments