mirror of
https://github.com/NVIDIA/Model-Optimizer.git
synced 2026-10-02 03:14:52 +08:00
### What does this PR do?
Type of change: documentation.
Replaces the legacy Sphinx RTD theme with Shibuya and gives the ModelOpt
documentation a modern responsive light/dark presentation.
The configuration uses the Shibuya green palette with NVIDIA green
(#76b900) as the primary accent, follows the reader system color
preference by default, enables dark code blocks, and expands the first
level of global navigation. RTD-specific CSS is removed, while the
announcement page now uses Shibuya semantic color tokens in both light
and dark modes.
Shibuya 2026.7.12 is licensed under BSD-3-Clause.
### Usage
```python
html_theme = "shibuya"
html_theme_options = {
"accent_color": "green",
"color_mode": "auto",
"dark_code": True,
"globaltoc_expand_depth": 1,
}
```
Doc preview:
https://nvidia.github.io/Model-Optimizer/pr-preview/pr-2242/
### Testing
- `nox -N --envdir /tmp/modelopt-shibuya-nox -s docs`
- Sphinx 9.1 built all 411 pages successfully with `--fail-on-warning`.
- `pre-commit run --files docs/source/conf.py
docs/source/_static/custom.css docs/source/_static/announcements.css
pyproject.toml uv.lock --show-diff-on-failure`
- All applicable hooks passed.
- Verified generated HTML loads Shibuya assets, declares the green
accent, includes automatic light/dark mode logic, and includes the
custom theme-token CSS.
### Before your PR is "*Ready for review*"
Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md)
and your commits are signed (`git commit -s -S`).
Make sure you read and follow the [Security Best
Practices](https://github.com/NVIDIA/Model-Optimizer/blob/main/SECURITY.md#security-coding-practices-for-contributors)
(e.g. avoiding hardcoded `trust_remote_code=True`, `torch.load(...,
weights_only=False)`, `pickle`, etc.).
- Is this change backward compatible?: ✅
- If you copied code from any other sources or added a new PIP
dependency, did you follow guidance in `CONTRIBUTING.md`: ✅
- Did you write any new necessary tests?: N/A — documentation theme
change covered by the full warning-as-error build.
- Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?:
N/A — documentation presentation change.
- Did you get Claude approval on this PR?: N/A — focused documentation
theme migration.
### Additional Information
No source code or public API behavior changes.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Documentation**
* Updated the documentation site with the Shibuya theme.
* Added green theme accents, automatic light/dark mode, and dark code
blocks.
* Improved table-of-contents behavior and refreshed announcement
styling.
* Removed outdated layout and table customization overrides.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Signed-off-by: realAsma <akuriparambi@nvidia.com>
223 lines
8.4 KiB
Python
223 lines
8.4 KiB
Python
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
"""Conf.py file for Sphinx documentation."""
|
|
|
|
# Configuration file for the Sphinx documentation builder.
|
|
#
|
|
# This file only contains a selection of the most common options. For a full
|
|
# list see the documentation:
|
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
|
|
# -- Path setup --------------------------------------------------------------
|
|
|
|
# If extensions (or modules to document with autodoc) are in another directory,
|
|
# add these directories to sys.path here. If the directory is relative to the
|
|
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
|
#
|
|
# import os
|
|
# import sys
|
|
# sys.path.insert(0, os.path.abspath('.'))
|
|
|
|
import contextlib
|
|
import os
|
|
import sys
|
|
|
|
import sphinx.application
|
|
from docutils import nodes
|
|
from docutils.nodes import Element
|
|
from sphinx.writers.html5 import HTML5Translator
|
|
|
|
from modelopt import __version__
|
|
|
|
sys.path.insert(0, os.path.abspath("../../"))
|
|
sys.path.append(os.path.abspath("./_ext"))
|
|
|
|
# Pre-import modelopt.torch so it is cached in sys.modules before Sphinx applies
|
|
# autodoc_mock_imports. Mocking triton/tensorrt_llm at the Sphinx level can break
|
|
# transitive imports (transformers, transformer_engine, …) and cause modelopt.torch
|
|
# to fail inside autosummary. Importing here — while the real packages are still on
|
|
# sys.path — avoids that problem entirely.
|
|
with contextlib.suppress(Exception):
|
|
import modelopt.torch # noqa: F401
|
|
|
|
# -- Project information -----------------------------------------------------
|
|
|
|
project = "Model Optimizer" # pylint: disable=C0103
|
|
copyright = "2023-2025, NVIDIA Corporation" # pylint: disable=C0103
|
|
author = "NVIDIA Corporation" # pylint: disable=C0103
|
|
version = __version__
|
|
|
|
# -- General configuration ---------------------------------------------------
|
|
|
|
# Add any Sphinx extension module names here, as strings. They can be
|
|
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
|
# ones.
|
|
extensions = [
|
|
"sphinx.ext.autodoc",
|
|
"sphinx.ext.autosummary",
|
|
"sphinx.ext.githubpages",
|
|
"sphinx.ext.napoleon", # Support for NumPy and Google style docstrings
|
|
"sphinxarg.ext", # for command-line help documentation
|
|
"sphinx_copybutton", # line numbers getting copied so cannot use `:linenos:`
|
|
"sphinx_inline_tabs",
|
|
"sphinx_togglebutton",
|
|
"sphinxcontrib.autodoc_pydantic",
|
|
"modelopt_autodoc_pydantic",
|
|
]
|
|
|
|
# Only show copybutton for python code-blocks
|
|
copybutton_selector = ", ".join(
|
|
[
|
|
"div.highlight-python pre",
|
|
"div.highlight-ipython3 pre",
|
|
"div.highlight-bash pre",
|
|
"div.highlight-shell pre",
|
|
]
|
|
)
|
|
|
|
# List of patterns, relative to source directory, that match files and
|
|
# directories to ignore when looking for source files.
|
|
# This pattern also affects html_static_path and html_extra_path.
|
|
exclude_patterns = []
|
|
templates_path = ["_templates"]
|
|
|
|
# Suppress ambiguous cross-reference warnings that arise because EMAConfig and
|
|
# QuantizerAttributeConfig both define a field named `type`. Renaming would be
|
|
# an API break; silencing the warning here is the least-invasive fix.
|
|
suppress_warnings = ["ref.python"]
|
|
|
|
|
|
# -- Options for HTML output -------------------------------------------------
|
|
|
|
# The theme to use for HTML and HTML Help pages. See the documentation for
|
|
# a list of builtin themes.
|
|
#
|
|
html_theme = "shibuya"
|
|
html_theme_options = {
|
|
"accent_color": "green",
|
|
"color_mode": "auto",
|
|
"dark_code": True,
|
|
"globaltoc_expand_depth": 1,
|
|
}
|
|
|
|
# Add any paths that contain custom static files (such as style sheets) here,
|
|
# relative to this directory. They are copied after the builtin static files,
|
|
# so a file named "default.css" will overwrite the builtin "default.css".
|
|
html_static_path = ["_static"]
|
|
|
|
html_title = f"Model Optimizer {version}"
|
|
html_css_files = ["custom.css", "announcements.css"]
|
|
html_js_files = ["announcements.js"]
|
|
html_permalinks_icon = "#" # default icon not rendering properly
|
|
|
|
# TODO: left here as reference for future
|
|
# You can put all these files in the `_static` folder and then activate them as shown below
|
|
# html_favicon = "_static/Nvidia_Symbol.png"
|
|
# html_theme_options = {
|
|
# "light_logo": "Nvidia_Light.png",
|
|
# "dark_logo": "Nvidia_Dark.png",
|
|
# }
|
|
|
|
|
|
# Mock imports for autodoc
|
|
autodoc_mock_imports = ["mpi4py", "tensorrt_llm", "triton", "vllm"]
|
|
|
|
autosummary_generate = True
|
|
autosummary_imported_members = False
|
|
|
|
# Only consider members from __all__ if available
|
|
autosummary_ignore_module_all = False
|
|
|
|
# Disable docstring inheritance
|
|
autodoc_inherit_docstrings = False
|
|
|
|
# show inheritance
|
|
autodoc_default_options = {"show-inheritance": True}
|
|
|
|
# Omit type package prefixes and type annotations as much as possible to reduce verbosity
|
|
add_module_names = False
|
|
python_use_unqualified_type_names = True
|
|
|
|
# Automatically extract typehints when specified and place them in
|
|
# descriptions of the relevant function/method.
|
|
autodoc_typehints = "description"
|
|
|
|
# Don't show class signature with the class' name.
|
|
autodoc_class_signature = "separated"
|
|
|
|
# Order of autodoc
|
|
# NOTE: summary table on the top of each page does not follow this order so we should also set __all__ in sorted order
|
|
autodoc_member_order = "alphabetical" # can also use `bysource` or `groupwise` to sort members
|
|
|
|
|
|
# autodoc_pydantic model settings
|
|
autodoc_pydantic_model_show_config_summary = False
|
|
autodoc_pydantic_model_show_validator_summary = False
|
|
autodoc_pydantic_model_show_validator_members = False
|
|
autodoc_pydantic_model_show_field_summary = False
|
|
autodoc_pydantic_model_show_json = True # we overwrite this to show the schema or default or both
|
|
autodoc_pydantic_model_signature_prefix = "ModeloptConfig"
|
|
autodoc_pydantic_model_modelopt_show_default_dict = True # show default inside json
|
|
autodoc_pydantic_model_modelopt_show_json_schema = False # hide json schema
|
|
|
|
# autodoc_pydantic field settings
|
|
autodoc_pydantic_field_swap_name_and_alias = True
|
|
autodoc_pydantic_field_doc_policy = "description"
|
|
autodoc_pydantic_field_show_alias = False
|
|
autodoc_pydantic_field_list_validators = False
|
|
autodoc_pydantic_field_show_default = False
|
|
|
|
|
|
class PatchedHTMLTranslator(HTML5Translator):
|
|
"""Open all external links in a new tab. Ref: https://stackoverflow.com/a/61669375 ."""
|
|
|
|
def visit_reference(self, node: Element) -> None:
|
|
"""Visit a reference node."""
|
|
atts = {"class": "reference"}
|
|
if node.get("internal") or "refuri" not in node:
|
|
atts["class"] += " internal"
|
|
else:
|
|
atts["class"] += " external"
|
|
# ---------------------------------------------------------
|
|
# Customize behavior (open in new tab, secure linking site)
|
|
atts["target"] = "_blank"
|
|
atts["rel"] = "noopener noreferrer"
|
|
# ---------------------------------------------------------
|
|
if "refuri" in node:
|
|
atts["href"] = node["refuri"] or "#"
|
|
if self.settings.cloak_email_addresses and atts["href"].startswith("mailto:"):
|
|
atts["href"] = self.cloak_mailto(atts["href"])
|
|
self.in_mailto = True
|
|
else:
|
|
assert "refid" in node, 'References must have "refuri" or "refid" attribute.'
|
|
atts["href"] = "#" + node["refid"]
|
|
if not isinstance(node.parent, nodes.TextElement):
|
|
assert len(node) == 1 and isinstance(node[0], nodes.image)
|
|
atts["class"] += " image-reference"
|
|
if "reftitle" in node:
|
|
atts["title"] = node["reftitle"]
|
|
if "target" in node:
|
|
atts["target"] = node["target"]
|
|
self.body.append(self.starttag(node, "a", "", **atts))
|
|
|
|
if node.get("secnumber"):
|
|
self.body.append(("%s" + self.secnumber_suffix) % ".".join(map(str, node["secnumber"])))
|
|
|
|
|
|
def setup(app: sphinx.application.Sphinx) -> None:
|
|
"""Setup according to the Sphinx extension API."""
|
|
app.set_translator("html", PatchedHTMLTranslator)
|