Skip to content

Run a compiled CNN on pinned Sentinel-2 images, with a float64 check for final outputs where float32 PyTorch is itself outside 1e-4 - #53

Merged
noelEOS merged 3 commits into
mainfrom
raster/compiled-cnn-imagery
Nov 21, 2026
Merged

noelEOS merged 3 commits into
mainfrom
raster/compiled-cnn-imagery

Conversation

@noelEOS

@noelEOS noelEOS commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Two things: a rule for a model's final output where float32 PyTorch cannot serve as the 1e-4 reference, and an input read from catalogue images in the compiled-CNN run tool, with the record of one live run of the released Fields of The World v3.1 U-Net on a real Sentinel-2 chip.

No block, record, status, default, golden file or catalogue row changes.

The rule change (CONTRIBUTING.md, AGENTS.md)

The 1e-4 target against float32 PyTorch stays for block fixtures and for a model's final outputs. One case is added, by the maintainer's decision:

  • A final output on which float32 PyTorch is itself more than 1e-4 from float64 PyTorch (the same model and float32 weights, model.double()) is checked as an intermediate output already is: its largest absolute error against float64 must be no larger than float32 PyTorch's own.
  • Why. There, 1e-4 against float32 tests whether the output reproduces the reference's own rounding.
  • Which check applies is decided by the two PyTorch runs alone, never by the output under test, and the record names it. It is not "pass if either holds".
  • Block fixtures are never checked this way.

On the chip of this pull request float32 and float64 PyTorch differ by 1.83e-04 (63 of 196,608 values over 1e-4), so this check decided the run. The rule and the tool's comparison were committed, and the gates run, before the model exports were submitted and before any logit was fetched.

The tool (tools/compiled_cnn_run.py)

  • An imagery input. A recipe may declare how its input is read from catalogue images (Recipe.imagery: collection, bands per image, image count, divisor). The image IDs and the chip's grid are run arguments (--images, --crs, --origin, --pixel-size, all four together). The trained recipe declares its release's convention: two COPERNICUS/S2_SR_HARMONIZED images, B4, B3, B2, B8 of each, divided by 3000.
  • discover: one computeValue per call, no task or asset. It lists a day's images whose footprint contains the chip, with tile, cloud percentage, processing baseline and whether the chip's pixels are pixels of the band.
  • The input export: the pinned bands, divided and cast to float32 last. The plan refuses a request that does not declare float32. Nothing is filled or resampled.
  • check-input: one computePixels of the saved input with a validity band. run submits no model export without its record, or with a masked pixel, or with a fetch that is not finite float32 of the chip's shape.
  • compare: computes float32 and float64 PyTorch, chooses the check from them (judged), and records the check, the three largest absolute errors, the counts over 1e-4, the float32 step at the largest reference, and the class agreement against both. On imagery the references are computed on the array check-input kept. A record from before this change prints as it did.
  • map: offline, the images in true colour next to the predicted classes.
  • A fix to the upload. A refused input export is no longer skipped on a second upload and the upload marked verified (_Command.input_image is shared by both paths).
  • tools/prithvi_real_input.py: day_images factored out of discover_expression for reuse; its expression is unchanged.

Base revision: 40b0e11 (main).

