Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
130 changes: 125 additions & 5 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,10 +135,22 @@
"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",
"deflist",
Expand All @@ -127,6 +165,88 @@
"exclude-members": "__weakref__",
}

# Mock imports for dependencies that aren't available during doc building
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for my understanding, once we have wheels that work in CI then we can go ahead and remove all of this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be problematic for a local installation that doesn't have all these deps more than the CI since we are installing all this. Also, just for API docs these import might not be necessarily needed. Since I'm only adding doc build changes and sphinx gallery in this PR, I will delete this part for now.

autodoc_mock_imports = [
"monarch",
"monarch.actor",
"monarch.distributed",
"torchtitan",
"torchtitan.components",
"torchtitan.components.loss",
"torchstore",
"torchdata",
"vllm",
"vllm.engine",
"vllm.engine.arg_utils",
"vllm.engine.async_llm_engine",
"vllm.sampling_params",
"hf_transfer",
"torch",
"torch.nn",
"torch.distributed",
"torch.utils",
"torch.utils.data",
"transformers",
"datasets",
"tiktoken",
"tokenizers",
"sentencepiece",
"wandb",
"tensorboard",
"omegaconf",
"hydra",
"numpy",
"pandas",
"rich",
"rich.console",
"rich.progress",
"accelerate",
"peft",
"tqdm",
"typing_extensions",
"fairscale",
"fairscale.nn",
"fairscale.nn.model_parallel",
"fairscale.nn.model_parallel.initialize",
"safetensors",
"bitsandbytes",
"flash_attn",
]

# Handle import errors gracefully
autodoc_default_flags = ["members", "undoc-members"]

# Additional autodoc configuration
autodoc_preserve_defaults = True
autodoc_member_order = "bysource"


# Autosummary settings
autosummary_generate = True
autosummary_imported_members = True
autosummary_generate_overwrite = True
autosummary_mock_imports = autodoc_mock_imports

# Prevent duplicate documentation
autodoc_inherit_docstrings = False
add_module_names = False

# Ensure autosummary can find templates
autosummary_context = {}

# Suppress duplicate object warnings and mocked object warnings
suppress_warnings = ["autodoc.mock_imports"]

# -- 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.
Loading
Loading