Skip to content

Commit 9017e3a

Browse files
updated script
1 parent 59a4d7f commit 9017e3a

1 file changed

Lines changed: 17 additions & 54 deletions

File tree

scripts/validate_model_quota.sh

Lines changed: 17 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ DEPLOYMENT_TYPE="Standard"
66
CAPACITY=0
77
RECOMMENDED_TOKENS=200
88
TABLE_SHOWN=false
9+
RECOMMENDATIONS_SHOWN=false
910

1011
ALL_REGIONS=('australiaeast' 'eastus' 'eastus2' 'francecentral' 'japaneast' 'norwayeast' 'southindia' 'swedencentral' 'uksouth' 'westus' 'westus3')
1112

@@ -58,9 +59,13 @@ check_quota() {
5859
ALL_RESULTS+=("$region|$LIMIT|$CURRENT_VALUE|$AVAILABLE")
5960

6061
if [[ "$AVAILABLE" -ge "$RECOMMENDED_TOKENS" ]]; then
61-
RECOMMENDED_REGIONS+=("$region")
62+
if [[ ! " ${RECOMMENDED_REGIONS[@]} " =~ " $region " ]]; then
63+
RECOMMENDED_REGIONS+=("$region")
64+
fi
6265
else
63-
NOT_RECOMMENDED_REGIONS+=("$region")
66+
if [[ ! " ${NOT_RECOMMENDED_REGIONS[@]} " =~ " $region " ]]; then
67+
NOT_RECOMMENDED_REGIONS+=("$region")
68+
fi
6469
fi
6570

6671
if [[ "$AVAILABLE" -ge "$CAPACITY" ]]; then
@@ -131,13 +136,12 @@ ask_for_location() {
131136
echo "✅ Updated and ready to deploy in '$LOCATION'."
132137
exit 0
133138
else
134-
echo "❌ Insufficient quota in '$LOCATION'. Checking fallback regions..."
139+
# echo "❌ Insufficient quota in '$LOCATION'. Checking fallback regions..."
135140
check_fallback_regions
136141
fi
137142
}
138143

139144
check_fallback_regions() {
140-
# Check fallback regions if the primary location fails
141145
for region in "${ALL_REGIONS[@]}"; do
142146
[[ "$region" == "$LOCATION" ]] && continue
143147
check_quota "$region"
@@ -151,24 +155,30 @@ check_fallback_regions() {
151155
TABLE_SHOWN=true
152156
fi
153157

154-
if [[ ${#FALLBACK_RESULTS[@]} -gt 0 ]]; then
158+
if [[ "$RECOMMENDATIONS_SHOWN" == false && ${#FALLBACK_RESULTS[@]} -gt 0 ]]; then
155159
echo -e "\n➡️ Found fallback regions with sufficient quota."
156160
if [[ ${#RECOMMENDED_REGIONS[@]} -gt 0 ]]; then
157161
echo -e "\nℹ️ Recommended regions (≥ $RECOMMENDED_TOKENS tokens available):"
158162
for region in "${RECOMMENDED_REGIONS[@]}"; do
159163
echo " - $region"
160164
done
161165
fi
162-
163166
echo -e "\n❗ The originally selected region '$LOCATION' does not have enough quota."
164167
echo -e "👉 You can manually choose one of the recommended fallback regions for deployment."
168+
RECOMMENDATIONS_SHOWN=true
169+
elif [[ "$RECOMMENDATIONS_SHOWN" == true ]]; then
170+
echo -e "\n⚠️ Could not retrieve the quota info for the region: $LOCATION"
171+
echo "👉 You can manually choose one of the recommended fallback regions for deployment from the list shown above."
165172
else
166173
echo -e "\n❌ ERROR: No region has sufficient quota."
167174
fi
168175

169-
# Allow retry or exit
170176
echo -n "❓ Would you like to retry with a different region? (y/n): "
171177
read -r retry < /dev/tty
178+
while [[ ! "$retry" =~ ^[YyNn]$ ]]; do
179+
echo "❌ Invalid input. Please enter 'y' or 'n': "
180+
read -r retry < /dev/tty
181+
done
172182
if [[ "$retry" =~ ^[Yy]$ ]]; then
173183
ask_for_location
174184
else
@@ -177,53 +187,6 @@ check_fallback_regions() {
177187
fi
178188
}
179189

180-
manual_region_input() {
181-
echo -n "Please enter a region you want to try manually: "
182-
read -r manual_region < /dev/tty
183-
if [[ -z "$manual_region" ]]; then
184-
echo "❌ ERROR: No region entered. Exiting."
185-
exit 1
186-
fi
187-
188-
echo -n "Enter the capacity you want to use (numeric value): "
189-
read -r manual_capacity < /dev/tty
190-
191-
if ! [[ "$manual_capacity" =~ ^[0-9]+$ ]] || (( manual_capacity <= 0 )); then
192-
echo "❌ Invalid capacity value. Try again."
193-
manual_region_input
194-
return
195-
fi
196-
197-
if (( manual_capacity < RECOMMENDED_TOKENS )); then
198-
echo -e "\n⚠️ You have entered a capacity of $manual_capacity, which is less than the recommended minimum ($RECOMMENDED_TOKENS)."
199-
echo -e "🚨 This may cause performance issues or unexpected behavior."
200-
echo -e "ℹ️ Recommended regions (≥ $RECOMMENDED_TOKENS tokens available): ${RECOMMENDED_REGIONS[*]}"
201-
echo -n "❓ Proceed anyway? (y/n): "
202-
read -r proceed_anyway < /dev/tty
203-
while [[ ! "$proceed_anyway" =~ ^[YyNn]$ ]]; do
204-
echo "❌ Invalid input. Please enter 'y' or 'n': "
205-
read -r proceed_anyway < /dev/tty
206-
done
207-
if [[ ! "$proceed_anyway" =~ ^[Yy]$ ]]; then
208-
manual_region_input
209-
return
210-
fi
211-
fi
212-
213-
echo -e "\n🔍 Checking quota in region '$manual_region' for requested capacity: $manual_capacity..."
214-
CAPACITY=$manual_capacity
215-
LOCATION=$manual_region
216-
check_quota "$LOCATION"
217-
218-
if [[ $? -eq 0 ]]; then
219-
update_env_and_parameters "$LOCATION" "$CAPACITY"
220-
echo "✅ Deployment values set. Exiting."
221-
exit 0
222-
else
223-
echo "❌ Quota in region '$LOCATION' is insufficient. Available: $manual_capacity"
224-
fi
225-
}
226-
227190
# ---------- Parse Inputs ----------
228191
while [[ $# -gt 0 ]]; do
229192
case "$1" in

0 commit comments

Comments
 (0)