-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_models.py
99 lines (80 loc) · 3.19 KB
/
check_models.py
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
import requests
from datetime import datetime
# List of base URLs to compare
base_urls = [
"https://us-south.ml.cloud.ibm.com",
"https://eu-de.ml.cloud.ibm.com",
"https://jp-tok.ml.cloud.ibm.com",
"https://au-syd.ml.cloud.ibm.com"
]
endpoint = "/ml/v1/foundation_model_specs"
params = {
"version": "2024-09-16",
"filters": "function_embedding,!lifecycle_withdrawn" #"function_text_chat,!lifecycle_withdrawn"
}
# Get today's date
today = datetime.today().strftime("%Y-%m-%d")
results = {}
model_sets = {}
# Function to check if a model is deprecated or withdrawn
def is_deprecated_or_withdrawn(lifecycle):
for entry in lifecycle:
if entry["id"] in {"deprecated", "withdrawn"} and entry["start_date"] <= today:
return True
return False
# Fetch models from each region
for base_url in base_urls:
url = f"{base_url}{endpoint}"
print(f"Fetching models from {url} with params {params}")
try:
response = requests.get(url, params=params, timeout=10)
response.raise_for_status()
data = response.json()
# Store response data
results[base_url] = data
# Extract and filter model IDs based on lifecycle status
model_sets[base_url] = {
model["model_id"]
for model in data.get("resources", [])
if not is_deprecated_or_withdrawn(model.get("lifecycle", []))
}
except requests.exceptions.RequestException as e:
print(f"Error fetching from {base_url}: {e}")
results[base_url] = None
model_sets[base_url] = set()
# Reference model set (US-South)
us_south_models = model_sets["https://us-south.ml.cloud.ibm.com"]
# Compare models across regions
for base_url, models in model_sets.items():
if base_url == "https://us-south.ml.cloud.ibm.com":
continue # Skip comparison for US-South itself
missing_models = us_south_models - models
if missing_models:
print(f"\nModels missing in {base_url} compared to US-South (excluding deprecated/withdrawn models):")
for model in missing_models:
print(f" - {model}")
else:
print(f"\n{base_url} has all active models present in US-South.")
# Reference model set (US-South)
us_south_models = model_sets["https://us-south.ml.cloud.ibm.com"]
# Compare models in other regions and find those not in US-South
for base_url, models in model_sets.items():
if base_url == "https://us-south.ml.cloud.ibm.com":
continue # Skip comparison for US-South itself
# Find models in the current region that are NOT in US-South
unique_models = models - us_south_models
if unique_models:
print(f"\nModels in {base_url} but not in US-South (excluding deprecated/withdrawn models):")
for model in unique_models:
print(f" - {model}")
else:
print(f"\nNo unique models in {base_url} compared to US-South.")
# Find models present in all regions
common_models = set.intersection(*model_sets.values())
if common_models:
print("\nModels present in all regions (excluding deprecated/withdrawn models):")
for model in common_models:
print(f" - {model}")
else:
print("\nNo models are present in all regions.")
print()