iT邦幫忙

2026 iThome 鐵人賽

DAY 14
0
AI Security

打開黑盒子:大型語言模型的機制解釋性入門系列 第 14

Day 14|Feature 的意義找到了,但模型怎麼使用它?

  • 分享至 

  • xImage
  •  

前兩篇中,我們先用 Sparse Autoencoder,把模型某個位置的 dense activation 分解成一組 sparse features;接著透過 activating examples、minimal pairs、logit information 與 steering,替其中一個 feature 建立可以被反駁的 interpretation。但即使我們真的得到一本很好的 feature dictionary,我們得到的資訊仍然只是模型在這個位置表示了什麼,而還是不知道模型如何把這些資訊一步步轉換,最後形成答案。

例如,在我們一路追查的 factual recall 問題裡,假設某個 layer 出現了與 Taiwan 有關的 feature,後面的 layer 也出現了會提高 Taipei 機率的 feature,我們仍然不知道前者是否真的促成了後者?中間經過了哪個 MLP 或 Attention Head?還有哪些 features 一起參與?

Day 8 的 Path/Attribution Patching 已經讓我們可以估計某個 component 或 edge 對特定輸出的影響。但如果 edge 的兩端仍然是整個 MLP、整組 neurons,或難以命名的 activation,得到的路徑依然很難轉換成人能理解的 computation。今天的問題因此更具體:我們能不能把 MLP 本身改寫成一組 sparsely active、比較容易解釋的 input-output features,讓模型的轉換也能以 feature level 表示?

這就是 Transcoder 想處理的問題。

SAE 描述狀態,Transcoder 近似轉換

先回想 SAE 的任務。它讀入一個 activation x,再嘗試重建同一個 activation:

https://ithelp.ithome.com.tw/upload/images/20260910/20183469RQ7STUxkNN.png

所以 SAE 比較像在問這個 activation 可以由哪些 sparse features 組成?

但 Transformer 裡的 MLP 做的是一個轉換。令 x 是 MLP input、y 是 MLP output:

https://ithelp.ithome.com.tw/upload/images/20260910/20183469ngNZdmjph6.png

Transcoder 不再重建 x,而是讀取 x,再嘗試預測原本 MLP 產生的 y:

https://ithelp.ithome.com.tw/upload/images/20260910/201834699rh3znFoN7.png

https://ithelp.ithome.com.tw/upload/images/20260910/20183469WiZc2BRag6.png

訓練時同時要求 hat{y} 接近真正的 MLP output,而且每次只有少數 transcoder features 啟用:

https://ithelp.ithome.com.tw/upload/images/20260910/20183469mT6K9GYIHf.png

如果把這件事寫成簡化版 code,核心大概是:

with torch.no_grad():
    target = original_mlp(mlp_input)

features = relu(encoder(mlp_input))
prediction = decoder(features)

loss = mse(prediction, target) + sparsity_weight * features.abs().sum()

原本 Transformer 的參數不會在這個過程中被更新;我們另外訓練一個 sparse model 去模仿它的 MLP computation。

https://ithelp.ithome.com.tw/upload/images/20260910/20183469Sr2tagCRLc.png

最核心的差別可以濃縮成一句話,SAE 嘗試分解一個狀態;Transcoder 嘗試近似一個轉換。

一個 Transcoder Feature 是一條簡單的 Input-Output Rule

一個 transcoder feature i 同時具有 encoder vector e_i 和 decoder vector d_i。

  • Encoder 決定:什麼樣的 MLP input 會讓它 activate?
  • Decoder 決定:它 activate 之後,會向 MLP output 寫入什麼方向?

可以把它粗略理解成:

如果 input 符合某個 pattern
        ↓
Feature i activate,強度為 z_i(x)
        ↓
向 MLP output 寫入 z_i(x) · d_i

因此,Transcoder 不只替 feature 提供「它像什麼」的描述,也提供一條簡單的 input-output rule:什麼時候觸發,以及觸發後寫入什麼。這也讓兩個 features 之間的 connection 變得比較容易計算。假設較早的 feature i 寫入 decoder direction d_i,較晚的 feature j 使用 encoder direction e_j 讀取 Residual Stream。在忽略 attention 與 normalization 細節的簡化情況下,i 對 j 的 contribution 可以寫成:[1]

https://ithelp.ithome.com.tw/upload/images/20260910/20183469P9Fb8fAbbs.png

這個式子把 edge 拆成兩部分:

  • z_i(x) 是 input-dependent:換一個 prompt,feature activation 就可能改變;
  • d_i^{\top}e_j 是 input-invariant:Transcoder 訓練完成後,這個權重不會隨 prompt 改變。

這正是它和 Day 8 的 attribution 方法最重要的差異之一。Attribution Patching 主要估計「在這次輸入上,改動這裡可能造成多大效果」;Transcoder 則另外提供一個由 weights 決定、可以跨 inputs 檢查的 candidate connection。把固定的連接強度和當下的 activation 合在一起,我們才得到這條 edge 在特定 prompt 上的 contribution。但要注意,這個數值仍然來自 Transcoder approximation。它是一條值得驗證的 mechanistic hypothesis,不會自動成為原模型裡已經證實的 causal edge。

https://ithelp.ithome.com.tw/upload/images/20260910/20183469p8XpGkVXIh.png

真的有比 Neurons 更容易理解嗎?

Dunefsky、Chlenski 與 Nanda 在 2024 年用 GPT-2 Small 的 greater-than circuit 測試這個問題。[1] 考慮這個 prompt:

The war lasted from the year 1732 to the year 17

接下來合理的兩位數年份應該大於 32,例如 334087,而不應該是 1225。先前研究已經發現,部分 Attention Heads 會把起始年份末兩位的資訊移到最後的位置,後期 MLPs 則會提高大於該數字的年份 logits。[4] Transcoder 分析在這個已知 circuit 中找回了相近的結構:Layer 10 的重要 transcoder features,會受到較早的數字相關 features 經由 Layer 9 Head 1 的影響。這些 Layer 10 features 大致會對特定年份範圍 activate,並提高後續年份的 logits。[1] 簡化後可以想成:

起始年份末兩位的資訊,例如 32
                ↓ 透過 Attention Head 傳遞
與特定年份範圍相關的 Transcoder Features
                ↓ 寫入 output directions
提高 33、34、35、… 等後續年份的 logits

研究者保留少量重要 transcoder features 時,就能恢復原模型在這項任務上的大部分表現;若改用原始 MLP neurons,則需要保留更多單位才能達到相近效果。這提供了一項具體證據:至少在這個案例裡,Transcoder 確實能把一段 dense MLP computation 改寫成比較稀疏、比較容易描述的 approximation。不過它沒有完整恢復原模型的表現,其中也存在會造成反效果的 feature。因此,這個案例支持的是「Transcoder 提供了一個有用的稀疏近似」,而不是「Transcoder 已經完整找回原模型真正的演算法」。

為什麼單層 Transcoder 還不夠?

一般 Transcoder 只近似一個 MLP:

Layer 5 MLP input
        ↓
Layer 5 Transcoder features
        ↓
Predict Layer 5 MLP output

但 Transformer 的 computation 不會在每層結束後重新開始。Residual Stream 會把資訊一路向後傳遞,而不同 layers 也可能反覆放大或維持相近的 representation。如果每一層都獨立訓練一個 Transcoder,一項資訊可能被表示成:

Layer 3:Taipei-related feature
        ↓
Layer 4:Taipei-related feature
        ↓
Layer 5:Taipei-related feature
        ↓
Layer 6:Taipei-related feature

最後得到一條很長的 amplification chain。我們很難判斷這是四個不同的 computational steps,還是同一項資訊在不同 layers 中被反覆維持。這是 Cross-Layer Transcoder(CLT) 想改善的問題。[2]

Cross-Layer Transcoder:讓早期 Feature 解釋後續多層輸出

CLT 把 features 分配到不同 layers,所有 layers 的 features 則一起訓練。

位於 Layer l 的 features,會從該層的 Residual Stream x^{l} 讀取資訊:

https://ithelp.ithome.com.tw/upload/images/20260910/20183469ie82IInEAY.png

但它的 decoder 不只可以貢獻到同一層,也能參與重建所有後續 MLP outputs。Layer l 的重建結果為:

https://ithelp.ithome.com.tw/upload/images/20260910/20183469DVhXQCgUIU.png

其中,

https://ithelp.ithome.com.tw/upload/images/20260910/20183469bxguaW34kb.png

表示 Layer l 的 features 對 Layer l MLP output 所使用的 decoder weights。不需要記住公式。重要的直覺是:如果一項資訊在早期形成,並持續影響後面幾層的 MLP outputs,CLT 可以用同一個早期 feature 的多組 decoder weights 來近似這些影響,而不必在每一層重新建立一個近乎重複的 feature。

這裡要特別小心用詞。它不表示原始 Transformer 裡真的新增了一條「Layer 3 直接連到 Layer 9 MLP」的電線;這是 CLT 用來近似多層 computation 的表示方式。它可以把 graph 變短、減少重複,但也可能因此改變原模型真正的 causal structure。

https://ithelp.ithome.com.tw/upload/images/20260910/201834699ySpQvG609.png

從公式到可以執行的 Pipeline:CLT-Forge

真正訓練與分析 CLT,還需要處理大量工程問題:怎麼收集每一層的 activations?資料大到放不進記憶體時怎麼 cache?CLT 本身太大時怎麼分散到多張 GPUs?訓練完成後,又怎麼替 features 產生 descriptions、建立 attribution graph 並進行 intervention?

CLT-Forge 是 2026 年釋出的 open-source library,把這些步驟整合成一套 end-to-end pipeline:[5]

Cache model activations
        ↓
Train a Cross-Layer Transcoder
        ↓
Inspect and auto-interpret features
        ↓
Compute attribution graphs with Circuit-Tracer
        ↓
Visualize and test interventions

它也提供 activation compression、feature-wise GPU sharding 與 sparse decoding,讓研究者能把同一套流程擴展到更大的 CLTs。官方 tutorial 則使用 GPT-2 與 TinyStories,在免費的 T4/L4 Colab GPU 上訓練一個小型 CLT,讓我們不必先準備大型 GPU cluster,也能實際看到 activation caching、CLT training、sparsity 與 reconstruction 的完整流程。不過,工具把實驗變得容易執行,不代表它自動解決了解釋上的問題。CLT-Forge 產生的 features 與 graphs,仍然必須接受後面會談到的 faithfulness evaluation 與 intervention tests。

這篇也附上使用 CLT-Forge 的 companion notebook。我們會在一個小型 TinyStories 模型上,實際收集 activations、訓練 CLT,並觀察 reconstruction error 與 feature sparsity;接著用 CLT 重建值取代原本的 MLP outputs,比較 replacement model 和原模型的 next-token predictions。今天重點不是找出完整 circuit,而是親手確認:MLP outputs 重建得不錯,是否就代表模型的行為也能保留下來?

Replacement Model 不是只畫一張圖

CLT 訓練好之後,研究者可以真的修改 forward pass:

  1. Attention layers 仍然使用原模型的 computation;
  2. 每一層原本的 MLP output 被移除;
  3. 改用當前與先前 CLT features 的 decoder outputs 加總取代。

這會得到一個 replacement model:

Original attention computation
              +
CLT reconstruction of every MLP output
              ↓
Replacement model prediction

因此,CLT 不是單純替原模型的 activation 貼標籤。它建立了一個真的可以執行、但比較 sparse 的 proxy model。Anthropic 在其實驗中發現,較大的 CLT replacement models 能在約一半的 evaluated completions 上,產生和原模型相同的 top-1 token;Cross-Layer Transcoder 也比參數量相近的 per-layer Transcoders 產生更短的 attribution paths。[2]

這兩個結果分別回答不同問題:

  • Behavioral approximation:replacement model 的輸出有多接近原模型?
  • Graph simplicity:同一段 behavior 能否用更短、更稀疏的 feature paths 描述?

有了可以執行的 replacement model,研究者就能針對一次具體回答,從 target logit 往回計算:哪些 active features 對它有正向或負向 contribution?這些 features 又受到哪些 embeddings、earlier features 或 Attention Heads 影響?最後便能產生下一篇要介紹的 Attribution Graph。

Reconstruction 正確,不代表 Mechanism 正確

假設 CLT 能準確預測一個 MLP output,甚至讓 replacement model 輸出和原模型相同的 token,是否代表它使用了和原模型相同的 mechanism?

