--- id: wiki-2026-0508-feature-clamping-피처-고정 title: Feature Clamping (피처 고정) category: 10_Wiki/Topics status: verified canonical_id: self aliases: [feature clamping, activation clamping, SAE feature steering, mechanistic intervention] duplicate_of: none source_trust_level: A confidence_score: 0.92 verification_status: applied tags: [interpretability, mechanistic, sae, feature-clamping, anthropic, steering] raw_sources: [] last_reinforced: 2026-05-10 github_commit: pending tech_stack: language: Python framework: TransformerLens / PyTorch / Anthropic SAE --- # Feature Clamping (피처 고정) ## 매 한 줄 > **"매 SAE feature 의 activation 의 specific value 의 force"**. 매 model behavior 의 causally test. Anthropic 'Towards Monosemanticity' (2023), 'Golden Gate Claude' (2024). 매 mechanistic interpretability + 매 model steering 의 핵심 도구. ## 매 핵심 ### 매 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. ### 매 응용 - **Causal understanding**: 매 feature → behavior. - **Steering**: 매 desired behavior 의 amplify. - **Refusal modify**: 매 safety adjust (carefully). - **Concept editing**: 매 specific concept 의 emphasize. ### 매 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. ### 매 trade-off - ✅ Causal evidence. - ✅ Steering control. - ❌ Other capabilities 의 degrade (over-clamp). - ❌ SAE feature 의 monosemantic 의 X (often). ## 💻 패턴 ### Basic SAE clamp ```python import torch 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() ``` ### 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() ``` ### 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) # 매 example: amplify "kindness", suppress "hostility" features = {KINDNESS_FEATURE: 5.0, HOSTILITY_FEATURE: 0.0} ``` ### 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]] - Adjacent: [[Sparse-Autoencoder]] ## 🤖 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 |