Skip to content

[Doc] Cache executed sphinx-gallery output between doc builds#3983

Open
vmoens wants to merge 1 commit into
gh/vmoens/282/basefrom
gh/vmoens/282/head
Open

[Doc] Cache executed sphinx-gallery output between doc builds#3983
vmoens wants to merge 1 commit into
gh/vmoens/282/basefrom
gh/vmoens/282/head

Conversation

@vmoens

@vmoens vmoens commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

Every docs build re-executes all 28 tutorials even when none changed,
dominating the ~30 minute build. sphinx-gallery already skips a
tutorial when its generated output (including the .md5 checksum of the
source) is present in the gallery dir, so preserving that directory
across builds is enough; the build runs inside test-infra's
linux_job_v2, which does not support actions/cache steps, so the cache
lives in a dedicated docs-gallery-cache branch instead.

  • Restore (in-script, before sphinx-build) on pull requests and pushes
    to main only: never on schedule (the nightly orchestrator's build is
    the daily full rebuild that catches tutorials broken by library
    changes), and never on tags/release branches (they build with stable
    torch and must not inherit nightly-torch outputs). The cache key
    folds in conf.py, docs/requirements.txt and the resolved
    torch/sphinx-gallery versions; TORCHRL_DOCS_GALLERY_CACHE=0 disables.
  • Save: main pushes and the nightly run stage docs/source/tutorials
    plus the key into the docs artifact; the gh-pages upload job strips
    that directory so it never lands on the site.
  • update-gallery-cache job: force-pushes the staged cache as a single
    orphan commit (the branch never grows), serialized by its own
    concurrency group since docs.yml's is per-sha on main. The nightly
    writer bounds output staleness with respect to torch/tensordict/
    torchrl to at most a day.

Verified locally with the pinned sphinx/sphinx-gallery: a second build
with the gallery dir restored skips execution (identical output), and
check_tutorial_time_budget.py parses the 00:00.004 entries a skipped
build writes.

Also fixes the PR-only RUNNER_DOCS_DIR copy, which was written as
[[ ${{ github.event_name == 'pull_request' }} ]] and therefore ran on
every event (both "true" and "false" are truthy in [[ ]]).

Known tradeoff: published pages for unchanged tutorials show outputs
from an older build (bounded by the nightly refresh), and a library
change that breaks an unchanged tutorial surfaces at nightly rather
than on the PR.

Co-Authored-By: Claude Fable 5 noreply@anthropic.com

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3983

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit f3a0c52 with merge base a74b478 (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Has to do with CI setup (e.g. wheels & builds, tests...) CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant