Skip to content

Commit 1b8775a

Browse files
Merge pull request #331 from microsoft/psl-quota-script-update
fix: Psl quota script update
2 parents 15b7052 + 87b23a0 commit 1b8775a

File tree

3 files changed

+175
-144
lines changed

3 files changed

+175
-144
lines changed

docs/images/quota-check-output.png

12.6 KB
Loading

docs/quota_check.md

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,84 @@
11
## Check Quota Availability Before Deployment
22

3-
Before deploying the accelerator, **ensure sufficient quota availability** for the required model.
4-
Use one of the following scripts based on your needs:
3+
Before deploying the accelerator, **ensure sufficient quota availability** for the required model. \
54

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.
5+
### 📌 Default Models & Capacities:
6+
```
7+
gpt-4o:30, text-embedding-ada-002:80, gpt-4:30
8+
```
9+
### 📌 Default Regions:
10+
```
11+
eastus, uksouth, eastus2, northcentralus, swedencentral, westus, westus2, southcentralus, canadacentral
12+
```
13+
### Usage Scenarios:
14+
- No parameters passed → Default models and capacities will be checked in default regions.
15+
- Only model(s) provided → The script will check for those models in the default regions.
16+
- Only region(s) provided → The script will check default models in the specified regions.
17+
- Both models and regions provided → The script will check those models in the specified regions.
18+
19+
### **Input Formats**
20+
✔️ Run without parameters to check default models & regions:
21+
```
22+
./quota_check_params.sh
23+
```
24+
✔️ Model name and required capacity in the format:
25+
```
26+
./quota_check_params.sh gpt-4o:30
27+
```
28+
✔️ Multiple models can be passed, separated by commas:
29+
```
30+
./quota_check_params.sh gpt-4o:30,text-embedding-ada-002:80
31+
```
32+
✔️ Passing Both models and regions:
33+
```
34+
./quota_check_params.sh gpt-4o:30 eastus,westus2
35+
```
36+
✔️ Check default models in specific regions:
37+
```
38+
./quota_check_params.sh "" eastus,westus2
39+
```
40+
41+
### **Sample Output**
42+
The final table lists regions with available quota. You can select any of these regions for deployment.
43+
44+
![quota-check-ouput](images/quota-check-output.png)
845

946
---
10-
## **If using Azure Portal and Cloud Shell**
47+
### **If using Azure Portal and Cloud Shell**
1148

