-
Notifications
You must be signed in to change notification settings - Fork 522
Expand file tree
/
Copy pathvalidate_model_deployment_quota.ps1
More file actions
73 lines (58 loc) · 2.5 KB
/
Copy pathvalidate_model_deployment_quota.ps1
File metadata and controls
73 lines (58 loc) · 2.5 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
param (
[string]$SubscriptionId,
[string]$Location,
[string]$ModelsParameter
)
# Verify all required parameters are provided
$MissingParams = @()
if (-not $SubscriptionId) {
$MissingParams += "subscription"
}
if (-not $Location) {
$MissingParams += "location"
}
if (-not $ModelsParameter) {
$MissingParams += "models-parameter"
}
if ($MissingParams.Count -gt 0) {
Write-Error "❌ ERROR: Missing required parameters: $($MissingParams -join ', ')"
Write-Host "Usage: .\validate_model_deployment_quotas.ps1 -SubscriptionId <SUBSCRIPTION_ID> -Location <LOCATION> -ModelsParameter <MODELS_PARAMETER>"
exit 1
}
$JsonContent = Get-Content -Path "./infra/main.parameters.json" -Raw | ConvertFrom-Json
if (-not $JsonContent) {
Write-Error "❌ ERROR: Failed to parse main.parameters.json. Ensure the JSON file is valid."
exit 1
}
$aiModelDeployments = $JsonContent.parameters.$ModelsParameter.value
if (-not $aiModelDeployments -or -not ($aiModelDeployments -is [System.Collections.IEnumerable])) {
Write-Error "❌ ERROR: The specified property $ModelsParameter does not exist or is not an array."
exit 1
}
az account set --subscription $SubscriptionId
Write-Host "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)"
$QuotaAvailable = $true
foreach ($deployment in $aiModelDeployments) {
$name = if ($env:AZURE_ENV_MODEL_NAME) { $env:AZURE_ENV_MODEL_NAME } else { $deployment.name }
$model = if ($env:AZURE_ENV_MODEL_NAME) { $env:AZURE_ENV_MODEL_NAME } else { $deployment.model.name }
$type = if ($env:AZURE_ENV_MODEL_DEPLOYMENT_TYPE) { $env:AZURE_ENV_MODEL_DEPLOYMENT_TYPE } else { $deployment.sku.name }
$capacity = if ($env:AZURE_ENV_MODEL_CAPACITY) { $env:AZURE_ENV_MODEL_CAPACITY } else { $deployment.sku.capacity }
Write-Host "`n🔍 Validating model deployment: $name ..."
& .\scripts\validate_model_quota.ps1 -Location $Location -Model $model -Capacity $capacity -DeploymentType $type
$exitCode = $LASTEXITCODE
if ($exitCode -ne 0) {
if ($exitCode -eq 2) {
# Quota error already printed inside the script, exit gracefully without reprinting
exit 1
}
Write-Error "❌ ERROR: Quota validation failed for model deployment: $name"
$QuotaAvailable = $false
}
}
if (-not $QuotaAvailable) {
Write-Error "❌ ERROR: One or more model deployments failed validation."
exit 1
} else {
Write-Host "✅ All model deployments passed quota validation successfully."
exit 0
}