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

UpdatingCLIAzureMLNIMDeployment_for_demo #99

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 31 additions & 3 deletions cloud-service-providers/azure/azureml/cli/1_set_credentials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,46 @@
set -x
source config.sh

CREATE_RESOURCE_GROUP=false
CREATE_CONTAINER_REGISTRY=false
CREATE_WORKSPACE=false

for i in "$@"; do
case $i in
--create_new_workspace) CREATE_WORKSPACE=true ;;
-*|--*) echo "Unknown option $i"; exit 1 ;;
--create_new_resource_group)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove the create resource group flag? I think it is safe to assume that users will already have a resource group to deploy this on.

Copy link
Author

Choose a reason for hiding this comment

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

I actually dont think it is safe.

Its a bit redundant but it makes the script to work even when the user does not have a work group for the workspace

I for instance like to create a worksgroup for every single project/test I do as it is way easier to delete resources by workgroup than individually

CREATE_RESOURCE_GROUP=true
shift # past argument with no value
;;
--create_new_container_registry)
CREATE_CONTAINER_REGISTRY=true
shift # past argument with no value
;;
--create_new_workspace)
CREATE_WORKSPACE=true
shift # past argument with no value
;;
-*|--*)
echo "Unknown option $i"
exit 1
;;
*)
;;
esac
done

# Create new resource group
if $CREATE_RESOURCE_GROUP; then
az group create --name $resource_group --location $location
fi

# Create new container registry
if $CREATE_CONTAINER_REGISTRY; then
az acr create --resource-group $resource_group --name $acr_registry_name --sku Basic
fi

# Create new workspace
if $CREATE_WORKSPACE; then
az ml workspace create --name $workspace --resource-group $resource_group --location $location
az ml workspace create --name $workspace --resource-group $resource_group --location $location --container-registry /subscriptions/${subscription_id}/resourceGroups/${resource_group}/providers/Microsoft.ContainerRegistry/registries/${acr_registry_name}
fi

# Assign role permission to read secrets from workspace connections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source config.sh
# Create new endpoint in this workspace
cp azureml_files/endpoint.yml actual_endpoint_aml.yml
# sed -i "s/endpoint_name_placeholder/${endpoint_name}/g" actual_endpoint_aml.yml
sed -i '' "s|endpoint_name_placeholder|$endpoint_name|g" actual_endpoint_aml.yml
sed -i "s|endpoint_name_placeholder|$endpoint_name|g" actual_endpoint_aml.yml
echo "Creating Online Endpoint ${endpoint_name}"
az ml online-endpoint create -f actual_endpoint_aml.yml --resource-group $resource_group --workspace-name $workspace
rm actual_endpoint_aml.yml
12 changes: 6 additions & 6 deletions cloud-service-providers/azure/azureml/cli/5_create_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ cp azureml_files/deployment.yml actual_deployment_aml.yml
connection_path="\${{azureml://connections/ngc/credentials/NGC_API_KEY}}"

# Replace placeholders in the actual_deployment_aml.yml file
sed -i '' "s|ngc_api_key_placeholder|${connection_path}|g" actual_deployment_aml.yml
sed -i '' "s|endpoint_name_placeholder|$endpoint_name|g" actual_deployment_aml.yml
sed -i '' "s|deployment_name_placeholder|$deployment_name|g" actual_deployment_aml.yml
sed -i '' "s|acr_registry_placeholder|$acr_registry_name|g" actual_deployment_aml.yml
sed -i '' "s|image_name_placeholder|$image_name|g" actual_deployment_aml.yml
sed -i '' "s|instance_type_placeholder|$instance_type|g" actual_deployment_aml.yml
sed -i "s|ngc_api_key_placeholder|${connection_path}|g" actual_deployment_aml.yml
sed -i "s|endpoint_name_placeholder|$endpoint_name|g" actual_deployment_aml.yml
sed -i "s|deployment_name_placeholder|$deployment_name|g" actual_deployment_aml.yml
sed -i "s|acr_registry_placeholder|$acr_registry_name|g" actual_deployment_aml.yml
sed -i "s|image_name_placeholder|$image_name|g" actual_deployment_aml.yml
sed -i "s|instance_type_placeholder|$instance_type|g" actual_deployment_aml.yml

