-
Notifications
You must be signed in to change notification settings - Fork 834
Expand file tree
/
Copy pathvalidate_model_quota.ps1
More file actions
108 lines (87 loc) · 3.94 KB
/
Copy pathvalidate_model_quota.ps1
File metadata and controls
108 lines (87 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
param (
[string]$Location,
[string]$Model,
[string]$DeploymentType = "GlobalStandard",
[int]$Capacity
)
# Verify required parameters
$MissingParams = @()
if (-not $Location) { $MissingParams += "location" }
if (-not $Model) { $MissingParams += "model" }
if (-not $Capacity) { $MissingParams += "capacity" }
if (-not $DeploymentType) { $MissingParams += "deployment-type" }
if ($MissingParams.Count -gt 0) {
Write-Error "❌ ERROR: Missing required parameters: $($MissingParams -join ', ')"
Write-Host "Usage: .\validate_model_quota.ps1 -Location <LOCATION> -Model <MODEL> -Capacity <CAPACITY> [-DeploymentType <DEPLOYMENT_TYPE>]"
exit 1
}
if ($DeploymentType -ne "Standard" -and $DeploymentType -ne "GlobalStandard") {
Write-Error "❌ ERROR: Invalid deployment type: $DeploymentType. Allowed values are 'Standard' or 'GlobalStandard'."
exit 1
}
$ModelType = "OpenAI.$DeploymentType.$Model"
$PreferredRegions = @('australiaeast', 'eastus2', 'francecentral', 'japaneast', 'norwayeast', 'swedencentral', 'uksouth', 'westus')
$AllResults = @()
function Check-Quota {
param (
[string]$Region
)
$ModelInfoRaw = az cognitiveservices usage list --location $Region --query "[?name.value=='$ModelType']" --output json
$ModelInfo = $null
try {
$ModelInfo = $ModelInfoRaw | ConvertFrom-Json
} catch {
return
}
if (-not $ModelInfo) {
return
}
$CurrentValue = ($ModelInfo | Where-Object { $_.name.value -eq $ModelType }).currentValue
$Limit = ($ModelInfo | Where-Object { $_.name.value -eq $ModelType }).limit
$CurrentValue = [int]($CurrentValue -replace '\.0+$', '')
$Limit = [int]($Limit -replace '\.0+$', '')
$Available = $Limit - $CurrentValue
$script:AllResults += [PSCustomObject]@{
Region = $Region
Model = $ModelType
Limit = $Limit
Used = $CurrentValue
Available = $Available
}
}
foreach ($region in $PreferredRegions) {
Check-Quota -Region $region
}
# Display Results Table
Write-Host "\n-------------------------------------------------------------------------------------------------------------"
Write-Host "| No. | Region | Model Name | Limit | Used | Available |"
Write-Host "-------------------------------------------------------------------------------------------------------------"
$count = 1
foreach ($entry in $AllResults) {
$index = $PreferredRegions.IndexOf($entry.Region) + 1
$modelShort = $entry.Model.Substring($entry.Model.LastIndexOf(".") + 1)
Write-Host ("| {0,-4} | {1,-16} | {2,-35} | {3,-7} | {4,-7} | {5,-9} |" -f $index, $entry.Region, $entry.Model, $entry.Limit, $entry.Used, $entry.Available)
$count++
}
Write-Host "-------------------------------------------------------------------------------------------------------------"
$EligibleRegion = $AllResults | Where-Object { $_.Region -eq $Location -and $_.Available -ge $Capacity }
if ($EligibleRegion) {
Write-Host "\n✅ Sufficient quota found in original region '$Location'."
exit 0
}
$FallbackRegions = $AllResults | Where-Object { $_.Region -ne $Location -and $_.Available -ge $Capacity }
if ($FallbackRegions.Count -gt 0) {
Write-Host "`n❌ Deployment cannot proceed because the original region '$Location' lacks sufficient quota."
Write-Host "➡️ You can retry using one of the following regions with sufficient quota:`n"
foreach ($region in $FallbackRegions) {
Write-Host " • $($region.Region) (Available: $($region.Available))"
}
Write-Host "`n🔧 To proceed, run:"
Write-Host " azd env set AZURE_ENV_OPENAI_LOCATION '<region>'"
Write-Host "📌 To confirm it's set correctly, run:"
Write-Host " azd env get-value AZURE_ENV_OPENAI_LOCATION"
Write-Host "▶️ Once confirmed, re-run azd up to deploy the model in the new region."
exit 2
}
Write-Error "❌ ERROR: No available quota found in any region."
exit 1