Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge test_postgres to main #371

Merged
merged 58 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
2422bb7
Add postgres LLM demo
aamini7 Sep 9, 2024
2a5325f
Make scenario active
aamini7 Sep 9, 2024
f9fcd2f
Cleanup
aamini7 Sep 9, 2024
c14446d
Get rid of openai command
aamini7 Sep 9, 2024
4d379a6
Add promp
aamini7 Sep 9, 2024
13fa070
Fix command
aamini7 Sep 9, 2024
d237ad2
Remove prompt
aamini7 Sep 9, 2024
6e930f8
Fixes
aamini7 Sep 10, 2024
f0adf0e
More fixes
aamini7 Sep 10, 2024
f076b4f
Add requirements.txt
aamini7 Sep 10, 2024
c7aebb5
Add api key
aamini7 Sep 12, 2024
5d78942
Add final step
aamini7 Sep 12, 2024
71702fb
More fixes
aamini7 Sep 17, 2024
691834b
More fixes
aamini7 Sep 18, 2024
49a573c
More fixes
aamini7 Sep 18, 2024
d2487de
Remove line
aamini7 Sep 18, 2024
7ea6fe5
Remove all
aamini7 Sep 18, 2024
51e79b8
Fix bug
aamini7 Sep 18, 2024
9a69782
Final
aamini7 Sep 18, 2024
1f7c0fd
Add terms/conditions
aamini7 Sep 18, 2024
ed8d138
Add register command
aamini7 Sep 18, 2024
9ba23ae
Fix command
aamini7 Sep 18, 2024
be0bd9e
Re order
aamini7 Sep 18, 2024
72bc167
Add back commands
aamini7 Sep 18, 2024
93265df
Fix
aamini7 Sep 18, 2024
fcfc058
Change version
aamini7 Sep 18, 2024
1a7dc39
Update version
aamini7 Sep 18, 2024
7b9c76e
Fix region
aamini7 Sep 18, 2024
f5d0d3d
Fix recommended region
aamini7 Sep 18, 2024
4fbddc6
Fix wrong api version
aamini7 Sep 30, 2024
c92b98d
Initial
aamini7 Oct 4, 2024
09226c6
Update metadata
aamini7 Oct 4, 2024
9ca714a
Clean up
aamini7 Oct 4, 2024
c82c8a6
More fixes
aamini7 Oct 4, 2024
9c31e12
Add auto upgrade
aamini7 Oct 4, 2024
499bd74
More fixes
aamini7 Oct 4, 2024
d3aae38
Fix
aamini7 Oct 8, 2024
41bc09a
Test
aamini7 Oct 8, 2024
3ba3e11
Undo test
aamini7 Oct 8, 2024
be33e2f
Formatting fixes
aamini7 Oct 9, 2024
7034213
Remove service principal role
aamini7 Oct 9, 2024
7f38ec7
Change region
aamini7 Oct 9, 2024
20e9324
Fixes
aamini7 Oct 9, 2024
d2d938f
Reformat
aamini7 Oct 9, 2024
c409448
test
aamini7 Oct 9, 2024
c1ef721
test
aamini7 Oct 9, 2024
62c9137
Fixes
aamini7 Oct 10, 2024
bdeeade
More cleanup
aamini7 Oct 10, 2024
d054fa6
Fix bugs
aamini7 Oct 10, 2024
620e24b
Add back service principal
aamini7 Oct 10, 2024
b04f592
Fix
aamini7 Oct 10, 2024
c2da768
Forgot command
aamini7 Oct 10, 2024
5a6e48b
Fixes
aamini7 Oct 17, 2024
d0e74ea
PR fixes
aamini7 Oct 21, 2024
0a876f8
Kaito fixes
aamini7 Oct 22, 2024
a86194d
Remove step
aamini7 Oct 22, 2024
5d1b1ac
remove unused import
aamini7 Oct 22, 2024
378b9f7
Merge branch 'main' of https://github.com/MicrosoftDocs/executable-do…
aamini7 Oct 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 188 additions & 0 deletions scenarios/AksKaito/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
---
title: Deploy an AI model on Azure Kubernetes Service (AKS) with the AI toolchain operator (preview)
description: Learn how to enable the AI toolchain operator add-on on Azure Kubernetes Service (AKS) to simplify OSS AI model management and deployment.
ms.topic: article
ms.custom: azure-kubernetes-service, devx-track-azurecli
ms.date: 02/28/2024
author: schaffererin
ms.author: schaffererin

