perf(triangles): step-0 Point containment without the (N,3,2) gather (#579) - #580
Merged
Merged
Conversation
Private switch _STEP0_CONTAINMENT (gather | nopad | components | structured), Step0Layout / static_lattice_layout (cached, int-only, pytree aux), plumbed via CoordinateArrayTriangles.for_limits_and_scale(static_vertices=True) -> with_vertices -> ArrayTriangles.containing_indices. Refinement lattices keep the general path. No tests yet; not measured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uards (#579) - Fuzz every step-0 route against the gather path under jit + vmap with a traced vertex table: ~5.7e4 points per route by default (every vertex, edge midpoints, centroids, random) over five geometries -- the solver lattice, the same lattice SIS-deflected, alternating key-row widths 14/15, widths 10/11 with a padded grid, and an even row count at scale 0.13. PYAUTO_STEP0_FUZZ_SCALE=4 gives ~1.5e5 points per route. The routed mask is compared to 64 entries, past MAX_CONTAINING_SIZE truncation. - Refinement path unchanged: derived lattices drop the layout and every route matches gather through kept -> neighbourhood -> up-sample. - HLO guard: no gather of the (23 283, 3, 2) triangle array in the default route's optimised HLO (vertices traced). Red on main 14d6336 and on the gather / nopad routes. - Fix: only an exact `Point` takes the step-0 route. Circle, Triangle, Polygon and Square subclass Point but override mask; isinstance sent them through Point containment on the static lattice (caught by the refinement test). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
Workspace PR: PyAutoLabs/autolens_profiling#330 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The JAX
PointSolvernow tests step-0 containment on the static initial lattice without building the(N, 3, 2)triangle array. That gather was the largest single cost of the single-source point likelihood: about 0.9 ms of ~2.1 ms on RAL CPU in phase 4a. This is phase 4b of the point-source CPU speed-up (#579). The solver geometry and the defaults are unchanged. The kept triangle set, and so every result, is bit-identical.static_lattice_layout(lru-cached, ints only) derives the closed-form layout ofstatic_vertex_table's index map, checks it element by element against the real map, and falls back (grid=None) if any parity class breaks the strided pattern.ArrayTriangles.containing_indicessends an exactPoint(not theCircle/Triangle/Polygon/Squaresubclasses, which overridemask) through_step0_point_maskwhen the triangles carry aStep0Layout. That only happens on the step-0 lattice fromfor_limits_and_scale(static_vertices=True)→with_vertices; derived lattices (for_indexes,up_sample,neighborhood) drop it, so refinement is untouched.array._STEP0_CONTAINMENTselects the route:gather(the old path),nopad,components(six 1-D gathers) orstructured(the default: strided slices of the traced vertex table, with no gather at all). It is read at trace time and exists for the profiling A/B.API Changes
None — internal changes only. The new
step0_layout=Nonekeyword onArrayTriangles/CoordinateArrayTrianglesis optional and set internally.Step0Layoutandstatic_lattice_layoutare new internal helpers.See full details below.
Test Plan
test_autoarray/structures/triangles/test_coordinate_jax.py: 54 passed.gatherunder jit + vmap over 5 geometries, including alternating key-row widths, a padded grid and an SIS-deflected lattice. It uses about 5.7e4 points per route;PYAUTO_STEP0_FUZZ_SCALE=4gives about 1.5e5 and passed.Circle.gather/nopadroutes, and passes oncomponents/structured.test_static_lattice_jax.py, including the step-0 vertex tie test, passes 16/16 on all four routes.solver_config_sweep.py --step0-route; 20 rounds × 20 calls; bootstrap 90 % CI). Every route is bit-identical in log L (fiducial7.743201200876812), positions, image counts, grad (withregister_model, non-zero) and vmap 1/4/16. Completeness is 200/200 prior and 200/200 stress.Step-0 containment falls by 66 %. Compile time is +3–5 %.
structureduses 47 % less temporary memory. The quotable Xeon 8490H row (job 357321, queued on a saturatedralpartition) will land with the autolens_profiling data PR.Full API Changes (for automation & release notes)
Added
autoarray.structures.triangles.array.Step0Layout(n_rows, n_cols, grid=None): frozen dataclass (internal)autoarray.structures.triangles.coordinate_array.static_lattice_layout(y_min, y_max, x_min, x_max, scale): lru-cached (internal)ArrayTriangles(..., step0_layout=None),CoordinateArrayTriangles(..., step0_layout=None): optional keyword, set internallyChanged Behaviour
ArrayTriangles.containing_indices(Point)on the static step-0 lattice now uses strided slicing instead of the(N, 3, 2)gather. The output is bit-identical.Part of #579 (library half; the profiling data PR follows).
Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code