Setting the file. One moment.
Discover And Rank · Capacity · microsoft/azure-skills · Skills Docs
ContentsBack to the top of the page Raw file
scripts/ discover_and_rank.ps1
PowerShell · 113 lines · 5 KB
13 #>
14 param (
15 [ Parameter ( Mandatory )][ string ]$ModelName ,
16 [ Parameter ( Mandatory )][ string ]$ModelVersion ,
17 [ int ]$MinCapacity = 0
18 )
19
20 $ErrorActionPreference = "Stop"
21
22 $subId = az account show -- query id - o tsv
23
24 # Query model capacity across all regions
25 $capRaw = az rest -- method GET `
26 -- url "https://management.azure.com/subscriptions/ $subId /providers/Microsoft.CognitiveServices/modelCapacities" `
27 -- url - parameters api - version = 2024 - 10 - 01 modelFormat = OpenAI modelName = $ModelName modelVersion = $ModelVersion `
28 2> $null | Out-String | ConvertFrom-Json
29
30 # Query all Microsoft Foundry projects (AIProject kind)
31 $projRaw = az rest -- method GET `
32 -- url "https://management.azure.com/subscriptions/ $subId /providers/Microsoft.CognitiveServices/accounts" `
33 -- url - parameters api - version = 2024 - 10 - 01 `
34 -- query "value[?kind=='AIProject'].{Name:name, Location:location}" `
35 2> $null | Out-String | ConvertFrom-Json
36
37 # Build capacity map (GlobalStandard only, pick max per region)
38 $capMap = @ {}
39 foreach ($item in $capRaw.value) {
40 $sku = $item.properties.skuName
41 $avail = [ int ]$item.properties.availableCapacity
42 $region = $item.location
43 if ($sku -eq "GlobalStandard" -and $avail -gt 0 ) {
44 if ( -not $capMap[$region] -or $avail -gt $capMap[$region]) {
45 $capMap[$region] = $avail
46 }
47 }
48 }
49
50 # Build project map
51 $projMap = @ {}
52 $projSample = @ {}
53 foreach ($p in $projRaw) {
54 $loc = $p.Location
55 if ( -not $projMap[$loc]) { $projMap[$loc] = 0 }
56 $projMap[$loc] ++
57 if ( -not $projSample[$loc]) { $projSample[$loc] = $p.Name }
58 }
59
60 # Check subscription quota per region
61 $quotaMap = @ {}
62 $checkedRegions = @ {}
63 foreach ($region in $capMap.Keys) {
64 if ($checkedRegions[$region]) { continue }
65 $checkedRegions[$region] = $true
66 try {
67 $usageData = az cognitiveservices usage list -- location $region -- subscription $subId - o json 2> $null | Out-String | ConvertFrom-Json
68 $usageEntry = $usageData | Where-Object { $_ .name.value -eq "OpenAI.GlobalStandard. $ModelName " }
69 if ($usageEntry) {
70 $quotaMap[$region] = [ int ]$usageEntry.limit - [ int ]$usageEntry.currentValue
71 } else {
72 $quotaMap[$region] = 0
73 }
74 } catch {
75 $quotaMap[$region] = -1 # Unable to check
76 }
77 }
78
79 # Combine and rank
80 $results = foreach ($region in $capMap.Keys) {
81 $avail = $capMap[$region]
82 $meets = $avail -ge $MinCapacity
83 $quota = if ($quotaMap[$region]) { $quotaMap[$region] } else { 0 }
84 $quotaDisplay = if ($quota -eq -1 ) { "?" } elseif ($quota -gt 0 ) { " ${quota} K" } else { "0" }
85 $quotaOk = $quota -gt 0 -or $quota -eq -1
86 [ PSCustomObject ] @ {
87 Region = $region
88 AvailableTPM = " ${avail} K"
89 AvailableRaw = $avail
90 MeetsTarget = if ($meets) { "YES" } else { "no" }
91 Projects = if ($projMap[$region]) { $projMap[$region] } else { 0 }
92 SampleProject = if ($projSample[$region]) { $projSample[$region] } else { "(none)" }
93 QuotaAvailable = $quotaDisplay
94 QuotaOk = $quotaOk
95 }
96 }
97
98 $results = $results | Sort-Object @ {Expression = { $_ .MeetsTarget -eq "YES" }; Descending = $true } ,
99 @ {Expression = { $_ .QuotaOk}; Descending = $true } ,
100 @ {Expression = { $_ .Projects}; Descending = $true } ,
101 @ {Expression = { $_ .AvailableRaw}; Descending = $true }
102
103 # Output summary
104 $total = ($results | Measure-Object ).Count
105 $matching = ($results | Where-Object { $_ .MeetsTarget -eq "YES" } | Measure-Object ).Count
106 $withQuota = ($results | Where-Object { $_ .MeetsTarget -eq "YES" -and $_ .QuotaOk } | Measure-Object ).Count
107 $withProjects = ($results | Where-Object { $_ .MeetsTarget -eq "YES" -and $_ .Projects -gt 0 } | Measure-Object ).Count
108
109 Write-Host "Model: $ModelName v $ModelVersion | SKU: GlobalStandard | Min Capacity: ${MinCapacity} K TPM"
110 Write-Host "Regions with capacity: $total | Meets target: $matching | With quota: $withQuota | With projects: $withProjects "
111 Write-Host ""
112
113 $results | Select-Object Region , AvailableTPM , MeetsTarget , QuotaAvailable , Projects , SampleProject | Format-Table - AutoSize