|
1 | 1 | #!/usr/bin/env python3 |
| 2 | + |
| 3 | +import json |
2 | 4 | from datetime import datetime |
3 | 5 | from textwrap import dedent |
| 6 | +from typing import Iterable |
4 | 7 |
|
5 | 8 | import yaml |
6 | 9 |
|
7 | 10 |
|
8 | 11 | MD_FILENAME = "DEPLOYMENTS.md" |
| 12 | +A100_TOTAL_MEM = 220 # Gi |
| 13 | + |
| 14 | + |
| 15 | +def flatten(l: Iterable) -> list: |
| 16 | + ret = [] |
| 17 | + for el in l: |
| 18 | + if isinstance(el, list): |
| 19 | + ret.extend(flatten(el)) |
| 20 | + else: |
| 21 | + ret.append(el) |
| 22 | + return ret |
| 23 | + |
9 | 24 |
|
10 | | -def stringify_nodeselector(selector: dict[str, str]): |
11 | | - # separate with markdown linebreak |
12 | | - return " * ".join([f"{k}={v}" for k, v in selector.items()]) |
| 25 | +def get_model_usage(filename): |
| 26 | + with open(filename) as f: |
| 27 | + values = json.load(f) |
| 28 | + return {row["model"]: row["Count"] for row in values} |
13 | 29 |
|
14 | 30 |
|
15 | 31 | def get_deployments(filename): |
16 | 32 | # filename: yaml filename |
17 | 33 | with open(filename) as f: |
18 | 34 | values = yaml.safe_load(f) |
19 | 35 | deployments = values["deployments"] |
20 | | - return {depl["name"]: stringify_nodeselector(depl["nodeSelector"]) for depl in deployments} |
| 36 | + queue_name_vars = values["autoscaling"]["queueNameVars"] |
| 37 | + return [ |
| 38 | + { |
| 39 | + "name": depl["name"], |
| 40 | + "memoryLimit": depl.get("limits", {}).get("memory", None), |
| 41 | + "replicas": depl.get("autoscaling", {}).get("minReplicaCount", 1), |
| 42 | + "models": list( |
| 43 | + filter( |
| 44 | + bool, |
| 45 | + flatten( |
| 46 | + [ |
| 47 | + depl.get("env", {}).get(qnv, "").split("\n") |
| 48 | + for qnv in queue_name_vars |
| 49 | + ] |
| 50 | + ), |
| 51 | + ) |
| 52 | + ), |
| 53 | + } |
| 54 | + for depl in deployments |
| 55 | + ] |
21 | 56 |
|
22 | 57 |
|
23 | 58 | def main(): |
24 | | - gcp_deployments = get_deployments(filename="chart/values.yaml") |
25 | | - az_deployments = get_deployments(filename="chart/values-azure.yaml") |
| 59 | + deployments = get_deployments(filename="chart/model-values.yaml") |
26 | 60 |
|
27 | 61 | md_table = [ |
28 | | - ["Model ID", "GCP", "Azure", "Node Selector (GCP)", "Node Selector (Azure)"], |
| 62 | + ["Name", "% of A100", "Replicas", "Model IDs"], |
29 | 63 | ] |
30 | 64 |
|
31 | | - deployment_info = {} |
32 | | - for model_id in gcp_deployments | az_deployments: |
33 | | - deployment_info.setdefault( |
34 | | - model_id, |
35 | | - {"GCP": "❌", "Azure": "❌", "Node Selector (GCP)": "", "Node Selector (Azure)": ""}, |
| 65 | + for info in deployments: |
| 66 | + if memoryLimit := info["memoryLimit"]: |
| 67 | + a100_fraction = int(memoryLimit.removesuffix("Gi")) / A100_TOTAL_MEM |
| 68 | + else: |
| 69 | + a100_fraction = None |
| 70 | + md_table.append( |
| 71 | + [ |
| 72 | + info["name"], |
| 73 | + f"{a100_fraction:.2%}" if a100_fraction else "N/A", |
| 74 | + str(info["replicas"]), |
| 75 | + (info["models"] or ["N/A"])[0], |
| 76 | + ] |
36 | 77 | ) |
37 | | - if info := az_deployments.get(model_id): |
38 | | - deployment_info[model_id]["Azure"] = "✅" |
39 | | - deployment_info[model_id]["Node Selector (Azure)"] = info |
40 | | - if info := gcp_deployments.get(model_id): |
41 | | - deployment_info[model_id]["GCP"] = "✅" |
42 | | - deployment_info[model_id]["Node Selector (GCP)"] = info |
43 | | - |
44 | | - for model_id, info in deployment_info.items(): |
45 | | - md_table.append([model_id, info["GCP"], info["Azure"], info["Node Selector (GCP)"], info["Node Selector (Azure)"]]) |
| 78 | + for model in info["models"][1:]: |
| 79 | + md_table.append(["", "", "", model]) |
46 | 80 |
|
47 | 81 | with open(MD_FILENAME, "w") as f: |
48 | | - f.write(dedent(f"""\ |
| 82 | + f.write( |
| 83 | + dedent( |
| 84 | + f"""\ |
49 | 85 | # Deployments Table |
50 | 86 |
|
51 | 87 | Generated by {__file__.rsplit("/", maxsplit=1)[-1]} on {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}. |
52 | 88 |
|
53 | | - """)) |
| 89 | + """ |
| 90 | + ) |
| 91 | + ) |
54 | 92 |
|
55 | 93 | header = "| " + " | ".join(md_table[0]) + " |\n" |
56 | 94 | f.write(header) |
|
0 commit comments