From cf2ef297b0af3bfda5d14a3b565139c19c6874e9 Mon Sep 17 00:00:00 2001 From: Han Wang Date: Wed, 6 Sep 2023 16:15:21 +0800 Subject: [PATCH] [Sample]Enable automatic runtime sample (#218) # Description Please add an informative description that covers that changes made by the pull request and link all relevant issues. # All Promptflow Contribution checklist: - [ ] **The pull request does not introduce [breaking changes]** - [ ] **CHANGELOG is updated for new features, bug fixes or other significant changes.** - [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).** ## General Guidelines and Best Practices - [ ] Title of the pull request is clear and informative. - [ ] There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md). ### Testing Guidelines - [ ] Pull request includes test coverage for the included changes. --- examples/flows/chat/chat-with-pdf/README.md | 20 ++++++++ .../chat-with-pdf/chat-with-pdf-azure.ipynb | 2 +- .../flows/chat/chat-with-pdf/flow.dag.yaml | 2 + .../tests/azure_chat_with_pdf_test.py | 2 +- .../flow-with-additional-includes/README.md | 18 +++++-- .../standard/flow-with-symlinks/README.md | 4 +- .../standard/web-classification/README.md | 6 +-- .../run-management/cloud-run-management.ipynb | 49 ++++++++++++++++++- 8 files changed, 90 insertions(+), 13 deletions(-) diff --git a/examples/flows/chat/chat-with-pdf/README.md b/examples/flows/chat/chat-with-pdf/README.md index 6f4b7acc79f..306f85c0f1b 100644 --- a/examples/flows/chat/chat-with-pdf/README.md +++ b/examples/flows/chat/chat-with-pdf/README.md @@ -31,6 +31,8 @@ fi ### CLI Example +#### Run flow + ```bash # test with default input value in flow.dag.yaml pf flow test --flow . @@ -47,3 +49,21 @@ pf run create --flow . --data ./data/bert-paper-qna-3-line.jsonl --stream --colu # visualize run output details pf run visualize --name $run_name ``` + +#### Submit run to cloud + +Assume we already have a connection named `open_ai_connection` in workspace. + +```bash +# set default workspace +az account set -s +az configure --defaults group= workspace= +``` + +``` bash +# create run +pfazure run create --flow . --data ./data/bert-paper-qna-3-line.jsonl --stream --column-mapping question='${data.question}' pdf_url='${data.pdf_url}' chat_history='${data.chat_history}' config='{ \"EMBEDDING_MODEL_DEPLOYMENT_NAME\": \"text-embedding-ada-002\", \"CHAT_MODEL_DEPLOYMENT_NAME\": \"gpt-35-turbo\", \"PROMPT_TOKEN_LIMIT\": \"2000\", \"MAX_COMPLETION_TOKENS\": \"256\", \"VERBOSE\": \"True\", \"CHUNK_SIZE\": \"256\", \"CHUNK_OVERLAP\": \"32\" }' --name $run_name --runtime chat_with_pdf_runtime +# pfazure run create --flow . --data ./data/bert-paper-qna-3-line.jsonl --stream --column-mapping question='${data.question}' pdf_url='${data.pdf_url}' chat_history='${data.chat_history}' config='{ \"EMBEDDING_MODEL_DEPLOYMENT_NAME\": \"text-embedding-ada-002\", \"CHAT_MODEL_DEPLOYMENT_NAME\": \"gpt-35-turbo\", \"PROMPT_TOKEN_LIMIT\": \"2000\", \"MAX_COMPLETION_TOKENS\": \"256\", \"VERBOSE\": \"True\", \"CHUNK_SIZE\": \"256\", \"CHUNK_OVERLAP\": \"32\" }' --name $run_name # automatic runtime +``` + +Note: Click portal_url of the run to view the final snapshot. diff --git a/examples/flows/chat/chat-with-pdf/chat-with-pdf-azure.ipynb b/examples/flows/chat/chat-with-pdf/chat-with-pdf-azure.ipynb index 29094def1ab..479f2e6bcec 100644 --- a/examples/flows/chat/chat-with-pdf/chat-with-pdf-azure.ipynb +++ b/examples/flows/chat/chat-with-pdf/chat-with-pdf-azure.ipynb @@ -65,7 +65,7 @@ "# Get a handle to workspace\n", "pf = azure.PFClient.from_config(credential=credential)\n", "runtime = \"chat_with_pdf_runtime\" # TODO add guide to create runtime\n", - "# runtime = None # serverless" + "# runtime = None # automatic runtime" ] }, { diff --git a/examples/flows/chat/chat-with-pdf/flow.dag.yaml b/examples/flows/chat/chat-with-pdf/flow.dag.yaml index 2fc490edad7..778a0d1ed30 100644 --- a/examples/flows/chat/chat-with-pdf/flow.dag.yaml +++ b/examples/flows/chat/chat-with-pdf/flow.dag.yaml @@ -77,3 +77,5 @@ nodes: question: ${inputs.question} history: ${inputs.chat_history} env_ready_signal: ${setup_env.output} +environment: + python_requirements_txt: requirements.txt diff --git a/examples/flows/chat/chat-with-pdf/tests/azure_chat_with_pdf_test.py b/examples/flows/chat/chat-with-pdf/tests/azure_chat_with_pdf_test.py index 64f91ecc68b..be836c6f90a 100644 --- a/examples/flows/chat/chat-with-pdf/tests/azure_chat_with_pdf_test.py +++ b/examples/flows/chat/chat-with-pdf/tests/azure_chat_with_pdf_test.py @@ -22,7 +22,7 @@ def setUp(self): self.pf = azure.PFClient.from_config(credential=credential) self.runtime = "chat_with_pdf_runtime" - # self.runtime = None # serverless + # self.runtime = None # automatic runtime def tearDown(self) -> None: return super().tearDown() diff --git a/examples/flows/standard/flow-with-additional-includes/README.md b/examples/flows/standard/flow-with-additional-includes/README.md index bf162d722fb..e49ce95438b 100644 --- a/examples/flows/standard/flow-with-additional-includes/README.md +++ b/examples/flows/standard/flow-with-additional-includes/README.md @@ -63,12 +63,20 @@ pf run create --file run.yml --stream #### Submit run to cloud +Assume we already have a connection named `open_ai_connection` in workspace. + +```bash +# set default workspace +az account set -s +az configure --defaults group= workspace= +``` + ``` bash # create run -# pfazure run create --flow . --data ./data.jsonl --stream --runtime demo-mir --subscription -g -w -# pfazure run create --flow . --data ./data.jsonl --stream # serverless compute -# pfazure run create --file run.yml --runtime demo-mir -# pfazure run create --file run.yml --stream # serverless compute +pfazure run create --flow . --data ./data.jsonl --stream --runtime demo-mir +# pfazure run create --flow . --data ./data.jsonl --stream # automatic runtime +pfazure run create --file run.yml --runtime demo-mir +# pfazure run create --file run.yml --stream # automatic runtime ``` -Note: Click portal_url of the run to view the final snapshot. \ No newline at end of file +Note: Click portal_url of the run to view the final snapshot. diff --git a/examples/flows/standard/flow-with-symlinks/README.md b/examples/flows/standard/flow-with-symlinks/README.md index 3471ffdc5b8..187191e8798 100644 --- a/examples/flows/standard/flow-with-symlinks/README.md +++ b/examples/flows/standard/flow-with-symlinks/README.md @@ -76,12 +76,12 @@ pf run create --file run.yml --stream ``` bash # create run pfazure run create --flow . --data ./data.jsonl --stream --runtime demo-mir --subscription -g -w -# pfazure run create --flow . --data ./data.jsonl --stream # serverless compute +# pfazure run create --flow . --data ./data.jsonl --stream # automatic runtime # set default workspace az account set -s az configure --defaults group= workspace= pfazure run create --file run.yml --runtime demo-mir --stream -# pfazure run create --file run.yml --stream # serverless compute +# pfazure run create --file run.yml --stream # automatic runtime ``` diff --git a/examples/flows/standard/web-classification/README.md b/examples/flows/standard/web-classification/README.md index 203730a4e75..a19fed957c6 100644 --- a/examples/flows/standard/web-classification/README.md +++ b/examples/flows/standard/web-classification/README.md @@ -96,15 +96,15 @@ az account set -s az configure --defaults group= workspace= # create run -pfazure run create --flow . --data ./data.jsonl --stream --runtime demo-mir --subscription -g -w -# pfazure run create --flow . --data ./data.jsonl --stream # serverless compute +pfazure run create --flow . --data ./data.jsonl --stream --runtime demo-mir +# pfazure run create --flow . --data ./data.jsonl --stream # automatic runtime # (Optional) create a new random run name for further use run_name="web_classification_"$(openssl rand -hex 12) # create run using yaml file, --name is optional pfazure run create --file run.yml --runtime demo-mir --name $run_name -# pfazure run create --file run.yml --stream --name $run_name # serverless compute +# pfazure run create --file run.yml --stream --name $run_name # automatic runtime pfazure run stream --name $run_name diff --git a/examples/tutorials/run-management/cloud-run-management.ipynb b/examples/tutorials/run-management/cloud-run-management.ipynb index 3b0d88057fe..bd21cbc2d13 100644 --- a/examples/tutorials/run-management/cloud-run-management.ipynb +++ b/examples/tutorials/run-management/cloud-run-management.ipynb @@ -18,7 +18,7 @@ "- create run which references another runs inputs\n", "- manage runs via run.yaml\n", "- create run with connection override\n", - "- serverless runtime\n", + "- automatic runtime\n", "\n", "\n", "**Motivations** - This guide will walk you through cloud run management abilities." @@ -310,6 +310,53 @@ "\n", "pf.runs.stream(base_run)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 4 Create a flow run with uses automatic runtime\n", + "\n", + "If you don't want to create your own runtime, you can leave the `runtime` field empty to use system automatic created runtime.\n", + "To customize base image or python packages, you can add the following config in your `flow.dag.yaml`:\n", + "\n", + "```yml\n", + "environment:\n", + " image: python:3.8-slim\n", + " python_requirements_txt: requirements.txt\n", + "```\n", + "\n", + "You can also change instance type or idle time of the automatic runtime or reset the automatic runtime to clean state.\n", + "The following code cell shows how to do so." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# create run\n", + "run = Run(\n", + " # local flow file\n", + " flow=\"../../flows/standard/web-classification\",\n", + " # remote data\n", + " data=data_id,\n", + " # to customize automatic runtime instance type and idle time, you can provide them in resources\n", + " # resources={\n", + " # \"instance_type\": \"STANDARD_DS11_V2\",\n", + " # \"idle_time_before_shutdown_minutes\": 10\n", + " # }\n", + ")\n", + "\n", + "base_run = pf.runs.create_or_update(\n", + " run=run,\n", + " # leave runtime None to use automatic runtime\n", + " runtime=None,\n", + " # to reset automatic runtime to clean state, set reset_runtime to True\n", + " # reset_runtime=True,\n", + ")" + ] } ], "metadata": {