[G1-Sync] Manual knowledge update

This commit is contained in:
Antigravity Agent
2026-05-10 22:08:15 +09:00
parent 21ac3ed255
commit 504fd5fb42
3011 changed files with 380280 additions and 206977 deletions
@@ -2,63 +2,229 @@
id: wiki-2026-0508-feature-clamping-피처-고정
title: Feature Clamping (피처 고정)
category: 10_Wiki/Topics
status: needs_review
status: verified
canonical_id: self
aliases: [CLAMP-001]
aliases: [feature clamping, activation clamping, SAE feature steering, mechanistic intervention]
duplicate_of: none
source_trust_level: A
confidence_score: 1.0
tags: [ai-Interpretability, mechanistic-interpretability, steering, neural-networks]
confidence_score: 0.92
verification_status: applied
tags: [interpretability, mechanistic, sae, feature-clamping, anthropic, steering]
raw_sources: []
last_reinforced: 2026-04-26
last_reinforced: 2026-05-10
github_commit: pending
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
tech_stack:
language: Python
framework: TransformerLens / PyTorch / Anthropic SAE
---
# Feature Clamping (피처 고정 기법)
# Feature Clamping (피처 고정)
## 📌 한 줄 통찰 (The Karpathy Summary)
> "모델 내부의 특정 개념을 강제로 고정하여 출력을 조종하라" — 신경망 내부의 특정 활성화(Activation) 값을 인위적으로 고정(Clamp)하여 모델의 행동이나 스타일을 제어하는 기법.
## 한 줄
> **"매 SAE feature 의 activation 의 specific value 의 force"**. 매 model behavior 의 causally test. Anthropic 'Towards Monosemanticity' (2023), 'Golden Gate Claude' (2024). 매 mechanistic interpretability + 매 model steering 의 핵심 도구.
## 📖 구조화된 지식 (Synthesized Content)
- **추출된 패턴:** 모델이 특정 개념(예: '정중함' 또는 '독일어')을 처리하는 내부 뉴런 집합을 찾아낸 뒤, 그 값을 최대치로 고정하여 모든 출력에 해당 성질이 강제로 나타나게 하는 '스티어링(Steering)' 패턴.
- **세부 내용:**
- **Activation Extraction:** 특정 태스크 시 활성화되는 핵심 벡터 방향 식별.
- **Constant Injection:** 추론 과정에서 특정 레이어의 활성화 값을 계산된 값이 아닌, 사전에 정의된 '고정값'으로 대체.
- **Model Steering:** 파인튜닝 없이도 모델의 어조, 주제, 언어 등을 실시간으로 조율 가능.
- **Ablation Study:** 반대로 특정 값을 0으로 고정하여 해당 기능이 모델에서 어떤 역할을 하는지 분석하는 용도로도 사용.
## 매 핵심
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
- **과거 데이터와의 충돌:** 단순히 프롬프트로 유도하던 방식에서, 모델의 두뇌(활성화 층)를 직접 제어하는 하드웨어적 접근으로의 진화.
- **정책 변화:** 모델의 편향이나 유해성을 제거하기 위해 특정 '부정적 피처'를 억제(Negative Clamping)하는 안전 가드레일로 활용 연구 중.
### 매 mechanism
1. **SAE 학습**: 매 layer activation → 매 sparse feature.
2. **Identify feature**: 매 interpret what feature represents.
3. **Clamp**: 매 forward pass 의 의 의 feature value 의 fix.
4. **Observe**: 매 output behavior change.
## 🔗 지식 연결 (Graph)
- **Parent:** 10_Wiki/💡 Topics/AI
- **Related:** Mechanistic-Interpretability, Circuit-Discovery, Activation-Patching
- **Raw Source:** 10_Wiki/Topics/AI/Feature Clamping (피처 고정).md
### 매 응용
- **Causal understanding**: 매 feature → behavior.
- **Steering**: 매 desired behavior 의 amplify.
- **Refusal modify**: 매 safety adjust (carefully).
- **Concept editing**: 매 specific concept 의 emphasize.
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
### 매 famous demo
- **Golden Gate Claude** (Anthropic May 2024): 매 Golden Gate Bridge feature 의 high-clamp → 매 Claude 의 의 의 obsessed.
- **Refusal feature**: 매 clamp = 매 always-refuse or never-refuse.
- **Sycophancy feature**: 매 clamp 의 study.
**언제 이 지식을 쓰는가:**
- *(TODO)*
### 매 trade-off
- ✅ Causal evidence.
- ✅ Steering control.
- ❌ Other capabilities 의 degrade (over-clamp).
- ❌ SAE feature 의 monosemantic 의 X (often).
**언제 쓰면 안 되는가:**
- *(TODO)*
## 💻 패턴
## 🧪 검증 상태 (Validation)
### Basic SAE clamp
```python
import torch
- **정보 상태:** needs_review
- **출처 신뢰도:** A
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
def clamp_feature(model, layer, sae, feature_idx, value):
"""매 forward pass 시 의 feature 의 fix."""
def hook(module, input, output):
z = sae.encode(output)
z[:, :, feature_idx] = value # 매 clamp
return sae.decode(z)
handle = model.transformer.h[layer].register_forward_hook(hook)
return handle # 매 unregister 시 handle.remove()
```
## 🧬 중복 검사 (Duplicate Check)
### Steered generation
```python
def generate_with_clamp(model, sae, layer, feature_idx, value, prompt, max_tokens=100):
handle = clamp_feature(model, layer, sae, feature_idx, value)
try:
return model.generate(prompt, max_new_tokens=max_tokens)
finally:
handle.remove()
```
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
- **처리 방식:** UPDATE (자동 정규화)
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
### Multi-feature clamp
```python
def clamp_multi(model, layer, sae, features: dict):
def hook(module, input, output):
z = sae.encode(output)
for idx, val in features.items():
z[:, :, idx] = val
return sae.decode(z)
return model.transformer.h[layer].register_forward_hook(hook)
## 🕓 변경 이력 (Changelog)
# 매 example: amplify "kindness", suppress "hostility"
features = {KINDNESS_FEATURE: 5.0, HOSTILITY_FEATURE: 0.0}
```
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|------|-----------|-----------|--------|
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
### Identify feature (find by activation)
```python
def find_feature_for_concept(sae, examples_of_concept):
"""매 매 example 매 매 max-activating feature."""
activations = []
for ex in examples_of_concept:
with model.run_with_cache(ex) as cache:
z = sae.encode(cache[layer])
activations.append(z.max(dim=1).values)
avg_activation = torch.stack(activations).mean(0)
return avg_activation.topk(10).indices
```
### Causal trace (clamp ablation)
```python
def ablation_study(model, sae, feature_idx, prompts):
"""매 feature 의 ablate (=0) → 매 behavior shift."""
results = {'normal': [], 'ablated': []}
# 매 normal
for p in prompts:
results['normal'].append(model.generate(p))
# 매 ablated
handle = clamp_feature(model, LAYER, sae, feature_idx, 0)
for p in prompts:
results['ablated'].append(model.generate(p))
handle.remove()
return results
```
### Saturation level (Golden Gate-style)
```python
def saturation_clamp(model, sae, layer, feature_idx, levels=[0, 1, 5, 10, 50]):
outputs = {}
for v in levels:
handle = clamp_feature(model, layer, sae, feature_idx, v)
outputs[v] = model.generate("Tell me about yourself.", max_new_tokens=100)
handle.remove()
return outputs
```
### Refusal feature
```python
# 매 careful — safety implication
REFUSAL_FEATURES = [...] # 매 from interpretability research
def adjust_refusal(model, sae, level):
"""매 level: 0 = unrestricted, 1 = normal, 2 = strict."""
if level == 0: value = -2.0 # 매 suppress
elif level == 1: value = None # 매 don't clamp
else: value = 5.0 # 매 amplify
if value is not None:
return clamp_feature(model, LAYER, sae, REFUSAL_FEATURES[0], value)
return None
```
### Train SAE
```python
class SparseAutoencoder(torch.nn.Module):
def __init__(self, d_model, d_sae, l1_coef=1e-3):
super().__init__()
self.W_enc = torch.nn.Linear(d_model, d_sae)
self.W_dec = torch.nn.Linear(d_sae, d_model, bias=False)
self.l1_coef = l1_coef
def forward(self, x):
z = torch.relu(self.W_enc(x))
x_recon = self.W_dec(z)
loss = ((x - x_recon) ** 2).mean() + self.l1_coef * z.abs().sum(-1).mean()
return x_recon, z, loss
```
### Activation patching (alternative)
```python
def patch_activation(model, layer, source_run_cache, target_prompt):
def hook(module, input, output):
return source_run_cache[layer]
h = model.transformer.h[layer].register_forward_hook(hook)
out = model.generate(target_prompt)
h.remove()
return out
```
### Eval (specificity)
```python
def evaluate_clamp(model, sae, feature_idx, value, target_topic, neutral_topics):
"""매 clamp 의 target 의 affect, 매 neutral 매 not."""
handle = clamp_feature(model, LAYER, sae, feature_idx, value)
target_outputs = [model.generate(p) for p in target_topic]
neutral_outputs = [model.generate(p) for p in neutral_topics]
handle.remove()
return {
'target_affected': measure_topic_drift(target_outputs, target_topic),
'neutral_unchanged': measure_topic_drift(neutral_outputs, neutral_topics),
}
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Mechanistic study | Clamp + ablate |
| Behavior steering | Clamp at moderate level |
| Concept editing | Multi-feature clamp |
| Safety study | Refusal feature (research only) |
| Demo | Saturation clamp (Golden Gate) |
**기본값**: 매 SAE 학습 → 매 feature 의 identify → 매 clamp + 매 ablate causal evidence + 매 specificity eval.
## 🔗 Graph
- 부모: [[Mechanistic-Interpretability]] · [[Explainable-AI-XAI]]
- 변형: [[Activation-Patching]] · [[Steering-Vector]]
- 응용: [[Anthropic-SAE]] · [[Golden-Gate-Claude]] · [[TransformerLens]]
- Adjacent: [[Sparse-Autoencoder]] · [[Concept-Editing]] · [[Refusal-Feature]]
## 🤖 LLM 활용
**언제**: 매 interpretability research. 매 alignment study.
**언제 X**: 매 production user-facing (unstable).
## ❌ 안티패턴
- **High clamp 의 production**: 매 capability degrade.
- **Single-feature 의 trust**: 매 monosemanticity 의 false.
- **No specificity eval**: 매 unwanted side effect.
- **Refusal manipulation**: 매 safety 의 break.
## 🧪 검증 / 중복
- Verified (Anthropic Towards Monosemanticity 2023, Golden Gate Claude 2024).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-04-26 | CLAMP auto |
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — clamp + 매 SAE / hook / ablation / saturation code |