diff --git a/best-practices/largescale-deep-learning/Training/Bert-Pretrain/src/environment/context/Dockerfile b/best-practices/largescale-deep-learning/Training/Bert-Pretrain/src/environment/context/Dockerfile index 27462c49f80..18d9640229c 100644 --- a/best-practices/largescale-deep-learning/Training/Bert-Pretrain/src/environment/context/Dockerfile +++ b/best-practices/largescale-deep-learning/Training/Bert-Pretrain/src/environment/context/Dockerfile @@ -24,7 +24,7 @@ RUN pip install 'ipykernel~=6.0' \ 'py-spy==0.3.12' \ 'debugpy~=1.6.3' RUN pip install \ - azure-ai-ml==1.2.0 \ + azure-ai-ml>=1.23.1 \ azureml-inference-server-http~=0.7.0 \ inference-schema~=1.4.2.1 \ MarkupSafe==2.0.1 \ diff --git a/cli/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.sh b/cli/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.sh index 5151099cac7..0543a325c48 100644 --- a/cli/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.sh +++ b/cli/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.sh @@ -44,7 +44,7 @@ finetuning_pipeline_component="transformers_image_classification_pipeline" process_count_per_instance=$gpus_per_node # set to the number of GPUs available in the compute # 1. Install dependencies -pip install azure-ai-ml==1.8.0 +pip install azure-ai-ml>=1.23.1 pip install azure-identity==1.13.0 # 2. Setup pre-requisites diff --git a/cli/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.sh b/cli/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.sh index 242cae8b3d3..d67d9a840fd 100644 --- a/cli/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.sh +++ b/cli/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.sh @@ -45,7 +45,7 @@ finetuning_pipeline_component="transformers_image_classification_pipeline" process_count_per_instance=$gpus_per_node # set to the number of GPUs available in the compute # 1. Install dependencies -pip install azure-ai-ml==1.8.0 +pip install azure-ai-ml>=1.23.1 pip install azure-identity==1.13.0 # 2. Setup pre-requisites diff --git a/cli/foundation-models/system/finetune/image-instance-segmentation/mmdetection-fridgeobjects-instance-segmentation.sh b/cli/foundation-models/system/finetune/image-instance-segmentation/mmdetection-fridgeobjects-instance-segmentation.sh index e7af08f7cce..3c7920ee8d4 100644 --- a/cli/foundation-models/system/finetune/image-instance-segmentation/mmdetection-fridgeobjects-instance-segmentation.sh +++ b/cli/foundation-models/system/finetune/image-instance-segmentation/mmdetection-fridgeobjects-instance-segmentation.sh @@ -45,7 +45,7 @@ finetuning_pipeline_component="mmdetection_image_objectdetection_instancesegment process_count_per_instance=$gpus_per_node # set to the number of GPUs available in the compute # 1. Install dependencies -pip install azure-ai-ml==1.8.0 +pip install azure-ai-ml>=1.23.1 pip install azure-identity==1.13.0 # 2. Setup pre-requisites diff --git a/cli/foundation-models/system/finetune/image-object-detection/mmdetection-fridgeobjects-detection.sh b/cli/foundation-models/system/finetune/image-object-detection/mmdetection-fridgeobjects-detection.sh index 9a41e067f4e..f3d631e0769 100644 --- a/cli/foundation-models/system/finetune/image-object-detection/mmdetection-fridgeobjects-detection.sh +++ b/cli/foundation-models/system/finetune/image-object-detection/mmdetection-fridgeobjects-detection.sh @@ -44,7 +44,7 @@ finetuning_pipeline_component="mmdetection_image_objectdetection_instancesegment process_count_per_instance=$gpus_per_node # set to the number of GPUs available in the compute # 1. Install dependencies -pip install azure-ai-ml==1.8.0 +pip install azure-ai-ml>=1.23.1 pip install azure-identity==1.13.0 # 2. Setup pre-requisites diff --git a/cli/foundation-models/system/finetune/text-to-image/diffusers-dreambooth-dog-text-to-image.sh b/cli/foundation-models/system/finetune/text-to-image/diffusers-dreambooth-dog-text-to-image.sh index 896607f7345..0080cd4b1a9 100644 --- a/cli/foundation-models/system/finetune/text-to-image/diffusers-dreambooth-dog-text-to-image.sh +++ b/cli/foundation-models/system/finetune/text-to-image/diffusers-dreambooth-dog-text-to-image.sh @@ -40,7 +40,7 @@ process_count_per_instance=$gpus_per_node # set to the number of GPUs available instance_count=$instance_count # 1. Install dependencies -pip install azure-ai-ml==1.8.0 +pip install azure-ai-ml>=1.23.1 pip install azure-identity==1.13.0 # 2. Setup pre-requisites diff --git a/cli/foundation-models/system/finetune/video-multi-object-tracking/mmtracking-mot17tiny-mot.sh b/cli/foundation-models/system/finetune/video-multi-object-tracking/mmtracking-mot17tiny-mot.sh index f0b573901e5..cabaf941c6e 100644 --- a/cli/foundation-models/system/finetune/video-multi-object-tracking/mmtracking-mot17tiny-mot.sh +++ b/cli/foundation-models/system/finetune/video-multi-object-tracking/mmtracking-mot17tiny-mot.sh @@ -30,7 +30,7 @@ mmtracking_sample_request_data="./sample_request_data.json" finetuning_pipeline_component="mmtracking_video_multi_object_tracking_pipeline" # 1. Install dependencies -pip install azure-ai-ml==1.8.0 +pip install azure-ai-ml>=1.23.1 pip install azure-identity==1.13.0 # 2. Setup pre-requisites diff --git a/sdk/python/endpoints/online/llm/langchain/deployments/env.yml b/sdk/python/endpoints/online/llm/langchain/deployments/env.yml index 86390f94661..4ee91d948b5 100644 --- a/sdk/python/endpoints/online/llm/langchain/deployments/env.yml +++ b/sdk/python/endpoints/online/llm/langchain/deployments/env.yml @@ -3,7 +3,7 @@ dependencies: - python=3.9 - pip=21.2.4 - pip: - - azure-ai-ml==1.5.0 + - azure-ai-ml>=1.23.1 - azure-core==1.26.4 - azure-identity==1.13.0b3 - azureml-inference-server-http diff --git a/sdk/python/endpoints/online/llm/langchain/requirements.txt b/sdk/python/endpoints/online/llm/langchain/requirements.txt index 3bb1786bd6c..7abe11dc70b 100644 --- a/sdk/python/endpoints/online/llm/langchain/requirements.txt +++ b/sdk/python/endpoints/online/llm/langchain/requirements.txt @@ -1,4 +1,4 @@ -azure-ai-ml==1.5.0 +azure-ai-ml>=1.23.1 azure-core==1.26.4 azure-identity==1.13.0b3 azureml-inference-server-http diff --git a/sdk/python/endpoints/online/llm/src/sk/requirements.txt b/sdk/python/endpoints/online/llm/src/sk/requirements.txt index 65f81b5fc02..65369fb3895 100644 --- a/sdk/python/endpoints/online/llm/src/sk/requirements.txt +++ b/sdk/python/endpoints/online/llm/src/sk/requirements.txt @@ -4,6 +4,6 @@ flask[async] azure-keyvault azure-keyvault-secrets azure-mgmt-keyvault -azure-ai-ml==1.23.1 +azure-ai-ml>=1.23.1 pyyaml azure-cli diff --git a/sdk/python/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.ipynb b/sdk/python/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.ipynb index ca2c37a634e..17f78017d69 100644 --- a/sdk/python/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.ipynb +++ b/sdk/python/foundation-models/system/finetune/image-classification/multiclass-classification/hftransformers-fridgeobjects-multiclass-classification.ipynb @@ -43,7 +43,7 @@ "metadata": {}, "outputs": [], "source": [ - "! pip install azure-ai-ml==1.8.0\n", + "! pip install azure-ai-ml>=1.23.1\n", "! pip install azure-identity==1.13.0" ] }, diff --git a/sdk/python/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.ipynb b/sdk/python/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.ipynb index 4cbbace1e81..7d4bafa29aa 100644 --- a/sdk/python/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.ipynb +++ b/sdk/python/foundation-models/system/finetune/image-classification/multilabel-classification/hftransformers-fridgeobjects-multilabel-classification.ipynb @@ -43,7 +43,7 @@ "metadata": {}, "outputs": [], "source": [ - "! pip install azure-ai-ml==1.8.0\n", + "! pip install azure-ai-ml>=1.23.1\n", "! pip install azure-identity==1.13.0" ] }, diff --git a/sdk/python/foundation-models/system/finetune/image-instance-segmentation/mmdetection-fridgeobjects-instance-segmentation.ipynb b/sdk/python/foundation-models/system/finetune/image-instance-segmentation/mmdetection-fridgeobjects-instance-segmentation.ipynb index 22a00fc9ec1..d82c06f980d 100644 --- a/sdk/python/foundation-models/system/finetune/image-instance-segmentation/mmdetection-fridgeobjects-instance-segmentation.ipynb +++ b/sdk/python/foundation-models/system/finetune/image-instance-segmentation/mmdetection-fridgeobjects-instance-segmentation.ipynb @@ -43,7 +43,7 @@ "metadata": {}, "outputs": [], "source": [ - "! pip install azure-ai-ml==1.8.0\n", + "! pip install azure-ai-ml>=1.23.1\n", "! pip install azure-identity==1.13.0" ] }, diff --git a/sdk/python/foundation-models/system/finetune/image-object-detection/mmdetection-fridgeobjects-object-detection.ipynb b/sdk/python/foundation-models/system/finetune/image-object-detection/mmdetection-fridgeobjects-object-detection.ipynb index ad8f3b5647a..05d85fc0bad 100644 --- a/sdk/python/foundation-models/system/finetune/image-object-detection/mmdetection-fridgeobjects-object-detection.ipynb +++ b/sdk/python/foundation-models/system/finetune/image-object-detection/mmdetection-fridgeobjects-object-detection.ipynb @@ -43,7 +43,7 @@ "metadata": {}, "outputs": [], "source": [ - "! pip install azure-ai-ml==1.8.0\n", + "! pip install azure-ai-ml>=1.23.1\n", "! pip install azure-identity==1.13.0" ] }, diff --git a/sdk/python/foundation-models/system/finetune/text-to-image/diffusers-dreambooth-dog-text-to-image.ipynb b/sdk/python/foundation-models/system/finetune/text-to-image/diffusers-dreambooth-dog-text-to-image.ipynb index 22ee67702e7..ae0066c9a13 100644 --- a/sdk/python/foundation-models/system/finetune/text-to-image/diffusers-dreambooth-dog-text-to-image.ipynb +++ b/sdk/python/foundation-models/system/finetune/text-to-image/diffusers-dreambooth-dog-text-to-image.ipynb @@ -43,7 +43,7 @@ "metadata": {}, "outputs": [], "source": [ - "! pip install azure-ai-ml==1.8.0\n", + "! pip install azure-ai-ml>=1.23.1\n", "! pip install azure-identity==1.13.0" ] }, diff --git a/sdk/python/foundation-models/system/finetune/video-multi-object-tracking/mmtracking-video-multi-object-tracking.ipynb b/sdk/python/foundation-models/system/finetune/video-multi-object-tracking/mmtracking-video-multi-object-tracking.ipynb index d48a53257f3..bc230886828 100644 --- a/sdk/python/foundation-models/system/finetune/video-multi-object-tracking/mmtracking-video-multi-object-tracking.ipynb +++ b/sdk/python/foundation-models/system/finetune/video-multi-object-tracking/mmtracking-video-multi-object-tracking.ipynb @@ -43,7 +43,7 @@ "metadata": {}, "outputs": [], "source": [ - "! pip install azure-ai-ml==1.8.0\n", + "! pip install azure-ai-ml>=1.23.1\n", "! pip install azure-identity==1.13.0" ] }, diff --git a/sdk/python/foundation-models/system/inference/text-generation/falcon-safe-online-deployment.ipynb b/sdk/python/foundation-models/system/inference/text-generation/falcon-safe-online-deployment.ipynb index 6c3cff3094e..ab042a1358b 100644 --- a/sdk/python/foundation-models/system/inference/text-generation/falcon-safe-online-deployment.ipynb +++ b/sdk/python/foundation-models/system/inference/text-generation/falcon-safe-online-deployment.ipynb @@ -3,6 +3,7 @@ { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "# How to create an Azure AI Content Safety enabled Falcon online endpoint (Preview)\n", "### This notebook will walk you through the steps to create an __Azure AI Content Safety__ enabled __Falcon__ online endpoint.\n", @@ -10,30 +11,36 @@ "### The steps are:\n", "1. Create an __Azure AI Content Safety__ resource for moderating the request from user and response from the __Falcon__ online endpoint.\n", "2. Create a new __Azure AI Content Safety__ enabled __Falcon__ online endpoint with a custom score.py which will integrate with the __Azure AI Content Safety__ resource to moderate the response from the __Falcon__ model and the request from the user, but to make the custom score.py to successfully authenticated to the __Azure AI Content Safety__ resource, is to create a User Assigned Identity (UAI) and assign appropriate roles to the UAI. Then, the custom score.py can obtain the access token of the UAI from the AAD server to access the Azure AI Content Safety resource. Use [this notebook](aacs-prepare-uai.ipynb) to create UAI account for step 3 below" - ], - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "### 1. Prerequisites\n", "#### 1.1 Check List:\n", "- [x] You have created a new Python virtual environment for this notebook.\n", "- [x] The identity you are using to execute this notebook(yourself or your VM) need to have the __Contributor__ role on the resource group where the AML Workspace your specified is located, because this notebook will create an Azure AI Content Safety resource using that identity." - ], - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 1.2 Assign variables for the workspace and deployment" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1706764185734 + } + }, + "outputs": [], "source": [ "# The public registry name contains Falcon models\n", "registry_name = \"azureml\"\n", @@ -54,47 +61,47 @@ "\n", "# UAI to be used for endpoint if you choose to use UAI as authentication method\n", "uai_name = \"\" # default to \"aacs-uai\" in prepare uai notebook" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1706764185734 - } - } + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 1.3 Install Dependencies(as needed)" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "# uncomment the following lines to install the required packages\n", "# %pip install azure-identity==1.13.0\n", "# %pip install azure-mgmt-cognitiveservices==13.4.0\n", - "# %pip install azure-ai-ml==1.8.0\n", + "# %pip install azure-ai-ml>=1.23.1\n", "# %pip install azure-mgmt-msi==7.0.0\n", "# %pip install azure-mgmt-authorization==3.0.0" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 1.4 Get credential" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1706764189401 + } + }, + "outputs": [], "source": [ "from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential\n", "\n", @@ -105,25 +112,25 @@ "except Exception as ex:\n", " # Fall back to InteractiveBrowserCredential in case DefaultAzureCredential not work\n", " credential = InteractiveBrowserCredential()" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1706764189401 - } - } + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 1.5 Configure workspace " - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1706764193416 + } + }, + "outputs": [], "source": [ "from azure.ai.ml import MLClient\n", "\n", @@ -143,29 +150,29 @@ "workspace = ml_client.workspace_name\n", "\n", "print(f\"Connected to workspace {workspace}\")" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1706764193416 - } - } + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 1.6 Assign variables for Azure Content Safety\n", "Currently, Azure AI Content Safety is in a limited set of regions:\n", "\n", "\n", "__NOTE__: before you choose the region to deploy the Azure AI Content Safety, please be aware that your data will be transferred to the region you choose and by selecting a region outside your current location, you may be allowing the transmission of your data to regions outside your jurisdiction. It is important to note that data protection and privacy laws may vary between jurisdictions. Before proceeding, we strongly advise you to familiarize yourself with the local laws and regulations governing data transfer and ensure that you are legally permitted to transmit your data to an overseas location for processing. By continuing with the selection of a different region, you acknowledge that you have understood and accepted any potential risks associated with such data transmission. Please proceed with caution." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1706764197848 + } + }, + "outputs": [], "source": [ "from azure.mgmt.cognitiveservices import CognitiveServicesManagementClient\n", "\n", @@ -197,25 +204,25 @@ "print(\n", " f\"Choose a new Azure AI Content Safety resource in {aacs_location} with SKU {aacs_sku_name}\"\n", ")" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1706764197848 - } - } + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "### 2. Create Azure AI Content Safety" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1706764200966 + } + }, + "outputs": [], "source": [ "from azure.mgmt.cognitiveservices.models import Account, Sku, AccountProperties\n", "\n", @@ -268,33 +275,33 @@ ")\n", "print(f\"AACS endpoint is {aacs_endpoint}\")\n", "print(f\"AACS ResourceId is {aacs_resource_id}\")" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1706764200966 - } - } + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "### 3. Create Azure AI Content Safety enabled Falcon online endpoint" - ], - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 3.1 Check if Falcon model is available in the AML registry." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1706764228889 + } + }, + "outputs": [], "source": [ "reg_client = MLClient(\n", " credential,\n", @@ -315,25 +322,25 @@ " print(\n", " f\"Using model name: {curated_model.name}, version: {curated_model.version}, id: {curated_model.id} for inferencing\"\n", " )" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1706764228889 - } - } + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 3.2 Check if UAI is used" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1706764234090 + } + }, + "outputs": [], "source": [ "uai_id = \"\"\n", "uai_client_id = \"\"\n", @@ -348,34 +355,34 @@ " uai_resource = msi_client.user_assigned_identities.get(resource_group, uai_name)\n", " uai_id = uai_resource.id\n", " uai_client_id = uai_resource.client_id" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1706764234090 - } - } + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 3.3 Create Falcon online endpoint\n", "This step may take a few minutes." - ], - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### Create endpoint" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1706764241993 + } + }, + "outputs": [], "source": [ "from azure.ai.ml.entities import (\n", " ManagedOnlineEndpoint,\n", @@ -408,41 +415,41 @@ " raise RuntimeError(\n", " f\"Endpoint creation failed. Detailed Response:\\n{err}\"\n", " ) from err" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1706764241993 - } - } + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "##### 3.4 Deploy Falcon model" - ], - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### Create deployment" - ], - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "Initialize deployment parameters" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1706764245348 + } + }, + "outputs": [], "source": [ "REQUEST_TIMEOUT_MS = 90000\n", "\n", @@ -454,17 +461,17 @@ " \"RESOURCE_GROUP_NAME\": resource_group,\n", " \"UAI_CLIENT_ID\": uai_client_id,\n", "}" - ], - "outputs": [], + ] + }, + { + "cell_type": "code", "execution_count": null, "metadata": { "gather": { - "logged": 1706764245348 + "logged": 1706766837699 } - } - }, - { - "cell_type": "code", + }, + "outputs": [], "source": [ "from azure.ai.ml.entities import (\n", " CodeConfiguration,\n", @@ -503,25 +510,25 @@ " raise RuntimeError(\n", " f\"Deployment creation failed. Detailed Response:\\n{err}\"\n", " ) from err" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1706766837699 - } - } + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "### 4. Test the Safety Enabled Falcon online endpoint." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1706766982789 + } + }, + "outputs": [], "source": [ "import os\n", "\n", @@ -529,25 +536,25 @@ "os.makedirs(test_src_dir, exist_ok=True)\n", "print(f\"test script directory: {test_src_dir}\")\n", "sample_data = os.path.join(test_src_dir, \"sample-request.json\")" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1706766982789 - } - } + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "##### Choose request from following cells based on the scenario you want to test" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1706766986877 + } + }, + "outputs": [], "source": [ "## Successful response\n", "\n", @@ -571,17 +578,13 @@ " },\n", " f,\n", " )" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1706766986877 - } - } + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "## Blocked request/response due to hateful content\n", "\n", @@ -604,60 +607,57 @@ " },\n", " f,\n", " )" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "ml_client.online_endpoints.invoke(\n", " endpoint_name=endpoint_name,\n", " deployment_name=deployment_name,\n", " request_file=sample_data,\n", ")" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] } ], "metadata": { + "kernel_info": { + "name": "python310-sdkv2" + }, "kernelspec": { - "name": "python310-sdkv2", + "display_name": "Python 3.10 - SDK v2", "language": "python", - "display_name": "Python 3.10 - SDK v2" + "name": "python310-sdkv2" }, "language_info": { - "name": "python", - "version": "3.10.11", - "mimetype": "text/x-python", "codemirror_mode": { "name": "ipython", "version": 3 }, - "pygments_lexer": "ipython3", + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", "nbconvert_exporter": "python", - "file_extension": ".py" + "pygments_lexer": "ipython3", + "version": "3.10.11" }, "microsoft": { - "ms_spell_check": { - "ms_spell_check_language": "en" - }, "host": { "AzureML": { "notebookHasBeenCompleted": true } + }, + "ms_spell_check": { + "ms_spell_check_language": "en" } }, - "kernel_info": { - "name": "python310-sdkv2" - }, "nteract": { "version": "nteract-front-end@1.0.0" } }, "nbformat": 4, "nbformat_minor": 1 -} \ No newline at end of file +} diff --git a/sdk/python/foundation-models/system/inference/text-generation/llama-safe-batch-deployment.ipynb b/sdk/python/foundation-models/system/inference/text-generation/llama-safe-batch-deployment.ipynb index 17ec3bd5090..f56d5bc0fb7 100644 --- a/sdk/python/foundation-models/system/inference/text-generation/llama-safe-batch-deployment.ipynb +++ b/sdk/python/foundation-models/system/inference/text-generation/llama-safe-batch-deployment.ipynb @@ -74,7 +74,7 @@ "# uncomment the following lines to install the required packages\n", "# %pip install azure-identity==1.13.0\n", "# %pip install azure-mgmt-cognitiveservices==13.4.0\n", - "# %pip install azure-ai-ml==1.8.0\n", + "# %pip install azure-ai-ml>=1.23.1\n", "# %pip install azure-mgmt-msi==7.0.0\n", "# %pip install azure-mgmt-authorization==3.0.0" ] diff --git a/sdk/python/foundation-models/system/inference/text-generation/llama-safe-online-deployment.ipynb b/sdk/python/foundation-models/system/inference/text-generation/llama-safe-online-deployment.ipynb index 3617f669029..f68641f7302 100644 --- a/sdk/python/foundation-models/system/inference/text-generation/llama-safe-online-deployment.ipynb +++ b/sdk/python/foundation-models/system/inference/text-generation/llama-safe-online-deployment.ipynb @@ -3,6 +3,7 @@ { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "# How to create an Azure AI Content Safety enabled Llama 2 online endpoint (Preview)\n", "### This notebook will walk you through the steps to create an __Azure AI Content Safety__ enabled __Llama 2__ online endpoint.\n", @@ -10,30 +11,32 @@ "### The steps are:\n", "1. Create an __Azure AI Content Safety__ resource for moderating the request from user and response from the __Llama 2__ online endpoint.\n", "2. Create a new __Azure AI Content Safety__ enabled __Llama 2__ online endpoint with a custom score.py which will integrate with the __Azure AI Content Safety__ resource to moderate the response from the __Llama 2__ model and the request from the user, but to make the custom score.py to successfully authenticated to the __Azure AI Content Safety__ resource, is to create a User Assigned Identity (UAI) and assign appropriate roles to the UAI. Then, the custom score.py can obtain the access token of the UAI from the AAD server to access the Azure AI Content Safety resource. Use [this notebook](aacs-prepare-uai.ipynb) to create UAI account for step 3 below" - ], - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "### 1. Prerequisites\n", "#### 1.1 Check List:\n", "- [x] You have created a new Python virtual environment for this notebook.\n", "- [x] The identity you are using to execute this notebook(yourself or your VM) need to have the __Contributor__ role on the resource group where the AML Workspace your specified is located, because this notebook will create an Azure AI Content Safety resource using that identity." - ], - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 1.2 Assign variables for the workspace and deployment" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "# The public registry name contains Llama 2 models\n", "registry_name = \"azureml-meta\"\n", @@ -54,43 +57,43 @@ "\n", "# UAI to be used for endpoint if you choose to use UAI as authentication method\n", "uai_name = \"\" # default to \"aacs-uai\" in prepare uai notebook" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 1.3 Install Dependencies(as needed)" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "# uncomment the following lines to install the required packages\n", "# %pip install azure-identity==1.13.0\n", "# %pip install azure-mgmt-cognitiveservices==13.4.0\n", - "# %pip install azure-ai-ml==1.8.0\n", + "# %pip install azure-ai-ml>=1.23.1\n", "# %pip install azure-mgmt-msi==7.0.0\n", "# %pip install azure-mgmt-authorization==3.0.0" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 1.4 Get credential" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential\n", "\n", @@ -101,21 +104,21 @@ "except Exception as ex:\n", " # Fall back to InteractiveBrowserCredential in case DefaultAzureCredential not work\n", " credential = InteractiveBrowserCredential()" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 1.5 Configure workspace " - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "from azure.ai.ml import MLClient\n", "\n", @@ -135,25 +138,25 @@ "workspace = ml_client.workspace_name\n", "\n", "print(f\"Connected to workspace {workspace}\")" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 1.6 Assign variables for Azure Content Safety\n", "Currently, Azure AI Content Safety is in a limited set of regions:\n", "\n", "\n", "__NOTE__: before you choose the region to deploy the Azure AI Content Safety, please be aware that your data will be transferred to the region you choose and by selecting a region outside your current location, you may be allowing the transmission of your data to regions outside your jurisdiction. It is important to note that data protection and privacy laws may vary between jurisdictions. Before proceeding, we strongly advise you to familiarize yourself with the local laws and regulations governing data transfer and ensure that you are legally permitted to transmit your data to an overseas location for processing. By continuing with the selection of a different region, you acknowledge that you have understood and accepted any potential risks associated with such data transmission. Please proceed with caution." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "from azure.mgmt.cognitiveservices import CognitiveServicesManagementClient\n", "\n", @@ -185,21 +188,21 @@ "print(\n", " f\"Choose a new Azure AI Content Safety resource in {aacs_location} with SKU {aacs_sku_name}\"\n", ")" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "### 2. Create Azure AI Content Safety" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "from azure.mgmt.cognitiveservices.models import Account, Sku, AccountProperties\n", "\n", @@ -252,29 +255,29 @@ ")\n", "print(f\"AACS endpoint is {aacs_endpoint}\")\n", "print(f\"AACS ResourceId is {aacs_resource_id}\")" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "### 3. Create Azure AI Content Safety enabled Llama 2 online endpoint" - ], - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 3.1 Check if Llama 2 model is available in the AML registry." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "reg_client = MLClient(\n", " credential,\n", @@ -303,21 +306,21 @@ " print(\n", " f\"Using model name: {llama_model.name}, version: {llama_model.version}, id: {llama_model.id} for inferencing\"\n", " )" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 3.2 Check if UAI is used" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "uai_id = \"\"\n", "uai_client_id = \"\"\n", @@ -332,30 +335,30 @@ " uai_resource = msi_client.user_assigned_identities.get(resource_group, uai_name)\n", " uai_id = uai_resource.id\n", " uai_client_id = uai_resource.client_id" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### 3.3 Create Llama 2 online endpoint\n", "This step may take a few minutes." - ], - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "#### Create endpoint" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "from azure.ai.ml.entities import (\n", " ManagedOnlineEndpoint,\n", @@ -390,13 +393,11 @@ " raise RuntimeError(\n", " f\"Endpoint creation failed. Detailed Response:\\n{err}\"\n", " ) from err" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "cell_type": "markdown", + "metadata": {}, "source": [ "#### 3.4 Setup Deployment Parameters\n", "\n", @@ -414,11 +415,13 @@ "__NOTE__: \n", "- `NUM_REPLICAS` is currently only supported by the vLLM engine.\n", "- DeepSpeed MII Engine is only supported on A100 / H100 GPUs.\n" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "REQUEST_TIMEOUT_MS = 90000 # the timeout for each request in milliseconds\n", "MAX_CONCURRENT_REQUESTS = (\n", @@ -448,21 +451,21 @@ "# \"WORKER_COUNT\": MAX_CONCURRENT_REQUESTS,\n", "# }\n", "# deployment_env_vars = {**mii_fastgen_env_vars, **acs_env_vars}" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "cell_type": "markdown", + "metadata": {}, "source": [ "##### 3.5 Deploy Llama 2 model\n", "This step may take a few minutes." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "from azure.ai.ml.entities import (\n", " OnlineRequestSettings,\n", @@ -512,21 +515,21 @@ " raise RuntimeError(\n", " f\"Deployment creation failed. Detailed Response:\\n{err}\"\n", " ) from err" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "### 4. Test the Safety Enabled Llama 2 online endpoint." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "import os\n", "\n", @@ -534,21 +537,21 @@ "os.makedirs(test_src_dir, exist_ok=True)\n", "print(f\"test script directory: {test_src_dir}\")\n", "sample_data = os.path.join(test_src_dir, \"sample-request.json\")" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "attachments": {}, "cell_type": "markdown", + "metadata": {}, "source": [ "##### Choose request from following 4 cells based on the Llama 2 model type you chosen and the scenario you want to test" - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "## For text-generation models (without -chat suffix)\n", "## Successful response\n", @@ -573,13 +576,13 @@ " },\n", " f,\n", " )" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "## For text-generation models (without -chat suffix)\n", "## Blocked request/response due to hateful content\n", @@ -603,13 +606,13 @@ " },\n", " f,\n", " )" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "## For chat-complete models (with \"-chat\" suffix)\n", "## Successful request/response\n", @@ -646,13 +649,13 @@ " },\n", " f,\n", " )" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "## For chat-complete models (with \"-chat\" suffix)\n", "## Blocked request due to hateful content\n", @@ -679,62 +682,59 @@ " },\n", " f,\n", " )" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "ml_client.online_endpoints.invoke(\n", " endpoint_name=endpoint_name,\n", " deployment_name=deployment_name,\n", " request_file=sample_data,\n", ")" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "cell_type": "code", - "source": [], - "outputs": [], "execution_count": null, - "metadata": {} + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { + "kernel_info": { + "name": "python3" + }, "kernelspec": { - "name": "python3", + "display_name": "Python 3 (ipykernel)", "language": "python", - "display_name": "Python 3 (ipykernel)" + "name": "python3" }, "language_info": { - "name": "python", - "version": "3.8.5", - "mimetype": "text/x-python", "codemirror_mode": { "name": "ipython", "version": 3 }, - "pygments_lexer": "ipython3", + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", "nbconvert_exporter": "python", - "file_extension": ".py" + "pygments_lexer": "ipython3", + "version": "3.8.5" }, "microsoft": { "ms_spell_check": { "ms_spell_check_language": "en" } }, - "kernel_info": { - "name": "python3" - }, "nteract": { "version": "nteract-front-end@1.0.0" } }, "nbformat": 4, "nbformat_minor": 1 -} \ No newline at end of file +} diff --git a/sdk/python/foundation-models/system/inference/text-to-image/safe-image-text-to-image-batch-deployment.ipynb b/sdk/python/foundation-models/system/inference/text-to-image/safe-image-text-to-image-batch-deployment.ipynb index 5a6865fbd64..b48e7223f6d 100644 --- a/sdk/python/foundation-models/system/inference/text-to-image/safe-image-text-to-image-batch-deployment.ipynb +++ b/sdk/python/foundation-models/system/inference/text-to-image/safe-image-text-to-image-batch-deployment.ipynb @@ -54,7 +54,7 @@ "# Install the required packages\n", "%pip install azure-identity==1.13.0\n", "%pip install azure-mgmt-cognitiveservices==13.4.0\n", - "%pip install azure-ai-ml==1.8.0\n", + "%pip install azure-ai-ml>=1.23.1\n", "%pip install azure-mgmt-msi==7.0.0\n", "%pip install azure-mgmt-authorization==3.0.0" ] @@ -758,10 +758,10 @@ } ], "metadata": { - "language_info": { - "name": "ipython" - } - }, + "language_info": { + "name": "ipython" + } + }, "nbformat": 4, "nbformat_minor": 1 } diff --git a/sdk/python/foundation-models/system/inference/text-to-image/safe-image-text-to-image-online-endpoint.ipynb b/sdk/python/foundation-models/system/inference/text-to-image/safe-image-text-to-image-online-endpoint.ipynb index 78c67e16f0d..039e7beae0f 100644 --- a/sdk/python/foundation-models/system/inference/text-to-image/safe-image-text-to-image-online-endpoint.ipynb +++ b/sdk/python/foundation-models/system/inference/text-to-image/safe-image-text-to-image-online-endpoint.ipynb @@ -57,7 +57,7 @@ "# Install the required packages\n", "%pip install azure-identity==1.13.0\n", "%pip install azure-mgmt-cognitiveservices==13.4.0\n", - "%pip install azure-ai-ml==1.11.1\n", + "%pip installazure-ai-ml>=1.23.1\n", "%pip install azure-mgmt-msi==7.0.0\n", "%pip install azure-mgmt-authorization==3.0.0" ] @@ -741,9 +741,9 @@ } ], "metadata": { - "language_info": { - "name": "ipython" - } + "language_info": { + "name": "ipython" + } }, "nbformat": 4, "nbformat_minor": 2 diff --git a/sdk/python/foundation-models/system/inference/text-to-image/safe-text-to-image-batch-deployment.ipynb b/sdk/python/foundation-models/system/inference/text-to-image/safe-text-to-image-batch-deployment.ipynb index 1ce35ab3252..c147579fa03 100644 --- a/sdk/python/foundation-models/system/inference/text-to-image/safe-text-to-image-batch-deployment.ipynb +++ b/sdk/python/foundation-models/system/inference/text-to-image/safe-text-to-image-batch-deployment.ipynb @@ -52,7 +52,7 @@ "# Install the required packages\n", "%pip install azure-identity==1.13.0\n", "%pip install azure-mgmt-cognitiveservices==13.4.0\n", - "%pip install azure-ai-ml==1.8.0\n", + "%pip install azure-ai-ml>=1.23.1\n", "%pip install azure-mgmt-msi==7.0.0\n", "%pip install azure-mgmt-authorization==3.0.0" ] diff --git a/sdk/python/foundation-models/system/inference/text-to-image/safe-text-to-image-inpainting-online-endpoint.ipynb b/sdk/python/foundation-models/system/inference/text-to-image/safe-text-to-image-inpainting-online-endpoint.ipynb index a6658cf9dfb..bfaf09a666b 100644 --- a/sdk/python/foundation-models/system/inference/text-to-image/safe-text-to-image-inpainting-online-endpoint.ipynb +++ b/sdk/python/foundation-models/system/inference/text-to-image/safe-text-to-image-inpainting-online-endpoint.ipynb @@ -57,7 +57,7 @@ "# Install the required packages\n", "%pip install azure-identity==1.13.0\n", "%pip install azure-mgmt-cognitiveservices==13.4.0\n", - "%pip install azure-ai-ml==1.11.1\n", + "%pip install azure-ai-ml>=1.23.1\n", "%pip install azure-mgmt-msi==7.0.0\n", "%pip install azure-mgmt-authorization==3.0.0" ] diff --git a/sdk/python/foundation-models/system/inference/text-to-image/safe-text-to-image-online-deployment.ipynb b/sdk/python/foundation-models/system/inference/text-to-image/safe-text-to-image-online-deployment.ipynb index eb4034b621d..046a7b313c4 100644 --- a/sdk/python/foundation-models/system/inference/text-to-image/safe-text-to-image-online-deployment.ipynb +++ b/sdk/python/foundation-models/system/inference/text-to-image/safe-text-to-image-online-deployment.ipynb @@ -57,7 +57,7 @@ "# Install the required packages\n", "%pip install azure-identity==1.13.0\n", "%pip install azure-mgmt-cognitiveservices==13.4.0\n", - "%pip install azure-ai-ml==1.11.1\n", + "%pip install azure-ai-ml>=1.23.1\n", "%pip install azure-mgmt-msi==7.0.0\n", "%pip install azure-mgmt-authorization==3.0.0" ] @@ -728,7 +728,7 @@ } ], "metadata": { - "language_info": { + "language_info": { "name": "ipython" } }, diff --git a/sdk/python/foundation-models/system/inference/text-to-image/text-to-image-online-endpoint.ipynb b/sdk/python/foundation-models/system/inference/text-to-image/text-to-image-online-endpoint.ipynb index 2da22b5e415..b62ee472519 100644 --- a/sdk/python/foundation-models/system/inference/text-to-image/text-to-image-online-endpoint.ipynb +++ b/sdk/python/foundation-models/system/inference/text-to-image/text-to-image-online-endpoint.ipynb @@ -44,7 +44,7 @@ "# Install the required packages\n", "%pip install azure-identity==1.13.0\n", "%pip install azure-mgmt-cognitiveservices==13.4.0\n", - "%pip install azure-ai-ml==1.11.1\n", + "%pip install azure-ai-ml>=1.23.1\n", "%pip install azure-mgmt-msi==7.0.0\n", "%pip install azure-mgmt-authorization==3.0.0" ] @@ -109,7 +109,7 @@ "source": [ "model_name = \"runwayml-stable-diffusion-v1-5\"\n", "diffusion_model = registry_ml_client.models.get(name=model_name, label=\"latest\")\n", - "print(\n", + "print(\n", " f\"\\n\\nUsing model name: {diffusion_model.name}, version: {diffusion_model.version}, id: {diffusion_model.id} for generating images from text.\"\n", ")" ] @@ -399,7 +399,7 @@ } ], "metadata": { - "language_info": { + "language_info": { "name": "ipython" } }, diff --git a/sdk/python/foundation-models/system/inference/video-multi-object-tracking/video-multi-object-tracking-online-endpoint.ipynb b/sdk/python/foundation-models/system/inference/video-multi-object-tracking/video-multi-object-tracking-online-endpoint.ipynb index 961e8efa7c9..cd34c95e3f9 100644 --- a/sdk/python/foundation-models/system/inference/video-multi-object-tracking/video-multi-object-tracking-online-endpoint.ipynb +++ b/sdk/python/foundation-models/system/inference/video-multi-object-tracking/video-multi-object-tracking-online-endpoint.ipynb @@ -46,7 +46,7 @@ "metadata": {}, "outputs": [], "source": [ - "! pip install azure-ai-ml==1.8.0\n", + "! pip install azure-ai-ml>=1.23.1\n", "! pip install azure-identity==1.13.0" ] }, diff --git a/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/crack_and_chunk_with_doc_intel_parallel_component.ipynb b/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/crack_and_chunk_with_doc_intel_parallel_component.ipynb index 489772e45fa..5429c0ab63f 100644 --- a/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/crack_and_chunk_with_doc_intel_parallel_component.ipynb +++ b/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/crack_and_chunk_with_doc_intel_parallel_component.ipynb @@ -17,7 +17,7 @@ }, "outputs": [], "source": [ - "%pip install -U azure-ai-ml==1.16.0b1 # versions may change later\n", + "%pip install -U azure-ai-ml>=1.23.1 # versions may change later\n", "%pip install azure-identity\n", "%pip install -U 'azureml-rag[azure,cognitive_search]>=0.2.28'\n", "%pip install promptflow-rag==0.1.0" diff --git a/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/d_parallel_crack_pdfs_with_azure_document_intelligence.ipynb b/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/d_parallel_crack_pdfs_with_azure_document_intelligence.ipynb index 91956f001a1..96d8f488c93 100644 --- a/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/d_parallel_crack_pdfs_with_azure_document_intelligence.ipynb +++ b/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/d_parallel_crack_pdfs_with_azure_document_intelligence.ipynb @@ -2,6 +2,7 @@ "cells": [ { "cell_type": "markdown", + "metadata": {}, "source": [ "# Create an Index with custom cracking and chunking (in Parallel) using Azure Document Intelligence\n", "\n", @@ -10,35 +11,26 @@ "This notebook does crack_and_chunk with parallel processing. It runs on a compute cluster with multiple nodes and each has multiple processes, the input files are divided into mini batches and assigned to each process. All processes do the crack_and_chunk in parallel.\n", "\n", "This version works with generate_embeddings serial component, with set_automatic_compoute() function." - ], - "metadata": {} + ] }, { "cell_type": "code", - "source": [ - "%pip install -U azure-ai-ml==1.16.0b1 # versions may change later\n", - "%pip install azure-identity\n", - "%pip install -U 'azureml-rag[azure,cognitive_search]>=0.2.28'\n", - "%pip install promptflow-rag==0.1.0" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { "logged": 1712725306438 } - } + }, + "outputs": [], + "source": [ + "%pip install -U azure-ai-ml>=1.23.1 # versions may change later\n", + "%pip install azure-identity\n", + "%pip install -U 'azureml-rag[azure,cognitive_search]>=0.2.28'\n", + "%pip install promptflow-rag==0.1.0" + ] }, { "cell_type": "code", - "source": [ - "from pathlib import Path\n", - "from azure.ai.ml import Input, Output, command, load_component\n", - "from azure.ai.ml.entities import BuildContext, Environment\n", - "from azure.ai.ml.constants import AssetTypes, InputOutputModes\n", - "from azure.ai.ml.parallel import parallel_run_function, RunFunction" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { @@ -53,10 +45,25 @@ "deleting": false } } - } + }, + "outputs": [], + "source": [ + "from pathlib import Path\n", + "from azure.ai.ml import Input, Output, command, load_component\n", + "from azure.ai.ml.entities import BuildContext, Environment\n", + "from azure.ai.ml.constants import AssetTypes, InputOutputModes\n", + "from azure.ai.ml.parallel import parallel_run_function, RunFunction" + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "microsoft": { + "language": "plaintext" + } + }, + "outputs": [], "source": [ "%%writefile config.json\n", "{\n", @@ -64,17 +71,17 @@ " \"resource_group\": \"\",\n", " \"workspace_name\": \"\"\n", "}" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "microsoft": { - "language": "plaintext" - } - } + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714025250362 + } + }, + "outputs": [], "source": [ "from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential\n", "from azure.ai.ml import MLClient\n", @@ -89,17 +96,26 @@ " credential = InteractiveBrowserCredential()\n", "\n", "ml_client = MLClient.from_config(credential=credential)" - ], - "outputs": [], + ] + }, + { + "cell_type": "code", "execution_count": null, "metadata": { "gather": { - "logged": 1714025250362 + "logged": 1714025250575 + }, + "jupyter": { + "outputs_hidden": false, + "source_hidden": false + }, + "nteract": { + "transient": { + "deleting": false + } } - } - }, - { - "cell_type": "code", + }, + "outputs": [], "source": [ "from pathlib import Path\n", "from azure.ai.ml.entities import BuildContext, Environment\n", @@ -114,43 +130,34 @@ "llm_rag_embeddings_doc_intel_environment = ml_client.environments.get(\n", " name=\"llm_rag_embeddings_doc_intel\", version=\"6\"\n", ")" - ], - "outputs": [], - "execution_count": null, + ] + }, + { + "cell_type": "markdown", "metadata": { - "gather": { - "logged": 1714025250575 - }, - "jupyter": { - "outputs_hidden": false, - "source_hidden": false - }, "nteract": { "transient": { "deleting": false } } - } - }, - { - "cell_type": "markdown", + }, "source": [ "Define the crack_and_chunk_with_doc_intel_component_parallel which can be used in place of the crack_and_chunk_parallel Component in Vector Index creation Pipelines.\n", "\n", "Please reference this article for parallel job setup of ML pipeline. https://learn.microsoft.com/en-us/azure/machine-learning/how-to-use-parallel-job-in-pipeline?view=azureml-api-2&tabs=python \n", "\n", "Please reference this article for setting up optimum parameters of parallel job https://microsoft.github.io/azureml-ops-accelerator/4-Migrate/3-PerformanceTunePRS.html" - ], - "metadata": { - "nteract": { - "transient": { - "deleting": false - } - } - } + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714025250701 + } + }, + "outputs": [], "source": [ "crack_and_chunk_with_doc_intel_component_parallel = parallel_run_function(\n", " # version=\"0.0.1\",\n", @@ -239,24 +246,24 @@ " environment=llm_rag_embeddings_doc_intel_environment,\n", " ),\n", ")" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1714025250701 - } - } + ] }, { "cell_type": "markdown", + "metadata": {}, "source": [ "Define pipeline using the custom `crack_and_chunk_with_doc_intel_component_parallel along with the AzureML provided Components to embed and index your data." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714025252217 + } + }, + "outputs": [], "source": [ "ml_registry = MLClient(credential=ml_client._credential, registry_name=\"azureml\")\n", "\n", @@ -272,17 +279,17 @@ "register_mlindex_asset_component = ml_registry.components.get(\n", " \"llm_rag_register_mlindex_asset\", label=\"latest\"\n", ")" - ], - "outputs": [], + ] + }, + { + "cell_type": "code", "execution_count": null, "metadata": { "gather": { - "logged": 1714025252217 + "logged": 1714025252508 } - } - }, - { - "cell_type": "code", + }, + "outputs": [], "source": [ "from azure.ai.ml import Input, Output\n", "from azure.ai.ml.dsl import pipeline\n", @@ -376,38 +383,32 @@ " \"mlindex_asset_uri\": update_acs_index.outputs.index,\n", " \"mlindex_asset_id\": register_mlindex.outputs.asset_id,\n", " }" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1714025252508 - } - } + ] }, { "cell_type": "markdown", + "metadata": {}, "source": [ "Get the connections to Azure OpenAI (for embeddings with `text-embedding-ada-002`) and Azure Cognitive Search." - ], - "metadata": {} + ] }, { "cell_type": "code", - "source": [ - "aoai_connection = ml_client.connections.get(\"AOAI-westus\")\n", - "acs_connection = ml_client.connections.get(\"cog-serch-westus\")" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { "logged": 1714025253221 } - } + }, + "outputs": [], + "source": [ + "aoai_connection = ml_client.connections.get(\"AOAI-westus\")\n", + "acs_connection = ml_client.connections.get(\"cog-serch-westus\")" + ] }, { "cell_type": "markdown", + "metadata": {}, "source": [ "Create a Custom Connection with details for an Azure AI Document Intelligence Service.\n", "[Setup instructions for Azure AI Document Intelligence](https://learn.microsoft.com/azure/ai-services/document-intelligence/create-document-intelligence-resource?view=doc-intel-3.1.0)\n", @@ -415,27 +416,33 @@ "Use the Connections UI in an AzureML Workspace, under the Promptflow tab, to create a connection with these fields: ![custom_doc_intel_connection.png](./assets/custom_doc_intel_connection.png)\n", "\n", "It's not yet supported to create/retrieve Custom Connections using SDK, so you will need to create it using the UI and we'll use string replacement below to get the ID for this custom connection to pass to our pipeline." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714025253367 + } + }, + "outputs": [], "source": [ "document_intelligence_connection_id = aoai_connection.id.replace(\n", " \"AOAI-westus\", \"doc-intelligence\"\n", ")\n", "document_intelligence_connection_id" - ], - "outputs": [], + ] + }, + { + "cell_type": "code", "execution_count": null, "metadata": { "gather": { - "logged": 1714025253367 + "logged": 1714025253534 } - } - }, - { - "cell_type": "code", + }, + "outputs": [], "source": [ "import json\n", "from azure.ai.ml import Input\n", @@ -476,17 +483,17 @@ "pipeline_job.properties[\"azureml.mlIndexAssetName\"] = asset_name\n", "pipeline_job.properties[\"azureml.mlIndexAssetKind\"] = \"acs\"\n", "pipeline_job.properties[\"azureml.mlIndexAssetSource\"] = \"AzureML Data\"" - ], - "outputs": [], + ] + }, + { + "cell_type": "code", "execution_count": null, "metadata": { "gather": { - "logged": 1714025253534 + "logged": 1714025258052 } - } - }, - { - "cell_type": "code", + }, + "outputs": [], "source": [ "submission_name = f\"crack-parallel-embedding-serial\"\n", "print(f\"Submitting pipeline job to experiment: {submission_name}\")\n", @@ -495,40 +502,23 @@ ")\n", "\n", "print(f\"Submitted run, url: {running_pipeline_job.studio_url}\")" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1714025258052 - } - } + ] }, { "cell_type": "code", - "source": [ - "ml_client.jobs.stream(running_pipeline_job.name)" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { "logged": 1714025789174 } - } + }, + "outputs": [], + "source": [ + "ml_client.jobs.stream(running_pipeline_job.name)" + ] }, { "cell_type": "code", - "source": [ - "from promptflow.rag import get_langchain_retriever_from_index\n", - "\n", - "question = \"What are the employees benefits\"\n", - "\n", - "my_index = ml_client.data.get(name=asset_name, label=\"latest\")\n", - "index_langchain_retriever = get_langchain_retriever_from_index(my_index.path)\n", - "index_langchain_retriever.get_relevant_documents(question)" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { @@ -543,7 +533,17 @@ "deleting": false } } - } + }, + "outputs": [], + "source": [ + "from promptflow.rag import get_langchain_retriever_from_index\n", + "\n", + "question = \"What are the employees benefits\"\n", + "\n", + "my_index = ml_client.data.get(name=asset_name, label=\"latest\")\n", + "index_langchain_retriever = get_langchain_retriever_from_index(my_index.path)\n", + "index_langchain_retriever.get_relevant_documents(question)" + ] } ], "metadata": { @@ -559,21 +559,21 @@ "name": "python3" }, "kernelspec": { - "name": "python3", + "display_name": "Python 3 (ipykernel)", "language": "python", - "display_name": "Python 3 (ipykernel)" + "name": "python3" }, "language_info": { - "name": "python", - "version": "3.8.5", - "mimetype": "text/x-python", "codemirror_mode": { "name": "ipython", "version": 3 }, - "pygments_lexer": "ipython3", + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", "nbconvert_exporter": "python", - "file_extension": ".py" + "pygments_lexer": "ipython3", + "version": "3.8.5" }, "microsoft": { "host": { diff --git a/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/e_parallel_crack_pdfs_with_azure_document_intelligence.ipynb b/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/e_parallel_crack_pdfs_with_azure_document_intelligence.ipynb index aeae68d8027..c23ba74bfad 100644 --- a/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/e_parallel_crack_pdfs_with_azure_document_intelligence.ipynb +++ b/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/e_parallel_crack_pdfs_with_azure_document_intelligence.ipynb @@ -2,6 +2,7 @@ "cells": [ { "cell_type": "markdown", + "metadata": {}, "source": [ "# Create an Index with custom cracking and chunking (in Parallel) and generate embeddings (in Parallel) using Azure Document Intelligence\n", "\n", @@ -10,35 +11,26 @@ "This notebook has two components do parallel processing:\n", "- crack_and_chunk_with_doc_intel_parallel. This component is created for custom crack_and_chunk. It runs on a compute cluster with multiple nodes and each has multiple processes, the input files are divided into mini batches and assigned to each process. All processes do the crack_and_chunk in parallel.\n", "- generate_embeddings_parallel. This is a build-in component provided by Azure Designer. User can set parallel parameters, like instance count, max_concurrency_per_instance, mini_batch_size, etc." - ], - "metadata": {} + ] }, { "cell_type": "code", - "source": [ - "%pip install -U azure-ai-ml==1.16.0b1 # versions may change later\n", - "%pip install azure-identity\n", - "%pip install -U 'azureml-rag[azure,cognitive_search]>=0.2.28'\n", - "%pip install promptflow-rag==0.1.0" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { "logged": 1712725306438 } - } + }, + "outputs": [], + "source": [ + "%pip install -U azure-ai-ml>=1.23.1 # versions may change later\n", + "%pip install azure-identity\n", + "%pip install -U 'azureml-rag[azure,cognitive_search]>=0.2.28'\n", + "%pip install promptflow-rag==0.1.0" + ] }, { "cell_type": "code", - "source": [ - "from pathlib import Path\n", - "from azure.ai.ml import Input, Output, command, load_component\n", - "from azure.ai.ml.entities import BuildContext, Environment\n", - "from azure.ai.ml.constants import AssetTypes, InputOutputModes\n", - "from azure.ai.ml.parallel import parallel_run_function, RunFunction" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { @@ -53,10 +45,25 @@ "deleting": false } } - } + }, + "outputs": [], + "source": [ + "from pathlib import Path\n", + "from azure.ai.ml import Input, Output, command, load_component\n", + "from azure.ai.ml.entities import BuildContext, Environment\n", + "from azure.ai.ml.constants import AssetTypes, InputOutputModes\n", + "from azure.ai.ml.parallel import parallel_run_function, RunFunction" + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "microsoft": { + "language": "plaintext" + } + }, + "outputs": [], "source": [ "%%writefile config.json\n", "{\n", @@ -64,17 +71,17 @@ " \"resource_group\": \"\",\n", " \"workspace_name\": \"\"\n", "}" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "microsoft": { - "language": "plaintext" - } - } + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714024787236 + } + }, + "outputs": [], "source": [ "from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential\n", "from azure.ai.ml import MLClient\n", @@ -89,17 +96,26 @@ " credential = InteractiveBrowserCredential()\n", "\n", "ml_client = MLClient.from_config(credential=credential)" - ], - "outputs": [], + ] + }, + { + "cell_type": "code", "execution_count": null, "metadata": { "gather": { - "logged": 1714024787236 + "logged": 1714024787436 + }, + "jupyter": { + "outputs_hidden": false, + "source_hidden": false + }, + "nteract": { + "transient": { + "deleting": false + } } - } - }, - { - "cell_type": "code", + }, + "outputs": [], "source": [ "from pathlib import Path\n", "from azure.ai.ml.entities import BuildContext, Environment\n", @@ -114,43 +130,34 @@ "llm_rag_embeddings_doc_intel_environment = ml_client.environments.get(\n", " name=\"llm_rag_embeddings_doc_intel\", version=\"6\"\n", ")" - ], - "outputs": [], - "execution_count": null, + ] + }, + { + "cell_type": "markdown", "metadata": { - "gather": { - "logged": 1714024787436 - }, - "jupyter": { - "outputs_hidden": false, - "source_hidden": false - }, "nteract": { "transient": { "deleting": false } } - } - }, - { - "cell_type": "markdown", + }, "source": [ "Define the crack_and_chunk_with_doc_intel_component_parallel which can be used in place of the crack_and_chunk_parallel Component in Vector Index creation Pipelines.\n", "\n", "Please reference this article for parallel job setup of ML pipeline. https://learn.microsoft.com/en-us/azure/machine-learning/how-to-use-parallel-job-in-pipeline?view=azureml-api-2&tabs=python \n", "\n", "Please reference this article for setting up optimum parameters of parallel job https://microsoft.github.io/azureml-ops-accelerator/4-Migrate/3-PerformanceTunePRS.html" - ], - "metadata": { - "nteract": { - "transient": { - "deleting": false - } - } - } + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714024787580 + } + }, + "outputs": [], "source": [ "crack_and_chunk_with_doc_intel_component_parallel = parallel_run_function(\n", " # version=\"0.0.1\",\n", @@ -239,26 +246,26 @@ " environment=llm_rag_embeddings_doc_intel_environment,\n", " ),\n", ")" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1714024787580 - } - } + ] }, { "cell_type": "markdown", + "metadata": {}, "source": [ "Define pipeline using the custom `crack_and_chunk_with_doc_intel_component_parallel along with the AzureML provided Components to embed and index your data.\n", "\n", "The llm_rag_generate_embeddings_parallel does parallel processing job." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714024794202 + } + }, + "outputs": [], "source": [ "ml_registry = MLClient(credential=ml_client._credential, registry_name=\"azureml\")\n", "\n", @@ -274,30 +281,30 @@ "register_mlindex_asset_component = ml_registry.components.get(\n", " \"llm_rag_register_mlindex_asset\", label=\"latest\"\n", ")" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1714024794202 - } - } + ] }, { "cell_type": "markdown", - "source": [ - "Setup parallel parameters for component llm_rag_generate_embeddings_parallel." - ], "metadata": { "nteract": { "transient": { "deleting": false } } - } + }, + "source": [ + "Setup parallel parameters for component llm_rag_generate_embeddings_parallel." + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714024794501 + } + }, + "outputs": [], "source": [ "from azure.ai.ml import Input, Output\n", "from azure.ai.ml.dsl import pipeline\n", @@ -395,38 +402,32 @@ " \"mlindex_asset_uri\": update_acs_index.outputs.index,\n", " \"mlindex_asset_id\": register_mlindex.outputs.asset_id,\n", " }" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1714024794501 - } - } + ] }, { "cell_type": "markdown", + "metadata": {}, "source": [ "Get the connections to Azure OpenAI (for embeddings with `text-embedding-ada-002`) and Azure Cognitive Search." - ], - "metadata": {} + ] }, { "cell_type": "code", - "source": [ - "aoai_connection = ml_client.connections.get(\"AOAI-westus\")\n", - "acs_connection = ml_client.connections.get(\"cog-serch-westus\")" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { "logged": 1714024794907 } - } + }, + "outputs": [], + "source": [ + "aoai_connection = ml_client.connections.get(\"AOAI-westus\")\n", + "acs_connection = ml_client.connections.get(\"cog-serch-westus\")" + ] }, { "cell_type": "markdown", + "metadata": {}, "source": [ "Create a Custom Connection with details for an Azure AI Document Intelligence Service.\n", "[Setup instructions for Azure AI Document Intelligence](https://learn.microsoft.com/azure/ai-services/document-intelligence/create-document-intelligence-resource?view=doc-intel-3.1.0)\n", @@ -434,27 +435,33 @@ "Use the Connections UI in an AzureML Workspace, under the Promptflow tab, to create a connection with these fields: ![custom_doc_intel_connection.png](./assets/custom_doc_intel_connection.png)\n", "\n", "It's not yet supported to create/retrieve Custom Connections using SDK, so you will need to create it using the UI and we'll use string replacement below to get the ID for this custom connection to pass to our pipeline." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714024795053 + } + }, + "outputs": [], "source": [ "document_intelligence_connection_id = aoai_connection.id.replace(\n", " \"AOAI-westus\", \"doc-intelligence\"\n", ")\n", "document_intelligence_connection_id" - ], - "outputs": [], + ] + }, + { + "cell_type": "code", "execution_count": null, "metadata": { "gather": { - "logged": 1714024795053 + "logged": 1714024795190 } - } - }, - { - "cell_type": "code", + }, + "outputs": [], "source": [ "import json\n", "from azure.ai.ml import Input\n", @@ -495,17 +502,17 @@ "pipeline_job.properties[\"azureml.mlIndexAssetName\"] = asset_name\n", "pipeline_job.properties[\"azureml.mlIndexAssetKind\"] = \"acs\"\n", "pipeline_job.properties[\"azureml.mlIndexAssetSource\"] = \"AzureML Data\"" - ], - "outputs": [], + ] + }, + { + "cell_type": "code", "execution_count": null, "metadata": { "gather": { - "logged": 1714024795190 + "logged": 1714024800470 } - } - }, - { - "cell_type": "code", + }, + "outputs": [], "source": [ "# submission_name = f\"embedding-parallel-no-auto\"\n", "submission_name = f\"embedding-parallel-auto1\"\n", @@ -515,40 +522,23 @@ ")\n", "\n", "print(f\"Submitted run, url: {running_pipeline_job.studio_url}\")" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1714024800470 - } - } + ] }, { "cell_type": "code", - "source": [ - "ml_client.jobs.stream(running_pipeline_job.name)" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { "logged": 1714025810556 } - } + }, + "outputs": [], + "source": [ + "ml_client.jobs.stream(running_pipeline_job.name)" + ] }, { "cell_type": "code", - "source": [ - "from promptflow.rag import get_langchain_retriever_from_index\n", - "\n", - "question = \"What are the employees benefits\"\n", - "\n", - "my_index = ml_client.data.get(name=asset_name, label=\"latest\")\n", - "index_langchain_retriever = get_langchain_retriever_from_index(my_index.path)\n", - "index_langchain_retriever.get_relevant_documents(question)" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { @@ -563,7 +553,17 @@ "deleting": false } } - } + }, + "outputs": [], + "source": [ + "from promptflow.rag import get_langchain_retriever_from_index\n", + "\n", + "question = \"What are the employees benefits\"\n", + "\n", + "my_index = ml_client.data.get(name=asset_name, label=\"latest\")\n", + "index_langchain_retriever = get_langchain_retriever_from_index(my_index.path)\n", + "index_langchain_retriever.get_relevant_documents(question)" + ] } ], "metadata": { @@ -579,21 +579,21 @@ "name": "python3" }, "kernelspec": { - "name": "python3", + "display_name": "Python 3 (ipykernel)", "language": "python", - "display_name": "Python 3 (ipykernel)" + "name": "python3" }, "language_info": { - "name": "python", - "version": "3.8.5", - "mimetype": "text/x-python", "codemirror_mode": { "name": "ipython", "version": 3 }, - "pygments_lexer": "ipython3", + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", "nbconvert_exporter": "python", - "file_extension": ".py" + "pygments_lexer": "ipython3", + "version": "3.8.5" }, "microsoft": { "host": { diff --git a/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/local_parallel_crack_pdfs_with_azure_document_intelligence.ipynb b/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/local_parallel_crack_pdfs_with_azure_document_intelligence.ipynb index bcbf6ceca61..f4aadef2dd3 100644 --- a/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/local_parallel_crack_pdfs_with_azure_document_intelligence.ipynb +++ b/sdk/python/generative-ai/rag/notebooks/custom_crack_and_chunk_parallel/local_parallel_crack_pdfs_with_azure_document_intelligence.ipynb @@ -2,6 +2,7 @@ "cells": [ { "cell_type": "markdown", + "metadata": {}, "source": [ "# Create an Index with custom cracking and chunking (in Parallel) and generate embeddings (in Parallel) using Azure Document Intelligence\n", "\n", @@ -12,44 +13,35 @@ "- generate_embeddings_parallel. This is a build-in component provided by Azure Designer. User can set parallel parameters, like instance count, max_concurrency_per_instance, mini_batch_size, etc.\n", "\n", "This notebook is almost the same as e_parallel_crack_pdfs_with_azure_document_intelligence.ipynb, the difference is that this notebook can be run locally, i.e. VS code, and all pdf files are stored in local folder (window example)." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "!az login --tenant \"XXXXX\"" - ], - "outputs": [], - "execution_count": null, - "metadata": {} + ] }, { "cell_type": "code", - "source": [ - "%pip install -U azure-ai-ml==1.16.0b1 # versions may change later\n", - "%pip install azure-identity\n", - "%pip install -U 'azureml-rag[azure,cognitive_search]>=0.2.28'\n", - "%pip install promptflow-rag==0.1.0" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { "logged": 1712725306438 } - } + }, + "outputs": [], + "source": [ + "%pip install -U azure-ai-ml>=1.23.1 # versions may change later\n", + "%pip install azure-identity\n", + "%pip install -U 'azureml-rag[azure,cognitive_search]>=0.2.28'\n", + "%pip install promptflow-rag==0.1.0" + ] }, { "cell_type": "code", - "source": [ - "from pathlib import Path\n", - "from azure.ai.ml import Input, Output, command, load_component\n", - "from azure.ai.ml.entities import BuildContext, Environment\n", - "from azure.ai.ml.constants import AssetTypes, InputOutputModes\n", - "from azure.ai.ml.parallel import parallel_run_function, RunFunction" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { @@ -64,10 +56,25 @@ "deleting": false } } - } + }, + "outputs": [], + "source": [ + "from pathlib import Path\n", + "from azure.ai.ml import Input, Output, command, load_component\n", + "from azure.ai.ml.entities import BuildContext, Environment\n", + "from azure.ai.ml.constants import AssetTypes, InputOutputModes\n", + "from azure.ai.ml.parallel import parallel_run_function, RunFunction" + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "microsoft": { + "language": "plaintext" + } + }, + "outputs": [], "source": [ "%%writefile config.json\n", "{\n", @@ -75,17 +82,17 @@ " \"resource_group\": \"\",\n", " \"workspace_name\": \"\"\n", "}" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "microsoft": { - "language": "plaintext" - } - } + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714024787236 + } + }, + "outputs": [], "source": [ "from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential\n", "from azure.ai.ml import MLClient\n", @@ -100,17 +107,26 @@ " credential = InteractiveBrowserCredential()\n", "\n", "ml_client = MLClient.from_config(credential=credential)" - ], - "outputs": [], + ] + }, + { + "cell_type": "code", "execution_count": null, "metadata": { "gather": { - "logged": 1714024787236 + "logged": 1714024787436 + }, + "jupyter": { + "outputs_hidden": false, + "source_hidden": false + }, + "nteract": { + "transient": { + "deleting": false + } } - } - }, - { - "cell_type": "code", + }, + "outputs": [], "source": [ "from pathlib import Path\n", "from azure.ai.ml.entities import BuildContext, Environment\n", @@ -126,43 +142,34 @@ "llm_rag_embeddings_doc_intel_environment = ml_client.environments.get(\n", " name=\"llm_rag_embeddings_doc_intel\", version=\"6\"\n", ")" - ], - "outputs": [], - "execution_count": null, + ] + }, + { + "cell_type": "markdown", "metadata": { - "gather": { - "logged": 1714024787436 - }, - "jupyter": { - "outputs_hidden": false, - "source_hidden": false - }, "nteract": { "transient": { "deleting": false } } - } - }, - { - "cell_type": "markdown", + }, "source": [ "Define the crack_and_chunk_with_doc_intel_component_parallel which can be used in place of the crack_and_chunk_parallel Component in Vector Index creation Pipelines.\n", "\n", "Please reference this article for parallel job setup of ML pipeline. https://learn.microsoft.com/en-us/azure/machine-learning/how-to-use-parallel-job-in-pipeline?view=azureml-api-2&tabs=python \n", "\n", "Please reference this article for setting up optimum parameters of parallel job https://microsoft.github.io/azureml-ops-accelerator/4-Migrate/3-PerformanceTunePRS.html" - ], - "metadata": { - "nteract": { - "transient": { - "deleting": false - } - } - } + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714024787580 + } + }, + "outputs": [], "source": [ "crack_and_chunk_with_doc_intel_component_parallel = parallel_run_function(\n", " # version=\"0.0.1\",\n", @@ -251,26 +258,26 @@ " environment=llm_rag_embeddings_doc_intel_environment,\n", " ),\n", ")" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1714024787580 - } - } + ] }, { "cell_type": "markdown", + "metadata": {}, "source": [ "Define pipeline using the custom `crack_and_chunk_with_doc_intel_component_parallel along with the AzureML provided Components to embed and index your data.\n", "\n", "The llm_rag_generate_embeddings_parallel does parallel processing job." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714024794202 + } + }, + "outputs": [], "source": [ "ml_registry = MLClient(credential=ml_client._credential, registry_name=\"azureml\")\n", "\n", @@ -286,30 +293,30 @@ "register_mlindex_asset_component = ml_registry.components.get(\n", " \"llm_rag_register_mlindex_asset\", label=\"latest\"\n", ")" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1714024794202 - } - } + ] }, { "cell_type": "markdown", - "source": [ - "Setup parallel parameters for component llm_rag_generate_embeddings_parallel." - ], "metadata": { "nteract": { "transient": { "deleting": false } } - } + }, + "source": [ + "Setup parallel parameters for component llm_rag_generate_embeddings_parallel." + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714024794501 + } + }, + "outputs": [], "source": [ "from azure.ai.ml import Input, Output\n", "from azure.ai.ml.dsl import pipeline\n", @@ -407,38 +414,32 @@ " \"mlindex_asset_uri\": update_acs_index.outputs.index,\n", " \"mlindex_asset_id\": register_mlindex.outputs.asset_id,\n", " }" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1714024794501 - } - } + ] }, { "cell_type": "markdown", + "metadata": {}, "source": [ "Get the connections to Azure OpenAI (for embeddings with `text-embedding-ada-002`) and Azure Cognitive Search." - ], - "metadata": {} + ] }, { "cell_type": "code", - "source": [ - "aoai_connection = ml_client.connections.get(\"AOAI-westus\")\n", - "acs_connection = ml_client.connections.get(\"cog-serch-westus\")" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { "logged": 1714024794907 } - } + }, + "outputs": [], + "source": [ + "aoai_connection = ml_client.connections.get(\"AOAI-westus\")\n", + "acs_connection = ml_client.connections.get(\"cog-serch-westus\")" + ] }, { "cell_type": "markdown", + "metadata": {}, "source": [ "Create a Custom Connection with details for an Azure AI Document Intelligence Service.\n", "[Setup instructions for Azure AI Document Intelligence](https://learn.microsoft.com/azure/ai-services/document-intelligence/create-document-intelligence-resource?view=doc-intel-3.1.0)\n", @@ -446,27 +447,33 @@ "Use the Connections UI in an AzureML Workspace, under the Promptflow tab, to create a connection with these fields: ![custom_doc_intel_connection.png](./assets/custom_doc_intel_connection.png)\n", "\n", "It's not yet supported to create/retrieve Custom Connections using SDK, so you will need to create it using the UI and we'll use string replacement below to get the ID for this custom connection to pass to our pipeline." - ], - "metadata": {} + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1714024795053 + } + }, + "outputs": [], "source": [ "document_intelligence_connection_id = aoai_connection.id.replace(\n", " \"AOAI-westus\", \"doc-intelligence\"\n", ")\n", "document_intelligence_connection_id" - ], - "outputs": [], + ] + }, + { + "cell_type": "code", "execution_count": null, "metadata": { "gather": { - "logged": 1714024795053 + "logged": 1714024795190 } - } - }, - { - "cell_type": "code", + }, + "outputs": [], "source": [ "import json\n", "from azure.ai.ml import Input\n", @@ -505,17 +512,17 @@ "pipeline_job.properties[\"azureml.mlIndexAssetName\"] = asset_name\n", "pipeline_job.properties[\"azureml.mlIndexAssetKind\"] = \"acs\"\n", "pipeline_job.properties[\"azureml.mlIndexAssetSource\"] = \"AzureML Data\"" - ], - "outputs": [], + ] + }, + { + "cell_type": "code", "execution_count": null, "metadata": { "gather": { - "logged": 1714024795190 + "logged": 1714024800470 } - } - }, - { - "cell_type": "code", + }, + "outputs": [], "source": [ "# submission_name = f\"embedding-parallel-no-auto\"\n", "submission_name = f\"embedding-parallel-local\"\n", @@ -523,40 +530,23 @@ "running_pipeline_job = ml_client.jobs.create_or_update(\n", " pipeline_job, experiment_name=submission_name\n", ")" - ], - "outputs": [], - "execution_count": null, - "metadata": { - "gather": { - "logged": 1714024800470 - } - } + ] }, { "cell_type": "code", - "source": [ - "ml_client.jobs.stream(running_pipeline_job.name)" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { "logged": 1714025810556 } - } + }, + "outputs": [], + "source": [ + "ml_client.jobs.stream(running_pipeline_job.name)" + ] }, { "cell_type": "code", - "source": [ - "from promptflow.rag import get_langchain_retriever_from_index\n", - "\n", - "question = \"What are the employees benefits\"\n", - "\n", - "my_index = ml_client.data.get(name=asset_name, label=\"latest\")\n", - "index_langchain_retriever = get_langchain_retriever_from_index(my_index.path)\n", - "index_langchain_retriever.get_relevant_documents(question)" - ], - "outputs": [], "execution_count": null, "metadata": { "gather": { @@ -571,7 +561,17 @@ "deleting": false } } - } + }, + "outputs": [], + "source": [ + "from promptflow.rag import get_langchain_retriever_from_index\n", + "\n", + "question = \"What are the employees benefits\"\n", + "\n", + "my_index = ml_client.data.get(name=asset_name, label=\"latest\")\n", + "index_langchain_retriever = get_langchain_retriever_from_index(my_index.path)\n", + "index_langchain_retriever.get_relevant_documents(question)" + ] } ], "metadata": { @@ -587,21 +587,21 @@ "name": "python3" }, "kernelspec": { - "name": "python3", + "display_name": "Python 3 (ipykernel)", "language": "python", - "display_name": "Python 3 (ipykernel)" + "name": "python3" }, "language_info": { - "name": "python", - "version": "3.8.5", - "mimetype": "text/x-python", "codemirror_mode": { "name": "ipython", "version": 3 }, - "pygments_lexer": "ipython3", + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", "nbconvert_exporter": "python", - "file_extension": ".py" + "pygments_lexer": "ipython3", + "version": "3.8.5" }, "microsoft": { "host": {