dynamic-components

Identify and deactivate language-specific neurons in multilingual LLMs to analyze behavior changes.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Understanding which neurons control language-specific behavior in multilingual LLMs requires tedious manual analysis of activations across layers. This Skill provides scripts to load pre-identified language neurons, create deactivation masks, and measure the impact on perplexity and generation. ## Core Features & Use Cases - Neuron Loading & Analysis: Load pre-identified language-specific neurons from .neuron.pth files for LLaMA-2, BLOOM, OPT, Mistral, and Phi-2, with per-layer distribution statistics and cross-language overlap comparison. - Deactivation Mask Generation: Create binary activation masks for MLP or attention neurons at configurable deactivation ratios, including progressive deactivation experiments. - Perplexity Impact Measurement: Compute perplexity with and without neuron deactivation across languages (en, zh, fr, es, vi, id, ja) and visualize cross-lingual impact matrices. - Use Case: Deactivate Chinese-specific neurons in LLaMA-2-7B and measure how perplexity changes for Chinese versus other languages to verify neuron language specificity. ## Quick Start Analyze the language-specific neurons in LLaMA-2-7B and create a deactivation mask for Chinese neurons, then measure the resulting perplexity change.

Frequently Asked Questions about dynamic-components

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

FAQPage Schema
How do I identify language-specific neurons in multilingual LLMs?

Record neuron activations per language using activation.py, then run identify.py to extract language-specific neurons stored as .neuron.pth files. The load_neurons.py script loads these files and reports per-layer neuron distributions for each language.

How to deactivate specific neurons and measure perplexity change?

Use deactivate_neurons.py to generate an activation mask from a .neuron.pth file with a chosen language and ratio, then run compute_perplexity.py with the mask to compare perplexity with and without deactivation.

Which models support language-specific neuron analysis?

Pre-identified neuron files are available for LLaMA-2 7B/13B/70B, BLOOM-7B, OPT-6.7B, Mistral-7B, and Phi-2 2.7B. Each model has defined layer counts, hidden sizes, and intermediate sizes used for mask generation.

What languages are covered by the neuron identification data?

Seven languages are supported: English, Chinese, French, Spanish, Vietnamese, Indonesian, and Japanese. Each maps to a fixed index (0-6) in the neuron tensor structure for consistent cross-language analysis.

Does deactivating one language's neurons affect other languages?

Yes, neuron overlap between languages causes cross-lingual impact. The analyze_cross_lingual_impact function quantifies overlap per layer and overall impact ratios, showing which layers share neurons between language pairs.

What are the limitations of neuron deactivation analysis?

The perplexity script uses a simulated forward pass as a placeholder; real experiments require model hooks to intercept activations. Results also depend on pre-recorded activation files and correct model configuration matching.