Skip to content

refactor: the registry builds the pipelines; delete the four if ladders - #70

Open
Hendrik-code wants to merge 1 commit into
hm/config-schemafrom
hm/registry-builder
Open

refactor: the registry builds the pipelines; delete the four if ladders#70
Hendrik-code wants to merge 1 commit into
hm/config-schemafrom
hm/registry-builder

Conversation

@Hendrik-code

Copy link
Copy Markdown
Collaborator

Stacked on #69. The largest PR in the stack, and the one that breaks configs.

The four if ladders go

smauglab/transforms/build.py does the dispatch once, for all three GPU pipeline modes and the CPU one:

file before after
gpu/transforms.py 714 31
gpu/transforms_list.py (two ladders) 974 117
cpu/transforms.py 412 80

Which class a config key maps to, which parameters it accepts, and where it sits in the pipeline all come from the registry now, so the four copies cannot drift again. The temporary aliases #66 left in contrast.py go with them.

Configs move to the new format in the same commit

The ladders and the old key names are the same thing, so they can't be separated. All 29 shipped configs were rewritten by migration/migrate.py, not by hand, and the originals are kept verbatim in unit_tests/fixtures/legacy_configs/ so the migrator has something to be tested against.

$ smauglab migrate --in-place smauglab/configs/*.json
smauglab/configs/transform_params.json -> smauglab/configs/transform_params.json
    pushed top-level retain_stats=True into the blocks that read it
    ConvTransform(kernel_type='Laplace') -> LaplaceConvTransform
    expanded FunctionTransform into 5 blocks
    moved mirror_axes -> CPU.MirrorTransform.allowed_axes

⚠️ This breaks every config file outside the repo. migration/ is how you bring one forward, and the error messages point at it.

How I know it changed nothing

Not asserted — checked. unit_tests/fixtures/legacy_effective_kwargs.json records the class and effective constructor kwargs of every transform the ladders built, for every config and both GPU modes. It was captured from the commit before they were deleted, by instrumenting each __init__. unit_tests/test_builder.py rebuilds each of those pipelines through the registry and compares.

All 27 match.

Three differences are normalised away, and the test file says why:

  • the ladders built one class parameterised by kernel_type/func/invert_image; the builder builds the leaf;
  • that shared class therefore bound kernel-specific parameters its leaves don't declare — a Scharr transform carried sigma, which only the blur reads;
  • p_batch is new and defaults to kornia's own 1.0 either way.

The 21 pipelines with no "before"

Of 48 config×mode combinations, only 27 could be compared. The other 21 crashed in the old ladder:

choose_x_params = self.transform_params.get("RandomChooseXTransforms")
... choose_x_params.get("probability", 1.0)      # AttributeError when the block is absent

That's 21 of 29 configs — AugTransformsGPURandomOrder was unusable for all of them. They build now, because config.pipeline_options() always returns a dict. That's a fix, not a regression, but it does mean those configs have no baseline to check against.

Also

  • pipeline.order is wired through build_transforms: registry order by default, config key order when a config asks for it. Tested both ways.
  • .gitignore's repo-wide *.json would have swallowed the fixtures and the migration table, so each gets an explicit un-ignore.

Testing

unit_tests/test_builder.py (9 tests / 27 subtests) plus the existing suite: 172 passed, 5 skipped, 503 subtests. ruff and mypy clean.

smauglab/transforms/build.py does the dispatch once, for all three GPU pipeline
modes and for the CPU one. The ladders it replaces go:

  gpu/transforms.py        714 ->  31 lines
  gpu/transforms_list.py   974 -> 117 lines   (two ladders in one file)
  cpu/transforms.py        412 ->  80 lines

Which class a config key maps to, which parameters it accepts, and where it sits
in the pipeline all come from the registry now, so the four copies cannot drift
again. The temporary aliases the previous commits left in contrast.py go with
them.

Configs move to the sectioned, class-name-keyed format in the same commit,
because the ladders and the old key names are the same thing. All 29 shipped
configs were rewritten by migration/migrate.py rather than by hand; the originals
are kept verbatim as unit_tests/fixtures/legacy_configs/ so the migrator has
something to be tested against.

That this changed nothing is checked, not asserted.
unit_tests/fixtures/legacy_effective_kwargs.json records the class and effective
constructor kwargs of every transform the ladders built, for every config and
both GPU modes, captured from the commit before they were deleted by
instrumenting each __init__. unit_tests/test_builder.py rebuilds each of those
pipelines through the registry and compares. All 27 match.

Three differences are normalised away, and the test says why: the ladders built
one class parameterised by kernel_type/func/invert_image where the builder builds
the leaf; that shared class therefore bound kernel-specific parameters its leaves
do not declare (a Scharr transform carried `sigma`, which only the blur reads);
and p_batch is new and defaults to kornia's own 1.0 either way.

The remaining 21 of the 48 pipelines could not be compared because the ladder
crashed on them: AugTransformsGPURandomOrder did
config.get("RandomChooseXTransforms").get(...), which is an AttributeError for
every config that omits that block -- 21 of 29. They build now. That is a fix,
not a regression, but it does mean those configs have no "before" to check
against.

pipeline.order is wired through build_transforms: registry order by default,
config key order when a config asks for it.

.gitignore's repo-wide *.json would have swallowed the fixtures and the migration
table, so each gets an explicit un-ignore.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 21, 2026 06:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants