Skip to content

Built in Logit Lens - #1861

Merged
jlarson4 merged 1 commit into
devfrom
feat/logit-lens-readout
Oct 7, 2026
Merged

jlarson4 merged 1 commit into
devfrom
feat/logit-lens-readout

Conversation

@jlarson4

@jlarson4 jlarson4 commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Description

Created a simple tool for doing basic logit analysis. Being able to read the residual stream after each individual layer is a common research pattern that did not yet have a direct analog in TransformerLens, this intends to close that gap.

The PR adds a single-call tool to transformer_lens.tools.analysis:

  • logit_lens(model, prompt) or cache.logit_lens() reads each entry of the accumulated residual stream through the model's final norm and unembedding and returns per-layer logits, log-probabilities, target-token ranks, top-k tokens or a vocabulary subset.
  • logit_readout(model, vectors) does the equivalent for any d_model tensor (head outputs, steering directions, sparse-coder decoder columns).
  • targets can be a [batch, pos] tensor of next-token ids, producing the rank of the next token at every layer & position.
  • Results carry rank_trajectory, top_tokens, decode and to_dataframe.
  • Fixes Cohere in compatibility mode, where the adapter applied logit_scale twice after folding it into the unembedding.
  • Docs section in analysis_tools.md; 32 unit, 12 integration and 2 adapter tests.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Bug Fix
  • Documentation Update

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 3c67a68 into dev Oct 7, 2026
27 checks passed
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