모델 양자화

모델 양자화

ONNX Runtime은 보정(calibration) 데이터를 이용해 가중치를 int8 같은 저비트로 양자화하고, 부동소수 연산을 정수 연산으로 바꿔 속도와 메모리를 개선해요. CPU에선 int8 양자화가 특히 효과적이에요.

int8 양자화 흐름

from onnxruntime.quantization import quantize_dynamic, QuantType

quantize_dynamic("model.onnx", "model_int8.onnx", weight_type=QuantType.QInt8)

quantize_dynamic은 실시간(dynamic) 양자화로, 보정 데이터 없이도 빠르게 적용할 수 있어요. 정적 양자화는 보정 데이터로 범위를 먼저 구한 뒤 적용해 정확도를 더 살려요.

확인 포인트

  • 다이내믹 양자화는 간단하지만, 스태틱 양자화가 보통 정확도가 더 좋아요.
  • 양자화 후엔 정확도 회귀 확인을 꼭 해야 해요.

출처: https://onnxruntime.ai/docs/performance/model-optimizations/quantization.html

더 알아보기