Setting the file. One moment.
Discover And Rank · Capacity · microsoft/azure-skills · Skills Docs
ContentsBack to the top of the page (opens in a new tab)
scripts/ discover_and_rank.sh
Shell · 113 lines · 5 KB
$0
<
model-name
> <
model-version
> [min-capacity]
}
"
14 MODEL_VERSION = " ${2 :? Usage : $0 < model-name > < model-version > [min-capacity] } "
15 MIN_CAPACITY = " ${3 :- 0} "
16
17 SUB_ID = $( az account show --query id -o tsv )
18
19 # Query model capacity across all regions (GlobalStandard SKU)
20 CAPACITY_JSON = $( az rest --method GET \
21 --url "https://management.azure.com/subscriptions/${ SUB_ID }/providers/Microsoft.CognitiveServices/modelCapacities" \
22 --url-parameters api-version=2024-10-01 modelFormat=OpenAI modelName=" $MODEL_NAME " modelVersion=" $MODEL_VERSION " \
23 2> /dev/null )
24
25 # Query all AI Services projects
26 PROJECTS_JSON = $( az rest --method GET \
27 --url "https://management.azure.com/subscriptions/${ SUB_ID }/providers/Microsoft.CognitiveServices/accounts" \
28 --url-parameters api-version=2024-10-01 \
29 --query "value[?kind=='AIServices'].{name:name, location:location}" \
30 2> /dev/null )
31
32 # Get unique regions from capacity results for quota checking
33 REGIONS = $( echo " $CAPACITY_JSON " | jq -r '.value[] | select(.properties.skuName=="GlobalStandard" and .properties.availableCapacity > 0) | .location' | sort -u )
34
35 # Build quota map: check subscription quota per region
36 declare -A QUOTA_MAP
37 for region in $REGIONS; do
38 usage_json = $( az cognitiveservices usage list --location " $region " --subscription " $SUB_ID " -o json 2> /dev/null || echo "[]" )
39 quota_avail = $( echo " $usage_json " | jq -r --arg name "OpenAI.GlobalStandard. $MODEL_NAME " \
40 '[.[] | select(.name.value == $name)] | if length > 0 then .[0].limit - .[0].currentValue else 0 end' )
41 QUOTA_MAP[$region] = "${ quota_avail :- 0 }"
42 done
43
44 # Export quota map as JSON for Python
45 QUOTA_JSON = "{"
46 first = true
47 for region in "${ ! QUOTA_MAP [ @ ]}" ; do
48 if [ " $first " = true ]; then first = false ; else QUOTA_JSON += "," ; fi
49 QUOTA_JSON += " \" $region \" :${ QUOTA_MAP [ $region ]}"
50 done
51 QUOTA_JSON += "}"
52
53 # Combine, rank, and output using inline Python (available on all Azure CLI installs)
54 python3 -c "
55 import json, sys
56
57 capacity = json.loads('''${ CAPACITY_JSON }''')
58 projects = json.loads('''${ PROJECTS_JSON }''')
59 quota = json.loads('''${ QUOTA_JSON }''')
60 min_cap = int('${ MIN_CAPACITY }')
61
62 # Build capacity map (GlobalStandard only)
63 cap_map = {}
64 for item in capacity.get('value', []):
65 props = item.get('properties', {})
66 if props.get('skuName') == 'GlobalStandard' and props.get('availableCapacity', 0) > 0:
67 region = item.get('location', '')
68 cap_map[region] = max(cap_map.get(region, 0), props['availableCapacity'])
69
70 # Build project count map
71 proj_map = {}
72 proj_sample = {}
73 for p in (projects if isinstance(projects, list) else []):
74 loc = p.get('location', '')
75 proj_map[loc] = proj_map.get(loc, 0) + 1
76 if loc not in proj_sample:
77 proj_sample[loc] = p.get('name', '')
78
79 # Combine and rank
80 results = []
81 for region, cap in cap_map.items():
82 meets = cap >= min_cap
83 q = quota.get(region, 0)
84 quota_ok = q > 0
85 results.append({
86 'region': region,
87 'available': cap,
88 'meets': meets,
89 'projects': proj_map.get(region, 0),
90 'sample': proj_sample.get(region, '(none)'),
91 'quota': q,
92 'quota_ok': quota_ok
93 })
94
95 # Sort: meets target first, then quota available, then by project count, then by capacity
96 results.sort(key=lambda x: (-x['meets'], -x['quota_ok'], -x['projects'], -x['available']))
97
98 # Output
99 total = len(results)
100 matching = sum(1 for r in results if r['meets'])
101 with_quota = sum(1 for r in results if r['meets'] and r['quota_ok'])
102 with_projects = sum(1 for r in results if r['meets'] and r['projects'] > 0)
103
104 print(f'Model: { \" ${ MODEL_NAME } \" } v{ \" ${ MODEL_VERSION } \" } | SKU: GlobalStandard | Min Capacity: {min_cap}K TPM')
105 print(f'Regions with capacity: {total} | Meets target: {matching} | With quota: {with_quota} | With projects: {with_projects}')
106 print()
107 print(f'{ \" Region \" :<22} { \" Available \" :<12} { \" Meets Target \" :<14} { \" Quota \" :<12} { \" Projects \" :<10} { \" Sample Project \" }')
108 print('-' * 100)
109 for r in results:
110 mark = 'YES' if r['meets'] else 'no'
111 q_display = f'{r[ \" quota \" ]}K' if r['quota'] > 0 else '0 (none)'
112 print(f'{r[ \" region \" ]:<22} {r[ \" available \" ]}K{ \"\" :.<10} {mark:<14} {q_display:<12} {r[ \" projects \" ]:<10} {r[ \" sample \" ]}')
113 "