static-parameters

Analyze and disrupt massive values in LLM attention matrices to study contextual knowledge processing.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Understanding how large language models process contextual versus parametric knowledge requires inspecting internal attention states, which is difficult without dedicated tooling. This Skill provides scripts to extract Q/K/V attention matrices, identify massive values in low-frequency dimensions, and measure how disrupting them affects model performance on knowledge tasks. ## Core Features & Use Cases - Attention Extraction & Visualization: Hook into transformer layers of models like Llama, Mistral, Qwen, and Gemma to capture Q/K/V states and generate attention heatmaps. - Massive Value Identification: Detect outlier activations via percentile thresholds and analyze their frequency distribution with FFT. - Disruption Experiments: Replace massive values with mean, zero, or random values and measure accuracy drops on contextual knowledge QA and passkey retrieval tasks. - Use Case: A researcher investigating RoPE's role in contextual knowledge understanding runs a disruption experiment on Llama-2-7b, observing that zeroing top outliers in query matrices at layers 1, 2, and 10 degrades QA accuracy, confirming the ICML 2025 paper's findings. ## Quick Start Run the attention analysis script on a HuggingFace model with a sample prompt to extract Q/K/V states and visualize massive values across specified layers.

Frequently Asked Questions about static-parameters

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

FAQPage Schema
How do I extract attention Q/K/V matrices from a HuggingFace model?

Register forward hooks on each transformer layer's self-attention module to capture the outputs of q_proj, k_proj, and v_proj during a forward pass. The attention_analysis.py script implements this and saves the tensors as .pt files per layer.

How to identify massive values in transformer attention mechanisms?

Compute the L2 norm of each attention state vector and flag positions exceeding a percentile threshold, typically the 99th percentile. The script returns the layer, head, position, and magnitude of each detected massive value.

Which models support massive value attention analysis?

The tooling supports Llama, Mistral, Qwen, Gemma, GPT-2, GPT-Neo, GPT-NeoX, and Jamba through HuggingFace Transformers. Custom modeling files handle architecture-specific details like RoPE and grouped-query attention.

Does disrupting massive values affect LLM knowledge understanding?

Yes, replacing top outliers in query or key matrices with mean, zero, or random values measurably drops accuracy on contextual knowledge QA tasks. The disruption_experiment.py script quantifies this by comparing baseline and disrupted accuracy.

What datasets evaluate contextual knowledge after attention disruption?

The experiments use knowledge QA categories including city, aqua, imdb, sports, art, cele, and long, plus synthetic passkey retrieval datasets. Test files are loaded as JSON with context, question, and answer fields.