[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,89 +2,207 @@
|
||||
id: wiki-2026-0508-scalability-in-ai-systems
|
||||
title: Scalability in AI Systems
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [SYS-SCALE-AI-001]
|
||||
aliases: [AI Scalability, Distributed Training, LLM Scaling]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 1.0
|
||||
tags: [ai, infrastructure, Scalability, Distributed-Systems, load-balancing, microservices, MLOps]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [scalability, distributed-training, inference, vllm, fsdp, llm]
|
||||
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: unspecified
|
||||
framework: unspecified
|
||||
language: Python
|
||||
framework: PyTorch / vLLM / DeepSpeed
|
||||
---
|
||||
|
||||
# Scalability in AI[[_system|system]]s (AI 시스템의 확장성)
|
||||
# Scalability in AI Systems
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> "폭증하는 트래픽과 데이터 앞에 시스템이 무너지지 않도록, 선형적 확장(Scaling)이 가능한 모듈형 아키텍처를 구축하고 병목을 선제적으로 해체하라" — 사용자 수나 데이터 규모가 커져도 성능 저하 없이 자원을 추가하여 대응할 수 있는 AI 인프라의 능력.
|
||||
## 매 한 줄
|
||||
> **"매 model size × data × users × latency 의 4축 동시 만족 — 매 single GPU → multi-node training (FSDP/ZeRO/TP/PP) 과 매 10K+ QPS inference (vLLM/SGLang/PagedAttention) 의 양 갈래"**. 매 2020 GPT-3 (175B) 부터 매 2026 trillion-param MoE (Llama 4 Behemoth, Claude Opus 4.7, GPT-5) 까지 매 scaling laws (Chinchilla, Hoffmann 2022) 가 산업 의 compass.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
- **추출된 패턴:** "Horizontal Elasticity and Resource Decoupling" — 서버 한 대의 성능을 높이는 대신(Vertical), 여러 대의 저렴한 서버를 병렬로 연결하고(Horizontal), 연산(GPU)과 저장(DB)을 분리하여 부하에 따라 유연하게 늘리고 줄이는 패턴.
|
||||
- **핵심 확장 전략:**
|
||||
- **Load Balancing:** 트래픽을 여러 추론 서버로 균등하게 분산.
|
||||
- **Model Parallelism:** 거대 모델을 여러 GPU에 나누어 적재.
|
||||
- **Asynchronous [[Processing|Processing]]:** 무거운 작업은 큐(Queue)를 통해 비동기로 처리.
|
||||
- **Microservices:** 기능을 쪼개어 독립적으로 확장 가능하게 설계.
|
||||
- **의의:** 실험실 수준의 AI 모델이 수억 명이 사용하는 대규모 상용 서비스(예: ChatGPT)로 거듭나기 위한 필수적인 공학적 토대.
|
||||
## 매 핵심
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 무조건 자원을 많이 투입하는 것이 답이라던 시대를 지나, 이제는 서버리스(Serverless) 추론이나 지능형 자동 확장(Auto-scaling)을 통해 비용 효율과 확장성을 동시에 잡는 '그린 AI' 인프라가 주목받고 있음.
|
||||
- **정책 변화:** Antigravity 프로젝트는 에이전트의 동시 접속자 수 증가에 대비하여, 도커(Docker)와 쿠버네티스(Kubernetes) 기반의 컨테이너 환경에서 유연하게 확장 가능한 마이크로서비스 구조를 기본 채택함.
|
||||
### 매 Training scalability axes
|
||||
- **Data parallel (DP)**: replicate model, shard batch — gradient all-reduce.
|
||||
- **Tensor parallel (TP)**: split single layer across GPUs (Megatron-LM).
|
||||
- **Pipeline parallel (PP)**: split layers across stages (GPipe, 1F1B).
|
||||
- **FSDP / ZeRO**: shard params + grads + optimizer state (ZeRO-1/2/3).
|
||||
- **Sequence/Context parallel**: shard along sequence (Ring Attention, DeepSpeed-Ulysses).
|
||||
- **MoE expert parallel**: route tokens to expert subsets across GPUs.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- System-Design-for-AI-Scale, [[High-Availability-Systems|High-Availability-Systems]], [[Parallel-Computing-in-AI|Parallel-Computing-in-AI]], Cloud-Computing-Foundations
|
||||
- **Raw Source:** 10_Wiki/Topics/AI/Scalability-in-AI-Systems.md
|
||||
### 매 Inference scalability
|
||||
- **Continuous batching**: vLLM / TGI — token-level scheduling, no head-of-line block.
|
||||
- **PagedAttention**: KV cache paged like virtual memory → high concurrency.
|
||||
- **Prefix caching**: shared system prompt cache (vLLM, SGLang).
|
||||
- **Speculative decoding**: small draft model proposes, large verifies → 2-3x.
|
||||
- **Quantization**: FP8, INT4 (AWQ, GPTQ), MX formats (MXFP4) — 2026 H200/B200 native.
|
||||
- **Disaggregated serving**: prefill nodes vs decode nodes (Splitwise, DistServe).
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### 매 응용
|
||||
1. Pretraining 70B+ on 256+ GPU cluster.
|
||||
2. LoRA/QLoRA fine-tune on single H100 (24GB shard).
|
||||
3. 100K+ concurrent chatbot QPS via vLLM cluster.
|
||||
4. RAG at 1M+ docs with sharded vector DB.
|
||||
5. Multi-tenant inference with tenant-aware caching.
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
## 💻 패턴
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### FSDP2 with PyTorch (2026 idiom)
|
||||
```python
|
||||
import torch
|
||||
from torch.distributed.fsdp import fully_shard, MixedPrecisionPolicy
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
model = LlamaForCausalLM.from_pretrained("meta-llama/Llama-3.1-70B")
|
||||
mp_policy = MixedPrecisionPolicy(
|
||||
param_dtype=torch.bfloat16,
|
||||
reduce_dtype=torch.float32,
|
||||
)
|
||||
for layer in model.model.layers:
|
||||
fully_shard(layer, mp_policy=mp_policy)
|
||||
fully_shard(model, mp_policy=mp_policy)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
# Gradient checkpointing for memory
|
||||
model.gradient_checkpointing_enable()
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### DeepSpeed ZeRO-3 config
|
||||
```json
|
||||
{
|
||||
"train_batch_size": 1024,
|
||||
"gradient_accumulation_steps": 4,
|
||||
"bf16": {"enabled": true},
|
||||
"zero_optimization": {
|
||||
"stage": 3,
|
||||
"offload_param": {"device": "cpu"},
|
||||
"offload_optimizer": {"device": "nvme", "nvme_path": "/mnt/nvme"},
|
||||
"overlap_comm": true,
|
||||
"contiguous_gradients": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### vLLM serving (continuous batching + prefix cache)
|
||||
```python
|
||||
from vllm import LLM, SamplingParams
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
llm = LLM(
|
||||
model="meta-llama/Llama-3.1-70B-Instruct",
|
||||
tensor_parallel_size=4,
|
||||
enable_prefix_caching=True,
|
||||
max_model_len=128000,
|
||||
quantization="fp8",
|
||||
gpu_memory_utilization=0.92,
|
||||
)
|
||||
out = llm.generate(prompts, SamplingParams(max_tokens=512, temperature=0.7))
|
||||
```
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
### SGLang RadixAttention (shared prefix tree)
|
||||
```python
|
||||
import sglang as sgl
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
sgl.set_default_backend(sgl.RuntimeEndpoint("http://localhost:30000"))
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
@sgl.function
|
||||
def multi_turn(s, system, turns):
|
||||
s += sgl.system(system) # cached across all calls
|
||||
for t in turns:
|
||||
s += sgl.user(t["q"]) + sgl.assistant(sgl.gen(max_tokens=256))
|
||||
|
||||
# Massive throughput when many users share system prompt
|
||||
```
|
||||
|
||||
### Speculative decoding (vLLM)
|
||||
```python
|
||||
llm = LLM(
|
||||
model="meta-llama/Llama-3.1-70B-Instruct",
|
||||
speculative_model="meta-llama/Llama-3.2-1B-Instruct",
|
||||
num_speculative_tokens=5,
|
||||
use_v2_block_manager=True,
|
||||
)
|
||||
```
|
||||
|
||||
### Megatron-LM tensor + pipeline parallel
|
||||
```bash
|
||||
torchrun --nproc_per_node=8 --nnodes=8 \
|
||||
pretrain_gpt.py \
|
||||
--tensor-model-parallel-size 8 \
|
||||
--pipeline-model-parallel-size 8 \
|
||||
--num-layers 80 --hidden-size 8192 \
|
||||
--num-attention-heads 64 --seq-length 8192 \
|
||||
--micro-batch-size 1 --global-batch-size 1024 \
|
||||
--bf16 --use-flash-attn
|
||||
```
|
||||
|
||||
### Distributed inference K8s (vLLM + Ray Serve)
|
||||
```python
|
||||
from ray import serve
|
||||
from vllm.entrypoints.openai.api_server import app as vllm_app
|
||||
|
||||
@serve.deployment(num_replicas=4, ray_actor_options={"num_gpus": 2})
|
||||
@serve.ingress(vllm_app)
|
||||
class LLMService:
|
||||
def __init__(self, model):
|
||||
self.engine = AsyncLLMEngine.from_engine_args(
|
||||
AsyncEngineArgs(model=model, tensor_parallel_size=2)
|
||||
)
|
||||
```
|
||||
|
||||
### KV cache sizing rule of thumb
|
||||
```python
|
||||
def kv_cache_bytes(layers, hidden_dim, seq_len, batch, dtype_bytes=2, kv_heads=None):
|
||||
h = kv_heads or hidden_dim # GQA: kv_heads < hidden
|
||||
return 2 * batch * layers * seq_len * h * dtype_bytes
|
||||
# Llama-3-70B at 128K context, batch=1, GQA(8): ~10 GB KV
|
||||
```
|
||||
|
||||
### Disaggregated prefill/decode (Splitwise pattern)
|
||||
```python
|
||||
# Prefill cluster: H100, optimized for compute
|
||||
# Decode cluster: H100/L40S, optimized for memory bandwidth
|
||||
# KV transfer over NVLink/RDMA between clusters
|
||||
prefill_resp = await prefill_client.prefill(prompt) # returns KV blocks ref
|
||||
decode_stream = decode_client.decode(kv_ref=prefill_resp.kv_ref, max_tokens=512)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| <13B model train | DDP / FSDP1 single node 8xGPU |
|
||||
| 70B train | FSDP2 / ZeRO-3 multi-node + activation checkpoint |
|
||||
| 400B+ MoE | TP + PP + EP + ZeRO-1 (Megatron-Core / NeMo) |
|
||||
| Chatbot serving | vLLM + prefix cache + speculative decoding |
|
||||
| Long context (1M+) | Ring attention / context parallel |
|
||||
| High concurrency | SGLang RadixAttention + disaggregated |
|
||||
|
||||
**기본값**: FSDP2 for training under 100B; vLLM with FP8 + prefix cache + spec decoding for serving.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Distributed-Systems]] · [[High-Performance-Computing]]
|
||||
- 변형: [[FSDP]] · [[DeepSpeed-ZeRO]] · [[Tensor-Parallelism]] · [[Pipeline-Parallelism]]
|
||||
- 응용: [[LLM-Pretraining]] · [[LLM-Serving]] · [[Fine-tuning]]
|
||||
- Adjacent: [[vLLM]] · [[Flash-Attention]] · [[Speculative-Decoding]] · [[Quantization]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: capacity planning estimates, config-file generation (deepspeed, accelerate), debugging OOM via log triage, scaling-law back-of-envelope.
|
||||
**언제 X**: actually scheduling kernels — the orchestrator (PyTorch/vLLM) handles deterministic scheduling.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **All-reduce on tiny gradients**: communication dominates; bucket gradients.
|
||||
- **Naive batching for serving**: head-of-line blocking — use continuous batching.
|
||||
- **Unbounded KV cache**: OOM at peak; use PagedAttention + admission control.
|
||||
- **No prefix cache for shared system prompt**: 5-10x throughput left on table.
|
||||
- **PP without enough microbatches**: bubble dominates pipeline.
|
||||
- **MoE without expert balance loss**: dead experts, capacity waste.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Megatron-LM/Megatron-Core, vLLM paper SOSP 2023, Chinchilla 2022, NVIDIA H100/B200 perf guides 2026).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FSDP/ZeRO/TP/PP, vLLM/SGLang, disaggregated serving |
|
||||
|
||||
Reference in New Issue
Block a user