界面已本地化;技能介绍与说明文档按所选语言由 AI 自动翻译,代码、命令、路径和专业术语保留原文,以原作者文档为准。
探索技能
效率与协作 · SKILL.md

attention_path_expansion

attention_path_expansion

【效率与协作】Compute frozen-attention direct, head, and virtual-head path contributions for attention-only circuits.

独立 GitHub 快照 · 自动分类 · 以原作者文档为准

技能说明

GitHub

name: attention_path_expansion description: Compute frozen-attention direct, head, and virtual-head path contributions for attention-only circuits.

Attention Path Expansion

Use this skill when you have fixed or frozen attention patterns and want to decompose attention-only logits into additive circuit paths. It is suited for toy transformers, ablations, and mechanism checks inspired by Transformer Circuits. Do not use it for full transformers with changing layer normalization or MLP paths unless those parts are explicitly separated.

Inputs

  • Token ids and an embedding matrix.
  • Unembedding matrix.
  • One or more attention patterns shaped destination-position by source-position.
  • Matching OV matrices shaped model-by-model.

Outputs

  • Direct residual-to-logit contribution.
  • First-order per-head contributions.
  • Optional virtual-head contribution for a two-head sequence.
  • Maximum consistency error against explicit frozen-attention forward computation.

Workflow

  1. Embed tokens into residual states.
  2. Compute direct logits through the unembedding.
  3. Apply each head as attention @ residual @ OV and unembed the result.
  4. For two sequential heads, compute the virtual contribution A2 @ A1 @ residual @ OV1 @ OV2.
  5. Compare the expanded sum with an explicit sequential frozen-attention forward pass.

Validation

Run the deterministic tests or validate with the module-to-skill tree validator.

Limitations

The script implements the paper's simplified attention-only setting with supplied attention patterns. It intentionally does not implement softmax QK score construction.

我的收藏