Deploying a Large Language Model (GPT-2) on Azure Using Power Automate: Step-by-Step Guide

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Community Hub.

I'm John Aziz a Gold Microsoft Learn Student Ambassador from Egypt, and a session lead at Udacity passionate about utilizing Microsoft tools to make cool tools.

Feel free to connect with me on:

 

Technical Overview

In this demo, I will guide you through deploying a Large Language Model (GPT-2) to the Azure platform and using Power Automate to consume its endpoint, make requests, and ingest responses. In addition, We will use the Power Apps template that I created to display the generated text and give you creative writing ideas.

 

Drawing (2).png

 

Prerequisites:

An Azure subscription.

A Power Apps environment.

Solution File from GitHub.

Summary of the steps:

Step 1: Open your Azure Portal and Sign in
Step 2: Create an Azure Machine Learning Workspace
Step 3: Deploy a Machine Learning Model using templates
Step 4: Open Power Apps and Import the Solution

Step 5: Edit the Power Automate Flow

Step 6: Publish your Power App

 

Step 1: Open your Azure Portal and Sign in

Go to https://portal.azure.com and sign in.

LeeStott_0-1686207594745.png

 

Choose your preferred account and proceed

Now you are inside the Azure portal!

LeeStott_3-1686214508976.png

 

Step 2: Create an Azure Machine Learning Workspace

Search for Azure Machine Learning and select it.

first screenshot.png

 

Click on Create and choose New Workspace to create a new machine learning workspace.

second screenshot.png

 

What do you need to create it?

  • Azure Subscription (All resources in an Azure subscription are billed together. Learn more: here)
  • Azure Resource Group (A resource group is a collection of resources that share the same life cycle, permissions, and policies. Learn more: here)
  • Workspace Name (Unique name that matches the constraints for naming on Azure)
  • Region (Choose the region closest to you and your customers. Learn more: here)
  • Storage Account (A storage account is used as the default datastore for the workspace. You may create a new Azure Storage resource or select an existing one in your subscription. Learn more: here)
  • Key vault (A key vault is used to store secrets and other sensitive information that is needed by the workspace. You may create a new Azure Key Vault resource or select an existing one in your subscription. Learn more: here)
  • Application Insights (The workspace uses Azure Application Insights to store monitoring information about your deployed models. You may create a new Azure Application Insights resource or select an existing one in your subscription. Learn more: here)
  • Container Registry (A container registry is used to register docker images used in training and deployments. To minimize costs, a new Azure Container Registry resource is created only after you build your first image. Alternatively, you may choose to create the resource now or select an existing one in your subscription. Learn more: here)

For simplicity, we will click on Create new for the resource group, provide a name, click on Ok then provide a name for the workspace and all the other options will be automatically populated for us if you want to learn more about each option you may look at the attached links above.

 

then Click Review + Create.

third screenshot.png

 

Wait for the deployment to finish then click on Go to resource.

fourth screenshot.png

Step 3: Deploy a Machine Learning Model using templates

Open the Azure Machine Learning Studio using the Studio web URL.

fifth screenshot.png

 

 

 

Click on All Workpaces to access the shard resources in your tenant.

sixth screenshot.png

 

Click on Models under the Shared Assets from the left side menu to choose the LLM template that we want to deploy.

seventh screenshot.png

Here you can find binary files for different machine learning models trained with specific algorithms on training datasets and then able to produce predictions and inferences on additional, larger datasets provided by AzureML and HugginingFace.

 

For this demo, we will choose GPT-2 for text generation this model can be used for different applications like sentiment analysis and many more.

You will see how easy it is to deploy any of these models and use them you may want to try other models later but for this time let's stick to the instructions.

 

Click on gpt-2 then choose Deploy then Choose Real-time endpoint as we need our inferences in real time not a batch job.

eighth screenshot.png

Choose your subscription and the workspace we created together before then Click on Proceed to workspace.

nineth screenshot.png

What do you need to deploy a model?

  • Virtual Machine (to host the model and run its code. Learn more: here)
  • Instance Count (The number of instances to use for the deployment. Specify the value based on the workload you expect. For high availability, Microsoft recommends you set it to at least 3)
  • Endpoint Name (An endpoint is an HTTPS path that provides an interface for clients to send requests (input data) and receive the inferencing (scoring) output of a trained model. It provides authentication, SSL termination, and a stable scoring URI. Learn more: here)
  • Deployment Name (Deployments are hosted within an endpoint, and can receive data from clients and send responses back in real-time.)

For the sake of simplicity leave all the default options and Click on Deploy you make check it later and test it.

tenth screenshot.png

 

Move to the next step until the deployment is created as it will take a couple of minutes.

 

Step 4: Open Power Apps and Import the Solution

Fork this repo https://github.com/John0Isaac/help-me-write-aml-powerapp, I created a simple App using Power Apps and a Cloud Flow using Power Automate which are found in a Zip file inside a folder names HelpMeWrite Solution.

 

eleventh screenshot.png

 

then Clone the Repo to have the files available locally.

 

twelveth screenshot.png

Open Power Apps using this link https://make.powerapps.com/.

thirteenth screenshot.png

 

Click on More from the left side window then Choose Solutions.

fourteenth screenshot.png

 

Click on Import Solution to load the Zip file that we cloned.

 

fifteenth screenshot.png

 

Click on Browse and Choose the Zip File that we cloned then Click on Open and Next.

sixteenth screenshot.png

 

After it finishes processing Click on Import and wait for a couple of minutes.

 

You can now find a Solution named AML PowerApps HelpMeWrite Sample in the solutions table ready for you to use.

seventeenth screenshot.png

 

Step 5: Edit the Power Automate Flow

Click on the Solution Display Name to open it, then Click on the Canvas App to Open the application in edit mode.

 

eighteenth screenshot.png

Now you can edit the application if you want to change colors, fonts, and backgrounds or leave it as it is and continue by clicking on Power Automate from the left side menu.

nineteenth screenshot.png

 

Hover over the flow name (HelpMeWriteFlow) and from the three dots Click on Edit.

twentyth screenshot.png

 

Go back to your Azure Machine Learning Studio in the endpoints tab you will find that the deployment has finished it should look like the image below.

 

twenty two screenshot.png

 

Click on Consume and get the REST endpoint which is the ML Endpoint we will use in our Power Automate Flow and any of the two authentication keys available for you to use as our ML API Key in Power Automate Flow.

twenty three screenshot.png

 

Go back to Power Automate and Add the values you copied in the places shown below then Click on Save and Close the flow from the X button.

twenty one screenshot.png

 

Step 6: Publish your Power App

Now let's preview our application to test if everything works Click on the Play button from the Navigation Menu or (F5).

 

twenty four screenshot.png

 

Enter any text in the Text Input box then Click on Generate and Wait for the magic to happen.

twenty five screenshot.png

 

The last step is to save our changes and publish them by Clicking on Save Icon from the Navigation Menu and waiting until it finishes saving then Clicking on the Publish Icon from the same Menu.

 

twenty six screenshot.png

 

Now you can find the application in your Microsoft 365 Online Apps section. https://www.office.com/apps 

twenty seven screenshot.png

 

You can share your application with anyone inside your Organization.
twenty eight screenshot.png

 

Thank you so much for following along...

 

You can learn more at:

See you in future demos!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.