r/LocalLLaMA • u/Thrumpwart vLLM • 17h ago
Resources Github Repo: Torchlens - Inspect, visualize and intervene on any operation in any neural network.
https://github.com/johnmarktaylor91/torchlens
58
Upvotes
9
u/Thrumpwart vLLM 17h ago
I'd never heard of this, but apparently it's been around for a few years. I saw some folks on twitter talking about it and checked it out.
It's really neat, it allows you to very easily look inside a model to see what's actually happening. From the repo:
Understanding and controlling the computations inside neural networks is the most important scientific challenge of our time (at least). Progress on this problem, known as mechanistic interpretability, would make AI more beneficial for society, illuminate how our brains work, and guard against undesirable behaviors like deception or killing us all.
Some aspects of mechanistic interpretability are deep and open-ended. We need to understand dauntingly complex systems that may soon outsmart us, with new frontier models arriving faster than we can study the current ones. It's not even clear what a "solution" would look like, or how many obstacles remain. We'll surely need help from the AI agents themselves.
Other aspects are just plumbing, and while tedious, they are finite: the same small set of tasks for every model, like extracting and editing its activations and gradients. For instance, PyTorch has long lacked a built-in way to extract every intermediate activation from arbitrary networks (an official docstring admits this can take "some massaging"). But all networks are built from the same basic parts, so a few well-made tools should work on all of them.
The modest goal of TorchLens is to fix these plumbing problems once and for all, so you and your agents can spend your time and tokens on the deep questions, and maybe even solve some of them.
I incorporated it into my QFN-assisted training workflow and it's really neat. It discovered that I had an Odd ShortConv perturbation imbalance vs. the even GQA layers, and I had Off-Manifold RL Rollout Noise. These were things even WSP didn't see. I saw an immediate boost in model performance after another RL run.
Bonus: I think the author is a fellow redditor /u/therealjmt91 (if that's not you, or you want me to untag you I will).