Repository navigation
fix: bug-fix review follow-ups and regression test backfill - #2
Merged
Merged
Conversation
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
force-pushed
the
fix/mypy-type-errors
branch
from
September 16, 2026 12:41
cbe6d4d to
063add1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_metricsnow accepts/forwardsattention_mask; kurtosis and autocorrelation are computed over unmasked positions only — the same pad-corruption classb05e14efixed intrain_jacobian_lenshad survived herejspace_occupancystops when the residual is exactly exhausted (h=0previously returnedmax_k)train_jacobian_lensdrops fully-masked corpus rows from the J_l average and raises when no valid positions remain (previously cached all-zero rows)get_position_idsyielded −1 for leading pads)_capture_h_lcaptures the pre-final-norm residual for the last source layer via a norm-input hook (transformers ≥ 5.x tieshidden_states[-1]to the post-normlast_hidden_state)load_lens_layerrestores dtype preservation and defensive copy (the0ceefe1asarray(..., float32)was a behavior change, not a cast)utils.resolve_model_revision: cache fingerprints key on the resolved hub sha instead of the often-None--model-revision--probe-idsbefore model load and validates--target-layerrange after loaddemo.ipynbforwardsattention_masktotrain_jacobian_lensandcompute_discovery_metricsRegression tests — model-free only, so the suite stays fast (no hub loads in new tests): occupancy zero-residual stop,
build_V_l/_resolve_Vgeometry with non-symmetric J_l (the old test's symmetricIpassed under both geometries),load_lens_layerdtype/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-symmetricJ_lin the old decomposition test.Verification
mypy: clean ·ruff check: clean