[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,90 +2,156 @@
|
||||
id: wiki-2026-0508-ai-safety-and-alignment
|
||||
title: AI Safety and Alignment
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-CANONICAL-AI-SAFETY-ALIGNMENT]
|
||||
aliases: [AI Alignment, AI Safety]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
tags: [canonical, ai-safety, alignment, rlhf, rlaif, constitutional-ai]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [ai-safety, alignment, rlhf, constitutional-ai]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-08
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: trl/transformers
|
||||
---
|
||||
|
||||
# [[AI_Safety_and_Alignment|AI Safety & Alignment]]
|
||||
# AI Safety and Alignment
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> "지능이 통제를 벗어나지 않게 하는 브레이크와 핸들." AI Safety는 적대적 공격과 오작동으로부터 시스템을 보호하는 '기술적 견고성(Robustness)'을, Alignment는 AI의 목표가 인간의 가치와 일치하도록 보정하는 'RLHF/Constitutional AI' 기술을 통해 인류 보편적 이익에 부합하는 초지능(AGI)을 구축하는 핵심 연구 분야입니다.
|
||||
## 매 한 줄
|
||||
> **"매 capable model 의 intended behavior 의 reliable production — 매 outer + inner alignment."** 매 RLHF (InstructGPT 2022) 로 시작 의 mainstream — 매 Constitutional AI (Anthropic 2022), DPO (2023), RLAIF (2023), 매 2026 에 deliberative alignment + interpretability-aware training 의 frontier.
|
||||
|
||||
---
|
||||
## 매 핵심
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
### 1. AI 정렬 (AI Alignment)의 핵심 메커니즘
|
||||
AI 정렬은 모델의 목표(Objective)가 인간의 의도(Intention) 및 가치(Value)와 일치하도록 만드는 과정입니다.
|
||||
* **외부 정렬 (Outer Alignment):** 모델에게 주어지는 보상 함수(Reward Function)나 손실 함수가 인간의 실제 목표를 정확히 반영하도록 설계하는 것. (예: "돈을 벌어라" -> "정당한 방법으로 가치를 창출하여 돈을 벌어라")
|
||||
* **내부 정렬 (Inner Alignment):** 모델 내부에서 스스로 생성한 하위 목표(Sub-goals)가 인간의 목표와 충돌하지 않는지 검증하는 것.
|
||||
* **기만적 정렬 (Deceptive Alignment):** 모델이 훈련 중에는 안전한 척 행동하다가, 배포 후 통제를 벗어났을 때 본래의 유해한 목표를 드러내는 위험 현상.
|
||||
### 매 alignment problem 분해
|
||||
- **Outer alignment**: 매 specified objective ≈ true human intent — 매 reward hacking, Goodhart's law.
|
||||
- **Inner alignment**: 매 trained policy 의 specified objective 의 optimization — 매 mesa-optimization, deceptive alignment.
|
||||
- **Scalable oversight**: 매 super-human capability 의 supervision — 매 debate, recursive reward modeling, weak-to-strong.
|
||||
|
||||
### 2. 주요 정렬 기술 (Techniques)
|
||||
* **RLHF (Reinforcement Learning from Human Feedback):** 인간의 선호도를 기반으로 보상 모델을 학습시키고, 이를 통해 언어 모델을 강화학습으로 정밀 튜닝하는 기법. 현대 LLM(GPT-4 등)의 표준 정렬 방식.
|
||||
* **헌법 AI (Constitutional AI):** Anthropic이 제안한 기법. 인간의 일일이 피드백 대신, 명문화된 '헌법(원칙)'을 AI에게 제공하고 AI가 스스로 자신의 답변을 비판/수정하도록 학습(RLAIF) 시키는 방식.
|
||||
* **RLAIF (RL from AI Feedback):** 인간 대신 정렬된 모델(Teacher)이 다른 모델(Student)의 답변을 평가하여 선호도 데이터를 생성하는 확장된 강화학습 체계.
|
||||
### 매 techniques (2026 stack)
|
||||
- **RLHF**: PPO on reward model from preferences.
|
||||
- **DPO / IPO / KTO**: 매 reward-model-free preference optimization.
|
||||
- **Constitutional AI**: 매 written principles → self-critique → RLAIF.
|
||||
- **Deliberative alignment** (OpenAI o-series, Claude 4.x): 매 reasoning trace 의 spec lookup.
|
||||
- **Interpretability**: SAEs, circuits — 매 feature steering.
|
||||
|
||||
### 3. AI 안전 (AI Safety)의 3대 기둥
|
||||
* **기술적 견고성 (Technical Robustness):** 적대적 공격(Adversarial Attack)이나 예외적인 입력값(Out-of-distribution)에도 시스템이 붕괴하지 않고 안전 모드를 유지하는 능력.
|
||||
* **해석 가능성 (Interpretability):** 신경망 내부의 블랙박스 연산 과정을 인간이 이해할 수 있는 논리 구조(Circuit)로 시각화하고 분석하는 기술(Mechanistic Interpretability).
|
||||
* **감시 및 통제 (Monitoring & Control):** 모델의 위험 징후를 실시간 감지하고, 필요시 즉시 기능을 차단하는 '킬 스위치(Kill-switch)' 및 샌드박스 환경 구축.
|
||||
### 매 응용
|
||||
1. Refusal of harmful requests + helpful behavior on benign edge cases.
|
||||
2. Policy compliance (privacy, copyright, weapons).
|
||||
3. Honesty / calibration.
|
||||
|
||||
### 4. 위험 시나리오 (Risk Scenarios)
|
||||
* **보상 해킹 (Reward Hacking):** 모델이 목표 달성 대신 보상 시스템의 허점을 이용해 가짜 성과를 내는 현상.
|
||||
* **목표 오일반화 (Goal Misgeneralization):** 훈련 환경에서는 올바른 목표를 학습한 것처럼 보이나, 새로운 환경에서 엉뚱한 방식으로 목표를 해석하여 행동하는 위험.
|
||||
## 💻 패턴
|
||||
|
||||
---
|
||||
### Reward model training (Bradley-Terry)
|
||||
```python
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
|
||||
## ⚖️ 트레이드오프 및 주의사항 (Trade-offs)
|
||||
* **성능 vs 안전 (Tax on Safety):** 엄격한 정렬은 모델의 창의성이나 추론 능력을 일부 제한할 수 있다는 비판이 있으나, 최근에는 정렬된 모델이 더 논리적인 사고를 수행한다는 '정렬 시너지'가 확인되고 있습니다.
|
||||
* **가치 중립의 한계:** "누구의 가치에 맞출 것인가?"에 대한 정치적/철학적 논쟁이 존재하며, 이는 기술적 정렬을 넘어 '민주적 거버넌스'의 영역으로 확장됩니다.
|
||||
def bt_loss(reward_chosen, reward_rejected):
|
||||
# P(chosen > rejected) = sigmoid(r_c - r_r)
|
||||
return -F.logsigmoid(reward_chosen - reward_rejected).mean()
|
||||
|
||||
---
|
||||
# Forward
|
||||
r_c = model(chosen_ids).logits[:, -1, 0]
|
||||
r_r = model(rejected_ids).logits[:, -1, 0]
|
||||
loss = bt_loss(r_c, r_r)
|
||||
```
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Parent:** [[10_Wiki/Topics]]
|
||||
- **Related:** [[Nodejs_and_Backend_Optimization]], [[Ethics_and_Future_of_AI]], [[Prompt_Engineering_Foundations]]
|
||||
- **Redirects:** [[AI_Safety]], [[AI_Alignment]], [[RLHF]], [[Constitutional_AI]], [[RLAIF]], [[Reward_Hacking]]
|
||||
### DPO loss
|
||||
```python
|
||||
def dpo_loss(pi_logp_c, pi_logp_r, ref_logp_c, ref_logp_r, beta=0.1):
|
||||
# Direct preference optimization
|
||||
chosen = beta * (pi_logp_c - ref_logp_c)
|
||||
rejected = beta * (pi_logp_r - ref_logp_r)
|
||||
return -F.logsigmoid(chosen - rejected).mean()
|
||||
```
|
||||
|
||||
---
|
||||
*Last updated: 2026-05-08*
|
||||
### Constitutional self-critique
|
||||
```python
|
||||
def constitutional_revise(prompt, response, principles, llm):
|
||||
critique = llm(f"""
|
||||
Principles: {principles}
|
||||
Prompt: {prompt}
|
||||
Response: {response}
|
||||
Critique the response against the principles.
|
||||
""")
|
||||
revised = llm(f"""
|
||||
Original: {response}
|
||||
Critique: {critique}
|
||||
Revise the response to address the critique.
|
||||
""")
|
||||
return revised
|
||||
```
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### SAE feature steering (interpretability)
|
||||
```python
|
||||
# Sparse autoencoder feature ablation
|
||||
def steer(activations, sae, feature_idx, scale):
|
||||
z = sae.encode(activations)
|
||||
z[:, feature_idx] *= scale # 0 = ablate, >1 = amplify
|
||||
return sae.decode(z)
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
# Hook on residual stream
|
||||
hook = lambda x: steer(x, sae, refusal_feature_idx, scale=0.0)
|
||||
```
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### Best-of-N with RM
|
||||
```python
|
||||
def best_of_n(prompt, policy, rm, n=64):
|
||||
samples = [policy.sample(prompt) for _ in range(n)]
|
||||
scores = [rm.score(prompt, s) for s in samples]
|
||||
return samples[int(torch.tensor(scores).argmax())]
|
||||
```
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
### Red-team probe
|
||||
```python
|
||||
def red_team_eval(model, attacks):
|
||||
results = []
|
||||
for attack in attacks:
|
||||
out = model.generate(attack.prompt)
|
||||
results.append({
|
||||
"attack": attack.name,
|
||||
"harmful": classify_harm(out),
|
||||
"refused": "I can't" in out or "I cannot" in out,
|
||||
})
|
||||
return results
|
||||
```
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Limited compute | DPO over PPO-RLHF |
|
||||
| Need transparent specs | Constitutional AI |
|
||||
| Frontier model | Deliberative alignment + scalable oversight |
|
||||
| Behavior debugging | SAE feature steering |
|
||||
| Pre-deployment | Red-team + capability evals |
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
**기본값**: 매 SFT → DPO → eval → iterate. 매 PPO 의 only-when-needed.
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
## 🔗 Graph
|
||||
- 부모: [[Machine Learning]] · [[AI Ethics]]
|
||||
- 변형: [[RLHF]] · [[DPO]] · [[Constitutional AI]] · [[RLAIF]]
|
||||
- 응용: [[Claude]] · [[GPT-5]] · [[Llama Guard]]
|
||||
- Adjacent: [[Mechanistic Interpretability]] · [[Red Teaming]] · [[AI Governance]]
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 production deployment 전 의 alignment pipeline (SFT + preference training + evals).
|
||||
**언제 X**: 매 pure capability research, 매 internal-only sandbox.
|
||||
|
||||
- **과거 데이터와의 충돌:** 없음
|
||||
- **정책 변화:** 없음
|
||||
## ❌ 안티패턴
|
||||
- **Reward hacking**: 매 proxy metric 의 over-optimization — 매 KL penalty, eval diversity.
|
||||
- **Sycophancy**: 매 user agreement 의 over-reward — 매 truthfulness 의 explicit reward.
|
||||
- **Over-refusal**: 매 false-positive harmful detection — 매 helpfulness eval 의 balance.
|
||||
- **Single-axis eval**: 매 only safety, no capability — 매 Pareto frontier.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Anthropic Constitutional AI paper, OpenAI InstructGPT, Rafailov et al. DPO 2023).
|
||||
- 신뢰도 A.
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — alignment stack with code patterns |
|
||||
|
||||
Reference in New Issue
Block a user