Skip to content

Commit a20decc

Browse files
authored
Merge branch 'main' into arm64-binaries
2 parents 46904ac + 57e19ad commit a20decc

130 files changed

Lines changed: 4960 additions & 922 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.ci/docker/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ case "$image" in
206206
KATEX=yes
207207
CONDA_CMAKE=yes
208208
TRITON=yes
209+
DOCS=yes
209210
;;
210211
pytorch-linux-jammy-cuda11.7-cudnn8-py3.8-clang12)
211212
ANACONDA_PYTHON_VERSION=3.8
@@ -321,6 +322,7 @@ docker build \
321322
--build-arg "CONDA_CMAKE=${CONDA_CMAKE}" \
322323
--build-arg "TRITON=${TRITON}" \
323324
--build-arg "ONNX=${ONNX}" \
325+
--build-arg "DOCS=${DOCS}" \
324326
-f $(dirname ${DOCKERFILE})/Dockerfile \
325327
-t "$tmp_tag" \
326328
"$@" \

.ci/docker/common/install_conda.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,13 @@ if [ -n "$ANACONDA_PYTHON_VERSION" ]; then
9797
pip_install scikit-learn==0.20.3
9898
fi
9999

100+
if [ -n "$DOCS" ]; then
101+
apt-get update
102+
apt-get -y install expect-dev
103+
104+
# We are currently building docs with python 3.8 (min support version)
105+
pip_install -r /opt/conda/requirements-docs.txt
106+
fi
107+
100108
popd
101109
fi

.ci/docker/requirements-docs.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
sphinx==5.0.0
2+
#Description: This is used to generate PyTorch docs
3+
#Pinned versions: 5.0.0
4+
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
5+
6+
# TODO: sphinxcontrib.katex 0.9.0 adds a local KaTeX server to speed up pre-rendering
7+
# but it doesn't seem to work and hangs around idly. The initial thought is probably
8+
# something related to Docker setup. We can investigate this later
9+
sphinxcontrib.katex==0.8.6
10+
#Description: This is used to generate PyTorch docs
11+
#Pinned versions: 0.8.6
12+
13+
matplotlib==3.5.3
14+
#Description: This is used to generate PyTorch docs
15+
#Pinned versions: 3.5.3
16+
17+
tensorboard==2.13.0
18+
#Description: This is used to generate PyTorch docs
19+
#Pinned versions: 2.13.0
20+
21+
breathe==4.15.0
22+
#Description: This is used to generate PyTorch C++ docs
23+
#Pinned versions: 4.25.0
24+
25+
exhale==0.2.3
26+
#Description: This is used to generate PyTorch C++ docs
27+
#Pinned versions: 0.2.3
28+
29+
docutils==0.16
30+
#Description: This is used to generate PyTorch C++ docs
31+
#Pinned versions: 0.16
32+
33+
bs4==0.0.1
34+
#Description: This is used to generate PyTorch C++ docs
35+
#Pinned versions: 0.0.1
36+
37+
IPython==8.12.0
38+
#Description: This is used to generate PyTorch functorch docs
39+
#Pinned versions: 8.12.0
40+
41+
myst-nb==0.17.2
42+
#Description: This is used to generate PyTorch functorch docs
43+
#Pinned versions: 0.13.2
44+
45+
# The following are required to build torch.distributed.elastic.rendezvous.etcd* docs
46+
python-etcd==0.4.5
47+
sphinx-copybutton==0.5.0
48+
sphinx-panels==0.4.1
49+
myst-parser==0.18.1

