Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 81 additions & 52 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
build-docs:
name: Build Documentation
runs-on: ubuntu-latest
runs-on: linux.g5.4xlarge.nvidia.gpu
timeout-minutes: 30
steps:
- name: Checkout
Expand All @@ -24,7 +24,7 @@ jobs:
miniconda-version: "latest"
activate-environment: test
python-version: '3.10'
auto-activate-base: false
auto-activate: false
- name: Verify conda environment
shell: bash -l {0}
run: |
Expand All @@ -36,7 +36,7 @@ jobs:
run: python -m pip install --upgrade pip
- name: Install pytorch
shell: bash -l {0}
run: python -m pip install torch==2.9.0.dev20250826 --extra-index-url https://download.pytorch.org/whl/nightly/cpu
run: python -m pip install torch==2.9.0 --index-url https://download.pytorch.org/whl/test/cu130
- name: Install monarch
shell: bash -l {0}
run: python -m pip install monarch-no-torch==0.1.0.dev20250826 --find-links assets/ci
Expand All @@ -51,61 +51,90 @@ jobs:
- name: Build docs
shell: bash -l {0}
working-directory: docs
run: make html --keep-going SPHINXOPTS='-W'
run: |
set +e # Don't exit on error
make html SPHINXOPTS="-WT --keep-going" || echo "Build completed with warnings/errors"
set -e # Re-enable exit on error for subsequent commands
- name: Upload docs artifact
uses: actions/upload-artifact@v4
with:
name: docs
path: docs/build/html/

