Skip to content

Re-join optimizer hyperparameters to param groups by key on reconnect#19

Closed
cedriclim1 wants to merge 1 commit into
feat/tomography-inr-fixesfrom
fix/optimizer-reconnect-by-name
Closed

Re-join optimizer hyperparameters to param groups by key on reconnect#19
cedriclim1 wants to merge 1 commit into
feat/tomography-inr-fixesfrom
fix/optimizer-reconnect-by-name

Conversation

@cedriclim1

Copy link
Copy Markdown
Owner

Problem

reconnect_optimizer_to_parameters (used after device moves / AutoSerialize loads; called from the tomography object and dataset models) restored per-group hyperparameters by zip-index against a fresh get_optimization_parameters() call. Nothing makes that dict's order or membership contractual — the dataset model's groups change with alignment settings — so any difference between creation time and reconnect time silently attaches the wrong learning rate to every group. No error is raised; a PPLR reconstruction just trains with swapped lrs (e.g. grids at 1e-3 and sigma_net at 1e-2).

This was flagged as a design fragility in the loop's first sweep; it is reproducible, so it gets a fix rather than a note.

Fix

  • set_optimizer records each group's key in the torch param group as "name" (torch preserves unknown keys in param groups and state_dicts).
  • reconnect_optimizer_to_parameters re-joins old hyperparameters to new groups by that key; a group with no old counterpart keeps optimizer defaults.
  • Optimizers restored from checkpoints predating group names (no "name" present) fall back to the previous index alignment, so old checkpoints behave exactly as before.

Evidence

  • New TestReconnectHyperparamAlignment (5 tests): group reorder keeps each lr with its key (failed before — lrs swapped silently), added group gets defaults while others keep lrs (failed before), Adam state survives reconnect, legacy no-name fallback, names recorded at creation.
  • Full suite uv run pytest tests --runslow: 434 passed, 1 skipped; only the pre-existing unrelated ptychography failure.
  • ruff check / format clean on touched files.

Independent branch off the integration tip; no overlap with the other open PRs.

reconnect_optimizer_to_parameters restored per-group hyperparameters by
zip-index against a fresh get_optimization_parameters() call. Group order
and membership from that dict are not contractual (the dataset model's
groups change with alignment settings), so any difference between creation
time and reconnect time silently attached the wrong learning rate to every
group -- no error, just a reconstruction quietly training with swapped lrs.

set_optimizer now records each group's key in the torch param group under
"name" (torch preserves unknown keys), and reconnect re-joins
hyperparameters by that key; groups with no old counterpart keep optimizer
defaults. Optimizers restored from checkpoints predating group names fall
back to the previous index alignment. Regression tests cover reorder,
group addition, state survival, and the legacy fallback.
@cedriclim1

Copy link
Copy Markdown
Owner Author

Merged into #21 as e661f56 (full merge). Real fix — reconnect restored hyperparameters by zip position, so reordered groups could swap learning rates. Note: on the benchmark stack this measurably changed (improved) 30-epoch mae_full, so it defines a comparability boundary; see #21's bundle notes.

@cedriclim1 cedriclim1 closed this Jul 9, 2026
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