forked from bentoml/openllm-models
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_readme.py
80 lines (69 loc) · 2.38 KB
/
gen_readme.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
import os
import yaml
import glob
from collections import defaultdict
from jinja2 import Environment, FileSystemLoader
root_dir = "bentoml/bentos"
grouped_data = defaultdict(list)
model_display_names = {
"llama3": "Llama-3",
"phi3": "Phi-3",
"mistral": "Mistral",
"qwen2": "Qwen-2",
"gemma": "Gemma",
"llama2": "Llama-2",
"mixtral": "Mixtral",
}
model_priority = {
"llama3": 1,
"phi3": 2,
"mistral": 3,
"qwen2": 4,
"gemma": 5,
"llama2": 6,
"mixtral": 7,
}
yaml_files = glob.glob(os.path.join(root_dir, "**/bento.yaml"), recursive=True)
# Read each bento.yaml file and group data by "name" field
for yaml_file in yaml_files:
with open(yaml_file, "r") as f:
data = yaml.safe_load(f)
# Extract the HF model ID from routes.input.model.default
for route in data.get("schema", {}).get("routes", []):
for prop, details in route.get("input", {}).get("properties", {}).items():
if prop == "model" and "default" in details:
data["hf_model"] = details["default"]
break
# Append data to grouped_data
if "name" in data and "version" in data and "hf_model" in data:
grouped_data[data["name"]].append(
{
"name": data["name"],
"version": data["version"],
"hf_model": data["hf_model"],
}
)
# Deduplicate entries
for name in grouped_data:
seen = set()
deduped_items = []
for item in grouped_data[name]:
item_tuple = (item["name"], item["version"], item["hf_model"])
if item_tuple not in seen:
seen.add(item_tuple)
deduped_items.append(item)
grouped_data[name] = deduped_items
# Sort the items within each group by version
for name in grouped_data:
grouped_data[name] = sorted(grouped_data[name], key=lambda x: x["version"])
# Sort the model names by priority and transform grouped_data into a list
sorted_grouped_data = sorted(
grouped_data.items(), key=lambda x: model_priority.get(x[0], float("inf"))
)
env = Environment(loader=FileSystemLoader("."))
template = env.get_template("readme_md.tpl")
readme_content = template.render(
grouped_data=sorted_grouped_data, model_display_names=model_display_names
)
with open("README.md", "w") as readme_file:
readme_file.write(readme_content)