Skip to content

Address PR #28 review: NG backend polish + doc coherence - #33

Merged
neuromechanist merged 4 commits into
feature/issue-9-epic-torch-parityfrom
feature/issue-29-pr28-cleanups
Jul 3, 2026
Merged

neuromechanist merged 4 commits into
feature/issue-9-epic-torch-parityfrom
feature/issue-29-pr28-cleanups

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Closes #29. Applies the PR #28 (epic close-out) review findings into the epic so #28 carries them.

Important

  • Fix AMICA(backend="ng") crashing on its own default config on Apple Silicon: fit()
    auto-selected MPS, but AMICATorchNG defaults to float64 (Fortran parity), which MPS rejects.
    When the device is not pinned and resolves to MPS for a float64 NG run, fall back to CPU (CUDA is
    unaffected). Users can still opt into MPS with dtype=torch.float32, device="mps".
  • Add a real-data wrapper test for backend="ng" (test_amica_ng_wrapper.py): constructor guard,
    debug/output_dir guards, save/load NotImplementedError, the MPS->CPU device fallback, and a
    small real-data fit + transform/get_mixing/get_unmixing. No synthetic data.

Doc coherence

Suggestions

  • Re-export AMICATorchNG from pyAMICA/__init__.py; docstring model_ notes both backends.

Follow-up issues filed

Test plan

  • uv run pytest pyAMICA/tests -m "not slow" -> 61 passed, 2 xfailed
  • new wrapper tests -> 7 passed
  • ruff check / ruff format clean

AMICA(backend='ng') auto-selected MPS but AMICATorchNG defaults to
float64 (Fortran parity), which MPS rejects; the default config crashed
on Apple Silicon. Fall back to CPU when MPS is auto-selected for a
float64 NG run. Re-export AMICATorchNG, note it in the model_ docstring,
and add a real-data wrapper test (guards, save/load, device fallback).
Refs #29.
The two xfail tests blamed 'epic #9'; that epic is delivered. They are
independent legacy bugs: CLI save/load format mismatch (#30) and the
GaussianMixtureICA fit_em M-step LL descent (#31). Repoint the reasons.
Update AGENTS.md (backend map, completed UV migration, follow-ups),
FEATURE_PARITY.md and PROGRESS_SUMMARY.md (NG parity numbers, replace
stale pre-epic metrics), and accept ADR 0001. Point V2 removal at #32.
Refs #26 #27 #29 #30 #31 #32.
Silent-failure-hunter: emit the MPS->CPU downgrade via logger.warning
unconditionally (not just verbose print), matching the codebase's device
caveats; derive AMICATorchNG's default dtype from its signature instead of
duplicating the float64 literal; document the fallback on the device
parameter. Test-analyzer: add explicit device='mps'+float64 raise test
(no MPS needed) and the dtype=float32 MPS escape-hatch test (skipif), and
assert the fallback warning fires even with verbose=False.
@neuromechanist

Copy link
Copy Markdown
Member Author

Review (pr-review-toolkit, model=sonnet)

Three reviewers ran against commits e27f717..bab24d1 (code, silent-failure, tests). All findings addressed in 80ad9f2.

code-reviewer: No findings at confidence >= 80. Verified the MPS->CPU fallback on real MPS hardware with real sample data; confirmed explicit device="mps" still raises AMICATorchNG's ValueError, CUDA is unaffected, and moving import torch to module top is safe. (Sub-threshold note: a dtype="float64" string bypasses both the wrapper and AMICATorchNG's own guard, but that is pre-existing in the constructor, not a regression here, and violates the documented dtype: torch.dtype contract; left as-is.)

silent-failure-hunter:

  • HIGH: the fallback notice was gated behind verbose -> now emitted via logger.warning unconditionally (matches amica_torch.py/utils.py device-caveat convention), with the print kept as a verbose-only nicety.
  • MEDIUM: duplicated torch.float64 default literal -> now derived from inspect.signature(AMICATorchNG) so the fallback can't silently stop firing if the default changes.
  • MEDIUM: public docstring didn't mention the fallback -> added to the device parameter docs.
  • Confirmed the fallback scoping (auto-only, explicit-mps still raises) is correct.

pr-test-analyzer:

  • Added test_ng_explicit_mps_float64_raises (the negative complement of the fix; no MPS hardware needed).
  • Added test_ng_mps_float32_escape_hatch (skipif no MPS) for the documented workaround.
  • The fallback test now asserts the warning fires even with verbose=False.

Suite: 63 passed, 2 xfailed (0 failures); ruff check/format clean. No CI is configured on the repo.

@neuromechanist
neuromechanist merged commit 5663868 into feature/issue-9-epic-torch-parity Jul 3, 2026
@neuromechanist
neuromechanist deleted the feature/issue-29-pr28-cleanups branch July 3, 2026 18:26
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