Skip to content

Remove superseded torch backends (#32) - #35

Merged
neuromechanist merged 2 commits into
mainfrom
32-remove-parked-amicatorchv2-and-promote-backend=ng-to-default
Jul 4, 2026
Merged

neuromechanist merged 2 commits into
mainfrom
32-remove-parked-amicatorchv2-and-promote-backend=ng-to-default

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Summary

Now that AMICATorchNG (the natural-gradient EM backend) reaches Fortran parity, this removes the superseded Adam/autograd backends. AMICATorchNG becomes the sole PyTorch backend and the public AMICA interface wraps it directly.

Per maintainer direction: retire (remove) the buggy/superseded paths outright rather than deprecate; NG covers the needed functionality.

Changes

  • Deleted modules: amica_torch.py (AMICATorch), amica_torch_v2.py (AMICATorchV2), and their now-dead helpers mixture_models.py, optimizers.py, newton_optimizer.py, adaptive_pdf.py, fortran_output.py. AMICATorchNG imports only .utils, so nothing it needs was removed.
  • Deleted dead scripts/tests: root-level test_torch_fixed.py, test_torch_amica.py, test_enhanced_amica.py; and torch_tests/{test_torch_components,test_torch_vs_fortran,test_correctness_fixes}.py (all exercised the removed backends). NG/Fortran parity coverage remains in test_ng_backend.py and test_amica_ng_wrapper.py.
  • AMICA interface (amica.py): dropped the backend= selector and the basic-backend-only debug/output_dir fit args; it now wraps AMICATorchNG. save/load raise NotImplementedError (a persistence format is tracked in Test coverage gaps: AMICA.save/load and plot_components #15).
  • utils.py: removed the buggy save_pytorch_results() (it called a non-existent AMICATorch.save) — resolves save_pytorch_results() calls non-existent AMICATorch.save #16.
  • validate_implementations.py: repointed the PyTorch path at NG via the AMICA wrapper (maps sample_params.json to NG kwargs).
  • examples/torch_example.py: rewritten to use the AMICA (NG) wrapper.
  • Docs: AGENTS.md, FEATURE_PARITY.md, PROGRESS_SUMMARY.md, ADR 0001 (addendum), .context/plan.md updated.

Related issues

Testing

Net: +205 / -4908 lines across 26 files.

AMICATorchNG is now the sole PyTorch backend; AMICA wraps it directly.

- Delete AMICATorch, AMICATorchV2, and their helper modules
  (mixture_models, optimizers, newton_optimizer, adaptive_pdf,
  fortran_output) plus the dead root-level dev scripts.
- Drop the backend= selector and the basic-backend-only debug/output_dir
  fit args; save/load now raise NotImplementedError (#15).
- Remove buggy save_pytorch_results (resolves #16); deleting the basic
  mixture M-step also makes #31 moot.
- Repoint validate_implementations.py at NG via the AMICA wrapper.
- Update docs (AGENTS, FEATURE_PARITY, PROGRESS_SUMMARY, ADR 0001).

Tested: torch suite (23 passed) and non-slow suite (31 passed,
1 xfailed) green; harness smoke-fit ascends toward the Fortran LL.
@neuromechanist neuromechanist linked an issue Jul 4, 2026 that may be closed by this pull request
4 tasks
- validate harness: warn on params.json keys the NG backend can't honor
  (was silently dropped), raise on num_comps != data_dim (NG has no PCA
  reduction), and pop seed/device from NG kwargs to avoid a future
  duplicate-keyword TypeError.
- Restore a fast, deterministic per-source LL factorization-order guard
  for single-model NG (independent NumPy reference; no fit/Fortran),
  covering the historical issue-#11 bug class the deleted tests guarded.
- save()/load() now reference issue #36 (NG persistence) instead of #15
  (which is about test coverage of the removed backend).
- Docs/comments: drop stale backend= selector refs (FEATURE_PARITY,
  PROGRESS_SUMMARY), fix the autodiff feature bullet, reflow the NG module
  docstring, note removed persistence in the example, correct the harness
  init comment (identity + small perturbation).

Tested: torch suite 24 passed; non-slow suite 32 passed, 1 xfailed.
@neuromechanist

Copy link
Copy Markdown
Member Author

PR review (4 agents, Sonnet) + resolutions

Ran code-review, silent-failure, test-coverage, and comment-accuracy reviewers. Findings and how each was handled (fixed in a196007):

Addressed

  • Silent param drop in the validation harness (silent-failure, High): run_pytorch_amica filtered sample_params.json to NG kwargs with no diagnostic, so unsupported settings (min_dll/use_grad_norm convergence criteria, pdftype, share_comps, do_opt_block, ...) were dropped silently — a parity harness could compare mismatched configs. Now prints a WARNING listing every ignored key.
  • num_comps silently ignored (silent-failure, High): NG hardcodes n_sources == n_channels; the old code wired n_sources=num_comps. Now raises ValueError if num_comps != data_dim (NG can't do PCA reduction, so the comparison wouldn't be apples-to-apples).
  • seed/device duplicate-kwarg landmine (silent-failure, Medium): both are NG constructor kwargs passed explicitly; added them to the pop-list so a future params.json with seed won't crash with an opaque TypeError.
  • Lost LL factorization-order guard (test-coverage, Important/sev7): the deleted test_correctness_fixes.py guarded the issue-Phase 2: Isolated correctness fixes (3 math bugs) #11 per-source-logsumexp order; the reviewer showed a swap survives the fast NG suite. Added test_forward_ll_per_source_factorization_order (fast, deterministic, independent NumPy reference; asserts NG matches the correct order and that the swapped order genuinely differs).
  • save/load cited Test coverage gaps: AMICA.save/load and plot_components #15 (comment): Test coverage gaps: AMICA.save/load and plot_components #15 is about test coverage of the removed backend, not NG persistence. Filed Implement save/load persistence for AMICATorchNG #36 and repointed the messages.
  • Stale backend="ng" doc refs (comment): cleaned headers/recommendations in FEATURE_PARITY.md and PROGRESS_SUMMARY.md, the __init__ "Automatic differentiation" bullet (NG is non-autograd), the NG module-docstring reflow, and the harness "identity mixing matrix" comment (actually identity + small perturbation).

Skipped (with rationale)

  • dtype-guard only checks == torch.float64 (silent-failure, Low): mirrors AMICATorchNG's own constructor guard; an explicit non-standard dtype on MPS surfaces NG's own ValueError. Widening it here would duplicate that check.
  • save() dropped its is_fitted_ precheck (silent-failure, Low): save() now unconditionally raises NotImplementedError (the feature doesn't exist for any backend), so a fit-state message would be misleading; the NotImplementedError is the accurate error.
  • "Dead" utils (test-coverage, Minor): compare_with_fortran (+ compute_correlation_matrix/find_best_permutation) IS used by the rewritten examples/torch_example.py; check_numerical_stability cleanup is deferred to the module-restructure epic Epic: Clean module naming and structure (drop amica_/pyAMICA/_torch/_v2 sprawl) #34.
  • Broad except Exception in run_fortran_amica: pre-existing legacy in the Fortran runner, not substantively touched by this PR; can be a separate follow-up.

Tests after fixes: torch suite 24 passed; non-slow suite 32 passed, 1 xfailed (the unrelated NumPy-CLI #30).

@neuromechanist
neuromechanist merged commit 5f49faa into main Jul 4, 2026
@neuromechanist
neuromechanist deleted the 32-remove-parked-amicatorchv2-and-promote-backend=ng-to-default branch July 4, 2026 18:23
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.

Remove parked AMICATorchV2 and promote backend='ng' to default save_pytorch_results() calls non-existent AMICATorch.save

1 participant