Changes by layer

  • Library: none.
  • Tools: tools/compiled_cnn_run.py, tools/prithvi_real_input.py.
  • Tests: tests/test_compiled_cnn_run.py (against fake clients; zero cloud calls).
  • Documents: CONTRIBUTING.md ("Numerical comparisons", one item), AGENTS.md ("Numerical claims", two sentences).
  • Evidence: docs/evidence/compiled-cnn-ftw-v31-sentinel2-live.json (the tool's report output, unedited) and the two discover outputs, docs/evidence/compiled-cnn-ftw-v31-sentinel2-discover-2021-06-17.json and …-2021-09-25.json.

Checks on the head commit

Run locally on 198da8f with a clean tree (Python 3.14, all extras, trained checkpoints present):

  • G1: 45 of 45 graphs equal (9 trained, 36 fixtures, none skipped).
  • G1-ext: 19 of 19 graphs equal.
  • pytest -q: 4262 passed, 21 skipped.
  • Catalogue check: in sync.
  • compiled_cnn_run.py plan, for the four selections that ran live earlier (one request and staged, both recipes): byte-identical to the base revision's, in JSON and in text.
  • report on the four run directories: the one-request record, the trained record and this pull request's record come out byte-identical to the committed files. The deterministic-weights record differs only in the class-agreement text that Run compiled CNNs in stages: saved nodes in compile_model, a run tool, and live runs of an EfficientNet-B3 U-Net #52 already noted.
  • Without segmentation-models-pytorch (hidden behind an import blocker) and without a resources checkout: tests/test_compiled_cnn_run.py and tests/test_compile_saved_nodes.py together give 86 passed, 4 skipped.
  • live_fixtures.py --offline and --plan: not run. No fixture or selection is added or changed, so there is no mirror-against-PyTorch figure to report.

Not reproduced locally: the hosted jobs on Python 3.11 and 3.12 without extras.

The live run

One 256 × 256 chip at 10 m (EPSG:32633, upper-left corner 361120, 5335910) of Sentinel-2 tile 33UUP, from the acquisitions of 17 June and 25 September 2021. Each lookup returned exactly one image, with the chip on the image's own pixels and cloud cover of 0.22% and 0.0004% of the tile. The run was at 5c29e8e on a clean tree (the record carries no revision), staged with the features cut list and a path bound of 1,600, and read the weight tables of the earlier trained run. Limits as prepared: budget 600 EECU-seconds, 900 s per task, 1,800 s in the queue.

Export Map EECU-seconds
Input 256 × 256 × 8 0.60
1 128 × 128 × 40 3.36
2 64 × 64 × 32 37.85
3 32 × 32 × 48 34.30
4 16 × 16 × 136 106.61
5 8 × 8 × 384 151.01
6, logits 256 × 256 × 3 56.16
The six model exports 389.3

Six exportImage calls for the model, none repeated, no cancel. The fetched input was float32 and finite with no masked pixel.

Logits, largest absolute error Value Values over 1e-4
Earth Engine against float64 PyTorch 7.80e-05 0
float32 PyTorch against float64 PyTorch 1.83e-04 63
Earth Engine against float32 PyTorch 1.68e-04 59
  • The check that applied: the float64 one, passed (7.80e-05 is no larger than 1.83e-04).
  • Scale: largest reference 59.29, where the float32 step is 3.81e-06.
  • Classes: the same class as float32 PyTorch and as float64 PyTorch on 65,536 of 65,536 pixels: 36,026 background, 17,932 field, 11,578 boundary.

What the run shows, and what it does not

  • Live agreement of the logits, on one real chip, by the float64 check. Against float32 PyTorch at 1e-4 the same logits would not pass, and the record says so.
  • Not model accuracy. No label was compared. That the model outlines fields on this chip is its PyTorch behaviour, reproduced.
  • Only the final logits were compared. No saved stage image was compared with a reference.
  • The cost is of this chip and this cut list. The logits export cost 56.2 EECU-seconds here against 29.8 on the numerical chip; one measurement each, not explained.

Limitations

  • One chip, one pair of scenes, one cut list. No tiling: a region is not addressed here.
  • Not exercised live: a one-graph imagery run, a source image with a masked pixel, and a chip off the images' pixel grid. On another grid Earth Engine resamples by nearest neighbour and nothing in the tool detects it; discover reports each image's grid for that reason.
  • Earth Engine holds the 2023 reprocessing of these acquisitions (processing baseline 05.00), so its pixels need not equal those of another archive's copy of the same scenes.
  • The float64 reference costs a second forward pass in compare, in float64, on the CPU.
  • The trained recipe needs the checkpoint. Without it the recipe is unavailable and its test skips by name; the hosted jobs do not have it.

Open questions

  • docs/vit-b16-dpt224.md and the other model pages state "1e-4 against float32 PyTorch" for final outputs without the new case. They stay true for the outputs they describe; whether to add a pointer is left open.
  • compile_model's docstring still lists two staged live runs of saved_nodes; this run is a third, on the same architecture and cut list. Not edited here.

…p, input check before any model export, compare on the fetched input, an offline map

A recipe may declare an imagery input convention (collection, bands per image, number of
images, divisor); the trained Fields of The World recipe declares its release's. The image
IDs and the chip's grid are run arguments. With them: discover lists a day's images in one
request; the input image is exported from the pinned images, cast to float32 last, nothing
filled; check-input fetches it once with a validity band and records what it is; run submits
no model export without that record, or with a masked pixel; compare's reference is PyTorch
on the fetched array; map draws the images and the predicted classes offline. A staged run
with an imagery input adopts only the tables of an earlier upload and saves its own input.
Without image arguments every request and plan is unchanged.

The input export is one implementation for the numerical chip and for imagery; a refused
input export is no longer passed over when upload is run again.
…Torch is itself more than 1e-4 from it

The compiled-CNN run tool's compare computes both references, chooses the check from them alone
and records it with all three largest absolute errors.
…ups, the input and six exports, the logits judged against float64 PyTorch
@noelEOS
noelEOS enabled auto-merge (squash) November 21, 2026 02:54
@noelEOS
noelEOS merged commit d7e9214 into main Nov 21, 2026
3 checks passed
@noelEOS
noelEOS deleted the raster/compiled-cnn-imagery branch November 21, 2026 03:20
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