# doc-preview:
# runs-on: [ubuntu-latest]
# needs: build-docs
# if: ${{ github.event_name == 'pull_request' }}
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Download artifact
# uses: actions/download-artifact@v4
# with:
# name: docs
# path: docs
# - name: Add noindex to preview docs
# run: |
# echo "Adding noindex meta tag to prevent search engine indexing of preview docs"
# find docs -name "*.html" -print0 | xargs -0 sed -i 's/<head>/<head>\n <meta name="robots" content="noindex">/'
# - 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: meta-pytorch/forge/${{ github.event.pull_request.number }}
doc-preview:
runs-on: linux.large
needs: build-docs
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: docs
path: docs
- name: Add noindex to preview docs
run: |
echo "Adding noindex meta tag to prevent search engine indexing of preview docs"
find docs -name "*.html" -print0 | xargs -0 sed -i 's/<head>/<head>\n <meta name="robots" content="noindex">/'
- 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: meta-pytorch/forge/${{ 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 == 'meta-pytorch/forge' && 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@v4
with:
ref: gh-pages
persist-credentials: true
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: docs
path: docs
#- name: Add no-index tag
# run: |
# REF_NAME=$(echo "${{ github.ref }}")
# echo "Ref name: ${REF_NAME}"
# if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then
# find docs -name "*.html" -print0 | xargs -0 sed -i '/<head>/a \ \ <meta name="robots" content="noindex">';
# fi
- name: Move and commit changes
run: |
set -euo pipefail
# 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 }}

deploy-docs:
needs: build-docs
if: github.ref == 'refs/heads/main'
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: docs
path: .
# 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_FOLDER="${BASH_REMATCH[1]}"
else
TARGET_FOLDER="main"
fi
echo "Target Folder: ${TARGET_FOLDER}"

- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: .
mkdir -p "${TARGET_FOLDER}"
rm -rf "${TARGET_FOLDER}"/*
mv docs/* "${TARGET_FOLDER}"

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
git config user.name 'pytorchbot'
git config user.email '[email protected]'
git add "${TARGET_FOLDER}" || true
git commit -m "auto-generating sphinx docs" || true
git push -f
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ docs/source/generated_examples/
docs/source/gen_modules/
docs/source/generated/
docs/source/sg_execution_times.rst
docs/source/tutorials
# pytorch-sphinx-theme gets installed here
docs/src

Expand Down
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
sphinx==7.2.6
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git@pytorch_sphinx_theme2#egg=pytorch_sphinx_theme2
pytorch-sphinx-theme2==0.1.0
docutils>=0.18.1,<0.21
sphinx-design==0.6.1
sphinxcontrib-mermaid==1.0.0
sphinx-gallery==0.19.0
myst-parser #==0.18.1 # if want to contribute in markdown
sphinx-sitemap==2.7.1
65 changes: 57 additions & 8 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,33 @@
import pytorch_sphinx_theme2

# Add the source directory to Python path so modules can be imported
sys.path.insert(0, os.path.abspath("../../src"))
sys.path.insert(0, os.path.abspath("../../src/forge"))


# Determine the version path for deployment
def get_version_path():
"""Get the version path based on environment variables or git context."""
# Check if we're in CI/CD and get the target folder
github_ref = os.environ.get("GITHUB_REF", "")

# Convert refs/tags/v1.12.0rc3 into 1.12.
# Matches the logic in .github/workflows/docs.yml
if github_ref.startswith("refs/tags/v"):
import re

match = re.match(r"^refs/tags/v([0-9]+\.[0-9]+)\..*", github_ref)
if match:
return match.group(1) + "/"

# Default to main for main branch or local development
return "main/"


# Set base URL based on deployment context
version_path = get_version_path()

project = "torchforge"
copyright = "2025, PyTorch Contributors"
copyright = ""
author = "PyTorch Contributors"
release = "0.1"

Expand All @@ -38,9 +61,12 @@
"sphinx.ext.napoleon",
"sphinx.ext.intersphinx",
"sphinx.ext.viewcode",
"sphinx_gallery.gen_gallery",
]

html_baseurl = "https://meta-pytorch.org/forge/" # needed for sphinx-sitemap
html_baseurl = (
f"https://meta-pytorch.org/forge/{version_path}" # needed for sphinx-sitemap
)
sitemap_locales = [None]
sitemap_excludes = [
"search.html",
Expand All @@ -52,7 +78,7 @@
"_templates",
os.path.join(os.path.dirname(pytorch_sphinx_theme2.__file__), "templates"),
]
exclude_patterns = []
exclude_patterns = ["tutorials/index.rst"]

sys.path.insert(0, os.path.abspath("."))
sys.path.insert(0, os.path.abspath("../../src"))
Expand Down Expand Up @@ -90,7 +116,7 @@
},
{
"name": "PyPi",
"url": "https://pypi.org/project/forge/",
"url": "https://pypi.org/project/torchforge/",
"icon": "fa-brands fa-python",
},
],
Expand All @@ -109,9 +135,21 @@
"github_user": "meta-pytorch",
"github_repo": "forge",
"feedback_url": "https://github.com/meta-pytorch/forge",
"colab_branch": "gh-pages",
"github_version": "main",
"doc_path": "docs/source",
"has_sphinx_gallery": True, # Enable tutorial call-to-action links
}

# For tutorial repository configuration
# Note: github_user and github_repo are combined in the template as "{{ github_user }}/{{ github_repo }}"
# So we keep github_user = "meta-pytorch" and github_repo = "forge" already set above
# and only need to ensure the branch settings are correct
tutorial_repo_config = {
"github_version": "main", # This maps to github_branch in the template
"colab_branch": "gh-pages",
}
html_context.update(tutorial_repo_config)

myst_enable_extensions = [
"colon_fence",
Expand All @@ -127,6 +165,17 @@
"exclude-members": "__weakref__",
}

# Autosummary settings
autosummary_generate = True
autosummary_imported_members = True

# -- Sphinx Gallery configuration -------------------------------------------
sphinx_gallery_conf = {
"examples_dirs": "tutorial_sources", # Path to examples directory
"gallery_dirs": "tutorials", # Path to generate gallery
"filename_pattern": ".*", # Include all files
"download_all_examples": False,
"first_notebook_cell": "%matplotlib inline",
"plot_gallery": "True",
"promote_jupyter_magic": True,
"backreferences_dir": None,
"write_computation_times": True,
"show_signature": False,
}
5 changes: 5 additions & 0 deletions docs/source/tutorial_sources/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Tutorials
=========

This gallery contains tutorials and examples to help you get started with Forge.
Each tutorial demonstrates specific features and use cases with practical examples.
91 changes: 91 additions & 0 deletions docs/source/tutorial_sources/template_tutorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

"""
Template Tutorial
=================

**Author:** `FirstName LastName <https://github.com/username>`_

.. grid:: 2

.. grid-item-card:: :octicon:`mortar-board;1em;` What you will learn
:class-card: card-prerequisites

* Item 1
* Item 2
* Item 3

.. grid-item-card:: :octicon:`list-unordered;1em;` Prerequisites
:class-card: card-prerequisites

* PyTorch v2.0.0
* GPU ???
* Other items 3


To test your tutorial locally, you can do one of the following:

* You can control specific files that generate the results by using
``GALLERY_PATTERN`` environment variable. The GALLERY_PATTERN variable
respects regular expressions.
For example to run only ``neural_style_transfer_tutorial.py``,
use the following command:

.. code-block:: sh

GALLERY_PATTERN="neural_style_transfer_tutorial.py" make html

or

.. code-block:: sh

GALLERY_PATTERN="neural_style_transfer_tutorial.py" sphinx-build . _build

* Make a copy of this repository and add only your
tutorial to the `beginner_source` directory removing all other tutorials.
Then run ``make html``.

Verify that all outputs were generated correctly in the created HTML.
"""

#########################################################################
# Overview
# --------
#
# Describe Why is this topic important? Add Links to relevant research papers.
#
# This tutorial walks you through the process of....
#
# Steps
# -----
#
# Example code (the output below is generated automatically):
#
import torch

x = torch.rand(5, 3)
print(x)

######################################################################
# (Optional) Additional Exercises
# -------------------------------
#
# Add additional practice exercises for users to test their knowledge.
# Example: `NLP from Scratch <https://pytorch.org/tutorials/intermediate/char_rnn_generation_tutorial.html#exercises>`__.
#

######################################################################
# Conclusion
# ----------
#
# Summarize the steps and concepts covered. Highlight key takeaways.
#
# Further Reading
# ---------------
#
# * Link1
# * Link2
Loading
Loading