Closed james77777778 closed 10 months ago
Patch coverage: 100.00%
and project coverage change: +0.25%
:tada:
Comparison is base (
94b5361
) 76.56% compared to head (10e4a03
) 76.82%. Report is 4 commits behind head on main.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Fixes #824
This PR accomplishes the following:
rsqrt
in numpy backend (using jax's impl)1 / ops.sqrt(x)
withops.rsqrt
for improved speedtf.nn.batch_normalization
linkAfter completing 3, tflite recognizes the pattern of CONV+BN+ReLU, and the ops are fused successfully.
standalone MobileNetV3 export script
```python import tensorflow as tf from keras_core.applications.mobilenet_v3 import MobileNetV3Small keras_core_model = MobileNetV3Small( input_shape=(224, 224, 3), minimalistic=True ) tf_callable = tf.function( keras_core_model.call, input_signature=[tf.TensorSpec((1, 224, 224, 3), tf.float32)], autograph=True, jit_compile=True, ) tf_concrete_function = tf_callable.get_concrete_function() converter = tf.lite.TFLiteConverter.from_concrete_functions( [tf_concrete_function], tf_callable ) converter.optimizations = [tf.lite.Optimize.DEFAULT] tflite_model = converter.convert() with open("model.tflite", "wb") as f: f.write(tflite_model) ```The visualization from netron: (before this PR vs. after this PR)
![圖片](https://github.com/keras-team/keras-core/assets/20734616/a43e556b-2a55-4dc6-8a1b-6acf38e9e724)
benchmark script
```python from keras_core import layers from keras_core import mixed_precision from keras_core import models from keras_core import ops # "float32" # "mixed_float16" # "mixed_bfloat16" dtype_policy = "float32" mixed_precision.set_dtype_policy(dtype_policy) x_train = ops.random.uniform(shape=(512, 64, 64, 64)) y_train = ops.random.uniform(shape=(512, 64, 64, 64)) # layers.BatchNormalization # layers.GroupNormalization # layers.LayerNormalization normalization_cls = layers.LayerNormalization normalization_args = {} if normalization_cls is layers.GroupNormalization: normalization_args = {"groups": -1} model = models.Sequential( [ layers.InputLayer(shape=(64, 64, 64)), normalization_cls(**normalization_args), normalization_cls(**normalization_args), normalization_cls(**normalization_args), ] ) model.compile(loss="mse", optimizer="adam") model.fit(x_train, y_train, batch_size=128, epochs=3) ```