Skip to content

Commit e0f5bcb

Browse files
klhhhhhzhaochenyang20
authored andcommitted
Support Markdown/Notebook-Friendly Documentation Export for Downstream Integration (sgl-project#18131)
Co-authored-by: 赵晨阳 <[email protected]>
1 parent 107a7d6 commit e0f5bcb

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

.github/workflows/release-docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
run: |
4848
cd docs
4949
make html
50+
make markdown
5051
python3 wrap_run_llm.py
5152
5253
cd _build/html

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ compile:
3838
echo "Total execution time: $${TOTAL_ELAPSED}s" >> logs/timing.log; \
3939
echo "All Notebook execution timings:" && cat logs/timing.log
4040

41+
# Convert Notebook files to Markdown artifacts (no execution)
42+
markdown:
43+
@set -e; \
44+
echo "Exporting notebooks to Markdown..."; \
45+
mkdir -p "$(BUILDDIR)/html/markdown"; \
46+
find $(SOURCEDIR) -path "*/_build/*" -prune -o -name "*.ipynb" -print0 | \
47+
parallel -0 -j3 --halt soon,fail=1 ' \
48+
NB_SRC="{}"; \
49+
REL_DIR=$$(dirname "$$NB_SRC"); \
50+
NB_NAME=$$(basename "$$NB_SRC"); \
51+
NB_BASE=$${NB_NAME%.ipynb}; \
52+
OUT_DIR="$(BUILDDIR)/html/markdown/$$REL_DIR"; \
53+
mkdir -p "$$OUT_DIR"; \
54+
jupyter nbconvert --to markdown "$$NB_SRC" \
55+
--output "$$NB_BASE.md" \
56+
--output-dir "$$OUT_DIR" \
57+
>/dev/null; \
58+
' || exit 1; \
59+
echo "Markdown artifacts written to: $(BUILDDIR)/html/markdown"
60+
4161
# Serve documentation with auto-build and live reload
4262
serve:
4363
@echo "Starting auto-build server at http://0.0.0.0:$(PORT)"

docs/README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ find . -name '*.ipynb' -exec nbstripout {} \;
4545
# After these checks pass, push your changes and open a PR on your branch
4646
pre-commit run --all-files
4747
```
48-
---
4948

5049
## Documentation Style Guidelines
5150

@@ -55,3 +54,71 @@ pre-commit run --all-files
5554
- Reuse the launched server as much as possible to reduce server launch time.
5655
- Do not use absolute links (e.g., `https://docs.sglang.io/get_started/install.html`). Always prefer relative links (e.g., `../get_started/install.md`).
5756
- Follow the existing examples to learn how to launch a server, send a query and other common styles.
57+
58+
## Documentation Build, Deployment, and CI
59+
60+
The SGLang documentation pipeline is based on **Sphinx** and supports rendering Jupyter notebooks (`.ipynb`) into HTML/Markdown for web display. Detailed logits can be found in the [Makefile](./Makefile).
61+
62+
### Notebook Execution (`make compile`)
63+
64+
The `make compile` target is responsible for executing notebooks before rendering:
65+
66+
* Finds all `.ipynb` files under `docs/` (excluding `_build/`)
67+
* Executes notebooks in parallel using GNU Parallel, with a relatively small `--mem-fraction-static`
68+
* Wraps execution with `retry` to reduce flaky failures
69+
* Executes notebooks via `jupyter nbconvert --execute --inplace`
70+
* Records execution timing in `logs/timing.log`
71+
72+
This step ensures notebooks contain up-to-date outputs with each commit in the main branch before rendering.
73+
74+
### Web Rendering (`make html`)
75+
76+
After compilation, Sphinx builds the website:
77+
78+
* Reads Markdown, reStructuredText, and Jupyter notebooks
79+
* Renders them into HTML pages
80+
* Outputs the website into:
81+
82+
```
83+
docs/_build/html/
84+
```
85+
86+
This directory is the source for online documentation hosting.
87+
88+
### Markdown Export (`make markdown`)
89+
90+
To support downstream consumers, we add a **new Makefile target**:
91+
92+
```bash
93+
make markdown
94+
```
95+
96+
This target:
97+
98+
* Does **not modify** `make compile`
99+
* Scans all `.ipynb` files (excluding `_build/`)
100+
* Converts notebooks directly to Markdown using `jupyter nbconvert --to markdown`
101+
* Writes Markdown artifacts into the existing build directory:
102+
103+
```
104+
docs/_build/html/markdown/<relative-path>.md
105+
```
106+
107+
Example:
108+
109+
```
110+
docs/advanced_features/lora.ipynb
111+
→ docs/_build/html/markdown/advanced_features/lora.md
112+
```
113+
114+
### CI Execution
115+
116+
In our [CI](https://github.com/sgl-project/sglang/blob/main/.github/workflows/release-docs.yml), the documentation pipeline first gets all the executed results and renders HTML and Markdown by:
117+
118+
```bash
119+
make compile # execute notebooks (ensure outputs are up to date)
120+
make html # build website as usual
121+
make markdown # export markdown artifacts into _build/html/markdown
122+
```
123+
124+
Then, the compiled results are forced pushed to [sgl-project.io](https://github.com/sgl-project/sgl-project.github.io) for rendering. In other words, sgl-project.io is push-only. All the changes of SGLang docs should be made directly in SGLang main repo, then push to the sgl-project.io.

0 commit comments

Comments
 (0)