Skip to content

[Feature] Bilinear probing#41

Merged
Xmaster6y merged 8 commits intomainfrom
bilinear-probing
Feb 15, 2026
Merged

[Feature] Bilinear probing#41
Xmaster6y merged 8 commits intomainfrom
bilinear-probing

Conversation

@Xmaster6y
Copy link
Owner

@Xmaster6y Xmaster6y commented Feb 15, 2026

What does this PR do?

Key insights about the PR.

Linked Issues

  • Closes #?
  • #?

Checklist

  • I have read the CONTRIBUTING guide.
  • I have added tests for my changes if needed.
  • I have updated the documentation if needed.

Summary by cubic

Adds bilinear probing to train classifiers on paired layer representations and analyze cross-layer interactions. Refactors probing into a torch-first, modular API with ProbeManager/BilinearProbeManager, updates docs/notebooks, and expands tests; removes the sklearn manager.

  • New Features

    • BilinearProbeManager for layer pairs with a key_pattern regex; BilinearProbe caches activations and validates pairs via before_all/after_all.
    • Torch estimators: BilinearEstimator, LowRankBilinearEstimator, LinearEstimator, plus MeanDifferenceClassifier; optional verbose fit logs.
    • New bilinear probing notebook and docs card; GPT-2 + IMDb example.
  • Refactors

    • Probing moved into tdhook.latent.probing (context, estimators, managers); exports updated; sklearn manager removed.
    • Notebooks now use ProbeManager (linear-probing and torchrl-ppo); fixed r2 callback signature in torchrl-ppo.

Written for commit d0477ae. Summary will update on new commits.

@codecov
Copy link

codecov bot commented Feb 15, 2026

Codecov Report

❌ Patch coverage is 97.95322% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.19%. Comparing base (b7c78fb) to head (d0477ae).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/tdhook/latent/probing/context.py 93.47% 3 Missing ⚠️
src/tdhook/latent/probing/managers.py 98.28% 3 Missing ⚠️
src/tdhook/latent/probing/estimators.py 99.13% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #41      +/-   ##
==========================================
+ Coverage   96.81%   97.19%   +0.38%     
==========================================
  Files          36       39       +3     
  Lines        2226     2426     +200     
==========================================
+ Hits         2155     2358     +203     
+ Misses         71       68       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 11 files

Confidence score: 3/5

  • Potential runtime errors in src/tdhook/latent/probing/estimators.py when bias=False adds None to a tensor or when a dataset has a single class leading to divide-by-zero/NaNs.
  • src/tdhook/latent/probing/context.py may raise a TypeError during hook registration if list types are passed into MultiHookManager without converting to tuples.
  • Score reflects multiple medium-severity issues that could cause failures or invalid outputs at runtime.
  • Pay close attention to src/tdhook/latent/probing/estimators.py and src/tdhook/latent/probing/context.py - guard against runtime errors in edge cases and hook registration.
Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/tdhook/latent/probing/context.py">

<violation number="1" location="src/tdhook/latent/probing/context.py:42">
P2: Convert `classes_to_hook`/`classes_to_skip` lists to tuples before passing them to `MultiHookManager`; otherwise passing a list will raise a `TypeError` in the `isinstance` checks during hook registration.</violation>
</file>

<file name="src/tdhook/latent/probing/estimators.py">

<violation number="1" location="src/tdhook/latent/probing/estimators.py:36">
P2: Guard against datasets with only one class; otherwise mean computation divides by zero and yields NaNs.</violation>

<violation number="2" location="src/tdhook/latent/probing/estimators.py:44">
P2: Avoid dividing by a zero coefficient norm; guard or skip normalization when the norm is zero.</violation>

<violation number="3" location="src/tdhook/latent/probing/estimators.py:172">
P2: Handle bias=False explicitly; adding None to a tensor raises a runtime error.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/source/notebooks/tutorials/torchrl-ppo.ipynb">

<violation number="1" location="docs/source/notebooks/tutorials/torchrl-ppo.ipynb:267">
P2: The R² metric lambda uses predictions as the first argument, but `ProbeManager` passes `(predictions, labels)` and `r2_score` expects `y_true` first. This swaps `y_true`/`y_pred` and produces incorrect R² scores.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/latent/test_probing.py">

<violation number="1" location="tests/latent/test_probing.py:197">
P2: This test codifies a crash for bias=False instead of asserting correct bias-free behavior. Consider adjusting the estimator to handle bias=None (e.g., add 0) and update the test to expect a valid output shape; otherwise the test will hide a real bug.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@Xmaster6y Xmaster6y merged commit e37469c into main Feb 15, 2026
7 checks passed
@Xmaster6y Xmaster6y deleted the bilinear-probing branch February 15, 2026 17:12
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

Comments