완전한 Python 제어가 필요할 때
keras.Model 서브클래싱은 Python으로 forward pass 제어 권한을 줘. __init__에서 layer 정의, call()에서 계산. 가장 유연한 접근 — dynamic architecture, 조건부 로직, 새로운 state 가진 recurrent cell, static graph에 안 맞는 연구 프로토타입에 써.
training 인자가 중요해. Dropout이랑 BatchNormalization 같은 layer는 training과 inference에서 다르게 작동해. model.fit은 자동으로 training=True 넘겨주지만 custom loop에선 명시적으로 — training step엔 model(x, training=True), eval/inference엔 model(x, training=False).
Subclassing trade-off:
model.summary()가 덜 자세함. 저장/불러오기엔 get_config() + from_config() 필요. 배포 예정 model이면 진짜 subclassing이 필요한 게 아닌 한 Functional API가 일반적으로 권장.