Skip to content

Commit a7efb6d

Browse files
committed
Fix API Docs generation
This is a minimal set of changes to fix API docs generation that's currently failing all our Read The Docs syncing. Adapted from #3029
1 parent d0ad85c commit a7efb6d

4 files changed

Lines changed: 39 additions & 33 deletions

File tree

.github/workflows/check_docs_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
persist-credentials: false
1919

2020
- name: Install uv and set the Python version
21-
uses: astral-sh/setup-uv@v6
21+
uses: astral-sh/setup-uv@eb1897b8dc4b5d5bfe39a428a8f2304605e0983c # v7.0.0
2222
with:
2323
python-version: '3.12'
2424
enable-cache: true
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Sphinx-related requirements.
2-
sphinx
2+
sphinx<9
33
myst-nb
44
myst-parser[linkify]
55
sphinx-book-theme
@@ -8,10 +8,4 @@ sphinx-copybutton
88

99
# for import docs
1010
-r base_requirements/requirements.txt
11-
google-tunix
12-
mlcommons-loadgen
13-
mlperf-logging @ https://github.com/mlcommons/logging/archive/38ab22670527888c8eb7825a4ece176fcc36a95d.zip
14-
tf-keras
15-
torch==2.7.1
16-
trl==0.19.0
17-
vllm
11+
jax

docs/conf.py

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@
2828
import os
2929
import os.path
3030
import sys
31-
import warnings
31+
import logging
32+
from sphinx.util import logging as sphinx_logging
3233

3334
# Prevent JAX/Torch/TF from trying to access TPU/GPU during doc build
3435
os.environ["JAX_PLATFORMS"] = "cpu"
3536
os.environ["CUDA_VISIBLE_DEVICES"] = ""
37+
3638
MAXTEXT_REPO_ROOT = os.environ.get("MAXTEXT_REPO_ROOT", os.path.join(os.path.dirname(os.path.dirname(__file__))))
37-
sys.path.insert(0, os.path.abspath(os.path.join(MAXTEXT_REPO_ROOT, "test")))
3839
sys.path.insert(0, os.path.abspath(os.path.join(MAXTEXT_REPO_ROOT, "src")))
3940

40-
warnings.filterwarnings("ignore", category=FutureWarning, module="keras.src.export.tf2onnx_lib")
41-
4241
project = "MaxText"
4342
# pylint: disable=redefined-builtin
4443
copyright = "2023–2026, Google LLC"
@@ -62,15 +61,7 @@
6261
source_suffix = [".rst", ".ipynb", ".md"]
6362

6463
# Suppress specific warnings
65-
suppress_warnings = [
66-
"app.add_node",
67-
"ref.python",
68-
"myst.xref_ambiguous",
69-
"docutils",
70-
"autodoc",
71-
"autodoc.duplicate_object_description",
72-
"toc.not_included",
73-
]
64+
suppress_warnings = ["autodoc.import_object"]
7465

7566
# -- Options for HTML output -------------------------------------------------
7667
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
@@ -94,18 +85,14 @@
9485
autodoc_member_order = "bysource"
9586
autodoc_typehints = "description"
9687
autodoc_mock_imports = [
97-
"cloud_tpu_diagnostics",
98-
"google_cloud_mldiagnostics",
99-
"jetstream",
100-
"librosa",
101-
"ml_goodput_measurement",
102-
"pathwaysutils",
10388
"safetensors",
10489
"tensorflow_datasets",
10590
"torch",
10691
"tpu_inference",
107-
"transformer_engine",
10892
"vllm",
93+
"grain",
94+
"librosa",
95+
"sentencepiece",
10996
]
11097
autosummary_generate = True
11198

@@ -129,10 +116,12 @@
129116
os.path.join("guides", "run_maxtext", "run_maxtext_via_multihost_job.md"),
130117
os.path.join("guides", "run_maxtext", "run_maxtext_via_multihost_runner.md"),
131118
os.path.join("explanations", "llm_calculator.ipynb"),
132-
os.path.join("reference", "api.rst"),
133119
os.path.join("run_maxtext", "run_maxtext_via_multihost_job.md"),
134120
os.path.join("run_maxtext", "run_maxtext_via_multihost_runner.md"),
135121
os.path.join("reference", "core_concepts", "llm_calculator.ipynb"),
122+
os.path.join("reference", "api_generated", "modules.rst"),
123+
os.path.join("reference", "api_generated", "install_maxtext_extra_deps.rst"),
124+
os.path.join("reference", "api_generated", "install_maxtext_extra_deps.install_github_deps.rst"),
136125
]
137126

138127

@@ -191,8 +180,31 @@ def run_apidoc(_):
191180
sys.exit(1)
192181

193182

194-
# Connect the apidoc generation to the Sphinx build process
183+
class FilterSphinxWarnings(logging.Filter):
184+
"""Filter autosummary 'duplicate object description' warnings.
185+
186+
These warnings are unnecessary as they do not cause missing documentation
187+
or rendering issues, so it is safe to filter them out.
188+
"""
189+
190+
def __init__(self, app):
191+
self.app = app
192+
super().__init__()
193+
194+
def filter(self, record: logging.LogRecord) -> bool:
195+
msg = record.getMessage()
196+
filter_out = ("duplicate object description",)
197+
return not msg.strip().startswith(filter_out)
198+
199+
195200
def setup(app):
201+
"""Set up the Sphinx application with custom behavior."""
202+
203+
# Connect the apidoc generation to the Sphinx build process
196204
run_apidoc(None)
197205
print("running:", app)
198-
# app.connect("builder-inited", run_apidoc)
206+
207+
# Set up custom logging filters
208+
logger = logging.getLogger("sphinx")
209+
warning_handler, *_ = [h for h in logger.handlers if isinstance(h, sphinx_logging.WarningStreamHandler)]
210+
warning_handler.filters.insert(0, FilterSphinxWarnings(app))

docs/reference/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ This section contains the complete API documentation for the ``MaxText`` library
2323
:caption: Package Modules
2424
:glob:
2525

26-
api_generated/modules
26+
api_generated/MaxText

0 commit comments

Comments
 (0)