csukuangfj
commited on
Commit
•
1bac49a
1
Parent(s):
4729e5b
update run.sh
Browse files- run.sh +2 -0
- update-k2-doc-cpu-macos.py +143 -0
- update-k2-doc-cpu-windows.py +143 -0
run.sh
CHANGED
@@ -6,5 +6,7 @@ fi
|
|
6 |
|
7 |
./update_readme.py
|
8 |
./update-k2-doc-cpu-linux.py
|
|
|
|
|
9 |
./update-k2-doc-cuda-linux.py
|
10 |
|
|
|
6 |
|
7 |
./update_readme.py
|
8 |
./update-k2-doc-cpu-linux.py
|
9 |
+
./update-k2-doc-cpu-macos.py
|
10 |
+
./update-k2-doc-cpu-windows.py
|
11 |
./update-k2-doc-cuda-linux.py
|
12 |
|
update-k2-doc-cpu-macos.py
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
|
3 |
+
import os
|
4 |
+
import re
|
5 |
+
from collections import defaultdict
|
6 |
+
from pathlib import Path
|
7 |
+
from typing import Dict, List, Tuple
|
8 |
+
|
9 |
+
from update_readme import generate_url, get_all_files
|
10 |
+
|
11 |
+
|
12 |
+
class Wheel:
|
13 |
+
def __init__(self, full_name: str, url: str):
|
14 |
+
"""
|
15 |
+
Args:
|
16 |
+
full_name:
|
17 |
+
Example: k2-1.24.3.dev20230720+cpu.torch1.10.0-cp36-cp36m-macosx_10_9_x86_64.whl
|
18 |
+
"""
|
19 |
+
self.full_name = full_name
|
20 |
+
# pattern = r"k2-(\d)\.(\d+)(\.(\d+))?\.dev(\d{8})+cpu\.torch(\d\.\d+)"
|
21 |
+
pattern = (
|
22 |
+
r"k2-(\d)\.(\d)+((\.)(\d))?\.dev(\d{8})\+cpu\.torch(\d\.\d+\.\d)-cp(\d+)"
|
23 |
+
)
|
24 |
+
m = re.search(pattern, full_name)
|
25 |
+
|
26 |
+
self.k2_major = int(m.group(1))
|
27 |
+
self.k2_minor = int(m.group(2))
|
28 |
+
self.k2_patch = int(m.group(5))
|
29 |
+
self.k2_date = int(m.group(6))
|
30 |
+
self.torch_version = m.group(7)
|
31 |
+
self.py_version = int(m.group(8))
|
32 |
+
self.url = url
|
33 |
+
|
34 |
+
def __str__(self):
|
35 |
+
return self.url
|
36 |
+
|
37 |
+
def __repr__(self):
|
38 |
+
return self.url
|
39 |
+
|
40 |
+
|
41 |
+
def generate_index(filename: str, torch_versions) -> str:
|
42 |
+
b = []
|
43 |
+
for i in torch_versions:
|
44 |
+
b.append(f" ./{i}.rst")
|
45 |
+
b = "\n".join(b)
|
46 |
+
|
47 |
+
s = f"""\
|
48 |
+
Pre-compiled CPU wheels (macOS)
|
49 |
+
===============================
|
50 |
+
|
51 |
+
This page describes pre-compiled ``CPU`` wheels for `k2`_ on macOS.
|
52 |
+
|
53 |
+
.. toctree::
|
54 |
+
:maxdepth: 2
|
55 |
+
|
56 |
+
{b}
|
57 |
+
"""
|
58 |
+
with open(filename, "w") as f:
|
59 |
+
f.write(s)
|
60 |
+
|
61 |
+
|
62 |
+
def sort_by_wheel(x: Wheel):
|
63 |
+
return x.k2_major, x.k2_minor, x.k2_patch, x.k2_date, x.py_version
|
64 |
+
|
65 |
+
|
66 |
+
def sort_by_torch(x):
|
67 |
+
major, minor, patch = x.split(".")
|
68 |
+
return int(major), int(minor), int(patch)
|
69 |
+
|
70 |
+
|
71 |
+
def get_all_torch_versions(wheels: List[Wheel]) -> List[str]:
|
72 |
+
ans = set()
|
73 |
+
for w in wheels:
|
74 |
+
ans.add(w.torch_version)
|
75 |
+
|
76 |
+
# sort torch version from high to low
|
77 |
+
ans = list(ans)
|
78 |
+
ans.sort(reverse=True, key=sort_by_torch)
|
79 |
+
return ans
|
80 |
+
|
81 |
+
|
82 |
+
def get_doc_dir():
|
83 |
+
k2_dir = os.getenv("K2_DIR")
|
84 |
+
if k2_dir is None:
|
85 |
+
raise ValueError("Please set the environment variable k2_dir")
|
86 |
+
|
87 |
+
cpu_dir = Path(k2_dir) / "docs/source/installation/pre-compiled-cpu-wheels-macos"
|
88 |
+
|
89 |
+
if not Path(cpu_dir).is_dir():
|
90 |
+
raise ValueError(f"{cpu_dir} does not exist")
|
91 |
+
|
92 |
+
print(f"k2 doc cpu_dir: {cpu_dir}")
|
93 |
+
return cpu_dir
|
94 |
+
|
95 |
+
|
96 |
+
def remove_all_files(d: str):
|
97 |
+
files = get_all_files(d, "*.rst")
|
98 |
+
for f in files:
|
99 |
+
print(f"removing {f}")
|
100 |
+
os.remove(f)
|
101 |
+
|
102 |
+
|
103 |
+
def get_all_cpu_wheels():
|
104 |
+
cpu = get_all_files("macos", suffix="*.whl")
|
105 |
+
cpu_wheels = generate_url(cpu)
|
106 |
+
return cpu_wheels
|
107 |
+
|
108 |
+
|
109 |
+
def generate_file(d: str, torch_version: str, wheels: List[Wheel]) -> str:
|
110 |
+
s = f"torch {torch_version}\n"
|
111 |
+
s += "=" * len(f"torch {torch_version}")
|
112 |
+
s += "\n" * 3
|
113 |
+
wheels = filter(lambda w: w.torch_version == torch_version, wheels)
|
114 |
+
wheels = list(wheels)
|
115 |
+
wheels.sort(reverse=True, key=sort_by_wheel)
|
116 |
+
for w in wheels:
|
117 |
+
s += f"- `{w.full_name} <{w.url}>`_\n"
|
118 |
+
|
119 |
+
with open(f"{d}/{torch_version}.rst", "w") as f:
|
120 |
+
f.write(s)
|
121 |
+
|
122 |
+
|
123 |
+
def main():
|
124 |
+
d = get_doc_dir()
|
125 |
+
remove_all_files(d)
|
126 |
+
|
127 |
+
urls = get_all_cpu_wheels()
|
128 |
+
|
129 |
+
wheels = []
|
130 |
+
for url in urls:
|
131 |
+
full_name = url.rsplit("/", maxsplit=1)[1]
|
132 |
+
wheels.append(Wheel(full_name, url))
|
133 |
+
torch_versions = get_all_torch_versions(wheels)
|
134 |
+
|
135 |
+
content = []
|
136 |
+
for t in torch_versions:
|
137 |
+
s = generate_file(d, t, wheels)
|
138 |
+
|
139 |
+
generate_index(f"{d}/index.rst", torch_versions)
|
140 |
+
|
141 |
+
|
142 |
+
if __name__ == "__main__":
|
143 |
+
main()
|
update-k2-doc-cpu-windows.py
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
|
3 |
+
import os
|
4 |
+
import re
|
5 |
+
from collections import defaultdict
|
6 |
+
from pathlib import Path
|
7 |
+
from typing import Dict, List, Tuple
|
8 |
+
|
9 |
+
from update_readme import generate_url, get_all_files
|
10 |
+
|
11 |
+
|
12 |
+
class Wheel:
|
13 |
+
def __init__(self, full_name: str, url: str):
|
14 |
+
"""
|
15 |
+
Args:
|
16 |
+
full_name:
|
17 |
+
Example: k2-1.24.3.dev20230720+cpu.torch1.10.0-cp37-cp37m-win_amd64.whl
|
18 |
+
"""
|
19 |
+
self.full_name = full_name
|
20 |
+
# pattern = r"k2-(\d)\.(\d+)(\.(\d+))?\.dev(\d{8})+cpu\.torch(\d\.\d+)"
|
21 |
+
pattern = (
|
22 |
+
r"k2-(\d)\.(\d)+((\.)(\d))?\.dev(\d{8})\+cpu\.torch(\d\.\d+\.\d)-cp(\d+)"
|
23 |
+
)
|
24 |
+
m = re.search(pattern, full_name)
|
25 |
+
|
26 |
+
self.k2_major = int(m.group(1))
|
27 |
+
self.k2_minor = int(m.group(2))
|
28 |
+
self.k2_patch = int(m.group(5))
|
29 |
+
self.k2_date = int(m.group(6))
|
30 |
+
self.torch_version = m.group(7)
|
31 |
+
self.py_version = int(m.group(8))
|
32 |
+
self.url = url
|
33 |
+
|
34 |
+
def __str__(self):
|
35 |
+
return self.url
|
36 |
+
|
37 |
+
def __repr__(self):
|
38 |
+
return self.url
|
39 |
+
|
40 |
+
|
41 |
+
def generate_index(filename: str, torch_versions) -> str:
|
42 |
+
b = []
|
43 |
+
for i in torch_versions:
|
44 |
+
b.append(f" ./{i}.rst")
|
45 |
+
b = "\n".join(b)
|
46 |
+
|
47 |
+
s = f"""\
|
48 |
+
Pre-compiled CPU wheels (Windows)
|
49 |
+
=================================
|
50 |
+
|
51 |
+
This page describes pre-compiled ``CPU`` wheels for `k2`_ on Windows.
|
52 |
+
|
53 |
+
.. toctree::
|
54 |
+
:maxdepth: 2
|
55 |
+
|
56 |
+
{b}
|
57 |
+
"""
|
58 |
+
with open(filename, "w") as f:
|
59 |
+
f.write(s)
|
60 |
+
|
61 |
+
|
62 |
+
def sort_by_wheel(x: Wheel):
|
63 |
+
return x.k2_major, x.k2_minor, x.k2_patch, x.k2_date, x.py_version
|
64 |
+
|
65 |
+
|
66 |
+
def sort_by_torch(x):
|
67 |
+
major, minor, patch = x.split(".")
|
68 |
+
return int(major), int(minor), int(patch)
|
69 |
+
|
70 |
+
|
71 |
+
def get_all_torch_versions(wheels: List[Wheel]) -> List[str]:
|
72 |
+
ans = set()
|
73 |
+
for w in wheels:
|
74 |
+
ans.add(w.torch_version)
|
75 |
+
|
76 |
+
# sort torch version from high to low
|
77 |
+
ans = list(ans)
|
78 |
+
ans.sort(reverse=True, key=sort_by_torch)
|
79 |
+
return ans
|
80 |
+
|
81 |
+
|
82 |
+
def get_doc_dir():
|
83 |
+
k2_dir = os.getenv("K2_DIR")
|
84 |
+
if k2_dir is None:
|
85 |
+
raise ValueError("Please set the environment variable k2_dir")
|
86 |
+
|
87 |
+
cpu_dir = Path(k2_dir) / "docs/source/installation/pre-compiled-cpu-wheels-windows"
|
88 |
+
|
89 |
+
if not Path(cpu_dir).is_dir():
|
90 |
+
raise ValueError(f"{cpu_dir} does not exist")
|
91 |
+
|
92 |
+
print(f"k2 doc cpu_dir: {cpu_dir}")
|
93 |
+
return cpu_dir
|
94 |
+
|
95 |
+
|
96 |
+
def remove_all_files(d: str):
|
97 |
+
files = get_all_files(d, "*.rst")
|
98 |
+
for f in files:
|
99 |
+
print(f"removing {f}")
|
100 |
+
os.remove(f)
|
101 |
+
|
102 |
+
|
103 |
+
def get_all_cpu_wheels():
|
104 |
+
cpu = get_all_files("windows-cpu", suffix="*.whl")
|
105 |
+
cpu_wheels = generate_url(cpu)
|
106 |
+
return cpu_wheels
|
107 |
+
|
108 |
+
|
109 |
+
def generate_file(d: str, torch_version: str, wheels: List[Wheel]) -> str:
|
110 |
+
s = f"torch {torch_version}\n"
|
111 |
+
s += "=" * len(f"torch {torch_version}")
|
112 |
+
s += "\n" * 3
|
113 |
+
wheels = filter(lambda w: w.torch_version == torch_version, wheels)
|
114 |
+
wheels = list(wheels)
|
115 |
+
wheels.sort(reverse=True, key=sort_by_wheel)
|
116 |
+
for w in wheels:
|
117 |
+
s += f"- `{w.full_name} <{w.url}>`_\n"
|
118 |
+
|
119 |
+
with open(f"{d}/{torch_version}.rst", "w") as f:
|
120 |
+
f.write(s)
|
121 |
+
|
122 |
+
|
123 |
+
def main():
|
124 |
+
d = get_doc_dir()
|
125 |
+
remove_all_files(d)
|
126 |
+
|
127 |
+
urls = get_all_cpu_wheels()
|
128 |
+
|
129 |
+
wheels = []
|
130 |
+
for url in urls:
|
131 |
+
full_name = url.rsplit("/", maxsplit=1)[1]
|
132 |
+
wheels.append(Wheel(full_name, url))
|
133 |
+
torch_versions = get_all_torch_versions(wheels)
|
134 |
+
|
135 |
+
content = []
|
136 |
+
for t in torch_versions:
|
137 |
+
s = generate_file(d, t, wheels)
|
138 |
+
|
139 |
+
generate_index(f"{d}/index.rst", torch_versions)
|
140 |
+
|
141 |
+
|
142 |
+
if __name__ == "__main__":
|
143 |
+
main()
|