From 327a58f92fdc69836f6d0df82d93aabb067a7183 Mon Sep 17 00:00:00 2001 From: Abraham Omorogbe Date: Wed, 23 Aug 2023 17:08:31 -0700 Subject: [PATCH 1/3] clean up deployment flie --- promptflow/deployment/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/promptflow/deployment/deployment.yaml b/promptflow/deployment/deployment.yaml index 3afdbc7..d4eea87 100644 --- a/promptflow/deployment/deployment.yaml +++ b/promptflow/deployment/deployment.yaml @@ -25,7 +25,7 @@ environment_variables: PROMPTFLOW_RUN_MODE: serving # for pulling connections from workspace - PRT_CONFIG_OVERRIDE: deployment.subscription_id=,deployment.resource_group=o,deployment.workspace_name=,deployment.endpoint_name=,deployment.deployment_name= + PRT_CONFIG_OVERRIDE: deployment.subscription_id=,deployment.resource_group=,deployment.workspace_name=,deployment.endpoint_name=,deployment.deployment_name= # (Optional) When there are multiple fields in the response, using this env variable will filter the fields to expose in the response. # For example, if there are 2 flow outputs: "answer", "context", and I only want to have "answer" in the endpoint response, I can set this env variable to '["answer"]'. From 968d186aa22df31b899b121ac5c1a971e83851d5 Mon Sep 17 00:00:00 2001 From: Abraham Omorogbe Date: Tue, 12 Sep 2023 10:07:44 -0700 Subject: [PATCH 2/3] updated docs based on feedback --- .../deploy-pf-online-endpoint-pipeline.yml | 33 +++++++------ .github/workflows/run-eval-pf-pipeline.yml | 48 +++++++++---------- docs/e2e_llmops_with_promptflow.md | 22 ++++++--- .../llmops-helper/service_principal_script.sh | 10 ++++ 4 files changed, 68 insertions(+), 45 deletions(-) create mode 100644 promptflow/llmops-helper/service_principal_script.sh diff --git a/.github/workflows/deploy-pf-online-endpoint-pipeline.yml b/.github/workflows/deploy-pf-online-endpoint-pipeline.yml index 250fef0..bc7fce4 100644 --- a/.github/workflows/deploy-pf-online-endpoint-pipeline.yml +++ b/.github/workflows/deploy-pf-online-endpoint-pipeline.yml @@ -11,42 +11,47 @@ on: env: GROUP: ${{secrets.GROUP}} WORKSPACE: ${{secrets.WORKSPACE}} - SUBSCRIPTION: ${{secrets.SUBSCRIPTION}} + SUBSCRIPTION_ID: ${{secrets.SUBSCRIPTION_ID}} RUN_NAME: web_classification_variant_1_20230816_215600_605116 EVAL_RUN_NAME: classification_accuracy_eval_default_20230821_111809_077086 ENDPOINT_NAME: web-classification + DEPLOYMENT_NAME: blue jobs: create-endpoint-and-deploy-pf: runs-on: ubuntu-latest if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} steps: - - name: check out repo + - name: Check out repo uses: actions/checkout@v2 - - name: install az ml extension + - name: Install az ml extension run: az extension add -n ml -y - - name: azure login + - name: Azure login uses: azure/login@v1 with: creds: ${{secrets.AZURE_CREDENTIALS}} - - name: list current directory + - name: List current directory run: ls - - name: set default subscription + - name: Set default subscription run: | az account set -s ${{env.SUBSCRIPTION}} - - name: create Hash + - name: Create Hash run: echo "HASH=$(echo -n $RANDOM | sha1sum | cut -c 1-6)" >> "$GITHUB_ENV" - - name: create unique endpoint name + - name: Create unique endpoint name run: echo "ENDPOINT_NAME=$(echo 'web-classification-'$HASH)" >> "$GITHUB_ENV" - - name: display endpoint name + - name: Display endpoint name run: echo "Endpoint name is:" ${{env.ENDPOINT_NAME}} - - name: setup endpoint + - name: Setup endpoint run: az ml online-endpoint create --file promptflow/deployment/endpoint.yaml --name ${{env.ENDPOINT_NAME}} -g ${{env.GROUP}} -w ${{env.WORKSPACE}} - - name: setup deployment + - name: Update deployment PRT_CONFIG variable + run: | + PRT_CONFIG_OVERRIDE=deployment.subscription_id=${{ env.SUBSCRIPTION }},deployment.resource_group=${{ env.GROUP }},deployment.workspace_name=${{ env.WORKSPACE }},deployment.endpoint_name=${{ env.ENDPOINT_NAME }},deployment.deployment_name=${{ env.DEPLOYMENT_NAME }} + sed -i "s/PRT_CONFIG_OVERRIDE:.*/PRT_CONFIG_OVERRIDE: $PRT_CONFIG_OVERRIDE/g" promptflow/deployment/deployment.yaml + - name: Setup deployment run: az ml online-deployment create --file promptflow/deployment/deployment.yaml --endpoint-name ${{env.ENDPOINT_NAME}} --all-traffic -g ${{env.GROUP}} -w ${{env.WORKSPACE}} - - name: check the status of the endpoint + - name: Check the status of the endpoint run: az ml online-endpoint show -n ${{env.ENDPOINT_NAME}} -g ${{env.GROUP}} -w ${{env.WORKSPACE}} - - name: check the status of the deployment + - name: Check the status of the deployment run: az ml online-deployment get-logs --name blue --endpoint-name ${{env.ENDPOINT_NAME}} -g ${{env.GROUP}} -w ${{env.WORKSPACE}} - - name: invoke model + - name: Invoke model run: az ml online-endpoint invoke --name ${{env.ENDPOINT_NAME}} --request-file promptflow/deployment/sample-request.json -g ${{env.GROUP}} -w ${{env.WORKSPACE}} \ No newline at end of file diff --git a/.github/workflows/run-eval-pf-pipeline.yml b/.github/workflows/run-eval-pf-pipeline.yml index 128526c..f80da73 100644 --- a/.github/workflows/run-eval-pf-pipeline.yml +++ b/.github/workflows/run-eval-pf-pipeline.yml @@ -8,7 +8,7 @@ on: env: GROUP: ${{secrets.GROUP}} WORKSPACE: ${{secrets.WORKSPACE}} - SUBSCRIPTION: ${{secrets.SUBSCRIPTION}} + SUBSCRIPTION_ID: ${{secrets.SUBSCRIPTION_ID}} RUN_NAME: web_classification_variant_1_20230816_215600_605116 EVAL_RUN_NAME: classification_accuracy_eval_default_20230821_111809_077086 @@ -16,11 +16,11 @@ jobs: login-and-run-and-evalpf: runs-on: ubuntu-latest steps: - - name: check out repo + - name: Check out repo uses: actions/checkout@v2 - - name: install az ml extension + - name: Install az ml extension run: az extension add -n ml -y - - name: azure login + - name: Azure login uses: azure/login@v1 with: creds: ${{secrets.AZURE_CREDENTIALS}} @@ -28,39 +28,39 @@ jobs: uses: actions/setup-python@v2 with: python-version: '3.11.4' - - name: list current directory + - name: List current directory run: ls - - name: install promptflow + - name: Install promptflow run: pip install -r promptflow/web-classification/requirements.txt - - name: run promptflow + - name: Run promptflow run: | pfazure run create -f promptflow/web-classification/run.yml --subscription ${{env.SUBSCRIPTION}} -g ${{env.GROUP}} -w ${{env.WORKSPACE}} --stream > promptflow/llmops-helper/run_info.txt cat promptflow/llmops-helper/run_info.txt - - name: set run name + - name: Set run name run: | echo "RUN_NAME=$(python promptflow/llmops-helper/parse_run_output.py run_info.txt)" >> "$GITHUB_ENV" - - name: show the current run name + - name: Show the current run name run: echo "Run name is:" ${{env.RUN_NAME}} - - name: show promptflow results + - name: Show promptflow results run: pfazure run show-details --name ${{env.RUN_NAME}} --subscription ${{env.SUBSCRIPTION}} -g ${{env.GROUP}} -w ${{env.WORKSPACE}} - - name: run promptflow evaluations + - name: Run promptflow evaluations run: pfazure run create -f promptflow/web-classification/run_evaluation.yml --run ${{env.RUN_NAME}} --subscription ${{env.SUBSCRIPTION}} -g ${{env.GROUP}} -w ${{env.WORKSPACE}} --stream > promptflow/llmops-helper/eval_info.txt - - name: get eval run name - run: export EVAL_RUN_NAME=$(python promptflow/llmops-helper/parse_run_output.py eval_info.txt) - - name: show promptflow details + - name: Get eval run name + run: echo "EVAL_RUN_NAME=$(python promptflow/llmops-helper/parse_run_output.py eval_info.txt)" >> "$GITHUB_ENV" + - name: Show promptflow details run: pfazure run show-details --name ${{env.EVAL_RUN_NAME}} --subscription ${{env.SUBSCRIPTION}} -g ${{env.GROUP}} -w ${{env.WORKSPACE}} - - name: show promptflow metrics + - name: Show promptflow metrics run: pfazure run show-metrics --name ${{env.EVAL_RUN_NAME}} --subscription ${{env.SUBSCRIPTION}} -g ${{env.GROUP}} -w ${{env.WORKSPACE}} > promptflow/llmops-helper/eval_result.json - + assert-and-register-model: needs: login-and-run-and-evalpf runs-on: ubuntu-latest steps: - - name: check out repo + - name: Check out repo uses: actions/checkout@v2 - - name: install az ml extension + - name: Install az ml extension run: az extension add -n ml -y - - name: azure login + - name: Azure login uses: azure/login@v1 with: creds: ${{secrets.AZURE_CREDENTIALS}} @@ -68,14 +68,14 @@ jobs: uses: actions/setup-python@v2 with: python-version: '3.11.4' - - name: set default subscription + - name: Set default subscription run: | az account set -s ${{env.SUBSCRIPTION}} - - name: list current directory + - name: List current directory run: ls - - name: install promptflow + - name: Install promptflow run: pip install -r promptflow/web-classification/requirements.txt - - name: get assert eval results + - name: Get assert eval results id: jobMetricAssert run: | export ASSERT=$(python promptflow/llmops-helper/assert.py result.json 0.6) # NOTE .json is the file name and decimal is the threshold for the assertion @@ -88,6 +88,6 @@ jobs: echo "::warning::Prompt flow run didn't meet quality bar." echo "::set-output name=result::false" fi - - name: register promptflow model + - name: Register promptflow model if: ${{ steps.jobMetricAssert.outputs.result == 'true' }} run: az ml model create --file promptflow/deployment/model.yaml -g ${{env.GROUP}} -w ${{env.WORKSPACE}} \ No newline at end of file diff --git a/docs/e2e_llmops_with_promptflow.md b/docs/e2e_llmops_with_promptflow.md index 3c07889..0d5a57e 100644 --- a/docs/e2e_llmops_with_promptflow.md +++ b/docs/e2e_llmops_with_promptflow.md @@ -84,9 +84,7 @@ Before you can set up an Prompt flow project with Machine Learning, you need to 1. Close the Cloud Shell once the service principals are created. ## Set up GitHub repo -1. Fork example repo. [LLMOps Demo Template Repo](https://github.com/Azure/llmops-gha-demo/) in your GitHub organization - -1. Go to https://github.com/Azure/llmops-gha-demo/fork to fork the LLMOps demo repo into your GitHub org. This repo has reusable LLMOps code that can be used across multiple projects. +1. Fork example repo. [LLMOps Demo Template Repo](https://github.com/Azure/llmops-gha-demo/fork) in your GitHub organization. This repo has reusable LLMOps code that can be used across multiple projects. ## Add secret to GitHub Repo @@ -103,9 +101,9 @@ Before you can set up an Prompt flow project with Machine Learning, you need to ![Screenshot of GitHub Secrets String 1.](media/e2e-llmops/github-secrets-string.png) 1. Add each of the following additional GitHub secrets using the corresponding values from the service principal output as the content of the secret: - - **GROUP** - - **WORKSPACE** - - **SUBSCRIPTION** + - **GROUP**: \ + - **WORKSPACE**: \ + - **SUBSCRIPTION_ID**: \ > [!NOTE] > This finishes the prerequisite section and the deployment of the solution accelerator can happen accordingly. @@ -120,6 +118,13 @@ Please go to workspace portal, click `Prompt flow` -> `Connections` -> `Create`, ![Screenshot of Prompt flow Connections](media/e2e-llmops/promptflow_connections.png) +## Setup runtime for Prompt flow +Prompt flow's runtime provides the computing resources required for the application to run, including a Docker image that contains all necessary dependency packages. + +In this guide, we will use a runtime to run your prompt flow. You need to create your own [Prompt flow runtime](https://learn.microsoft.com/azure/machine-learning/prompt-flow/how-to-create-manage-runtime) + +Please go to workspace portal, click `Prompt flow` -> `Runtime` -> `Add`, then follow the instruction to create your own connections + ## Setup variables with for Prompt flow and GitHub Actions 1. Clone repo to your local machine @@ -136,9 +141,12 @@ Please go to workspace portal, click `Prompt flow` -> `Connections` -> `Create`, |Variable | Description | |---------|---------| |GROUP | Name of resource group | - |SUBSCRIPTION | Subscription of your workspace | + |SUBSCRIPTION_ID | Subscription ID of your workspace | |WORKSPACE | Name of Azure Machine Learning workspace | +> [!TIP] +> The `env` section in the `run-eval-pf-pipeline.yml` and `deploy-pf-online-endpoint-pipeline.yml` contains the workspace secrets you added in the previous step. + ### Update run.yml with your connections and runtime You'll use the `run.yml` and `run_evaluation` files to deploy the Prompt flow standard run and evaluation run. This is a flow run definition. You only need to update your [prompt flow runtime](https://learn.microsoft.com/azure/machine-learning/prompt-flow/how-to-create-manage-runtime). You will also need to update all the `connections` to match the connections in your Azure Machine Learning workspace and `deployment_name` to match the name of your GPT 3.5 Turbo deployment associate with that connection. diff --git a/promptflow/llmops-helper/service_principal_script.sh b/promptflow/llmops-helper/service_principal_script.sh new file mode 100644 index 0000000..d0d0914 --- /dev/null +++ b/promptflow/llmops-helper/service_principal_script.sh @@ -0,0 +1,10 @@ +projectName="" +roleName="Contributor" +subscriptionId="" +environment="" #First letter should be capitalized +servicePrincipalName="Azure-ARM-${environment}-${projectName}" +# Verify the ID of the active subscription +echo "Using subscription ID $subscriptionID" +echo "Creating SP for RBAC with name $servicePrincipalName, with role $roleName and in scopes /subscriptions/$subscriptionId" +az ad sp create-for-rbac --name $servicePrincipalName --role $roleName --scopes /subscriptions/$subscriptionId --sdk-auth +echo "Please ensure that the information created here is properly save for future use." \ No newline at end of file From 35cf454181d5cc9c9a7d3e598d68101f3d8dee08 Mon Sep 17 00:00:00 2001 From: Abraham Omorogbe Date: Tue, 12 Sep 2023 10:13:10 -0700 Subject: [PATCH 3/3] adding more docs updates --- docs/e2e_llmops_with_promptflow.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/docs/e2e_llmops_with_promptflow.md b/docs/e2e_llmops_with_promptflow.md index 0d5a57e..c0f624d 100644 --- a/docs/e2e_llmops_with_promptflow.md +++ b/docs/e2e_llmops_with_promptflow.md @@ -105,6 +105,12 @@ Before you can set up an Prompt flow project with Machine Learning, you need to - **WORKSPACE**: \ - **SUBSCRIPTION_ID**: \ + |Variable | Description | + |---------|---------| + |GROUP | Name of resource group | + |SUBSCRIPTION_ID | Subscription ID of your workspace | + |WORKSPACE | Name of Azure Machine Learning workspace | + > [!NOTE] > This finishes the prerequisite section and the deployment of the solution accelerator can happen accordingly. @@ -136,16 +142,7 @@ Please go to workspace portal, click `Prompt flow` -> `Runtime` -> `Add`, then f ### Update workflow to connect to your Azure Machine Learning workspace 1. You need to update `run-eval-pf-pipeline.yml` and `deploy-pf-online-endpoint-pipeline.yml` to connect to your Azure Machine Learning workspace. You'll need to update the CLI setup file variables to match your workspace. 1. In your cloned repository, go to `.github/workflow/`. -1. Edit `env` section in the `run-eval-pf-pipeline.yml` and `deploy-pf-online-endpoint-pipeline.yml` and update these variables in the file. - - |Variable | Description | - |---------|---------| - |GROUP | Name of resource group | - |SUBSCRIPTION_ID | Subscription ID of your workspace | - |WORKSPACE | Name of Azure Machine Learning workspace | - -> [!TIP] -> The `env` section in the `run-eval-pf-pipeline.yml` and `deploy-pf-online-endpoint-pipeline.yml` contains the workspace secrets you added in the previous step. +1. Verify `env` section in the `run-eval-pf-pipeline.yml` and `deploy-pf-online-endpoint-pipeline.yml` refers to the workspace secrets you added in the previous step. ### Update run.yml with your connections and runtime