Skip to content

Run compiled CNNs in stages: saved nodes in compile_model, a run tool, and live runs of an EfficientNet-B3 U-Net - #52

Merged
noelEOS merged 7 commits into
mainfrom
raster/compiled-cnn-run
Nov 21, 2026
Merged

noelEOS merged 7 commits into
mainfrom
raster/compiled-cnn-run

Conversation

@noelEOS

@noelEOS noelEOS commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

A way to run a CNN that is too complex for one Earth Engine request as a sequence of exports, with the records of three live runs of SMP's EfficientNet-B3 U-Net (8 bands, 3 classes, one 256 × 256 chip): one request, refused as too complex; then the same model in six exports, with deterministic weights and with the released Fields of The World v3.1 weights, each within 1e-4 of float32 PyTorch.

No block, record, status, default, golden file or catalogue row changes, and no reader documentation.

  • The setting. compile_model(..., saved_nodes=None), keyword-only. It maps FX node names to images an earlier export saved for those nodes. A saved node's tensor is still built, for its grid and bands, and then replaced by the saved image, read exactly as the input is. Compiling the whole model with a saved node gives the same graph as compiling the model's tail alone from that image, which the tests assert byte for byte. The default emits today's graph. Refused: a name that is not a tensor operation of the traced graph, a node with no raster tensor, and a one-pixel tensor.
  • The tool, tools/compiled_cnn_run.py, for one chip of one model:
    • plan is offline and exact: the weight tables, every request with its size, hash and graph counts, every call with its cap, the limits and the outcomes.
    • upload exports the weights as tables and the input chip as an image, and verifies both.
    • run submits the model as one export, or as a staged run from a cut list (--cuts): export k compiles the whole model with every earlier saved node read from its image and exports node k; the last export is the logits. One submission per export, never repeated; resumable; a wall and a queue limit per task; an EECU budget checked before every submission; a required bound on the longest path of any export.
    • compare fetches the saved input and logits once each and compares the logits with float32 PyTorch at 1e-4.
    • report is offline.
  • Recipes. Two, of one architecture. One has deterministic weights (integer-hash values at each tensor's native initializer scale, then a fixed BatchNorm calibration: tools/fixtures/cnn_reference.py). The other reads the released Fields of The World v3.1 CC BY checkpoint from a resources checkout: the tool never fetches it, refuses a file whose SHA-256 is not the pinned one, and reads it with torch.load(..., weights_only=True) only.
  • Reuse. The table uploader and provider (tensor_ee.weight_assets), the export request, the call guard and the asset and operation checks (tensor_ee/converter/), and the limits and helpers of tools/raster_cost_run.py, all unmodified. compile_model stays the CNN path; the converter's planner is not involved.

Base revision: 18e9365 (main).

Changes by layer

  • Library: tensor_ee/compiler.py (saved_nodes; the input read and the saved-node read share one helper).
  • Tools: tools/compiled_cnn_run.py (new), tools/fixtures/cnn_reference.py (new).
  • Tests: tests/test_compile_saved_nodes.py (new), tests/test_compiled_cnn_run.py (new, against a fake client; zero cloud calls).
  • Evidence: docs/evidence/compiled-cnn-one-graph-live.json, docs/evidence/compiled-cnn-staged-live.json, docs/evidence/compiled-cnn-ftw-v31-staged-live.json (the tool's report output, unedited).

Checks on the head commit

Run locally on fcc3999 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.
  • Both gates on the three revisions that ran live (6e2d8fc, 862c3ae, e2a0af8): 45 of 45 and 19 of 19 each.
  • pytest -q: 4225 passed, 21 skipped. The two new files alone: 52 passed, 1 skipped (the released-checkpoint test, which reads the checkpoint only when a resources checkout is named).
  • Catalogue check: in sync.
  • compiled_cnn_run.py plan, one request with deterministic weights, and staged for both recipes: every request hash equals the one in the live record of that run (1 + 6 + 6 model requests, and the deterministic-weights input).
  • raster_cost_run.py plan --cases base,screen_size,long: its 16 request hashes equal those of docs/evidence/raster-gate-cost-live.json, so the shared input read leaves those compiled graphs as they were.
  • Without segmentation-models-pytorch (hidden behind an import blocker): the two new files give 49 passed, 4 skipped.
  • live_fixtures.py --offline and --plan: not run. No fixture or selection is added or changed.

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

Live runs

Each on one 256 × 256 chip of 8 bands (the fixtures' evaluation chip with deterministic weights; the same chip plus 0.5 with trained weights), clip_footprints=True, include_unfused_nodes=False, weights read from tables. The records carry neither the revision that ran nor the staged runs' limits: the one-request run was at 6e2d8fc, the staged run with deterministic weights at 862c3ae, the staged run with trained weights at e2a0af8, each on a clean tree.

One request: refused. 6,587,046 bytes, 7,503 invocations, longest invocation path 4,132. exportImage raised "Computation is too complex." at submission. It was not submitted again.

Six exports (cut list features: five saved nodes, then the logits; path bound 1,600):

Export Map Request bytes Longest path EECU-seconds, deterministic weights EECU-seconds, trained weights
1 128 × 128 × 40 17,624 45 3.33 3.90
2 64 × 64 × 32 341,148 692 27.40 25.01
3 32 × 32 × 48 680,233 456 29.31 29.28
4 16 × 16 × 136 2,274,042 1,486 101.16 100.13
5 8 × 8 × 384 4,290,722 1,191 181.78 170.19
6, logits 256 × 256 × 3 714,408 310 30.51 29.81
All six 373.5 358.3

Request bytes are those of the deterministic-weights run; the trained run's differ by a few hundred bytes. Limits of both staged runs, as prepared: budget 600 EECU-seconds, 900 s per task, 1,800 s in the queue. Six exportImage calls per run, none repeated, no cancel.

Logits against float32 PyTorch Largest absolute error Values over 1e-4 Largest reference Same class
Deterministic weights 9.94e-05 0 6.50 65,535 of 65,536 pixels
Trained weights 3.43e-05 0 35.69 65,536 of 65,536 pixels

In both runs the saved input equals the local chip bit for bit.

The trained run was resumed once: after export 4 was submitted a status read failed on the client, and the tool stopped without an outcome. The task itself had succeeded. Run again, the tool read export 4's operation without resubmitting it and went on. The bounded retry of status reads in this pull request was added after that.

What the runs show, and what they do not

  • Live agreement of the logits, on one chip. Not model accuracy: the chip is integer-generated numbers, not imagery. With the trained weights every pixel is class 0, in Earth Engine and in PyTorch alike, so that class match carries no weight.
  • 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 two smallest maps, exports 4 and 5, are about three quarters of it. Other chip sizes and other cut lists were not measured.
  • Why the single request was refused is not established. The path bound of 1,600 is a setting of these runs, not a limit of Earth Engine.
  • The cases have no NumPy mirror in the tool, so the comparison is with PyTorch only.

Limitations

  • One architecture, one chip size, one cut list, clip on. No other model, cut or clip_footprints=False has run in stages live.
  • No tiling. A staged run is one chip; a region is not addressed here.
  • Not exercised live: the retry of a failed status read; a wall or queue limit, so cancelOperation; a lost submission answer; a staged run without an adopted upload.
  • 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.
  • The deterministic-weights record's text line prints the class agreement as "1.0000"; its value is 0.9999847 (65,535 of 65,536). The tool has printed a count since e2a0af8.
  • Private helpers. The tool imports underscore-named helpers from tensor_ee/converter/run.py and tools/raster_cost_run.py; a change there can break it, which its tests would show.

Open questions

  • The wording of the setting's live coverage in compile_model's docstring ("Run live in two staged runs of one architecture … No saved stage image was itself compared …") is a proposal.
  • docs/api.md does not mention saved_nodes. A sentence next to clip_footprints would be the place.

@noelEOS
noelEOS merged commit 40b0e11 into main Nov 21, 2026
3 checks passed
@noelEOS
noelEOS deleted the raster/compiled-cnn-run branch November 21, 2026 02:31
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