Tensor Core (V100, A100, H100, RTX 30/40 시리즈) 가 FP16 / BF16 에서 2-3 배 더 빠른 matmul. mixed precision 은 weight / activation 을 FP16 로, master copy 와 일부 통계는 FP32 로 — 속도 + 정확도 둘 다.
Keras 에서 한 줄: keras.mixed_precision.set_global_policy('mixed_float16'). 그 후 model 학습. loss scaling 자동 — FP16 underflow 방지. 큰 모델·큰 배치에서 가장 효과적.
백엔드 노트:
⚙️ Backend Note
Code
# Enable mixed precision globally
keras.mixed_precision.set_global_policy("mixed_float16")
# Build and train normally — Keras handles the casting
model = keras.Sequential([
keras.Input(shape=(784,)),
layers.Dense(256, activation="relu"), # Computes in float16
layers.Dense(10), # Raw logits (no activation)
])
# Use from_logits for numerical stability with mixed precision
model.compile(
optimizer="adam",
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
)