Skip to content

Re-land the torch grader image and sandbox-timeout defaults - #66

Merged
eliotwrobson merged 12 commits into
mainfrom
reland-torch-image
Nov 26, 2026
Merged

eliotwrobson merged 12 commits into
mainfrom
reland-torch-image

Conversation

@eliotwrobson

Copy link
Copy Markdown
Collaborator

Summary

Re-lands the work from #64 and #65, which were stacked PRs that merged into their intermediate base branches instead of main — so although both show as merged, their changes never reached main (only #63 did). This brings them in as a single PR against the current main; the merge is conflict-free and the diff is exactly that stranded work (no #63 changes, which are already on main).

What lands here:

  • Overridable default sandbox timeout (Let grader images set a default sandbox timeout #64). sandbox_timeout defaults to None and resolves from the PL_GRADER_SANDBOX_TIMEOUT environment variable (falling back to 1s), so a grader image can set a sensible default that a question's ConfigObject/marker still overrides.
  • Torch grader image (Add a torch grader image with sensible baked-in defaults #65). docker/Dockerfile.torch on a glibc base, a self-contained fully-pinned requirements-torch.txt, a CPU-only torch/torchvision/torchinfo install, and baked-in overridable defaults (PL_GRADER_SANDBOX_TIMEOUT=10, single-threaded OMP/MKL). Published as :torch via a new publish.yaml matrix entry.
  • Full image on a glibc base. Moves the full image off Alpine so its scientific stack installs from prebuilt wheels (scikit-learn has no musl wheel and was compiling from source, pushing the build to ~an hour); the build drops to a few minutes and the image no longer carries build-base.
  • Build-only CI (docker-build.yaml). Builds all three images on PRs/pushes touching docker/** (amd64, no push, per-variant cache), so a broken dependency combination surfaces before release rather than at tag time.
  • Docs. The torch guidance lives in a PyTorch grading section of quick_start.md (the image table now lists :torch); README points there.

After this merges, a new release tag will build and push the :torch image (and rebuild full/lite from the glibc switch) — the current v1.4.2 release predates this work and only published full/lite.

Testing

  • Verified the full stack builds, lint/format/mypy, and uv lock --check pass locally on Python 3.13; torch tests skip when torch isn't installed.
  • The torch and full images themselves are validated by the new docker-build CI job on this PR (they aren't built locally).
  • The exact torch pins (2.8.0 / 0.23.0 / 1.8.0) are provisional pending that build's confirmation against the pinned numpy==2.5.4 / Pillow==13.0.0.

🤖 Generated with Claude Code

eliotwrobson and others added 12 commits November 25, 2026 18:37
Serialize torch.Tensor values across the sandbox (detached, on CPU) in
json_utils, and add assert_tensor_allclose / assert_tensor_equal with
student-friendly failure messages. torch is a lazy, optional import so the
lite and full images are unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ConfigObject.sandbox_timeout now defaults to None, meaning 'use the image/global
default'. The plugin resolves an unset timeout from the PL_GRADER_SANDBOX_TIMEOUT
environment variable (falling back to 1.0s), so an image can bake in a more
sensible default while questions keep full control by setting an explicit value.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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>
Gate the torch dev dependency below Python 3.14 (no wheels yet) so the lock
resolves and the 3.14 job skips the torch tests, and guard the test's torch
typing behind TYPE_CHECKING so mypy resolves torch.Tensor.

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>
#64 and #65 were merged into their stacked base branches rather than main,
so their changes never reached main. This brings them in: the overridable
sandbox-timeout default (#64), the torch grader image, the glibc base for
the full image, the build-only CI workflow, and the docs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@eliotwrobson
eliotwrobson marked this pull request as ready for review November 26, 2026 05:03
@eliotwrobson
eliotwrobson merged commit fe19283 into main Nov 26, 2026
8 checks passed
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