.ci/docker/ubuntu/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ RUN bash ./install_docs_reqs.sh && rm install_docs_reqs.sh
3636
# Install conda and other packages (e.g., numpy, pytest)
3737
ARG ANACONDA_PYTHON_VERSION
3838
ARG CONDA_CMAKE
39+
ARG DOCS
3940
ENV ANACONDA_PYTHON_VERSION=$ANACONDA_PYTHON_VERSION
4041
ENV PATH /opt/conda/envs/py_$ANACONDA_PYTHON_VERSION/bin:/opt/conda/bin:$PATH
41-
COPY requirements-ci.txt /opt/conda/requirements-ci.txt
42+
ENV DOCS=$DOCS
43+
COPY requirements-ci.txt requirements-docs.txt /opt/conda/
4244
COPY ./common/install_conda.sh install_conda.sh
4345
COPY ./common/common_utils.sh common_utils.sh
44-
RUN bash ./install_conda.sh && rm install_conda.sh common_utils.sh /opt/conda/requirements-ci.txt
46+
RUN bash ./install_conda.sh && rm install_conda.sh common_utils.sh /opt/conda/requirements-ci.txt /opt/conda/requirements-docs.txt
4547

4648
# Install gcc
4749
ARG GCC_VERSION

.ci/pytorch/cpp_doc_push_script.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
3+
# This is where the local pytorch install in the docker image is located
4+
pt_checkout="/var/lib/jenkins/workspace"
5+
6+
# Since we're cat-ing this file, we need to escape all $'s
7+
echo "cpp_doc_push_script.sh: Invoked with $*"
8+
9+
# for statements like ${1:-${DOCS_INSTALL_PATH:-docs/}}
10+
# the order of operations goes:
11+
# 1. Check if there's an argument $1
12+
# 2. If no argument check for environment var DOCS_INSTALL_PATH
13+
# 3. If no environment var fall back to default 'docs/'
14+
15+
# NOTE: It might seem weird to gather the second argument before gathering the first argument
16+
# but since DOCS_INSTALL_PATH can be derived from DOCS_VERSION it's probably better to
17+
# try and gather it first, just so we don't potentially break people who rely on this script
18+
# Argument 2: What version of the Python API docs we are building.
19+
version="${2:-${DOCS_VERSION:-main}}"
20+
if [ -z "$version" ]; then
21+
echo "error: cpp_doc_push_script.sh: version (arg2) not specified"
22+
exit 1
23+
fi
24+
25+
# Argument 1: Where to copy the built documentation for Python API to
26+
# (pytorch.github.io/$install_path)
27+
install_path="${1:-${DOCS_INSTALL_PATH:-docs/${DOCS_VERSION}}}"
28+
if [ -z "$install_path" ]; then
29+
echo "error: cpp_doc_push_script.sh: install_path (arg1) not specified"
30+
exit 1
31+
fi
32+
33+
echo "install_path: $install_path version: $version"
34+
35+
# ======================== Building PyTorch C++ API Docs ========================
36+
37+
echo "Building PyTorch C++ API docs..."
38+
39+
# Clone the cppdocs repo
40+
rm -rf cppdocs
41+
git clone https://github.com/pytorch/cppdocs
42+
43+
set -ex
44+
45+
# Generate ATen files
46+
pushd "${pt_checkout}"
47+
time python -m torchgen.gen \
48+
-s aten/src/ATen \
49+
-d build/aten/src/ATen
50+
51+
# Copy some required files
52+
cp torch/_utils_internal.py tools/shared
53+
54+
# Generate PyTorch files
55+
time python tools/setup_helpers/generate_code.py \
56+
--native-functions-path aten/src/ATen/native/native_functions.yaml \
57+
--tags-path aten/src/ATen/native/tags.yaml
58+
59+
# Build the docs
60+
pushd docs/cpp
61+
time make VERBOSE=1 html -j
62+
63+
popd
64+
popd
65+
66+
pushd cppdocs
67+
68+
# Purge everything with some exceptions
69+
mkdir /tmp/cppdocs-sync
70+
mv _config.yml README.md /tmp/cppdocs-sync/
71+
rm -rf ./*
72+
73+
# Copy over all the newly generated HTML
74+
cp -r "${pt_checkout}"/docs/cpp/build/html/* .
75+
76+
# Copy back _config.yml
77+
rm -rf _config.yml
78+
mv /tmp/cppdocs-sync/* .
79+
80+
# Make a new commit
81+
git add . || true
82+
git status
83+
git config user.email "soumith+bot@pytorch.org"
84+
git config user.name "pytorchbot"
85+
# If there aren't changes, don't make a commit; push is no-op
86+
git commit -m "Generate C++ docs from pytorch/pytorch@${GITHUB_SHA}" || true
87+
git status
88+
89+
if [[ "${WITH_PUSH:-}" == true ]]; then
90+
git push -u origin
91+
fi
92+
93+
popd

.ci/pytorch/docs-test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
66
echo "Testing pytorch docs"
77

88
cd docs
9-
pip_install -r requirements.txt
109
make doctest
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# This is where the local pytorch install in the docker image is located
4+
pt_checkout="/var/lib/jenkins/workspace"
5+
source "$pt_checkout/.ci/pytorch/common_utils.sh"
6+
echo "functorch_doc_push_script.sh: Invoked with $*"
7+
8+
set -ex
9+
10+
version=${DOCS_VERSION:-nightly}
11+
echo "version: $version"
12+
13+
# Build functorch docs
14+
pushd $pt_checkout/functorch/docs
15+
make html
16+
popd
17+
18+
git clone https://github.com/pytorch/functorch -b gh-pages --depth 1 functorch_ghpages
19+
pushd functorch_ghpages
20+
21+
if [ "$version" == "main" ]; then
22+
version=nightly
23+
fi
24+
25+
git rm -rf "$version" || true
26+
mv "$pt_checkout/functorch/docs/build/html" "$version"
27+
28+
git add "$version" || true
29+
git status
30+
git config user.email "soumith+bot@pytorch.org"
31+
git config user.name "pytorchbot"
32+
# If there aren't changes, don't make a commit; push is no-op
33+
git commit -m "Generate Python docs from pytorch/pytorch@${GITHUB_SHA}" || true
34+
git status
35+
36+
if [[ "${WITH_PUSH:-}" == true ]]; then
37+
git push -u origin gh-pages
38+
fi
39+
40+
popd
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#!/bin/bash
2+
3+
# This is where the local pytorch install in the docker image is located
4+
pt_checkout="/var/lib/jenkins/workspace"
5+
6+
source "$pt_checkout/.ci/pytorch/common_utils.sh"
7+
8+
echo "python_doc_push_script.sh: Invoked with $*"
9+
10+
set -ex
11+
12+
# for statements like ${1:-${DOCS_INSTALL_PATH:-docs/}}
13+
# the order of operations goes:
14+
# 1. Check if there's an argument $1
15+
# 2. If no argument check for environment var DOCS_INSTALL_PATH
16+
# 3. If no environment var fall back to default 'docs/'
17+
18+
# NOTE: It might seem weird to gather the second argument before gathering the first argument
19+
# but since DOCS_INSTALL_PATH can be derived from DOCS_VERSION it's probably better to
20+
# try and gather it first, just so we don't potentially break people who rely on this script
21+
# Argument 2: What version of the docs we are building.
22+
version="${2:-${DOCS_VERSION:-main}}"
23+
if [ -z "$version" ]; then
24+
echo "error: python_doc_push_script.sh: version (arg2) not specified"
25+
exit 1
26+
fi
27+
28+
# Argument 1: Where to copy the built documentation to
29+
# (pytorch.github.io/$install_path)
30+
install_path="${1:-${DOCS_INSTALL_PATH:-docs/${DOCS_VERSION}}}"
31+
if [ -z "$install_path" ]; then
32+
echo "error: python_doc_push_script.sh: install_path (arg1) not specified"
33+
exit 1
34+
fi
35+
36+
is_main_doc=false
37+
if [ "$version" == "main" ]; then
38+
is_main_doc=true
39+
fi
40+
41+
# Argument 3: The branch to push to. Usually is "site"
42+
branch="${3:-${DOCS_BRANCH:-site}}"
43+
if [ -z "$branch" ]; then
44+
echo "error: python_doc_push_script.sh: branch (arg3) not specified"
45+
exit 1
46+
fi
47+
48+
echo "install_path: $install_path version: $version"
49+
50+
51+
build_docs () {
52+
set +e
53+
set -o pipefail
54+
make "$1" 2>&1 | tee /tmp/docs_build.txt
55+
code=$?
56+
if [ $code -ne 0 ]; then
57+
set +x
58+
echo =========================
59+
grep "WARNING:" /tmp/docs_build.txt
60+
echo =========================
61+
echo Docs build failed. If the failure is not clear, scan back in the log
62+
echo for any WARNINGS or for the line "build finished with problems"
63+
echo "(tried to echo the WARNINGS above the ==== line)"
64+
echo =========================
65+
fi
66+
set -ex
67+
return $code
68+
}
69+
70+
71+
git clone https://github.com/pytorch/pytorch.github.io -b "$branch" --depth 1
72+
pushd pytorch.github.io
73+
74+
export LC_ALL=C
75+
export PATH=/opt/conda/bin:$PATH
76+
if [ -n "$ANACONDA_PYTHON_VERSION" ]; then
77+
export PATH=/opt/conda/envs/py_$ANACONDA_PYTHON_VERSION/bin:$PATH
78+
fi
79+
80+
rm -rf pytorch || true
81+
82+
# Get all the documentation sources, put them in one place
83+
pushd "$pt_checkout"
84+
pushd docs
85+
86+
# Build the docs
87+
if [ "$is_main_doc" = true ]; then
88+
if ! build_docs html; then
89+
exit $?
90+
fi
91+
make coverage
92+
# Now we have the coverage report, we need to make sure it is empty.
93+
# Count the number of lines in the file and turn that number into a variable
94+
# $lines. The `cut -f1 ...` is to only parse the number, not the filename
95+
# Skip the report header by subtracting 2: the header will be output even if
96+
# there are no undocumented items.
97+
#
98+
# Also: see docs/source/conf.py for "coverage_ignore*" items, which should
99+
# be documented then removed from there.
100+
lines=$(wc -l build/coverage/python.txt 2>/dev/null |cut -f1 -d' ')
101+
undocumented=$((lines - 2))
102+
if [ $undocumented -lt 0 ]; then
103+
echo coverage output not found
104+
exit 1
105+
elif [ $undocumented -gt 0 ]; then
106+
echo undocumented objects found:
107+
cat build/coverage/python.txt
108+
echo "Make sure you've updated relevant .rsts in docs/source!"
109+
exit 1
110+
fi
111+
else
112+
# skip coverage, format for stable or tags
113+
if ! build_docs html-stable; then
114+
exit $?
115+
fi
116+
fi
117+
118+
# Move them into the docs repo
119+
popd
120+
popd
121+
git rm -rf "$install_path" || true
122+
mv "$pt_checkout/docs/build/html" "$install_path"
123+
124+
# Prevent Google from indexing $install_path/_modules. This folder contains
125+
# generated source files.
126+
# NB: the following only works on gnu sed. The sed shipped with mac os is different.
127+
# One can `brew install gnu-sed` on a mac and then use "gsed" instead of "sed".
128+
find "$install_path/_modules" -name "*.html" -print0 | xargs -0 sed -i '/<head>/a \ \ <meta name="robots" content="noindex">'
129+
130+
git add "$install_path" || true
131+
git status
132+
git config user.email "soumith+bot@pytorch.org"
133+
git config user.name "pytorchbot"
134+
# If there aren't changes, don't make a commit; push is no-op
135+
git commit -m "Generate Python docs from pytorch/pytorch@${GITHUB_SHA}" || true
136+
git status
137+
138+
if [[ "${WITH_PUSH:-}" == true ]]; then
139+
# push to a temp branch first to trigger CLA check and satisfy branch protections
140+
git push -u origin HEAD:pytorchbot/temp-branch-py -f
141+
git push -u origin HEAD^:pytorchbot/base -f
142+
sleep 30
143+
git push -u origin "${branch}"
144+
fi
145+
146+
popd

0 commit comments

Comments
 (0)