Faster tests (#1334) #124
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: GPU Docs | |
| on: | |
| schedule: | |
| - cron: "30 2 */1 * *" | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| pr_number: | |
| description: "PR number to test" | |
| required: true | |
| type: string | |
| pr_sha: | |
| description: "Exact PR commit to test" | |
| required: true | |
| type: string | |
| jobs: | |
| gpu-docs: | |
| name: Check examples and docs run on GPU | |
| runs-on: gpu | |
| env: | |
| DEEPINV_MOCK_TESTS: "True" | |
| DEEPINV_DOWNLOAD_VERBOSE: "False" | |
| WORKING_DIR: "/local/jtachell" | |
| PIXI_HOME: "/local/jtachell/.pixi" | |
| TMP_DIR: "/local/jtachell/tmp" | |
| DEEPINV_CACHE_DIR: "/local/jtachell/.cache/deepinv" | |
| HF_HOME: "/local/jtachell/.cache/huggingface" | |
| TORCH_HOME: "/local/jtachell/.cache/torch" | |
| HOME: "/local/jtachell" | |
| steps: | |
| - name: Check out main or PR commit | |
| uses: actions/checkout@v5 | |
| with: | |
| # `github.sha` is the commit that triggered the workflow, which is the latest commit on main for schedule/push events | |
| ref: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_sha || github.sha }} | |
| - name: Setup Pixi | |
| uses: prefix-dev/setup-pixi@v0.9.3 | |
| with: | |
| pixi-version: latest | |
| post-cleanup: true | |
| pixi-bin-path: /local/jtachell/pixi/bin/pixi | |
| environments: docs doctest | |
| - name: Check import | |
| run: | | |
| pixi run -e docs python -c "import deepinv" | |
| - name: Check CUDA is available | |
| run: | | |
| pixi run -e docs python -c " | |
| import torch | |
| assert torch.cuda.is_available(), ( | |
| f'torch.cuda.is_available() returned False. ' | |
| f'Device count: {torch.cuda.device_count()}, ' | |
| f'PyTorch build: {torch.version.cuda}' | |
| ) | |
| print(f'CUDA OK — {torch.cuda.device_count()} device(s), ' | |
| f'CUDA {torch.version.cuda}, ' | |
| f'GPU: {torch.cuda.get_device_name(0)}') | |
| " | |
| - name: Determine which examples to run | |
| id: get_pattern | |
| env: | |
| PR_BODY: ${{ github.event.pull_request.body }} | |
| run: | | |
| if [ "${{ github.event_name }}" == "pull_request" ]; then | |
| # Check PR body for the keyword "test-examples" (case-insensitive) | |
| if printf "%s" "$PR_BODY" | grep -iq "test-examples"; then | |
| # FORCE RUN: If keyword is found, set pattern to ".*" and skip dependency analysis. | |
| PATTERN=".*" | |
| echo "Keyword 'test-examples' found. Forcing full documentation build (Pattern: $PATTERN)." | |
| else | |
| # Use the remote reference for the base branch and HEAD for the current commit. | |
| BASE_REF="origin/${{ github.event.pull_request.base.ref }}" | |
| HEAD_REF="HEAD" | |
| echo "Analyzing changes between $BASE_REF and $HEAD_REF..." | |
| # Execute the Python script to find affected examples | |
| PATTERN=$(pixi run -e docs python .github/scripts/diff_sphinx_gallery.py "$BASE_REF" "$HEAD_REF") | |
| echo "Conditional PR Pattern: $PATTERN" | |
| fi | |
| else | |
| # push to main | |
| # The pattern ".*" matches all files, ensuring a full build is run. | |
| PATTERN=".*" | |
| echo "Full build triggered by ${{ github.event_name }} event." | |
| fi | |
| # Pass the determined pattern to the next step | |
| echo "SG_PATTERN=$PATTERN" >> $GITHUB_OUTPUT | |
| - name: Build documentation with chosen examples | |
| env: | |
| SG_PATTERN: ${{ steps.get_pattern.outputs.SG_PATTERN }} | |
| run: | | |
| echo "Running Sphinx with filename_pattern: $SG_PATTERN" | |
| pixi run -e docs sphinx-build -W docs/source _build -D "sphinx_gallery_conf.filename_pattern=$SG_PATTERN" | |
| - name: Notebook generation | |
| run: | | |
| set -euo pipefail | |
| echo "Converting Python examples to notebooks in _build/auto_examples/_notebooks..." | |
| mkdir -p _build/auto_examples/_notebooks | |
| find examples -type f -name '*.py' | while read -r f; do | |
| rel="${f#examples/}" | |
| out_dir="_build/auto_examples/_notebooks/$(dirname "$rel")" | |
| mkdir -p "$out_dir" | |
| base="$(basename "$rel" .py)" | |
| out_path="$out_dir/$base.ipynb" | |
| pixi run -e docs python .github/scripts/convert_to_notebook.py --input "$f" --output "$out_path" | |
| done | |
| - name: Upload Documentation Artifact | |
| id: upload-artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: documentation | |
| path: _build/ | |
| - name: Deploy to ghpages | |
| uses: peaceiris/actions-gh-pages@v3 | |
| if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
| with: | |
| publish_branch: gh-pages | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: _build/ | |
| force_orphan: true | |
| enable_jekyll: false | |
| cname: deepinv.org | |
| # Comment results back to PR | |
| - name: Post result to PR | |
| if: always() && inputs.pr_number != '' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const pr = context.payload.inputs.pr_number; | |
| const result = "${{ job.status }}"; | |
| const runUrl = `${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`; | |
| const artifactUrl = "${{ steps.upload-artifact.outputs.artifact-url }}"; | |
| const body = result === "success" | |
| ? `✅ GPU docs passed | |
| 🔗 [View run details](${runUrl}) | |
| 📦 [Download built docs](${artifactUrl})` | |
| : `❌ GPU docs failed\n\n🔗 [View run details](${runUrl})`; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: pr, | |
| body, | |
| }); | |
| - name: Run doctests | |
| env: | |
| TQDM_DISABLE: 1 | |
| HF_HUB_DISABLE_PROGRESS_BARS: 1 | |
| DEEPINV_DOWNLOAD_VERBOSE: 0 | |
| run: | | |
| pixi run -e doctest pytest --doctest-glob="*.rst" docs/ \ | |
| --ignore=docs/source/user_guide/training/multigpu.rst \ | |
| --ignore=docs/source/user_guide/training/datasets.rst | |
| - name: Cleanup Pixi | |
| if: always() | |
| run: | | |
| rm -rf /local/jtachell/pixi |