Skip to content

CI Warnings Cleanup - #1732

Merged
jlarson4 merged 3 commits into
devfrom
chore/warning-cleanup
Sep 1, 2026
Merged

jlarson4 merged 3 commits into
devfrom
chore/warning-cleanup

Conversation

@jlarson4

Copy link
Copy Markdown
Collaborator

Description

CI was throwing errors for several deprecated dependency versions & for our deprecation warnings on Hooked* modules. This commit cleans some of those up and reduces the amount of clutter on the CI results pages.

This does involve increasing the version on Jax-typing. It should not cause any issues, but I wanted to make sure it was explicitly called out.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

@jlarson4
jlarson4 merged commit dc68d38 into dev Sep 1, 2026
46 of 50 checks passed
@jlarson4 jlarson4 mentioned this pull request Sep 11, 2026
10 tasks done
jlarson4 pushed a commit that referenced this pull request Sep 22, 2026
…on tensors (#1774)

* feat(sparse_probing): add leakage-safe core k-sparse probe fit

Add fit_sparse_probe: a stratified train/test split is computed before
any learned statistic, features are selected by train-only mean
difference, and a CPU-float64 LBFGS logistic fit reports explicit
objective/gradient-norm convergence diagnostics instead of assuming
success.

Report held-out accuracy, precision, recall, and F1 so callers can
judge decodability without the result implying causal model use,
neuron monosemanticity, or superposition.

Cover exact score/index selection, leakage isolation, deterministic
ties/RNG, optimizer convergence and failure, constant columns, and
invalid-input rejection. Sweep, controls, exports, and docs land in a
follow-up commit.

* feat(sparse_probing): add k-sweep, null controls, exports, and docs

Add sweep_sparse_probe: fits a shared-split k-grid and reports raw
random-coordinate and shuffled-training-label control distributions
alongside each k, so callers can judge coordinate concentration without
the result implying an automatic significance test.

Export fit_sparse_probe, sweep_sparse_probe, and the result dataclasses
from transformer_lens.tools.analysis, and add the sparse_probing guide
to the docs toctree, documenting the leakage-safe contract and a
run_with_cache composition example.

* test(sparse_probing): cover MPS-to-CPU transfer before float64 fit

fit_sparse_probe accepts feature matrices on any device, including
MPS, where float64 is unsupported. Add a regression test that fits a
probe over MPS-resident features and asserts the selected train/test
tensors land on CPU with float64 dtype instead of raising when the
float64 cast is attempted while still on the Metal device.

* fix(sparse_probing): accept jaxtyping>=0.3 type-check exception and dtype policy

Rebasing onto origin/dev pulled in jaxtyping>=0.3 (#1732), which re-raises
type-check violations as jaxtyping.TypeCheckError instead of letting
BeartypeCallHintParamViolation propagate, and now classifies float8_e4m3fn
as a valid Float dtype at the annotation level. Use the project's
tests/typecheck_errors.TYPECHECK_ERRORS convention for the annotation-level
cases, and move the float8_e4m3fn case to the explicit ValueError
dtype-rejection table, where the function's own dtype guard now catches it.

* fix(sparse_probing): make gradient acceptance scale-relative

* fix(sparse_probing): stamp the realized k on each sweep result

* test(sparse_probing): pin metrics to the held-out rows and control labels

* docs(sparse_probing): correct result-field list and add grouped-split caveat

* test(sparse_probing): cover the single-example-per-class rejection

* fix(sparse_probing): key gradient acceptance to feature magnitude, not initial correlation

The fit accepted when the final gradient inf-norm stayed under gradient_tolerance * max(1, initial gradient inf-norm), where the initial gradient at the zero start measures label-feature correlation rather than activation scale. A real probe support got a generous bound while random-subset and label-shuffle controls, uncorrelated by construction, were pinned to the bare absolute floor and could reject a genuinely converged fit at activation scale, discarding the whole sweep.

Key the bound to the magnitude of the selected training columns instead: gradient_tolerance * max(1, k * max abs(selected training features)), computed from the same matrix used for the main fit and both control arms. LBFGS's own tolerance_grad is left unchanged. Docstrings and the guide describe the new bound.

The large-scale guard test now scales activations into the thousands so the achieved gradient lands strictly between the absolute floor and the relative bound, and asserts both sides independently of the production formula. A new test drives the controls through sweep_sparse_probe at the same scale to cover the case the old bound broke.

* fix(sparse_probing): cap LBFGS evaluations explicitly and report the stop reason

torch.optim.LBFGS was constructed without max_eval, silently falling back
to torch's undocumented max_iter * 5 // 4 default. Combined with a
tolerance_grad that activation-scale fits may never reach, a fit can run
to either cap and return a truncated, off-optimum solve that still clears
the scale-relative acceptance check, with nothing on the result letting a
caller tell it apart from a fit that actually met its gradient tolerance.

Set max_eval explicitly as a named local and derive a stop_reason from the
realized iteration count, evaluation count, and gradient norm, in priority
order so a met tolerance outranks a simultaneously hit cap and max_iter
outranks max_eval. Thread stop_reason through _FitOutcome, _fit_result, and
SparseProbeResult, and document the new field in the guide. Add a test that
distinguishes a converged (tolerance_grad) fit from iteration-capped
(max_iter) and evaluation-capped (max_eval) truncations.

* fix(sparse_probing): reject gradient_tolerance at the top of its range

_validate_inputs accepted gradient_tolerance == 1, which is passed
straight to LBFGS as tolerance_grad. Since the acceptance threshold has a
max(1.0, ...) floor, a tolerance_grad of 1.0 lets LBFGS stop before the
first step whenever the initial gradient is already <= 1, returning an
all-zero-coefficient untrained probe as a successful fit. Reject the
whole closed top of the range: the valid interval is (0, 1), not (0, 1].

Update the validation message and the guide doc to match, and add the
newly-rejected boundary value to the invalid-input parametrization.

* test(sparse_probing): assert class_weight changes the fit against a weighted Newton reference

The previous test fit a balanced fixture in both class_weight="balanced"
and class_weight=None modes and only checked metadata round-tripping. On a
balanced fixture every class weight is 1.0 in both modes, so the two fits
are numerically identical: a bug that ignores class_weight=None and always
balances, or one that forces all-ones weights, both leave that test green.

Fit an imbalanced (~1:4) fixture in each mode at a shared seed so the split
and selected support are identical, then assert the coefficient vectors
differ and each matches an independent Newton reference computed with the
matching weighting. Generalize the reference helpers to take the weighting
mode explicitly instead of hardcoding the balanced formula.

* test(sparse_probing): guard the standardized held-out recompute against leakage

The held-out recompute ran only under the default preprocess="none", where
preprocess_mean/preprocess_scale are the identity, so it never standardized
anything and could not catch a leakage bug on the preprocess="standardize"
path, such as standardizing held-out rows with their own mean and std instead
of the returned train-only statistics.

Parametrize the test over preprocess in ("none", "standardize") and apply the
returned train-only preprocess_mean/preprocess_scale to the raw held-out rows
before scoring. Under "none" this is a no-op; under "standardize" it pins the
recompute to the train statistics the module reports, so a held-out-own-stats
leakage bug would diverge from result.metrics and fail the equality asserts.
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