microsoft / mlops-promptflow-prompt

MLOps for PromptFlow SDK
MIT License
32 stars 2 forks source link

MLOps for PromptFlow Workloads using AI Studio

This repository demonstrates how AI Studio and Prompt flow can be utilized in the Machine Learning Development and Operations (MLOps) process for LLM-based applications (aka LLMOps).

During the Microsoft Build 2024 conference, Azure AI Studio was announced in GA. Prompt flow also received several new features, including Prompty, traces, flex flows, an ability to execute a DAG flow as a function, and new evaluation capabilities. All these features bring additional opportunities for data scientists and software engineers in all aspects of MLOps, starting from the experimentation phase to deployment into production.

The goal of this repository is to provide a good enough set of samples and “how to” instructions that can be used as a set of building blocks for real projects. The repository doesn’t recommend the only way to achieve your goals, and the building blocks can be picked based on your personal preferences (for example, it’s possible to develop the same flow using a function, class or YAML-based approaches) or based on available infrastructure or requirements.

Folder Structure.

The repository has the following folders (provided in logical rather than alphabetic sequence):

Additionally, the root folder contains some important files:

Prompt flow Examples.

The repository shows three different flows; some are implemented using various approaches. Comparing implementations of the same flow should help you see differences.

Local Environment.

Most of the scripts in the repository can be executed locally. We recommend setting up a separate Conda environment based on requirements.txt at the repo's root. This document provides step-by-step instructions for setting up a local Conda environment. Additionally, we are providing a Docker image that can be used as a development environment in VS Code.

Configuration and Local Run.

Azure OpenAI should be available to start running the flows locally. The following models should be deployed:

Deployment names can be provided in config.yaml for each flow/environment you plan to execute. The parameters AOAI_BASE_ENDPOINT and AOAI_API_KEY should be provided in the .env file. To use Bing search as part of the plan, the plan and execution flows require BING_API_KEY. Having just these parameters, you can execute all the flows locally. It can be done from the root of the repo using the following commands:

python -m mlops.run_chat_with_pdf --environment_name pr –visualize
python -m mlops.run_class_basic_flow --environment_name pr --visualize
python -m mlops.run_class_plan_and_execute --environment_name pr --visualize
python -m mlops.run_function_basic_flow --environment_name pr --visualize
python -m mlops.run_yaml_basic_flow --environment_name pr --visualize
python -m mlops.yaml_plan_and_execute --environment_name pr --visualize

We use the --visualize parameter to open traces in your default browser. Skip this parameter if you don’t need this behaviour.

We use the --environment_name parameter to provide information about which section of the config.yaml file configuration parameters should be taken. For example, in the case of the class_basic_flow and pr environment, the class_basic_flow_pr section will be used. You can define your sections for QA, prod, and other environments.

Pay attention to the fact that each script shows how to invoke flow using several different methods, starting with an invocation on a single record and ending with batch execution. This is necessary to show how to use the flow in various scenarios.

An AI Studio project should be deployed to log traces into AI Studio and run evaluation. Add three more parameters into the .env file that is related to the project: SUBSCRIPTION_ID, RESOURCE_GROUP_NAME and PROJECT_NAME. Right after that, you can use the --deploy_traces parameter that will enable tracing deployment into the cloud:

python -m mlops.run_class_basic_flow --environment_name pr --deploy_traces

The following commands show how to execute evaluation flow for class_basic_flow in the pr environment:

python -m flows.class_basic_flow.evaluate.evaluate --environment_name pr

Execution in the cloud.

Several scripts demonstrate how to run flow batches in Azure using serverless compute. To run these scripts, all required connections should be created in AI Studio, and their names should be provided in config.yaml.

Data can be used from a local disk or uploaded into AI Studio manually or using the register_data_assets.py script (or an AzDO pipeline or GitHub workflow register_data_assets.yml as part of the MLOps process). If you are using data in AI Studio, config.yaml should contain correct references to datasets in AI Studio.

The following command demonstrates how to invoke class_basic_flow in Azure as a batch:

python -m mlops.run_class_basic_flow_azure --environment_name pr

Pay attention to the fact that the new evaluation package doesn’t allow the execution of evaluations in the cloud now.

DevOps Pipelines for Pull Requests.

Each flow has its own Azure DevOps pipeline and GitHub workflow that should be invoked for every Pull Request that affects the flow's code or related scripts. For example, for class_basic_flow, we have the class_basic_flow_pr.yml GitHub workflow. The workflow executes quality checks using flake8 and unit tests and evaluates the flow. This set of actions should be good enough for most projects to decide whether the PR may be approved.

Some variables should be provided to execute PR builds (primarily the same ones used in the .env file for local execution). Repository variables:

GitHub Variables

Repository secrets:

GitHub Secrets

In the case of Azure DevOps, we are using the mlops_platform_dev_vg variable group:

AzDO Variables

CI DevOps Pipeline.

TODO: This content will be available shortly.

How to...

TODO: This content will be available shortly.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.