Repository navigation
Weight nd by pre-update model weights - #241
Conversation
Review findings addressedThe test reviewer did the decisive thing I had not: it reverted the change and re-ran. All tests still passed, on both backends. The PR had no regression guard. Three findings, all fixed: 1. The ordering test was vacuous. It mutated 2. Nothing would fail if the change were reverted. The remaining assertions ( 3. The PyTorch backend had no test at all, despite being the backend where The discriminatorHold one accumulator dict fixed across two M-steps, so the post-update gm ( nd_a = step_with_pre_update_gm(model, acc, n, [0.9, 0.1])
nd_b = step_with_pre_update_gm(model, acc, n, [0.1, 0.9])
assert nd_a != nd_bEach has a complement asserting the same pre-update gm is deterministic, so they cannot pass on unrelated sensitivity, plus a single-model case pinning why issue #24 parity is untouched ( Verified by reverting
10 tests pass with the fix in place. New file |
Second reviewer's findings addressedThe general code reviewer independently reproduced the revert-and-rerun result, and added three more. Comment accuracy — my regression. The pre-PR numpy comment said "Diagnostic only, it does not affect the fitted parameters"; I dropped that clause, leaving a comment that reads identically to the torch one for a change with materially different consequences. Restored, and now states explicitly that numpy's A-update is a separate loop that never reads Torch comment undersold its own scope. It said "the ndtmpsum block below", but that block is also the A-update. Reworded to say Latent fragility. The reviewer also asked that the numpy/torch asymmetry be called out explicitly; it already is, under "Correction to the issue" in the PR description. Filed rather than fixed here#242 — the reviewer found that Pre-existing and untouched by this PR (the loop is not in the diff), and out of scope here. With #240 it makes |
Every job was ubuntu-latest, so pamica/tests/mlx_tests/ had never run in CI and the Accelerate BLAS path was untested. The second gap is not theoretical: a test_ng_convergence.py assertion stayed green on Linux through #241 and failed immediately on macOS, because the ~1e-6 trajectory shift moved the stopping iteration off the multiple of mir_step the assertion assumed. macos-26 is the current arm64 image and standard runners are free for public repositories. The job installs the mlx extra and asserts the import rather than letting mlx_tests self-skip into a green no-op. Refs #246. Co-Authored-By: Claude Opus 5 <[email protected]>
* Add a macOS Apple Silicon CI job Every job was ubuntu-latest, so pamica/tests/mlx_tests/ had never run in CI and the Accelerate BLAS path was untested. The second gap is not theoretical: a test_ng_convergence.py assertion stayed green on Linux through #241 and failed immediately on macOS, because the ~1e-6 trajectory shift moved the stopping iteration off the multiple of mir_step the assertion assumed. macos-26 is the current arm64 image and standard runners are free for public repositories. The job installs the mlx extra and asserts the import rather than letting mlx_tests self-skip into a green no-op. Refs #246. Co-Authored-By: Claude Opus 5 <[email protected]> * Assert the Apple GPU; correct the macOS job comments Review findings. Assert mx.default_device().type == gpu, not just that mlx imports. The mlx_tests module is gated on both (test_mlx_backend.py:28-33), so a runner that imported mlx and fell back to CPU would skip all 11 tests and still report success. The hosted macos-26 image does expose the GPU -- all 11 passed on the first run -- but nothing in the job would have caught it if a future image stopped. Add PYTORCH_ENABLE_MPS_FALLBACK=1. The two Linux jobs already set it defensively; this is the only job whose hardware can actually auto-select MPS. Add EXTRA_LDFLAGS=-static-libquadmath so the build really is the release-binaries.yml macos-arm64 recipe the comment claims. Correct the -m 'not slow' rationale: it was attributed to Rosetta and the x86_64 amica15mac, but most slow tests never invoke a binary, and the two that do resolve through PAMICA_NATIVE_BINARY (native/resolver.py:112), which this job sets to the arm64 binary it just built. They are excluded for wall-clock, and enabling them is a real follow-up rather than blocked work. Refs #246. Co-Authored-By: Claude Opus 5 <[email protected]> --------- Co-authored-by: Claude Opus 5 <[email protected]>
* Complete 0.3.3 changelog for release Rename Unreleased to 0.3.3 with a release summary and add the missing user-facing entries: best-of-N restarts (#198/#299), MNE bad_* annotation rejection (#251/#252), the numpy comp_used staleness fix (#240/#243), and the nd pre-update gm weighting (#219/#241). Docs only, not tested beyond proofread. * Correct stale counts and citations in changelog The 0.3.3 param-reader entry still said 36 unsupported keywords and listed the do_opt_block search among them; #232 moved those four keys to identity mappings, leaving 32 (fortran_params.py's own arithmetic: 57 + 32 = 89). Also aligned two Fortran citations with the literal source: the loglik/modloglik allocation spans 2617-2620 and the reject_data zeroing block 2231-2234, matching the ranges now used across the codebase. Docs only.
Closes #219.
The ordering
Fortran builds
dAkinsideaccum_updates_and_likelihoodand only reassignsgminupdate_params:So the reference weights by the previous iteration's model weights. Both backends reassigned
gmfirst; both now snapshot it.Correction to the issue
#219 describes this as diagnostic-only. That holds for
numpy_impl, wheredAkfeedsndalone. It does not hold forAMICATorchNG, where the samedAkis the A-update (self.A = self.A - self.lrate * dAk), so the ordering reaches fitted parameters there. Worth stating plainly, since the issue's framing implied this PR could not change results.Measured effect
Single-model and Newton fits are bit-identical (
gm == 1). Multi-model shifts by 1.0e-06 relative in log-likelihood.That shift is not a semantic change: for a disjoint
comp_listeach column belongs to exactly one model, sogm[h]cancels againstzeta[idx] = gm[h]and the result is algebraically identical either way. What changes is the floating-point association, amplified by the chaotic EM trajectory to ~1e-6 — the same order as the documentedblock_sizetrajectory shift, and well inside the ~5e-4 parity tolerance.The weighting differs semantically only under
share_comps, where a column belongs to more than one model and the cancellation no longer applies.Tests
Two added to
test_numpy_grad_norm.py: one pinning the pre-update weighting with a forced shared column, one asserting a shared column keeps the gradient norm finite (zetaaccumulates a positive weight per contributing model, so the division cannot go 0/0).Found on the way
Writing the sharing test surfaced #240:
numpy_impl+share_compsleaves half ofmuandbetaNaN while reporting a successful fit. Pre-existing and independent of this change — the mixture update never readsdAk— so it is filed rather than fixed here.