johnmarktaylor91/torchlens
Inspect, visualize and intervene on any operation in any neural network. Capture every activation and gradient, the full computational graph and 800+ metadata fields without changing model code. Supports PyTorch, JAX, TensorFlow, MLX, PaddlePaddle and tinygrad. Validated on 6400+ models. Built for researchers and their AI agents.
What it solves
TorchLens addresses the difficulty of inspecting, visualizing, and modifying the internal computations of PyTorch neural networks. It solves the "plumbing" problems of mechanistic interpretability by providing a unified way to extract intermediate activations, gradients, and metadata from any model without requiring manual hooks or code changes.
How it works
Everything begins with the tl.trace function, which runs your model as-is and logs every operation, module, and tensor result. This creates a comprehensive record of the model's computational graph. You can then use this trace to select specific activations, visualize the network structure, intervene on values using "do-calculus" (such as ablating heads or patching activations), and compare different model runs side-by-side.
Who it’s for
It is designed for researchers and developers working on mechanistic interpretability who need to understand how neural networks make decisions, debug model behavior, or experiment with steering model outputs.
Highlights
- Works with any PyTorch model, including those with complex control flows like loops and conditional branches.
- Captures over 800 metadata fields per operation, including FLOPs, memory usage, and source code location.
- Provides a simple, composable syntax for selecting and intervening on activations or gradients.
- Includes built-in debugging tools for identifying NaNs, dead neurons, and gradient health issues.
- Supports advanced visualization, including rolled/unrolled views of loops and custom node styling based on execution metrics.
Related
- Project
huggingface/transformersHugging Face Transformers is a library providing state-of-the-art pretrained models for inference and training across text, vision, audio, video, and multimodal tasks. It acts as a central model-definition framework compatible with many training frameworks, inference engines, and modeling libraries. Over 1 million model checkpoints are available on the Hugging Face Hub. It requires Python 3.11+ and PyTorch 2.6+, and offers a high-level Pipeline API for tasks like text generation, speech recognition, image classification, and visual QA. It's not a modular neural-net toolbox, and its training API is PyTorch-specific (use Accelerate for generic loops). The README also lists example models per modality and a citation for the EMNLP 2020 paper.
- Project
hiddenstateresearch/visualtorchVisualTorch is a Python library that visualizes PyTorch neural‑network architectures. It traces a real forward pass and can render the model as flow‑style, graph‑style, or LeNet‑style diagrams, optionally exporting animated GIFs that reveal layers step‑by‑step. Install via `pip install visualtorch` (or with the `[mcp]` extra for a generic stdio server). The tool is MIT‑licensed, documented, and cited in research papers.
- Project
LukeDitria/pytorch_tutorialsA collection of beginner-friendly PyTorch tutorials that assume basic Python and some deep learning knowledge, walking through implementations from basic ML algorithms to CNNs, autoencoders, reinforcement learning, and attention/transformers. Includes skeleton code, solutions, and companion YouTube videos.
- Project
ankane/torch.rbTorch.rb is a Ruby gem that brings PyTorch-style deep learning to Ruby, powered by LibTorch (PyTorch's C++ engine). It provides tensors, operations, automatic differentiation (autograd), neural network modules, optimizers, and model save/load — all following the PyTorch API with Ruby naming conventions. Installation requires downloading LibTorch first and takes 5–10 minutes to compile; Windows is unsupported. GPU acceleration works via CUDA on Linux and MPS on Apple silicon. The project includes companion libraries for vision, text, audio, and more, plus tutorials and examples for getting started.
- Project
Exorust/TorchLeetTorchLeet is a free collection of 68 real PyTorch interview problems (from Google, Meta, Anthropic, etc.) as Jupyter notebooks with question/solution pairs, organized into Basics, LLM Learning Path, and Advanced tracks, plus an MCP-based AI tutor that coaches without spoiling answers.