Skip to content

Commit

Permalink
Fix paddle flavor for paddle 2.6.0 (mlflow#10757)
Browse files Browse the repository at this point in the history
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: mlflow-automation <mlflow-automation@users.noreply.github.com>
Co-authored-by: mlflow-automation <mlflow-automation@users.noreply.github.com>
  • Loading branch information
2 people authored and annzhang-db committed Jan 3, 2024
1 parent 9f8c1bb commit 53f31e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion mlflow/paddle/__init__.py
Expand Up @@ -456,6 +456,7 @@ def predict(
Model predictions.
"""
import numpy as np
import paddle
import pandas as pd

if isinstance(data, pd.DataFrame):
Expand All @@ -473,7 +474,7 @@ def predict(

self.pd_model.eval()

predicted = self.pd_model(inp_data)
predicted = self.pd_model(paddle.to_tensor(inp_data))
return pd.DataFrame(predicted.numpy())


Expand Down
16 changes: 9 additions & 7 deletions tests/paddle/test_paddle_model_export.py
Expand Up @@ -125,13 +125,13 @@ def test_model_save_load(pd_model, model_path):
reloaded_pyfunc = pyfunc.load_model(model_uri=model_path)

np.testing.assert_array_almost_equal(
pd_model.model(pd_model.inference_dataframe),
pd_model.model(paddle.to_tensor(pd_model.inference_dataframe)),
reloaded_pyfunc.predict(pd_model.inference_dataframe),
decimal=5,
)

np.testing.assert_array_almost_equal(
reloaded_pd_model(pd_model.inference_dataframe),
reloaded_pd_model(paddle.to_tensor(pd_model.inference_dataframe)),
reloaded_pyfunc.predict(pd_model.inference_dataframe),
decimal=5,
)
Expand All @@ -148,8 +148,8 @@ def test_model_load_from_remote_uri_succeeds(pd_model, model_path, mock_s3_bucke
model_uri = artifact_root + "/" + artifact_path
reloaded_model = mlflow.paddle.load_model(model_uri=model_uri)
np.testing.assert_array_almost_equal(
pd_model.model(pd_model.inference_dataframe),
reloaded_model(pd_model.inference_dataframe),
pd_model.model(paddle.to_tensor(pd_model.inference_dataframe)),
reloaded_model(paddle.to_tensor(pd_model.inference_dataframe)),
decimal=5,
)

Expand All @@ -169,8 +169,8 @@ def test_model_log(pd_model, model_path, tmp_path):

reloaded_pd_model = mlflow.paddle.load_model(model_uri=model_uri)
np.testing.assert_array_almost_equal(
model(pd_model.inference_dataframe),
reloaded_pd_model(pd_model.inference_dataframe),
model(paddle.to_tensor(pd_model.inference_dataframe)),
reloaded_pd_model(paddle.to_tensor(pd_model.inference_dataframe)),
decimal=5,
)

Expand Down Expand Up @@ -578,7 +578,9 @@ def test_pyfunc_serve_and_score(pd_model):
scores = pd.DataFrame(
data=json.loads(resp.content.decode("utf-8"))["predictions"]
).values.squeeze()
np.testing.assert_array_almost_equal(scores, model(inference_dataframe).squeeze())
np.testing.assert_array_almost_equal(
scores, model(paddle.to_tensor(inference_dataframe)).squeeze()
)


def test_log_model_with_code_paths(pd_model):
Expand Down

0 comments on commit 53f31e5

Please sign in to comment.