Skip to content

Add global average pooling and multiply to the raster lane, validated live - #48

Merged
noelEOS merged 4 commits into
mainfrom
raster/global-pool-multiply
Nov 12, 2026
Merged

noelEOS merged 4 commits into
mainfrom
raster/global-pool-multiply

Conversation

@noelEOS

@noelEOS noelEOS commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Two new raster blocks, the parts of a squeeze-and-excitation gate the CNN path lacked, with their recognition in compile_model. Both were validated live in this pull request.

  • global_avg_pool2d (EXTENT, float32_operands): PyTorch's adaptive_avg_pool2d(x, 1), the mean of an H × W map, as a [N, C, 1, 1] tensor on a one-pixel grid that covers exactly the map (core.grid.one_pixel). It is pool2d's aligned expression with the map's size as the kernel, through one shared private helper (_aligned_reduce).
  • multiply (POINTWISE, float32_operands): x * other for an operand on x's grid, or for a one-pixel gate on one_pixel(x.grid), with equal channel counts. Channel broadcasts, scalars, other grids and other channel counts are refused.
  • Compiler. compile_model recognizes nn.AdaptiveAvgPool2d(1), F.adaptive_avg_pool2d(x, 1), torch.mean/Tensor.mean over (2, 3) with keepdim=True, and *, torch.mul, Tensor.mul in either operand order. 1 × 1 convolutions and pointwise activations run on the one-pixel grid unchanged.
  • Tiling. A global mean depends on the whole compiled grid. analyze_receptive_field lists it in extent_nodes and refuses a halo, tiled compilation refuses the model, and the compatibility report adds one restriction when a global mean is present. Equality with PyTorch is per compiled grid.
  • Fixture harness. Fixture.raster_side lets one fixture raise its own request grid to at most 128 × 128; only raster/global_avg_pool2d/h128-w128 uses it.

No existing block, default, cast or status changes. pool2d emits the same graph through the shared helper, which G1 shows.

Base revision: 5c170c36 (main).

Changes by layer

  • Core: tensor_ee/core/grid.py (one_pixel).
  • Raster blocks: blocks/raster/pooling.py (_aligned_reduce, global_avg_pool2d), blocks/raster/merge.py (multiply), blocks/raster/__init__.py.
  • Compiler and analysis: semantics.py, compiler.py, receptive_field.py, compatibility.py.
  • Fixtures and harness: tools/fixtures/core.py, tools/fixtures/raster.py (selection global_pool_multiply, seven fixtures, integer-generated inputs and weights), tools/live_fixtures.py.
  • Tests: tests/test_raster_global_pool_multiply.py (new), tests/reference/raster_gate.py (new mirror), tests/reference/activations.py, tests/reference/__init__.py, tests/test_live_fixtures.py, tests/test_raster_blocks.py, tests/test_receptive_field.py, tests/test_x02b_validated_settings.py.
  • Docs and evidence: README.md (90 blocks), docs/api.md, docs/library-contract.md, docs/live-fixtures.md, docs/building-blocks.md (regenerated), docs/evidence/raster-global-pool-multiply-offline.json, docs/evidence/live-fixtures/20261112T151417Z-global_pool_multiply.json.

Checks on the head commit

Run locally on c000725 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 at the base: 45 of 45 and 19 of 19, run on 5c170c36 before the first edit.
  • pytest -q: 3778 passed, 20 skipped.
  • Catalogue check: in sync.
  • --offline global_pool_multiply: 7 fixtures passed, zero cloud calls.
  • --plan global_pool_multiply: 13 requests, largest 49,152 values and 374,955 bytes, 0 assets, 0 tasks, within budget.
  • Existing raster selections: the --plan graphs and totals of calibration, p02, hard_activations, batch_norm, bilinear, grouped_conv and standardize are identical at the base and at 4b30c592.

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

Largest absolute error per fixture (tolerance 1e-4). The three columns are separate claims:

