Skip to content

Commit f105b05

Browse files
authored
Make bullet points clickable (#428)
1 parent 227cf9f commit f105b05

File tree

2 files changed

+75
-21
lines changed

2 files changed

+75
-21
lines changed

docs/conf.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@
66

77
import os
88
import sys
9+
from typing import Callable
10+
from typing import Protocol
911

1012
# -- Path setup --------------------------------------------------------------
1113

14+
15+
class SphinxApp(Protocol):
16+
"""Protocol for Sphinx application objects."""
17+
18+
def connect(self, event: str, callback: Callable[..., None]) -> None:
19+
"""Connect an event handler to a Sphinx event."""
20+
...
21+
22+
1223
# If extensions (or modules to document with autodoc) are in another directory,
1324
# add these directories to sys.path here.
1425
sys.path.insert(0, os.path.abspath(".."))
@@ -112,3 +123,45 @@
112123
typehints_fully_qualified = False
113124
always_document_param_types = True
114125
typehints_document_rtype = True
126+
127+
128+
def remove_sphinx_gallery_content(
129+
app: SphinxApp, docname: str, source: list[str]
130+
) -> None:
131+
"""
132+
Remove sphinx-gallery generated content from the examples index.rst file.
133+
This runs after sphinx-gallery generates the file but before the site is built.
134+
"""
135+
if docname == "examples/index":
136+
content = source[0]
137+
138+
# Find the first toctree directive and remove everything after it
139+
lines = content.split("\n")
140+
new_lines = []
141+
found_toctree = False
142+
143+
for line in lines:
144+
if line.strip().startswith(".. toctree::") and not found_toctree:
145+
found_toctree = True
146+
# Keep the line with the toctree directive
147+
new_lines.append(line)
148+
# Look for the next few lines that are part of the toctree options
149+
continue
150+
if found_toctree and (line.strip().startswith(":") or line.strip() == ""):
151+
# Keep toctree options and empty lines immediately after
152+
new_lines.append(line)
153+
continue
154+
if found_toctree:
155+
# We've hit content after the toctree options, stop here
156+
break
157+
# Keep everything before the toctree
158+
new_lines.append(line)
159+
160+
# Update the source content
161+
source[0] = "\n".join(new_lines)
162+
163+
164+
def setup(app: SphinxApp) -> dict[str, str]:
165+
"""Setup function to register the event handler."""
166+
app.connect("source-read", remove_sphinx_gallery_content)
167+
return {"version": "0.1"}

examples/README.rst

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,48 @@ The examples are organized into the following categories:
77
Basic Operations
88
~~~~~~~~~~~~~~~
99

10-
- ``add.py``: Element-wise addition with broadcasting support
11-
- ``exp.py``: Element-wise exponential function
12-
- ``sum.py``: Sum reduction along the last dimension
13-
- ``long_sum.py``: Efficient sum reduction along a long dimension
14-
- ``softmax.py``: Different implementations of the softmax function
10+
- :doc:`add.py <add>`: Element-wise addition with broadcasting support
11+
- :doc:`exp.py <exp>`: Element-wise exponential function
12+
- :doc:`sum.py <sum>`: Sum reduction along the last dimension
13+
- :doc:`long_sum.py <long_sum>`: Efficient sum reduction along a long dimension
14+
- :doc:`softmax.py <softmax>`: Different implementations of the softmax function
15+
1516

1617
Matrix Multiplication Operations
1718
~~~~~~~~~~~~~~~~
1819

19-
- ``matmul.py``: Basic matrix multiplication
20-
- ``bmm.py``: Batch matrix multiplication
21-
- ``matmul_split_k.py``: Matrix multiplication using split-K algorithm for better parallelism
22-
- ``matmul_layernorm.py``: Fused matrix multiplication and layer normalization
23-
- ``fp8_gemm.py``: Matrix multiplication using FP8 precision
20+
- :doc:`matmul.py <matmul>`: Basic matrix multiplication
21+
- :doc:`bmm.py <bmm>`: Batch matrix multiplication
22+
- :doc:`matmul_split_k.py <matmul_split_k>`: Matrix multiplication using split-K algorithm for better parallelism
23+
- :doc:`matmul_layernorm.py <matmul_layernorm>`: Fused matrix multiplication and layer normalization
24+
- :doc:`fp8_gemm.py <fp8_gemm>`: Matrix multiplication using FP8 precision
2425

2526
Attention Operations
2627
~~~~~~~~~~~~~~~~~~~
2728

28-
- ``attention.py``: Scaled dot-product attention mechanism
29-
- ``fp8_attention.py``: Attention mechanism using FP8 precision
29+
- :doc:`attention.py <attention>`: Scaled dot-product attention mechanism
30+
- :doc:`fp8_attention.py <fp8_attention>`: Attention mechanism using FP8 precision
3031

3132
Normalization
3233
~~~~~~~~~~~~
3334

34-
- ``rms_norm.py``: Root Mean Square (RMS) normalization
35+
- :doc:`rms_norm.py <rms_norm>`: Root Mean Square (RMS) normalization
3536

3637
Sparse and Jagged Tensors
3738
~~~~~~~~~~~~~~~~~~~~~~~~~
3839

39-
- ``jagged_dense_add.py``: Addition between a jagged tensor and a dense tensor
40-
- ``jagged_mean.py``: Computing the mean of each row in a jagged tensor
41-
- ``segment_reduction.py``: Segmented reduction operation
42-
- ``moe_matmul_ogs.py``: Mixture-of-Experts matrix multiplication using Outer-Gather-Scatter
40+
- :doc:`jagged_dense_add.py <jagged_dense_add>`: Addition between a jagged tensor and a dense tensor
41+
- :doc:`jagged_mean.py <jagged_mean>`: Computing the mean of each row in a jagged tensor
42+
- :doc:`segment_reduction.py <segment_reduction>`: Segmented reduction operation
43+
- :doc:`moe_matmul_ogs.py <moe_matmul_ogs>`: Mixture-of-Experts matrix multiplication using Outer-Gather-Scatter
4344

4445
Other Operations
4546
~~~~~~~~~~~~~~~
4647

47-
- ``concatenate.py``: Tensor concatenation along a dimension
48-
- ``cross_entropy.py``: Cross entropy loss function
49-
- ``embedding.py``: Embedding lookup operation
50-
- ``all_gather_matmul.py``: All-gather operation followed by matrix multiplication
48+
- :doc:`concatenate.py <concatenate>`: Tensor concatenation along a dimension
49+
- :doc:`cross_entropy.py <cross_entropy>`: Cross entropy loss function
50+
- :doc:`embedding.py <embedding>`: Embedding lookup operation
51+
- :doc:`all_gather_matmul.py <all_gather_matmul>`: All-gather operation followed by matrix multiplication
5152

5253
.. toctree::
5354
:maxdepth: 2

0 commit comments

Comments
 (0)