Skip to content

Commit 9cc4032

Browse files
committed
Update to new PT Theme
stack-info: PR: #2361, branch: drisspg/stack/76
1 parent 399551a commit 9cc4032

File tree

8 files changed

+264
-42
lines changed

8 files changed

+264
-42
lines changed

docs/requirements.txt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
sphinx-gallery>0.11
2-
sphinx==5.0.0
3-
sphinx_design
4-
sphinx_copybutton
5-
sphinx-tabs
6-
matplotlib
7-
myst-parser
8-
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
1+
sphinx==5.3.0
2+
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git@pytorch_sphinx_theme2#egg=pytorch_sphinx_theme2
3+
sphinxcontrib.katex==0.8.6
4+
sphinxext-opengraph==0.9.1
5+
breathe==4.34.0 # only if generating C++
6+
exhale==0.2.3 # only if generating C++ docs
7+
docutils==0.17.1 # Changed from 0.16 to match sphinx-tabs requirement
8+
sphinx-design==0.4.0
9+
sphinxcontrib-mermaid==1.0.0
10+
myst-parser==0.18.1 # if want to contribute in markdown
11+
sphinx-gallery==0.11.1 # if hosting interactive tutorials
12+
sphinx-tabs==3.4.0
13+
sphinx-copybutton==0.5.2
14+
sphinx-sitemap==2.6.0

docs/source/_static/css/custom.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,25 @@ article.pytorch-article .sphx-glr-thumbnails .sphx-glr-thumbcontainer {
185185
article.pytorch-article div.section div.wy-table-responsive tbody td {
186186
width: 50%;
187187
}
188+
189+
/* Mermaid diagram styling */
190+
.mermaid {
191+
text-align: center;
192+
margin: 1.5em 0;
193+
}
194+
195+
/* Ensure mermaid diagrams are visible */
196+
div.mermaid {
197+
display: block !important;
198+
width: 100% !important;
199+
min-height: 200px;
200+
background: #f8f9fa;
201+
border: 1px solid #dee2e6;
202+
border-radius: 0.25rem;
203+
padding: 1rem;
204+
}
205+
206+
/* Fix for mermaid in pytorch theme */
207+
.pytorch-article .mermaid {
208+
overflow: visible !important;
209+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!-- Load Mermaid JS -->
2+
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
3+
<script>
4+
document.addEventListener('DOMContentLoaded', function() {
5+
mermaid.initialize({
6+
startOnLoad: true,
7+
theme: 'default',
8+
flowchart: {
9+
useMaxWidth: true,
10+
htmlLabels: true
11+
}
12+
});
13+
14+
// Force re-render of mermaid diagrams
15+
setTimeout(function() {
16+
mermaid.init();
17+
}, 500);
18+
});
19+
</script>

docs/source/api_reference.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
API Reference
2+
=============
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
api_ref_intro
8+
api_ref_dtypes
9+
api_ref_quantization
10+
api_ref_sparsity
11+
api_ref_float8
12+
api_ref_kernel

docs/source/conf.py

Lines changed: 164 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
import os
2424
import sys
2525

26-
import pytorch_sphinx_theme
27-
from docutils.parsers import rst
26+
sys.path.insert(0, os.path.abspath("."))
27+
import pytorch_sphinx_theme2
2828

29-
sys.path.append(os.path.abspath("."))
29+
html_theme = "pytorch_sphinx_theme2"
30+
html_theme_path = [pytorch_sphinx_theme2.get_html_theme_path()]
3031

3132
# -- General configuration ------------------------------------------------
3233

@@ -46,11 +47,16 @@
4647
"sphinx.ext.napoleon",
4748
"sphinx.ext.viewcode",
4849
"sphinx.ext.duration",
50+
"sphinx.ext.linkcode",
4951
"sphinx_tabs.tabs",
5052
"sphinx_design",
5153
"sphinx_gallery.gen_gallery",
5254
"sphinx_copybutton",
5355
"myst_parser",
56+
"sphinx_sitemap",
57+
"sphinxcontrib.mermaid",
58+
"pytorch_sphinx_theme2",
59+
"sphinxext.opengraph",
5460
]
5561

5662
sphinx_gallery_conf = {
@@ -72,6 +78,10 @@
7278
napoleon_google_docstring = True
7379
project = "torchao"
7480

81+
# -- OpenGraph Protocol settings --
82+
ogp_site_url = "http://pytorch.org/ao"
83+
ogp_image = "https://pytorch.org/assets/images/social-share.jpg"
84+
7585
# Get TORCHAO_VERSION_DOCS during the build.
7686
torchao_version_docs = os.environ.get("TORCHAO_VERSION_DOCS", None)
7787
print(f"torchao_version_docs: {torchao_version_docs}")
@@ -91,8 +101,18 @@
91101
print(f"Version: {version}")
92102
html_title = " ".join((project, version, "documentation"))
93103

104+
# Determine if this is a release build
105+
RELEASE = version != "main"
106+
107+
# Configure version for switcher if you have multiple versions
108+
switcher_version = "main" if not RELEASE else version
109+
94110
# Add any paths that contain templates here, relative to this directory.
95-
templates_path = ["_templates"]
111+
theme_variables = pytorch_sphinx_theme2.get_theme_variables()
112+
templates_path = [
113+
"_templates",
114+
os.path.join(os.path.dirname(pytorch_sphinx_theme2.__file__), "templates"),
115+
]
96116

97117
# The suffix(es) of source filenames.
98118
# You can specify multiple suffix as a list of string:
@@ -102,6 +122,27 @@
102122
".md": "markdown",
103123
}
104124

125+
# Myst-markdown configuration
126+
myst_enable_extensions = [
127+
"colon_fence",
128+
"deflist",
129+
"html_image",
130+
]
131+
132+
# Mermaid configuration
133+
mermaid_version = "10.6.1"
134+
mermaid_output_format = "raw"
135+
mermaid_init_js = """
136+
mermaid.initialize({
137+
startOnLoad: true,
138+
theme: 'default',
139+
flowchart: {
140+
useMaxWidth: true,
141+
htmlLabels: true
142+
}
143+
});
144+
"""
145+
105146
# The master toctree document.
106147
master_doc = "index"
107148

@@ -133,25 +174,90 @@
133174
# The theme to use for HTML and HTML Help pages. See the documentation for
134175
# a list of builtin themes.
135176
#
136-
html_theme = "pytorch_sphinx_theme"
137-
html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]
177+
# Theme configuration is set earlier in the file (lines 29-30)
138178

