Skip to content

Test mir_history_ against the keep_best rollback and save/load #161

Closed

Description

@neuromechanist

Follow-up from #137 / PR #160. Two documented claims about mir_history_ have no direct test. Neither is believed broken; both are verified by review only, and this epic has repeatedly found that a documented-but-untested claim is exactly where a regression hides.

1. mir_history_ vs the keep_best rollback (#51)

The docstrings state plainly (torch_impl/core.py, amica.py) that mir_history_ is a true trajectory which a best-iterate restore does NOT rewrite, and therefore that the fit-end MIR is model.mir(X) (computed from the restored, exported parameters), not mir_history_[-1]. This mirrors the existing final_ll_ vs ll_history_[-1] distinction that exists precisely because of #51.

Verified by review: mir_history_ is absent from _PARAM_TENSORS, and _snapshot_params/_restore_params only clone and restore that tuple, so the rollback cannot touch it. But nothing exercises a fit where a restore actually fires.

This is a known-reachable gap, not hypothetical: test_write_amica_output_ll_matches_kept_iterate in the same file already has a proven recipe for forcing a real rollback on real data (n_models=2, max_iter=60, do_newton=True, newt_start=1, lrate=0.5, seed=0, with a pytest.skip fallback if that seed happens to stay monotone). Extend it to mir_step > 0 and assert the trajectory survives the restore intact.

2. mir_history_ after save/load

AMICA.load() comments that mir_history_ is deliberately not persisted in state_dict() (it is a diagnostic, not a fitted parameter; persisting it would need a format-version bump) and is therefore always empty on a loaded model. Nothing does fit(mir_step>0) -> save -> load -> assert empty. A regression that leaked stale trajectory data through state_dict/from_state_dict would go unnoticed.

Also worth a docstring line (informational, from review)

Within the fit loop, mir_history_'s entry for iteration i is computed from the parameters after that iteration's update, while ll_history[i] records the LL of the pre-update parameters at the same i (see its own comment). So the two histories describe snapshots one update apart, and a reader zipping them by index would be comparing different parameter states. Intentional and consistent with the code, but nowhere stated.

Why deferred rather than blocking

Both are bookkeeping assertions on an opt-in diagnostic (mir_step=0 by default), the underlying mechanism was verified by review, and #137 was the epic's final phase. Not worth holding the epic's close.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions