Skip to content

Commit 56cccd2

Browse files
authored
Change the logic to combine subpackages' documentation (#429)
1 parent a2a2626 commit 56cccd2

File tree

2 files changed

+61
-9
lines changed

2 files changed

+61
-9
lines changed

docs/combine_docs.py

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
def rename_subpackage_toc(subpackage: str, toc: Dict):
2222
"""
23-
Extend table of contents sections with subpackage name prefix.
23+
Extend table of contents sections with the subpackage name as the parent folder.
2424
2525
Args:
2626
subpackage (str): subpackage name.
@@ -29,21 +29,73 @@ def rename_subpackage_toc(subpackage: str, toc: Dict):
2929
for item in toc:
3030
for file in item["sections"]:
3131
if "local" in file:
32-
file["local"] = f"{subpackage}_" + file["local"]
32+
file["local"] = f"{subpackage}/" + file["local"]
3333
else:
3434
# if "local" is not in file, it means we have a subsection, hence the recursive call
3535
rename_subpackage_toc(subpackage, [file])
3636

3737

38+
def rename_copy_subpackage_html_paths(subpackage: str, subpackage_path: Path, optimum_path: Path, version: str):
39+
"""
40+
Copy and rename the files from the given subpackage's documentation to Optimum's documentation.
41+
In Optimum's documentation, the subpackage files are organized as follows:
42+
43+
optimum_doc
44+
├──────── subpackage_1
45+
│ ├────── folder_1
46+
│ │ └───── ...
47+
│ ├────── ...
48+
│ └────── folder_x
49+
│ └───── ...
50+
├──────── ...
51+
├──────── subpackage_n
52+
│ ├────── folder_1
53+
│ │ └───── ...
54+
│ ├────── ...
55+
│ └────── folder_y
56+
│ └───── ...
57+
└──────── usual_optimum_doc
58+
59+
Args:
60+
subpackage (str): subpackage name
61+
subpackage_path (Path): path to the subpackage's documentation
62+
optimum_path (Path): path to Optimum's documentation
63+
version (str): Optimum's version
64+
"""
65+
subpackage_html_paths = list(subpackage_path.rglob("*.html"))
66+
# The language folder is the 4th folder in the subpackage HTML paths
67+
language_folder_level = 3
68+
69+
for html_path in subpackage_html_paths:
70+
language_folder = html_path.parts[language_folder_level]
71+
# Build the relative path from the language folder
72+
relative_path_from_language_folder = Path(*html_path.parts[language_folder_level + 1 :])
73+
# New path in Optimum's doc
74+
new_path_in_optimum = Path(
75+
f"{optimum_path}/optimum/{version}/{language_folder}/{subpackage}/{relative_path_from_language_folder}"
76+
)
77+
# Build the parent folders if necessary
78+
new_path_in_optimum.parent.mkdir(parents=True, exist_ok=True)
79+
80+
shutil.copyfile(html_path, new_path_in_optimum)
81+
82+
3883
def main():
3984
args = parser.parse_args()
4085
optimum_path = Path("optimum-doc-build")
86+
87+
# Copy and rename all files from subpackages' docs to Optimum doc
4188
for subpackage in args.subpackages:
4289
subpackage_path = Path(f"{subpackage}-doc-build")
90+
4391
# Copy all HTML files from subpackage into optimum
44-
subpackage_html_paths = list(subpackage_path.rglob("*.html"))
45-
for html_path in subpackage_html_paths:
46-
shutil.copyfile(html_path, f"{optimum_path}/optimum/{args.version}/en/{subpackage}_{html_path.name}")
92+
rename_copy_subpackage_html_paths(
93+
subpackage,
94+
subpackage_path,
95+
optimum_path,
96+
args.version,
97+
)
98+
4799
# Load optimum table of contents
48100
base_toc_path = next(optimum_path.rglob("_toctree.yml"))
49101
with open(base_toc_path, "r") as f:
@@ -52,7 +104,7 @@ def main():
52104
subpackage_toc_path = next(subpackage_path.rglob("_toctree.yml"))
53105
with open(subpackage_toc_path, "r") as f:
54106
subpackage_toc = yaml.safe_load(f)
55-
# Extend table of contents sections with subpackage name prefix
107+
# Extend table of contents sections with the subpackage name as the parent folder
56108
rename_subpackage_toc(subpackage, subpackage_toc)
57109
# Update optimum table of contents
58110
base_toc.extend(subpackage_toc)

docs/source/index.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ As such, 🤗 Optimum enables developers to efficiently use any of these platfor
2121

2222
<div class="mt-10">
2323
<div class="w-full flex flex-col space-y-4 md:space-y-0 md:grid md:grid-cols-3 md:gap-y-4 md:gap-x-5">
24-
<a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./graphcore_index"
24+
<a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./graphcore/index"
2525
><div class="w-full text-center bg-gradient-to-br from-blue-400 to-blue-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">Optimum Graphcore</div>
2626
<p class="text-gray-700">Train transformers on <a href="https://www.graphcore.ai/products/ipu">Graphcore IPUs</a>, a completely new kind of massively parallel processor to accelerate machine intelligence.</p>
2727
</a>
28-
<a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./habana_index"
28+
<a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./habana/index"
2929
><div class="w-full text-center bg-gradient-to-br from-indigo-400 to-indigo-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">Optimum Habana</div>
3030
<p class="text-gray-700">Maximize training throughput and efficiency with <a href="https://docs.habana.ai/en/latest/Gaudi_Overview/Gaudi_Architecture.html">Habana's Gaudi processor</a>.</p>
3131
</a>
32-
<a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./intel_index"
32+
<a class="!no-underline border dark:border-gray-700 p-5 rounded-lg shadow hover:shadow-lg" href="./intel/index"
3333
><div class="w-full text-center bg-gradient-to-br from-pink-400 to-pink-500 rounded-lg py-1.5 font-semibold mb-5 text-white text-lg leading-relaxed">Optimum Intel</div>
3434
<p class="text-gray-700">Use Intel's <a href="https://www.intel.com/content/www/us/en/developer/tools/oneapi/neural-compressor.html">Neural Compressor</a> and <a href="https://docs.openvino.ai/latest/index.html">OpenVINO</a> frameworks to accelerate transformer inference.</p>
3535
</a>

0 commit comments

Comments
 (0)