Skip to content

ENH: Pool layers of any stride to the cells by regions - #17

Open
vboussot wants to merge 2 commits into
mainfrom
region-any-lattice
Open

vboussot wants to merge 2 commits into
mainfrom
region-any-lattice

Conversation

@vboussot

Copy link
Copy Markdown
Collaborator

The registration by regions found a layer's stride from one 65-voxel probe, which tells only powers of two apart, and refused layers coarser than the cells. A second probe (129 voxels) now identifies any stride up to 9 (power-of-two lattices read as before), regions align on the least common multiple of the strides, and the coarse stage pools a layer coarser than the cells as the whole run does. The fine stage refuses such a layer before reading any image: the whole run compares it at its own resolution, which by regions needs per-layer grids.

Regions against the whole run: strides 3 and 6, 0 mm (1.4e-6 masked); a stride-16 layer beside a full-resolution one, 2.4e-6 mm; fine stage, strides 3 and 6, 8.9e-8 mm. Every difference the region tests printed before is unchanged.

Also: Forward scales the gradient through a half-precision network on a graph (the fine stage's Jacobian mode underflowed: sampled step cosine 0.91 to float32 on a 96^3 toy pair, 0.9995 now; TS/M730 0.979 -> 0.9991), with a GPU contract test.

🤖 Generated with Claude Code

The region-sampled coarse and fine stages took a feature layer only on a
lattice of a power of two of the image's voxels, no coarser than the
cells, where the whole-image run pools any layer to them. A layer's
lattice is now told from two probes, of 65 and 129 voxels a side: a
power of two up to 64 as before, every other stride up to 9 besides.
The regions start on the least common multiple of the layers' strides
and reach a cell and two samples of the coarsest layer past a cell's
own voxels, which holds what adaptive pooling reads for a layer coarser
than the cells too.

The coarse stage now pools such a layer, and a voxel size coarser than
the cells, by regions as whole. The fine stage refuses a layer coarser
than its control cells, now before reading the images: its whole-image
run compares that layer at its own resolution, the field resized to
it, where the run by regions compares the cells.

ImpactToyModelLattice has layers of strides 3 (last sample partial), 6
and 16 (partial). By regions against whole, the coarse stage's dense
fields agree to 1.4e-6 mm with strides 3 and 6 on cells of 4 voxels and
to 2.4e-6 mm with stride 16 on cells of 2 beside a layer at the image's
resolution (alone, eight cells a side share its features and their
candidates tie, which round-off settles), masked or not; the fine
stage's to 8.9e-8 mm with strides 3 and 6 on cells of 8, on the
resident maps, by bricks and with every box drawn. The existing
contract tests print the same differences as before.
The fine stage's Jacobian mode differentiates its loss through the
moving model. In half precision the loss's derivative with respect to
each feature, a mean over many voxels, lay below float16's range, and
the network's backward pass rounded it to zero: on a 96-voxel pair with
the losses unnormalised, 42% of the sampled mode's first steps and 58%
of the dense mode's were zero, the sampled step 0.91 in cosine to the
single-precision one. The metric's online backward pass already scaled
its seed (5401592); the fine stage's paths did not.

Forward now brings its input to the model's precision itself. On the
graph of a single-precision input, a half-precision model's layers come
back in single precision; the first of their gradients to return sets a
power of two that brings its largest magnitude near one, every layer's
gradient enters the network scaled by it, and the input's is divided by
it in single precision. The callers that differentiate (the dense and
sampled Jacobian modes, the regions) hand it single-precision input.
Without a graph, and in single precision, nothing changes.

The sampled step's cosine is now 0.9995 and 1% of its steps are zero;
with TS/M730 on the same pair, 0.979 before and 0.9991 after. M730's
dense step stays 0.967, as when its loss is scaled by 1e4 before the
half backward: half precision's rounding through the network, not an
underflow.

This branch has not been deployed

No deployments
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