Repository navigation
Add Logit Lens and Tuned Lens methods - #161
Conversation
- add AllLayersSplitter to capture every residual-stream boundary - project all layer activations together through the native model head - skip redundant transformer computation while preserving output contracts - add zero-initialized residual translators for Tuned Lens - provide a simple single-text API for lens explanations and training - add lens visualization, documentation, notebook, exports, and tests
AntoninPoche
left a comment
There was a problem hiding this comment.
Really nice work, much smoother than the previous version!
My comments are mainly on the documentation.
Also, I do not think we need a BaseLens, if LogitLens correspond to it exactly.
There was a problem hiding this comment.
🟡 Changes recommended
Layer discovery is unsafe for some architectures, and several advertised APIs and executed documentation artifacts are missing.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds Logit Lens and Tuned Lens support using a new all-layer transformer splitter, public visualization, tests, and documentation.
Changes:
- Adds all-layer activation extraction and lens projection/training.
- Adds normalized lens outputs and HTML visualization.
- Exports and documents the new public APIs.
File summaries
| File | Description |
|---|---|
tests/lens/test_lens.py |
Tests lens behavior and visualization. |
tests/concepts/splitters/test_all_layers_splitter.py |
Tests activation extraction and head replay. |
README.md |
Advertises lens methods and tutorial. |
mkdocs.yml |
Adds lens documentation navigation. |
interpreto/visualizations/lens.py |
Implements lens HTML rendering. |
interpreto/visualizations/commons.py |
Makes visualization JavaScript optional. |
interpreto/visualizations/__init__.py |
Exports plot_lens. |
interpreto/typing.py |
Defines lens result types. |
interpreto/lens/tuned_lens.py |
Implements Tuned Lens fitting. |
interpreto/lens/logit_lens.py |
Defines Logit Lens. |
interpreto/lens/_lens_base.py |
Provides shared lens inference logic. |
interpreto/lens/__init__.py |
Exports lens classes. |
interpreto/concepts/splitters/all_layers_splitter.py |
Adds all-layer extraction and prediction replay. |
interpreto/concepts/splitters/__init__.py |
Exports the new splitter. |
interpreto/concepts/__init__.py |
Re-exports the splitter. |
interpreto/__init__.py |
Adds top-level public exports. |
docs/notebooks/lens_notebook.ipynb |
Demonstrates lens usage. |
docs/api/visualizations.md |
Documents lens visualization. |
docs/api/lens/overview.md |
Introduces the lens API. |
docs/api/lens/methods/tuned_lens.md |
Documents Tuned Lens. |
docs/api/lens/methods/logit_lens.md |
Documents Logit Lens. |
docs/api/concepts/splitters/all_layers_splitter.md |
Documents the new splitter. |
Review details
- Files reviewed: 22/22 changed files
- Comments generated: 5
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Add to capture every transformer block boundary and reuse the model's native prediction path. - Add , decoding every residual state together through one prediction-head call. - Add with zero-initialized affine translators trained across all model depths. - Support causal language modeling and compatible sequence-classification models. - Add following Interpreto's visualization conventions. - Export the Lens API from . - Add consolidated API documentation and an executed notebook covering classification, generation, fitting, and visualization. - Add tests for projection fidelity, layer discovery, device handling, training, notebook execution, and visualization compatibility.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- accept model repository IDs directly in LogitLens and TunedLens - replace per-layer tables with compact confidence grids - preserve top-k details through interactive hover information - expand the executed notebook with dataset-size and epoch comparisons - update documentation, dependencies, and regression tests
- keep next-token predictions as the default generation behavior - add align=True for target-aligned visualizations - improve whitespace rendering and update lens documentation and tests
- align causal lens predictions by default - distinguish input, embeddings, and layer outputs - highlight correct predictions and document unaligned views
- adapt lens colors to the active documentation theme - improve prediction text contrast - refresh notebook outputs and add regression coverage
AntoninPoche
left a comment
There was a problem hiding this comment.
Looks perfect now, thank you very much for your contribution and your patience!!
Description
This PR adds Logit Lens and Tuned Lens methods for inspecting predictions decoded from intermediate transformer representations.
Both methods integrate with
ModelWithSplitPoints: the lens operates on the wrapped model's configured split point and reuses the model's prediction path.Main changes:
LogitLensfor projecting an intermediate activation through the model's prediction path.TunedLenswith an affine translator tied to the configured split point.head_name,pre_head_name, andpooling_strategyoverrides.plot_lens, following the existing Interpreto visualization conventions.interpreto.Related Issue
#85
Type of Change
Checklist
CODE_OF_CONDUCT.mddocument.CONTRIBUTING.mdguide.make lint.make test.