LRP-eXplains-Transformers  by rachtibat

Explainable AI for Transformers

Created 2 years ago
251 stars

Top 99.9% on SourcePulse

GitHubView on GitHub
Project Summary

Summary

LXT (Layer-wise Relevance Propagation for Transformers) accelerates Explainable AI (XAI) research for Large Language Models (LLMs) and Vision Transformers (ViTs). It provides fast, faithful input attributions by revealing how each token and neuron contributes to model predictions, overcoming the noise and unreliability of traditional gradient-based methods. This enables deeper understanding and debugging of complex transformer architectures for researchers and power users.

How It Works

LXT employs AttnLRP, an attention-aware backpropagation technique that corrects gradient flow through non-linearities, ensuring accurate relevance scores. This method requires only a single backward pass, offering significant efficiency gains. It outperforms existing gradient, decomposition, and perturbation-based XAI methods, scaling computationally with $O(1)$ complexity and $O(\sqrt{N})$ memory relative to model depth. Beyond input attributions, LXT facilitates latent feature attribution and visualization by analyzing individual neuron importance, allowing for deeper model introspection.

Quick Start & Requirements

  • Installation: pip install lxt
  • Dependencies: Tested with transformers==5.9.0, torch==2.12.0, python==3.11.
  • Documentation: Official Docs
  • Examples: Available in the examples/* directory.

Highlighted Details

  • Faithful attributions for black-box transformers via AttnLRP.
  • Efficient implementation leveraging Input*Gradient and monkey patching.
  • Latent feature attribution and neuron visualization capabilities.
  • Broad model support including LLaMA 2/3, Gemma 3, Qwen 2, BERT, GPT-2, and Vision Transformers.

Maintenance & Community

Contributions are encouraged. The project is associated with ICML 2024. No specific community channels (e.g., Discord, Slack) or roadmap links are provided in the README.

Licensing & Compatibility

  • License: BSD-3 Clause License.
  • Restrictions: The README states LRP is a patented technology, usable free of charge only for personal and scientific purposes. This implies significant restrictions for commercial applications.

Limitations & Caveats

  • Attribution for Qwen 3 models may be skewed towards the first token.
  • GPT-2 models are best used with contrastive explanations.
  • The BSD-3 Clause license includes a patent restriction limiting free use to personal and scientific contexts, posing a barrier for commercial adoption.
Health Check
Last Commit

1 month ago

Responsiveness

1 week

Pull Requests (30d)
0
Issues (30d)
1
Star History
1 stars in the last 30 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems") and Jeff Hammerbacher Jeff Hammerbacher(Cofounder of Cloudera).

self-adaptive-llms by SakanaAI

0.1%
1k
Self-adaptation framework for real-time LLM adaptation
Created 1 year ago
Updated 1 year ago
Starred by Eric Zhu Eric Zhu(Coauthor of AutoGen; Research Scientist at Microsoft Research), Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), and
1 more.

textgrad by zou-group

0.1%
4k
Autograd engine for textual gradients, enabling LLM-driven optimization
Created 2 years ago
Updated 1 year ago
Starred by Shizhe Diao Shizhe Diao(Author of LMFlow; Research Scientist at NVIDIA), Yineng Zhang Yineng Zhang(Inference Lead at SGLang; Research Scientist at Together AI), and
8 more.

EAGLE by SafeAILab

0%
3k
Speculative decoding research paper for faster LLM inference
Created 2 years ago
Updated 6 months ago
Feedback? Help us improve.