139179
# Theme options are theme-specific and customize the look and feel of a theme
140180
# further. For a list of options available for each theme, see the
141181
# documentation.
142182
#
143183
html_theme_options = {
144-
"collapse_navigation": False,
184+
"navigation_with_keys": False,
185+
"analytics_id": "GTM-T8XT4PS",
186+
"logo": {
187+
"text": "",
188+
},
189+
"icon_links": [
190+
{
191+
"name": "X",
192+
"url": "https://x.com/PyTorch",
193+
"icon": "fa-brands fa-x-twitter",
194+
},
195+
{
196+
"name": "GitHub",
197+
"url": "https://github.com/pytorch/ao",
198+
"icon": "fa-brands fa-github",
199+
},
200+
{
201+
"name": "Discourse",
202+
"url": "https://dev-discuss.pytorch.org/",
203+
"icon": "fa-brands fa-discourse",
204+
},
205+
{
206+
"name": "PyPi",
207+
"url": "https://pypi.org/project/torchao/",
208+
"icon": "fa-brands fa-python",
209+
},
210+
],
211+
"use_edit_page_button": True,
212+
"navbar_center": "navbar-nav",
213+
# Option 2: Display version in navbar (since torchao is relatively new)
214+
"navbar_start": ["pytorch_version"],
145215
"display_version": True,
146-
"logo_only": True,
147-
"pytorch_project": "docs",
148-
"navigation_with_keys": True,
216+
# Uncomment below when you have multiple versions and a versions.json file
217+
# "switcher": {
218+
# "json_url": "https://pytorch.org/ao/torchao-versions.json",
219+
# "version_match": switcher_version,
220+
# },
221+
# "show_version_warning_banner": True,
222+
# Make the top banner less intrusive on scroll
223+
"announcement": None, # This removes any announcement banner
224+
"navbar_sticky": "top", # Makes navbar sticky but less intrusive
149225
}
150226

151227
html_logo = "_static/img/pytorch-logo-dark.svg"
152228

153229
html_css_files = ["css/custom.css"]
154230

