Skip to content

Commit 65db51f

Browse files
Merge pull request #321 from microsoft/psl-gpt-quota-check
feat: feature to check quota availability before deploying the accelerator
2 parents 6e06810 + ea0e55b commit 65db51f

File tree

4 files changed

+313
-9
lines changed

4 files changed

+313
-9
lines changed

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ The sample data used in this repository is synthetic and generated using Azure O
3939
QUICK DEPLOY
4040
</h2>
4141

42-
| [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/microsoft/Conversation-Knowledge-Mining-Solution-Accelerator) | [![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/Conversation-Knowledge-Mining-Solution-Accelerator) | [![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fmicrosoft%2FConversation-Knowledge-Mining-Solution-Accelerator%2Fmain%2Finfra%2Fmain.json) |
43-
|---|---|---|
44-
45-
46-
4742
### **Prerequisites**
4843

4944
To deploy this solution accelerator, ensure you have access to an [Azure subscription](https://azure.microsoft.com/free/) with the necessary permissions to create **resource groups and resources**. Follow the steps in [Azure Account Set Up](./docs/AzureAccountSetUp.md)
@@ -60,7 +55,13 @@ Check the [Azure Products by Region](https://azure.microsoft.com/en-us/explore/g
6055

6156
Here are some example regions where the services are available: East US, East US2, Australia East, UK South, France Central.
6257

58+
### ⚠️ Important: Check Azure OpenAI Quota Availability
59+
60+
➡️ To ensure sufficient quota is available in your subscription, please follow **[Quota check instructions guide](./docs/quota_check.md)** before you deploy the solution.
6361

62+
| [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/microsoft/Conversation-Knowledge-Mining-Solution-Accelerator) | [![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/Conversation-Knowledge-Mining-Solution-Accelerator) | [![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fmicrosoft%2FConversation-Knowledge-Mining-Solution-Accelerator%2Fmain%2Finfra%2Fmain.json) |
63+
|---|---|---|
64+
6465
### **Configurable Deployment Settings**
6566

6667
When you start the deployment, most parameters will have **default values**, but you can update the following settings:
@@ -84,10 +85,6 @@ By default, the **GPT model capacity** in deployment is set to **30k tokens**.
8485
8586
To adjust quota settings, follow these [steps](./docs/AzureGPTQuotaSettings.md)
8687

87-
88-
**⚠️ Warning:** **Insufficient quota can cause deployment errors.** Please ensure you have the recommended capacity or request for additional capacity before deploying this solution.
89-
90-
9188
### Deployment Options
9289
Pick from the options below to see step-by-step instructions for: GitHub Codespaces, VS Code Dev Containers, Local Environments, and Bicep deployments.
9390

docs/quota_check.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## Check Quota Availability Before Deployment
2+
3+
Before deploying the accelerator, **ensure sufficient quota availability** for the required model.
4+
Use one of the following scripts based on your needs:
5+
6+
- **`quota_check_params.sh`** → If you **know the model and capacity** required.
7+
- **`quota_check_all_regions.sh`** → If you **want to check available capacity across all regions** for supported models.
8+
9+
---
10+
## **If using Azure Portal and Cloud Shell**
11+
12+
1. Navigate to the [Azure Portal](https://portal.azure.com).
13+
2. Click on **Azure Cloud Shell** in the top right navigation menu.
14+
3. Run the appropriate command based on your requirement:
15+
16+
**To check quota for a specific model and capacity:**
17+
18+
```sh
19+
curl -L -o quota_check_params.sh "https://raw.githubusercontent.com/microsoft/Conversation-Knowledge-Mining-Solution-Accelerator/main/infra/scripts/quota_check_params.sh"
20+
chmod +x quota_check_params.sh
21+
./quota_check_params.sh <model_name:capacity> [<model_region>] (e.g., gpt-4o-mini:30,text-embedding-ada-002:20 eastus)
22+
```
23+
24+
**To check available quota across all regions for supported models:**
25+
26+
```sh
27+
curl -L -o quota_check_all_regions.sh "https://raw.githubusercontent.com/microsoft/Conversation-Knowledge-Mining-Solution-Accelerator/main/infra/scripts/quota_check_all_regions.sh"
28+
chmod +x quota_check_all_regions.sh
29+
./quota_check_all_regions.sh
30+
```
31+
32+
## **If using VS Code or Codespaces**
33+
34+
1. Run the appropriate script based on your requirement:
35+
36+
**To check quota for a specific model and capacity:**
37+
38+
```sh
39+
./quota_check_params.sh <model_name:capacity> [<model_region>] (e.g., gpt-4o-mini:30,text-embedding-ada-002:20 eastus)
40+
```
41+
42+
**To check available quota across all regions for supported models:**
43+
44+
```sh
45+
./quota_check_all_regions.sh
46+
```
47+
2. If you see the error `_bash: az: command not found_`, install Azure CLI:
48+
49+
```sh
50+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
51+
az login
52+
```
53+
3. Rerun the script after installing Azure CLI.
54+
55+
**Parameters**
56+
- `<model_name:capacity>`: The name and required capacity for each model, in the format model_name:capacity (**e.g., gpt-4o-mini:30,text-embedding-ada-002:20**).
57+
- `[<model_region>] (optional)`: The Azure region to check first. If not provided, all supported regions will be checked (**e.g., eastus**).
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
#!/bin/bash
3+
4+
# Pre-defined list of models to check
5+
MODEL_NAMES=("gpt-4o" "gpt-4o-mini" "text-embedding-ada-002" "gpt-3.5-turbo" "gpt-4")
6+
7+
echo "🔄 Fetching available Azure subscriptions..."
8+
SUBSCRIPTIONS=$(az account list --query "[?state=='Enabled'].{Name:name, ID:id}" --output tsv)
9+
SUB_COUNT=$(echo "$SUBSCRIPTIONS" | wc -l)
10+
11+
if [ "$SUB_COUNT" -eq 1 ]; then
12+
AZURE_SUBSCRIPTION_ID=$(echo "$SUBSCRIPTIONS" | awk '{print $2}')
13+
echo "✅ Using the only available subscription: $AZURE_SUBSCRIPTION_ID"
14+
else
15+
echo "Multiple subscriptions found:"
16+
echo "$SUBSCRIPTIONS" | awk '{print NR")", $1, "-", $2}'
17+
while true; do
18+
echo "Enter the number of the subscription to use:"
19+
read SUB_INDEX
20+
if [[ "$SUB_INDEX" =~ ^[0-9]+$ ]] && [ "$SUB_INDEX" -ge 1 ] && [ "$SUB_INDEX" -le "$SUB_COUNT" ]; then
21+
AZURE_SUBSCRIPTION_ID=$(echo "$SUBSCRIPTIONS" | awk -v idx="$SUB_INDEX" 'NR==idx {print $2}')
22+
echo "✅ Selected Subscription: $AZURE_SUBSCRIPTION_ID"
23+
break
24+
else
25+
echo "❌ Invalid selection. Please enter a valid number from the list."
26+
fi
27+
done
28+
fi
29+
30+
az account set --subscription "$AZURE_SUBSCRIPTION_ID"
31+
32+
echo "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)"
33+
echo "🔄 Fetching Azure regions..."
34+
35+
REGIONS=$(az account list-locations --query "[].name" --output tsv)
36+
37+
echo "✅ Retrieved Azure regions. Checking availability..."
38+
39+
# Array to store table data
40+
declare -a TABLE_ROWS
41+
INDEX=1
42+
43+
# Loop through all regions
44+
for REGION in $REGIONS; do
45+
REGION=$(echo "$REGION" | xargs)
46+
echo "----------------------------------------"
47+
echo "🔍 Checking region: $REGION"
48+
QUOTA_INFO=$(az cognitiveservices usage list --location "$REGION" --output json)
49+
if [ -z "$QUOTA_INFO" ]; then
50+
echo "⚠️ WARNING: Failed to retrieve quota for region $REGION. Skipping."
51+
continue
52+
fi
53+
54+
for MODEL_NAME in "${MODEL_NAMES[@]}"; do
55+
for MODEL_PREFIX in "OpenAI.Standard" "OpenAI.GlobalStandard"; do
56+
FULL_MODEL_NAME="${MODEL_PREFIX}.$MODEL_NAME"
57+
MODEL_INFO=$(echo "$QUOTA_INFO" | awk -v model="\"value\": \"$FULL_MODEL_NAME\"" '
58+
BEGIN { RS="},"; FS="," }
59+
$0 ~ model { print $0 }
60+
')
61+
if [ -z "$MODEL_INFO" ]; then
62+
continue
63+
fi
64+
65+
CURRENT_VALUE=$(echo "$MODEL_INFO" | awk -F': ' '/"currentValue"/ {print $2}' | tr -d ',' | tr -d ' ')
66+
LIMIT=$(echo "$MODEL_INFO" | awk -F': ' '/"limit"/ {print $2}' | tr -d ',' | tr -d ' ')
67+
CURRENT_VALUE=${CURRENT_VALUE:-0}
68+
LIMIT=${LIMIT:-0}
69+
CURRENT_VALUE=$(echo "$CURRENT_VALUE" | cut -d'.' -f1)
70+
LIMIT=$(echo "$LIMIT" | cut -d'.' -f1)
71+
72+
AVAILABLE=$((LIMIT - CURRENT_VALUE))
73+
74+
TABLE_ROWS+=("$(printf "| %-4s | %-20s | %-49s | %-9s | %-9s | %-9s |" "$INDEX" "$REGION" "$FULL_MODEL_NAME" "$LIMIT" "$CURRENT_VALUE" "$AVAILABLE")")
75+
76+
INDEX=$((INDEX + 1))
77+
done
78+
done
79+
echo "----------------------------------------"
80+
done
81+
82+
# Print table header
83+
echo "----------------------------------------------------------------------------------------------------------"
84+
printf "| %-4s | %-20s | %-49s | %-9s | %-9s | %-9s |\n" "No." "Region" "Model Name" "Limit" "Used" "Available"
85+
echo "----------------------------------------------------------------------------------------------------------"
86+
87+
for ROW in "${TABLE_ROWS[@]}"; do
88+
echo "$ROW"
89+
done
90+
91+
echo "----------------------------------------------------------------------------------------------------------"
92+
echo "✅ Script completed."
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/bin/bash
2+
3+
# Parameters
4+
IFS=',' read -r -a MODEL_CAPACITY_PAIRS <<< "$1" # Split the comma-separated model and capacity pairs into an array
5+
USER_REGION="$2"
6+
7+
if [ ${#MODEL_CAPACITY_PAIRS[@]} -lt 1 ]; then
8+
echo "❌ ERROR: At least one model and capacity pairs must be provided as arguments."
9+
exit 1
10+
fi
11+
12+
# Extract model names and required capacities into arrays
13+
declare -a MODEL_NAMES
14+
declare -a CAPACITIES
15+
16+
for PAIR in "${MODEL_CAPACITY_PAIRS[@]}"; do
17+
MODEL_NAME=$(echo "$PAIR" | cut -d':' -f1)
18+
CAPACITY=$(echo "$PAIR" | cut -d':' -f2)
19+
20+
if [ -z "$MODEL_NAME" ] || [ -z "$CAPACITY" ]; then
21+
echo "❌ ERROR: Invalid model and capacity pair '$PAIR'. Both model and capacity must be specified."
22+
exit 1
23+
fi
24+
25+
MODEL_NAMES+=("$MODEL_NAME")
26+
CAPACITIES+=("$CAPACITY")
27+
done
28+
29+
echo "🔄 Using Models: ${MODEL_NAMES[*]} with respective Capacities: ${CAPACITIES[*]}"
30+
31+
echo "🔄 Fetching available Azure subscriptions..."
32+
SUBSCRIPTIONS=$(az account list --query "[?state=='Enabled'].{Name:name, ID:id}" --output tsv)
33+
SUB_COUNT=$(echo "$SUBSCRIPTIONS" | wc -l)
34+
35+
if [ "$SUB_COUNT" -eq 1 ]; then
36+
# If only one subscription, automatically select it
37+
AZURE_SUBSCRIPTION_ID=$(echo "$SUBSCRIPTIONS" | awk '{print $2}')
38+
echo "✅ Using the only available subscription: $AZURE_SUBSCRIPTION_ID"
39+
else
40+
# If multiple subscriptions exist, prompt the user to choose one
41+
echo "Multiple subscriptions found:"
42+
echo "$SUBSCRIPTIONS" | awk '{print NR")", $1, "-", $2}'
43+
44+
while true; do
45+
echo "Enter the number of the subscription to use:"
46+
read SUB_INDEX
47+
48+
# Validate user input
49+
if [[ "$SUB_INDEX" =~ ^[0-9]+$ ]] && [ "$SUB_INDEX" -ge 1 ] && [ "$SUB_INDEX" -le "$SUB_COUNT" ]; then
50+
AZURE_SUBSCRIPTION_ID=$(echo "$SUBSCRIPTIONS" | awk -v idx="$SUB_INDEX" 'NR==idx {print $2}')
51+
echo "✅ Selected Subscription: $AZURE_SUBSCRIPTION_ID"
52+
break
53+
else
54+
echo "❌ Invalid selection. Please enter a valid number from the list."
55+
fi
56+
done
57+
fi
58+
59+
# Set the selected subscription
60+
az account set --subscription "$AZURE_SUBSCRIPTION_ID"
61+
echo "🎯 Active Subscription: $(az account show --query '[name, id]' --output table)"
62+
63+
# List of regions to check
64+
DEFAULT_REGIONS=("eastus" "uksouth" "eastus2" "northcentralus" "swedencentral" "westus" "westus2" "southcentralus" "canadacentral")
65+
66+
# Prioritize user-provided region if given
67+
if [ -n "$USER_REGION" ]; then
68+
# Ensure the user-provided region is checked first
69+
REGIONS=("$USER_REGION" "${DEFAULT_REGIONS[@]}")
70+
else
71+
REGIONS=("${DEFAULT_REGIONS[@]}")
72+
fi
73+
74+
echo "✅ Retrieved Azure regions. Checking availability..."
75+
76+
VALID_REGIONS=()
77+
for REGION in "${REGIONS[@]}"; do
78+
echo "----------------------------------------"
79+
echo "🔍 Checking region: $REGION"
80+
81+
# Fetch quota information for the region
82+
QUOTA_INFO=$(az cognitiveservices usage list --location "$REGION" --output json)
83+
if [ -z "$QUOTA_INFO" ]; then
84+
echo "⚠️ WARNING: Failed to retrieve quota for region $REGION. Skipping."
85+
continue
86+
fi
87+
88+
# Initialize a flag to track if both models have sufficient quota in the region
89+
BOTH_MODELS_AVAILABLE=true
90+
91+
for index in "${!MODEL_NAMES[@]}"; do
92+
MODEL_NAME="${MODEL_NAMES[$index]}"
93+
REQUIRED_CAPACITY="${CAPACITIES[$index]}"
94+
95+
echo "🔍 Checking model: $MODEL_NAME with required capacity: $REQUIRED_CAPACITY"
96+
97+
# Extract model quota information
98+
MODEL_INFO=$(echo "$QUOTA_INFO" | awk -v model="\"value\": \"OpenAI.Standard.$MODEL_NAME\"" '
99+
BEGIN { RS="},"; FS="," }
100+
$0 ~ model { print $0 }
101+
')
102+
103+
if [ -z "$MODEL_INFO" ]; then
104+
echo "⚠️ WARNING: No quota information found for model: OpenAI.Standard.$MODEL_NAME in $REGION. Skipping."
105+
BOTH_MODELS_AVAILABLE=false
106+
break # If any model is not available, no need to check further for this region
107+
fi
108+
109+
CURRENT_VALUE=$(echo "$MODEL_INFO" | awk -F': ' '/"currentValue"/ {print $2}' | tr -d ',' | tr -d ' ')
110+
LIMIT=$(echo "$MODEL_INFO" | awk -F': ' '/"limit"/ {print $2}' | tr -d ',' | tr -d ' ')
111+
112+
CURRENT_VALUE=${CURRENT_VALUE:-0}
113+
LIMIT=${LIMIT:-0}
114+
115+
CURRENT_VALUE=$(echo "$CURRENT_VALUE" | cut -d'.' -f1)
116+
LIMIT=$(echo "$LIMIT" | cut -d'.' -f1)
117+
118+
AVAILABLE=$((LIMIT - CURRENT_VALUE))
119+
120+
echo "✅ Model: OpenAI.Standard.$MODEL_NAME | Used: $CURRENT_VALUE | Limit: $LIMIT | Available: $AVAILABLE"
121+
122+
# Check if quota is sufficient
123+
if [ "$AVAILABLE" -lt "$REQUIRED_CAPACITY" ]; then
124+
echo "❌ ERROR: 'OpenAI.Standard.$MODEL_NAME' in $REGION has insufficient quota. Required: $REQUIRED_CAPACITY, Available: $AVAILABLE"
125+
BOTH_MODELS_AVAILABLE=false
126+
break
127+
fi
128+
done
129+
130+
# If both models have sufficient quota, add region to valid regions
131+
if [ "$BOTH_MODELS_AVAILABLE" = true ]; then
132+
echo "✅ All models have sufficient quota in $REGION."
133+
VALID_REGIONS+=("$REGION")
134+
fi
135+
done
136+
137+
# Determine final result and display in table format
138+
if [ ${#VALID_REGIONS[@]} -eq 0 ]; then
139+
echo "----------------------------------------"
140+
echo "❌ No region with sufficient quota found for all models. Blocking deployment."
141+
echo "----------------------------------------"
142+
exit 0
143+
else
144+
echo "----------------------------------------"
145+
echo "✅ Suggested Regions with Sufficient Quota"
146+
echo "----------------------------------------"
147+
printf "| %-5s | %-20s |\n" "No." "Region"
148+
echo "----------------------------------------"
149+
150+
INDEX=1
151+
for REGION in "${VALID_REGIONS[@]}"; do
152+
printf "| %-5s | %-20s |\n" "$INDEX" "$REGION"
153+
INDEX=$((INDEX + 1))
154+
done
155+
156+
echo "----------------------------------------"
157+
exit 0
158+
fi

0 commit comments

Comments
 (0)