# Display the modified file
cat actual_deployment_aml.yml
Expand Down
23 changes: 13 additions & 10 deletions cloud-service-providers/azure/azureml/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ az account set -s ${subscription_id}

## Setup AzureML Workspace

Create a new AzureML workspace with the "Azure ML Secrets Reader" role assignment. All necessary commands are provided in the `1_setup_credentials.sh` script file.
The deployment procedure requires an Azure AI Workspace with an associated Azure AI private container registry. The workspace will also require to assign the "Azure ML Secrets Reader" role assignment to the user. The user could use any pre-existent workspace with those characteristics, populating accordingly the names of the resource group, container registry name and workspace name in the config.sh file.

The `1_setup_credentials.sh` script file, provides the role assigment, optionally it can create the necessary resource group, container registry and workspace (with the required association to the container registry, all using the names provided in the config.sh file) by the use of flags `--create_new_resource_group`, `--create_new_container_registry` and `--create_new_workspace` respectively.

Create a new AzureML resource group, container registry and workspace (if needed) with the "Azure ML Secrets Reader" role assignment. All necessary commands are provided in the `1_setup_credentials.sh` script file.

```bash
./1_setup_credentials.sh --create_new_workspace
./1_setup_credentials.sh --create_new_resource --create_new_container_registry --create_new_workspace
```

The above command creates a new workspace with the workspace name provided in the `config.sh` file. If the workspace name already exists, omit the `--create_new_workspace` flag to skip the creation process and update the workspace with the necessary role assignments.

## Store NGC API Key for Use in the AzureML Deployment

The NGC API Key needs to be stored within Azure so the AzureML workspace can access it during deployment. The API key is required to pull the correct model from the NGC model catalog. The key can be stored in Azure Key Vault or provided as a workspace connection to the AzureML workspace.
Expand Down Expand Up @@ -87,7 +89,7 @@ Required commands are provided in the `5_create_deployment.sh` script.
./5_create_deployment.sh
```

## Verify Your Connection
## Querying the model

Verify your deployment using the `test_chat_completions.sh` script. Modify the URL to your endpoint URL and add the following headers:
`-H 'Authorization: Bearer <your-azureml-endpoint-token>' -H 'azureml-model-deployment: <your-azureml-model-deployment-name>'`
Expand All @@ -96,9 +98,10 @@ For example:

```bash
curl -X 'POST' \
'https://llama3-8b-nim-endpoint-aml-1.westeurope.inference.ml.azure.com/v1/chat/completions' \
'https://llama3-8b-nim-endpoint-aml-1.southcentralus.inference.ml.azure.com/v1/chat/completions' \
-H 'accept: application/json' \
-H 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxx' \
-H 'Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' \
-H 'azureml-model-deployment: llama3-8b-nim-deployment-aml-1' \
-H 'Content-Type: application/json' \
-d '{
"messages": [
Expand All @@ -112,11 +115,11 @@ curl -X 'POST' \
}
],
"model": "meta/llama3-8b-instruct",
"max_tokens": 16,
"max_tokens": 400,
"top_p": 1,
"n": 1,
"stream": false,
"stop": "\n",
"frequency_penalty": 0.0
}'
```
```

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: deployment_name_placeholder
endpoint_name: endpoint_name_placeholder
environment:
name: image_name_placeholder-env
image: acr_registry_placeholder.azurecr.io/image_name_placeholder:v1
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove "latest" and mention "tag" instead to make it generalized.

Copy link
Author

Choose a reason for hiding this comment

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

When using the v1 it was crashing

Copy link
Author

Choose a reason for hiding this comment

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

I tried the way it was and the deployment was throwing errors as it couldn't find the image, the errors went away with latest

image: acr_registry_placeholder.azurecr.io/image_name_placeholder:latest
inference_config:
liveness_route:
path: /v1/health/ready
Expand Down