---

## Quickstart: Create a Linux virtual machine with the Azure CLI on Azure
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title needs to be updated


**Applies to:** :heavy_check_mark: Linux VMs

[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://go.microsoft.com/fwlink/?linkid=2262692)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the button since it is pertaining to the old doc


This quickstart shows you how to use the Azure CLI to deploy a Linux virtual machine (VM) in Azure. The Azure CLI is used to create and manage Azure resources via either the command line or scripts.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description change needed since this is a description of an older doc


If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.

## Deploy an AI model on Azure Kubernetes Service (AKS) with the AI toolchain operator (preview)

The AI toolchain operator (KAITO) is a managed add-on for AKS that simplifies the experience of running OSS AI models on your AKS clusters. The AI toolchain operator automatically provisions the necessary GPU nodes and sets up the associated inference server as an endpoint server to your AI models. Using this add-on reduces your onboarding time and enables you to focus on AI model usage and development rather than infrastructure setup.

This article shows you how to enable the AI toolchain operator add-on and deploy an AI model on AKS.

[!INCLUDE [preview features callout](~/reusable-content/ce-skilling/azure/includes/aks/includes/preview/preview-callout.md)]

## Before you begin

* This article assumes a basic understanding of Kubernetes concepts. For more information, see [Kubernetes core concepts for AKS](./concepts-clusters-workloads.md).
* For ***all hosted model inference images*** and recommended infrastructure setup, see the [KAITO GitHub repository](https://github.com/Azure/kaito).
* The AI toolchain operator add-on currently supports KAITO version **v0.1.0**, please make a note of this in considering your choice of model from the KAITO model repository.

## Prerequisites

* If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
* If you have multiple Azure subscriptions, make sure you select the correct subscription in which the resources will be created and charged using the [az account set](https://learn.microsoft.com/en-us/cli/azure/account?view=azure-cli-latest#az-account-set) command.

> [!NOTE]
> The subscription you use must have GPU VM quota.

* Azure CLI version 2.47.0 or later installed and configured. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI](/cli/azure/install-azure-cli).
* The Kubernetes command-line client, kubectl, installed and configured. For more information, see [Install kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/).
* [Install the Azure CLI AKS preview extension](#install-the-azure-cli-preview-extension).
* [Register the AI toolchain operator add-on feature flag](#register-the-ai-toolchain-operator-add-on-feature-flag).

## Set up resource group

Set up a resource group with a random ID. Create an Azure resource group using the [az group create](https://learn.microsoft.com/en-us/cli/azure/group?view=azure-cli-latest#az-group-create) command.

```bash
export RANDOM_ID="$(openssl rand -hex 3)"
export AZURE_RESOURCE_GROUP="myKaitoResourceGroup$RANDOM_ID"
export REGION="centralus"
export CLUSTER_NAME="myClusterName$RANDOM_ID"
export SUBSCRIPTION_ID="0c8875c7-e423-4caa-827a-1f0350bd8dd3"

az group create \
--name $AZURE_RESOURCE_GROUP \
--location $REGION \
```

## Install the Azure CLI preview extension

Install the Azure CLI preview extension using the [az extension add](https://learn.microsoft.com/en-us/cli/azure/extension?view=azure-cli-latest#az-extension-add) command. Then update the extension to make sure you have the latest version using the [az extension update](https://learn.microsoft.com/en-us/cli/azure/extension?view=azure-cli-latest#az-extension-update) command.

```bash
az extension add --name aks-preview
az extension update --name aks-preview
```

## Register the AI toolchain operator add-on feature flag

Register the AIToolchainOperatorPreview feature flag using the az feature register command.
It takes a few minutes for the registration to complete.

```bash
az feature register --namespace "Microsoft.ContainerService" --name "AIToolchainOperatorPreview"
```

## Verify the AI toolchain operator add-on registration

Verify the registration using the [az feature show](https://learn.microsoft.com/en-us/cli/azure/feature?view=azure-cli-latest#az-feature-show) command.

```bash
while true; do
status=$(az feature show --namespace "Microsoft.ContainerService" --name "AIToolchainOperatorPreview" --query "properties.state" -o tsv)
if [ "$status" == "Registered" ]; then
break
else
sleep 15
fi
done
```

## Create an AKS cluster with the AI toolchain operator add-on enabled

Create an AKS cluster with the AI toolchain operator add-on enabled using the [az aks create](https://learn.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest#az-aks-create) command with the `--enable-ai-toolchain-operator` and `--enable-oidc-issuer` flags.

```bash
az aks create --location ${REGION} \
--resource-group ${AZURE_RESOURCE_GROUP} \
--name ${CLUSTER_NAME} \
--enable-oidc-issuer \
--node-os-upgrade-channel SecurityPatch \
--auto-upgrade-channel stable \
--enable-ai-toolchain-operator \
--generate-ssh-keys \
--k8s-support-plan KubernetesOfficial
```

## Connect to your cluster

Configure `kubectl` to connect to your cluster using the [az aks get-credentials](https://learn.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest#az-aks-get-credentials) command.

```bash
az aks get-credentials --resource-group ${AZURE_RESOURCE_GROUP} --name ${CLUSTER_NAME}
```

## Create role assignment for the service principal

```bash
export MC_RESOURCE_GROUP=$(az aks show --resource-group ${AZURE_RESOURCE_GROUP} \
--name ${CLUSTER_NAME} \
--query nodeResourceGroup \
-o tsv)

export KAITO_IDENTITY_NAME="ai-toolchain-operator-${CLUSTER_NAME}"

export AKS_OIDC_ISSUER=$(az aks show --resource-group "${AZURE_RESOURCE_GROUP}" \
--name "${CLUSTER_NAME}" \
--query "oidcIssuerProfile.issuerUrl" \
-o tsv)

export PRINCIPAL_ID=$(az identity show --name "ai-toolchain-operator-${CLUSTER_NAME}" \
--resource-group "${MC_RESOURCE_GROUP}" \
--query 'principalId' \
-o tsv)

az role assignment create --role "Contributor" \
--assignee "${PRINCIPAL_ID}" \
--scope "/subscriptions/${SUBSCRIPTION_ID}/resourcegroups/${AZURE_RESOURCE_GROUP}"
```

## Establish a federated identity credential

Create the federated identity credential between the managed identity, AKS OIDC issuer, and subject using the [az identity federated-credential create](https://learn.microsoft.com/en-us/cli/azure/identity/federated-credential?view=azure-cli-latest) command.

```bash
az identity federated-credential create --name "kaito-federated-identity" \
--identity-name "${KAITO_IDENTITY_NAME}" \
-g "${MC_RESOURCE_GROUP}" \
--issuer "${AKS_OIDC_ISSUER}" \
--subject system:serviceaccount:"kube-system:kaito-gpu-provisioner" \
--audience api://AzureADTokenExchange
```

## Verify that your deployment is running

Restart the KAITO GPU provisioner deployment on your pods using the `kubectl rollout restart` command:

```bash
kubectl rollout restart deployment/kaito-gpu-provisioner -n kube-system
```

## Deploy a default hosted AI model

Deploy the Falcon 7B-instruct model from the KAITO model repository using the `kubectl apply` command.

```bash
kubectl apply -f https://raw.githubusercontent.com/Azure/kaito/main/examples/inference/kaito_workspace_falcon_7b-instruct.yaml
```

## Ask a question

Verify deployment done: `kubectl get workspace workspace-falcon-7b-instruct -w`.
Store IP: `export SERVICE_IP=$(kubectl get svc workspace-falcon-7b-instruct -o jsonpath='{.spec.clusterIP}')`.
Ask question: `kubectl run -it --rm --restart=Never curl --image=curlimages/curl -- curl -X POST http://$SERVICE_IP/chat -H "accept: application/json" -H "Content-Type: application/json" -d "{\"prompt\":\"YOUR QUESTION HERE\"}"`

```bash
echo "See last step for details on how to ask questions to the model."
```

## Next steps

For more inference model options, see the [KAITO GitHub repository](https://github.com/Azure/kaito).
139 changes: 139 additions & 0 deletions scenarios/PostgresRagLlmDemo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
title: 'Quickstart: Deploy a Postgres vector database'
description: Setup a Postgres vector database and openai resources to run a RAG-LLM model.
ms.topic: quickstart
ms.date: 09/06/2024
author: aamini7
ms.author: ariaamini
ms.custom: innovation-engine, linux-related-content
---

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add an intro/some description around the scenario

## Set up resource group

Set up a resource group with a random ID.

```bash
export RANDOM_ID="$(openssl rand -hex 3)"
export RG_NAME="myPostgresResourceGroup$RANDOM_ID"
export REGION="centralus"

az group create \
--name $RG_NAME \
--location $REGION \
```

## Create OpenAI resources

Create the openai resource

```bash
export OPEN_AI_SERVICE_NAME="openai-service-$RANDOM_ID"
export EMBEDDING_MODEL="text-embedding-ada-002"
export CHAT_MODEL="gpt-4-turbo-2024-04-09"

az cognitiveservices account create \
--name $OPEN_AI_SERVICE_NAME \
--resource-group $RG_NAME \
--location westus \
--kind OpenAI \
--sku s0 \
```

## Create OpenAI deployments

```bash
export EMBEDDING_MODEL="text-embedding-ada-002"
export CHAT_MODEL="gpt-4"

az cognitiveservices account deployment create \
--name $OPEN_AI_SERVICE_NAME \
--resource-group $RG_NAME \
--deployment-name $EMBEDDING_MODEL \
--model-name $EMBEDDING_MODEL \
--model-version "2" \
--model-format OpenAI \
--sku-capacity "1" \
--sku-name "Standard"

az cognitiveservices account deployment create \
--name $OPEN_AI_SERVICE_NAME \
--resource-group $RG_NAME \
--deployment-name $CHAT_MODEL \
--model-name $CHAT_MODEL \
--model-version "turbo-2024-04-09" \
--model-format OpenAI \
--sku-capacity "1" \
--sku-name "Standard"
```

## Create Database

Create an Azure postgres database.

```bash
export POSTGRES_SERVER_NAME="mydb$RANDOM_ID"
export PGHOST="${POSTGRES_SERVER_NAME}.postgres.database.azure.com"
export PGUSER="dbadmin$RANDOM_ID"
export PGPORT=5432
export PGDATABASE="azure-ai-demo"
export PGPASSWORD="$(openssl rand -base64 32)"

az postgres flexible-server create \
--admin-password $PGPASSWORD \
--admin-user $PGUSER \
--location $REGION \
--name $POSTGRES_SERVER_NAME \
--database-name $PGDATABASE \
--resource-group $RG_NAME \
--sku-name Standard_B2s \
--storage-auto-grow Disabled \
--storage-size 32 \
--tier Burstable \
--version 16 \
--yes -o JSON \
--public-access 0.0.0.0
```

## Enable postgres vector extension

Set up the vector extension for postgres to allow storing vectors/embeddings.

```bash
az postgres flexible-server parameter set \
--resource-group $RG_NAME \
--server-name $POSTGRES_SERVER_NAME \
--name azure.extensions --value vector

psql -c "CREATE EXTENSION IF NOT EXISTS vector;"

psql \
-c "CREATE TABLE embeddings(id int PRIMARY KEY, data text, embedding vector(1536));" \
-c "CREATE INDEX ON embeddings USING hnsw (embedding vector_ip_ops);"
```

## Populate with data from knowledge file

The chat bot uses a local file called "knowledge.txt" as the sample document to generate embeddings for
and to store those embeddings in the newly created postgres database. Then any questions you ask will
be augmented with context from the "knowledge.txt" after searching the document for the most relevant
pieces of context using the embeddings. The "knowledge.txt" is about a fictional material called Zytonium.
You can view the full knowledge.txt and the code for the chatbot by looking in the "scenarios/PostgresRagLlmDemo" directory.

```bash
export ENDPOINT=$(az cognitiveservices account show --name $OPEN_AI_SERVICE_NAME --resource-group $RG_NAME | jq -r .properties.endpoint)
export API_KEY=$(az cognitiveservices account keys list --name $OPEN_AI_SERVICE_NAME --resource-group $RG_NAME | jq -r .key1)

cd ~/scenarios/PostgresRagLlmDemo
pip install -r requirements.txt
python chat.py --populate --api-key $API_KEY --endpoint $ENDPOINT --pguser $PGUSER --phhost $PGHOST --pgpassword $PGPASSWORD --pgdatabase $PGDATABASE
```

## Run Chat bot

This final step prints out the command you can copy/paste into the terminal to run the chatbot. `cd ~/scenarios/PostgresRagLlmDemo && python chat.py --api-key $API_KEY --endpoint $ENDPOINT --pguser $PGUSER --phhost $PGHOST --pgpassword $PGPASSWORD --pgdatabase $PGDATABASE`

```bash
echo "
To run the chatbot, see the last step for more info.
"
```
Loading
Loading