Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serving SavedModel files with Tensorflow Java? #126

Open
turtlemonvh opened this issue Aug 15, 2024 · 3 comments
Open

Serving SavedModel files with Tensorflow Java? #126

turtlemonvh opened this issue Aug 15, 2024 · 3 comments

Comments

@turtlemonvh
Copy link

Your documentation mentions :

Run models in Python, C++, Go, JavaScript, and CLI.

image

What about Tensorflow Java? https://github.com/tensorflow/java/releases
If so, which versions are supported?
I was looking to see what version of TensorFlow was required for serving these models, but couldn't tell from the docs.

@rstz
Copy link
Collaborator

rstz commented Aug 16, 2024

Tl;Dr: It's likely possible by first converting to JAX and then to Tensorflow, but our team has not yet tried it.

There are two paths for serving from Tensorflow:

Using the Tensorflow Decision Forests custom op

TensorFlow Decision Forests (TF-DF) defines a custom op for Tensorflow that allows Tensorflow to run tree models generated with YDF or TF-DF itself. This means that you can save a YDF model with model.to_tensorflow_saved_model("/tmp/ydf/tf_model", mode="tf") (details here) and then run it in Tensorflow environments provided that they support this custom op. Notably, the custom op is supported by TF-Serving and Python environments that have Tensorflow Decision Forests installed.

To the best of my knowledge, the custom op is not available in TensorFlow Java and no attempts have been made to include it in Tensorflow Java.

Pure models by converting YDF -> Jax -> Tensorflow

We recently added the possibility to export YDF models to pure JAX functions. JAX functions can be converted to TensorFlow models as shown in this tutorial. The resulting SavedModel is a pure Tensorflow model and should be compatible with all (*) TensorFlow surfaces. We have not tried it with TensorFlow Java, but I'd be very interested if someone has the bandwidth to experiment with it. Note that exporting to JAX is currently implemented for Gradient Boosted Trees only.

(*) TFLite support is coming with the next version of YDF.

@Craigacp
Copy link

Craigacp commented Aug 21, 2024

I believe people eventually got TFDF models to work with TF-Java, there were a bunch of issues with how TFDF was exporting its symbols which were incompatible with TF-Java's build, but now we're using the same binaries as Python it should work (with TF-Java 1.0.0-rc.1).

@rstz
Copy link
Collaborator

rstz commented Aug 22, 2024

That's super interesting, thank you for letting us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants