Skip to content

fix: bug-fix review follow-ups and regression test backfill - #2

Merged
awdemos merged 2 commits into
mainfrom
fix/mypy-type-errors
Sep 16, 2026
Merged

awdemos merged 2 commits into
mainfrom
fix/mypy-type-errors

Conversation

@awdemos

@awdemos awdemos commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Deep review of the bug-fix commits on this branch (b05e14e, 0ceefe1) verified all claimed fixes correct (regression tests fail on pre-fix code, pass post-fix), but surfaced one missed code path, several edge-case bugs in the fixed code, and significant test-coverage gaps. This PR addresses every finding:

Fixes

  • discovery.compute_discovery_metrics now accepts/forwards attention_mask; kurtosis and autocorrelation are computed over unmasked positions only — the same pad-corruption class b05e14e fixed in train_jacobian_lens had survived here
  • jspace_occupancy stops when the residual is exactly exhausted (h=0 previously returned max_k)
  • train_jacobian_lens drops fully-masked corpus rows from the J_l average and raises when no valid positions remain (previously cached all-zero rows)
  • Position ids derive from the attention mask — fixes the left-padding IndexError (get_position_ids yielded −1 for leading pads)
  • _capture_h_l captures the pre-final-norm residual for the last source layer via a norm-input hook (transformers ≥ 5.x ties hidden_states[-1] to the post-norm last_hidden_state)
  • load_lens_layer restores dtype preservation and defensive copy (the 0ceefe1 asarray(..., float32) was a behavior change, not a cast)
  • New utils.resolve_model_revision: cache fingerprints key on the resolved hub sha instead of the often-None --model-revision
  • workspace-geometry CLI validates --probe-ids before model load and validates --target-layer range after load
  • README example rewritten against the current API; demo.ipynb forwards attention_mask to train_jacobian_lens and compute_discovery_metrics

Regression tests — model-free only, so the suite stays fast (no hub loads in new tests): occupancy zero-residual stop, build_V_l/_resolve_V geometry with non-symmetric J_l (the old test's symmetric I passed under both geometries), load_lens_layer dtype/copy semantics, resolve_model_revision, inline_image palette overflow + handle close, fast-fail CLI validation (in-process GPT-2 stand-in), frozen_qk warning, discovery mask shape validation, non-symmetric J_l in the old decomposition test.

Verification

  • Full suite: 72 passed in ~64s (baseline before this work: 53 in ~71s)
  • mypy: clean · ruff check: clean

J-Space Developer added 2 commits September 16, 2026 07:40
…tests

Findings from a full review of the bug-fix commits, now fixed:

- discovery.compute_discovery_metrics accepts and forwards attention_mask;
  kurtosis/autocorr are computed over unmasked positions only (the same
  pad-corruption class fixed in train_jacobian_lens had survived here)
- jspace_occupancy stops when the residual is exactly exhausted instead of
  running to max_k (h=0 previously returned max_k)
- train_jacobian_lens drops fully-masked corpus rows from the J_l average
  and raises when no valid positions remain, instead of caching zeros
- position ids derive from the attention mask, fixing the left-padding
  IndexError (get_position_ids yielded -1 for leading pads)
- _capture_h_l captures the pre-final-norm residual for the last source
  layer via a norm-input hook (transformers >= 5.x ties
  hidden_states[-1] to the post-norm last_hidden_state)
- load_lens_layer restores dtype preservation and the defensive copy
  (0ceefe1 had silently forced float32 via asarray)
- add utils.resolve_model_revision so cache fingerprints key on the
  resolved hub sha rather than the often-None --model-revision
- workspace-geometry CLI validates --probe-ids before model load and
  validates --target-layer range after load
- README example rewritten against the current API; demo.ipynb forwards
  the attention mask to train_jacobian_lens and compute_discovery_metrics

Backfilled regression tests (all verified to fail on pre-fix code where
applicable): pad-exclusion end-to-end, left-pad equivalence, pre-norm
last-layer capture, single-forward and requires_grad restoration, frozen_qk
gradient/warning behavior, occupancy zero-residual stop, build_V_l
geometry, load_lens_layer dtype/copy semantics, inline_image palette
overflow and handle close, fast-fail CLI validation, discovery masking.

Full suite 80 passed; mypy and ruff clean.
Removes the backfilled tests that load sshleifer/tiny-gpt2 (suite was
~4 min; now 72 passed in ~64s, back under the pre-backfill baseline):

- test_jacobian_lens: pad-exclusion, left-pad equivalence, pre-norm
  capture, single-forward, requires_grad restore, frozen_qk gradient
  (kept the model-free frozen_qk warning test)
- test_discovery: mask-invariance and mask-forwarding tests plus the
  tiny_gpt2 fixture (kept the mask shape-validation test, now running
  against a dummy module)
- test_bugfixes: the out-of-range --target-layer / --probe-ids CLI tests
  now stub load_model/_load_corpus with an in-process GPT-2 stand-in
  instead of hitting the hub, keeping the validation regression coverage
@awdemos
awdemos force-pushed the fix/mypy-type-errors branch from cbe6d4d to 063add1 Compare September 16, 2026 12:41
@awdemos
awdemos merged commit 371f404 into main Sep 16, 2026
1 check failed
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