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

Model deployment for predictions in Vertex AI #162

Open
lenassero opened this issue Jan 28, 2025 · 2 comments
Open

Model deployment for predictions in Vertex AI #162

lenassero opened this issue Jan 28, 2025 · 2 comments

Comments

@lenassero
Copy link

lenassero commented Jan 28, 2025

Hi all,

I am currently transitioning from tfdf to ydf for training Random Forest models. I need to save the models in the SavedModel format for Vertex AI predictions, still requiring me to use tfdf. I am thus using the following versions in my training pipeline:

tensorflow = "2.16.1"
tf-keras = "2.16"
tensorflow-decision-forests = "1.9.1" 
ydf = "0.9.0" 
  • I use tfdf==1.9.1 which fixes the collision issue with YDF
  • The TF version is fixed to 2.16.1 since tfdf==1.9.1 is only compatible with that version of TF (cf. compatibility table)
  • I use tf-keras to be able to use Keras 2.x since Keras 3.x is now the default in TF 2.16.1

After training, I save my model in the Keras SavedModel format and would like to deploy it in Vertex AI for making predictions. However, the latest TF version available in Vertex AI as a prebuilt container is 2.15.

Do you know if there is a plan to include a prebuilt container with TF 2.16.1 to allow for models trained with YDF to be used in Vertex AI ?
If not, is there an other way to circumvent the collision issue (I cannot force install ydf as my dependencies are resolved with poetry).

Thank you for your help and for the great lib :),
Best,
Nasser

@rstz
Copy link
Collaborator

rstz commented Jan 30, 2025

Have you tried if it "just works" with Tensorflow 2.15.0, tfdf 1.8.1 and ydf 0.9.0?

I just tried the following on Google colab after installing these versions and everything worked fine. I think the proto collision was separately solved on the YDF side.

import ydf
import tensorflow_decision_forests as tfdf
import tensorflow as tf 
import pandas as pd
import numpy as np

print(f"Tensorflow version is {tf.__version__}")
print(f"Tensorflow Decision Forests version is {tfdf.__version__}")
print(f"YDF version is {ydf.__version__}")
# Tensorflow version is 2.15.0
# Tensorflow Decision Forests version is 1.8.1
# YDF version is 0.9.0
ds_path = "https://raw.githubusercontent.com/google/yggdrasil-decision-forests/main/yggdrasil_decision_forests/test_data/dataset"
train_ds = pd.read_csv(f"{ds_path}/gaussians_train.csv")
test_ds = pd.read_csv(f"{ds_path}/gaussians_test.csv")

ydf_model = ydf.RandomForestLearner(label="label", task=ydf.Task.CLASSIFICATION).train(train_ds)

ydf_model.to_tensorflow_saved_model('my_tfdf_model')
tfdf_model = tf.keras.models.load_model('my_tfdf_model')

ydf_pred = ydf_model.predict(test_ds)
test_tf_ds = tfdf.keras.pd_dataframe_to_tf_dataset(test_ds, label="label")
tfdf_pred = tfdf_model.predict(test_tf_ds).flatten()
np.all(tfdf_pred == ydf_pred)
# True

@lenassero
Copy link
Author

Hi @rstz,

Thank you for your quick reply and looking into this ! It works with those versions but the collision error happens at the import of ydf depending on the order of install of ydf and tfdf (cf. here for more details). The proto collision was actually fixed in tfdf==1.9.1 (release notes) as tfdf depends on ydf there.

But I cannot force install ydf as my dependencies are resolved with poetry as suggested here (and the error message in ydf)

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

2 participants