neuron-explorer README

项目的 README,来自 github.com/lyramakesmusic/neuron-explorer。合并为一个 markdown 文件:README.md。

neuron explorer

Steering-first neuron explorer for Qwen3.5-4B. Every MLP neuron in a layer is pushed up and down on a few prompts, every rollout is kept, and the explorer lays the results out over a 3D view of the model.

neuron explorer

Explorer

uv sync
uv run python explorer/server.py        # http://localhost:8791

Reads sweep runs from runs/ and per-layer stats from stats/, both produced by the sweep below; the caches in explorer/cache/ ship with the repo. Loads Qwen3.5-4B locally (MPS, CUDA or CPU) for live steered chat, lens, connections and live inference over your own text.

The R and J++ lens rows read the maps of bubskee/qwen3.5-4b-r-jpp-lenses (Apache-2.0):

hf download bubskee/qwen3.5-4b-r-jpp-lenses --local-dir explorer/cache/rjpp

Sweep

Runs on a CUDA 13 GPU pod with the steering fork of vLLM (RhizoNymph/vllm).

bash sweep/setup_pod.sh                                   # fork, deps, model; writes /workspace/env.sh
python sweep/neuron_stats.py --layers 22 --tokens 2000000 --out stats/q35-4b
python sweep/steer_sweep.py --stats stats/q35-4b_L22.npz --design main_rel --dose-unit rel \
    --neurons all --random-controls 256 --run q35-4b-L22
sweep/run_depth.sh "4 9 13 17" 384 64                     # random-subset sweep across several layers

main_rel doses are fractions of the median residual norm leaving the layer: {who, snake, orange} × {−0.7, +0.5, +0.8} and {free} × {+3}, plus one unsteered baseline per prompt.

script output
sweep/neuron_stats.py per-neuron activation extremes by sign regime, down columns, residual norms
sweep/steer_sweep.py runs/<run>.jsonl: text, token ids, logprobs, top-k per step; optional activation captures
sweep/rank.py runs/<run>.units.jsonl: distinctive words, cluster mass, percentile against controls
sweep/steer_lens.py stats/steer_lens_L{l}.npz: next-token Δlogprob and KL for ±0.8 pushes on every neuron
sweep/depth_report.py runs/depth_report.json: per-layer share of neurons above controls, coherence, top units
sweep/shift.py word-shift score against controls, all words counted
sweep/merge_runs.py joins sharded runs of one layer
sweep/check_equivalence.py HF vs vLLM steering and capture agreement
sweep/bench.py, sweep/peek.py throughput conditions; terminal views of a run
explorer/build_embeddings.py runs/<run>.umap.json
explorer/build_layout.py explorer/cache/layout_writes.npz
explorer/build_connections.py explorer/cache/connections.npz: each neuron's 24 strongest direct-path links up and down
sweep/fit_input_lens.py S.pt: the fitted input map S_L (token embeddings to the residual each MLP reads, layers 0–31), RelP rules of safety-research/jpp_lens; shards over prompts, merged by num_prompts; copy to explorer/cache/slens/S.pt
explorer/build_s_index.py explorer/cache/s_index.npz: each neuron's top S-lens (read side) tokens, both poles
explorer/build_rjpp_index.py explorer/cache/r_index.npz, jpp_index.npz: each neuron's top R- and J++-lens tokens, both poles (needs the R/J++ release in explorer/cache/rjpp/)
sweep/finefineweb.py <out>/corpus.npz, urls.json, acts.npz: a domain-balanced FineFineWeb sample (about 20M tokens over 66 domains) and every neuron's top contexts per sign and per-domain activation statistics; copy the three files to explorer/cache/ffw/
sweep/capture_prefill.py captures/<run>.mlp_in.npy: MLP input at the last prompt token at the run's capture layers, steered

research_log.md holds the findings and reasoning; NOTES.md the source notes.

License

MIT, see LICENSE.

neuron-explorer (lyramakesmusic/neuron-explorer)

正在搜索数据库…

这是干什么的?这是一个以转向为核心的神经元探索工具,针对 Qwen3.5-4B。它会在一小批提示词上把每个 MLP 神经元向上和向下推动,保留每一次推演结果,并把这些结果展示在该模型的交互式 3D 视图中。
这是科研工具还是打包好的应用?这是一个本地科研工具:一个 Python 服务器(explorer/server.py),在浏览器中提供交互式 3D 探索器,后端使用预先计算好的扫描数据,并实时加载 Qwen3.5-4B 模型。
我怎么把探索器跑起来?运行 'uv sync',然后运行 'uv run python explorer/server.py';它会加载随仓库一起提供的预构建扫描缓存,所以无需自己跑扫描,就能直接浏览。
自己跑神经元扫描容易吗?不太容易。需要一台 CUDA 13 的 GPU 实例,以及通过 sweep/setuppod.sh 配置的定制转向版 vLLM 分支(RhizoNymph/vllm),还要依次运行多个脚本(neuronstats.py、steersweep.py、rank.py、steerlens.py 等),结果才能输入探索器。
地图、列表、神经元和嵌入这几个视图各显示什么?地图在 3D 中展示模型的各层,每个神经元对应一个点,并按投影相似度着色;列表按词簇强度对神经元排序,并支持搜索透镜;神经元视图按提示词和剂量展示转向后的推演结果,并提供三列(−、0、+)的转向聊天;嵌入视图展示某一层推演结果的 UMAP 图,可按神经元、提示词、剂量或类型着色。
Claude 标签页究竟做什么?它通过 MCP 服务器(agentmcp.py)把 Claude CLI 连接到探索器,以聊天形式使用:可以读取神经元、cones 和透镜,运行实时的转向、激活和消融查询,移动地图并设置高亮,还有文件工具,以及主目录中的一个 shell。
转向扫描中的'剂量'是什么意思?剂量是指离开某一层的残差范数中位数的比例。例如,默认设计会把提示词 'who'、'snake'、'orange' 分别推动 ±0.7/+0.5/+0.8,把 'free' 推动 +3,同时每个提示词还保留一个未转向的基线。
我能用自己的文本代替预设提示词来跑模型吗?可以。列表视图中的 'fires' 工具可以让你的文本在模型中运行,并按激活值筛选神经元;Claude 标签页也能对任意文本运行实时推理。
大小
150.9 MB
星标
2K
更新
提交Nov 01
时长
28天
提交 · 90 天