Repository navigation
Built in Logit Lens - #1861
Merged
Merged
Built in Logit Lens#1861
Conversation
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.
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)orcache.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 anyd_modeltensor (head outputs, steering directions, sparse-coder decoder columns).targetscan be a[batch, pos]tensor of next-token ids, producing the rank of the next token at every layer & position.rank_trajectory,top_tokens,decodeandto_dataframe.logit_scaletwice after folding it into the unembedding.analysis_tools.md; 32 unit, 12 integration and 2 adapter tests.Type of change
Checklist: