[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,74 +2,207 @@
id: wiki-2026-0508-스테이블-디퓨전의-가중치-및-제어-시스템
title: 스테이블 디퓨전의 가중치 및 제어 시스템
category: 10_Wiki/Topics
status: needs_review
status: verified
canonical_id: self
aliases: []
aliases: [SD Weight Control, Stable Diffusion Weights, Prompt Weighting, ControlNet]
duplicate_of: none
source_trust_level: A
confidence_score: 0.92
tags: [uncategorized]
confidence_score: 0.9
verification_status: applied
tags: [stable-diffusion, weights, controlnet, image-generation, prompt-engineering]
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: Diffusers/ComfyUI
---
# [[스테이블 디퓨전의 가중치 및 제어 시스템|스테이블 디퓨전의 가중치 및 제어 시스템]]
# 스테이블 디퓨전의 가중치 및 제어 시스템
## 📌 한 줄 통찰 (The Karpathy Summary)
스테이블 디퓨전(Stable Diffusion)의 가중치 및 제어 시스템은 텍스트 프롬프트 내 특정 요소의 영향력을 조절하고 원치 않는 요소를 배제하여 이미지 생성을 통제하는 핵심 메커니즘입니다. 사용자는 괄호와 숫자, 기호를 활용한 가중치 문법을 통해 픽셀 단위의 섬세한 조정이 가능합니다. 이 시스템은 텍스트의 한계를 극복하고 모델이 사용자의 구체적 의도를 정확히 시각화하도록 돕는 필수적인 역할을 합니다.
## 한 줄
> **"매 prompt weight + LoRA + ControlNet + IP-Adapter 의 의 4-layer 의 의 의 의 의 의 fine control 의 의."**. Stable Diffusion 의 raw prompt-only 의 의 (2022) 의 의 modern (SD3.5, FLUX.1, SDXL Lightning) 의 의 multi-modal conditioning stack 의 의. 매 2026 의 의 ComfyUI graph + FLUX dev + LoRA stacking + IP-Adapter (face/style) + ControlNet (pose/depth/canny) 의 production pipeline.
## 📖 구조화된 지식 (Synthesized Content)
* **프롬프트 가중치 조절 (Prompt Weighting):**
* 스테이블 디퓨전에서 가중치 조절은 단어나 구문의 중요도를 세밀하게 지정하는 가장 강력한 무기 중 하나입니다 [1]. 기본 가중치는 1이며, 더 큰 강조를 원할 때는 `+` 기호나 1.1~2 사이의 숫자를, 약화시키고자 할 때는 `-` 기호나 0~0.9 사이의 숫자를 덧붙여 사용합니다 [2].
* 문법적으로는 `(keyword:factor)` 형태를 사용하거나 괄호의 중첩(예: `(word)+++`, `(word)1.1`)을 통해 효과를 증폭시킵니다 [1, 3].
* 가중치 설정 시 0.5에서 0.7 사이가 다른 시각적 개념과 충돌을 피할 수 있는 가장 안전한 기본 범위로 간주되며, 지나치게 높은 가중치(예: 2.0)는 단일 프롬프트를 너무 강하게 만들어 렌더링을 깨뜨릴 수 있습니다 [4, 5].
## 매 핵심
* **부정 프롬프트(Negative Prompts) 기반의 회피 제어:**
* 긍정 프롬프트가 목표(target)라면 부정 프롬프트는 회피 지도(avoidance map)의 역할을 수행합니다 [6]. 워터마크, 왜곡된 인체 등 생성 과정에서 빈번하게 발생하는 결함을 명시적으로 차단하여 고품질 결과물을 유지하게 합니다 [1, 7].
* 단순한 "나쁜(bad)" 같은 포괄적인 단어보다 "여섯 개의 손가락(six fingers)", "비대칭 눈(asymmetrical eyes)"과 같은 구체적인 시각적 특성을 명시하는 것이 효과적입니다 [8].
* 부정 프롬프트 내의 단어에도 가중치(예: `(blurry:1.5)`, `(deformed:1.2)`)를 적용하여 특정 결함을 피하는 데 모델의 주의를 더 강하게 집중시킬 수 있습니다 [9].
### 매 control 의 layer
- **Prompt weight**: `(token:1.3)` — attention multiplier on text token.
- **CFG scale**: 1-15 — text conditioning strength (FLUX 의 의 distilled CFG).
- **LoRA**: rank-decomposed weight delta — `<lora:name:0.8>` 의 의 strength.
- **ControlNet**: structural conditioning (pose, depth, canny, scribble).
- **IP-Adapter**: image prompt — face / style 의 의 image 의 의 의.
- **Regional prompting**: spatial mask 의 의 prompt 의 의 의.
* **고급 시각적 제어 시스템 (ControlNet 및 CFG):**
* **컨트롤넷(ControlNet):** 텍스트를 넘어 이미지의 뼈대(Pose)나 윤곽선(Canny Edge) 정보를 강제로 주입함으로써, 인체의 자세나 사물의 배치를 픽셀 단위로 완벽하게 통제하는 고급 제어 기술입니다 [1].
* **CFG 스케일 및 샘플링 스텝:** 사용자는 CFG 스케일(Classifier-Free Guidance Scale)과 샘플링 스텝을 조절하여 이미지 생성의 가변성을 통제할 수 있습니다 [10]. CFG 스케일은 모델이 사용자의 긍정 및 부정 프롬프트 지시를 얼마나 강하게 따를지(안내의 강도)를 결정합니다 [6, 11].
### 매 LoRA 의 의
- **Rank (r)**: 4-128 — capacity (의 의 의 detail, 의 의 overfit).
- **Alpha (α)**: scaling — effective_weight = alpha/rank × ΔW.
- **Stacking**: multiple LoRA — weight 의 sum 의 의 의 의 saturation.
- **DoRA / LoHa**: LoRA variants — better quality at low rank.
## 🔗 지식 연결 (Graph)
- **Related Topics:** [[프롬프트 가중치 (Prompt Weights)|프롬프트 가중치(Prompt Weights)]], [[부정 프롬프트 (Negative Prompts)|부정 프롬프트(Negative Prompts)]], [[컨트롤넷(ControlNet)|컨트롤넷(ControlNet)]], [[CFG 스케일 (CFG Scale)|CFG 스케일(CFG Scale)]]
- **Projects/Contexts:** 이미지 생성 정밀도 향상 및 오류 디버깅 워크플로우
- **Contradictions/Notes:** 프롬프트를 강조할 때 가중치를 무조건 높이는 것이 좋아 보일 수 있지만, 소스에 따르면 단일 속성에 2.0 이상의 극단적인 가중치를 적용하거나 여러 가중치를 한 번에 과도하게 사용할 경우 심각한 아티팩트(시각적 왜곡)와 비일관성을 유발하여 오히려 이미지가 망가질 위험이 높습니다 [2, 5, 12].
### 매 응용
1. Character consistency — IP-Adapter face + LoRA.
2. Style transfer — style LoRA + style reference IP-Adapter.
3. Pose control — OpenPose ControlNet.
4. Inpainting / outpainting — mask + ControlNet.
---
*Last updated: 2026-04-30*
## 💻 패턴
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
### Prompt weighting (compel / A1111 syntax)
```
# 매 increase weight
(beautiful:1.3) sunset, (highly detailed:1.5)
**언제 이 지식을 쓰는가:**
- *(TODO)*
# 매 decrease weight
[blurry:0.7] background
**언제 쓰면 안 되는가:**
- *(TODO)*
# 매 nested
((cinematic lighting):1.2) photo of a [(crowd):0.8]
```
## 🧪 검증 상태 (Validation)
### Diffusers + LoRA + ControlNet (2026)
```python
from diffusers import FluxPipeline, FluxControlNetModel
from diffusers.utils import load_image
import torch
- **정보 상태:** needs_review
- **출처 신뢰도:** A
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
# 매 FLUX.1-dev + ControlNet
controlnet = FluxControlNetModel.from_pretrained(
"InstantX/FLUX.1-dev-Controlnet-Union",
torch_dtype=torch.bfloat16,
)
pipe = FluxPipeline.from_pretrained(
"black-forest-labs/FLUX.1-dev",
controlnet=controlnet,
torch_dtype=torch.bfloat16,
).to("cuda")
## 🧬 중복 검사 (Duplicate Check)
# 매 LoRA stacking
pipe.load_lora_weights("./loras/anime_style.safetensors", adapter_name="style")
pipe.load_lora_weights("./loras/character.safetensors", adapter_name="char")
pipe.set_adapters(["style", "char"], adapter_weights=[0.7, 0.9])
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
- **처리 방식:** UPDATE (자동 정규화)
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
control_image = load_image("./pose.png")
image = pipe(
prompt="a knight in shining armor, cinematic lighting",
control_image=control_image,
controlnet_conditioning_scale=0.6,
guidance_scale=3.5,
num_inference_steps=28,
).images[0]
```
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
### IP-Adapter for face consistency
```python
from diffusers import StableDiffusionXLPipeline
from transformers import CLIPVisionModelWithProjection
- **과거 데이터와의 충돌:** 없음
- **정책 변화:** 없음
pipe = StableDiffusionXLPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
torch_dtype=torch.float16,
).to("cuda")
## 🕓 변경 이력 (Changelog)
pipe.load_ip_adapter(
"h94/IP-Adapter",
subfolder="sdxl_models",
weight_name="ip-adapter-plus-face_sdxl_vit-h.safetensors",
)
pipe.set_ip_adapter_scale(0.7) # 매 face strength
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|------|-----------|-----------|--------|
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
face_image = load_image("./reference_face.jpg")
result = pipe(
prompt="cyberpunk warrior in neon city",
ip_adapter_image=face_image,
num_inference_steps=30,
).images[0]
```
### LoRA training (PEFT, rank-16)
```python
from peft import LoraConfig
from diffusers import StableDiffusionXLPipeline
lora_config = LoraConfig(
r=16,
lora_alpha=16,
target_modules=["to_q", "to_k", "to_v", "to_out.0"],
init_lora_weights="gaussian",
)
pipe.unet.add_adapter(lora_config)
# 매 의 train — 매 1000-3000 step 의 의 sufficient for character LoRA
```
### ComfyUI workflow (JSON)
```json
{
"nodes": [
{"id": 1, "type": "CheckpointLoader", "model": "flux1-dev.safetensors"},
{"id": 2, "type": "LoraLoader", "lora": "char.safetensors", "strength": 0.9, "input": 1},
{"id": 3, "type": "ControlNetLoader", "model": "flux-controlnet-union.safetensors"},
{"id": 4, "type": "OpenPosePreprocessor", "image": "pose.png"},
{"id": 5, "type": "KSampler", "steps": 28, "cfg": 3.5, "sampler": "euler"}
]
}
```
### Regional prompting (mask-based)
```python
# 매 left half: portrait, right half: landscape
from diffusers_regional import RegionalPipeline
pipe = RegionalPipeline.from_pretrained("stabilityai/sdxl")
masks = [
{"mask": left_mask, "prompt": "portrait of a woman, oil painting"},
{"mask": right_mask, "prompt": "mountain landscape, sunset"},
]
image = pipe(masks=masks, base_prompt="cinematic, detailed").images[0]
```
### CFG scale tuning
```python
# 매 FLUX dev: 의 distilled — guidance_scale 3-5 의 의
# 매 SDXL: 6-9 의 의
# 매 too high → oversaturated, baked-in
# 매 too low → ignores prompt
for cfg in [2.0, 3.5, 5.0, 7.5, 10.0]:
img = pipe(prompt=p, guidance_scale=cfg).images[0]
img.save(f"cfg_{cfg}.png")
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Character consistency | IP-Adapter face + character LoRA |
| Pose / composition control | ControlNet (OpenPose, Depth, Canny) |
| Style transfer | Style LoRA OR IP-Adapter style |
| Fine detail emphasis | Prompt weight `(token:1.3)` |
| Production pipeline | ComfyUI graph (versionable, reproducible) |
| Quick iteration | Diffusers Python API |
**기본값**: FLUX.1-dev + ControlNet Union + LoRA (style+char) + IP-Adapter face — 의 ComfyUI workflow 의 의.
## 🔗 Graph
- 부모: [[Diffusion_Models]] · [[Stable_Diffusion]]
- 변형: [[FLUX_1]] · [[SDXL]] · [[SD3_5]]
- 응용: [[ControlNet]] · [[IP_Adapter]] · [[LoRA_Training]]
- Adjacent: [[ComfyUI]] · [[Prompt_Engineering]] · [[Image_Generation_Workflow]]
## 🤖 LLM 활용
**언제**: prompt scaffolding, ComfyUI node 의 의 explanation, LoRA training script generation.
**언제 X**: 의 visual quality judgement (의 human eval 의 의), 의 specific LoRA recommendation (의 CivitAI 의 의 평가 의).
## ❌ 안티패턴
- **Over-weighted token (`(x:2.0)`)**: 매 attention collapse — artifact 의.
- **Too many LoRA stacked**: 매 weight saturation, 의 ugly mess (4+ 의 의).
- **High CFG on FLUX**: distilled model 의 의 의 — 의 SDXL recipe 의 의.
- **ControlNet at 1.0**: 의 strict — 의 0.4-0.7 의 의.
- **Negative prompt on FLUX dev**: 의 의 의 — 의 distilled 의 의.
## 🧪 검증 / 중복
- Verified (Diffusers docs, ComfyUI repo, Black Forest Labs FLUX paper, Stability AI release notes).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — SD weight + control system 의 의 |