Skip to content

Commit 91afbff

Browse files
feat: Added Quota Script
1 parent 8aeec79 commit 91afbff

File tree

5 files changed

+297
-0
lines changed

5 files changed

+297
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ QUICK DEPLOY
5555

5656
Follow the [quick deploy steps on the deployment guide](./docs/DeploymentGuide.md) to deploy this solution to your own Azure subscription.
5757

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.
61+
5862
| [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/microsoft/content-processing-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/content-processing-solution-accelerator) |
5963
|---|---|
6064

docs/Images/git_bash.png

29.3 KB
Loading

docs/Images/quota-check-output.png

12.6 KB
Loading

docs/quota_check.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
## Check Quota Availability Before Deployment
2+
3+
Before deploying the accelerator, **ensure sufficient quota availability** for the required model.
4+
5+
### Login if you have not done so already
6+
```
7+
azd auth login
8+
```
9+
10+
### 📌 Default Models & Capacities:
11+
```
12+
gpt-4o:30
13+
```
14+
### 📌 Default Regions:
15+
```
16+
eastus, uksouth, eastus2, northcentralus, swedencentral, westus, westus2, southcentralus, canadacentral
17+
```
18+
### Usage Scenarios:
19+
- No parameters passed → Default models and capacities will be checked in default regions.
20+
- Only model(s) provided → The script will check for those models in the default regions.
21+
- Only region(s) provided → The script will check default models in the specified regions.
22+
- Both models and regions provided → The script will check those models in the specified regions.
23+
24+
### **Input Formats**
25+
✔️ Run without parameters to check default models & regions:
26+
```
27+
./quota_check_params.sh
28+
```
29+
✔️ Model name and required capacity in the format:
30+
```
31+
./quota_check_params.sh gpt-4o:30
32+
```
33+
✔️ Multiple models can be passed, separated by commas:
34+
```
35+
./quota_check_params.sh gpt-4o:30,text-embedding-ada-002:80
36+
```
37+
✔️ Passing Both models and regions:
38+
```
39+
./quota_check_params.sh gpt-4o:30 eastus,westus2
40+
```
41+
✔️ Check default models in specific regions:
42+
```
43+
./quota_check_params.sh "" eastus,westus2
44+
```
45+
46+
### **Sample Output**
47+
The final table lists regions with available quota. You can select any of these regions for deployment.
48+
49+
![quota-check-ouput](Images/quota-check-output.png)
50+
51+
---
52+
### **If using Azure Portal and Cloud Shell**
53+
54+
1. Navigate to the [Azure Portal](https://portal.azure.com).
55+
2. Click on **Azure Cloud Shell** in the top right navigation menu.
56+
3. Run the appropriate command based on your requirement:
57+
58+
**To check quota for the deployment**
59+
60+
```sh
61+
curl -L -o quota_check_params.sh "https://raw.githubusercontent.com/microsoft/content-processing-solution-accelerator/main/scripts/quota_check_params.sh"
62+
chmod +x quota_check_params.sh
63+
./quota_check_params.sh
64+
```
65+
- Refer to [Input Formats](#input-formats) for detailed commands.
66+
67+
### **If using VS Code or Codespaces**
68+
1. Open the terminal in VS Code or Codespaces.
69+
2. If you're using VS Code, click the dropdown on the right side of the terminal window, and select `Git Bash`.
70+
![git_bash](Images/git_bash.png)
71+
3. Navigate to the `scripts` folder where the script files are located and make the script as executable:
72+
```sh
73+
cd infra/scripts
74+
chmod +x quota_check_params.sh
75+
```
76+
4. Run the appropriate script based on your requirement:
77+
78+
**To check quota for the deployment**
79+
80+
```sh
81+
./quota_check_params.sh
82+
```
83+
- Refer to [Input Formats](#input-formats) for detailed commands.
84+
85+
5. If you see the error `_bash: az: command not found_`, install Azure CLI:
86+
87+
```sh
88+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
89+
az login
90+
```
91+
6. Rerun the script after installing Azure CLI.
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
#!/bin/bash
2+
3+
# Default Models and Capacities (Comma-separated in "model:capacity" format)
4+
DEFAULT_MODEL_CAPACITY="gpt-4o:30"
5+
6+
# Convert the comma-separated string into an array
7+
IFS=',' read -r -a MODEL_CAPACITY_PAIRS <<< "$DEFAULT_MODEL_CAPACITY"
8+
9+
echo "🔄 Fetching available Azure subscriptions..."
10+
SUBSCRIPTIONS=$(az account list --query "[?state=='Enabled'].{Name:name, ID:id}" --output tsv)
11+
SUB_COUNT=$(echo "$SUBSCRIPTIONS" | wc -l)
12+
13+
if [ "$SUB_COUNT" -eq 0 ]; then
14+
echo "❌ ERROR: No active Azure subscriptions found. Please log in using 'az login' and ensure you have an active subscription."
15+
exit 1
16+
elif [ "$SUB_COUNT" -eq 1 ]; then
17+
# If only one subscription, automatically select it
18+
AZURE_SUBSCRIPTION_ID=$(echo "$SUBSCRIPTIONS" | awk '{print $2}')
19+
if [ -z "$AZURE_SUBSCRIPTION_ID" ]; then
20+
echo "❌ ERROR: No active Azure subscriptions found. Please log in using 'az login' and ensure you have an active subscription."
21+
exit 1
22+
fi
23+
echo "✅ Using the only available subscription: $AZURE_SUBSCRIPTION_ID"
24+
else
25+
# If multiple subscriptions exist, prompt the user to choose one
26+
echo "Multiple subscriptions found:"
27+
echo "$SUBSCRIPTIONS" | awk '{print NR")", $1, "-", $2}'
28+
29+
while true; do
30+
echo "Enter the number of the subscription to use:"
31+
read SUB_INDEX
32+
33+
# Validate user input
34+
if [[ "$SUB_INDEX" =~ ^[0-9]+$ ]] && [ "$SUB_INDEX" -ge 1 ] && [ "$SUB_INDEX" -le "$SUB_COUNT" ]; then
35+
AZURE_SUBSCRIPTION_ID=$(echo "$SUBSCRIPTIONS" | awk -v idx="$SUB_INDEX" 'NR==idx {print $2}')
36+
echo "✅ Selected Subscription: $AZURE_SUBSCRIPTION_ID"
37+
break
38+
else
39+
echo "❌ Invalid selection. Please enter a valid number from the list."
40+
fi
41+
done
42+
fi
43+
44+
# Set the selected subscription
45+
az account set --subscription "$AZURE_SUBSCRIPTION_ID"
46+
echo "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)"
47+
48+
# Default Regions to check (Comma-separated, now configurable)
49+
DEFAULT_REGIONS="eastus,uksouth,eastus2,northcentralus,swedencentral,westus,westus2,southcentralus,canadacentral"
50+
IFS=',' read -r -a DEFAULT_REGION_ARRAY <<< "$DEFAULT_REGIONS"
51+
52+
# Read parameters (if any)
53+
IFS=',' read -r -a USER_PROVIDED_PAIRS <<< "$1"
54+
USER_REGION="$2"
55+
56+
IS_USER_PROVIDED_PAIRS=false
57+
58+
if [ ${#USER_PROVIDED_PAIRS[@]} -lt 1 ]; then
59+
echo "No parameters provided, using default model-capacity pairs: ${MODEL_CAPACITY_PAIRS[*]}"
60+
else
61+
echo "Using provided model and capacity pairs: ${USER_PROVIDED_PAIRS[*]}"
62+
IS_USER_PROVIDED_PAIRS=true
63+
MODEL_CAPACITY_PAIRS=("${USER_PROVIDED_PAIRS[@]}")
64+
fi
65+
66+
declare -a FINAL_MODEL_NAMES
67+
declare -a FINAL_CAPACITIES
68+
declare -a TABLE_ROWS
69+
70+
for PAIR in "${MODEL_CAPACITY_PAIRS[@]}"; do
71+
MODEL_NAME=$(echo "$PAIR" | cut -d':' -f1 | tr '[:upper:]' '[:lower:]')
72+
CAPACITY=$(echo "$PAIR" | cut -d':' -f2)
73+
74+
if [ -z "$MODEL_NAME" ] || [ -z "$CAPACITY" ]; then
75+
echo "❌ ERROR: Invalid model and capacity pair '$PAIR'. Both model and capacity must be specified."
76+
exit 1
77+
fi
78+
79+
FINAL_MODEL_NAMES+=("$MODEL_NAME")
80+
FINAL_CAPACITIES+=("$CAPACITY")
81+
82+
done
83+
84+
echo "🔄 Using Models: ${FINAL_MODEL_NAMES[*]} with respective Capacities: ${FINAL_CAPACITIES[*]}"
85+
echo "----------------------------------------"
86+
87+
# Check if the user provided a region, if not, use the default regions
88+
if [ -n "$USER_REGION" ]; then
89+
echo "🔍 User provided region: $USER_REGION"
90+
IFS=',' read -r -a REGIONS <<< "$USER_REGION"
91+
else
92+
echo "No region specified, using default regions: ${DEFAULT_REGION_ARRAY[*]}"
93+
REGIONS=("${DEFAULT_REGION_ARRAY[@]}")
94+
APPLY_OR_CONDITION=true
95+
fi
96+
97+
echo "✅ Retrieved Azure regions. Checking availability..."
98+
INDEX=1
99+
100+
VALID_REGIONS=()
101+
for REGION in "${REGIONS[@]}"; do
102+
echo "----------------------------------------"
103+
echo "🔍 Checking region: $REGION"
104+
105+
QUOTA_INFO=$(az cognitiveservices usage list --location "$REGION" --output json | tr '[:upper:]' '[:lower:]')
106+
if [ -z "$QUOTA_INFO" ]; then
107+
echo "⚠️ WARNING: Failed to retrieve quota for region $REGION. Skipping."
108+
continue
109+
fi
110+
111+
TEXT_EMBEDDING_AVAILABLE=false
112+
AT_LEAST_ONE_MODEL_AVAILABLE=false
113+
TEMP_TABLE_ROWS=()
114+
115+
for index in "${!FINAL_MODEL_NAMES[@]}"; do
116+
MODEL_NAME="${FINAL_MODEL_NAMES[$index]}"
117+
REQUIRED_CAPACITY="${FINAL_CAPACITIES[$index]}"
118+
FOUND=false
119+
INSUFFICIENT_QUOTA=false
120+
121+
if [ "$MODEL_NAME" = "text-embedding-ada-002" ]; then
122+
MODEL_TYPES=("openai.standard.$MODEL_NAME")
123+
else
124+
MODEL_TYPES=("openai.standard.$MODEL_NAME" "openai.globalstandard.$MODEL_NAME")
125+
fi
126+
127+
for MODEL_TYPE in "${MODEL_TYPES[@]}"; do
128+
FOUND=false
129+
INSUFFICIENT_QUOTA=false
130+
echo "🔍 Checking model: $MODEL_NAME with required capacity: $REQUIRED_CAPACITY ($MODEL_TYPE)"
131+
132+
MODEL_INFO=$(echo "$QUOTA_INFO" | awk -v model="\"value\": \"$MODEL_TYPE\"" '
133+
BEGIN { RS="},"; FS="," }
134+
$0 ~ model { print $0 }
135+
')
136+
137+
if [ -z "$MODEL_INFO" ]; then
138+
FOUND=false
139+
echo "⚠️ WARNING: No quota information found for model: $MODEL_NAME in region: $REGION for model type: $MODEL_TYPE."
140+
continue
141+
fi
142+
143+
if [ -n "$MODEL_INFO" ]; then
144+
FOUND=true
145+
CURRENT_VALUE=$(echo "$MODEL_INFO" | awk -F': ' '/"currentvalue"/ {print $2}' | tr -d ',' | tr -d ' ')
146+
LIMIT=$(echo "$MODEL_INFO" | awk -F': ' '/"limit"/ {print $2}' | tr -d ',' | tr -d ' ')
147+
148+
CURRENT_VALUE=${CURRENT_VALUE:-0}
149+
LIMIT=${LIMIT:-0}
150+
151+
CURRENT_VALUE=$(echo "$CURRENT_VALUE" | cut -d'.' -f1)
152+
LIMIT=$(echo "$LIMIT" | cut -d'.' -f1)
153+
154+
AVAILABLE=$((LIMIT - CURRENT_VALUE))
155+
echo "✅ Model: $MODEL_TYPE | Used: $CURRENT_VALUE | Limit: $LIMIT | Available: $AVAILABLE"
156+
157+
if [ "$AVAILABLE" -ge "$REQUIRED_CAPACITY" ]; then
158+
FOUND=true
159+
if [ "$MODEL_NAME" = "text-embedding-ada-002" ]; then
160+
TEXT_EMBEDDING_AVAILABLE=true
161+
fi
162+
AT_LEAST_ONE_MODEL_AVAILABLE=true
163+
TEMP_TABLE_ROWS+=("$(printf "| %-4s | %-20s | %-45s | %-10s | %-10s | %-10s |" "$INDEX" "$REGION" "$MODEL_TYPE" "$LIMIT" "$CURRENT_VALUE" "$AVAILABLE")")
164+
else
165+
INSUFFICIENT_QUOTA=true
166+
fi
167+
fi
168+
169+
if [ "$FOUND" = false ]; then
170+
echo "❌ No models found for model: $MODEL_NAME in region: $REGION (${MODEL_TYPES[*]})"
171+
elif [ "$INSUFFICIENT_QUOTA" = true ]; then
172+
echo "⚠️ Model $MODEL_NAME in region: $REGION has insufficient quota (${MODEL_TYPES[*]})."
173+
fi
174+
done
175+
done
176+
177+
if { [ "$IS_USER_PROVIDED_PAIRS" = true ] && [ "$INSUFFICIENT_QUOTA" = false ] && [ "$FOUND" = true ]; } || { [ "$TEXT_EMBEDDING_AVAILABLE" = true ] && { [ "$APPLY_OR_CONDITION" != true ] || [ "$AT_LEAST_ONE_MODEL_AVAILABLE" = true ]; }; }; then
178+
VALID_REGIONS+=("$REGION")
179+
TABLE_ROWS+=("${TEMP_TABLE_ROWS[@]}")
180+
INDEX=$((INDEX + 1))
181+
elif [ ${#USER_PROVIDED_PAIRS[@]} -eq 0 ]; then
182+
echo "🚫 Skipping $REGION as it does not meet quota requirements."
183+
fi
184+
185+
done
186+
187+
if [ ${#TABLE_ROWS[@]} -eq 0 ]; then
188+
echo "------------------------------------------------------------------------------------------------------------------"
189+
190+
echo "❌ No regions have sufficient quota for all required models. Please request a quota increase: https://aka.ms/oai/stuquotarequest"
191+
else
192+
echo "----------------------------------------------------------------------------------------------------------------------"
193+
printf "| %-4s | %-20s | %-45s | %-10s | %-10s | %-10s |\n" "No." "Region" "Model Name" "Limit" "Used" "Available"
194+
echo "----------------------------------------------------------------------------------------------------------------------"
195+
for ROW in "${TABLE_ROWS[@]}"; do
196+
echo "$ROW"
197+
done
198+
echo "----------------------------------------------------------------------------------------------------------------------"
199+
echo "➡️ To request a quota increase, visit: https://aka.ms/oai/stuquotarequest"
200+
fi
201+
202+
echo "✅ Script completed."

0 commit comments

Comments
 (0)