Skip to content

Run checks that import TensorFlow on a Python 3.14 runtime - #53

Merged
rongxin-liu merged 4 commits into
mainfrom
tensorflow-runtime
Nov 25, 2026
Merged

rongxin-liu merged 4 commits into
mainfrom
tensorflow-runtime

Conversation

@rongxin-liu

@rongxin-liu rongxin-liu commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

check50 jobs whose checks import TensorFlow now run on a Python 3.14 runtime of their own, so cs50/cli's python3 no longer has to wait for TensorFlow to support a new Python before it can move. Every other job runs on cs50/cli's python3 as before, and that runtime no longer has TensorFlow installed at all.

This is the first half of the Python 3.15 move and is safe to merge on its own: main builds FROM cs50/cli:latest, still 3.14, so nothing about how a job runs changes beyond TensorFlow checks running on a 3.14.10 built here rather than in cs50/cli. The cs50/cli half (cs50/cli#256) waits on cs50/server, cs50/codespace, the EB apps, and recompiling the .pyc checks on cs50/problems@2022/python for 3.15.

Why the whole check50 process moves

It is not enough to swap the student's python3. The two TensorFlow checks (ai50/projects traffic and attention) import tensorflow in the check module itself and load student code into the check50 process with check50.py.import_. So docker-entry.sh prepends the runtime's bin to PATH before invoking check50, which switches check50, python3, and anything the checks spawn in one step.

Design decisions

  • CPython 3.14.10 built from source with cs50/cli's configure flags, installed with /opt/tensorflow as its prefix, so TensorFlow checks grade on the same interpreter students had on 3.14. Ubuntu's python3.14 package was considered and rejected: it stays at 3.14.4 for the life of the release with security backports only. The build adds ~4 min; bumping it is one ARG. One flag differs from cs50/cli: its --without-tests is not a CPython configure option (autoconf ignores it), so that build ships Lib/test and the _test* modules, ~116 MB. This runtime passes --disable-test-modules instead; cs50/cli should get the same fix.
  • The Python build sits above the requirements layers. Both runtimes are installed from one layer below it, so a pin bump, the most common change here, no longer rebuilds CPython from source, and editing check50-runtime no longer re-runs the TensorFlow import check.
  • Both runtimes get requirements.txt. Only requirements-tensorflow.txt differs. A student's traffic.py that also imports pandas behaves the same whichever runtime its job lands on, and a routing false positive is harmless. Cost: ~300 MB of duplicated non-TF packages; the image is 10.0 GB vs 10.2 GB for current latest, since the 2.1 GB TF stack moved rather than duplicated.
  • Routing by ast, not grep. check50-runtime scans the problem directory lib50 returns for imports of tensorflow, tf_keras, keras, or transformers. It catches import numpy, tensorflow as tf, from tensorflow.keras import …, and imports inside functions, and ignores comments and strings. A check it cannot parse routes to the default runtime and exits 0, so check50 reports the syntax error rather than docker-entry.sh's set -e ending the job first. It does not follow check50.import_checks("../other") into sibling directories; no ai50 check uses that.
  • Pins ready for 3.15. Because requirements.txt now has to install on both 3.14 and 3.15, numpy, pandas, scikit-learn, and Pillow move to the first versions with both cp314 and cp315 wheels (2.5.5, 3.0.6, 1.9.1, 12.3.0); no pandas 2.x has cp315. The CS50P shirt check byte-hashes the JPEG a student's Pillow writes, so the reference solution was run against the check's six inputs under Pillow 11.3.0, 12.3.0, and 13.0.0: all six hashes match on every version.

Against the real local clone of ai50/projects: traffic and attention route to 3.14; shopping, parser, nim stay on the default runtime.

Verification

Built for arm64 and ran tests/smoke.sh on the finished image (first commit); every check passed. The pin bump was then verified by building the Python layers FROM cs50/cli:latest (3.14) and FROM cs50/cli:canary (3.15) and running the smoke test's Python sections on each: both pass, with the TensorFlow runtime at 3.14.10 either way. CI here builds against canary, so the run on this PR is the real 3.15-base configuration.

The last commit (layer order, --disable-test-modules, smoke-test changes) has not been built locally. It was checked by bash -n, by running check50-runtime against every routing fixture, and by a dry run of tests/smoke.sh against a stub docker that confirmed each in-container script parses; the CI run on this push is its first full build.

New assertions, so a rebuild cannot quietly undo the split:

  • the default runtime cannot import tensorflow, tf_keras, keras, or transformers
  • each runtime satisfies its pin files at the pinned versions
  • check50-runtime routes five fixture check dirs correctly and exits 0 with no output on an unparsable one
  • check50 --dev on the 3.14 runtime grades a TensorFlow-using check against a TensorFlow-using traffic.py end to end, including a check50.run("python3 …") subprocess that must report (3, 14)
  • the Keras 3 / tf_keras / TFBertForMaskedLM assertions now run on the 3.14 runtime, at build time and in the smoke test
  • the 3.14 runtime is our build: sys.prefix is /opt/tensorflow, CONFIG_ARGS carries the optimization flags, libpython3.14 resolves from its prefix, and every stdlib extension module imports

The non-TensorFlow stack assertions (imports, nltk data, cv2, scikit-learn) are one shared snippet run on each runtime, so the two sections cannot drift apart.

Related: cs50/cli#254

TensorFlow trails new Python releases by about a year, and because this image
is FROM cs50/cli, it has been the reason cs50/cli could not move its python3
forward (cs50/cli#254). The TensorFlow stack now lives in a venv on Ubuntu
26.04's python3.14 at /opt/tensorflow, and docker-entry.sh routes a job there
when check50-runtime finds that its checks import tensorflow, tf_keras, keras,
or transformers. Every other job stays on cs50/cli's python3, which no longer
has TensorFlow installed at all.

The whole check50 process moves, not just the student's python3, because the
affected checks (ai50/projects traffic and attention) import tensorflow in the
check module and load student code in-process via check50.py.import_.

Both runtimes get requirements.txt so a check behaves the same on either; only
requirements-tensorflow.txt differs. The smoke test asserts the default
runtime cannot import TensorFlow, the routing picks the right checks, and
check50 grades a TensorFlow submission end to end on the 3.14 runtime.
…eels

requirements.txt is installed into both runtimes, and cs50/cli:canary is now
Python 3.15 (cs50/cli#256), so each pin needs cp314 and cp315 wheels. These
are the first versions of each that have both; no pandas 2.x has cp315.

Pillow's JPEG output decides whether a CS50P shirt submission passes (the check
byte-hashes the saved image), so the reference solution was run against the
check's six muppet inputs under Pillow 11.3.0, 12.3.0, and 13.0.0: all six
hashes match on every version.

Verified by building the Python layers FROM cs50/cli:latest (3.14) and
cs50/cli:canary (3.15) and running the smoke test's Python sections on each.
…'s flags

Ubuntu 26.04's python3.14 package stays at 3.14.4 for the life of the release
and backports security fixes only, so TensorFlow checks would have graded on
an interpreter behind the one students had on 3.14. The runtime is now
CPython 3.14.10 built with the same configure flags as cs50/cli, installed
with /opt/tensorflow as its prefix and an rpath so libpython resolves without
an ld.so.conf entry. Bumping it is one version string.

The smoke test asserts the runtime is this build (prefix, CONFIG_ARGS, and
libpython from /opt/tensorflow/lib) and that its stdlib extension modules
import, so a fallback to some other 3.14 cannot pass unnoticed.
… test suite

A pin bump in either requirements file no longer rebuilds CPython from
source: the build, which is the slowest layer, now sits above both COPYs,
and both runtimes are installed from one layer that also cleans up after
itself. The -dev packages join the first apt-get install, and
check50-runtime is copied in beside docker-entry.sh so editing it does not
re-run the TensorFlow import check.

cs50/cli's configure line passes --without-tests, which is not a CPython
option (autoconf ignores it), so the runtime was shipping Lib/test and the
_test* extension modules, ~116 MB. The flag is now --disable-test-modules,
and the version is one ARG.

The smoke test passes TF_PREFIX and TF into each container instead of
splicing them into quoted scripts, shares the non-TensorFlow stack
assertions between the two runtime sections so they cannot drift, and adds
an unparsable check to the routing fixtures: check50-runtime must still
exit 0 with no output, leaving the error for check50 to report, or
docker-entry.sh's set -e would kill the job first. check50-runtime's usage
line is a constant rather than a docstring index, and comments that
restated adjacent code are gone.
rongxin-liu added a commit to cs50/cli that referenced this pull request Nov 25, 2026
…test suite

configure has been warning "unrecognized options: --disable-static,
--without-tests" on every build. Neither is a CPython option. --disable-static
did nothing (a shared build installs no libpython.a), and --without-tests
quietly shipped Lib/test plus the _test* extension modules, 176 MB in the
3.15 image. --disable-test-modules is the real flag; PGO training still runs
from the source tree, and lib/python3.15 drops to 225 MB.

The smoke test asserts Lib/test and _testcapi are absent so a return to the
no-op flag cannot pass. (Spotted by rongxin-liu while reviewing cs50/check#53.)
@rongxin-liu
rongxin-liu merged commit 097852c into main Nov 25, 2026
1 check passed
@rongxin-liu
rongxin-liu deleted the tensorflow-runtime branch November 25, 2026 20:37
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