Ydf/tensorflow_decision_forests models to tensorflow to tflite (?)

Hello,

I am trying to see if ydf models can be converted to tflite format.
I went through the docs, which are very clear on how to export it to tensorflow, but don’t mention tflite. I see on Stackoverflow that tensorflow_decision_forests were not compatible with TFLite one year ago, I suppose that the situation has not changed with ydf?

Thank you for your work!!

Hello @chatnord ,

TensorFlow Decision Forests (TF-DF) and Yggdrasil Decision Forests (YDF) are not compatible with TensorFlow Lite (TFLite) because the necessary custom operations are unsupported. For more information, please refer to the official TensorFlow documentation.

Thank you.

Hi Chatnord,

Support for TFLite is being worked on by the YDF and TFLite team, but it is not yet officially available.
However, some conversion is already possible though the process is manual / not user-friendly.

Details / Warnings

The conversion currently only support Gradient Boosted Trees models (i.e., not the Random Forest models) with numerical, categorical, and boolean features (i.e., no support for free text features).

The conversion is experimental. It means the API and signature might change in the future.

When released, the YDF+TFLite conversion will be available in a single line as model.to_tensorflow_lite. However, this function is currently not available and the conversion need to be done manually.

While model.to_tensorflow_function(mode="tf") and model.to_tensorflow_saved_model(mode="tf") created a TensorFlow Graph/SavedModel with custom ops, the model.to_jax_function() method does not depend on any custom ops. Therefore, a YDF model can be converted into a TFLite model as follow:

  1. YDF to JAX with model.to_jax_function()
  2. JAX to TensorFlow with jax2tf.convert
  3. TensorFlow to TFLite with tf.lite.TFLiteConverter.from_concrete_functions.

Here is a unit test demonstrating this behavior: yggdrasil-decision-forests/yggdrasil_decision_forests/port/python/ydf/model/jax_model_test.py at main · google/yggdrasil-decision-forests · GitHub (look for the “Test TFLite conversion” text).

Hi @Mathieu,

is there yet any update on the conversion from YDF to TFLite? Would an official solution also include TensorFlow Decision Forests library?

Also I would like to know, if your described way is still working?

Thank you for you answer!

Best regards!