44import tensorflow as tf
55from absl import flags
66
7- import keras_core
7+ import keras
88
99FLAGS = flags .FLAGS
1010
@@ -66,7 +66,7 @@ def on_predict_batch_end(self, batch, logs=None):
6666 self .state ["throughput" ] = throughput
6767
6868
69- class KerasCoreBenchmarkMetricsCallback (keras_core .callbacks .Callback ):
69+ class KerasCoreBenchmarkMetricsCallback (keras .callbacks .Callback ):
7070 def __init__ (self , start_batch = 1 , stop_batch = None ):
7171 self ._callback = BenchmarkMetricsCallback (start_batch , stop_batch )
7272
@@ -108,36 +108,36 @@ def __init__(
108108 input_shape ,
109109 flat_call_inputs = True ,
110110 jit_compile = True ,
111- keras_core_layer = None ,
111+ keras_layer = None ,
112112 tf_keras_layer = None ,
113113 ):
114114 self .layer_name = layer_name
115- _keras_core_layer_class = getattr (keras_core .layers , layer_name )
115+ _keras_layer_class = getattr (keras .layers , layer_name )
116116 _tf_keras_layer_class = getattr (tf .keras .layers , layer_name )
117117
118- if keras_core_layer is None :
119- # Sometimes you want to initialize the keras_core layer and tf_keras
118+ if keras_layer is None :
119+ # Sometimes you want to initialize the keras layer and tf_keras
120120 # layer in a different way. For example, `Bidirectional` layer,
121- # which takes in `keras_core .layers.Layer` and
121+ # which takes in `keras .layers.Layer` and
122122 # `tf.keras.layer.Layer` separately.
123- self ._keras_core_layer = _keras_core_layer_class (** init_args )
123+ self ._keras_layer = _keras_layer_class (** init_args )
124124 else :
125- self ._keras_core_layer = keras_core_layer
125+ self ._keras_layer = keras_layer
126126
127127 if tf_keras_layer is None :
128128 self ._tf_keras_layer = _tf_keras_layer_class (** init_args )
129129 else :
130130 self ._tf_keras_layer = tf_keras_layer
131131
132132 self .input_shape = input_shape
133- self ._keras_core_model = self ._build_keras_core_model (
133+ self ._keras_model = self ._build_keras_model (
134134 input_shape , flat_call_inputs
135135 )
136136 self ._tf_keras_model = self ._build_tf_keras_model (
137137 input_shape , flat_call_inputs
138138 )
139139
140- self ._keras_core_model .compile (
140+ self ._keras_model .compile (
141141 loss = "mse" , optimizer = "sgd" , jit_compile = jit_compile
142142 )
143143 self ._tf_keras_model .compile (
@@ -148,19 +148,19 @@ def __init__(
148148 self .jit_compile = jit_compile
149149 self .input_shape = input_shape
150150
151- def _build_keras_core_model (self , input_shape , flat_call_inputs = True ):
151+ def _build_keras_model (self , input_shape , flat_call_inputs = True ):
152152 inputs = []
153153 if not isinstance (input_shape [0 ], (tuple , list )):
154154 input_shape = [input_shape ]
155155
156156 for shape in input_shape :
157- inputs .append (keras_core .Input (shape = shape ))
157+ inputs .append (keras .Input (shape = shape ))
158158
159159 if flat_call_inputs :
160- outputs = self ._keras_core_layer (* inputs )
160+ outputs = self ._keras_layer (* inputs )
161161 else :
162- outputs = self ._keras_core_layer (inputs )
163- return keras_core .Model (inputs = inputs , outputs = outputs )
162+ outputs = self ._keras_layer (inputs )
163+ return keras .Model (inputs = inputs , outputs = outputs )
164164
165165 def _build_tf_keras_model (self , input_shape , flat_call_inputs = True ):
166166 inputs = []
@@ -195,7 +195,7 @@ def benchmark_predict(self, num_samples, batch_size, data=None):
195195 stop_batch = num_iterations
196196 )
197197
198- self ._keras_core_model .predict (
198+ self ._keras_model .predict (
199199 data ,
200200 batch_size = batch_size ,
201201 callbacks = [callback ],
@@ -207,15 +207,15 @@ def benchmark_predict(self, num_samples, batch_size, data=None):
207207 callbacks = [tf_keras_callback ],
208208 )
209209
210- keras_core_throughput = (
210+ keras_throughput = (
211211 callback ._callback .state ["throughput" ] * batch_size
212212 )
213213 tf_keras_throughput = (
214214 tf_keras_callback ._callback .state ["throughput" ] * batch_size
215215 )
216216 print (
217- f"Keras Core throughput of forward pass of { self .layer_name } : "
218- f"{ keras_core_throughput :.2f} samples/sec."
217+ f"Keras 3 throughput of forward pass of { self .layer_name } : "
218+ f"{ keras_throughput :.2f} samples/sec."
219219 )
220220 print (
221221 f"TF Keras throughput of forward pass of { self .layer_name } : "
@@ -240,15 +240,15 @@ def benchmark_train(self, num_samples, batch_size, data=None, label=None):
240240 if self .flat_call_inputs :
241241 # Scale by a small factor to avoid zero gradients.
242242 label = (
243- keras_core .backend .convert_to_numpy (
244- self ._keras_core_layer (* data )
243+ keras .backend .convert_to_numpy (
244+ self ._keras_layer (* data )
245245 )
246246 * 1.001
247247 )
248248 else :
249249 label = (
250- keras_core .backend .convert_to_numpy (
251- self ._keras_core_layer (data )
250+ keras .backend .convert_to_numpy (
251+ self ._keras_layer (data )
252252 )
253253 * 1.001
254254 )
@@ -259,7 +259,7 @@ def benchmark_train(self, num_samples, batch_size, data=None, label=None):
259259 stop_batch = num_iterations
260260 )
261261
262- self ._keras_core_model .fit (
262+ self ._keras_model .fit (
263263 data ,
264264 label ,
265265 batch_size = batch_size ,
@@ -272,15 +272,15 @@ def benchmark_train(self, num_samples, batch_size, data=None, label=None):
272272 callbacks = [tf_keras_callback ],
273273 )
274274
275- keras_core_throughput = (
275+ keras_throughput = (
276276 callback ._callback .state ["throughput" ] * batch_size
277277 )
278278 tf_keras_throughput = (
279279 tf_keras_callback ._callback .state ["throughput" ] * batch_size
280280 )
281281 print (
282- f"Keras Core throughput of forward & backward pass of "
283- f"{ self .layer_name } : { keras_core_throughput :.2f} samples/sec."
282+ f"Keras 3 throughput of forward & backward pass of "
283+ f"{ self .layer_name } : { keras_throughput :.2f} samples/sec."
284284 )
285285 print (
286286 f"TF Keras throughput of forward & backward pass of "
0 commit comments