Fixture Offline: mirror vs float32 PyTorch Live: Earth Engine vs mirror Live: Earth Engine vs float32 PyTorch
raster/global_avg_pool2d/h5-w7 0 0 0
raster/global_avg_pool2d/h8-w8 2.38e-07 0 2.38e-07
raster/global_avg_pool2d/h64-w64 2.38e-07 0 2.38e-07
raster/global_avg_pool2d/h128-w128 0 0 0
raster/multiply/same-grid-h5-w7 0 0 0
raster/multiply/gate-h5-w7 0 0 0
raster/multiply/squeeze-excitation-h12-w20 out 0; pooled 1.19e-07; gate 0 0 on all three out 0; pooled 1.19e-07; gate 0

Live run

The selection global_pool_multiply ran once on the clean revision 4b30c592: 7 fixtures, 13 requests (the planned count), 0 assets, 0 tasks, no refused calls, 14.9 s. Every fixture passed. The record is committed unedited. The head commit's 13 planned graph hashes are identical to that revision's, so the record describes the graphs this pull request ships.

An earlier attempt of the same selection stopped in initialization on a credentials error before any request was sent. It says nothing about the blocks and its record is not committed.

Both blocks are promoted to Ready at what ran:

  • global_avg_pool2d: "Ready — maps 5 × 7, 8 × 8, 12 × 20, 64 × 64 and 128 × 128".
  • multiply: "Ready — same grid on a 5 × 7 map; one-pixel gate on 5 × 7 and 12 × 20 maps".

The map's size is the input's grid and not a parameter of either block, so the validated records hold only clip_footprints False and the statuses name the maps.

Limitations

  • Map size. reduceResolution accepted maxPixels 16,900 on the 128 × 128 map. A larger map needs a larger maxPixels and has not run.
  • Accumulation order. The pool fixtures' inputs have sums that are exact in every order, so the runs do not establish the order or type in which Earth Engine accumulates the mean.
  • Block claims only. No whole model with squeeze-and-excitation has been compiled or run. This pull request adds no cost measurement for a chain of gates and no model-accuracy claim.
  • Not recognized here. SMP's native EfficientNet still stops earlier, at its static same-padding convolutions and functional conv2d; its 26 pools and 26 products are no longer what refuses it.
  • Per chip. A model with a global mean equals PyTorch per compiled grid. A region is a mosaic of chips; no halo makes a tile equal a larger area.

…lane

Two raster blocks, Fixed — offline only: global_avg_pool2d, the mean of the whole map onto
its one-pixel grid through the private helper pool2d's aligned branch now uses
(byte-identical), and multiply, a same-grid product or a one-pixel gate pooled from the map.
compile_model recognizes AdaptiveAvgPool2d / F.adaptive_avg_pool2d to size 1, mean over
(2, 3) with keepdim=True, and *, torch.mul and Tensor.mul in either operand order. The
receptive-field analysis lists a global mean in extent_nodes and refuses every halo, so
tiled compilation refuses the model. Mirrors, integer-generated fixtures (one on a 128 x 128
map, by a per-fixture request-grid allowance), tests and the catalogue.
tools/live_fixtures.py --offline global_pool_multiply on the previous commit (clean tree):
7 fixtures passed, zero cloud calls; largest mirror-vs-PyTorch error 2.38e-07. The
catalogue now resolves the blocks' evidence.
x = a*col + b*row + c, so a pixel spanning the whole map takes b times the height and d times
the width. Grid refuses any shear, so both terms are zero and no graph changes.
The global_pool_multiply selection ran live once: 7 fixtures, 13 requests, all passed.
Earth Engine equals the NumPy mirror in every value; against float32 PyTorch the largest
absolute error is 2.38e-07 (the pooled mean) and 0 for the product. reduceResolution
accepted maxPixels 16,900 on the 128 x 128 map.

Both statuses name the maps that ran, since the map's size is the input's grid and not a
parameter; the validated records hold clip_footprints False. Larger maps and Earth
Engine's accumulation order remain unvalidated.
@noelEOS
noelEOS enabled auto-merge (squash) November 12, 2026 15:31
@noelEOS
noelEOS merged commit 98ad27c into main Nov 12, 2026
3 checks passed
@noelEOS
noelEOS deleted the raster/global-pool-multiply branch November 12, 2026 15:59
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