1249
1. Navigate to the [Azure Portal](https://portal.azure.com).
1350
2. Click on **Azure Cloud Shell** in the top right navigation menu.
1451
3. Run the appropriate command based on your requirement:
1552

16-
**To check quota for a specific model and capacity:**
53+
**To check quota for the deployment**
1754

1855
```sh
1956
curl -L -o quota_check_params.sh "https://raw.githubusercontent.com/microsoft/document-generation-solution-accelerator/main/scripts/quota_check_params.sh"
2057
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)
58+
./quota_check_params.sh
2259
```
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/document-generation-solution-accelerator/main/scripts/quota_check_all_regions.sh"
28-
chmod +x quota_check_all_regions.sh
29-
./quota_check_all_regions.sh
60+
- Refer to [Input Formats](#input-formats) for detailed commands.
61+
62+
### **If using VS Code or Codespaces**
63+
1. Open the terminal in VS Code or Codespaces.
64+
2. Navigate to the `scripts` folder where the script files are located and make the script as executable:
65+
```sh
66+
cd scripts
67+
chmod +x quota_check_params.sh
3068
```
31-
32-
## **If using VS Code or Codespaces**
33-
34-
1. Run the appropriate script based on your requirement:
69+
3. Run the appropriate script based on your requirement:
3570

36-
**To check quota for a specific model and capacity:**
71+
**To check quota for the deployment**
3772

3873
```sh
39-
./quota_check_params.sh <model_name:capacity> [<model_region>] (e.g., gpt-4o-mini:30,text-embedding-ada-002:20 eastus)
74+
./quota_check_params.sh
4075
```
76+
- Refer to [Input Formats](#input-formats) for detailed commands.
4177

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:
78+
4. If you see the error `_bash: az: command not found_`, install Azure CLI:
4879

4980
```sh
5081
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
5182
az login
5283
```
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**).
84+
5. Rerun the script after installing Azure CLI.

scripts/quota_check_params.sh

Lines changed: 117 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,163 @@
11
#!/bin/bash
22

3-
# Parameters
4-
IFS=',' read -r -a MODEL_CAPACITY_PAIRS <<< "$1" # Split the comma-separated model and capacity pairs into an array
3+
# Default Models and Capacities (Comma-separated in "model:capacity" format)
4+
DEFAULT_MODEL_CAPACITY="gpt-4o:30,text-embedding-ada-002:80,gpt-4:30"
5+
6+
# Convert the comma-separated string into an array
7+
IFS=',' read -r -a MODEL_CAPACITY_PAIRS <<< "$DEFAULT_MODEL_CAPACITY"
8+
9+
# Default Regions to check (Comma-separated, now configurable)
10+
DEFAULT_REGIONS="eastus,uksouth,eastus2,northcentralus,swedencentral,westus,westus2,southcentralus,canadacentral"
11+
IFS=',' read -r -a DEFAULT_REGION_ARRAY <<< "$DEFAULT_REGIONS"
12+
13+
# Read parameters (if any)
14+
IFS=',' read -r -a USER_PROVIDED_PAIRS <<< "$1"
515
USER_REGION="$2"
616

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
17+
IS_USER_PROVIDED_PAIRS=false
18+
19+
if [ ${#USER_PROVIDED_PAIRS[@]} -lt 1 ]; then
20+
echo "No parameters provided, using default model-capacity pairs: ${MODEL_CAPACITY_PAIRS[*]}"
21+
else
22+
echo "Using provided model and capacity pairs: ${USER_PROVIDED_PAIRS[*]}"
23+
IS_USER_PROVIDED_PAIRS=true
24+
MODEL_CAPACITY_PAIRS=("${USER_PROVIDED_PAIRS[@]}")
1025
fi
1126

12-
# Extract model names and required capacities into arrays
13-
declare -a MODEL_NAMES
14-
declare -a CAPACITIES
27+
declare -a FINAL_MODEL_NAMES
28+
declare -a FINAL_CAPACITIES
29+
declare -a TABLE_ROWS
1530

1631
for PAIR in "${MODEL_CAPACITY_PAIRS[@]}"; do
17-
MODEL_NAME=$(echo "$PAIR" | cut -d':' -f1)
32+
MODEL_NAME=$(echo "$PAIR" | cut -d':' -f1 | tr '[:upper:]' '[:lower:]')
1833
CAPACITY=$(echo "$PAIR" | cut -d':' -f2)
1934

2035
if [ -z "$MODEL_NAME" ] || [ -z "$CAPACITY" ]; then
2136
echo "❌ ERROR: Invalid model and capacity pair '$PAIR'. Both model and capacity must be specified."
2237
exit 1
2338
fi
2439

25-
MODEL_NAMES+=("$MODEL_NAME")
26-
CAPACITIES+=("$CAPACITY")
27-
done
28-
29-
echo "🔄 Using Models: ${MODEL_NAMES[*]} with respective Capacities: ${CAPACITIES[*]}"
40+
FINAL_MODEL_NAMES+=("$MODEL_NAME")
41+
FINAL_CAPACITIES+=("$CAPACITY")
3042

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)"
43+
done
6244

63-
# List of regions to check
64-
DEFAULT_REGIONS=("eastus" "uksouth" "eastus2" "northcentralus" "swedencentral" "westus" "westus2" "southcentralus" "canadacentral")
45+
echo "🔄 Using Models: ${FINAL_MODEL_NAMES[*]} with respective Capacities: ${FINAL_CAPACITIES[*]}"
46+
echo "----------------------------------------"
6547

66-
# Prioritize user-provided region if given
48+
# Check if the user provided a region, if not, use the default regions
6749
if [ -n "$USER_REGION" ]; then
68-
# Ensure the user-provided region is checked first
69-
REGIONS=("$USER_REGION" "${DEFAULT_REGIONS[@]}")
50+
echo "🔍 User provided region: $USER_REGION"
51+
IFS=',' read -r -a REGIONS <<< "$USER_REGION"
7052
else
71-
REGIONS=("${DEFAULT_REGIONS[@]}")
53+
echo "No region specified, using default regions: ${DEFAULT_REGION_ARRAY[*]}"
54+
REGIONS=("${DEFAULT_REGION_ARRAY[@]}")
55+
APPLY_OR_CONDITION=true
7256
fi
7357

7458
echo "✅ Retrieved Azure regions. Checking availability..."
59+
INDEX=1
7560

7661
VALID_REGIONS=()
7762
for REGION in "${REGIONS[@]}"; do
7863
echo "----------------------------------------"
7964
echo "🔍 Checking region: $REGION"
8065

81-
# Fetch quota information for the region
82-
QUOTA_INFO=$(az cognitiveservices usage list --location "$REGION" --output json)
66+
QUOTA_INFO=$(az cognitiveservices usage list --location "$REGION" --output json | tr '[:upper:]' '[:lower:]')
8367
if [ -z "$QUOTA_INFO" ]; then
8468
echo "⚠️ WARNING: Failed to retrieve quota for region $REGION. Skipping."
8569
continue
8670
fi
8771

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 ' ')
72+
TEXT_EMBEDDING_AVAILABLE=false
73+
AT_LEAST_ONE_MODEL_AVAILABLE=false
74+
TEMP_TABLE_ROWS=()
11175

112-
CURRENT_VALUE=${CURRENT_VALUE:-0}
113-
LIMIT=${LIMIT:-0}
76+
for index in "${!FINAL_MODEL_NAMES[@]}"; do
77+
MODEL_NAME="${FINAL_MODEL_NAMES[$index]}"
78+
REQUIRED_CAPACITY="${FINAL_CAPACITIES[$index]}"
79+
FOUND=false
80+
INSUFFICIENT_QUOTA=false
11481

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-
echo "➡️ To request a quota increase, visit: https://aka.ms/oai/stuquotarequest"
126-
BOTH_MODELS_AVAILABLE=false
127-
break
82+
if [ "$MODEL_NAME" = "text-embedding-ada-002" ]; then
83+
MODEL_TYPES=("openai.standard.$MODEL_NAME")
84+
else
85+
MODEL_TYPES=("openai.standard.$MODEL_NAME" "openai.globalstandard.$MODEL_NAME")
12886
fi
87+
88+
for MODEL_TYPE in "${MODEL_TYPES[@]}"; do
89+
FOUND=false
90+
INSUFFICIENT_QUOTA=false
91+
echo "🔍 Checking model: $MODEL_NAME with required capacity: $REQUIRED_CAPACITY ($MODEL_TYPE)"
92+
93+
MODEL_INFO=$(echo "$QUOTA_INFO" | awk -v model="\"value\": \"$MODEL_TYPE\"" '
94+
BEGIN { RS="},"; FS="," }
95+
$0 ~ model { print $0 }
96+
')
97+
98+
if [ -z "$MODEL_INFO" ]; then
99+
FOUND=false
100+
echo "⚠️ WARNING: No quota information found for model: $MODEL_NAME in region: $REGION for model type: $MODEL_TYPE."
101+
continue
102+
fi
103+
104+
if [ -n "$MODEL_INFO" ]; then
105+
FOUND=true
106+
CURRENT_VALUE=$(echo "$MODEL_INFO" | awk -F': ' '/"currentvalue"/ {print $2}' | tr -d ',' | tr -d ' ')
107+
LIMIT=$(echo "$MODEL_INFO" | awk -F': ' '/"limit"/ {print $2}' | tr -d ',' | tr -d ' ')
108+
109+
CURRENT_VALUE=${CURRENT_VALUE:-0}
110+
LIMIT=${LIMIT:-0}
111+
112+
CURRENT_VALUE=$(echo "$CURRENT_VALUE" | cut -d'.' -f1)
113+
LIMIT=$(echo "$LIMIT" | cut -d'.' -f1)
114+
115+
AVAILABLE=$((LIMIT - CURRENT_VALUE))
116+
echo "✅ Model: $MODEL_TYPE | Used: $CURRENT_VALUE | Limit: $LIMIT | Available: $AVAILABLE"
117+
118+
if [ "$AVAILABLE" -ge "$REQUIRED_CAPACITY" ]; then
119+
FOUND=true
120+
if [ "$MODEL_NAME" = "text-embedding-ada-002" ]; then
121+
TEXT_EMBEDDING_AVAILABLE=true
122+
fi
123+
AT_LEAST_ONE_MODEL_AVAILABLE=true
124+
TEMP_TABLE_ROWS+=("$(printf "| %-4s | %-20s | %-60s | %-10s | %-10s | %-10s |" "$INDEX" "$REGION" "$MODEL_TYPE" "$LIMIT" "$CURRENT_VALUE" "$AVAILABLE")")
125+
else
126+
INSUFFICIENT_QUOTA=true
127+
fi
128+
fi
129+
130+
if [ "$FOUND" = false ]; then
131+
echo "❌ No models found for model: $MODEL_NAME in region: $REGION (${MODEL_TYPES[*]})"
132+
elif [ "$INSUFFICIENT_QUOTA" = true ]; then
133+
echo "⚠️ Model $MODEL_NAME in region: $REGION has insufficient quota (${MODEL_TYPES[*]})."
134+
fi
135+
done
129136
done
130137

131-
# If both models have sufficient quota, add region to valid regions
132-
if [ "$BOTH_MODELS_AVAILABLE" = true ]; then
133-
echo "✅ All models have sufficient quota in $REGION."
138+
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
134139
VALID_REGIONS+=("$REGION")
140+
TABLE_ROWS+=("${TEMP_TABLE_ROWS[@]}")
141+
INDEX=$((INDEX + 1))
142+
elif [ ${#USER_PROVIDED_PAIRS[@]} -eq 0 ]; then
143+
echo "🚫 Skipping $REGION as it does not meet quota requirements."
135144
fi
145+
136146
done
137147

138-
# Determine final result and display in table format
139-
if [ ${#VALID_REGIONS[@]} -eq 0 ]; then
140-
echo "----------------------------------------"
141-
echo "❌ No region with sufficient quota found for all models. Blocking deployment."
142-
echo "----------------------------------------"
143-
exit 0
148+
if [ ${#TABLE_ROWS[@]} -eq 0 ]; then
149+
echo "----------------------------------------------------------------------------------------------------------"
150+
151+
echo "❌ No regions have sufficient quota for all required models. Please request a quota increase: https://aka.ms/oai/stuquotarequest"
144152
else
145-
echo "----------------------------------------"
146-
echo "✅ Suggested Regions with Sufficient Quota"
147-
echo "----------------------------------------"
148-
printf "| %-5s | %-20s |\n" "No." "Region"
149-
echo "----------------------------------------"
150-
151-
INDEX=1
152-
for REGION in "${VALID_REGIONS[@]}"; do
153-
printf "| %-5s | %-20s |\n" "$INDEX" "$REGION"
154-
INDEX=$((INDEX + 1))
153+
echo "----------------------------------------------------------------------------------------------------------"
154+
printf "| %-4s | %-20s | %-60s | %-10s | %-10s | %-10s |\n" "No." "Region" "Model Name" "Limit" "Used" "Available"
155+
echo "----------------------------------------------------------------------------------------------------------"
156+
for ROW in "${TABLE_ROWS[@]}"; do
157+
echo "$ROW"
155158
done
156-
157-
echo "----------------------------------------"
158-
exit 0
159+
echo "----------------------------------------------------------------------------------------------------------"
160+
echo "➡️ To request a quota increase, visit: https://aka.ms/oai/stuquotarequest"
159161
fi
162+
163+
echo "✅ Script completed."

0 commit comments

Comments
 (0)