Training 이 iterative; inference 가 성능-critical
model train 후 serving 위 최적화. routine 결합할 세 기법:
torch.compile(model)— TorchInductor 로 model graph JIT-compile. 한 줄에 1.5-3x speedup. (다음 트랙에 full coverage.)- Quantization — 더 작은 model 과 빠른 matmul 위 numerical 정밀도 감소 (fp32 → int8 또는 int4). modern path 가
torchao. - Batching — 32 single-sample inference 대신 한 32-sample batch. 활용도 부족이 실재 비용.
적용 순서
- eager-mode + fp32 로 정확성 맞추기. output 검증.
- hardware 지원하면 bf16 으로 전환. 정확도 유지 검증.
torch.compile(model)추가. 속도와 정확도 검증.- 더 필요하면 quantize (transformer 엔 int8 dynamic, LLM 엔 int8/int4 weight-only).
- request serving 면 작은 queueing window 로 user 들 batch.
Python overhead 잊지 마
Tokenization, post-processing, serialization 이 작은 model 의 inference time 지배 가능. 단지 forward pass 아니라 end-to-end (HTTP request → response) profile. fix 가 종종 'tokenizer cache' 또는 'faster JSON 라이브러리 사용' 이지 model-side 아님.