不一定。不同的演算法可以產生相同的答案。

這裡至少要區分三種問題:

  1. Reconstruction fidelity:CLT 能否重建原本的 MLP outputs?
  2. Behavioral fidelity:換成 CLT 後,model loss、logits 與 completions 是否接近原模型?
  3. Mechanistic fidelity:CLT features 與它們之間的 interactions,是否真的對應原模型使用的 computation?

前兩項做得好,不會自動保證第三項。例如,CLT 可能把原模型跨越數層的 amplification chain,壓縮成一個早期 feature 直接寫向多個後期 outputs。這讓 attribution graph 更短、更容易閱讀,但如果原模型確實依靠中間那串互相強化的 features,replacement model 就改寫了原本的 causal story。[2]

Olah 也用 toy model 說明,Sparse replacement model 可能在 input-output behavior 上很 faithful,內部卻使用不同的 algorithm。[3] 因此 Functional faithfulness 不等於 mechanistic faithfulness。此外,CLT 目前主要取代 MLPs,Attention computation 仍然來自原模型;重建誤差也不會憑空消失。Attribution Graph 中必須保留 error nodes,並透過 steering、ablation 或其他 interventions,檢查圖所提出的路徑是否真的能預測原模型的反應。[2]

所以 Attribution Graph 最好被理解成「根據一個 sparse replacement model 所提出、等待 intervention 驗證的 mechanistic hypothesis」而不是模型內部唯一且完整的真相。

從 Feature Dictionary 到一張可以檢驗的計算圖

我們現在可以把這幾天的內容重新排成三個問題:

Sparse Autoencoder
→ 某個位置的 activation 可以分解成哪些 features?

Transcoder/Cross-Layer Transcoder
→ MLP input 如何被近似轉換成 sparse feature outputs?

Attribution Graph
→ 在這次 prompt 中,哪些 active features 與 interactions 推動了 target output?

Transcoder 的關鍵貢獻不是替 SAE features 多畫幾條箭頭,而是另外學出一個 sparse、可執行的 MLP approximation,使 feature-to-feature contributions 更容易被計算。Cross-Layer Transcoder 再把這個想法延伸到多層 computation,讓跨層重複出現的資訊可以得到更簡潔的描述。但這份簡潔來自 replacement model,也帶來新的 faithfulness 問題。下一篇,我們會正式進入 Anthropic 的 Circuit Tracing,以 On the Biology of a Large Language Model 為主要案例,看看 Attribution Graph 實際長什麼樣子、研究者如何閱讀它,以及為什麼圖上的漂亮故事仍然需要 intervention 才能相信。

參考資料與延伸閱讀

[1] Dunefsky, J., Chlenski, P., & Nanda, N., “Transcoders Find Interpretable LLM Feature Circuits”, Advances in Neural Information Processing Systems (NeurIPS), 2024. https://arxiv.org/abs/2406.11944

[2] Ameisen, E., Lindsey, J., Pearce, A., et al., “Circuit Tracing: Revealing Computational Graphs in Language Models”, Transformer Circuits, 2025. https://transformer-circuits.pub/2025/attribution-graphs/methods.html

[3] Olah, C., “A Toy Model of Mechanistic (Un)Faithfulness”, Transformer Circuits, 2025. https://transformer-circuits.pub/2025/faithfulness-toy-model/

[4] Hanna, M., Liu, O., & Variengien, A., “How Does GPT-2 Compute Greater-Than? Interpreting Mathematical Abilities in a Pre-Trained Language Model”, Advances in Neural Information Processing Systems (NeurIPS), 2023. https://arxiv.org/abs/2305.00586

[5] Draye, F., Palit, V., Harrasse, A., et al., “CLT-Forge: A Scalable Library for Cross-Layer Transcoders and Attribution Graphs”, 2026. https://arxiv.org/abs/2603.21014 Code: https://github.com/LLM-Interp/CLT-Forge


上一篇
Day 13|SAE 拆出了 Features,但我們怎麼知道它們代表什麼?
下一篇
Day 15|黑盒子裡的線索,終於能拼成一張圖了嗎?
系列文
打開黑盒子:大型語言模型的機制解釋性入門27
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言