Skip to content

feat: add --models, --regions, and --verbose support #77

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

Merged
Merged
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
36 changes: 25 additions & 11 deletions docs/quota_check.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
## Check Quota Availability Before Deployment

Before deploying the accelerator, **ensure sufficient quota availability** for the required model. \
Before deploying the accelerator, **ensure sufficient quota availability** for the required model.
> **For Global Standard | GPT-4o - the capacity to at least 200K tokens for optimal performance.**

### Login if you have not done so already
```
azd auth login
```


### 📌 Default Models & Capacities:
```
gpt-4o:30, gpt-4:30
gpt-4o:5
```
### 📌 Default Regions:
```
Expand All @@ -15,27 +22,34 @@ eastus, uksouth, eastus2, northcentralus, swedencentral, westus, westus2, southc
- Only model(s) provided → The script will check for those models in the default regions.
- Only region(s) provided → The script will check default models in the specified regions.
- Both models and regions provided → The script will check those models in the specified regions.
- `--verbose` passed → Enables detailed logging output for debugging and traceability.

### **Input Formats**
✔️ Run without parameters to check default models & regions:
> Use the --models, --regions, and --verbose options for parameter handling:

✔️ Run without parameters to check default models & regions without verbose logging:
```
./quota_check_params.sh
```
✔️ Model name and required capacity in the format:
✔️ Enable verbose logging:
```
./quota_check_params.sh --verbose
```
✔️ Check specific model(s) in default regions:
```
./quota_check_params.sh gpt-4o:30
./quota_check_params.sh --models gpt-4o:30
```
✔️ Multiple models can be passed, separated by commas:
✔️ Check default models in specific region(s):
```
./quota_check_params.sh gpt-4o:30,gpt-4:80
./quota_check_params.sh --regions eastus,westus
```
✔️ Passing Both models and regions:
```
./quota_check_params.sh gpt-4o:30 eastus,westus2
./quota_check_params.sh --models gpt-4o:30 --regions eastus,westus2
```
✔️ Check default models in specific regions:
✔️ All parameters combined:
```
./quota_check_params.sh "" eastus,westus2
./quota_check_params.sh --models gpt-4:30 --regions eastus,westus --verbose
```

### **Sample Output**
Expand Down Expand Up @@ -83,4 +97,4 @@ The final table lists regions with available quota. You can select any of these
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
az login
```
6. Rerun the script after installing Azure CLI.
6. Rerun the script after installing Azure CLI.
86 changes: 66 additions & 20 deletions scripts/quota_check_params.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,52 @@
#!/bin/bash

# Default Models and Capacities (Comma-separated in "model:capacity" format)
DEFAULT_MODEL_CAPACITY="gpt-4o:30,gpt-4:30"
MODELS=""
REGIONS=""
VERBOSE=false

while [[ $# -gt 0 ]]; do
case "$1" in
--models)
MODELS="$2"
shift 2
;;
--regions)
REGIONS="$2"
shift 2
;;
--verbose)
VERBOSE=true
shift
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done

# Fallback to defaults if not provided
[[ -z "$MODELS" ]]
[[ -z "$REGIONS" ]]

echo "Models: $MODELS"
echo "Regions: $REGIONS"
echo "Verbose: $VERBOSE"

for arg in "$@"; do
if [ "$arg" = "--verbose" ]; then
VERBOSE=true
fi
done

log_verbose() {
if [ "$VERBOSE" = true ]; then
echo "$1"
fi
}

# Default Models and Capacities (Comma-separated in "model:capacity" format)
DEFAULT_MODEL_CAPACITY="gpt-4o:5"
# Convert the comma-separated string into an array
IFS=',' read -r -a MODEL_CAPACITY_PAIRS <<< "$DEFAULT_MODEL_CAPACITY"

Expand Down Expand Up @@ -41,6 +85,7 @@ else
done
fi


# Set the selected subscription
az account set --subscription "$AZURE_SUBSCRIPTION_ID"
echo "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)"
Expand All @@ -50,8 +95,8 @@ DEFAULT_REGIONS="eastus,uksouth,eastus2,northcentralus,swedencentral,westus,west
IFS=',' read -r -a DEFAULT_REGION_ARRAY <<< "$DEFAULT_REGIONS"

# Read parameters (if any)
IFS=',' read -r -a USER_PROVIDED_PAIRS <<< "$1"
USER_REGION="$2"
IFS=',' read -r -a USER_PROVIDED_PAIRS <<< "$MODELS"
USER_REGION="$REGIONS"

IS_USER_PROVIDED_PAIRS=false

Expand Down Expand Up @@ -99,12 +144,12 @@ INDEX=1

VALID_REGIONS=()
for REGION in "${REGIONS[@]}"; do
echo "----------------------------------------"
echo "🔍 Checking region: $REGION"
log_verbose "----------------------------------------"
log_verbose "🔍 Checking region: $REGION"

QUOTA_INFO=$(az cognitiveservices usage list --location "$REGION" --output json | tr '[:upper:]' '[:lower:]')
if [ -z "$QUOTA_INFO" ]; then
echo "⚠️ WARNING: Failed to retrieve quota for region $REGION. Skipping."
log_verbose "⚠️ WARNING: Failed to retrieve quota for region $REGION. Skipping."
continue
fi

