diff --git a/.github/workflows/doc_build.yml b/.github/workflows/doc_build.yml
index 03a0a53c6f..088b48a7ea 100644
--- a/.github/workflows/doc_build.yml
+++ b/.github/workflows/doc_build.yml
@@ -49,8 +49,8 @@ jobs:
# REF_NAME variable. This will be passed in
# conf.py to display the version in the
# site dropdown
- REF_NAME=${{ github.ref_name }}
- TORCHAO_VERSION_DOCS="${REF_NAME}"
+ GITHUB_REF=${{ github.ref }}
+ TORCHAO_VERSION_DOCS="${GITHUB_REF}"
echo "$TORCHAO_VERSION_DOCS"
- name: Build docs
run: |
@@ -61,13 +61,35 @@ jobs:
name: Doc-Build
path: docs/build/html/
+ doc-preview:
+ runs-on: [self-hosted, linux.2xlarge]
+ needs: build_docs
+ if: ${{ github.event_name == 'pull_request' }}
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ - name: Download artifact
+ uses: actions/download-artifact@v3
+ with:
+ name: Doc-Build
+ path: docs
+ - name: Upload docs preview
+ uses: seemethere/upload-artifact-s3@v5
+ if: ${{ github.event_name == 'pull_request' }}
+ with:
+ retention-days: 14
+ s3-bucket: doc-previews
+ if-no-files-found: error
+ path: docs
+ s3-prefix: pytorch/ao/${{ github.event.pull_request.number }}
+
upload:
runs-on: ubuntu-latest
permissions:
# Grant write permission here so that the doc can be pushed to gh-pages branch
contents: write
needs: build_docs
- 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') || github.event_name == 'workflow_dispatch')
+ if: github.repository == 'pytorch-labs/ao' && github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch')
steps:
- name: Checkout
uses: actions/checkout@v3
@@ -89,23 +111,20 @@ jobs:
- name: Move and commit changes
run: |
set -euo pipefail
- REF_TYPE=${{ github.ref_type }}
- REF_NAME=${{ github.ref_name }}
- if [[ "${REF_TYPE}" == branch ]]; then
- TARGET_FOLDER="${REF_NAME}"
- elif [[ "${REF_TYPE}" == tag ]]; then
- case "${REF_NAME}" in
- *-rc*)
- echo "Aborting upload since this is an RC tag: ${REF_NAME}"
- exit 0
- ;;
- *)
- TARGET_FOLDER=$(echo "${REF_NAME}" | sed 's/v\([0-9]\+\)\.\([0-9]\+\)\.[0-9]\+/\1.\2/')
- ;;
- esac
- fi
+ # Get github.ref for the output doc folder. By default "main"
+ # If matches a tag like refs/tags/v1.12.0-rc3 or
+ # refs/tags/v1.12.0 convert to 1.12
+ GITHUB_REF=${{ github.ref }}
+ # Convert refs/tags/v1.12.0rc3 into 1.12.
+ # Adopted from https://github.com/pytorch/pytorch/blob/main/.github/workflows/_docs.yml#L150C11-L155C13
+ if [[ "${GITHUB_REF}" =~ ^refs/tags/v([0-9]+\.[0-9]+)\.* ]]; then
+ target="${BASH_REMATCH[1]}"
+ else
+ target="main"
+ fi
echo "Target Folder: ${TARGET_FOLDER}"
+
mkdir -p "${TARGET_FOLDER}"
rm -rf "${TARGET_FOLDER}"/*
mv docs/* "${TARGET_FOLDER}"
diff --git a/.gitignore b/.gitignore
index 8d56ff2b9e..cdf17f0848 100644
--- a/.gitignore
+++ b/.gitignore
@@ -261,7 +261,7 @@ docs/dev
docs/build
docs/source/tutorials/*
docs/source/gen_modules/*
-docs/source/sg_execution_times.rst
+docs/source/sg_execution_times
# LevelDB files
*.sst
diff --git a/docs/source/_templates/layout.html b/docs/source/_templates/layout.html
index f432a1b7c4..6bb2207266 100644
--- a/docs/source/_templates/layout.html
+++ b/docs/source/_templates/layout.html
@@ -1,10 +1,9 @@
{% extends "!layout.html" %}
{% block sidebartitle %}
-
-
+
{% include "searchbox.html" %}
{% endblock %}
diff --git a/docs/source/conf.py b/docs/source/conf.py
index e1afc183d8..1c8793596e 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -67,34 +67,17 @@
torchao_version_docs = os.environ.get("TORCHAO_VERSION_DOCS", None)
# The code below will cut version displayed in the dropdown like this:
-# tags like v0.1.0 = > 0.1
-# branch like release/0.1 => 0.1
-# main will remain main
-# if not set will fail back to main
+# by default "main" is set.
+# tags like v0.1.0 or with the -rc suffix like v0.1.0-rc3 = > 0.1
# the version varible is used in layout.html: https://github.com/pytorch/torchao/blob/main/docs/source/_templates/layout.html#L29
+version = release = "main"
if torchao_version_docs:
- # Check if starts with release/ and set the version to the number after slash
- if torchao_version_docs.startswith("release/"):
- version = torchao_version_docs.split("/")[-1]
- else:
- # Remove "v" prefix if present
- if torchao_version_docs.startswith("v"):
- torchao_version_docs = torchao_version_docs[1:]
- # Split to major, minor, and patch
- version_components = torchao_version_docs.split(".")
-
- # Combine the major and minor version components:
- if len(version_components) >= 2:
- version = release = ".".join(version_components[:2])
- else:
- # If there are not enough components, use the full version
- version = release = torchao_version_docs
-
- html_title = " ".join((project, version, "documentation"))
-# IF TORCHAO_VERSION_DOCS not set, set version to main.
-else:
- version = "main"
- release = "main"
+ if torchao_version_docs.startswith("refs/tags/v"):
+ version = ".".join(
+ torchao_version_docs.split("/")[-1].split("-")[0].lstrip("v").split(".")[:2]
+ )
+print(f"Version: {version}")
+html_title = " ".join((project, version, "documentation"))
# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
diff --git a/docs/source/sg_execution_times.rst b/docs/source/sg_execution_times.rst
deleted file mode 100644
index 56399a4eee..0000000000
--- a/docs/source/sg_execution_times.rst
+++ /dev/null
@@ -1,37 +0,0 @@
-
-:orphan:
-
-.. _sphx_glr_sg_execution_times:
-
-
-Computation times
-=================
-**00:00.965** total execution time for 1 file **from all galleries**:
-
-.. container::
-
- .. raw:: html
-
-
-
-
-
-
-
- .. list-table::
- :header-rows: 1
- :class: table table-striped sg-datatable
-
- * - Example
- - Time
- - Mem (MB)
- * - :ref:`sphx_glr_tutorials_template_tutorial.py` (``tutorials_source/template_tutorial.py``)
- - 00:00.965
- - 0.0