231+
# Add custom JavaScript for mermaid
232+
html_js_files = [
233+
("https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js", {"async": "async"}),
234+
]
235+
236+
# Base URL for sitemap generation
237+
html_baseurl = "https://pytorch.org/ao/"
238+
239+
# Configure date info for "Created On | Last Updated" feature and theme variables
240+
html_context = {
241+
"date_info": {
242+
# Optional: Add paths to skip for performance optimization
243+
"paths_to_skip": [
244+
"gen_modules/", # Skip auto-generated API reference modules
245+
"tutorials/", # Skip auto-generated tutorial gallery
246+
],
247+
},
248+
"theme_variables": theme_variables,
249+
"display_github": True,
250+
"github_url": "https://github.com",
251+
"github_user": "pytorch",
252+
"github_repo": "ao",
253+
"feedback_url": "https://github.com/pytorch/ao",
254+
"github_version": "main",
255+
"doc_path": "docs/source",
256+
"library_links": theme_variables.get("library_links", []),
257+
"community_links": theme_variables.get("community_links", []),
258+
"language_bindings_links": html_theme_options.get("language_bindings_links", []),
259+
}
260+
155261
# Add any paths that contain custom static files (such as style sheets) here,
156262
# relative to this directory. They are copied after the builtin static files,
157263
# so a file named "default.css" will overwrite the builtin "default.css".
@@ -176,8 +282,52 @@
176282
# See http://stackoverflow.com/a/41184353/3343043
177283

178284

179-
from custom_directives import CustomCardEnd, CustomCardItem, CustomCardStart
285+
# Custom directives are now handled by pytorch_sphinx_theme2
286+
# No need to register them manually
287+
288+
289+
import inspect
290+
291+
292+
def linkcode_resolve(domain, info):
293+
"""Link API objects to GitHub source code."""
294+
if domain != "py":
295+
return None
296+
if not info["module"]:
297+
return None
298+
299+
try:
300+
# Import torchao module
301+
import torchao
302+
303+
module = __import__(info["module"], fromlist=[""])
304+
obj = module
305+
for part in info["fullname"].split("."):
306+
obj = getattr(obj, part)
307+
# Get the source file and line number
308+
obj = inspect.unwrap(obj)
309+
fn = inspect.getsourcefile(obj)
310+
_, lineno = inspect.getsourcelines(obj)
311+
except Exception:
312+
return None
313+
314+
# Get the relative path from the torchao package
315+
try:
316+
fn = os.path.relpath(fn, start=os.path.dirname(torchao.__file__))
317+
except Exception:
318+
return None
319+
320+
# Determine the tag/branch based on the version
321+
if RELEASE and version != "main":
322+
# For release versions, use the version tag
323+
tag = f"v{version}"
324+
else:
325+
# For development versions, use main branch
326+
tag = "main"
327+
328+
return f"https://github.com/pytorch/ao/blob/{tag}/torchao/{fn}#L{lineno}"
329+
180330

181-
rst.directives.register_directive("customcardstart", CustomCardStart)
182-
rst.directives.register_directive("customcarditem", CustomCardItem)
183-
rst.directives.register_directive("customcardend", CustomCardEnd)
331+
def setup(app):
332+
"""Configure Sphinx app for pytorch_sphinx_theme2 features."""
333+
app.config.add_last_updated = True

docs/source/developer_notes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Developer Notes
2+
===============
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
quantization
8+
sparsity
9+
dtypes
10+
performant_kernels
11+
contributor_guide

docs/source/index.rst

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,29 @@ using native PyTorch. Please checkout torchao `README <https://github.com/pytorc
77
for an overall introduction to the library and recent highlight and updates.
88

99
.. toctree::
10-
:glob:
1110
:maxdepth: 1
12-
:caption: Getting Started
11+
:hidden:
12+
:caption: Get Started
1313

1414
quick_start
1515

1616
.. toctree::
17-
:glob:
1817
:maxdepth: 1
19-
:caption: Developer Notes
18+
:hidden:
19+
:caption: Tutorials
2020

21-
quantization
22-
sparsity
23-
contributor_guide
21+
tutorials
2422

2523
.. toctree::
26-
:glob:
2724
:maxdepth: 1
28-
:caption: API Reference
25+
:hidden:
26+
:caption: API
2927

30-
api_ref_dtypes
31-
api_ref_quantization
32-
api_ref_sparsity
33-
api_ref_float8
28+
api_reference
3429

3530
.. toctree::
36-
:glob:
3731
:maxdepth: 1
38-
:caption: Tutorials
32+
:hidden:
33+
:caption: Developer
3934

40-
serialization
41-
subclass_basic
42-
subclass_advanced
43-
pretraining
44-
torchao_vllm_integration
35+
developer_notes

0 commit comments

Comments
 (0)