Skip to content

Commit ecd53f1

Browse files
Merge pull request #298 from microsoft/psl-aifoundry-readme
docs: changes to improve the documentation and scripts for checking quota availability before deployment
2 parents 54ecfcb + 1db5243 commit ecd53f1

File tree

4 files changed

+313
-7
lines changed

4 files changed

+313
-7
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ The documents are intended for use as sample data only.
4040
QUICK DEPLOY
4141
</h2>
4242

43-
| [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/microsoft/document-generation-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/document-generation-solution-accelerator) | [![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fmicrosoft%2Fdocument-generation-solution-accelerator%2Fmain%2Finfra%2Fmain.json) |
44-
|---|---|---|
45-
46-
4743
### Prerequisites
4844

4945
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)
@@ -57,9 +53,16 @@ Check the [Azure Products by Region](https://azure.microsoft.com/en-us/explore/g
5753
- GPT Model Capacity
5854
- [Azure Semantic Search](./docs/AzureSemanticSearchRegion.md)
5955

56+
Here are some example regions where the services are available: East US, East US2, Australia East, UK South, France Central.
57+
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.
6061

6162
<!-- Here are some example regions where the services are available: East US, East US2, Australia East, UK South, France Central. -->
6263

64+
| [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/microsoft/document-generation-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/document-generation-solution-accelerator) | [![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fmicrosoft%2Fdocument-generation-solution-accelerator%2Fmain%2Finfra%2Fmain.json) |
65+
|---|---|---|
6366

6467
### Configurable Deployment Settings
6568

@@ -83,9 +86,6 @@ By default, the **GPT model capacity** in deployment is set to **30k tokens**.
8386
8487
To adjust quota settings, follow these [steps](./docs/AzureGPTQuotaSettings.md)
8588

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

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**).

scripts/quota_check_all_regions.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
# Pre-defined list of models to check
4+
MODEL_NAMES=("gpt-4o" "gpt-4o-mini" "text-embedding-ada-002" "gpt-3.5-turbo" "gpt-4")
5+
6+
echo "🔄 Fetching available Azure subscriptions..."
7+
SUBSCRIPTIONS=$(az account list --query "[?state=='Enabled'].{Name:name, ID:id}" --output tsv)
8+
SUB_COUNT=$(echo "$SUBSCRIPTIONS" | wc -l)
9+
10+
if [ "$SUB_COUNT" -eq 1 ]; then
11+
AZURE_SUBSCRIPTION_ID=$(echo "$SUBSCRIPTIONS" | awk '{print $2}')
12+
echo "✅ Using the only available subscription: $AZURE_SUBSCRIPTION_ID"
13+
else
14+
echo "Multiple subscriptions found:"
15+
echo "$SUBSCRIPTIONS" | awk '{print NR")", $1, "-", $2}'
16+
while true; do
17+
echo "Enter the number of the subscription to use:"
18+
read SUB_INDEX
19+
if [[ "$SUB_INDEX" =~ ^[0-9]+$ ]] && [ "$SUB_INDEX" -ge 1 ] && [ "$SUB_INDEX" -le "$SUB_COUNT" ]; then
20+
AZURE_SUBSCRIPTION_ID=$(echo "$SUBSCRIPTIONS" | awk -v idx="$SUB_INDEX" 'NR==idx {print $2}')
21+
echo "✅ Selected Subscription: $AZURE_SUBSCRIPTION_ID"
22+
break
23+
else
24+
echo "❌ Invalid selection. Please enter a valid number from the list."
25+
fi
26+
done
27+
fi
28+
29+
az account set --subscription "$AZURE_SUBSCRIPTION_ID"
30+
31+
echo "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)"
32+
echo "🔄 Fetching Azure regions..."
33+
34+
REGIONS=$(az account list-locations --query "[].name" --output tsv)
35+
36+
echo "✅ Retrieved Azure regions. Checking availability..."
37+
38+
# Array to store table data
39+
declare -a TABLE_ROWS
40+
INDEX=1
41+
42+
# Loop through all regions
43+
for REGION in $REGIONS; do
44+
REGION=$(echo "$REGION" | xargs)
45+
echo "----------------------------------------"
46+
echo "🔍 Checking region: $REGION"
47+
QUOTA_INFO=$(az cognitiveservices usage list --location "$REGION" --output json)
48+
if [ -z "$QUOTA_INFO" ]; then
49+
echo "⚠️ WARNING: Failed to retrieve quota for region $REGION. Skipping."
50+
continue
51+
fi
52+
53+
for MODEL_NAME in "${MODEL_NAMES[@]}"; do
54+
for MODEL_PREFIX in "OpenAI.Standard" "OpenAI.GlobalStandard"; do
55+
FULL_MODEL_NAME="${MODEL_PREFIX}.$MODEL_NAME"
56+
MODEL_INFO=$(echo "$QUOTA_INFO" | awk -v model="\"value\": \"$FULL_MODEL_NAME\"" '
57+
BEGIN { RS="},"; FS="," }
58+
$0 ~ model { print $0 }
59+
')
60+
if [ -z "$MODEL_INFO" ]; then
61+
continue
62+
fi
63+
64+
CURRENT_VALUE=$(echo "$MODEL_INFO" | awk -F': ' '/"currentValue"/ {print $2}' | tr -d ',' | tr -d ' ')
65+
LIMIT=$(echo "$MODEL_INFO" | awk -F': ' '/"limit"/ {print $2}' | tr -d ',' | tr -d ' ')
66+
CURRENT_VALUE=${CURRENT_VALUE:-0}
67+
LIMIT=${LIMIT:-0}
68+
CURRENT_VALUE=$(echo "$CURRENT_VALUE" | cut -d'.' -f1)
69+
LIMIT=$(echo "$LIMIT" | cut -d'.' -f1)
70+
71+
AVAILABLE=$((LIMIT - CURRENT_VALUE))
72+
73+
TABLE_ROWS+=("$(printf "| %-4s | %-20s | %-49s | %-9s | %-9s | %-9s |" "$INDEX" "$REGION" "$FULL_MODEL_NAME" "$LIMIT" "$CURRENT_VALUE" "$AVAILABLE")")
74+
75+
INDEX=$((INDEX + 1))
76+
done
77+
done
78+
echo "----------------------------------------"
79+
done
80+
81+
# Print table header
82+
echo "----------------------------------------------------------------------------------------------------------"
83+
printf "| %-4s | %-20s | %-49s | %-9s | %-9s | %-9s |\n" "No." "Region" "Model Name" "Limit" "Used" "Available"
84+
echo "----------------------------------------------------------------------------------------------------------"
85+
86+
for ROW in "${TABLE_ROWS[@]}"; do
87+
echo "$ROW"
88+
done
89+
90+
echo "----------------------------------------------------------------------------------------------------------"
91+
echo "✅ Script completed."

scripts/quota_check_params.sh

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)