Table of Contents
Fetching ...

LogitLens4LLMs: Extending Logit Lens Analysis to Modern Large Language Models

Zhenyu Wang

TL;DR

Extends the standard Logit Lens by applying it to modern LLMs and formalizing $p_l(x_{t+1}|x_{\le t}) = \text{softmax}(W_{head} \cdot \text{Norm}(h_l^{(t)}))$. It introduces component-specific hooks for attention and MLP outputs and a wrapper intercepting four points per block. A layer-wise heatmap pipeline $H_{i,j} = \frac{1}{Z}\sum_{k=1}^K \mathbb{I}(token_k \in T_j) \cdot p_l(token_k|x_{\le t})$ enables visualization of prediction evolution across layers; gradient-preserving hooks ensure low overhead within HuggingFace, supporting interactive and batch analyses. Open-source release at https://github.com/zhenyu-02/LogitLens4LLMs facilitates large-scale mechanistic studies and cross-model comparisons.

Abstract

This paper introduces LogitLens4LLMs, a toolkit that extends the Logit Lens technique to modern large language models. While Logit Lens has been a crucial method for understanding internal representations of language models, it was previously limited to earlier model architectures. Our work overcomes the limitations of existing implementations, enabling the technique to be applied to state-of-the-art architectures (such as Qwen-2.5 and Llama-3.1) while automating key analytical workflows. By developing component-specific hooks to capture both attention mechanisms and MLP outputs, our implementation achieves full compatibility with the HuggingFace transformer library while maintaining low inference overhead. The toolkit provides both interactive exploration and batch processing capabilities, supporting large-scale layer-wise analyses. Through open-sourcing our implementation, we aim to facilitate deeper investigations into the internal mechanisms of large-scale language models. The toolkit is openly available at https://github.com/zhenyu-02/LogitLens4LLMs.

LogitLens4LLMs: Extending Logit Lens Analysis to Modern Large Language Models

TL;DR

Extends the standard Logit Lens by applying it to modern LLMs and formalizing . It introduces component-specific hooks for attention and MLP outputs and a wrapper intercepting four points per block. A layer-wise heatmap pipeline enables visualization of prediction evolution across layers; gradient-preserving hooks ensure low overhead within HuggingFace, supporting interactive and batch analyses. Open-source release at https://github.com/zhenyu-02/LogitLens4LLMs facilitates large-scale mechanistic studies and cross-model comparisons.

Abstract

This paper introduces LogitLens4LLMs, a toolkit that extends the Logit Lens technique to modern large language models. While Logit Lens has been a crucial method for understanding internal representations of language models, it was previously limited to earlier model architectures. Our work overcomes the limitations of existing implementations, enabling the technique to be applied to state-of-the-art architectures (such as Qwen-2.5 and Llama-3.1) while automating key analytical workflows. By developing component-specific hooks to capture both attention mechanisms and MLP outputs, our implementation achieves full compatibility with the HuggingFace transformer library while maintaining low inference overhead. The toolkit provides both interactive exploration and batch processing capabilities, supporting large-scale layer-wise analyses. Through open-sourcing our implementation, we aim to facilitate deeper investigations into the internal mechanisms of large-scale language models. The toolkit is openly available at https://github.com/zhenyu-02/LogitLens4LLMs.

Paper Structure

This paper contains 5 sections, 3 equations, 1 figure.

Figures (1)

  • Figure 1: Prediction evolution across layers in Llama-2-7B for the prompt "The capital of France is "