WARNING:tensorflow:5 out of the last 5 calls to <InferenceCoreModel.make_predict_function. predict_function_trained > tf.function retracing

Viewed 25

I'm using tensorflow_decision_forests-1.0.1 in tensorflow==2.10.0. First I got following warning in when use model.evaluate(test_ds, return_dict=True).

WARNING: AutoGraph could not transform <function simple_ml_inference_op_with_handle at 0x7f4e341ba440> and will run it as-is. Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10) and attach the full output. Cause: could not get source code To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert

Then I use tf.autograph.set_verbosity(1).

Ather that following warning shows.

WARNING:tensorflow:5 out of the last 5 calls to <function InferenceCoreModel.make_predict_function..predict_function_trained at 0x7f7c544fa3b0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors.

For (1), please define your @tf.function outside of the loop. For (2), @tf.function has reduce_retracing=True option that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.

Can anyone say what are those warnings and how can I fix them? Any help would be appreciated.

Following code part causes the warning(Last 2 lines of codes)

tf.keras.backend.clear_session()
train_ds = tfdf.keras.pd_dataframe_to_tf_dataset(tr_df, label= 'ctg')
test_ds = tfdf.keras.pd_dataframe_to_tf_dataset(ts_df, label='ctg')

model = tfdf.keras.RandomForestModel()
model.compile(metrics=["acc"])
model.fit(x=train_ds)
tr_eval = model.evaluate(train_ds, return_dict=True)
ts_eval = model.evaluate(test_ds, return_dict=True)
0 Answers
Related