Magnitude Analysis

Scores LLM internal components by magnitude to identify salient weights, neurons, and layers.

75|7|Updated May 2, 2026
One-click install
npx skills add https://github.com/zjunlp/Mechanist --skill magnitude-analysis-zjunlp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Magnitude Analysis
Source: https://github.com/zjunlp/Mechanist/tree/main/skills/mechanism-skills/magnitude-analysis
Command: npx skills add https://github.com/zjunlp/Mechanist --skill magnitude-analysis-zjunlp

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, transformers, numpy, matplotlib, tqdm, and includes scripts (resource) and references (resource) components.

What problem does it solve? Interpreting large language models requires finding which internal components matter most, but training probes or running backward-pass attribution is expensive. Magnitude Analysis provides a lightweight first-pass screening method that ranks weights, neurons, and layer representations by numerical magnitude to surface candidate components for deeper causal verification. ## Core Features & Use Cases - Static Parameter Analysis: Compute per-weight or per-row norms of weight matrices to find massive values and heavy hitters in attention mechanisms, including RoPE-based models, without running inference. - Dynamic Component Ranking: Rank neurons by activation statistics to localize specialized capabilities, such as language-specific neurons in multilingual models like LLaMA-2, BLOOM, OPT, Mistral, and Phi-2. - Layer-wise Representation Comparison: Measure layer-wise distances across contrastive inputs to localize task-relevant layers, demonstrated with TruthX for editing representations to improve truthfulness. - Use Case: A researcher investigating hallucinations uses layer-wise magnitude comparison to find where truthful representations diverge, then applies TruthX editing vectors to those layers and evaluates on TruthfulQA. ## Quick Start Ask the assistant to analyze massive values in a Llama model's attention matrices and visualize which layers and heads contain the largest activations.

Frequently Asked Questions about Magnitude Analysis

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find important neurons in an LLM without training probes?

Rank neurons by activation magnitude statistics across inputs to localize specialized components. This magnitude-based screening requires only forward passes and no auxiliary classifiers, making it scalable to large models like LLaMA-2 and BLOOM.

How to detect massive values in transformer attention mechanisms?

Extract Q, K, V projections via forward hooks, compute L2 norms across the hidden dimension, and flag positions exceeding a high percentile threshold. The included attention analysis script visualizes these outliers per layer and head.

Does high activation magnitude prove a neuron is causally important?

No. Magnitude indicates presence, not causal necessity, since a high-magnitude feature can be cancelled by later layers. Treat magnitude analysis as a first-pass filter whose candidates need verification through ablation or disruption experiments.

Which models support language-specific neuron identification?

Pre-identified neuron files cover LLaMA-2 (7B, 13B, 70B), BLOOM-7B, OPT-6.7B, Mistral-7B, and Phi-2. The scripts load these neuron indices, build deactivation masks, and measure perplexity changes across seven languages.

How does TruthX reduce LLM hallucinations?

TruthX applies editing vectors to internal representations at selected layers during inference, steering outputs toward truthful or hallucinatory modes. The included scripts demonstrate editing Llama-2-7b-chat and evaluating results on the TruthfulQA benchmark.