Skip to content

Commit 1f4b81a

Browse files
committed
Update to new PT Theme
stack-info: PR: #2361, branch: drisspg/stack/76
1 parent eaaf787 commit 1f4b81a

File tree

7 files changed

+245
-42
lines changed

7 files changed

+245
-42
lines changed

docs/requirements.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
sphinx-gallery>0.11
2-
sphinx==5.0.0
3-
sphinx_design
4-
sphinx_copybutton
5-
sphinx-tabs
6-
matplotlib
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+
docutils==0.17.1 # Changed from 0.16 to match sphinx-tabs requirement
6+
sphinx-design==0.4.0
7+
sphinxcontrib-mermaid==1.0.0
8+
myst-parser==0.18.1 # if want to contribute in markdown
9+
sphinx-gallery==0.11.1 # if hosting interactive tutorials
10+
sphinx-tabs==3.4.0
11+
sphinx-copybutton==0.5.2
12+
sphinx-sitemap==2.6.0
713
myst-parser
814
sphinxcontrib-mermaid==1.0.0
9-
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme

docs/source/_static/css/custom.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,40 @@ 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+
}
210+
211+
/* Fix for navbar overlapping content */
212+
.bd-container {
213+
padding-top: 1rem !important;
214+
}
215+
216+
/* Add proper spacing between navbar and content */
217+
.bd-article-container {
218+
margin-top: 1rem;
219+
}
220+
221+
/* Ensure proper spacing for the main content area */
222+
article.bd-article {
223+
padding-top: 1rem;
224+
}

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: 151 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,12 +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",
5456
"sphinxcontrib.mermaid",
57+
"sphinx_sitemap",
58+
"pytorch_sphinx_theme2",
59+
"sphinxext.opengraph",
5560
]
5661

5762
sphinx_gallery_conf = {
@@ -73,6 +78,10 @@
7378
napoleon_google_docstring = True
7479
project = "torchao"
7580

81+
# -- OpenGraph Protocol settings --
82+
ogp_site_url = "http://pytorch.org/ao"
83+
ogp_image = "https://pytorch.org/assets/images/social-share.jpg"
84+
7685
# Get TORCHAO_VERSION_DOCS during the build.
7786
torchao_version_docs = os.environ.get("TORCHAO_VERSION_DOCS", None)
7887
print(f"torchao_version_docs: {torchao_version_docs}")
@@ -92,8 +101,18 @@
92101
print(f"Version: {version}")
93102
html_title = " ".join((project, version, "documentation"))
94103

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+
95110
# Add any paths that contain templates here, relative to this directory.
96-
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+
]
97116

98117
# The suffix(es) of source filenames.
99118
# You can specify multiple suffix as a list of string:
@@ -103,6 +122,16 @@
103122
".md": "markdown",
104123
}
105124

125+
# Myst-markdown configuration
126+
myst_enable_extensions = [
127+
"colon_fence",
128+
"deflist",
129+
"html_image",
130+
]
131+
132+
# Mermaid configuration - simplified
133+
mermaid_output_format = "raw"
134+
106135
# The master toctree document.
107136
master_doc = "index"
108137

@@ -134,25 +163,89 @@
134163
# The theme to use for HTML and HTML Help pages. See the documentation for
135164
# a list of builtin themes.
136165
#
137-
html_theme = "pytorch_sphinx_theme"
138-
html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]
166+
# Theme configuration is set earlier in the file (lines 29-30)
139167

140168
# Theme options are theme-specific and customize the look and feel of a theme
141169
# further. For a list of options available for each theme, see the
142170
# documentation.
143171
#
144172
html_theme_options = {
145-
"collapse_navigation": False,
173+
"navigation_with_keys": False,
174+
"analytics_id": "GTM-T8XT4PS",
175+
"logo": {
176+
"text": "",
177+
},
178+
"icon_links": [
179+
{
180+
"name": "X",
181+
"url": "https://x.com/PyTorch",
182+
"icon": "fa-brands fa-x-twitter",
183+
},
184+
{
185+
"name": "GitHub",
186+
"url": "https://github.com/pytorch/ao",
187+
"icon": "fa-brands fa-github",
188+
},
189+
{
190+
"name": "Discourse",
191+
"url": "https://dev-discuss.pytorch.org/",
192+
"icon": "fa-brands fa-discourse",
193+
},
194+
{
195+
"name": "PyPi",
196+
"url": "https://pypi.org/project/torchao/",
197+
"icon": "fa-brands fa-python",
198+
},
199+
],
200+
"use_edit_page_button": True,
201+
"navbar_center": "navbar-nav",
202+
# Option 2: Display version in navbar (since torchao is relatively new)
203+
"navbar_start": ["pytorch_version"],
146204
"display_version": True,
147-
"logo_only": True,
148-
"pytorch_project": "docs",
149-
"navigation_with_keys": True,
205+
# Uncomment below when you have multiple versions and a versions.json file
206+
# "switcher": {
207+
# "json_url": "https://pytorch.org/ao/torchao-versions.json",
208+
# "version_match": switcher_version,
209+
# },
210+
# "show_version_warning_banner": True,
211+
# Remove any announcement banner
212+
"announcement": None,
150213
}
151214

152215
html_logo = "_static/img/pytorch-logo-dark.svg"
153216

154217
html_css_files = ["css/custom.css"]
155218

219+
# Remove external JS that's causing loading issues
220+
# html_js_files = [
221+
# ("https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js", {"async": "async"}),
222+
# ]
223+
224+
# Base URL for sitemap generation
225+
html_baseurl = "https://pytorch.org/ao/"
226+
227+
# Configure date info for "Created On | Last Updated" feature and theme variables
228+
html_context = {
229+
"date_info": {
230+
# Optional: Add paths to skip for performance optimization
231+
"paths_to_skip": [
232+
"gen_modules/", # Skip auto-generated API reference modules
233+
"tutorials/", # Skip auto-generated tutorial gallery
234+
],
235+
},
236+
"theme_variables": theme_variables,
237+
"display_github": True,
238+
"github_url": "https://github.com",
239+
"github_user": "pytorch",
240+
"github_repo": "ao",
241+
"feedback_url": "https://github.com/pytorch/ao",
242+
"github_version": "main",
243+
"doc_path": "docs/source",
244+
"library_links": theme_variables.get("library_links", []),
245+
"community_links": theme_variables.get("community_links", []),
246+
"language_bindings_links": html_theme_options.get("language_bindings_links", []),
247+
}
248+
156249
# Add any paths that contain custom static files (such as style sheets) here,
157250
# relative to this directory. They are copied after the builtin static files,
158251
# so a file named "default.css" will overwrite the builtin "default.css".
@@ -177,8 +270,52 @@
177270
# See http://stackoverflow.com/a/41184353/3343043
178271

179272

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

182-
rst.directives.register_directive("customcardstart", CustomCardStart)
183-
rst.directives.register_directive("customcarditem", CustomCardItem)
184-
rst.directives.register_directive("customcardend", CustomCardEnd)
319+
def setup(app):
320+
"""Configure Sphinx app for pytorch_sphinx_theme2 features."""
321+
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 & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +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-
static_quantization
44-
pretraining
45-
torchao_vllm_integration
35+
developer_notes

docs/source/tutorials.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Tutorials
2+
=========
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
serialization
8+
subclass_basic
9+
subclass_advanced
10+
pretraining
11+
torchao_vllm_integration

0 commit comments

Comments
 (0)