Skip to content

Commit 0470325

Browse files
authored
Add doc build (#136)
* Add doc build * Update doc build job * Update * Add the upload job * Update * Change to TorchAO to torchao * Update * Update env * Update * Add logic for the versions to display in dropdown * Addressed comments * Add write permissions in the doc job * Addressed comments
1 parent b0a649e commit 0470325

29 files changed

+1125
-0
lines changed

.github/workflows/doc_build.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Build Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- release/*
8+
tags:
9+
- v[0-9]+.[0-9]+.[0-9]
10+
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
11+
pull_request:
12+
workflow_dispatch:
13+
14+
concurrency:
15+
group: build-docs-${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_number || github.ref }}
16+
cancel-in-progress: true
17+
18+
defaults:
19+
run:
20+
shell: bash -l -eo pipefail {0}
21+
22+
jobs:
23+
build_docs:
24+
runs-on: ubuntu-latest
25+
strategy:
26+
matrix:
27+
python-version: ['3.11']
28+
steps:
29+
- name: Check out repo
30+
uses: actions/checkout@v3
31+
- name: Setup conda env
32+
uses: conda-incubator/setup-miniconda@v2
33+
with:
34+
auto-update-conda: true
35+
miniconda-version: "latest"
36+
activate-environment: test
37+
python-version: ${{ matrix.python-version }}
38+
- name: Update pip
39+
run: python -m pip install --upgrade pip
40+
- name: Install dependencies
41+
run: |
42+
python -m pip install torch
43+
python -m pip install -e .
44+
cd docs
45+
python -m pip install -r requirements.txt
46+
- name: Get the torchtune version
47+
run: |
48+
# Get the github.ref_name and save into the
49+
# REF_NAME variable. This will be passed in
50+
# conf.py to display the version in the
51+
# site dropdown
52+
REF_NAME=${{ github.ref_name }}
53+
TORCHAO_VERSION_DOCS="${REF_NAME}"
54+
echo "$TORCHAO_VERSION_DOCS"
55+
- name: Build docs
56+
run: |
57+
cd docs
58+
make html
59+
- uses: actions/upload-artifact@v3
60+
with:
61+
name: Doc-Build
62+
path: docs/build/html/
63+
64+
upload:
65+
runs-on: ubuntu-latest
66+
permissions:
67+
# Grant write permission here so that the doc can be pushed to gh-pages branch
68+
contents: write
69+
needs: build_docs
70+
if: github.repository == 'pytorch-labs/ao' && github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/tags/v'))
71+
steps:
72+
- name: Checkout
73+
uses: actions/checkout@v3
74+
with:
75+
ref: gh-pages
76+
persist-credentials: false
77+
- name: Download artifact
78+
uses: actions/download-artifact@v3
79+
with:
80+
name: Doc-Build
81+
path: docs
82+
- name: Add no-index tag
83+
run: |
84+
REF_NAME=$(echo "${{ github.ref }}")
85+
echo "Ref name: ${REF_NAME}"
86+
if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then
87+
find docs -name "*.html" -print0 | xargs -0 sed -i '/<head>/a \ \ <meta name="robots" content="noindex">';
88+
fi
89+
- name: Move and commit changes
90+
env:
91+
GITHUB_PYTORCHBOT_TOKEN: ${{ secrets.GH_PYTORCHBOT_TOKEN }}
92+
run: |
93+
git remote set-url origin https://pytorchbot:${GITHUB_PYTORCHBOT_TOKEN}@github.com/pytorch-labs/ao.git
94+
set -euo pipefail
95+
REF_TYPE=${{ github.ref_type }}
96+
REF_NAME=${{ github.ref_name }}
97+
if [[ "${REF_TYPE}" == branch ]]; then
98+
TARGET_FOLDER="${REF_NAME}"
99+
elif [[ "${REF_TYPE}" == tag ]]; then
100+
case "${REF_NAME}" in
101+
*-rc*)
102+
echo "Aborting upload since this is an RC tag: ${REF_NAME}"
103+
exit 0
104+
;;
105+
*)
106+
TARGET_FOLDER=$(echo "${REF_NAME}" | sed 's/v\([0-9]\+\)\.\([0-9]\+\)\.[0-9]\+/\1.\2/')
107+
;;
108+
esac
109+
fi
110+
111+
echo "Target Folder: ${TARGET_FOLDER}"
112+
mkdir -p "${TARGET_FOLDER}"
113+
rm -rf "${TARGET_FOLDER}"/*
114+
mv docs/* "${TARGET_FOLDER}"
115+
116+
git config user.name 'pytorchbot'
117+
git config user.email '[email protected]'
118+
git add "${TARGET_FOLDER}" || true
119+
git commit -m "auto-generating sphinx docs" || true
120+
git push -f

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ docs/gathered
258258
_site
259259
doxygen
260260
docs/dev
261+
docs/build
262+
docs/source/tutorials/*
263+
docs/source/gen_modules/*
264+
docs/source/sg_execution_times.rst
261265

262266
# LevelDB files
263267
*.sst

docs/Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
ifneq ($(EXAMPLES_PATTERN),)
5+
EXAMPLES_PATTERN_OPTS := -D sphinx_gallery_conf.filename_pattern="$(EXAMPLES_PATTERN)"
6+
endif
7+
8+
# You can set these variables from the command line.
9+
SPHINXOPTS = -W -j auto $(EXAMPLES_PATTERN_OPTS)
10+
SPHINXBUILD = sphinx-build
11+
SPHINXPROJ = torchao
12+
SOURCEDIR = source
13+
BUILDDIR = build
14+
15+
# Put it first so that "make" without argument is like "make help".
16+
help:
17+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
18+
19+
html-noplot: # Avoids running the gallery examples, which may take time
20+
$(SPHINXBUILD) -D plot_gallery=0 -b html "${SOURCEDIR}" "$(BUILDDIR)"/html
21+
@echo
22+
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
23+
24+
clean:
25+
rm -rf $(BUILDDIR)/*
26+
rm -rf $(SOURCEDIR)/generated_examples/ # sphinx-gallery
27+
rm -rf $(SOURCEDIR)/gen_modules/ # sphinx-gallery
28+
rm -rf $(SOURCEDIR)/sg_execution_times.rst # sphinx-gallery
29+
rm -rf $(SOURCEDIR)/generated/ # autosummary
30+
31+
.PHONY: help Makefile docset
32+
33+
# Catch-all target: route all unknown targets to Sphinx using the new
34+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
35+
%: Makefile
36+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/README.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Tutorials
2+
=========
3+
4+
template_tutorial.py
5+
Template Tutorial
6+
tutorials/template_tutorial.html

docs/requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sphinx-gallery>0.11
2+
sphinx==5.0.0
3+
sphinx_design
4+
sphinx_copybutton
5+
sphinx-tabs
6+
matplotlib
7+
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme

docs/source/_static/css/custom.css

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/* sphinx-design styles for cards/tabs */
10+
11+
12+
:root {
13+
--sd-color-info: #ee4c2c;
14+
--sd-color-primary: #6c6c6d;
15+
--sd-color-primary-highlight: #f3f4f7;
16+
--sd-color-card-border-hover: #ee4c2c;
17+
--sd-color-card-border: #f3f4f7;
18+
--sd-color-card-background: #fff;
19+
--sd-color-card-text: inherit;
20+
--sd-color-card-header: transparent;
21+
--sd-color-card-footer: transparent;
22+
--sd-color-tabs-label-active: #ee4c2c;
23+
--sd-color-tabs-label-hover: #ee4c2c;
24+
--sd-color-tabs-label-inactive: #6c6c6d;
25+
--sd-color-tabs-underline-active: #ee4c2c;
26+
--sd-color-tabs-underline-hover: #fabdbd;
27+
--sd-color-tabs-underline-inactive: transparent;
28+
--sd-color-tabs-overline: rgb(222, 222, 222);
29+
--sd-color-tabs-underline: rgb(222, 222, 222);
30+
}
31+
32+
.sd-text-info {
33+
color: #ee4c2c;
34+
}
35+
36+
.sd-card-img-top {
37+
background: #ee4c2c;
38+
height: 5px !important;
39+
}
40+
41+
.sd-card {
42+
position: relative;
43+
background-color: #fff;
44+
opacity: 1.0;
45+
border-radius: 0px;
46+
width: 30%;
47+
border: none;
48+
padding-bottom: 0px;
49+
}
50+
51+
52+
.sd-card-img:hover {
53+
opacity: 1.0;
54+
background-color: #f3f4f7;
55+
}
56+
57+
58+
.sd-card:after {
59+
display: block;
60+
opacity: 1;
61+
content: '';
62+
border-bottom: solid 1px #ee4c2c;
63+
background-color: #fff;
64+
transform: scaleX(0);
65+
transition: transform .250s ease-in-out;
66+
transform-origin: 0% 50%;
67+
}
68+
69+
.sd-card:hover {
70+
background-color: #fff;
71+
opacity: 1;
72+
border-top: 1px solid #f3f4f7;
73+
border-left: 1px solid #f3f4f7;
74+
border-right: 1px solid #f3f4f7;
75+
}
76+
77+
.sd-card:hover:after {
78+
transform: scaleX(1);
79+
}
80+
81+
.card-prerequisites:hover {
82+
transition: none;
83+
border: none;
84+
}
85+
86+
.card-prerequisites:hover:after {
87+
transition: none;
88+
transform: none;
89+
}
90+
91+
.card-prerequisites:after {
92+
display: block;
93+
content: '';
94+
border-bottom: none;
95+
background-color: #fff;
96+
transform: none;
97+
transition: none;
98+
transform-origin: none;
99+
}
100+
101+
102+
details.sd-dropdown {
103+
font-weight: 300;
104+
width: auto;
105+
}
106+
107+
details.sd-dropdown:after {
108+
border: none;
109+
transition: none;
110+
}
111+
112+
details.sd-dropdown:hover {
113+
border: none;
114+
transition: none;
115+
}
116+
117+
details.sd-dropdown .sd-summary-content {
118+
font-weight: 300;
119+
}
120+
121+
details.sd-dropdown .highlight .n {
122+
font-weight: normal;
123+
}
124+
125+
.et-page-column1 {
126+
float: left;
127+
width: 70%;
128+
font-size: 1rem;
129+
}
130+
131+
.et-page-column2 {
132+
float: right;
133+
padding-top: 40px;
134+
padding-left: 60px;
135+
padding-right: 60px;
136+
padding-bottom: 60px;
137+
width: 30%;
138+
}
139+
140+
.et-page-column-row:after {
141+
content: "";
142+
display: table;
143+
clear: both;
144+
}
145+
146+
/* For screens smaller than 768px (typical mobile devices) */
147+
@media screen and (max-width: 768px) {
148+
.et-page-column1, .et-page-column2 {
149+
float: none; /* Remove floats */
150+
width: 100%; /* Full width for both columns */
151+
padding: 0;
152+
font-size: 1rem;
153+
}
154+
155+
.et-page-column2 img {
156+
display: none;
157+
}
158+
.et-page-column-row:after {
159+
content: "";
160+
display: table;
161+
clear: both;
162+
}
163+
}
164+
165+
article.pytorch-article .class .method dt {
166+
border-top: none;
167+
}
168+
169+
article.pytorch-article .class .simple dt {
170+
border-top: none;
171+
}
172+
173+
article.pytorch-article .function dt.sig {
174+
border-top: none;
175+
}
176+
177+
/* Fix for Sphinx gallery thumbnails.
178+
See https://github.com/sphinx-gallery/sphinx-gallery/issues/990
179+
*/
180+
article.pytorch-article .sphx-glr-thumbnails .sphx-glr-thumbcontainer {
181+
width: unset;
182+
margin-right: 0;
183+
margin-left: 0;
184+
}
185+
article.pytorch-article div.section div.wy-table-responsive tbody td {
186+
width: 50%;
187+
}
Lines changed: 13 additions & 0 deletions
Loading
34.9 KB
Loading

0 commit comments

Comments
 (0)