Skip to content

Commit 0184501

Browse files
committed
Use ci.py explicitly in docs building instructions
This adds `ci.py` to the docs to make it more clear how to easily build the docs locally. This also re-arranges CI following the merging of all CI steps to run concurrently since there's no need to run the Sphinx precheck during GPU unit tests. This still preserves it though in the docs step as a way to quickly bail out if there are formatting errors so the full tutorials don't get built.
1 parent b1bd18e commit 0184501

File tree

5 files changed

+119
-83
lines changed

5 files changed

+119
-83
lines changed

Jenkinsfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,6 @@ stage('Test') {
388388
unpack_lib('gpu', tvm_multilib)
389389
timeout(time: max_time, unit: 'MINUTES') {
390390
ci_setup(ci_gpu)
391-
sh (
392-
script: "${docker_run} ${ci_gpu} ./tests/scripts/task_sphinx_precheck.sh",
393-
label: 'Check Sphinx warnings in docs',
394-
)
395391
sh (
396392
script: "${docker_run} ${ci_gpu} ./tests/scripts/task_java_unittest.sh",
397393
label: 'Run Java unit tests',

docs/README.md

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,61 @@
1616
<!--- under the License. -->
1717

1818
# TVM Documentation
19+
1920
This folder contains the source of TVM's documentation, hosted at https://tvm.apache.org/docs
2021

2122
## Build Locally
2223

23-
See also the instructions below to run a specific tutorial. Note that some of the tutorials need GPU support. Once build, either of these can be served using Python's build in HTTP server:
24+
### With Docker (recommended)
2425

25-
```bash
26-
# Run this and then visit http://localhost:8000 in your browser
27-
cd docs/_build/html && python3 -m http.server
28-
```
26+
1. Build TVM and the docs inside the [tlcpack/ci-gpu image](https://hub.docker.com/r/tlcpack/ci-gpu) using the [`ci.py`](../tests/scripts/ci.py) script.
2927

30-
### With Docker (recommended)
28+
```bash
29+
# If this runs into errors, try cleaning your 'build' directory
30+
python tests/scripts/ci.py docs
3131

32-
1. Build TVM and the docs inside the [tlcpack/ci-gpu image](https://hub.docker.com/r/tlcpack/ci-gpu)
32+
# See other doc building options
33+
python tests/scripts/ci.py docs --help
34+
```
3335

34-
```bash
35-
# If this runs into errors, try cleaning your 'build' directory
36-
make docs
37-
```
36+
2. Serve the docs and visit http://localhost:8000 in your browser
3837

38+
```bash
39+
# Run an HTTP server you can visit to view the docs in your browser
40+
python tests/scripts/ci.py serve-docs
41+
```
3942

4043
### Native
4144

4245
1. [Build TVM](https://tvm.apache.org/docs/install/from_source.html) first in the repo root folder
4346
2. Install dependencies
4447

45-
```bash
46-
# Pillow on Ubuntu may require libjpeg-dev from apt
47-
docker run tlcpack/ci-gpu:v0.78 bash -c \
48-
'python3 -m pip install --quiet tlcpack-sphinx-addon==0.2.1 synr==0.5.0 && python3 -m pip freeze' > frozen-requirements.txt
48+
```bash
49+
# Pillow on Ubuntu may require libjpeg-dev from apt
50+
docker run tlcpack/ci-gpu:v0.78 bash -c \
51+
'python3 -m pip install --quiet tlcpack-sphinx-addon==0.2.1 synr==0.5.0 && python3 -m pip freeze' > frozen-requirements.txt
4952

50-
pip install -r frozen-requirements.txt
51-
```
53+
pip install -r frozen-requirements.txt
54+
```
5255

5356
3. Generate the docs
5457

55-
```bash
56-
# TVM_TUTORIAL_EXEC_PATTERN=none skips the tutorial execution to the build
57-
# work on most environments (e.g. MacOS).
58-
export TVM_TUTORIAL_EXEC_PATTERN=none
58+
```bash
59+
# TVM_TUTORIAL_EXEC_PATTERN=none skips the tutorial execution to the build
60+
# work on most environments (e.g. MacOS).
61+
export TVM_TUTORIAL_EXEC_PATTERN=none
62+
63+
make html
64+
```
5965

60-
make html
61-
```
66+
4. Run an HTTP server and visit http://localhost:8000 in your browser
6267

68+
```bash
69+
cd docs/_build/html && python3 -m http.server
70+
```
6371

6472
## Only Execute Specified Tutorials
73+
6574
The document build process will execute all the tutorials in the sphinx gallery.
6675
This will cause failure in some cases when certain machines do not have necessary
6776
environment. You can set `TVM_TUTORIAL_EXEC_PATTERN` to only execute
@@ -70,14 +79,14 @@ the path that matches the regular expression pattern.
7079
For example, to only build tutorials under `/vta/tutorials`, run
7180

7281
```bash
73-
TVM_TUTORIAL_EXEC_PATTERN=/vta/tutorials make html
82+
python tests/scripts/ci.py docs --tutorials=/vta/tutorials
7483
```
7584

7685
To only build one specific file, do
7786

7887
```bash
7988
# The slash \ is used to get . in regular expression
80-
TVM_TUTORIAL_EXEC_PATTERN=file_name\.py make html
89+
python tests/scripts/ci.py docs --tutorials=file_name\.py
8190
```
8291

8392
## Helper Scripts
@@ -86,7 +95,7 @@ You can run the following script to reproduce the CI sphinx pre-check stage.
8695
This script skips the tutorial executions and is useful to quickly check the content.
8796

8897
```bash
89-
./tests/scripts/task_sphinx_precheck.sh
98+
python tests/scripts/ci.py docs --precheck
9099
```
91100

92101
The following script runs the full build which includes tutorial executions.
@@ -97,5 +106,7 @@ python tests/scripts/ci.py --precheck --full
97106
```
98107

99108
## Define the Order of Tutorials
100-
You can define the order of tutorials with `conf.py::subsection_order` and `conf.py::within_subsection_order`.
101-
By default, the tutorials within one subsection is sorted by filename.
109+
110+
You can define the order of tutorials with `subsection_order` and
111+
`within_subsection_order` in [`conf.py`](conf.py).
112+
By default, the tutorials within one subsection are sorted by filename.

tests/scripts/ci.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,11 @@ def docker(name: str, image: str, scripts: List[str], env: Dict[str, str]):
174174
def docs(
175175
tutorial_pattern: Optional[str] = None,
176176
full: bool = False,
177-
precheck: bool = False,
178177
cpu: bool = False,
179178
) -> None:
180179
"""
181180
Build the documentation from gallery/ and docs/. By default this builds only
182-
the Python docs. If you are on a CPU machine, you can skip the tutorials
183-
and build the docs with the '--precheck --cpu' options.
181+
the Python docs.
184182
185183
arguments:
186184
full -- Build all language docs, not just Python
@@ -233,9 +231,7 @@ def docs(
233231
config,
234232
f"./tests/scripts/task_build.sh build -j{NPROC}",
235233
"./tests/scripts/task_ci_setup.sh",
236-
"./tests/scripts/task_sphinx_precheck.sh"
237-
if precheck
238-
else "./tests/scripts/task_python_docs.sh",
234+
"./tests/scripts/task_python_docs.sh",
239235
]
240236

241237
if tutorial_pattern is None:

tests/scripts/task_python_docs.sh

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818

19-
set -e
20-
set -u
21-
set -o pipefail
19+
set -euo pipefail
2220

2321
source tests/scripts/setup-pytest-env.sh
2422

2523
# to avoid CI CPU thread throttling.
2624
export TVM_BIND_THREADS=0
27-
export OMP_NUM_THREADS=4
25+
export OMP_NUM_THREADS=1
2826
IS_LOCAL=${IS_LOCAL:-0}
2927
PYTHON_DOCS_ONLY=${PYTHON_DOCS_ONLY:-0}
3028

@@ -34,14 +32,75 @@ cleanup()
3432
}
3533
trap cleanup 0
3634

37-
# cleanup old states
38-
rm -rf docs/_build
39-
rm -rf docs/_staging
40-
mkdir -p docs/_build/html
41-
mkdir -p docs/_staging/html
42-
rm -rf docs/gen_modules
43-
rm -rf docs/doxygen
35+
clean_files() {
36+
# cleanup old states
37+
rm -rf docs/_build
38+
rm -rf docs/_staging
39+
mkdir -p docs/_build/html
40+
mkdir -p docs/_staging/html
41+
rm -rf docs/gen_modules
42+
rm -rf docs/doxygen
43+
find . -type f -path "*.pyc" | xargs rm -f
44+
}
45+
46+
sphinx_precheck() {
47+
clean_files
48+
echo "PreCheck sphinx doc generation WARNINGS.."
49+
make cython3
50+
51+
pushd docs
52+
make clean
53+
TVM_TUTORIAL_EXEC_PATTERN=none make html 2>&1 | tee /tmp/$$.log.txt
54+
check_sphinx_warnings
55+
popd
56+
}
57+
58+
59+
function join_by { local IFS="$1"; shift; echo "$*"; }
60+
61+
IGNORED_WARNINGS=(
62+
'__mro__'
63+
'UserWarning'
64+
'FutureWarning'
65+
'tensorflow'
66+
'Keras'
67+
'pytorch'
68+
'TensorFlow'
69+
'coremltools'
70+
'403'
71+
'git describe'
72+
'scikit-learn version'
73+
'doing serial write'
74+
'gen_gallery extension is not safe for parallel'
75+
'strategy:conv2d NHWC layout is not optimized for x86 with autotvm.'
76+
'strategy:depthwise_conv2d NHWC layout is not optimized for x86 with autotvm.'
77+
'autotvm:Cannot find config for target=llvm -keys=cpu -link-params=0'
78+
'autotvm:One or more operators have not been tuned. Please tune your model for better performance. Use DEBUG logging level to see more details.'
79+
)
80+
81+
JOINED_WARNINGS=$(join_by '|' "${IGNORED_WARNINGS[@]}")
82+
83+
check_sphinx_warnings() {
84+
grep -v -E "$JOINED_WARNINGS" < /tmp/$$.log.txt > /tmp/$$.logclean.txt || true
85+
if grep --quiet -E "WARN" < /tmp/$$.logclean.txt; then
86+
echo "Lines with 'WARNING' found in the log, please fix them:"
87+
grep -E "WARN" < /tmp/$$.logclean.txt
88+
echo "You can reproduce locally by running 'python tests/scripts/ci.py docs'"
89+
exit 1
90+
fi
91+
echo "No WARNINGS to be fixed."
92+
}
4493

94+
# run precheck step first to fast-fail if there are problems with the docs
95+
if [ "$IS_LOCAL" != "1" ]; then
96+
echo "Running precheck"
97+
sphinx_precheck
98+
else
99+
echo "Skipping precheck"
100+
fi
101+
102+
103+
clean_files
45104
# prepare auto scheduler tutorials
46105
rm -rf gallery/how_to/tune_with_auto_scheduler/*.json
47106
rm -rf gallery/tutorial/*.json
@@ -55,11 +114,14 @@ find . -type f -path "*.pyc" | xargs rm -f
55114
make cython3
56115

57116
cd docs
58-
PYTHONPATH=`pwd`/../python make html SPHINXOPTS='-j auto' |& tee /tmp/$$.log.txt
117+
PYTHONPATH=$(pwd)/../python make html SPHINXOPTS='-j auto' |& tee /tmp/$$.log.txt
59118
if grep -E "failed to execute|Segmentation fault" < /tmp/$$.log.txt; then
60119
echo "Some of sphinx-gallery item example failed to execute."
61120
exit 1
62121
fi
122+
123+
check_sphinx_warnings
124+
63125
cd ..
64126

65127
if [ "$IS_LOCAL" == "1" ] && [ "$PYTHON_DOCS_ONLY" == "1" ]; then

tests/scripts/task_sphinx_precheck.sh

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,7 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818

19-
# Precheck if sphinx docs build can fail.
20-
set -e
21-
set -u
22-
set -o pipefail
23-
24-
cleanup()
25-
{
26-
rm -rf /tmp/$$.*
27-
}
28-
trap cleanup 0
29-
30-
# cleanup cache
31-
rm -rf docs/_staging
32-
rm -rf docs/_build
33-
find . -type f -path "*.pyc" | xargs rm -f
34-
make cython3
35-
36-
echo "PreCheck sphinx doc generation WARNINGS.."
37-
cd docs
38-
make clean
39-
TVM_TUTORIAL_EXEC_PATTERN=none make html 2>&1 | tee /tmp/$$.log.txt
40-
41-
grep -v -E "__mro__|UserWarning|FutureWarning|tensorflow|Keras|pytorch|TensorFlow|coremltools|403|git describe|scikit-learn version" < /tmp/$$.log.txt > /tmp/$$.logclean.txt || true
42-
echo "---------Sphinx Log----------"
43-
cat /tmp/$$.logclean.txt
44-
echo "-----------------------------"
45-
if grep --quiet -E "WARN" < /tmp/$$.logclean.txt; then
46-
echo "WARNING found in the log, please fix them."
47-
grep -E "WARN" < /tmp/$$.logclean.txt
48-
echo "You can reproduce locally by running ./tests/scripts/task_sphinx_precheck.sh"
49-
exit 1
50-
fi
51-
echo "No WARNINGS to be fixed."
19+
# Intentionally do nothing, see https://github.com/apache/tvm/pull/9971. This
20+
# file cannot be deleted from the Jenkinsfile and deleted from the repo in the
21+
# same PR (since it wouldn't be able to pass CI). Once that PR is merged, this
22+
# file can be safely deleted.

0 commit comments

Comments
 (0)