Expand All @@ -127,7 +172,7 @@ for REGION in "${REGIONS[@]}"; do
for MODEL_TYPE in "${MODEL_TYPES[@]}"; do
FOUND=false
INSUFFICIENT_QUOTA=false
echo "🔍 Checking model: $MODEL_NAME with required capacity: $REQUIRED_CAPACITY ($MODEL_TYPE)"
log_verbose "🔍 Checking model: $MODEL_NAME with required capacity: $REQUIRED_CAPACITY ($MODEL_TYPE)"

MODEL_INFO=$(echo "$QUOTA_INFO" | awk -v model="\"value\": \"$MODEL_TYPE\"" '
BEGIN { RS="},"; FS="," }
Expand All @@ -136,7 +181,7 @@ for REGION in "${REGIONS[@]}"; do

if [ -z "$MODEL_INFO" ]; then
FOUND=false
echo "⚠️ WARNING: No quota information found for model: $MODEL_NAME in region: $REGION for model type: $MODEL_TYPE."
log_verbose "⚠️ WARNING: No quota information found for model: $MODEL_NAME in region: $REGION for model type: $MODEL_TYPE."
continue
fi

Expand All @@ -152,29 +197,30 @@ for REGION in "${REGIONS[@]}"; do
LIMIT=$(echo "$LIMIT" | cut -d'.' -f1)

AVAILABLE=$((LIMIT - CURRENT_VALUE))
echo "✅ Model: $MODEL_TYPE | Used: $CURRENT_VALUE | Limit: $LIMIT | Available: $AVAILABLE"
log_verbose "✅ Model: $MODEL_TYPE | Used: $CURRENT_VALUE | Limit: $LIMIT | Available: $AVAILABLE"

if [ "$AVAILABLE" -ge "$REQUIRED_CAPACITY" ]; then
FOUND=true
if [ "$MODEL_NAME" = "text-embedding-ada-002" ]; then
TEXT_EMBEDDING_AVAILABLE=true
fi
AT_LEAST_ONE_MODEL_AVAILABLE=true
TEMP_TABLE_ROWS+=("$(printf "| %-4s | %-20s | %-45s | %-10s | %-10s | %-10s |" "$INDEX" "$REGION" "$MODEL_TYPE" "$LIMIT" "$CURRENT_VALUE" "$AVAILABLE")")
TEMP_TABLE_ROWS+=("$(printf "| %-4s | %-20s | %-43s | %-10s | %-10s | %-10s |" "$INDEX" "$REGION" "$MODEL_TYPE" "$LIMIT" "$CURRENT_VALUE" "$AVAILABLE")")
else
INSUFFICIENT_QUOTA=true
fi
fi

if [ "$FOUND" = false ]; then
echo "❌ No models found for model: $MODEL_NAME in region: $REGION (${MODEL_TYPES[*]})"
log_verbose "❌ No models found for model: $MODEL_NAME in region: $REGION (${MODEL_TYPES[*]})"

elif [ "$INSUFFICIENT_QUOTA" = true ]; then
echo "⚠️ Model $MODEL_NAME in region: $REGION has insufficient quota (${MODEL_TYPES[*]})."
log_verbose "⚠️ Model $MODEL_NAME in region: $REGION has insufficient quota (${MODEL_TYPES[*]})."
fi
done
done

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
if { [ "$IS_USER_PROVIDED_PAIRS" = true ] && [ "$INSUFFICIENT_QUOTA" = false ] && [ "$FOUND" = true ]; } || { [ "$APPLY_OR_CONDITION" != true ] || [ "$AT_LEAST_ONE_MODEL_AVAILABLE" = true ]; }; then
VALID_REGIONS+=("$REGION")
TABLE_ROWS+=("${TEMP_TABLE_ROWS[@]}")
INDEX=$((INDEX + 1))
Expand All @@ -185,18 +231,18 @@ if { [ "$IS_USER_PROVIDED_PAIRS" = true ] && [ "$INSUFFICIENT_QUOTA" = false ] &
done

if [ ${#TABLE_ROWS[@]} -eq 0 ]; then
echo "------------------------------------------------------------------------------------------------------------------"
echo "--------------------------------------------------------------------------------------------------------------------"

echo "❌ No regions have sufficient quota for all required models. Please request a quota increase: https://aka.ms/oai/stuquotarequest"
else
echo "----------------------------------------------------------------------------------------------------------------------"
printf "| %-4s | %-20s | %-45s | %-10s | %-10s | %-10s |\n" "No." "Region" "Model Name" "Limit" "Used" "Available"
echo "----------------------------------------------------------------------------------------------------------------------"
echo "---------------------------------------------------------------------------------------------------------------------"
printf "| %-4s | %-20s | %-43s | %-10s | %-10s | %-10s |\n" "No." "Region" "Model Name" "Limit" "Used" "Available"
echo "---------------------------------------------------------------------------------------------------------------------"
for ROW in "${TABLE_ROWS[@]}"; do
echo "$ROW"
done
echo "----------------------------------------------------------------------------------------------------------------------"
echo "---------------------------------------------------------------------------------------------------------------------"
echo "➡️ To request a quota increase, visit: https://aka.ms/oai/stuquotarequest"
fi

echo "✅ Script completed."
echo "✅ Script completed."