How Deep Learning Computes
행렬 연산에서 모델 성능까지, 딥러닝 계산을 개념 단위 카드와 학습 경로로 따라갑니다. 카드는 여러 경로에서 재사용됩니다.
처음이라면 여기부터
AI 시스템 계산을 이해하는 데 가장 기본이 되는 세 경로입니다.
1 행렬 연산에서 Roofline 분석까지
행렬 곱셈의 연산량과 메모리 이동량에서 출발해 산술 강도와 Roofline 분석으로 이어지는 첫 번째 경로.
2 Forward Pass에서 학습 메모리까지모델을 행렬 연산의 반복으로 보고, forward/backward/update 동안 activation, gradient, optimizer state가 어떻게 생기는지 따라간다.
3 Transformer 구조를 텐서 흐름으로 이해하기Embedding, attention, MLP/FFN 세 덩어리에서 시작해 Transformer block과 MoE까지 텐서 모양 중심으로 따라간다.
전체 지식 지도
카드는 하나의 전역 그래프로 두고, 학습 경로는 지하철 노선처럼 겹쳐 보여줍니다.
행렬 연산에서 Roofline 분석까지 Forward Pass에서 학습 메모리까지 Transformer 구조를 텐서 흐름으로 이해하기 CUDA Attention과 FlashAttention CUDA 좌표계와 첫 커널 CUDA Kernel Optimization Basics Transformer를 위한 CUDA Naive Kernels Distributed Matmul: Sharded Matrices and Collective Operations dLLM 추론과 서빙 JAX Distributed Training JAX Profiling과 Kernel Optimization JAX Transformer 모델 직접 작성하기 JAX Transformer 학습하기 Large-Scale Training Parallelism LLM Inference Quantization LLM 추론 이론 LLM Training Parallelism nano-vLLM 만들어보기 nano-vLLM Kernel Optimization Numerical Precision and Quantization PyTorch Distributed Training PyTorch Profiling과 Kernel Optimization PyTorch Transformer 모델 직접 작성하기 PyTorch Transformer 학습하기 SSM 추론과 하이브리드 모델 vLLM Deep Dive
모든 학습 경로
관심 있는 주제로 바로 들어갈 수도 있습니다.
- CUDA Attention과 FlashAttention — naive attention에서 시작해 online softmax, tiling, IO 분석을 거쳐 FlashAttention forward의 핵심 아이디어를 이해한다.
- CUDA 좌표계와 첫 커널 — CPU loop에서 출발해 vectorAdd, grid/block/thread, host/device memory, 2D/3D indexing, warp와 block shape까지 익힌다.
- CUDA Kernel Optimization Basics — CUDA event timing, memory coalescing, shared memory, tiled matmul, reduction, warp primitive, occupancy를 통해 naive kernel을 최적화하는 기본기를 익힌다.
- Transformer를 위한 CUDA Naive Kernels — CPU reference와 비교하며 transpose, GEMM, GEMV, softmax, RMSNorm forward/backward를 naive CUDA kernel로 구현하고 PyTorch JIT extension으로 연결한다.
- Distributed Matmul: Sharded Matrices and Collective Operations — 행렬을 여러 accelerator에 나눠 계산할 때 mesh, sharding, collective communication이 어떻게 연결되는지 이해한다.
- dLLM 추론과 서빙 — discrete diffusion LLM을 autoregressive token-by-token decoding의 가정이 깨지는 사례로 보고, canvas denoising이 serving system을 어떻게 바꾸는지 이해한다.
- Forward Pass에서 학습 메모리까지 — 모델을 행렬 연산의 반복으로 보고, forward/backward/update 동안 activation, gradient, optimizer state가 어떻게 생기는지 따라간다.
- JAX Distributed Training — JAX의 device mesh, NamedSharding, PartitionSpec, pmap/pjit 관점으로 multi-device 학습을 이해한다.
- JAX Profiling과 Kernel Optimization — JAX에서 compile time과 execution time을 분리하고, block_until_ready, jit benchmark, profiler trace, Pallas/커스텀 커널 후보를 이해한다.
- JAX Transformer 모델 직접 작성하기 — PyTorch Transformer lab과 같은 decoder-only 모델을 JAX의 pure function, parameter pytree, explicit PRNG 방식으로 다시 작성한다.
- JAX Transformer 학습하기 — JAX Transformer에 next-token loss, value_and_grad, jit-compiled train step, explicit optimizer state를 붙여 학습 루프를 만든다.
- Large-Scale Training Parallelism — Picotron, Nanotron, Megatron을 단계적으로 읽으며 TP, PP, CP, EP를 production-scale 분산 학습 관점에서 이해한다.
- LLM Inference Quantization — LLM inference에서 weight, activation, KV cache quantization을 memory traffic, kernel 실행, serving benchmark 관점으로 이해한다.
- LLM 추론 이론 — prefill/decode, KV cache, MQA/GQA/MLA, PagedAttention처럼 LLM 추론 시스템을 이해하는 데 필요한 이론을 정리한다.
- LLM Training Parallelism — 단일 GPU 학습 step에서 출발해 DP, gradient overlap, 병렬화와 샤딩의 차이를 이해한다.
- 행렬 연산에서 Roofline 분석까지 — 행렬 곱셈의 연산량과 메모리 이동량에서 출발해 산술 강도와 Roofline 분석으로 이어지는 첫 번째 경로.
- nano-vLLM 만들어보기 — 동작하는 가장 작은 inference loop에서 시작해 request state, scheduler, prefill/decode, continuous batching, paged KV cache, model runner 분리를 단계별 snapshot으로 구현한다.
- nano-vLLM Kernel Optimization — nano-vLLM serving loop에 RMSNorm과 attention backend 교체 지점을 만들고 TTFT, TPOT, throughput 전후를 측정한다.
- Numerical Precision and Quantization — FP32, FP16, BF16, FP8의 표현 범위와 정밀도 trade-off에서 시작해 mixed precision training과 quantization의 기본 원리를 이해한다.
- PyTorch Distributed Training — 단일 GPU 학습 루프를 torchrun, DDP, FSDP, communication profiling으로 확장해 multi-GPU 학습을 구현한다.
- PyTorch Profiling과 Kernel Optimization — 직접 작성한 Transformer를 profiling하고 RMSNorm, manual attention, PyTorch SDPA, optimized attention을 비교한다.
- PyTorch Transformer 모델 직접 작성하기 — PyTorch로 작은 decoder-only Transformer의 구성 요소를 직접 구현하고 하나의 language model로 조립한다.
- PyTorch Transformer 학습하기 — 직접 작성한 Transformer에 next-token loss, batch pipeline, single-GPU training loop, mixed precision을 붙여 학습한다.
- SSM 추론과 하이브리드 모델 — SSM/Mamba를 새 모델 구조로만 보지 않고, KV-cache 중심 Transformer serving의 가정이 어떻게 바뀌는지 추적한다.
- Transformer 구조를 텐서 흐름으로 이해하기 — Embedding, attention, MLP/FFN 세 덩어리에서 시작해 Transformer block과 MoE까지 텐서 모양 중심으로 따라간다.
- vLLM Deep Dive — vLLM을 API server, engine core, GPU worker의 세 컴포넌트와 그 사이의 request/response/data contract 중심으로 분석한다.