Keras quantization-aware training support for custom layers with learnable activations
0 reputation · 27 Jul 2023, 14:14 UTC
Keras quantization-aware training for custom layers with learnable activations
Goal: deploy a Keras model for low-traffic CPU inference using TensorFlow Lite quantization while retaining a custom layer that applies a learnable activation, such as Swish with a trainable beta parameter. The model must remain trainable or convertible without replacing the custom layer with primitive TensorFlow operations.
Constraint: tfmot.quantization.keras.quantize_model requires every layer to expose quantization behavior, and layers without a quantize configuration can fail during conversion. TensorFlow 2.13+ provides quantize_scope, but the required surface area for a quantizable custom layer—particularly get_config and activation handling—is not clearly defined for learnable parameters. Dynamic range quantization avoids this requirement but keeps activations in floating point, limiting CPU latency gains.
- Can a custom Keras layer with a trainable activation parameter be quantized through quantize_scope without rewriting the layer in low-level TensorFlow ops?
- What minimum configuration must a custom layer implement for tfmot.quantization.keras.quantize_model to accept it in TensorFlow 2.13+?
- Is post-training dynamic range quantization the only viable option when a custom layer cannot supply a quantize config?