Skip to content

Add a torch grader image with sensible baked-in defaults - #65

Merged
eliotwrobson merged 7 commits into
torch-grader-defaultsfrom
torch-grader-image
Nov 26, 2026
Merged

eliotwrobson merged 7 commits into
torch-grader-defaultsfrom
torch-grader-image

Conversation

@eliotwrobson

@eliotwrobson eliotwrobson commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds the prairielearn/grader-python-pytest:torch image (closes #62, re-scoped to torch per discussion), plus two related build improvements.

Torch image

  • docker/Dockerfile.torch on a glibc (Debian) base — PyTorch publishes only manylinux wheels, so the Alpine base of the lite/full images can't install it. Pinned to Python 3.13 (newest with stable CPU torch wheels).
  • Self-contained, fully pinned requirements-torch.txt: the image carries its own pinned copy of the scientific stack plus the torch stack rather than layering on requirements-full.txt. It runs on a different Python/libc than the full image and pins torch tightly to specific numpy/Pillow versions, so it pins on its own terms; the cost is that new full-image packages are mirrored here by hand, which keeps changes to this heavy image explicit. (Also fixes a latent bug: the Dockerfile copied requirements-torch.txt but installed torch by bare name, so the file was never used.)
  • Installs a CPU-only torch + torchvision from the PyTorch CPU index (no multi-GB CUDA packages), plus torchinfo. The CPU index is the primary index and PyPI the extra, so torch resolves to CPU wheels and everything else falls through to PyPI.
  • Baked-in, overridable defaults: PL_GRADER_SANDBOX_TIMEOUT=10 (torch work blows past the 1s default) and single-threaded OMP/MKL_NUM_THREADS for reproducible grading. Questions override via ConfigObject / their own code.
  • Publishes the :torch tag via a new publish.yaml matrix entry.
  • A PyTorch grading section in quick_start.md documents the image, the override table, the tensor helpers, and the dataset/determinism gotchas (and the image table now lists :torch); README points there.

Full image build time

  • Moves the full image off Alpine onto the same glibc (bookworm-slim) base, keeping Python 3.14. On Alpine, scikit-learn has no musl wheel and compiled from source every build (dragging in build-base and pushing the build to ~an hour); every compiled dependency ships a manylinux 3.14 wheel, so on glibc the whole stack installs from wheels — build drops to a few minutes and the image no longer carries the compiler toolchain.

Build-only CI

  • New docker-build.yaml builds all three images on PRs / pushes that touch docker/** (amd64, push: false, per-variant layer cache). The publish workflow only builds on a release tag, so without this a broken dependency combination wouldn't surface until release.

Testing

  • Validated by the new CI build-only job rather than locally (the images pull the full scientific stack + torch).
  • The exact torch/torchvision/torchinfo pins (2.8.0 / 0.23.0 / 1.8.0) are provisional: confirm the CPU wheels resolve against the pinned numpy==2.5.4 / Pillow==13.0.0 via that CI build, and bump if newer is wanted.
  • Still open for review: whether to also publish the bare glibc base as an extension point for courses with custom deps.

Stacked on #64 (which is stacked on #63).

🤖 Generated with Claude Code

eliotwrobson and others added 7 commits November 25, 2026 18:45
Add Dockerfile.torch (a glibc base, since PyTorch has no musl wheels) with a CPU
build of torch, torchvision and torchinfo on top of the full scientific stack,
and publish it as the :torch tag. The image bakes in a 10s default sandbox
timeout (via PL_GRADER_SANDBOX_TIMEOUT) and single-threaded numeric defaults,
all overridable per question. Documents the image, the tensor assertion helpers,
and the dataset/determinism gotchas in torch.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Give the torch image its own fully pinned requirements file instead of
layering on requirements-full.txt. The torch image runs on a different
Python and libc than the full image and pins torch tightly to specific
numpy/Pillow versions, so it should pin its scientific stack on its own
terms rather than silently inheriting the full image's bumps.

Also fixes a latent bug: Dockerfile.torch copied requirements-torch.txt
but installed torch/torchvision/torchinfo by bare name, so the file was
never actually used. The whole set now installs from that one file, with
the PyTorch CPU index as the primary index so only CPU wheels are pulled.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
On the Alpine (musl) base, scikit-learn has no prebuilt wheel, so it
compiled from source on every build — pulling in the build-base toolchain
and pushing the image build to close to an hour. Every compiled dependency
(numpy, scipy, scikit-learn, pandas, matplotlib, Pillow) ships a manylinux
wheel for Python 3.14, so switching to the Debian slim base the torch image
already uses lets the whole stack install from wheels. No compiler is
needed, the build drops to a few minutes, and the image no longer carries
build-base.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The publish workflow only builds the images on a release tag, so a broken
dependency combination wouldn't surface until release. This builds all
three images on PRs and pushes that touch docker/**, amd64-only and without
pushing, with per-variant layer caching so unchanged images stay fast.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The publish and build-only workflows each carry their own copy of the image
matrix. Add a comment in each pointing at the other so a new image isn't
added to one and forgotten in the other.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Move the standalone torch.md into a PyTorch grading section of
quick_start.md, add the :torch row to the image table (which still listed
only two variants), and point the README there. A later PR will reorganize
these docs further.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@eliotwrobson
eliotwrobson marked this pull request as ready for review November 26, 2026 04:52
@eliotwrobson
eliotwrobson merged commit 5d47bdd into torch-grader-defaults Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant